Author: kono
Date: 2011-11-16 18:18:39 -0800 (Wed, 16 Nov 2011)
New Revision: 27508

Added:
   
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/CustomHeaderRenderer.java
   
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/util/
   
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/util/ColumnResizer.java
Removed:
   
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/MyTableHeaderRenderer.java
Modified:
   
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/AbstractTableBrowser.java
   
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/AttributeBrowserToolBar.java
   
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/BrowserTable.java
   
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/BrowserTableModel.java
   
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/DefaultTableBrowser.java
Log:
Lots of cosmetic issues had been fixed.  Column width adjuster added.

Modified: 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/AbstractTableBrowser.java
===================================================================
--- 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/AbstractTableBrowser.java
  2011-11-17 00:54:15 UTC (rev 27507)
+++ 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/AbstractTableBrowser.java
  2011-11-17 02:18:39 UTC (rev 27508)
@@ -19,6 +19,7 @@
 import org.cytoscape.application.CyApplicationManager;
 import org.cytoscape.application.swing.CytoPanelComponent;
 import org.cytoscape.application.swing.CytoPanelName;
+import org.cytoscape.browser.internal.util.ColumnResizer;
 import org.cytoscape.equations.EquationCompiler;
 import org.cytoscape.event.CyEventHelper;
 import org.cytoscape.model.CyNetworkManager;
@@ -125,6 +126,9 @@
                currentScrollPane = newScrollPane;
                applicationManager.setCurrentTable(currentTable);
                
