Author: pwang
Date: 2011-02-04 17:01:51 -0800 (Fri, 04 Feb 2011)
New Revision: 24028

Modified:
   
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/PreferenceAction.java
   
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/dialogs/PreferenceTableModel.java
   
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/dialogs/PreferenceValueDialog.java
   
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/dialogs/PreferencesDialogFactoryImpl.java
   
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/dialogs/PreferencesDialogImpl.java
Log:
Enable to edit separate properties objects

Modified: 
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/PreferenceAction.java
===================================================================
--- 
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/PreferenceAction.java
       2011-02-05 01:00:28 UTC (rev 24027)
+++ 
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/PreferenceAction.java
       2011-02-05 01:01:51 UTC (rev 24028)
@@ -42,16 +42,19 @@
 //-------------------------------------------------------------------------
 package org.cytoscape.internal.actions;
 
+import org.cytoscape.property.CyProperty;
+import org.cytoscape.property.bookmark.Bookmarks;
+import org.cytoscape.property.bookmark.BookmarksUtil;
 import org.cytoscape.session.CyApplicationManager;
 import org.cytoscape.application.swing.CySwingApplication;
 import org.cytoscape.application.swing.AbstractCyAction;
 import org.cytoscape.internal.dialogs.PreferencesDialogImpl;
 import org.cytoscape.internal.dialogs.PreferencesDialogFactoryImpl;
-
-import javax.swing.*;
 import java.awt.event.ActionEvent;
+import java.util.Properties;
+import java.util.Dictionary;
+import java.util.HashMap;
 
-
 /**
  *
  */
@@ -62,10 +65,19 @@
         */
        private CySwingApplication desktop;
        private PreferencesDialogFactoryImpl pdf;
-       public PreferenceAction(CySwingApplication desktop, 
CyApplicationManager appMgr, PreferencesDialogFactoryImpl pdf ) {
+       private BookmarksUtil bkUtil;
+       private PreferencesDialogImpl preferencesDialog = null;
+       private HashMap<String, Properties> propMap = new 
HashMap<String,Properties>();
+       private HashMap<String, Bookmarks> bookmarkMap = new 
HashMap<String,Bookmarks>();
+       
+       public PreferenceAction(CySwingApplication desktop, 
CyApplicationManager appMgr, PreferencesDialogFactoryImpl pdf,
+                       BookmarksUtil bkUtil) {
                super("Properties...",appMgr);
                this.desktop = desktop;
                this.pdf = pdf;
+
+               this.bkUtil = bkUtil;
+               
                setPreferredMenu("Edit.Preferences");
                setMenuGravity(10.0f);
        }
@@ -76,7 +88,38 @@
         * @param e DOCUMENT ME!
         */
        public void actionPerformed(ActionEvent e) {
-               PreferencesDialogImpl preferencesDialog = 
pdf.getPreferencesDialog(desktop.getJFrame()); 
-               preferencesDialog.showDialog();
+               preferencesDialog = 
pdf.getPreferencesDialog(desktop.getJFrame(), propMap, bookmarkMap, bkUtil); 
+               preferencesDialog.setVisible(true);
        } 
+       
+       //
+       public void addCyProperty(CyProperty<?> p, Dictionary d){
+               
+               String propertyName = (String) d.get("cyPropertyName");
+
+               Object obj = p.getProperties();
+               
+               if (obj instanceof Properties){         
+                       propMap.put(propertyName, (Properties)obj);
+               }
+               else if (obj instanceof Bookmarks){
+                       bookmarkMap.put(propertyName, (Bookmarks)obj);
+               }
+               else {
+                       System.out.println("PreferenceAction: Do not know what 
kind of properties it is!");
+               }
+       }
+       
+       public void removeCyProperty(CyProperty<?> p, Dictionary d){
+
+               String propertyName = (String) d.get("cyPropertyName");
+               
+               Object obj = p.getProperties();
+               if (obj instanceof Properties){
+                       propMap.remove(propertyName);
+               }
+               else if (obj instanceof Bookmarks){
+                       bookmarkMap.remove(propertyName);
+               }
+       }
 }

Modified: 
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/dialogs/PreferenceTableModel.java
===================================================================
--- 
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/dialogs/PreferenceTableModel.java
   2011-02-05 01:00:28 UTC (rev 24027)
+++ 
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/dialogs/PreferenceTableModel.java
   2011-02-05 01:01:51 UTC (rev 24028)
@@ -58,7 +58,7 @@
         */
        public PreferenceTableModel(Properties props) {
                super();
-               properties = (Properties) (props.clone());
+               properties = props;
                loadProperties();
        }
 
@@ -72,6 +72,8 @@
                        String name = (String) names.nextElement();
                        addProperty(new String[] { name, 
properties.getProperty(name) });
                }
