Author: rozagh
Date: 2012-07-11 11:23:39 -0700 (Wed, 11 Jul 2012)
New Revision: 29834

Added:
   
core3/api/trunk/work-swing-api/src/main/java/org/cytoscape/work/swing/DirectlyPresentableTunableHandler.java
Modified:
   
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/BooleanHandler.java
   
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
   
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JDialogTunableMutator.java
   
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JPanelTunableMutator.java
Log:
fixes #1237 Added an interface for directly presentable tunables which has a 
method named setTunableDirectly. Any tunable handler implementing this 
interface will be checked in the JPanelTunableMutator and set directly if no 
other tunables have been defined in the task. 

Added: 
core3/api/trunk/work-swing-api/src/main/java/org/cytoscape/work/swing/DirectlyPresentableTunableHandler.java
===================================================================
--- 
core3/api/trunk/work-swing-api/src/main/java/org/cytoscape/work/swing/DirectlyPresentableTunableHandler.java
                                (rev 0)
+++ 
core3/api/trunk/work-swing-api/src/main/java/org/cytoscape/work/swing/DirectlyPresentableTunableHandler.java
        2012-07-11 18:23:39 UTC (rev 29834)
@@ -0,0 +1,13 @@
+package org.cytoscape.work.swing;
+
+import java.awt.Window;
+
+public interface DirectlyPresentableTunableHandler {
+
+       /**
+        * This method allows us to bypass the normal tunable support when 
there is
+        * only one tunable in a Task.
+        */
+       boolean setTunableDirectly(Window possibleParent);
+       
+}

Modified: 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/BooleanHandler.java
===================================================================
--- 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/BooleanHandler.java
        2012-07-11 18:21:09 UTC (rev 29833)
+++ 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/BooleanHandler.java
        2012-07-11 18:23:39 UTC (rev 29834)
@@ -3,6 +3,7 @@
 
 import java.awt.BorderLayout;
 import java.awt.Font;
+import java.awt.Window;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.lang.reflect.Field;
@@ -11,11 +12,13 @@
 import javax.swing.BorderFactory;
 import javax.swing.JCheckBox;
 import javax.swing.JLabel;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 
 import org.cytoscape.work.Tunable;
 import org.cytoscape.work.internal.tunables.utils.GUIDefaults;
 import org.cytoscape.work.swing.AbstractGUITunableHandler;
+import org.cytoscape.work.swing.DirectlyPresentableTunableHandler;
 
 
 /**
@@ -23,10 +26,13 @@
  *
  * @author pasteur
  */
