Author: ruschein
Date: 2010-08-16 15:47:56 -0700 (Mon, 16 Aug 2010)
New Revision: 21402

Modified:
   
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/GuiTunableInterceptor.java
Log:
Work in progress.

Modified: 
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/GuiTunableInterceptor.java
===================================================================
--- 
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/GuiTunableInterceptor.java
   2010-08-16 21:12:57 UTC (rev 21401)
+++ 
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/GuiTunableInterceptor.java
   2010-08-16 22:47:56 UTC (rev 21402)
@@ -9,12 +9,14 @@
 
 import javax.swing.BorderFactory;
 import javax.swing.BoxLayout;
+import javax.swing.JDialog;
 import javax.swing.JFrame;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.border.TitledBorder;
 
 import org.cytoscape.work.HandlerFactory;
+import org.cytoscape.work.TaskFactory;
 import org.cytoscape.work.TunableValidator;
 import org.cytoscape.work.Tunable.Param;
 import org.cytoscape.work.internal.tunables.utils.CollapsablePanel;
@@ -111,7 +113,14 @@
                this.objectsWithTunables = convertSpringProxyObjs(proxyObjs);
                handlers = new ArrayList<GUIHandler>();
                JPanel providedGUI = null;
+               int factoryCount = 0; // # of descendents of TaskFactory...
+               int otherCount = 0;   // ...everything else.  (Presumeably 
descendents of Task.)
                for (final Object objectWithTunables : objectsWithTunables) {
+                       if (objectWithTunables instanceof TaskFactory)
+                               ++factoryCount;
+                       else
+                               ++otherCount;
+
                        if (guiProviderMap.containsKey(objectWithTunables)) {
                                if (providedGUI != null)
                                        throw new IllegalStateException("Found 
more than one provided GUI!");
@@ -127,6 +136,17 @@
                                throw new IllegalArgumentException("No Tunables 
and no provided GUI exists for Object yet!");
                }
 
+               // Sanity check:
+               if (factoryCount > 0) {
+                       if (factoryCount != 1) {
+                               logger.error("More than one annotated 
TaskFactory found!");
+                               return false;
+                       } else if (otherCount != 0) {
+                               logger.error("Found annotated Task objects in 
addition to an annotated TaskFactory!");
+                               return false;
+                       }
+               }
+
                if (providedGUI != null) {
                        //if no parentPanel is defined, then create a new 
JDialog to display the Tunables' panels
                        if (parentPanel == null) {
@@ -152,7 +172,8 @@
                if (!panelMap.containsKey(handlers)) {
                        final String MAIN = " ";
                        Map<String, JPanel> panels = new HashMap<String, 
JPanel>();
-                       panels.put(MAIN, createJPanel(MAIN, null, null, 
Param.hidden));
+                       final JPanel topLevel = createSimplePanel(MAIN, null, 
Param.hidden);
+                       panels.put(MAIN, topLevel);
 
                        // construct the GUI
                        for (GUIHandler gh : handlers) {
@@ -178,8 +199,7 @@
                                if (group.length <= alignments.length) {
                                        for (int i = 0; i < group.length; i++)
                                                groupAlignment.put(group[i], 
alignments[i]);
-                               }
-                               else {
+                               } else {
                                        for (int i = 0; i < alignments.length; 
i++)
                                                groupAlignment.put(group[i], 
alignments[i]);
 
@@ -191,8 +211,7 @@
                                if (group.length <= titleFlags.length) {
                                        for (int i = 0; i < group.length; i++)
                                                groupTitles.put(group[i], 
titleFlags[i]);
-                               }
-                               else {
+                               } else {
                                        for (int i = 0; i < titleFlags.length; 
i++)
                                                groupTitles.put(group[i], 
titleFlags[i]);
 
@@ -251,7 +270,7 @@
         */
        private JPanel createJPanel(final String title, final GUIHandler gh, 
final Param alignment, final Param groupTitle) {
                if (gh == null)
-                       return getSimplePanel(title,alignment, groupTitle);
+                       return createSimplePanel(title, alignment, groupTitle);
 
                // See if we need to create an XOR panel
                if (gh.controlsMutuallyExclusiveNestedChildren()) {
@@ -267,11 +286,10 @@
                                        return new CollapsablePanel(title, 
true);
                        }
                        // We're not collapsable, so return a normal jpanel
-                       return getSimplePanel(title,alignment, groupTitle);
+                       return createSimplePanel(title,alignment, groupTitle);
                }
        }
 
-
        /**
         * Creation of a JPanel that will contain panels of 
<code>GUIHandler</code>
         * A layout will be set for this <i>"container"</i> of panels 
(horizontally or vertically), and a title (displayed or not)
@@ -282,7 +300,7 @@
         *
         * @return a container for <code>GUIHandler</code>' panels
         */
-       private JPanel getSimplePanel(final String title, final Param 
alignment, final Param groupTitle) {
+       private JPanel createSimplePanel(final String title, final Param 
alignment, final Param groupTitle) {
                JPanel outPanel = new JPanel();
                TitledBorder titleborder = 
BorderFactory.createTitledBorder(title);
                titleborder.setTitleColor(Color.BLUE);
@@ -296,7 +314,28 @@
                return outPanel;
        }
 
+       /**
+        * Creation of a JDialog that will contain panels of 
<code>GUIHandler</code>
+        * A layout will be set for this <i>"container"</i> of panels 
(horizontally or vertically), and a title (displayed or not)
+        *
+        * @param title of the panel
+        * @param alignment the way the panels will be set in this 
<i>"container</i> panel
+        * @param groupTitle parameter to choose whether or not the title of 
the panel has to be displayed
+        *
+        * @return a container for <code>GUIHandler</code>' panels
+        */
+       private JDialog createSimpleDialog(final String title, final Param 
alignment, final Param groupTitle) {
+               final JDialog dialog = new JDialog((JDialog)null, title);
 
+               if (groupTitle == Param.displayed || groupTitle == null)
+                       /* Do nothing. */;
+               if (alignment == Param.vertical || alignment == null)
+                       dialog.setLayout(new BoxLayout(dialog, 
BoxLayout.PAGE_AXIS));
+               else if (alignment == Param.horizontal)
+                       dialog.setLayout(new BoxLayout(dialog, 
BoxLayout.LINE_AXIS));
+               return dialog;
+       }
+
        /**
         * Displays the JPanels of each <code>GUIHandler</code> in a 
<code>JOptionPane</code>
         *

-- 
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