attributeBrowserToolBar.setBrowserTableModel(currentBrowserTableModel);
+               
+               // Resize column
+               
ColumnResizer.adjustColumnPreferredWidths(currentBrowserTableModel.getTable());
        }
 
        private JScrollPane getScrollPane(final BrowserTableModel 
browserTableModel) {

Modified: 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/AttributeBrowserToolBar.java
===================================================================
--- 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/AttributeBrowserToolBar.java
       2011-11-17 00:54:15 UTC (rev 27507)
+++ 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/AttributeBrowserToolBar.java
       2011-11-17 02:18:39 UTC (rev 27508)
@@ -451,12 +451,12 @@
                                                                
.addPreferredGap(ComponentPlacement.RELATED)
                                                                
.addComponent(getSelectButton())
                                                                
.addPreferredGap(ComponentPlacement.RELATED)
-                                                               
.addComponent(getNewButton())
-                                                               
.addPreferredGap(ComponentPlacement.RELATED)
                                                                
.addComponent(getSelectAllButton())
                                                                
.addPreferredGap(ComponentPlacement.RELATED)
                                                                
.addComponent(getUnselectAllButton())
                                                                
.addPreferredGap(ComponentPlacement.RELATED)
+                                                               
.addComponent(getNewButton())
+                                                               
.addPreferredGap(ComponentPlacement.RELATED)
                                                                
.addComponent(getDeleteButton())
                                                                
.addPreferredGap(ComponentPlacement.RELATED)
                                                                
.addComponent(getDeleteTableButton())
@@ -472,19 +472,18 @@
                                                                       
javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                       27,
                                                                       
Short.MAX_VALUE)
-                                                        
.addComponent(createNewAttributeButton,
+                                                        
.addComponent(selectAllAttributesButton,
                                                                       
javax.swing.GroupLayout.Alignment.CENTER,
                                                                       
javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                       27, 
Short.MAX_VALUE)
-                                                        
.addComponent(selectAllAttributesButton,
+                                                        
.addComponent(unselectAllAttributesButton,
                                                                       
javax.swing.GroupLayout.Alignment.CENTER,
                                                                       
javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                       27, 
Short.MAX_VALUE)
-                                                        
.addComponent(unselectAllAttributesButton,
+                                                       
.addComponent(createNewAttributeButton,
                                                                       
javax.swing.GroupLayout.Alignment.CENTER,
                                                                       
javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                       27, 
Short.MAX_VALUE)
-
                                                         
.addComponent(deleteAttributeButton,
                                                                       
javax.swing.GroupLayout.Alignment.CENTER,
                                                                       
javax.swing.GroupLayout.DEFAULT_SIZE,

Modified: 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/BrowserTable.java
===================================================================
--- 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/BrowserTable.java
  2011-11-17 00:54:15 UTC (rev 27507)
+++ 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/BrowserTable.java
  2011-11-17 02:18:39 UTC (rev 27508)
@@ -126,17 +126,20 @@
        }
 
        protected void initHeader() {
+               this.setBackground(Color.white);
+               
                final JTableHeader header = getTableHeader();
                header.addMouseMotionListener(this);
-//             header.setDefaultRenderer(new SortHeaderRenderer());
-               header.setDefaultRenderer(new MyTableHeaderRenderer());
+               header.setBackground(Color.white);
+               header.setOpaque(false);
+               header.setDefaultRenderer(new CustomHeaderRenderer());
                header.addMouseListener(this);
+               header.getColumnModel().setColumnSelectionAllowed(true);
 
                
setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
 
                final BrowserTable table = this;
 
-
                // Event handler. Define actions when mouse is clicked.
                addMouseListener(new MouseAdapter() {
                                public void mouseClicked(MouseEvent e) {

Modified: 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/BrowserTableModel.java
===================================================================
--- 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/BrowserTableModel.java
     2011-11-17 00:54:15 UTC (rev 27507)
+++ 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/BrowserTableModel.java
     2011-11-17 02:18:39 UTC (rev 27508)
@@ -232,10 +232,11 @@
        public void handleEvent(final ColumnCreatedEvent e) {
                if (e.getSource() != dataTable)
                        return;
-
                attrNamesAndVisibilities.add(new 
AttrNameAndVisibility(e.getColumnName(), true));
                fireTableStructureChanged();
        }
+       
+       
 
        @Override
        public void handleEvent(final ColumnDeletedEvent e) {

Copied: 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/CustomHeaderRenderer.java
 (from rev 27489, 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/MyTableHeaderRenderer.java)
===================================================================
--- 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/CustomHeaderRenderer.java
                          (rev 0)
+++ 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/CustomHeaderRenderer.java
  2011-11-17 02:18:39 UTC (rev 27508)
@@ -0,0 +1,130 @@
+/*
+ Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications.  In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage.  See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+package org.cytoscape.browser.internal;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Font;
+
+import javax.swing.JLabel;
+import javax.swing.JTable;
+import javax.swing.border.Border;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.MatteBorder;
+import javax.swing.table.TableCellRenderer;
+
+import org.cytoscape.model.CyColumn;
+import org.cytoscape.model.CyTableEntry;
+
+final class CustomHeaderRenderer extends JLabel implements TableCellRenderer {
+
+       private static final long serialVersionUID = 4656466166588715282L;
+
+       private static final int FONT_SIZE = 12;
+
+       private static final Font COLUMN_FONT = new Font("SansSerif", 
Font.PLAIN, FONT_SIZE);
+       private static final Font COLUMN_SUID_FONT = new Font("SansSerif", 
Font.BOLD, FONT_SIZE);
+
+       private static final Color COLUMN_COLOR = new Color(0xa0, 0xa0, 0xa0, 
60);
+       private static final Color COLUMN_VIRTUAL_COLOR = new Color(0x00, 0x9A, 
0xCD, 70);
+       private static final Color COLUMN_TITLE_COLOR = new Color(0x10, 0x10, 
0x10);
+
+       private static final Color BORDER_COLOR = new Color(0x10, 0x10, 0x10, 
120);
+       private static final Border BORDER_INSIDE = new EmptyBorder(4, 3, 4, 3);
+       private static final Border BORDER_OUTSIDE = new MatteBorder(0, 0, 1, 
1, BORDER_COLOR);
+       private static final Border BORDER = new CompoundBorder(BORDER_OUTSIDE, 
BORDER_INSIDE);
+
+       CustomHeaderRenderer() {
+               setBorder(BORDER);
+               this.setHorizontalTextPosition(CENTER);
+               this.setHorizontalAlignment(CENTER);
+       }
+
+       // This method is called each time a column header
+       // using this renderer needs to be rendered.
+       public Component getTableCellRendererComponent(final JTable table, 
final Object value, boolean isSelected,
+                       boolean hasFocus, int rowIndex, int vColIndex) {
+
+               this.setOpaque(true);
+
+               // 'value' is column header value of column 'vColIndex'
+               // rowIndex is always -1
+               // isSelected is always false
+               // hasFocus is always false
+
+               // Configure the component with the specified value
+               final String text = value.toString();
+               setText(text);
+
+               if (!(table.getModel() instanceof BrowserTableModel))
+                       return this;
+
+               final BrowserTableModel model = (BrowserTableModel) 
table.getModel();
+               final CyColumn col = 
model.getAttributes().getColumn(value.toString());
+               if (col == null)
+                       return this;
+
+               String toolTip = col.getType().getName();
+               if (col.getVirtualColumnInfo().isVirtual()) {
+                       setForeground(COLUMN_TITLE_COLOR);
+                       setBackground(COLUMN_VIRTUAL_COLOR);
+                       toolTip = "<html>" + col.getType().getName() + "<br 
/>Virtual Column</html>";
+               } else {
+                       setForeground(COLUMN_TITLE_COLOR);
+                       setBackground(COLUMN_COLOR);
+               }
+
+               if (text.equals(CyTableEntry.SUID))
+                       this.setFont(COLUMN_SUID_FONT);
+               else
+                       this.setFont(COLUMN_FONT);
+
+               // Set tool tip if desired
+               setToolTipText(toolTip);
+
+               // Since the renderer is a component, return itself
+               return this;
+       }
+
+       //
+       // The following methods override the defaults for performance reasons
+       //
+       public void validate() {
+       }
+
+       public void revalidate() {
+       }
+
+       protected void firePropertyChange(String propertyName, Object oldValue, 
Object newValue) {
+       }
+
+       public void firePropertyChange(String propertyName, boolean oldValue, 
boolean newValue) {
+       }
+}

Modified: 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/DefaultTableBrowser.java
===================================================================
--- 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/DefaultTableBrowser.java
   2011-11-17 00:54:15 UTC (rev 27507)
+++ 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/DefaultTableBrowser.java
   2011-11-17 02:18:39 UTC (rev 27508)
@@ -91,6 +91,7 @@
                rowSelectionMode = selectionModeButton.isSelected();
                getCurrentBrowserTableModel().setShowAll(rowSelectionMode);
                getCurrentBrowserTableModel().updateShowAll();
+
        }
        
        @Override

Deleted: 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/MyTableHeaderRenderer.java
===================================================================
--- 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/MyTableHeaderRenderer.java
 2011-11-17 00:54:15 UTC (rev 27507)
+++ 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/MyTableHeaderRenderer.java
 2011-11-17 02:18:39 UTC (rev 27508)
@@ -1,104 +0,0 @@
-/*
- Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
-
- This library is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of the License, or
- any later version.
-
- This library is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
- MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
- documentation provided hereunder is on an "as is" basis, and the
- Institute for Systems Biology and the Whitehead Institute
- have no obligations to provide maintenance, support,
- updates, enhancements or modifications.  In no event shall the
- Institute for Systems Biology and the Whitehead Institute
- be liable to any party for direct, indirect, special,
- incidental or consequential damages, including lost profits, arising
- out of the use of this software and its documentation, even if the
- Institute for Systems Biology and the Whitehead Institute
- have been advised of the possibility of such damage.  See
- the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this library; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-*/
-package org.cytoscape.browser.internal;
-
-
-import java.awt.Color;
-import java.awt.Component;
-import javax.swing.JLabel;
-import javax.swing.JTable;
-import javax.swing.border.BevelBorder;
-import javax.swing.table.TableCellRenderer;
-import org.cytoscape.model.CyColumn;
-
-
-final class MyTableHeaderRenderer extends JLabel implements TableCellRenderer {
-       
-       private static Color defaultBackground = null;
-       private static Color defaultForeground = null;
-       
-       MyTableHeaderRenderer() {
-               setBorder(new BevelBorder(BevelBorder.RAISED));
-       }
-
-       // This method is called each time a column header
-       // using this renderer needs to be rendered.
-       public Component getTableCellRendererComponent(final JTable table, 
final Object value,
-                                                      boolean isSelected, 
boolean hasFocus, int rowIndex, int vColIndex)
-       {
-               if (defaultBackground == null)
-                       defaultBackground = getBackground();
-
-               if (defaultForeground == null)
-                       defaultForeground = getForeground();
-               
-               // 'value' is column header value of column 'vColIndex'
-               // rowIndex is always -1
-               // isSelected is always false
-               // hasFocus is always false
-
-               // Configure the component with the specified value
-               setText(value.toString());
-               setForeground(defaultForeground);
-               setBackground(defaultBackground);
-
-               if (!(table.getModel() instanceof BrowserTableModel)) 
-                       return this;
-               
-               BrowserTableModel model = (BrowserTableModel)table.getModel();
-               CyColumn col = 
model.getAttributes().getColumn(value.toString());
-               if ( col == null ) 
-                       return this;
-               
-               String toolTip = col.getType().getName();
-               if(col.getVirtualColumnInfo().isVirtual()){
-                       setForeground(defaultForeground);
-                       setBackground(Color.lightGray);
-                       setOpaque(true);
-                       toolTip = "<html>" + col.getType().getName()+ "<br 
/>Virtual Column</html>";
-               } 
-               
-               // Set tool tip if desired
-        setToolTipText(toolTip);
-               
-               // Since the renderer is a component, return itself
-               return this;
-       }
-
-       //
-       // The following methods override the defaults for performance reasons
-       //
-
-       public void validate() { }
-
-       public void revalidate() { }
-
-       protected void firePropertyChange(String propertyName, Object oldValue, 
Object newValue) { }
-
-       public void firePropertyChange(String propertyName, boolean oldValue, 
boolean newValue) { }
-}

Added: 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/util/ColumnResizer.java
===================================================================
--- 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/util/ColumnResizer.java
                            (rev 0)
+++ 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/util/ColumnResizer.java
    2011-11-17 02:18:39 UTC (rev 27508)
@@ -0,0 +1,114 @@
+package org.cytoscape.browser.internal.util;
+
+import java.awt.Component;
+import java.util.HashMap;
+
+import javax.swing.JTable;
+import javax.swing.table.TableCellRenderer;
+import javax.swing.table.TableColumn;
+import javax.swing.table.TableColumnModel;
+
+/**
+ * 
+ * Automatically resize column based on the objects in the cell.<br>
+ * 
+ * <p>
+ * From <i>Swing Hacks</i> by Joshua Marinacci and Chris Adamson.<br>
+ * 2005 Oreilly & Associates Inc. ISBN: 0-596-00907-0<br>
+ * </p>
+ * Customized by Keiichiro Ono
+ * 
+ * @author Joshua Marinacci, Chris Adamson, Keiichiro Ono
+ * 
+ */
+public class ColumnResizer {
+       private static final int DEFLMAX_WIDTH = 280;
+
+       public static void adjustColumnPreferredWidths(JTable table) {
+               // strategy - get max width for cells in column and
+               // make that the preferred width
+               TableColumnModel columnModel = table.getColumnModel();
+
+               for (int col = 0; col < table.getColumnCount(); col++) {
+                       int maxwidth = 0;
+
+                       for (int row = 0; row < table.getRowCount(); row++) {
+                               TableCellRenderer rend = 
table.getCellRenderer(row, col);
+                               Object value = table.getValueAt(row, col);
+                               Component comp = 
rend.getTableCellRendererComponent(table, value, false, false, row, col);
+                               maxwidth = 
Math.max(comp.getPreferredSize().width, maxwidth);
+                       } // for row
+
+                       /*
+                        * this version of the width set considers the column 
header's
+                        * preferred width too
+                        */
+                       TableColumn column = columnModel.getColumn(col);
+                       TableCellRenderer headerRenderer = 
column.getHeaderRenderer();
+
+                       if (headerRenderer == null)
+                               headerRenderer = 
table.getTableHeader().getDefaultRenderer();
+
+                       Object headerValue = column.getHeaderValue();
+                       Component headerComp = 
headerRenderer.getTableCellRendererComponent(table, headerValue, false, false, 
0,
+                                       col);
+                       maxwidth = Math.max(maxwidth, 
headerComp.getPreferredSize().width);
+
+                       /*
+                        * If the value is too big, adjust to fixed maximum val.
+                        */
+                       if (DEFLMAX_WIDTH < maxwidth) {
+                               maxwidth = DEFLMAX_WIDTH;
+                       }
+
+                       column.setPreferredWidth(maxwidth + 20);
+               } // for col
+       }
+
+       public static HashMap<String, Integer> getColumnPreferredWidths(JTable 
table) {
+
+               HashMap<String, Integer> retMap = new HashMap<String, 
Integer>();
+
+               // strategy - get max width for cells in column and
+               // make that the preferred width
+               TableColumnModel columnModel = table.getColumnModel();
+
+               for (int col = 0; col < table.getColumnCount(); col++) {
+                       int maxwidth = 0;
+
+                       for (int row = 0; row < table.getRowCount(); row++) {
+                               TableCellRenderer rend = 
table.getCellRenderer(row, col);
+                               Object value = table.getValueAt(row, col);
+                               Component comp = 
rend.getTableCellRendererComponent(table, value, false, false, row, col);
+                               maxwidth = 
Math.max(comp.getPreferredSize().width, maxwidth);
+                       } // for row
+
+                       /*
+                        * this version of the width set considers the column 
header's
+                        * preferred width too
+                        */
+                       TableColumn column = columnModel.getColumn(col);
+                       TableCellRenderer headerRenderer = 
column.getHeaderRenderer();
+
+                       if (headerRenderer == null)
+                               headerRenderer = 
table.getTableHeader().getDefaultRenderer();
+
+                       Object headerValue = column.getHeaderValue();
+                       Component headerComp = 
headerRenderer.getTableCellRendererComponent(table, headerValue, false, false, 
0,
+                                       col);
+                       maxwidth = Math.max(maxwidth, 
headerComp.getPreferredSize().width);
+
+                       /*
+                        * If the value is too big, adjust to fixed maximum val.
+                        */
+                       if (DEFLMAX_WIDTH < maxwidth) {
+                               maxwidth = DEFLMAX_WIDTH;
+                       }
+
+                       retMap.put(headerValue.toString(), new Integer(maxwidth 
+ 20));
+               } // for col
+
+               return retMap;
+       }
+
+}

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