-public class BooleanHandler extends AbstractGUITunableHandler implements 
ActionListener {
+public class BooleanHandler extends AbstractGUITunableHandler implements 
ActionListener, DirectlyPresentableTunableHandler{
        private JCheckBox checkBox;
        private boolean horizontal = false;
-
+       private JOptionPane optionPane;
+       private boolean useOptionPane = false;
+       private int selectedOption;
+       
        /**
         * Constructs the <code>GUIHandler</code> for the <code>Boolean</code> 
type
         *
@@ -84,13 +90,35 @@
                        e.printStackTrace();
                }
        }
+       
 
+       @Override
+       public boolean setTunableDirectly(Window possibleParent) {
+               selectedOption = setOptionPaneGUI(possibleParent);
+               useOptionPane = true;
+               handle();
+               useOptionPane = false;
+               return selectedOption != JOptionPane.CANCEL_OPTION;
+       }
+
+       @SuppressWarnings("static-access")
+       private int setOptionPaneGUI(Window possibleParent) {
+               
+               //optionPane = new JOptionPane(getDescription());
+               //optionPane.setOptionType(JOptionPane.YES_NO_OPTION);
+               return  optionPane.showOptionDialog(possibleParent, 
getDescription(), "", JOptionPane.YES_NO_CANCEL_OPTION, 
JOptionPane.PLAIN_MESSAGE, null, null, null);
+       }
+
        /**
         * To set the current value represented in the <code>GUIHandler</code> 
(in a <code>JCheckBox</code>)to the value of this <code>Boolean</code> object
         */
        public void handle() {
                try {
-                       final Boolean setting = checkBox.isSelected();
+                       final Boolean setting;
+                       if (useOptionPane)
+                               setting = selectedOption == 
JOptionPane.YES_OPTION ? true : false;
+                       else
+                               setting = checkBox.isSelected();
                        setValue(setting);
                } catch (Exception e) {
                        e.printStackTrace();

Modified: 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
===================================================================
--- 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
   2012-07-11 18:21:09 UTC (rev 29833)
+++ 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
   2012-07-11 18:23:39 UTC (rev 29834)
@@ -32,6 +32,7 @@
 import org.cytoscape.work.Tunable;
 import org.cytoscape.work.internal.tunables.utils.SupportedFileTypesManager;
 import org.cytoscape.work.swing.AbstractGUITunableHandler;
+import org.cytoscape.work.swing.DirectlyPresentableTunableHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -41,7 +42,7 @@
  *
  * @author pasteur
  */
-public class FileHandler extends AbstractGUITunableHandler {
+public class FileHandler extends AbstractGUITunableHandler  implements 
DirectlyPresentableTunableHandler{
        
        private static final Logger logger = 
LoggerFactory.getLogger(FileHandler.class);
        
@@ -213,12 +214,14 @@
                                                  .addContainerGap()));
        }
 
+       
        /**
         * This method allows us to bypass the normal tunable support when the 
only
         * tunable in a Task is a File.  This allows us to pop up a file dialog
         * without first presenting the tunable dialog.
         */
-       boolean setFileTunableDirectly(Window possibleParent) {
+       @Override
+       public boolean setTunableDirectly (Window possibleParent) {
                this.possibleParent = possibleParent;
                setGui();
                myFileActionListener action = new myFileActionListener();

Modified: 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JDialogTunableMutator.java
===================================================================
--- 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JDialogTunableMutator.java
 2012-07-11 18:21:09 UTC (rev 29833)
+++ 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JDialogTunableMutator.java
 2012-07-11 18:23:39 UTC (rev 29834)
@@ -65,7 +65,7 @@
 
                // found the special case of the file handle cancel panel,
                // which means we should quit now
-               else if ( panel == FILE_HANDLER_CANCEL_PANEL )
+               else if ( panel == HANDLER_CANCEL_PANEL )
                        return false;
 
                else

Modified: 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JPanelTunableMutator.java
===================================================================
--- 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JPanelTunableMutator.java
  2012-07-11 18:21:09 UTC (rev 29833)
+++ 
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JPanelTunableMutator.java
  2012-07-11 18:23:39 UTC (rev 29834)
@@ -28,6 +28,7 @@
 import org.cytoscape.work.TunableValidator.ValidationState;
 import org.cytoscape.work.internal.tunables.utils.XorPanel;
 import org.cytoscape.work.swing.GUITunableHandler;
+import org.cytoscape.work.swing.DirectlyPresentableTunableHandler;
 import org.cytoscape.util.swing.BasicCollapsiblePanel;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -67,7 +68,7 @@
        private final Logger logger = 
LoggerFactory.getLogger(JPanelTunableMutator.class);
 
        /** Do not ever modify this panel. Used for special case handling of 
files. */
-       protected final JPanel FILE_HANDLER_CANCEL_PANEL = new JPanel();
+       protected final JPanel HANDLER_CANCEL_PANEL = new JPanel();
 
        /**
         * Constructor.
@@ -155,18 +156,19 @@
                        return null; 
                }
 
-               // This is special case handling for when the only tunable 
specified
-               // in a task is a file, in which case we don't want a full 
tunable dialog
-               // and all of the extra clicks, instead we just want a file 
dialog.
-               if ( handlers.size() == 1 && handlers.get(0) instanceof 
FileHandler ) {
-                       FileHandler fh = (FileHandler) handlers.get(0);
-                       boolean fileFound = 
fh.setFileTunableDirectly(possibleParent);
+               // This is special case handling for when there is only one 
tunable specified
+               // in a task, in which case we don't want a full tunable dialog
+               // and all of the extra clicks, instead we just want to show 
the special dialog.
+               if ( handlers.size() == 1 && handlers.get(0) instanceof 
DirectlyPresentableTunableHandler ) {
+                       DirectlyPresentableTunableHandler fh = 
(DirectlyPresentableTunableHandler) handlers.get(0);
+                       boolean fileFound = 
fh.setTunableDirectly(possibleParent);
                        if ( fileFound )
                                return null; 
                        else
-                               return FILE_HANDLER_CANCEL_PANEL;
+                               return HANDLER_CANCEL_PANEL;
                } 
-
+               
+               
                if (!panelMap.containsKey(handlers)) {
                        final String MAIN = " ";
                        Map<String, JPanel> panels = new HashMap<String, 
JPanel>();

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