+
+               //this.fireTableDataChanged();
        }
 
        /**
@@ -108,6 +110,7 @@
                properties.setProperty(key, value);
 
                // update table model (propertiesList)
+               
                for (Iterator it = propertiesList.iterator(); it.hasNext();) {
                        String[] prop = (String[]) it.next();
 
@@ -115,6 +118,7 @@
                                prop[1] = value;
                        }
                }
+               this.fireTableDataChanged();
        }
 
        /**
@@ -127,15 +131,14 @@
                properties.remove(key);
 
                // remove property from table model (propertiesList)
-               for (Iterator it = propertiesList.iterator(); it.hasNext();) {
-                       String[] prop = (String[]) it.next();
-
+               for (int i=this.propertiesList.size()-1; i>=0;i--){
+                       String[] prop = (String[])this.propertiesList.get(i);
                        if (prop[0].equals(key)) {
                                propertiesList.remove(prop);
-
-                               return;
-                       }
+                       }                       
                }
+               
+               this.fireTableDataChanged();
        }
 
        /**
@@ -144,6 +147,7 @@
         * @param val DOCUMENT ME!
         */
        public void addProperty(String[] val) {
+               
                if ((val.length < 0) || (val.length > columnHeader.length))
                        return;
 
@@ -166,6 +170,8 @@
                sort();
                // also add to local properties object for saving 
                properties.setProperty(val[0], val[1]);
+               
+               this.fireTableDataChanged();
        }
 
        /**
@@ -224,9 +230,8 @@
         *
         * @return  DOCUMENT ME!
         */
-       public Object getValueAt(int row, int col) {
+       public Object getValueAt(int row, int col) {            
                String[] rowData = (String[]) propertiesList.get(row);
-
                return rowData[col];
        }
 
@@ -245,6 +250,7 @@
        public void sort() {
                Collections.sort(propertiesList, new StringComparator());
        }
+       
 }
 
 

Modified: 
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/dialogs/PreferenceValueDialog.java
===================================================================
--- 
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/dialogs/PreferenceValueDialog.java
  2011-02-05 01:00:28 UTC (rev 24027)
+++ 
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/dialogs/PreferenceValueDialog.java
  2011-02-05 01:01:51 UTC (rev 24028)
@@ -46,17 +46,16 @@
 /**
  *
  */
