[Mc4j-cvs] mc4j/src/org/mc4j/console/dashboard/components AttributeTableComponent.java,1.9,1.10 Attr
Brought to you by:
ghinkl
From: Greg H. <gh...@us...> - 2005-03-14 16:06:06
|
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/console/dashboard/components In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23769/src/org/mc4j/console/dashboard/components Modified Files: AttributeTableComponent.java AttributeTablePopupComponent.java Log Message: Fixed requirement on 1.5, utilizing JDNC now Index: AttributeTableComponent.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/dashboard/components/AttributeTableComponent.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** AttributeTableComponent.java 5 Oct 2004 05:16:00 -0000 1.9 --- AttributeTableComponent.java 14 Mar 2005 16:05:37 -0000 1.10 *************** *** 17,21 **** --- 17,29 ---- package org.mc4j.console.dashboard.components; + import org.jdesktop.jdnc.JNTable; + import org.jdesktop.swing.JXTable; + import org.jdesktop.swing.decorator.AlternateRowHighlighter; + import org.jdesktop.swing.decorator.ComponentAdapter; + import org.jdesktop.swing.decorator.ConditionalHighlighter; + import org.jdesktop.swing.decorator.Highlighter; + import org.jdesktop.swing.decorator.HighlighterPipeline; import org.mc4j.console.bean.MBeanNode; + import org.mc4j.console.bean.operation.OperationNode; import org.mc4j.console.bean.attribute.AttributeNode; import org.mc4j.console.connection.ConnectionNode; *************** *** 23,26 **** --- 31,36 ---- import org.mc4j.console.swing.table.TableMap; import org.mc4j.console.swing.table.TableSorter; + import org.mc4j.console.swing.editor.ButtonRenderer; + import org.mc4j.console.swing.editor.ButtonEditor; import javax.swing.*; *************** *** 38,42 **** /** - * * @author Greg Hinkle (gh...@us...), January 2004 * @version $Revision$($Author$ / $Date$) --- 48,51 ---- *************** *** 49,57 **** protected MBeanNode mbeanNode; ! protected String label = ""; protected JScrollPane scrollPane; ! protected JTable table; protected TableSorter tableSorter; protected AttributeTableModel tableModel; --- 58,66 ---- protected MBeanNode mbeanNode; ! protected String label = ""; protected JScrollPane scrollPane; ! protected JXTable table; protected TableSorter tableSorter; protected AttributeTableModel tableModel; *************** *** 62,73 **** this.attributeNames.add(name); } ! public String getAttributeName() { return "multi-value set"; } - - private static final Font NAME_FONT = Font.decode("Arial-BOLD-12"); - private static final Font VALUE_FONT = Font.decode("Arial-PLAIN-12"); --- 71,81 ---- this.attributeNames.add(name); } ! public String getAttributeName() { return "multi-value set"; } + private static final Font NAME_FONT = Font.decode("Arial-BOLD-12"); + private static final Font VALUE_FONT = Font.decode("Arial-BOLD-10"); *************** *** 77,83 **** public void init() { ! this.removeAll(); ! this.setMinimumSize(null); this.setPreferredSize(null); --- 85,91 ---- public void init() { ! this.removeAll(); ! this.setMinimumSize(null); this.setPreferredSize(null); *************** *** 92,110 **** this.tableModel = new AttributeTableModel(columnNames, this.mbeanNodes.size()); ! this.tableSorter = new TableSorter(this.tableModel); ! this.table = new JTable(this.tableSorter); ! this.scrollPane = new JScrollPane(this.table); ! this.tableSorter.addMouseListenerToHeaderInTable(this.table); this.table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ! this.table.setFont(VALUE_FONT); ! for (int i = 0; i < attributeNames.size(); i++) { this.table.getColumnModel().getColumn(i).setHeaderRenderer(new SortHeaderRenderer()); this.table.getColumnModel().getColumn(i).setCellRenderer(new ChangeRenderer()); ! } ! add(this.scrollPane, BorderLayout.CENTER); // The first refresh sets column classes properly --- 100,122 ---- this.tableModel = new AttributeTableModel(columnNames, this.mbeanNodes.size()); ! // this.tableSorter = new TableSorter(this.tableModel); ! JNTable nTable = new JNTable(tableModel); ! nTable.setHasColumnControl(true); ! ! this.table = nTable.getTable();//new JXTable(tableModel); //this.tableSorter); ! // this.scrollPane = new JScrollPane(this.table); ! // this.tableSorter.addMouseListenerToHeaderInTable(this.table); this.table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ! // this.table.setFont(VALUE_FONT); ! this.table.setHighlighters(new HighlighterPipeline(new Highlighter[]{new AlternateRowHighlighter(), new ChangeHighlighter()})); ! /*for (int i = 0; i < attributeNames.size(); i++) { this.table.getColumnModel().getColumn(i).setHeaderRenderer(new SortHeaderRenderer()); this.table.getColumnModel().getColumn(i).setCellRenderer(new ChangeRenderer()); ! }*/ ! add(nTable, BorderLayout.CENTER); // The first refresh sets column classes properly *************** *** 120,127 **** } public void refresh() { if (this.tableModel instanceof AttributeTableModel) ! ((AttributeTableModel)this.tableModel).resetChangeList(); // TODO GH: FIX! Here we are going to try and re-execute the original dashboard --- 132,156 ---- } + + public class ChangeHighlighter extends ConditionalHighlighter { + public ChangeHighlighter() { + setForeground(Color.red); + } + + protected boolean needsHighlight(ComponentAdapter adapter) { + return test(adapter); + } + + protected boolean test(ComponentAdapter componentAdapter) { + return tableModel.isValueAtChanged( + table.convertRowIndexToModel(componentAdapter.row), + table.convertColumnIndexToModel(componentAdapter.column)); + } + } + public void refresh() { if (this.tableModel instanceof AttributeTableModel) ! ((AttributeTableModel) this.tableModel).resetChangeList(); // TODO GH: FIX! Here we are going to try and re-execute the original dashboard *************** *** 171,181 **** } else { value = beanNode.getObjectName().getKeyProperty(attributeName); ! if (value == null) value = "unknown"; } if (!this.sorted) { ! this.tableModel.setColumnClass(col, (value!=null)?value.getClass():Object.class); } ! if ((value != null) && !value.equals(this.tableModel.getValueAt(row,col))) this.tableModel.setValueAt(value, row, col); --- 200,223 ---- } else { value = beanNode.getObjectName().getKeyProperty(attributeName); ! if (value == null) { ! // Treat it like an operation. ! OperationNode operationNode = ! (OperationNode) beanNode.getOperationNodeMap().get(attributeName); ! value = operationNode; ! ! ! if (!(table.getColumnModel().getColumn(col).getCellRenderer() instanceof ButtonRenderer)) { ! table.getColumnExt(col).setCellRenderer(new ButtonRenderer()); ! table.getColumnExt(col).setCellEditor(new ButtonEditor(new JCheckBox())); ! } ! ! } else if (value == null) value = "unknown"; + } if (!this.sorted) { ! this.tableModel.setColumnClass(col, (value != null) ? value.getClass() : Object.class); } ! if ((value != null) && !value.equals(this.tableModel.getValueAt(row, col))) this.tableModel.setValueAt(value, row, col); *************** *** 198,211 **** public void run() { // Its a hack, but sleep until the component is likely to be showing ! try { Thread.sleep(2000); } catch(Exception e) { } ! while(this.isShowing()) { refresh(); ! try { Thread.sleep(1000); } catch(Exception e) { } } } - public class AttributeTableModel extends DefaultTableModel { Class[] columnClass = new Class[20]; --- 240,258 ---- public void run() { // Its a hack, but sleep until the component is likely to be showing ! try { ! Thread.sleep(2000); ! } catch (Exception e) { ! } ! while (this.isShowing()) { refresh(); ! try { ! Thread.sleep(1000); ! } catch (Exception e) { ! } } } public class AttributeTableModel extends DefaultTableModel { Class[] columnClass = new Class[20]; *************** *** 269,279 **** int rowCount = getRowCount(); int columnCount = getColumnCount(); ! boolean[][] newChanges = new boolean[rowCount-1][columnCount]; ! if ( 0 < row ) { System.arraycopy(this.changes, 0, newChanges, 0, row); } ! if ( (row + 1) < rowCount ) { ! System.arraycopy(this.changes, row+1, newChanges, row, rowCount-row-1); } --- 316,326 ---- int rowCount = getRowCount(); int columnCount = getColumnCount(); ! boolean[][] newChanges = new boolean[rowCount - 1][columnCount]; ! if (0 < row) { System.arraycopy(this.changes, 0, newChanges, 0, row); } ! if ((row + 1) < rowCount) { ! System.arraycopy(this.changes, row + 1, newChanges, row, rowCount - row - 1); } *************** *** 289,293 **** int rowCount = getRowCount(); int columnCount = getColumnCount(); ! boolean[][] newChanges = new boolean[rowCount+1][columnCount]; System.arraycopy(this.changes, 0, newChanges, 0, rowCount); --- 336,340 ---- int rowCount = getRowCount(); int columnCount = getColumnCount(); ! boolean[][] newChanges = new boolean[rowCount + 1][columnCount]; System.arraycopy(this.changes, 0, newChanges, 0, rowCount); *************** *** 296,300 **** this.changes = newChanges; ! super.setRowCount(rowCount+1); } --- 343,347 ---- this.changes = newChanges; ! super.setRowCount(rowCount + 1); } *************** *** 313,336 **** public void setContext(Map context) { if (this.mbeanNodes == null) { ! throw new IllegalStateException( ! "AttributeTableComponent: You must specify an appropriate [beanList] attribute."); } ! dashboard = (Dashboard) context.get(Dashboard.CONTEXT_DASHBOARD); init(); } ! ! /** Getter for property label. ! * @return Value of property label. * */ public String getLabel() { return label; } ! ! /** Setter for property label. ! * @param label New value of property label. * */ public void setLabel(String label) { --- 360,384 ---- public void setContext(Map context) { if (this.mbeanNodes == null) { ! throw new IllegalStateException("AttributeTableComponent: You must specify an appropriate [beanList] attribute."); } ! dashboard = (Dashboard) context.get(Dashboard.CONTEXT_DASHBOARD); init(); } ! ! /** ! * Getter for property label. * + * @return Value of property label. */ public String getLabel() { return label; } ! ! /** ! * Setter for property label. * + * @param label New value of property label. */ public void setLabel(String label) { *************** *** 339,346 **** - - public static class SortHeaderRenderer ! extends DefaultTableCellRenderer { private static Icon ascendingIcon = createImageIcon("images/Up.gif"); --- 387,392 ---- public static class SortHeaderRenderer ! extends DefaultTableCellRenderer { private static Icon ascendingIcon = createImageIcon("images/Up.gif"); *************** *** 348,352 **** ! /** Returns an ImageIcon, or null if the path was invalid. */ protected static ImageIcon createImageIcon(String path) { java.net.URL imgURL = RefreshControlComponent.class.getClassLoader().getResource(path); --- 394,400 ---- ! /** ! * Returns an ImageIcon, or null if the path was invalid. ! */ protected static ImageIcon createImageIcon(String path) { java.net.URL imgURL = RefreshControlComponent.class.getClassLoader().getResource(path); *************** *** 364,371 **** } ! public Component getTableCellRendererComponent( ! JTable table, Object value, ! boolean isSelected, boolean hasFocus, ! int row, int col) { int index = -1; boolean ascending = true; --- 412,418 ---- } ! public Component getTableCellRendererComponent(JTable table, Object value, ! boolean isSelected, boolean hasFocus, ! int row, int col) { int index = -1; boolean ascending = true; *************** *** 374,379 **** if (model instanceof TableSorter) { ! index = ((TableSorter)model).getCurrentSortColumn(); ! ascending = ((TableSorter)model).isAscending(); } --- 421,426 ---- if (model instanceof TableSorter) { ! index = ((TableSorter) model).getCurrentSortColumn(); ! ascending = ((TableSorter) model).isAscending(); } *************** *** 387,411 **** } ! setFont(getFont().deriveFont((index == col)?Font.BOLD:Font.PLAIN)); if (index == col) { ! setIcon(ascending?ascendingIcon:descendingIcon); } else { setIcon(null); } ! setText((value == null) ? "" :value.toString()); setBorder(UIManager.getBorder("TableHeader.cellBorder")); return this; ! } } - public static class ChangeRenderer extends DefaultTableCellRenderer implements TableCellRenderer { ! public Component getTableCellRendererComponent( ! JTable table, Object value, ! boolean isSelected, boolean hasFocus, ! int row, int column) { Component comp = --- 434,456 ---- } ! setFont(getFont().deriveFont((index == col) ? Font.BOLD : Font.PLAIN)); if (index == col) { ! setIcon(ascending ? ascendingIcon : descendingIcon); } else { setIcon(null); } ! setText((value == null) ? "" : value.toString()); setBorder(UIManager.getBorder("TableHeader.cellBorder")); return this; ! } } public static class ChangeRenderer extends DefaultTableCellRenderer implements TableCellRenderer { ! public Component getTableCellRendererComponent(JTable table, Object value, ! boolean isSelected, boolean hasFocus, ! int row, int column) { Component comp = *************** *** 414,421 **** TableModel model = table.getModel(); if (model instanceof TableSorter) { ! int realRow = ((TableSorter)model).translateRow(row); ! model = ((TableMap)model).getModel(); if (model instanceof AttributeTableModel) { ! if (((AttributeTableModel)model).isValueAtChanged(realRow, column)) { comp.setForeground(Color.red); setFont(getFont().deriveFont(Font.BOLD)); --- 459,466 ---- TableModel model = table.getModel(); if (model instanceof TableSorter) { ! int realRow = ((TableSorter) model).translateRow(row); ! model = ((TableMap) model).getModel(); if (model instanceof AttributeTableModel) { ! if (((AttributeTableModel) model).isValueAtChanged(realRow, column)) { comp.setForeground(Color.red); setFont(getFont().deriveFont(Font.BOLD)); Index: AttributeTablePopupComponent.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/dashboard/components/AttributeTablePopupComponent.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AttributeTablePopupComponent.java 5 Oct 2004 05:16:00 -0000 1.3 --- AttributeTablePopupComponent.java 14 Mar 2005 16:05:38 -0000 1.4 *************** *** 51,54 **** --- 51,55 ---- if (null != this.tableSelectionBackground) { this.table.setSelectionBackground(this.tableSelectionBackground); + } } *************** *** 80,84 **** int selectedRow = AttributeTablePopupComponent.this.table.rowAtPoint(e.getPoint()); if (-1 != selectedRow) { ! selectedRow = AttributeTablePopupComponent.this.tableSorter.translateRow(selectedRow); MBeanNode mbeanNode = (MBeanNode) AttributeTablePopupComponent.this.mbeanNodes.get(selectedRow); --- 81,85 ---- int selectedRow = AttributeTablePopupComponent.this.table.rowAtPoint(e.getPoint()); if (-1 != selectedRow) { ! selectedRow = AttributeTablePopupComponent.this.table.convertRowIndexToModel(selectedRow); MBeanNode mbeanNode = (MBeanNode) AttributeTablePopupComponent.this.mbeanNodes.get(selectedRow); |