[MOBY-guts] biomoby commit

Martin Senger senger at pub.open-bio.org
Sun Nov 6 05:31:35 UTC 2005


senger
Sun Nov  6 00:31:35 EST 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard
In directory pub.open-bio.org:/tmp/cvs-serv3367/src/main/org/biomoby/service/dashboard

Modified Files:
	NOTES RegistrationPanel.java 
Log Message:


moby-live/Java/src/main/org/biomoby/service/dashboard NOTES,1.17,1.18 RegistrationPanel.java,1.9,1.10
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/NOTES,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/NOTES	2005/11/05 17:51:04	1.17
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/NOTES	2005/11/06 05:31:35	1.18
@@ -127,9 +127,6 @@
 * The same, after de-registration
 * Then make the reg/unreg real...
 
-* Icons:
-  - better icon for AddHAS (with a small star)
-  ? small icons to buttons
 
 * alltools2:
   - JTextFieldWithHistory should remember also an empty value ("")

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/RegistrationPanel.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/RegistrationPanel.java	2005/11/05 20:14:49	1.9
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/dashboard/RegistrationPanel.java	2005/11/06 05:31:35	1.10
@@ -38,12 +38,14 @@
 import javax.swing.JTextArea;
 import javax.swing.JTabbedPane;
 import javax.swing.JTable;
+import javax.swing.JList;
 import javax.swing.JComboBox;
 import javax.swing.JPopupMenu;
 import javax.swing.JMenuItem;
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.AbstractAction;
 import javax.swing.JComponent;
+import javax.swing.ListCellRenderer;
 import javax.swing.DefaultListModel;
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.DefaultCellEditor;
@@ -59,6 +61,8 @@
 import javax.swing.AbstractCellEditor;
 import javax.swing.BorderFactory;
 import javax.swing.border.Border;
+import javax.swing.event.PopupMenuListener;
+import javax.swing.event.PopupMenuEvent;
 
 import java.awt.GridBagLayout;
 import java.awt.Font;