-public class PreferenceValueDialog extends JDialog {
+public class PreferenceValueDialog extends JDialog implements ActionListener {
        private final static long serialVersionUID = 1202339873382923L;
        String preferenceName = null;
        String preferenceValue = null;
-       String title = null;
+       //String title = null;
        JLabel preferenceNameL = null;
        JTextField value = null;
        JButton okButton = null;
        JButton cancelButton = null;
-       TableModel tableModel = null;
-       PreferencesDialogImpl callerRef = null;
+       PreferenceTableModel tableModel = null;
 
        /**
         * Creates a new PreferenceValueDialog object.
@@ -68,28 +67,32 @@
         * @param tm  DOCUMENT ME!
         * @param title  DOCUMENT ME!
         */
-       public PreferenceValueDialog(Dialog owner, String name, String value, 
PreferencesDialogImpl caller,
-                                    TableModel tm, String title) {
+       public PreferenceValueDialog(JDialog owner, String name, String value,
+                       PreferenceTableModel tm, String title) {
                super(owner, true);
-               callerRef = caller;
+               //callerRef = caller;
                tableModel = tm;
-               this.title = title;
-
+               
                preferenceName = new String(name);
                preferenceValue = new String(value);
 
-               showDialog(owner);
+               initDialog(owner);
+
+               this.okButton.addActionListener(this);
+               this.cancelButton.addActionListener(this);
+               
+               this.setTitle(title);
+               // popup relative to owner/parent
+               this.setLocationRelativeTo(owner);
+               this.setVisible(true);
        }
 
-       protected void showDialog(Dialog owner) {
+       protected void initDialog(Dialog owner) {
                preferenceNameL = new JLabel(preferenceName);
                value = new JTextField(preferenceValue, 32);
                okButton = new JButton("OK");
                cancelButton = new JButton("Cancel");
 
-               okButton.addActionListener(new OkButtonListener(this, 
callerRef));
-               cancelButton.addActionListener(new CancelButtonListener(this, 
callerRef));
-
                JPanel outerPanel = new JPanel(new BorderLayout());
                JPanel valuePanel = new JPanel(new FlowLayout());
                JPanel buttonPanel = new JPanel(new FlowLayout());
@@ -103,45 +106,22 @@
 
                this.getContentPane().add(outerPanel, BorderLayout.CENTER);
                pack();
-
-               this.setTitle(title);
-               // popup relative to owner/parent
-               this.setLocationRelativeTo(owner);
-               this.setVisible(true);
        }
 
 
-       class OkButtonListener implements ActionListener {
-               PreferenceValueDialog motherRef = null;
-               PreferencesDialogImpl grandmotherRef = null;
+       public void actionPerformed(ActionEvent e) {
+               Object src = e.getSource();
+               
+               if (src instanceof JButton){
 
-               public OkButtonListener(PreferenceValueDialog mother, 
PreferencesDialogImpl grandmother) {
-                       super();
-                       motherRef = mother;
-                       grandmotherRef = grandmother;
+                       JButton btn = (JButton) src;
+                       if (btn == this.okButton){
+                               this.tableModel.setProperty(preferenceName, 
value.getText());
+                               this.dispose(); 
+                       }
+                       else if (btn == this.cancelButton){
+                               this.dispose(); 
+                       }
                }
-
-               public void actionPerformed(ActionEvent e) {
-                       // properties
-                       motherRef.preferenceValue = motherRef.value.getText();
-                       grandmotherRef.setParameter(tableModel, 
motherRef.preferenceName,
-                                                   motherRef.preferenceValue);
-                       motherRef.dispose();
-               }
        }
-
-       class CancelButtonListener implements ActionListener {
-               PreferenceValueDialog motherRef = null;
-               PreferencesDialogImpl grandmotherRef = null;
-
-               public CancelButtonListener(PreferenceValueDialog mother, 
PreferencesDialogImpl grandmother) {
-                       super();
-                       motherRef = mother;
-                       grandmotherRef = grandmother;
-               }
-
-               public void actionPerformed(ActionEvent e) {
-                       motherRef.dispose();
-               }
-       }
 }

Modified: 
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/dialogs/PreferencesDialogFactoryImpl.java
===================================================================
--- 
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/dialogs/PreferencesDialogFactoryImpl.java
   2011-02-05 01:00:28 UTC (rev 24027)
+++ 
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/dialogs/PreferencesDialogFactoryImpl.java
   2011-02-05 01:01:51 UTC (rev 24028)
@@ -37,8 +37,14 @@
 
 
 import java.awt.Frame;
+import java.util.HashMap;
+import java.util.Properties;
+
 import org.cytoscape.event.CyEventHelper;
 import org.cytoscape.internal.CyOperatingContextImpl;
+import org.cytoscape.property.CyProperty;
+import org.cytoscape.property.bookmark.Bookmarks;
+import org.cytoscape.property.bookmark.BookmarksUtil;
 
 /**
  */
@@ -52,7 +58,10 @@
                this.eh = eh;
        }
 
-       public PreferencesDialogImpl getPreferencesDialog(Frame parent) {
-               return new PreferencesDialogImpl(parent,coc,eh);        
+       public PreferencesDialogImpl getPreferencesDialog(Frame parent, 
HashMap<String, Properties> propMap, 
+                       HashMap<String, Bookmarks> bookmarkMap, BookmarksUtil 
bkUtil) {
+               return new PreferencesDialogImpl(parent,eh, propMap, 
bookmarkMap, bkUtil);      
        }
+       
+       
 }

Modified: 
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/dialogs/PreferencesDialogImpl.java
===================================================================
--- 
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/dialogs/PreferencesDialogImpl.java
  2011-02-05 01:00:28 UTC (rev 24027)
+++ 
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/dialogs/PreferencesDialogImpl.java
  2011-02-05 01:01:51 UTC (rev 24028)
@@ -46,6 +46,9 @@
 import java.awt.event.ItemListener;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.Properties;
 
 import javax.swing.BorderFactory;
@@ -69,121 +72,99 @@
 import org.cytoscape.event.CyEventHelper;
 
 import org.cytoscape.internal.CyOperatingContextImpl;
+import org.cytoscape.property.CyProperty;
+import org.cytoscape.property.bookmark.Bookmarks;
+import org.cytoscape.property.bookmark.BookmarksUtil;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import javax.swing.JComboBox;
+import javax.swing.AbstractListModel;
+import javax.swing.ComboBoxModel;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.table.DefaultTableColumnModel;
 
 
 /**
  *
  */
-public class PreferencesDialogImpl extends JDialog {
+public class PreferencesDialogImpl extends JDialog implements ItemListener, 
ActionListener, ListSelectionListener {
        private final static long serialVersionUID = 1202339873396288L;
        private static final Logger logger = 
LoggerFactory.getLogger(PreferencesDialogImpl.class);
 
-       int[] selection = null;
-       private Properties props;
-       private CyOperatingContextImpl context;
-       private CyEventHelper eh;
-
-       JScrollPane propsTablePane = new JScrollPane();
-       JTable prefsTable = new JTable();
-       JPanel propBtnPane = new JPanel(new FlowLayout());
-       JPanel okButtonPane = new JPanel(new FlowLayout());
-       JPanel vizmapPane = new JPanel(new FlowLayout());
-       JPanel cyPropsPane = new JPanel(new FlowLayout());
-       JCheckBox saveVizmapBtn = new JCheckBox("Make Current Visual Styles 
Default", false);
-       JCheckBox saveCyPropsBtn = new JCheckBox("Make Current Cytoscape 
Properties Default", false);
-       JTextArea vizmapText = new JTextArea("Only check this option if you 
want the current visual styles to be defaults in ALL future cytoscape sessions. 
 Your current visual styles are automatically saved in your Cytoscape session 
file and won't be lost.");
-       JTextArea cyPropsText = new JTextArea("Only check this option if you 
want the current Cytoscape properties to be defaults in ALL future cytoscape 
sessions.  Your current Cytoscape properties are automatically saved in your 
Cytoscape session file and won't be lost.");
-       JButton addPropBtn = new JButton("Add");
-       JButton deletePropBtn = new JButton("Delete");
-       JButton modifyPropBtn = new JButton("Modify");
-       JButton okButton = new JButton("OK");
-       JButton cancelButton = new JButton("Cancel");
-
+       //private Properties props;
+       //private CyProperty<Bookmarks>  bookmarks;
+       //private BookmarksUtil bkUtil;
+       
+       private HashMap<String, Properties> propMap = new 
HashMap<String,Properties>();
        /**
+        * Creates a new PreferencesDialog object.
         *
+        * @param owner  DOCUMENT ME!
         */
-       public PreferenceTableModel prefsTM = null;
-       private ListSelectionModel lsm = null;
-       private ListSelectionModel lsmA = null;
-       private boolean saveCyPropsAsDefault = false;
-       private boolean saveVizmapAsDefault = false;
+       public PreferencesDialogImpl(Frame owner, CyEventHelper eh, 
+                       HashMap<String, Properties> propMap, HashMap<String, 
Bookmarks> bookmarkMap, BookmarksUtil bkUtil) {
+               super(owner);
+               
+               this.propMap = propMap;
+               //this.bookmarks = bookmarks;
+               //this.bkUtil = bkUtil;
+               
+               try {
+                       initGUI();
+                       addListeners();
 
-       /**
-        *  DOCUMENT ME!
-        *
-        * @param tm DOCUMENT ME!
-        * @param preferenceName DOCUMENT ME!
-        * @param preferenceValue DOCUMENT ME!
-        */
-       public void setParameter(TableModel tm, final String preferenceName, 
final String preferenceValue) {
-               // preferences/properties
-               if (tm == prefsTM) {
-                       prefsTM.setProperty(preferenceName, preferenceValue);
-                       props.setProperty(preferenceName, preferenceValue);
-               }
+                       //
+                       modifyPropBtn.setEnabled(false);
+                       deletePropBtn.setEnabled(false);
+                       
 
-               refresh();
+                       initTable();
+                       initCMB();
 
-               // reset state of Modify and Delete buttons to inactive
-               // since update of parameter will clear any selections
-               modifyPropBtn.setEnabled(false);
-               deletePropBtn.setEnabled(false);
+                       updateTable();
+                       
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+
+               this.setTitle("Cytoscape Preferences Editor");
+               pack();
+               // set location relative to owner/parent
+               this.setLocationRelativeTo(owner);
+               this.setVisible(true);
+               
        }
 
-       /**
-        *  DOCUMENT ME!
-        */
-       public void refresh() {
-               // refresh the view
-               prefsTable.setModel(prefsTM);
-
-               prefsTable.clearSelection();
-               prefsTable.revalidate();
-               prefsTable.repaint();
+       
+       public void itemStateChanged(ItemEvent e) {     
+               updateTable();
        }
 
-       private void initButtonPane() {
-               propBtnPane.add(addPropBtn);
-               propBtnPane.add(modifyPropBtn);
-               propBtnPane.add(deletePropBtn);
 
-               okButtonPane.add(okButton);
-               okButtonPane.add(cancelButton);
+       private void initCMB() {
+               Object[] keys = this.propMap.keySet().toArray();
+               DefaultComboBoxModel cmbModel = new DefaultComboBoxModel(keys);
 
-               modifyPropBtn.setEnabled(false);
-               deletePropBtn.setEnabled(false);
-               addPropBtn.addActionListener(new AddPropertyListener(this));
-               modifyPropBtn.addActionListener(new 
ModifyPropertyListener(this));
-               deletePropBtn.addActionListener(new 
DeletePropertyListener(this));
-               okButton.addActionListener(new OkButtonListener(this));
-               cancelButton.addActionListener(new CancelButtonListener(this));
-               saveVizmapBtn.addItemListener(new CheckBoxListener());
-               saveCyPropsBtn.addItemListener(new CheckBoxListener());
+               this.cmbPropCategories.setModel(cmbModel);
+               
+               String key = "coreSettings";
+               
+               int index =0;
+               for (int i=0; i<keys.length; i++){
+                       if (keys[i].toString().equalsIgnoreCase(key)){
+                               index =i;
+                               break;
+                       }
+               }
+               
+               this.cmbPropCategories.setSelectedIndex(index);
        }
 
-       /**
-        *  DOCUMENT ME!
-        *
-        * @return  DOCUMENT ME!
-        */
-       public PreferenceTableModel getPTM() {
-               return prefsTM;
-       }
-
        private void initTable() {
-               prefsTM = new PreferenceTableModel(props);
-
-               prefsTable.setAutoCreateColumnsFromModel(false);
-               prefsTable.setRowSelectionAllowed(true);
-               lsm = prefsTable.getSelectionModel();
-               lsm.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
-               lsm.addListSelectionListener(new TableListener(this, lsm));
-
-               prefsTable.setModel(prefsTM);
-
+       
+               DefaultTableColumnModel cm = new DefaultTableColumnModel();
+               
                for (int i = 0; i < PreferenceTableModel.columnHeader.length; 
i++) {
                        DefaultTableCellRenderer renderer = new 
DefaultTableCellRenderer();
                        
renderer.setHorizontalAlignment(PreferenceTableModel.alignment[i]);
@@ -191,39 +172,106 @@
                        TableColumn Column = new TableColumn(i, 
PreferenceTableModel.columnWidth[i], renderer,
                                                             null);
                        
Column.setIdentifier(PreferenceTableModel.columnHeader[i]);
-                       prefsTable.addColumn(Column);
+                       
+                       cm.addColumn(Column);
                }
+
+               prefsTable.setColumnModel(cm);
+               
prefsTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        }
 
-       /**
-        * Creates a new PreferencesDialog object.
-        *
-        * @param owner  DOCUMENT ME!
-        */
-       public PreferencesDialogImpl(Frame owner,CyOperatingContextImpl 
context, CyEventHelper eh) {
-               super(owner);
-               this.context = context;
-               this.props = context.getProperties();
-               this.eh = eh;
+       
+       private void updateTable(){
+               
+               if (this.cmbPropCategories.getSelectedItem() == null){
+                       return;
+               }
+                               
+               String selectedPropertyName = 
this.cmbPropCategories.getSelectedItem().toString();
 
-               initButtonPane();
-               initTable();
+               Properties prop = this.propMap.get(selectedPropertyName);
+               
+               PreferenceTableModel m = new PreferenceTableModel(prop);
+               prefsTable.setModel(m);
+       }
+       
 
-               try {
-                       prefPopupInit();
-               } catch (Exception e) {
-                       e.printStackTrace();
+       // Handle action event from the buttons
+       public void actionPerformed(ActionEvent e) {
+               Object obj = e.getSource();
+               if (obj instanceof JButton){
+                       JButton btn = (JButton) obj;
+                       if (btn == this.closeButton){
+                               this.dispose();
+                       }
+                       else if (btn == this.deletePropBtn){                    
+                               int[] selectedIndices = 
this.prefsTable.getSelectedRows();
+                               for (int i = selectedIndices.length-1; i >= 0; 
i--) {                                   
+                                       String name = new String((String) 
(this.prefsTable.getModel().getValueAt(selectedIndices[i], 0)));
+                                       PreferenceTableModel m = 
(PreferenceTableModel)this.prefsTable.getModel();
+                                       m.deleteProperty(name);
+                               }
+                       }
+                       else if (btn == this.modifyPropBtn){                    
        
+                               int[] selectedIndices = 
this.prefsTable.getSelectedRows();
+                               for (int i = selectedIndices.length-1; i >= 0; 
i--) {                                   
+                                       String name = new String((String) 
(this.prefsTable.getModel().getValueAt(selectedIndices[i], 0)));
+                                       String value = new String((String) 
(this.prefsTable.getModel().getValueAt(selectedIndices[i], 1)));
+                                       
+                                       PreferenceTableModel m = 
(PreferenceTableModel)this.prefsTable.getModel();
+                                       PreferenceValueDialog pd = new 
PreferenceValueDialog(this, name,  value, m,
+                                                                               
                     "Modify value...");
+                               }
+                       }
+                       else if (btn == this.addPropBtn){
+                               String key = 
JOptionPane.showInputDialog(addPropBtn, "Enter property name:",
+                       "Add Property", JOptionPane.QUESTION_MESSAGE);
+
+                               if (key != null) {
+                                       String value = 
JOptionPane.showInputDialog(addPropBtn,
+                                     "Enter value for property " + key + ":",
+                                     "Add Property Value",
+                                     JOptionPane.QUESTION_MESSAGE);
+       
+                                       if (value != null) {
+                                               String[] vals = { key, value };
+                                               PreferenceTableModel m = 
(PreferenceTableModel)this.prefsTable.getModel();
+                                               
+                                               m.addProperty(vals);
+                                       }
+                               }
+                       }
                }
+       }
+       
+       
+       public void valueChanged(ListSelectionEvent e){
+       
+               if (this.prefsTable.getSelectedRowCount() == 0){
+                       this.modifyPropBtn.setEnabled(false);
+                       this.deletePropBtn.setEnabled(false);
+               }
+               else {
+                       this.modifyPropBtn.setEnabled(true);
+                       this.deletePropBtn.setEnabled(true);
+               }
+       }
 
-               this.setTitle("Cytoscape Preferences Editor");
-               pack();
-               // set location relative to owner/parent
-               this.setLocationRelativeTo(owner);
-               this.setVisible(true);
+
+       private void addListeners() {
+               addPropBtn.addActionListener(this);
+               modifyPropBtn.addActionListener(this);
+               deletePropBtn.addActionListener(this);
+               closeButton.addActionListener(this);
+
+               cmbPropCategories.addItemListener(this);
+               prefsTable.getSelectionModel().addListSelectionListener(this);
        }
 
-       private void prefPopupInit() throws Exception {
+    
 
+       private void initGUI() throws Exception {
+
                java.awt.GridBagConstraints gridBagConstraints;
 
                JPanel outerPanel = new JPanel(new java.awt.GridBagLayout());
@@ -235,14 +283,23 @@
                propsTablePane.getViewport().add(prefsTable, null);
                prefsTable.setPreferredScrollableViewportSize(new 
Dimension(400, 200));
                
+           gridBagConstraints = new java.awt.GridBagConstraints();
+           gridBagConstraints.gridx = 0;
+           gridBagConstraints.gridy = 0;
+           gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+           gridBagConstraints.insets = new java.awt.Insets(5, 7, 5, 7);
+           propsTablePanel.add(cmbPropCategories, gridBagConstraints);
+           //
+               
         gridBagConstraints = new java.awt.GridBagConstraints();
         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+        gridBagConstraints.gridy = 1;
         gridBagConstraints.weightx = 1.0;
         gridBagConstraints.weighty = 1.0;
         propsTablePanel.add(propsTablePane, gridBagConstraints);
 
         gridBagConstraints = new java.awt.GridBagConstraints();
-        gridBagConstraints.gridy = 1;
+        gridBagConstraints.gridy = 2;
         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
         gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
         propsTablePanel.add(propBtnPane, gridBagConstraints);
@@ -254,263 +311,33 @@
         gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
         outerPanel.add(propsTablePanel, gridBagConstraints);
                
-
-               JTextArea textArea = new JTextArea("NOTE: Changes to these 
properties are used in the current session ONLY unless otherwise specified 
below.");
-
-               textArea.setBackground(outerPanel.getBackground());
-               textArea.setEditable(false);
-               textArea.setDragEnabled(false);
-               textArea.setLineWrap(true);
-               textArea.setWrapStyleWord(true);
-
+        //
         gridBagConstraints = new java.awt.GridBagConstraints();
-        gridBagConstraints.gridy = 1;
-        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
-        gridBagConstraints.insets = new java.awt.Insets(0, 10, 10, 10);
-        outerPanel.add(textArea, gridBagConstraints);
-               
-               Box vizmapBox = Box.createVerticalBox();
-               vizmapBox.setBorder(BorderFactory.createTitledBorder("Default 
Visual Styles"));
-               vizmapText.setBackground(outerPanel.getBackground());
-               vizmapText.setEditable(false);
-               vizmapText.setDragEnabled(false);
-               vizmapText.setLineWrap(true);
-               vizmapText.setWrapStyleWord(true);
-               vizmapBox.add(vizmapText);
-               vizmapBox.add(Box.createVerticalStrut(5));
-               vizmapPane.add(saveVizmapBtn);
-               vizmapBox.add(vizmapPane);
-
-               gridBagConstraints = new java.awt.GridBagConstraints();
-        gridBagConstraints.gridy = 2;
-        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
-        gridBagConstraints.insets = new java.awt.Insets(0, 10, 10, 10);
-        outerPanel.add(vizmapBox, gridBagConstraints);
-               
-               Box cyPropsBox = Box.createVerticalBox();
-               cyPropsBox.setBorder(BorderFactory.createTitledBorder("Default 
Cytoscape Properties"));
-               cyPropsText.setBackground(outerPanel.getBackground());
-               cyPropsText.setEditable(false);
-               cyPropsText.setDragEnabled(false);
-               cyPropsText.setLineWrap(true);
-               cyPropsText.setWrapStyleWord(true);
-               cyPropsBox.add(cyPropsText);
-               cyPropsBox.add(Box.createVerticalStrut(5));
-               cyPropsPane.add(saveCyPropsBtn);
-               cyPropsBox.add(cyPropsPane);
-
-        gridBagConstraints = new java.awt.GridBagConstraints();
-        gridBagConstraints.gridy = 3;
-        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
-        gridBagConstraints.insets = new java.awt.Insets(0, 10, 10, 10);
-        outerPanel.add(cyPropsBox, gridBagConstraints);
-               
-        gridBagConstraints = new java.awt.GridBagConstraints();
         gridBagConstraints.gridy = 4;
         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
         gridBagConstraints.insets = new java.awt.Insets(0, 10, 10, 10);
         outerPanel.add(okButtonPane, gridBagConstraints);
         
                this.getContentPane().add(outerPanel, BorderLayout.CENTER);
-       }
+               
+               //
+               propBtnPane.add(addPropBtn);
+               propBtnPane.add(modifyPropBtn);
+               propBtnPane.add(deletePropBtn);
 
-       class AddPropertyListener implements ActionListener {
-               PreferencesDialogImpl callerRef = null;
-
-               public AddPropertyListener(PreferencesDialogImpl caller) {
-                       super();
-                       callerRef = caller;
-               }
-
-               public void actionPerformed(ActionEvent e) {
-                       String key = JOptionPane.showInputDialog(addPropBtn, 
"Enter property name:",
-                                                                "Add 
Property", JOptionPane.QUESTION_MESSAGE);
-
-                       if (key != null) {
-                               String value = 
JOptionPane.showInputDialog(addPropBtn,
-                                                                          
"Enter value for property " + key + ":",
-                                                                          "Add 
Property Value",
-                                                                          
JOptionPane.QUESTION_MESSAGE);
-
-                               if (value != null) {
-                                       String[] vals = { key, value };
-                                       prefsTM.addProperty(vals);
-                                       refresh(); // refresh view in table
-                               }
-                       }
-               }
+               okButtonPane.add(closeButton);
        }
 
-       class ModifyPropertyListener implements ActionListener {
-               PreferencesDialogImpl callerRef = null;
 
-               public ModifyPropertyListener(PreferencesDialogImpl caller) {
-                       super();
-                       callerRef = caller;
-               }
+       private JComboBox cmbPropCategories = new JComboBox();  
+       private JScrollPane propsTablePane = new JScrollPane();
+       private JTable prefsTable = new JTable();
+       private JPanel propBtnPane = new JPanel(new FlowLayout());
+       private JPanel okButtonPane = new JPanel(new FlowLayout());
+       //private JPanel cyPropsPane = new JPanel(new FlowLayout());
+       private JButton addPropBtn = new JButton("Add");
+       private JButton deletePropBtn = new JButton("Delete");
+       private JButton modifyPropBtn = new JButton("Modify");
+       private JButton closeButton = new JButton("Close");
 
-               public void actionPerformed(ActionEvent e) {
-                       for (int i = 0; i < selection.length; i++) {
-                               String name = new String((String) 
(prefsTM.getValueAt(selection[i], 0)));
-                               String value = new String((String) 
(prefsTM.getValueAt(selection[i], 1)));
-
-                               PreferenceValueDialog pd = new 
PreferenceValueDialog(PreferencesDialogImpl.this, name,
-                                                                               
     value, callerRef, prefsTM,
-                                                                               
     "Modify value...");
-                       }
-               }
-       }
-
-       class DeletePropertyListener implements ActionListener {
-               PreferencesDialogImpl callerRef = null;
-
-               public DeletePropertyListener(PreferencesDialogImpl caller) {
-                       super();
-                       callerRef = caller;
-               }
-
-               public void actionPerformed(ActionEvent e) {
-                       for (int i = 0; i < selection.length; i++) {
-                               String name = new String((String) 
(prefsTM.getValueAt(selection[i], 0)));
-                               prefsTM.deleteProperty(name);
-                       }
-
-                       refresh();
-               }
-       }
-
-       class OkButtonListener implements ActionListener {
-               PreferencesDialogImpl callerRef = null;
-
-               public OkButtonListener(PreferencesDialogImpl caller) {
-                       super();
-                       callerRef = caller;
-               }
-
-               public void actionPerformed(ActionEvent e) {
-                       // just saving via putAll() doesn't handle deletes...
-                       // therefore use TableModel's putAll() into new 
Properties obj
-                       // then clear Cytoscape's properties and
-                       Properties newProps = new Properties();
-                       callerRef.prefsTM.save(newProps);
-                       props.clear();
-                       props.putAll(newProps);
-                       callerRef.setVisible(false);
-
-                       if (saveVizmapAsDefault) {
-                               // TODO: Use new VizMap
-//                             eh.fireSynchronousEvent( new 
SaveVizmapPropsEvent() {
-//                                     public Object getSource() { return 
PreferencesDialogImpl.this; }
-//                                     }, SaveVizmapPropsListener.class );
-//                             saveVizmapAsDefault = false;
-//                             saveVizmapBtn.setSelected(false);
-                       }
-
-                       if (saveCyPropsAsDefault) {
-                               try {
-                                       File file = 
context.getConfigFile("cytoscape.props");
-                                       FileOutputStream output = new 
FileOutputStream(file);
-                                       props.store(output, "Cytoscape Property 
File");
-                                       logger.debug("wrote Cytoscape 
properties file to: "
-                                                          + 
file.getAbsolutePath());
-                               } catch (Exception ex) {
-                                       ex.printStackTrace();
-                                       logger.warn("Could not write 
cytoscape.props file!");
-                               }
-
-                               saveCyPropsAsDefault = false;
-                               saveCyPropsBtn.setSelected(false);
-                       }
-
-                       final Properties op = props;
-                       final Properties np = newProps;
-
-                       eh.fireSynchronousEvent( new 
PreferencesUpdatedEvent(PreferencesDialogImpl.this, op, np));
-               }
-       }
-
-       class CheckBoxListener implements ItemListener {
-               public CheckBoxListener() {
-                       super();
-               }
-
-               public void itemStateChanged(ItemEvent e) {
-                       Object source = e.getItemSelectable();
-
-                       if (e.getStateChange() == ItemEvent.SELECTED) {
-                               if (source == saveVizmapBtn)
-                                       saveVizmapAsDefault = true;
-
-                               if (source == saveCyPropsBtn)
-                                       saveCyPropsAsDefault = true;
-                       }
-               }
-       }
-
-       class CancelButtonListener implements ActionListener {
-               PreferencesDialogImpl callerRef = null;
-
-               public CancelButtonListener(PreferencesDialogImpl caller) {
-                       super();
-                       callerRef = caller;
-               }
-
-               public void actionPerformed(ActionEvent e) {
-                       Properties oldProps = props;
-                       callerRef.prefsTM.restore(oldProps);
-                       callerRef.setVisible(false);
-               }
-       }
-
-       class TableListener implements ListSelectionListener {
-               private ListSelectionModel model = null;
-               private PreferencesDialogImpl motherRef = null;
-
-               public TableListener(PreferencesDialogImpl mother, 
ListSelectionModel lsm) {
-                       motherRef = mother;
-                       model = lsm;
-               }
-
-               public void valueChanged(ListSelectionEvent lse) {
-                       if (!lse.getValueIsAdjusting()) {
-                               StringBuffer buf = new StringBuffer();
-                               selection = 
getSelectedIndices(model.getMinSelectionIndex(),
-                                                              
model.getMaxSelectionIndex());
-
-                               if (selection.length == 0) {
-                               } else {
-                                       modifyPropBtn.setEnabled(true);
-                                       deletePropBtn.setEnabled(true);
-                               }
-                       }
-               }
-
-               protected int[] getSelectedIndices(int start, int stop) {
-                       if ((start == -1) || (stop == -1)) {
-                               return new int[0];
-                       }
-
-                       int[] guesses = new int[stop - start + 1];
-                       int index = 0;
-
-                       for (int i = start; i <= stop; i++) {
-                               if (model.isSelectedIndex(i)) {
-                                       guesses[index++] = i;
-                               }
-                       }
-
-                       int[] realthing = new int[index];
-                       System.arraycopy(guesses, 0, realthing, 0, index);
-
-                       return realthing;
-               }
-
-               public void actionPerformed(ActionEvent e) {
-               }
-       }
-
-       public void showDialog() {
-               refresh();
-               setVisible(true);
-       }
 }

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