Author: clopes
Date: 2012-11-01 14:53:35 -0700 (Thu, 01 Nov 2012)
New Revision: 30729

Modified:
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/AboutDialogFactoryImpl.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/AboutDialogTask.java
Log:
Fixes #1557 (More than one About dialog open at a time)

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/AboutDialogFactoryImpl.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/AboutDialogFactoryImpl.java
    2012-11-01 18:55:20 UTC (rev 30728)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/AboutDialogFactoryImpl.java
    2012-11-01 21:53:35 UTC (rev 30729)
@@ -40,14 +40,21 @@
 import org.cytoscape.work.TaskIterator;
 
 public class AboutDialogFactoryImpl extends AbstractTaskFactory {
-       private CyVersion version;
+       
+       private final CyVersion version;
+       private AboutDialogTask task;
 
-       public AboutDialogFactoryImpl(CyVersion version) {
+       public AboutDialogFactoryImpl(final CyVersion version) {
                this.version = version;
        }
        
        @Override
        public TaskIterator createTaskIterator() {
-               return new TaskIterator(new AboutDialogTask(version));
+               synchronized (this) {
+                       if (task == null)
+                               task = new AboutDialogTask(version);
+               }
+               
+               return new TaskIterator(task);
        }
 }

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/AboutDialogTask.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/AboutDialogTask.java
   2012-11-01 18:55:20 UTC (rev 30728)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/AboutDialogTask.java
   2012-11-01 21:53:35 UTC (rev 30729)
@@ -20,54 +20,60 @@
 
 public class AboutDialogTask implements Task {
 
-       private CyVersion version;
+       private final CyVersion version;
+       private JDialog dialog;
 
-       public AboutDialogTask(CyVersion version) {
+       public AboutDialogTask(final CyVersion version) {
                this.version = version;
        }
        
        @Override
-       public void run(TaskMonitor taskMonitor) throws Exception {
-               final JDialog dialog = new JDialog();
-               dialog.setTitle("About Cytoscape");
-               dialog.setResizable(false);
+       public synchronized void run(final TaskMonitor taskMonitor) throws 
Exception {
+               if (dialog == null) {
+                       dialog = new JDialog();
+                       dialog.setTitle("About Cytoscape");
+                       dialog.setResizable(false);
+                       
+                       JRootPane pane = dialog.getRootPane();
+                       pane.setLayout(new GridBagLayout());
+                       
+                       ImageIcon icon = new 
ImageIcon(getClass().getClassLoader().getResource("images/logo.png"));
+                       JLabel iconLabel = new JLabel(icon);
+                       
+                       JLabel productLabel = new JLabel("Cytoscape", 
JLabel.CENTER);
+                       Font font = productLabel.getFont();
+                       productLabel.setFont(font.deriveFont(Font.BOLD, (int) 
(font.getSize() * 2)));
+                       
+                       JLabel versionLabel = new JLabel(String.format("Version 
%s", version.getVersion()), JLabel.CENTER);
+                       
+                       JButton okButton = new JButton("OK");
+                       okButton.addActionListener(new ActionListener() {
+                               @Override
+                               public void actionPerformed(ActionEvent e) {
+                                       dialog.setVisible(false);
+                               }
+                       });
+                       
+                       pane.setDefaultButton(okButton);
+                       pane.add(iconLabel, new GridBagConstraints(0, 0, 1, 1, 
0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 
0), 0, 0));
+                       pane.add(productLabel, new GridBagConstraints(0, 1, 1, 
1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 
0, 0), 0, 0));
+                       pane.add(versionLabel, new GridBagConstraints(0, 2, 1, 
1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 
0, 0), 0, 0));
+                       pane.add(okButton, new GridBagConstraints(0, 3, 1, 1, 
1, 0, GridBagConstraints.LINE_END, GridBagConstraints.NONE, new Insets(0, 0, 0, 
0), 0, 0));
                
-               JRootPane pane = dialog.getRootPane();
-               pane.setLayout(new GridBagLayout());
+                       dialog.pack();
+                       final Dimension size = dialog.getSize();
+                       dialog.setSize(size.width * 2, size.height);
+               }
                
-               ImageIcon icon = new 
ImageIcon(getClass().getClassLoader().getResource("images/logo.png"));
-               JLabel iconLabel = new JLabel(icon);
-               
-               JLabel productLabel = new JLabel("Cytoscape", JLabel.CENTER);
-               Font font = productLabel.getFont();
-               productLabel.setFont(font.deriveFont(Font.BOLD, (int) 
(font.getSize() * 2)));
-               
-               JLabel versionLabel = new JLabel(String.format("Version %s", 
version.getVersion()), JLabel.CENTER);
-               
-               JButton okButton = new JButton("OK");
-               okButton.addActionListener(new ActionListener() {
-                       @Override
-                       public void actionPerformed(ActionEvent e) {
-                               dialog.setVisible(false);
-                       }
-               });
-               
-               pane.setDefaultButton(okButton);
-               pane.add(iconLabel, new GridBagConstraints(0, 0, 1, 1, 0, 0, 
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 
0));
-               pane.add(productLabel, new GridBagConstraints(0, 1, 1, 1, 0, 0, 
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 
0));
-               pane.add(versionLabel, new GridBagConstraints(0, 2, 1, 1, 0, 0, 
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 
0));
-               pane.add(okButton, new GridBagConstraints(0, 3, 1, 1, 1, 0, 
GridBagConstraints.LINE_END, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 
0, 0));
-               
-               dialog.pack();
-               Dimension size = dialog.getSize();
-               dialog.setSize(size.width * 2, size.height);
-               
-               dialog.setLocationRelativeTo(null);
-               dialog.setVisible(true);
+               if (!dialog.isVisible()) {
+                       dialog.setLocationRelativeTo(null);
+                       dialog.setVisible(true);
+               } else {
+                       dialog.toFront();
+               }
        }
 
        @Override
        public void cancel() {
        }
-
 }

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to