Author: jm
Date: 2012-01-02 13:24:48 -0800 (Mon, 02 Jan 2012)
New Revision: 27895

Added:
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/AboutDialogTask.java
Modified:
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/AboutDialogFactoryImpl.java
Log:
Fixes #498: Updated Mac-specific menus with correct version and icon


Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
       2012-01-02 19:41:44 UTC (rev 27894)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
       2012-01-02 21:24:48 UTC (rev 27895)
@@ -50,6 +50,7 @@
 import org.cytoscape.application.CyApplicationConfiguration;
 import org.cytoscape.application.CyApplicationManager;
 import org.cytoscape.application.CyShutdown;
+import org.cytoscape.application.CyVersion;
 import org.cytoscape.application.events.CyShutdownListener;
 import org.cytoscape.application.events.SetCurrentNetworkViewListener;
 import org.cytoscape.application.swing.CyAction;
@@ -118,16 +119,19 @@
 import org.cytoscape.view.presentation.RenderingEngineFactory;
 import org.cytoscape.view.vizmap.VisualMappingManager;
 import org.cytoscape.work.TaskFactory;
+import org.cytoscape.work.TaskManager;
 import org.cytoscape.work.swing.DialogTaskManager;
 import org.cytoscape.work.swing.PanelTaskManager;
 import org.cytoscape.work.swing.SubmenuTaskManager;
 import org.cytoscape.work.swing.undo.SwingUndoSupport;
 import org.osgi.framework.BundleContext;
 
+import com.apple.eawt.AboutHandler;
+import com.apple.eawt.AppEvent.AboutEvent;
+import com.apple.eawt.AppEvent.QuitEvent;
 import com.apple.eawt.Application;
 import com.apple.eawt.QuitHandler;
 import com.apple.eawt.QuitResponse;
-import com.apple.eawt.AppEvent.QuitEvent;
 
 /**
  *
@@ -200,7 +204,6 @@
                                                                                
              propertyWriterManagerRef,
                                                                                
              cyApplicationConfigurationServiceRef);
                CyHelpBrokerImpl cyHelpBroker = new CyHelpBrokerImpl();
-               AboutDialogFactoryImpl aboutDialogFactory = new 
AboutDialogFactoryImpl(openBrowserServiceRef);
                PreferencesDialogFactoryImpl preferencesDialogFactory = new 
PreferencesDialogFactoryImpl(cyEventHelperServiceRef);
                BookmarkDialogFactoryImpl bookmarkDialogFactory = new 
BookmarkDialogFactoryImpl(bookmarkServiceRef,
                                                                                
                bookmarksUtilServiceRef);
@@ -276,6 +279,9 @@
                                                                                
     sessionReaderManagerServiceRef,
                                                                                
     cyApplicationManagerServiceRef);
                
+               CyVersion version = getService(bc, CyVersion.class);
+               AboutDialogFactoryImpl aboutDialogFactory = new 
AboutDialogFactoryImpl(version);
+               
                // Show Welcome Screen
                final WelcomeScreenAction welcomeScreenAction = new 
WelcomeScreenAction(bc,cytoscapeDesktop, openBrowserServiceRef, 
recentlyOpenedTrackerServiceRef, openSessionTaskFactory, 
submenuTaskManagerServiceRef, importNetworkFileTF, importNetworkTF, 
createNetworkViewTaskFactory, cyApplicationConfigurationServiceRef, 
dsManagerServiceRef, cytoscapePropertiesServiceRef);
                registerAllServices(bc, welcomeScreenAction, new Properties());
@@ -292,7 +298,7 @@
                registerService(bc, cytoPanelSouthWestAction, CyAction.class, 
new Properties());
 
                if (isMac()) {
-                       registerMacExitHandler(cytoscapeShutdownServiceRef);
+                       registerMacMenuHandlers(cytoscapeShutdownServiceRef, 
submenuTaskManagerServiceRef, aboutDialogFactory);
                } else {
                        registerService(bc, exitAction, CyAction.class, new 
Properties());
                }
@@ -403,7 +409,7 @@
                                        CyLayoutAlgorithm.class);
        }
 
-       private void registerMacExitHandler(final CyShutdown shutdown) {
+       private void registerMacMenuHandlers(final CyShutdown shutdown, final 
TaskManager<?, ?> taskManager, final TaskFactory aboutTaskFactory) {
                Application application = Application.getApplication();
                application.setQuitHandler(new QuitHandler() {
                        @Override
@@ -411,6 +417,12 @@
                                shutdown.exit(0);
                        }
                });
+               application.setAboutHandler(new AboutHandler() {
+                       @Override
+                       public void handleAbout(AboutEvent event) {
+                               taskManager.execute(aboutTaskFactory);
+                       }
+               });
        }
 
        private boolean isMac() {

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-01-02 19:41:44 UTC (rev 27894)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/AboutDialogFactoryImpl.java
    2012-01-02 21:24:48 UTC (rev 27895)
@@ -35,24 +35,19 @@
 */
 package org.cytoscape.internal.dialogs;
 
-import java.awt.Window;
+import org.cytoscape.application.CyVersion;
+import org.cytoscape.work.TaskFactory;
+import org.cytoscape.work.TaskIterator;
 
-import org.cytoscape.util.swing.OpenBrowser;
+public class AboutDialogFactoryImpl implements TaskFactory {
+       private CyVersion version;
 
-/**
- */
-public class AboutDialogFactoryImpl {
-
-       private OpenBrowser ob;
-
-       public AboutDialogFactoryImpl(OpenBrowser ob) { 
-               if ( ob == null )
-                       throw new NullPointerException("open browser class is 
null!");
-               else 
-                       this.ob = ob;
+       public AboutDialogFactoryImpl(CyVersion version) {
+               this.version = version;
        }
-
-       public AboutDialogImpl getAboutDialog(Window parent, boolean modal) {
-               return new AboutDialogImpl(parent,modal,ob);
+       
+       @Override
+       public TaskIterator createTaskIterator() {
+               return new TaskIterator(new AboutDialogTask(version));
        }
 }

Added: 
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
                           (rev 0)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/AboutDialogTask.java
   2012-01-02 21:24:48 UTC (rev 27895)
@@ -0,0 +1,73 @@
+package org.cytoscape.internal.dialogs;
+
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JRootPane;
+
+import org.cytoscape.application.CyVersion;
+import org.cytoscape.work.Task;
+import org.cytoscape.work.TaskMonitor;
+
+public class AboutDialogTask implements Task {
+
+       private CyVersion version;
+
+       public AboutDialogTask(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);
+               
+               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));
+               
+               dialog.pack();
+               Dimension size = dialog.getSize();
+               dialog.setSize(size.width * 2, size.height);
+               
+               dialog.setLocationRelativeTo(null);
+               dialog.setVisible(true);
+       }
+
+       @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