/******************************* Copyright notice ******************************* Copyright (C)2002 by Andrei Loskutov <loskutov@gmx.de>. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ********************************************************************************/ /** * Created on 02.12.2002 * * To change this generated comment edit the template variable "filecomment": * Window>Preferences>Java>Templates. * To enable and disable the creation of file comments go to * Window>Preferences>Java>Code Generation. */ package adiag.gui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Observable; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JProgressBar; import Acme.JPM.Encoders.GifEncoder; import adiag.connection.Configuration; import adiag.connection.Connector; import adiag.connection.P4CommandConnector; import adiag.model.Const; import adiag.model.Version; import adiag.view.Layout; import adiag.view.Toolz; import adiag.view.VersionView; /** * @author Andy the Great * * To change this generated comment edit the template variable "typecomment": * Window>Preferences>Java>Templates. * To enable and disable the creation of type comments go to * Window>Preferences>Java>Code Generation. */ public class BranchView extends Observable { /** current first clicked version, for diff */ private VersionView diffView; /** last clicked version */ private VersionView clicked; /** the instance of layout component */ private Layout layout; /** flag to redraw view */ protected boolean need_re_paint; /** versions to move/moved */ private VersionView[] moved; Configuration app; public BranchView(Configuration app){ this.app = app; } /** * Returns the clicked. * @return VersionView */ public VersionView getClicked() { return clicked; } /** * Returns the layout. * @return Layout */ public Layout getBranchLayout() { return layout; } /** * Returns the moved. * @return VersionView[] */ public VersionView[] getMoved() { return moved; } /** * Returns the need_re_paint. * @return boolean */ public boolean isNeed_re_paint() { return need_re_paint; } /** * Sets the need_re_paint. * @param need_re_paint The need_re_paint to set */ public void setNeed_re_paint(boolean need_re_paint) { this.need_re_paint = need_re_paint; } /** * Returns the diffView. * @return VersionView */ public VersionView getDiffView() { return diffView; } /** * Sets the diffView. * @param diffView The diffView to set */ public void setDiffView(VersionView diffView) { this.diffView = diffView; } /** * Returns the layout. * @return Layout */ public Layout getLayout() { return layout; } /** * Sets the clicked. * @param clicked The clicked to set */ public void setClicked(VersionView clicked) { this.clicked = clicked; } /** * Sets the layout. * @param layout The layout to set */ public void setLayout(Layout layout) { this.layout = layout; } /** * Sets the moved. * @param moved The moved to set */ public void setMoved(VersionView[] moved) { this.moved = moved; } /** * Request new data for given version from P4 process * @param v Version */ public void exploreVersion(Version v) { Connector c = app.getConnector(); app.setPath(v.getPath()); try { layout.addVersions(c.getData()); refreshLayout(false); } catch (Exception e) { app.error("Cannot get info:\n" + e.getMessage(), e); } } /** * Request new data for all known branches from P4 process */ public void exploreAllVersions() { Connector c = app.getConnector(); app.setDiscoverAllBranches(true); try { layout.addVersions(c.getData()); refreshLayout(false); } catch (Exception e) { app.error("Cannot get info:\n" + e.getMessage(), e); } app.setDiscoverAllBranches(false); } /** * Update view and redo layout * @param changeOffscreenLocation currently not used */ public void refreshLayout(boolean changeOffscreenLocation) { layout.doLayout(); this.setChanged(); this.notifyObservers(Commands.COMMAND_REDO_LAYOUT); } /** * Change path of the view to new one * @param path P4 depot path to view */ public void changeFile(final String path) { app.getPropsSetter().setProperty(Const.PROPERTY_OFFLINE, "false", app); Connector c = new P4CommandConnector(app); app.setConnector(c); app.setOffline(false); app.setPath(path); try { layout.setVersions(c.getData()); refreshLayout(true); } catch (Exception ee) { app.error("Cannot change file:\n" + ee.getMessage(), ee); } } /** * Perform save operation. Entire view will be saved on one or more gif images * with one html - index file. Images will be successive numbered. * @param f "base" file name to calculate real file names for multiple gif/html files */ public void saveViewAsImage(File f, Dimension d) { String message = "Images and HTML overview are successfully saved!"; BufferedOutputStream out = null; FileOutputStream fo = null; GifEncoder encoder = null; int image_width = 600; int image_height = 400; int count_width = d.width / image_width; int count_height = d.height / image_height; if(count_width <= 1){ image_width = d.width; } if(count_height <= 1){ image_height = d.height; } if(d.width - count_width * image_width > 0){ count_width ++; } if(d.height - count_height * image_height > 0){ count_height ++; } String prefix = f.getName(); String suffix = ".html"; String suffix_img = ".gif"; String cancel_txt = "Cancel"; if (prefix.endsWith(suffix)) { //f = new File(f.getParentFile(), f.getName() + ".gif"); prefix = prefix.substring(0, prefix.length() - suffix.length()); } BufferedImage img = new BufferedImage(image_width, image_height, BufferedImage.TYPE_INT_RGB); Graphics2D gr = (Graphics2D) img.getGraphics(); gr.setBackground(Color.white); gr.clearRect(0,0, image_width, image_height); //gr.scale(scale_x_axis, scale_y_axis); int dx = 0; int dy = 0; int y_position = 0; int x_position = 0; int images_nbr = count_height * count_width; final JProgressBar progressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, images_nbr); final JLabel label = new JLabel(); Thread messageThread = null; final JPanel panel = new JPanel(new BorderLayout(3,3)); final JOptionPane pane = new JOptionPane( panel, JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new String[]{cancel_txt} ); final JDialog dialog = pane.createDialog(app.getJComponent(), "Information"); if(images_nbr > 1){ Runnable run = new Runnable() { public void run() { dialog.setModal(true); panel.add(progressBar, BorderLayout.CENTER); panel.add(label, BorderLayout.SOUTH); dialog.show(); dialog.setModal(false); } }; messageThread = new Thread(run); //messageThread.setPriority(Thread.MAX_PRIORITY); messageThread.start(); } StringBuffer sb = new StringBuffer(); sb.append("<html>\n<head>\n<title>").append(app.getPath()).append("</title>\n</head>\n<body>"); sb.append("\n<table cellpadding='0' cellspacing='0' border='0'>"); String fileName = ""; int count = 0; for (int i = 0; i < count_height; i++) { y_position += dy; dx = 0; x_position = 0; if(dy == 0){ dy = -image_height; } sb.append("\n<tr>"); for (int j = 0; j < count_width; j++) { Object selectedValue = pane.getValue(); if(cancel_txt.equals(selectedValue) || !dialog.isModal()){ break; } try { gr.translate(x_position, y_position); if (getLayout() != null) { getLayout().paint(gr); } fileName = prefix + "_" + i + "_" + j + suffix_img; sb.append("\n\t<td><img src='").append(fileName).append("' width='"); sb.append(image_width).append("' height='").append(image_height).append("'></td>"); f = new File(f.getParentFile(), fileName); fo = new FileOutputStream(f); out = new BufferedOutputStream(fo); encoder = new GifEncoder(img, out, false); encoder.setColorModel(ColorModel.getRGBdefault()); encoder.encode(); gr.clearRect(-x_position, -y_position, image_width, image_height); //gr.clearRect(-x_position, -y_position, (int)(image_width/scale_x_axis), (int)(image_height/scale_y_axis)); //gr.clearRect(-x_position, -y_position, (int)((-x_position - image_width)/scale_x_axis), (int)((-y_position - image_height)/scale_y_axis)); gr.translate(-x_position, -y_position); if(dx == 0){ dx = -image_width; } x_position += dx; out.flush(); out.close(); fo = null; out = null; progressBar.setValue(++count); label.setText("Generate GIF files, " + ((count*100)/images_nbr) + "% ready ..."); } catch (Throwable t) { message = Toolz.getStackTrace(t); if (fo != null) { try { fo.close(); } catch (IOException io) { message += "\n\n" + Toolz.getStackTrace(io); } } } } sb.append("\n</tr>"); } sb.append("\n</table>\n</body>\n</html>"); label.setText(message); try { f = new File(f.getParentFile(), prefix + ".html"); fo = new FileOutputStream(f); out = new BufferedOutputStream(fo); out.write(sb.toString().getBytes()); out.flush(); out.close(); dialog.setVisible(false); dialog.dispose(); } catch (Exception e) { message = Toolz.getStackTrace(e); if (fo != null) { try { fo.close(); } catch (IOException io) { message += "\n\n" + Toolz.getStackTrace(io); } } } if(messageThread!=null){ messageThread = null; } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 2735 | andrei_loskutov | sources are now included to binary distribution at http://andrei.gmxhome.de/perforce/index.html | ||
#3 | 2554 | andrei_loskutov |
#25.12.2002 23:29 Revision 1.3.0.4 beta 1) Some small refactoring 2) First integration with P4eclipse: properties etc, thanks Boris Pr�ssmann 5) Better integration to Eclipse: use Eclipse internal compare tool for diff. 6) Fix some minor bugs. #14.12.2002 23:15 Revision 1.3.0.3 beta 1) Fix endless loop bug if p4 path was not set. 2) Fix never getting focus bug after error message shown 3) Fix painting bug on JDK 1.4.1 (must be verified!!!) 4) Some small refactoring 5) Fix error handling. 6) Fix some minor bugs. |
||
#2 | 2552 | andrei_loskutov | 1.3.0.4 changes | ||
#1 | 2460 | andrei_loskutov |
1) Change configuration: always reed properties 2) Change password store to hex format/password field 3) Create standalone/not standalone state for new branchview eclipse wrapper 4) Refactor all main classes to remove cyclic package dependency 5) Add workaround to fix new JDK 1.4.1 Swing bugs on JScrollPane/JViewPort 6) Add dispose methods to panel/connector 7) Minor internal GUI fixes/refactorings |