/******************************* 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. ********************************************************************************/ package adiag.gui; import java.awt.Component; import java.awt.Dimension; import java.awt.Point; import java.awt.Toolkit; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.IOException; import java.util.Observable; import java.util.Observer; import java.util.Properties; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JViewport; import javax.swing.UIManager; import adiag.connection.Configuration; import adiag.connection.Connector; import adiag.model.BVException; import adiag.model.Version; import adiag.view.Toolz; /** * The Applications-window with single view of P4 versions and capability to * maintain configuration file * @author Andrei Loskutov */ public class App extends JFrame implements Observer { private Configuration conf; /** error description, for start/init problems */ private String start_error; /** default view dimension */ private Dimension start_dimension = new Dimension(300, 300); /** the initial path to requested file(s) from Perforce - repository */ private String path; /** scroll pane with current view */ private JScrollPane scroll; /** Number of simultaneously opened windows */ private static int instanceNumber; private static boolean standalone; private boolean initialized; protected ViewPanel curr_view; public static String APP_NAME = "BranchViewApp"; /** frame icon source as p4 logo image (orange/yellow) */ public static final byte[] LOGO = new byte[] { 71,73,70,56,57,97,16,0,16,0,-94,4,0,-1,-74,0,-1,-1,-1,0,0,0,-128,91,0,-52,-52,-52,0,0, 0,0,0,0,0,0,0,33,-7,4,1,0,0,4,0,44,0,0,0,0,16,0,16,0,0,3,67,72,-70,-36,-2,45,-56, 25,20,29,22,-24,45,72,-40,-104,-89,9,31,64,110,64,88,-98,102,-87,-87,-29,-22,-90, 89,59,-94,-76,-120,-105,-60,91,-89,-125,83,-25,85,113,117,74,18,-112,-50,-76,68,97, -116,4,-127,84,-6,58,14,-82,29,-58,-11,10,-23,122,29,9,0,59 }; /** frame icon as p4 logo image (orange/yellow) */ public static final ImageIcon ICON = new ImageIcon(LOGO); static { try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception e) { e.printStackTrace(); } } /** * Default-Constructor. */ public App() { super(); instanceNumber ++; try { conf = new Configuration(); conf.addObserver(this); } catch (BVException e) { this.error("Initialisation error: ", e); } this.setName(APP_NAME); } /** * Default-Constructor. */ public App(String [] args) { this(); initFrame(args); Configuration.setRunMode(Configuration.RUN_MODE_STANDALONE); } /** * Default-Constructor. */ public App(Properties props) { instanceNumber ++; try { conf = new Configuration(props); conf.addObserver(this); Configuration.setRunMode(Configuration.RUN_MODE_PLUGIN_P4ECLIPSE); } catch (BVException e) { this.error("Initialisation error: ", e); } this.setName(APP_NAME); String file = conf.getPath(); initFrame(new String [] { file }); } /** * Starts the application. * @param args an array of command-line arguments, see online help */ public static void main(String[] args) { new App(args); standalone = true; } /** * Suspend application, run finalisation etc */ public void suspendFrame() { if(conf != null){ try { Configuration.storeProperties(); } catch (BVException ee) { error("Cannot write properties:\n" + ee.getMessage(), ee); } } if(standalone){ System.exit(0); return; } setVisible(false); if(scroll != null){ this.setContentPane(new JPanel()); scroll = null; } if(curr_view != null){ curr_view.dispose(); curr_view = null; } if(conf != null){ conf.setConnector(null); } System.runFinalization(); System.gc(); } /** * Init application * @param args command-line arguments, see online help */ public void initFrame(String[] args) { setIconImage(ICON.getImage()); this.setState(JFrame.ICONIFIED); try { start_error = conf.parseParameter(args); //if(curr_view == null){ curr_view = new ViewPanel(conf); scroll = new JScrollPane(curr_view); if(Toolz.isVmOk()){ /// this is feature of JDK >= 1.3 try{ //scroll.getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE); //scroll.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE); scroll.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); //scroll.getViewport().setOpaque(false); } catch (Exception e){} } //} curr_view.setData(conf.getConnector().getData()); } catch (Exception e) { // show error message in pane scroll = catchInitException(e); if(Toolz.isVmOk()){ /// this is feature of JDK >= 1.3 try{ //scroll.getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE); //scroll.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE); scroll.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); //scroll.getViewport().setOpaque(false); } catch (Exception ee){} } if(start_error != null){ start_error += "\nError:\n" + e.getMessage(); } else { start_error = "Error:\n" + e.getMessage(); } } this.setContentPane(scroll); // only if first time started if(!initialized){ addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { Connector c = conf.getConnector(); if (c != null) { try { if (conf.isDebug() && !conf.isOffline()) { try { Toolz.write(c.dataToString(), c.getLogFile()); } catch (Exception ee) { error("Cannot write log file:\n" + ee.getMessage(), ee); } } c.close(); } catch (IOException ioe) { error("Cannot close connector:\n" + ioe.getMessage(), ioe); } } instanceNumber --; if(instanceNumber <=0){ // last window suspendFrame(); } }; }); } initialized = true; restart(); } private void restart() { if(curr_view != null){ setBestAppSizeAndLocation(curr_view.getPreferredSize()); } else { setBestAppSizeAndLocation(start_dimension); } this.setState(JFrame.NORMAL); pack(); try{ show(); setVisible(true); repaint(); } catch (Throwable e){ // sometimes happend.... e.printStackTrace(); scroll = catchInitException(e); this.setContentPane(scroll); setBestAppSizeAndLocation(start_dimension); show(); setVisible(true); repaint(); } if(start_error!= null){ this.error(start_error, null); start_error = null; } curr_view.requestFocus(); } /** * set best (calculated ;) ) size and location of window * @param viewSize the size of view */ public void setBestAppSizeAndLocation(Dimension viewSize) { Dimension screen_dim = Toolkit.getDefaultToolkit().getScreenSize(); //Dimension screen_dim = new Dimension(300,300); Dimension current_dim = getSize(); // small space from left/top of screen int margin_left = 60; int margin_top = 60; double width = screen_dim.getWidth(); double height = screen_dim.getHeight(); double v_w = viewSize.getWidth(); double v_h = viewSize.getHeight(); height -= margin_top * 2; width -= margin_left * 2; // not to small size! if (v_h > margin_top && v_h < height) { height = v_h + margin_top/2; } else if (v_h < margin_top) { height = margin_top; } if (v_w < width && v_w > margin_left) { width = v_w + margin_left/2; } else if( v_w < margin_left) { width = margin_left; } if (Math.abs(current_dim.getHeight() - height) > margin_top || Math.abs(current_dim.getWidth() - width) > margin_left) { Dimension dim = new Dimension((int) width, (int) height); if (scroll != null) { //scroll.setSize(dim); scroll.setPreferredSize(dim); //scroll.getViewport().setViewSize(dim); } setSize( new Dimension((int) width + 20, (int) height + 20)); pack(); Point newLocation = new Point(margin_left, margin_top); Point p = this.getLocation(); if (!isVisible() || p.getX() + width > screen_dim.getWidth() || p.getY() + height > screen_dim.getHeight()) { setLocation(newLocation); } } } /** * Show start errors * @param e error * @return JScrollPane with error description */ private JScrollPane catchInitException(Throwable e) { JScrollPane scroll = null; Connector c = conf.getConnector(); try { if (c != null) { c.close(); } } catch (IOException ioe) { if(conf.isDebug()){ ioe.printStackTrace(); } } ViewPanel ta = null; try { ta = new ViewPanel(new Version[0], conf); scroll = new JScrollPane(ta); } catch (BVException ex) { setTitle("Error: " + e.getMessage()); if(conf.isDebug()){ ex.printStackTrace(); } scroll = new JScrollPane(); } return scroll; } /** * Set current path to retrieve data from P4 * @param newpath the current path to P4 file */ public void setPath(String newpath) { this.path = newpath; if(conf.isOffline()){ this.setTitle("Offline: " + conf.getConnector().getLogFile().getAbsolutePath()); } else { this.setTitle(path); } } /** * Show error dialog * @param message error description for user * @param error error instance or null */ public void error(String message, Throwable error) { Component parent = curr_view; if(parent == null){ parent = this; } JOptionPane.showMessageDialog(this, message, "Error!", JOptionPane.ERROR_MESSAGE); if(error != null && conf.isDebug()){ error.printStackTrace(); } setVisible(true); //requestFocus(); parent.requestFocus(); } /** * Show yes/no dialog * @param message description for user * @return user choice, true for "yes", false elsewhere */ public boolean yesno(String message) { Object[] options = { "yes", "no" }; int a = JOptionPane.showOptionDialog( this, message, "Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, null); return a == JOptionPane.YES_OPTION; } /* (non-Javadoc) * @see java.util.Observer#update(Observable, Object) */ public void update(Observable o, Object arg) { if(o instanceof Configuration){ this.setPath("" + arg); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 2735 | andrei_loskutov | sources are now included to binary distribution at http://andrei.gmxhome.de/perforce/index.html | ||
#4 | 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. |
||
#3 | 2552 | andrei_loskutov | 1.3.0.4 changes | ||
#2 | 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 |
||
#1 | 2222 | andrei_loskutov |
#13.10.2002 22:16 Revision 1.2.1 1) Documentation task is finished... Yes!!! 2) New feature: copy P4 depot path 3) Some small fixes to menu shortkeys belongs ctrl + c and ctrl + d 4) Clipboard fix because of JDK 1.2 - 1.3 bug 5) Smallest refactoring on some methods. 6) Html help updated |