Author: mmichaud
Date: 2009-04-02 07:58:08 -0700 (Thu, 02 Apr 2009)
New Revision: 16423

Added:
   
csplugins/trunk/pasteur/mathieu/tunables2/src/main/java/org/cytoscape/work/internal/gui/InputStreamHandler.java
Modified:
   
csplugins/trunk/pasteur/mathieu/tunables2/src/main/java/org/cytoscape/work/internal/gui/GuiHandlerFactory.java
   
csplugins/trunk/pasteur/mathieu/tunables2/src/main/java/org/cytoscape/work/internal/gui/GuiTunableInterceptor.java
Log:


Modified: 
csplugins/trunk/pasteur/mathieu/tunables2/src/main/java/org/cytoscape/work/internal/gui/GuiHandlerFactory.java
===================================================================
--- 
csplugins/trunk/pasteur/mathieu/tunables2/src/main/java/org/cytoscape/work/internal/gui/GuiHandlerFactory.java
      2009-04-02 14:57:49 UTC (rev 16422)
+++ 
csplugins/trunk/pasteur/mathieu/tunables2/src/main/java/org/cytoscape/work/internal/gui/GuiHandlerFactory.java
      2009-04-02 14:58:08 UTC (rev 16423)
@@ -1,5 +1,7 @@
 package org.cytoscape.work.internal.gui;
 
+import java.io.File;
+import java.io.InputStream;
 import java.lang.reflect.Field;
 import java.net.URL;
 
@@ -10,10 +12,9 @@
 import org.cytoscape.work.util.BoundedLong;
 import org.cytoscape.work.util.ListMultipleSelection;
 import org.cytoscape.work.util.ListSingleSelection;
-import org.cytoscape.work.util.myFile;
 
 public class GuiHandlerFactory<T> implements HandlerFactory<Guihandler> {
-
+       
        public Guihandler getHandler(Field f, Object o, Tunable t){
                
                Class<?> type = f.getType();
@@ -42,10 +43,12 @@
                        return new ListSingleHandler<String>(f,o,t);
                else if(type == ListMultipleSelection.class)
                        return new ListMultipleHandler<String>(f,o,t);
-               else if(type == myFile.class)
+               else if(type == File.class)
                        return new FileHandler(f,o,t);
                else if(type == URL.class)
                        return new URLHandler(f,o,t);
+               else if(type == InputStream.class)
+                       return new InputStreamHandler(f,o,t);
                return null;
        }
 }

Modified: 
csplugins/trunk/pasteur/mathieu/tunables2/src/main/java/org/cytoscape/work/internal/gui/GuiTunableInterceptor.java
===================================================================
--- 
csplugins/trunk/pasteur/mathieu/tunables2/src/main/java/org/cytoscape/work/internal/gui/GuiTunableInterceptor.java
  2009-04-02 14:57:49 UTC (rev 16422)
+++ 
csplugins/trunk/pasteur/mathieu/tunables2/src/main/java/org/cytoscape/work/internal/gui/GuiTunableInterceptor.java
  2009-04-02 14:58:08 UTC (rev 16423)
@@ -1,5 +1,6 @@
 package org.cytoscape.work.internal.gui;
 
+import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Component;
 import java.util.ArrayList;
@@ -21,16 +22,18 @@
 public class GuiTunableInterceptor extends 
