Author: mmichaud
Date: 2009-03-13 10:54:16 -0700 (Fri, 13 Mar 2009)
New Revision: 16256

Added:
   
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/InputStreamHandler.java
Modified:
   
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/GuiHandlerFactory.java
   
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/GuiTunableInterceptor.java
Log:


Modified: 
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/GuiHandlerFactory.java
===================================================================
--- 
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/GuiHandlerFactory.java
       2009-03-13 00:44:16 UTC (rev 16255)
+++ 
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/GuiHandlerFactory.java
       2009-03-13 17:54:16 UTC (rev 16256)
@@ -4,25 +4,35 @@
 import java.net.URL;
 
 import java.io.File;
+import java.io.InputStream;
 
 import org.cytoscape.property.bookmark.Bookmarks;
 import org.cytoscape.property.bookmark.BookmarksUtil;
 import org.cytoscape.property.CyProperty;
 import org.cytoscape.work.Tunable;
 import org.cytoscape.work.HandlerFactory;
-import org.cytoscape.work.util.*;
+import org.cytoscape.work.util.BoundedDouble;
+import org.cytoscape.work.util.BoundedFloat;
+import org.cytoscape.work.util.BoundedInteger;
+import org.cytoscape.work.util.BoundedLong;
+import org.cytoscape.work.util.ListMultipleSelection;
+import org.cytoscape.work.util.ListSingleSelection;
+
 import cytoscape.util.FileUtil;
+import org.cytoscape.io.util.StreamUtil;
 
 public class GuiHandlerFactory implements HandlerFactory<Guihandler> {
 
        private Bookmarks bookmarks;
        private BookmarksUtil bkUtil;
        private FileUtil flUtil;
+       private StreamUtil stUtil;
        
        public GuiHandlerFactory(CyProperty<Bookmarks> book, BookmarksUtil 
bkUtil) {
                this.bookmarks = book.getProperties();
                this.bkUtil = bkUtil;
                this.flUtil = flUtil;
+               this.stUtil = stUtil;
        }
 
        public Guihandler getHandler(Field f, Object o, Tunable t){
@@ -57,8 +67,8 @@
                        return new FileHandler(f,o,t,flUtil);
                else if(type == URL.class)
                        return new URLHandler(f,o,t,bookmarks,bkUtil);
-//             else if(type == URL.class)
-//                     return new 
InputStreamHandler(f,o,t,bookmarkrs,bkUtil,flUtil);
+               else if(type == InputStream.class)
+                       return new 
InputStreamHandler(f,o,t,bookmarks,bkUtil,flUtil,stUtil);
                return null;
        }
 }

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
   2009-03-13 00:44:16 UTC (rev 16255)
+++ 
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/GuiTunableInterceptor.java
   2009-03-13 17:54:16 UTC (rev 16256)
@@ -24,7 +24,6 @@
 
        private Component parent=null;
        private Map<java.util.List<Guihandler>,JPanel> panelMap;
-       private JPanel r = new JPanel(new BorderLayout());
        private java.util.List<Guihandler> lh;
        private boolean m;
        

Added: 
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/InputStreamHandler.java
===================================================================
--- 
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/InputStreamHandler.java
      2009-03-13 00:44:16 UTC (rev 16255)
+++ 
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/InputStreamHandler.java
      2009-03-13 17:54:16 UTC (rev 16256)
@@ -0,0 +1,322 @@
+package org.cytoscape.work.internal.tunables;
+
+
+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.URL;
+import java.util.List;
+import java.awt.event.KeyListener;
+import javax.swing.*;
+
+import cytoscape.util.*;
+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.Tunable;
+import org.cytoscape.io.util.*;
+
+
+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.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,Bookmarks 
bookmarks,BookmarksUtil bkUtil,FileUtil flUtil,StreamUtil stUtil) {
+               super(f,o,t);
+               this.bkUtil=bkUtil;
+               this.flUtil=flUtil;
+               this.stUtil=stUtil;
+               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,bookmarks.getCategory());    
+               if (theCategory == null) {
+                       theCategory = new Category();
+                       theCategory.setName(bookmarkCategory);
+
+                       List<Category> theCategoryList = 
bookmarks.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());
+                                                       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);
+                                       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() {
+               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"));
+               
+               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);
+
+               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