@@ -175,20 +179,15 @@
      ********************************************************************/
     protected void loadIcons() {
 	super.loadIcons();
-	if (menuAddISAIcon == null) 
-	    menuAddISAIcon = loadIcon ("images/smallAddISA.gif");
-	if (menuAddISAIconDis == null)
-	    menuAddISAIconDis = loadIcon ("images/smallAddISA_dis.gif");
+
+	if (menuAddISAIcon == null) menuAddISAIcon = loadIcon ("images/smallAddISA.gif");
+	if (menuAddISAIconDis == null) menuAddISAIconDis = loadIcon ("images/smallAddISA_dis.gif");
 	
-	if (menuAddHASAIcon == null)
-	    menuAddHASAIcon = loadIcon ("images/smallAddHASA.gif");
-	if (menuAddHASAIconDis == null)
-	    menuAddHASAIconDis = loadIcon ("images/smallAddHASA_dis.gif");
+	if (menuAddHASAIcon == null) menuAddHASAIcon = loadIcon ("images/smallAddHASA.gif");
+	if (menuAddHASAIconDis == null) menuAddHASAIconDis = loadIcon ("images/smallAddHASA_dis.gif");
 	
-	if (menuAddHASIcon == null)
-	    menuAddHASIcon = loadIcon ("images/smallAddHAS.gif");
-	if (menuAddHASIconDis == null)
-	    menuAddHASIconDis = loadIcon ("images/smallAddHAS_dis.gif");
+	if (menuAddHASIcon == null) menuAddHASIcon = loadIcon ("images/smallAddHAS.gif");
+	if (menuAddHASIconDis == null) menuAddHASIconDis = loadIcon ("images/smallAddHAS_dis.gif");
 	
 	if (menuUnregisterIcon == null) menuUnregisterIcon = loadIcon ("images/smallTrash.gif");
 	if (menuUnregisterIconDis == null) menuUnregisterIconDis = loadIcon ("images/smallTrash_dis.gif");
@@ -196,19 +195,14 @@
 	if (registerIcon == null) registerIcon = loadIcon ("images/smallRegister.gif");
 	if (registerIconDis == null) registerIconDis = loadIcon ("images/smallRegister_dis.gif");
 
-	if (addDataIcon == null)
-	    addDataIcon = loadIcon ("images/smallAddData.gif");
-	if (addDataIconDis == null)
-	    addDataIconDis = loadIcon ("images/smallAddData_dis.gif");
-
-	if (editDataIcon == null)
-	    editDataIcon = loadIcon ("images/smallEdit.gif");
-	if (editDataIconDis == null)
-	    editDataIconDis = loadIcon ("images/smallEdit_dis.gif");
+	if (addDataIcon == null) addDataIcon = loadIcon ("images/smallAddData.gif");
+	if (addDataIconDis == null) addDataIconDis = loadIcon ("images/smallAddData_dis.gif");
+
+	if (editDataIcon == null) editDataIcon = loadIcon ("images/smallEdit.gif");
+	if (editDataIconDis == null) editDataIconDis = loadIcon ("images/smallEdit_dis.gif");
 
 	if (deleteDataIcon == null) deleteDataIcon = loadIcon ("images/smallRemove.gif");
 	if (trashIcon == null) trashIcon = loadIcon ("images/smallTrash.gif");
-
     }
 
     /**************************************************************************
@@ -675,12 +669,59 @@
 	}
     }
 
-    /**************************************************************************
+   /**************************************************************************
      *
      **************************************************************************/
     class NamespaceEditor extends AbstractCellEditor
 	implements TableCellEditor {
+
+	// this is what is diplay when some namespaces are present
 	DefaultComboBoxModel comboModel = new DefaultComboBoxModel();
+	JComboBox comboBox;
+
+	// used when there are no namespaces (so a combo box is useless)
+	DefaultTableCellRenderer defaultRenderer = new DefaultTableCellRenderer();
+
+	// remember where this combo box is located it (we will need
+	// it to fire 'table update' when we remove some namespaces)
+	JTable table;
+	int row, col;
+
+	// remember where the displayed namespaces come from
+	MobyPrimaryDataSimple lastSimple = null;
+
+	public NamespaceEditor() {
+	    defaultRenderer.setText ("");
+	    comboBox = new JComboBox (comboModel);
+	    comboBox.setOpaque (true);
+	    comboBox.setRenderer (new ComboBoxRenderer());
+	    comboBox.addActionListener (new ActionListener() {
+		    public void actionPerformed (ActionEvent e) {
+			if ( (e.getModifiers() & ActionEvent.CTRL_MASK) > 0) {
+			    JComboBox cb = (JComboBox)e.getSource();
+			    Object selectedItem = cb.getSelectedItem();
+			    if (selectedItem != null) {
+				String namespace = selectedItem.toString();
+				if (lastSimple != null) {
+				    lastSimple.removeNamespace (namespace);
+				    ((AbstractTableModel)table.getModel()).fireTableCellUpdated (row, col);
+
+				}
+			    }
+			}
+			 // make the renderer reappear
+			fireEditingStopped();
+		    }
+		});
+	    comboBox.addPopupMenuListener (new PopupMenuListener() {
+		    public void popupMenuCanceled (PopupMenuEvent e) {
+			// make the renderer reappear
+			fireEditingStopped();
+		    }
+		    public void popupMenuWillBecomeVisible (PopupMenuEvent e) {}
+		    public void popupMenuWillBecomeInvisible (PopupMenuEvent e) {}
+		});
+	}
 
 	public Object getCellEditorValue() {
 	    return null;
@@ -689,28 +730,63 @@
 	public Component getTableCellEditorComponent (JTable table,
 						      Object value,
 						      boolean isSelected,
-						      int row, int column) {
+						      int row, int col) {
 
-	    JComboBox comboBox = new JComboBox (comboModel);
-	    comboBox.setOpaque (true);
-	    createPopups ("Namespace Menu", comboBox);
+	    // remember (used when a namespace is being deleted)
+	    this.table = table;
+	    this.row = row;
+	    this.col = col;
 
-	    MobyPrimaryDataSimple simple = null;
+	    // fill combo box with the current namespaces
+	    lastSimple = null;
 	    if (value instanceof MobyPrimaryDataSimple) {
-		simple = (MobyPrimaryDataSimple)value;
+		lastSimple = (MobyPrimaryDataSimple)value;
 	    } else if (value instanceof MobyPrimaryDataSet) {
 		MobyPrimaryDataSimple[] simples = ((MobyPrimaryDataSet)value).getElements();
 		if (simples.length > 0)
-		    simple = simples[0];
+		    lastSimple = simples[0];
 	    }
-	    if (simple != null) {
-		MobyNamespace[] nss = simple.getNamespaces();
-		comboModel.removeAllElements();
-		for (int i = 0; i < nss.length; i++) {
-		    comboModel.addElement (nss[i].getName());
+	    if (lastSimple != null) {
+		MobyNamespace[] nss = lastSimple.getNamespaces();
+		if (nss.length > 0) {
+		    comboModel.removeAllElements();
+		    for (int i = 0; i < nss.length; i++)
+			comboModel.addElement (nss[i].getName());
+		    return comboBox;
 		}
 	    }
-	    return comboBox;
+	    return defaultRenderer;
+	}
+    }
+
+    /**************************************************************************
+     *
+     **************************************************************************/
+    class ComboBoxRenderer extends JLabel
+	implements ListCellRenderer {
+
+	public ComboBoxRenderer() {
+	    setOpaque (true);
+	    setIcon (trashIcon);
+	}
+
+	public Component getListCellRendererComponent (JList list,
+						       Object value,
+						       int index,
+						       boolean isSelected,
+						       boolean cellHasFocus) {
+	    if (isSelected) {
+		setBackground (list.getSelectionBackground());
+		setForeground (list.getSelectionForeground());
+		if (index > -1)
+		    list.setToolTipText ("To remove a namespce, hold CTRL and select it");
+
+	    } else {
+		setBackground (list.getBackground());
+		setForeground (list.getForeground());
+	    }
+	    setText (value == null ? "" : value.toString());
+	    return this;
 	}
     }
 
@@ -1999,7 +2075,6 @@
 		int[] rows = table.getSelectedRows();
 		for (int i = 0; i < rows.length; i++) {
 		    String value = nodeObject.getValue();
-// 		    table.setValueAt (value, rows[i], PrimaryDataTableModel.COL_DATATYPE);
 		    Object data = table.getValueAt (rows[i],PrimaryDataTableModel.COL_NAMESPACE);
 		    MobyPrimaryDataSimple simple = null;
 		    if (data instanceof MobyPrimaryDataSimple) {
@@ -2017,58 +2092,4 @@
 	    }
 	}
     }
-
-
-
-
-    protected JPopupMenu popup;
-
-    /*********************************************************************
-     * Create a popup object with common items. Subclasses can (and
-     * usually do) add more items, or re-created the whole popup. <p>
-     *
-     * @param title is given to the popups
-     ********************************************************************/
-    protected void createPopups (String title, JComponent component) {
-	System.out.println ("POPUP");
-	popup = new JPopupMenu (title);
-	popup.add
-	    (CommonTree.createMenuItem (new AbstractAction ("Remove") {
-		    public void actionPerformed (ActionEvent e) {
-		    }
-		}, "R", trashIcon, trashIcon));
-
-	// add listener to this tree to bring up popup menus
-	MouseListener popupListener = new PopupListener();
-	component.addMouseListener (popupListener);
-    }
-
-    class PopupListener extends MouseAdapter {
-	public void mousePressed (MouseEvent e) {
-	    maybeShowPopup (e);
-	}
-	public void mouseReleased (MouseEvent e) {
-	    maybeShowPopup (e);
-	}
-	private void maybeShowPopup (MouseEvent e) {
-	    System.out.println ("ME: " + e);
-	    if (e.isPopupTrigger() && popup.isEnabled()) {
-		popup.show (e.getComponent(),
-			e.getX(), e.getY());
-	    }
-	}
-    }
-
-
-
-
-
-
-
-
-
-
-
-
-
 }




More information about the MOBY-guts mailing list