From: <sh...@us...> - 2008-11-27 10:43:57
|
Revision: 13331 http://cdk.svn.sourceforge.net/cdk/?rev=13331&view=rev Author: shk3 Date: 2008-11-27 10:43:52 +0000 (Thu, 27 Nov 2008) Log Message: ----------- added the exit action Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/JCPToolBar.java jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeModeAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties Added Paths: ----------- jchempaint/trunk/src/main/org/openscience/jchempaint/action/ExitAction.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JCPToolBar.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JCPToolBar.java 2008-11-27 09:27:09 UTC (rev 13330) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JCPToolBar.java 2008-11-27 10:43:52 UTC (rev 13331) @@ -252,7 +252,7 @@ if (toolKeys[i].equals("bond") && !elementtype) { button.setBackground(Color.GRAY); - chemPaintPanel.setActionButton(button); + chemPaintPanel.setLastActionButton(button); chemPaintPanel.get2DHub().setActiveDrawModule(new AddBondModule(chemPaintPanel.get2DHub())); } else { Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java 2008-11-27 09:27:09 UTC (rev 13330) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/JChemPaintPanel.java 2008-11-27 10:43:52 UTC (rev 13331) @@ -32,11 +32,12 @@ import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; import java.io.File; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; -import javax.swing.JApplet; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JMenuBar; @@ -53,27 +54,33 @@ public class JChemPaintPanel extends JPanel implements IChemObjectListener { - RenderPanel p; - + private RenderPanel renderPanel; private JComponent lastActionButton; - private File currentWorkDirectory; - private File lastOpenedFile; - private FileFilter currentOpenFileFilter; - private File isAlreadyAFile; private boolean isModified=false; - private FileFilter currentSaveFileFilter; private JCPStatusBar statusBar; + public static List<JChemPaintPanel> instances = new ArrayList<JChemPaintPanel>(); - public static List<JChemPaintPanel> instances = new ArrayList<JChemPaintPanel>(); - public JComponent getActionButton() { + /** + * Helps in keeping the current action button highlighted + * + * @return The last action button used + */ + public JComponent getLastActionButton() { return lastActionButton; } - public void setActionButton(JComponent actionButton) { + + /** + * Helps in keeping the current action button highlighted - needs to be set + * if a new action button is choosen + * + * @param actionButton The new action button + */ + public void setLastActionButton(JComponent actionButton) { lastActionButton = actionButton; } @@ -173,30 +180,46 @@ return isAlreadyAFile; } - public JChemPaintPanel(IChemModel ac, String gui){ + /** + * Builds a JCPPanel with a certain model and a certain gui + * + * @param chemModel The model + * @param gui The gui string + */ + public JChemPaintPanel(IChemModel chemModel, String gui){ this.setLayout(new BorderLayout()); JMenuBar menu = new JChemPaintMenuBar(this, gui); JPanel topContainer = new JPanel(new BorderLayout()); topContainer.setLayout(new BorderLayout()); this.add(topContainer,BorderLayout.NORTH); topContainer.add(menu,BorderLayout.NORTH); - p = new RenderPanel(ac); - this.add(p,BorderLayout.CENTER); + renderPanel = new RenderPanel(chemModel); + this.add(renderPanel,BorderLayout.CENTER); JToolBar toolbar = JCPToolBar.getToolbar(this, 1); topContainer.add(toolbar,BorderLayout.CENTER); statusBar=new JCPStatusBar(); this.add(statusBar,BorderLayout.SOUTH); instances.add(this); - ac.addListener(this); + chemModel.addListener(this); } + /** + * Return the ControllerHub of this JCPPanel + * + * @return The ControllerHub + */ public ControllerHub get2DHub() { - return p.getHub(); + return renderPanel.getHub(); } + /** + * Shows a warning if the JCPPanel has unsaved content and does save, if the user wants to do it. + * + * @return OptionPane.YES_OPTION/OptionPane.NO_OPTION/OptionPane.CANCEL_OPTION + */ public int showWarning() { if (isModified){ //TODO && !getIsOpenedByViewer() && !guiString.equals("applet")) { - int answer = JOptionPane.showConfirmDialog(this, p.getChemModel().getID() + " " + JCPLocalizationHandler.getInstance().getString("warning"), JCPLocalizationHandler.getInstance().getString("warningheader"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); + int answer = JOptionPane.showConfirmDialog(this, renderPanel.getChemModel().getID() + " " + JCPLocalizationHandler.getInstance().getString("warning"), JCPLocalizationHandler.getInstance().getString("warningheader"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (answer == JOptionPane.YES_OPTION) { new SaveAction(this, false).actionPerformed(new ActionEvent(this, 12, "")); } @@ -229,7 +252,7 @@ * closing Event. Shows a warning if this window has unsaved data and * terminates jvm, if last window. * - *@param e Description of the Parameter + * @param e Description of the Parameter */ public void windowClosing(WindowEvent e) { JFrame rootFrame = (JFrame) e.getSource(); @@ -240,7 +263,7 @@ int clear = ((JChemPaintPanel) ((JFrame) e.getSource()).getContentPane().getComponents()[0]).showWarning(); if (JOptionPane.CANCEL_OPTION != clear) { for (int i = 0; i < instances.size(); i++) { - if (((JPanel)instances.get(i)).getParent().getParent().getParent().getParent() == (JFrame)e.getSource()) { + if (instances.get(i).getParent().getParent().getParent().getParent() == (JFrame)e.getSource()) { instances.remove(i); break; } @@ -254,14 +277,22 @@ } } + /** + * Return the chemmodel of this JCPPanel + * + * @return + */ public IChemModel getChemModel(){ - return p.getChemModel(); + return renderPanel.getChemModel(); } + /* (non-Javadoc) + * @see org.openscience.cdk.interfaces.IChemObjectListener#stateChanged(org.openscience.cdk.interfaces.IChemObjectChangeEvent) + */ public void stateChanged(IChemObjectChangeEvent event) { isModified=true; if(this.getParent().getParent().getParent().getParent() instanceof JFrame) - ((JFrame)this.getParent().getParent().getParent().getParent()).setTitle(p.getChemModel().getID()+"*"); + ((JFrame)this.getParent().getParent().getParent().getParent()).setTitle(renderPanel.getChemModel().getID()+"*"); /* TODO gives concurrent access problems if (this.getChemModel() != null) { for (int i = 0; i < 3; i++) { String status = p.getStatus(i); @@ -273,4 +304,19 @@ } }*/ } + + + /** + * Closes all currently opened JCP instances. + */ + public static void closeAllInstances() { + Iterator<JChemPaintPanel> it = ((List<JChemPaintPanel>)((ArrayList<JChemPaintPanel>)instances).clone()).iterator(); + while (it.hasNext()) { + JFrame frame = (JFrame) it.next().getParent().getParent().getParent().getParent(); + WindowListener[] wls = (WindowListener[]) (frame.getListeners(WindowListener.class)); + wls[0].windowClosing(new WindowEvent(frame, 12)); + frame.setVisible(false); + frame.dispose(); + } + } } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeModeAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeModeAction.java 2008-11-27 09:27:09 UTC (rev 13330) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/ChangeModeAction.java 2008-11-27 10:43:52 UTC (rev 13331) @@ -120,9 +120,9 @@ hub.setActiveDrawModule(new AddAtomModule(hub)); hub.getController2DModel().setDrawElement(type); } - if (this.jcpPanel.getActionButton() != null) - this.jcpPanel.getActionButton().setBackground(Color.LIGHT_GRAY); - this.jcpPanel.setActionButton((JComponent) e.getSource()); + if (this.jcpPanel.getLastActionButton() != null) + this.jcpPanel.getLastActionButton().setBackground(Color.LIGHT_GRAY); + this.jcpPanel.setLastActionButton((JComponent) e.getSource()); ((JComponent) e.getSource()).setBackground(Color.GRAY); } Added: jchempaint/trunk/src/main/org/openscience/jchempaint/action/ExitAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/ExitAction.java (rev 0) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/ExitAction.java 2008-11-27 10:43:52 UTC (rev 13331) @@ -0,0 +1,55 @@ +/* + * $RCSfile$ + * $Author: egonw $ + * $Date: 2007-01-04 17:26:00 +0000 (Thu, 04 Jan 2007) $ + * $Revision: 7634 $ + * + * Copyright (C) 1997-2008 Stefan Kuhn + * + * Contact: cdk...@li... + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * All we ask is that proper credit is given for our work, which includes + * - but is not limited to - adding the above copyright notice to the beginning + * of your source code files, and to any copyright notice that you may distribute + * with programs based on this work. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.openscience.jchempaint.action; + +import java.awt.event.ActionEvent; + +import org.openscience.jchempaint.JChemPaintPanel; + + +/** + * Triggers an exit of the application + * + */ +public class ExitAction extends JCPAction +{ + + private static final long serialVersionUID = -7805547937237070627L; + + /** + * Opens an empty JChemPaint frame. + * + *@param e Description of the Parameter + */ + public void actionPerformed(ActionEvent e) + { + JChemPaintPanel.closeAllInstances(); + } +} + Property changes on: jchempaint/trunk/src/main/org/openscience/jchempaint/action/ExitAction.java ___________________________________________________________________ Added: svn:executable + * Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java 2008-11-27 09:27:09 UTC (rev 13330) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java 2008-11-27 10:43:52 UTC (rev 13331) @@ -29,15 +29,20 @@ package org.openscience.jchempaint.application; import java.awt.Dimension; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; +import java.util.Iterator; +import java.util.Vector; import javax.swing.JFrame; import javax.swing.JOptionPane; +import javax.swing.JPanel; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties 2008-11-27 09:27:09 UTC (rev 13330) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/resources/JChemPaintResources.properties 2008-11-27 10:43:52 UTC (rev 13331) @@ -84,7 +84,7 @@ compchemAction=org.openscience.cdk.applications.jchempaint.action.ExportCompChemAction printAction=org.openscience.cdk.applications.jchempaint.action.PrintAction closeAction=org.openscience.jchempaint.action.CloseAction -exitAction=org.openscience.cdk.applications.jchempaint.action.ExitAction +exitAction=org.openscience.jchempaint.action.ExitAction # Edit menu undoAction=org.openscience.cdk.applications.jchempaint.action.UndoAction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |