|
What this is
Other links
The source code// $Id: ProjectBrowser.java,v 1.134 2004/09/28 19:45:06 mvw Exp $ // Copyright (c) 1996-2004 The Regents of the University of California. All // Rights Reserved. Permission to use, copy, modify, and distribute this // software and its documentation without fee, and without a written // agreement is hereby granted, provided that the above copyright notice // and this paragraph appear in all copies. This software program and // documentation are copyrighted by The Regents of the University of // California. The software program and documentation are supplied "AS // IS", without any accompanying services from The Regents. The Regents // does not warrant that the operation of the program will be // uninterrupted or error-free. The end-user understands that the program // was developed for research purposes and is advised not to rely // exclusively on the program for any reason. IN NO EVENT SHALL THE // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. package org.argouml.ui; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.HashMap; import java.util.Iterator; import java.util.Locale; import java.util.Map; import java.util.Vector; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JMenuBar; import javax.swing.JPanel; import org.argouml.application.api.Argo; import org.argouml.application.api.Configuration; import org.argouml.application.events.ArgoModuleEvent; import org.argouml.application.helpers.ResourceLoaderWrapper; import org.argouml.cognitive.Designer; import org.argouml.cognitive.ui.TabToDo; import org.argouml.cognitive.ui.ToDoPane; import org.argouml.i18n.Translator; import org.argouml.kernel.Project; import org.argouml.kernel.ProjectManager; import org.argouml.swingext.BorderSplitPane; import org.argouml.swingext.Horizontal; import org.argouml.swingext.Orientation; import org.argouml.swingext.Vertical; import org.argouml.ui.cmd.GenericArgoMenuBar; import org.argouml.ui.targetmanager.TargetEvent; import org.argouml.ui.targetmanager.TargetListener; import org.argouml.ui.targetmanager.TargetManager; import org.argouml.uml.ui.ActionExit; import org.argouml.uml.ui.TabProps; import org.tigris.gef.base.Diagram; import org.tigris.gef.ui.IStatusBar; import org.tigris.gef.util.VectorSet; import org.tigris.toolbar.layouts.DockBorderLayout; /** The main window of the ArgoUML application. * * @stereotype singleton */ public class ProjectBrowser extends JFrame implements IStatusBar, PropertyChangeListener, TargetListener { private static final String BUNDLE = "statusmsg"; /** Default width: DEFAULT_COMPONENTWIDTH */ public static final int DEFAULT_COMPONENTWIDTH = 220; /** Default height: DEFAULT_COMPONENTHEIGHT */ public static final int DEFAULT_COMPONENTHEIGHT = 200; //////////////////////////////////////////////////////////////// // class variables /** * Member attribute to contain the singleton. */ private static ProjectBrowser theInstance; private static boolean showSplashScreen = false; // ----- diagrams //////////////////////////////////////////////////////////////// // instance variables private String appName = "ProjectBrowser"; private MultiEditorPane editorPane; /* Work in progress here to allow multiple details panes with ** different contents - Bob Tarling */ private DetailsPane northEastPane; private DetailsPane northPane; private DetailsPane northWestPane; private JPanel westPane; private DetailsPane eastPane; private DetailsPane southEastPane; private JPanel southWestPane; private DetailsPane southPane; private Map detailsPanesByCompassPoint = new HashMap(); private GenericArgoMenuBar menuBar; /** * Partially implemented. Needs work to display * import of source and saving of zargo. */ private StatusBar statusBar = new StatusBar(); /** this needs work so that users can set the font * size through a gui preference window */ private Font defaultFont = new Font("Dialog", Font.PLAIN, 10); private BorderSplitPane workAreaPane; /** * The splash screen shown at startup */ private SplashScreen splashScreen; /** * The explorer (formerly called navigator) pane * containing the modelstructure. */ private NavigatorPane explorerPane; /** * The todopane (lower left corner of screen) */ private ToDoPane todoPane; /** * For testing purposes. In tests this constructor can be called so * TheInstance is filled. */ private ProjectBrowser() { this("ArgoUML", false); } /** * The constructor. * * @param applicationName the title of the frame * @param doSplash determines if we have to show * the splash screen at startup */ private ProjectBrowser(String applicationName, boolean doSplash) { super(applicationName); theInstance = this; SplashScreen.setDoSplash(doSplash); if (doSplash) { splashScreen = SplashScreen.getInstance(); splashScreen.getStatusBar().showStatus( Translator.localize(BUNDLE, "statusmsg.bar.making-project-browser")); splashScreen.getStatusBar().showProgress(10); splashScreen.setVisible(true); } menuBar = new GenericArgoMenuBar(); editorPane = new MultiEditorPane(); getContentPane().setFont(defaultFont); getContentPane().setLayout(new BorderLayout()); this.setJMenuBar(menuBar); //getContentPane().add(_menuBar, BorderLayout.NORTH); getContentPane().add(createPanels(doSplash), BorderLayout.CENTER); getContentPane().add(statusBar, BorderLayout.SOUTH); setAppName(applicationName); // allows me to ask "Do you want to save first?" setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowCloser()); ImageIcon argoImage = ResourceLoaderWrapper.lookupIconResource("ArgoIcon"); this.setIconImage(argoImage.getImage()); // // adds this as listener to projectmanager so it gets updated when the // project changes ProjectManager.getManager().addPropertyChangeListener(this); // adds this as listener to TargetManager so gets notified // when the active diagram changes TargetManager.getInstance().addTargetListener(this); } /** * @see java.awt.Component#getLocale() */ public Locale getLocale() { return Locale.getDefault(); } /** * Creates the panels in the working area * * @param doSplash true if we show the splashscreen during startup * @return Component the area between the menu and the statusbar. * It contains the workarea at centre and the toolbar * position north, south, east or west. * */ protected Component createPanels(boolean doSplash) { if (doSplash) { splashScreen.getStatusBar().showStatus( Translator.localize(BUNDLE, "statusmsg.bar.making-project-browser-explorer")); splashScreen.getStatusBar().incProgress(5); } //_navPane = new NavigatorPane(doSplash); explorerPane = NavigatorPane.getInstance(); /* Work in progress here to allow multiple details panes with ** different contents - Bob Tarling */ eastPane = makeDetailsPane(BorderSplitPane.EAST, Vertical.getInstance()); southPane = makeDetailsPane(BorderSplitPane.SOUTH, Horizontal.getInstance()); southEastPane = makeDetailsPane(BorderSplitPane.SOUTHEAST, Horizontal.getInstance()); northWestPane = makeDetailsPane(BorderSplitPane.NORTHWEST, Horizontal.getInstance()); northPane = makeDetailsPane(BorderSplitPane.NORTH, Horizontal.getInstance()); northEastPane = makeDetailsPane(BorderSplitPane.NORTHEAST, Horizontal.getInstance()); if (southPane != null) { detailsPanesByCompassPoint.put(BorderSplitPane.SOUTH, southPane); } if (southEastPane != null) { detailsPanesByCompassPoint.put(BorderSplitPane.SOUTHEAST, southEastPane); } if (southWestPane != null) { detailsPanesByCompassPoint.put(BorderSplitPane.SOUTHWEST, southWestPane); } if (eastPane != null) { detailsPanesByCompassPoint.put(BorderSplitPane.EAST, eastPane); } if (westPane != null) { detailsPanesByCompassPoint.put(BorderSplitPane.WEST, westPane); } if (northWestPane != null) { detailsPanesByCompassPoint.put(BorderSplitPane.NORTHWEST, northWestPane); } if (northPane != null) { detailsPanesByCompassPoint.put(BorderSplitPane.NORTH, northPane); } if (northEastPane != null) { detailsPanesByCompassPoint.put(BorderSplitPane.NORTHEAST, northEastPane); } if (westPane != null) { detailsPanesByCompassPoint.put(BorderSplitPane.WEST, westPane); } if (southWestPane != null) { detailsPanesByCompassPoint.put(BorderSplitPane.SOUTHWEST, southWestPane); } // The workarea is all the visible space except the menu, // toolbar and status bar. Workarea is layed out as a // BorderSplitPane where the various components that make up // the argo application can be positioned. workAreaPane = new BorderSplitPane(); // create the todopane if (doSplash) { splashScreen.getStatusBar().showStatus(Translator.localize( "statusmsg.bar.making-project-browser-to-do-pane")); splashScreen.getStatusBar().incProgress(5); } todoPane = new ToDoPane(doSplash); restorePanelSizes(); // There are various details panes all of which could hold // different tabs pages according to users settings. // Place each pane in the required border area. Iterator it = detailsPanesByCompassPoint.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); String position = (String) entry.getKey(); if (entry.getValue() instanceof DetailsPane) { DetailsPane detailsPane = (DetailsPane) entry.getValue(); TargetManager.getInstance().addTargetListener(detailsPane); } workAreaPane.add((Component) entry.getValue(), position); } workAreaPane.add(explorerPane, BorderSplitPane.WEST); getTab(TabToDo.class); // TODO: If this doesn't have side effects, // it can be removed alltogether. //todo.setTree(_todoPane); workAreaPane.add(todoPane, BorderSplitPane.SOUTHWEST); workAreaPane.add(editorPane); // Toolbar boundry is the area between the menu and the status // bar. It contains the workarea at centre and the toolbar // position north, south, east or west. JPanel toolbarBoundry = new JPanel(); toolbarBoundry.setLayout(new DockBorderLayout()); // TODO: - should save and restore the last positions of the toolbars toolbarBoundry.add(menuBar.getFileToolbar(), BorderLayout.NORTH); toolbarBoundry.add(menuBar.getEditToolbar(), BorderLayout.NORTH); toolbarBoundry.add(menuBar.getViewToolbar(), BorderLayout.NORTH); toolbarBoundry.add(menuBar.getCreateDiagramToolbar(), BorderLayout.NORTH); toolbarBoundry.add(workAreaPane, BorderLayout.CENTER); return toolbarBoundry; } /** Set the size of each panel to that last saved in the configuration file */ private void restorePanelSizes() { if (northPane != null) { northPane.setPreferredSize( new Dimension(0, Configuration.getInteger( Argo.KEY_SCREEN_NORTH_HEIGHT, DEFAULT_COMPONENTHEIGHT))); } if (southPane != null) { southPane.setPreferredSize( new Dimension(0, Configuration.getInteger( Argo.KEY_SCREEN_SOUTH_HEIGHT, DEFAULT_COMPONENTHEIGHT))); } if (eastPane != null) { eastPane.setPreferredSize( new Dimension(Configuration.getInteger( Argo.KEY_SCREEN_EAST_WIDTH, DEFAULT_COMPONENTHEIGHT), 0)); } if (explorerPane != null) { explorerPane.setPreferredSize( new Dimension(Configuration.getInteger( Argo.KEY_SCREEN_WEST_WIDTH, DEFAULT_COMPONENTHEIGHT), 0)); } // if (_northWestPane != null) { // _northWestPane.setPreferredSize(new Dimension( // Configuration.getInteger( // Argo.KEY_SCREEN_NORTHWEST_WIDTH, DEFAULT_COMPONENTWIDTH), // Configuration.getInteger( // Argo.KEY_SCREEN_NORTH_HEIGHT, DEFAULT_COMPONENTHEIGHT) // )); // } // if (_todoPane != null) { // _todoPane.setPreferredSize(new Dimension( // Configuration.getInteger( // Argo.KEY_SCREEN_SOUTHWEST_WIDTH, DEFAULT_COMPONENTWIDTH), // Configuration.getInteger( // Argo.KEY_SCREEN_SOUTH_HEIGHT, DEFAULT_COMPONENTHEIGHT) // )); // } // if (_northEastPane != null) { // _northEastPane.setPreferredSize(new Dimension( // Configuration.getInteger( // Argo.KEY_SCREEN_NORTHEAST_WIDTH, DEFAULT_COMPONENTWIDTH), // Configuration.getInteger( // Argo.KEY_SCREEN_NORTH_HEIGHT, DEFAULT_COMPONENTHEIGHT) // )); // } // if (_southEastPane != null) { // _southEastPane.setPreferredSize(new Dimension( // Configuration.getInteger( // Argo.KEY_SCREEN_SOUTHEAST_WIDTH, DEFAULT_COMPONENTWIDTH), // Configuration.getInteger( // Argo.KEY_SCREEN_SOUTH_HEIGHT, DEFAULT_COMPONENTHEIGHT) // )); // } } //////////////////////////////////////////////////////////////// // accessors /** * @see java.awt.Frame#setTitle(java.lang.String) */ public void setTitle(String title) { if (title == null || "".equals(title)) { setTitle(getAppName()); } else { String changeIndicator = ProjectManager.getManager() .getCurrentProject().getSaveRegistry().hasChanged() ? " *" : ""; ArgoDiagram activeDiagram = ProjectManager.getManager() .getCurrentProject().getActiveDiagram(); if (activeDiagram != null) { super.setTitle(title + " - " + activeDiagram.getName() + " - " + getAppName() + changeIndicator); } else { super.setTitle(title + " - " + getAppName() + changeIndicator); } } } /** * Updates the window title to contain the latest values for * project name, active diagram, and save status. */ protected void updateTitle() { setTitle(ProjectManager.getManager().getCurrentProject().getName()); } /** * @return the application name as shown in the titlebar */ public String getAppName() { return appName; } /** * @param n the application name as shown in the titlebar */ public void setAppName(String n) { appName = n; } /** * The method used by the NavigatorPane, MultiEditor and DetailsPane * to set the target of the application. * * |
... this post is sponsored by my books ... | |
![]() #1 New Release! |
![]() FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.