AbstractTunableInterceptor<Guihandler> {
 
        private Component parent;
-       private Map<java.util.List<Guihandler>,JPanel> panelMap;
+       private Map<List<Guihandler>,JPanel> panelMap;
+       int n;
+       JPanel r = new JPanel(new BorderLayout());
+       List<Guihandler> lh;
 
-       public GuiTunableInterceptor(Component parent) {
+       public GuiTunableInterceptor() {
                super( new GuiHandlerFactory<Guihandler>());
-               this.parent = parent;
-               panelMap = new HashMap<java.util.List<Guihandler>,JPanel>();
+               panelMap = new HashMap<List<Guihandler>,JPanel>();
        }
 
-       public int createUI(Object... objs) {
-               java.util.List<Guihandler> lh = new ArrayList<Guihandler>();
+       public boolean createUI(Object... objs) {
+               lh = new ArrayList<Guihandler>();
                for ( Object o : objs ) {
                        if ( !handlerMap.containsKey( o ) )
                                throw new IllegalArgumentException("No Tunables 
exist for Object yet!");
@@ -39,9 +42,9 @@
                }
                
                if ( !panelMap.containsKey( lh ) ) {
-                       final String MAIN = "";
+                       final String MAIN = " ";
                        Map<String, JPanel> panels = new 
HashMap<String,JPanel>();
-                       panels.put(MAIN,createJPanel(MAIN,null));
+                       panels.put(MAIN,createJPanel(MAIN,null,null));
 
                        // construct the gui
                        for (Guihandler gh : lh) {
@@ -57,18 +60,32 @@
                                                }
                                        }
                                }
+                               
+                               Map<String,Param> groupalignement = new 
HashMap<String,Param>();
+                               String[] group = gh.getTunable().group();
+                               Param[] alignments = 
gh.getTunable().alignment();
+                               
+                               if(group.length==alignments.length){
+                                       for(int i = 0; i < group.length; 
i++)groupalignement.put(group[i], alignments[i]);
+                               }
+                               if(group.length>alignments.length){
+                                       for(int i = 0; i < alignments.length; 
i++)groupalignement.put(group[i], alignments[i]);
+                                       for(int 
i=alignments.length;i<group.length;i++)groupalignement.put(group[i], 
Param.vertical);
+                               }
+                               if(alignments.length>group.length){
+                                       for(int i = 0; i < group.length; 
i++)groupalignement.put(group[i], alignments[i]);
+                               }
+                               
                                // find the proper group to put the handler 
panel in
-                               String[] group = gh.getTunable().group();
-                               String lastGroup = MAIN; 
+                               String lastGroup = MAIN;
                                for ( String g : group ) {
                                        if ( !panels.containsKey(g) ) {
-                                               
panels.put(g,createJPanel(g,gh));                       
+                                               
panels.put(g,createJPanel(g,gh,groupalignement.get(g)));
                                                panels.get(lastGroup).add( 
panels.get(g), gh.getTunable().xorKey() );
                                        }
-
                                        lastGroup = g;
                                }
-
+                               
                                panels.get(lastGroup).add(gh.getJPanel());
                        }
                        panelMap.put(lh,panels.get(MAIN));
@@ -88,17 +105,18 @@
                    null,
                    buttons,
                    buttons[0]);
-               // process the values set in the gui 
-               //USELESS BECAUSE OF LISTENERS
-               if(n==0){
-                       for ( Guihandler h : lh )h.handle();
+
+               if ( n == JOptionPane.OK_OPTION ){
+                       for ( Guihandler h : lh ) 
h.notifyDependents();//h.handle();
+                       return true;
                }
-               return n;
+               else
+                       return false;
        }
 
-       private JPanel createJPanel(String title, Guihandler gh) {
+       private JPanel createJPanel(String title, Guihandler gh,Param 
alignment) {
                if ( gh == null )
-                       return getSimplePanel(title);
+                       return getSimplePanel(title,alignment);
                // See if we need to create an XOR panel
                if ( gh.getTunable().xorChildren() ) {
                        JPanel p = new XorPanel(title,gh);
@@ -116,16 +134,34 @@
                        }
                        
                        // We're not collapsable, so return a normal jpanel
-                       return getSimplePanel(title);
+                       return getSimplePanel(title,alignment);
                }
        }
-       private JPanel getSimplePanel(String title) {
+       private JPanel getSimplePanel(String title,Param alignment) {
                JPanel ret = new JPanel();
                TitledBorder titleborder = 
BorderFactory.createTitledBorder(title);
-               titleborder.setTitleColor(Color.BLUE);
-               ret.setBorder(titleborder);
-               //ret.setBorder(BorderFactory.createTitledBorder(title));
-               ret.setLayout(new BoxLayout(ret,BoxLayout.PAGE_AXIS));
+               titleborder.setTitleColor(Color.RED);
+               
+               if(title!="" && title!=" "){
+                       if(alignment==Param.vertical || alignment==null){
+                               ret.setBorder(titleborder);
+                               ret.setLayout(new 
BoxLayout(ret,BoxLayout.PAGE_AXIS));
+                       }
+                       else if(alignment==Param.horizontal){
+                               ret.setBorder(titleborder);
+                               ret.setLayout(new 
BoxLayout(ret,BoxLayout.LINE_AXIS));
+                       }
+               }
+               else {
+                       if(alignment==Param.vertical || alignment==null){
+                               ret.setLayout(new 
BoxLayout(ret,BoxLayout.PAGE_AXIS));
+                       }
+                       else if(alignment==Param.horizontal){
+                               
+                               ret.setLayout(new 
BoxLayout(ret,BoxLayout.LINE_AXIS));
+                       }
+               }
+               
                return ret;
        }
 }

Added: 
csplugins/trunk/pasteur/mathieu/tunables2/src/main/java/org/cytoscape/work/internal/gui/InputStreamHandler.java
===================================================================
--- 
csplugins/trunk/pasteur/mathieu/tunables2/src/main/java/org/cytoscape/work/internal/gui/InputStreamHandler.java
     2009-04-02 14:57:49 UTC (rev 16422)
+++ 
csplugins/trunk/pasteur/mathieu/tunables2/src/main/java/org/cytoscape/work/internal/gui/InputStreamHandler.java
     2009-04-02 14:58:08 UTC (rev 16423)
@@ -0,0 +1,329 @@
+package org.cytoscape.work.internal.gui;
+
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Font;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+import java.awt.event.KeyListener;
+import javax.swing.*;
+
+import org.cytoscape.io.util.StreamUtil;
+import org.cytoscape.property.bookmark.Bookmarks;
+import org.cytoscape.property.bookmark.BookmarksUtil;
+import org.cytoscape.property.bookmark.Category;
+import org.cytoscape.property.bookmark.DataSource;
+import org.cytoscape.work.AbstractGuiHandler;
+import org.cytoscape.work.Tunable;
+
+import cytoscape.util.FileUtil;
+
+
+public class InputStreamHandler extends AbstractGuiHandler {
+
+//     Bookmarks theBookmarks;
+       String bookmarkCategory = "network";
+       String urlstr;
+       BookmarkComboBoxEditor bookmarkEditor = new BookmarkComboBoxEditor();
+       JComboBox networkFileComboBox;
+       FileUtil flUtil;
+//     BookmarksUtil bkUtil;
+       StreamUtil stUtil;
+       
+       InputStream InStream = null;
+       URL url;
+       JButton button;
+       File myFile;
+       JFileChooser fileChooser;
+       boolean filechoosen;
+       JTextField path;
+       
+       private String pleaseMessage = "Please provide URL or select from list";
+       
+       private JPanel radioButtonPanel;
+       private JPanel valuePanel;
+       private javax.swing.JButton selectButton;
+       //private javax.swing.ButtonGroup buttonGroup1;
+       private javax.swing.JRadioButton remoteRadioButton;
+       private javax.swing.JRadioButton localRadioButton;
+       private javax.swing.JTextField networkFileTextField;
+       private static final String URL_TOOLTIP = "<html>Enter URL or 
<strong><font color=\"red\">Drag and Drop local/remote 
files.</font></strong></html>";
+       private static final String LOCAL_TOOLTIP = "<html>Specify path to 
local files.</html>";
+
+       
+       public InputStreamHandler(Field f, Object o, Tunable t) {
+               super(f,o,t);
+
+               //this.theBookmarks=bookmarks;
+               filechoosen = false;
+               fileChooser = new JFileChooser();
+               
+               try{
+                       this.InStream = (InputStream) f.get(o);
+               }catch(Exception e){e.printStackTrace();}
+
+//             Category theCategory = 
bkUtil.getCategory(bookmarkCategory,theBookmarks.getCategory()); 
+//             if (theCategory == null) {
+//                     theCategory = new Category();
+//                     theCategory.setName(bookmarkCategory);
+//
+//                     List<Category> theCategoryList = 
theBookmarks.getCategory();
+//                     theCategoryList.add(theCategory);
+//             }
+               
+               System.out.println("Test INPUTSTREAM");
+
+               panel.add(new JLabel("Path :"));
+               path = new JTextField("select file",12);
+               path.setFont(new Font(null, Font.ITALIC,10));
+               panel.add(path);
+
+               initComponents();
+               addListeners();
+               switchImportView("remote");
+               
+               panel = new JPanel(new BorderLayout());
+               panel.add(radioButtonPanel,BorderLayout.NORTH);
+               panel.add(valuePanel,BorderLayout.SOUTH);
+       }
+       
+       
+       public void handle() {
+               if(localRadioButton.isSelected()){
+                       if(!filechoosen){
+                               int ret = fileChooser.showOpenDialog(null);
+                               if (ret == JFileChooser.APPROVE_OPTION){
+                                       //File file = flUtil.getFile("Import 
Network File",flUtil.LOAD);
+                                   File file = fileChooser.getSelectedFile();
+                                       if ( file != null ){
+                                               try{
+                                                       InStream = new 
FileInputStream(file);
+                                                       //InStream = 
flUtil.getInputStream(file.getAbsolutePath());
+                                                       
System.out.println("INSTREAM = "+ InStream.toString());
+                                                       f.set(o,InStream);
+                                               }catch (Exception e) { 
e.printStackTrace();}
+                                               
networkFileTextField.setFont(new Font(null, Font.PLAIN,10));
+                                               
networkFileTextField.setText(file.getPath());
+                                       }
+                               }
+                       }
+                       filechoosen=true;
+               }
+               else if(remoteRadioButton.isSelected()){
+                       urlstr = bookmarkEditor.getURLstr();
+                       try{
+                               if ( urlstr != null ) {
+                                       url = new URL(urlstr);
+                                       InStream = stUtil.getInputStream(url);
+                                       System.out.println("URL = "+urlstr);
+                                       f.set(o,InStream);
+                               }
+                       }catch (Exception e){}
+               }
+       }
+
+
+       
+       
+    public String getState() {
+               String s = null;
+               try {
+                       if(f.get(o)!=null) s = f.get(o).toString();
+               } catch (IllegalAccessException e) {
+                       e.printStackTrace();
+                       s = "";
+               }
+               return s;
+    }
+    
+    
+    private void initComponents() {
+               //buttonGroup1 = new javax.swing.ButtonGroup();
+               localRadioButton = new javax.swing.JRadioButton();
+               remoteRadioButton = new javax.swing.JRadioButton();
+               networkFileTextField = new javax.swing.JTextField();
+               networkFileComboBox = new javax.swing.JComboBox();
+               selectButton = new javax.swing.JButton();
+               radioButtonPanel = new javax.swing.JPanel();
+               valuePanel = new javax.swing.JPanel();
+
+               
radioButtonPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Data 
Source Type"));
+               
+               //buttonGroup1.add(localRadioButton);
+               localRadioButton.setSelected(true);
+               localRadioButton.setText("Local");
+               
localRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 
0));
+               localRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
+               localRadioButton.setToolTipText(LOCAL_TOOLTIP);
+
+               //buttonGroup1.add(remoteRadioButton);
+               remoteRadioButton.setText("Remote/URL");
+               
remoteRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 
0, 0));
+               remoteRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
+               remoteRadioButton.setToolTipText(URL_TOOLTIP);
+
+       
+               radioButtonPanel.add(localRadioButton);
+               radioButtonPanel.add(remoteRadioButton);
+               valuePanel.add(networkFileTextField);
+               valuePanel.add(selectButton);
+               valuePanel.add(networkFileComboBox);
+               
+               networkFileTextField.setText("Please select a network file...");
+               networkFileTextField.setName("networkFileTextField");
+               //networkFileTextField.addFocusListener(this);
+
+               selectButton.setText("Select");
+
+               networkFileComboBox.setRenderer(new MyCellRenderer());
+               networkFileComboBox.setEditor(bookmarkEditor);
+               networkFileComboBox.setEditable(true);
+               networkFileComboBox.setName("networkFileComboBox");
+               networkFileComboBox.setToolTipText("<html><body>You can specify 
URL by the following:<ul><li>Type URL</li><li>Select from pull down 
menu</li><li>Drag & Drop URL from Web Browser</li></ul></body><html>");
+               final ToolTipManager tp = ToolTipManager.sharedInstance();
+               tp.setInitialDelay(1);
+               tp.setDismissDelay(7500);
+       }
+    
+    
+    private void addListeners() {
+               LocalRemoteListener l = new LocalRemoteListener();
+               localRadioButton.addActionListener(l);
+               remoteRadioButton.addActionListener(l);
+
+               // ButtonActionListener btnActionListener = new 
ButtonActionListener();
+               selectButton.addActionListener(this);
+               //bookmarkEditor.addActionListener(this);
+       }
+
+    
+    
+    
+    
+       private void switchImportView(String pLocation) {
+               if (pLocation.equalsIgnoreCase("Local")) {
+                       networkFileComboBox.setVisible(false);
+                       networkFileTextField.setVisible(true);
+                       localRadioButton.setSelected(true);
+                       remoteRadioButton.setSelected(false);
+                       selectButton.setVisible(true);
+               } else {
+                       networkFileComboBox.setVisible(true);
+                       networkFileTextField.setVisible(false);
+                       selectButton.setVisible(false);
+                       localRadioButton.setSelected(false);
+                       remoteRadioButton.setSelected(true);
+                       loadBookmarkCMBox();
+               }
+       }
+    
+       
+       
+       class LocalRemoteListener implements java.awt.event.ActionListener {
+               public void actionPerformed(java.awt.event.ActionEvent e) {
+                       Object _actionObject = e.getSource();
+
+                       // handle radioButton events
+                       if (_actionObject instanceof JRadioButton) {
+                               JRadioButton _rbt = (JRadioButton) 
_actionObject;
+
+                               // process radio button events
+                               if (_rbt == localRadioButton) {
+                                       switchImportView("Local");
+                               } else { // from rbtRemote
+                                       switchImportView("Remote");
+                               }
+                       }
+               } // actionPerformed()
+       }
+    
+    
+       class BookmarkComboBoxEditor implements ComboBoxEditor {
+               DataSource theDataSource = new DataSource();
+               JTextField tfInput = new JTextField(pleaseMessage);
+               
+               public String getURLstr() {
+                       return tfInput.getText();
+               }
+               
+               public void setStr(String txt){
+                       tfInput.setText(txt);
+               }
+               public void addActionListener(ActionListener l) {
+                       tfInput.addActionListener(l);
+               }
+               public void addKeyListener(KeyListener l) {
+                       tfInput.addKeyListener(l);
+               }
+               public Component getEditorComponent() {
+                       return tfInput;
+               }
+               public Object getItem() {
+                       return theDataSource;
+               }
+               public void removeActionListener(ActionListener l) {
+               }
+               public void selectAll() {
+               }
+               public void setItem(Object anObject) {
+                       if (anObject == null) {
+                               return;
+                       }
+
+                       if (anObject instanceof DataSource) {
+                               theDataSource = (DataSource) anObject;
+                               tfInput.setText(theDataSource.getHref());
+                       }
+               }
+       }
+       
+       private void loadBookmarkCMBox() {
+               networkFileComboBox.removeAllItems();
+
+               DefaultComboBoxModel theModel = new DefaultComboBoxModel();
+
+               DataSource firstDataSource = new DataSource();
+               firstDataSource.setName("");
+               firstDataSource.setHref(null);
+
+               theModel.addElement(firstDataSource);
+
+               // Extract the URL entries
+//             List<DataSource> theDataSourceList = 
bkUtil.getDataSourceList(bookmarkCategory,theBookmarks.getCategory());
+//             if (theDataSourceList != null) {
+//                     for (int i = 0; i < theDataSourceList.size(); i++) {
+//                             theModel.addElement(theDataSourceList.get(i));
+//                     }
+//             }
+//             networkFileComboBox.setModel(theModel);
+       }
+
+       
+       class MyCellRenderer extends JLabel implements ListCellRenderer {
+               private final static long serialVersionUID = 1202339872997986L;
+               public MyCellRenderer() {
+                       setOpaque(true);
+               }
+
+               public Component getListCellRendererComponent(JList list, 
Object value,
+                               int index, boolean isSelected, boolean 
cellHasFocus) {
+                       DataSource dataSource = (DataSource) value;
+                       setText(dataSource.getName());
+                       if (isSelected) {
+                               if (0 < index) {
+                                       
list.setToolTipText(dataSource.getHref());
+                               }
+                       }
+                       return this;
+               }
+       }
+       
+       
+}


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