author | vlivanov |
Thu, 18 Jan 2018 02:25:18 +0300 | |
changeset 48596 | 860326263d1f |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23711
95fb268275e3
8039022: Fix serial lint warnings in sun.tools.java
darcy
parents:
14342
diff
changeset
|
2 |
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
25 |
|
2 | 26 |
package sun.tools.jconsole.inspector; |
27 |
||
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
28 |
import java.awt.Color; |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
29 |
import java.awt.Component; |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
30 |
import java.awt.Font; |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
31 |
import javax.swing.JTable; |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
32 |
import javax.swing.table.DefaultTableCellRenderer; |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
33 |
import javax.swing.table.DefaultTableModel; |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
34 |
import javax.swing.table.TableCellRenderer; |
2 | 35 |
|
23711
95fb268275e3
8039022: Fix serial lint warnings in sun.tools.java
darcy
parents:
14342
diff
changeset
|
36 |
@SuppressWarnings("serial") // JDK implementation class |
2 | 37 |
public abstract class XTable extends JTable { |
38 |
static final int NAME_COLUMN = 0; |
|
39 |
static final int VALUE_COLUMN = 1; |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
40 |
private Color defaultColor, editableColor, errorColor; |
2 | 41 |
private Font normalFont, boldFont; |
42 |
||
43 |
public XTable () { |
|
44 |
super(); |
|
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
45 |
@SuppressWarnings("serial") |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
46 |
final TableSorter sorter = new TableSorter(); |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
47 |
setModel(sorter); |
2 | 48 |
sorter.addMouseListenerToHeaderInTable(this); |
49 |
setRowSelectionAllowed(false); |
|
50 |
setColumnSelectionAllowed(false); |
|
51 |
setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); |
|
52 |
} |
|
53 |
||
54 |
Color getDefaultColor() { |
|
55 |
return defaultColor; |
|
56 |
} |
|
57 |
||
58 |
Color getEditableColor() { |
|
59 |
return editableColor; |
|
60 |
} |
|
61 |
||
62 |
/** |
|
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
63 |
* Called by TableSorter if a mouse event requests to sort the rows. |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
64 |
* @param column the column against which the rows are sorted |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
65 |
*/ |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
66 |
void sortRequested(int column) { |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
67 |
// This is a hook for subclasses |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
68 |
} |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
69 |
|
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
70 |
/** |
2 | 71 |
* This returns the select index as the table was at initialization |
72 |
*/ |
|
73 |
public int getSelectedIndex() { |
|
74 |
return convertRowToIndex(getSelectedRow()); |
|
75 |
} |
|
76 |
||
77 |
/* |
|
78 |
* Converts the row into index (before sorting) |
|
79 |
*/ |
|
80 |
public int convertRowToIndex(int row) { |
|
81 |
if (row == -1) return row; |
|
82 |
if (getModel() instanceof TableSorter) { |
|
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
83 |
return ((TableSorter) getModel()).getIndexOfRow(row); |
2 | 84 |
} else { |
85 |
return row; |
|
86 |
} |
|
87 |
} |
|
88 |
||
89 |
public void emptyTable() { |
|
90 |
DefaultTableModel model = (DefaultTableModel)getModel(); |
|
91 |
while (model.getRowCount()>0) |
|
92 |
model.removeRow(0); |
|
93 |
} |
|
94 |
||
95 |
public abstract boolean isTableEditable(); |
|
96 |
public abstract boolean isColumnEditable(int column); |
|
97 |
public abstract boolean isReadable(int row); |
|
98 |
public abstract boolean isWritable(int row); |
|
99 |
public abstract boolean isCellError(int row, int col); |
|
100 |
public abstract boolean isAttributeViewable(int row, int col); |
|
101 |
public abstract void setTableValue(Object value,int row); |
|
102 |
public abstract Object getValue(int row); |
|
103 |
public abstract String getClassName(int row); |
|
104 |
public abstract String getValueName(int row); |
|
105 |
||
106 |
public boolean isReadWrite(int row) { |
|
107 |
return (isReadable(row) && isWritable(row)); |
|
108 |
} |
|
109 |
||
110 |
//JTable re-implementation |
|
111 |
||
112 |
//attribute can be editable even if unavailable |
|
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
113 |
@Override |
2 | 114 |
public boolean isCellEditable(int row, int col) { |
115 |
return ((isTableEditable() && isColumnEditable(col) |
|
116 |
&& isWritable(row) |
|
117 |
&& Utils.isEditableType(getClassName(row)))); |
|
118 |
} |
|
119 |
||
120 |
//attribute can be droppable even if unavailable |
|
121 |
public boolean isCellDroppable(int row, int col) { |
|
122 |
return (isTableEditable() && isColumnEditable(col) |
|
123 |
&& isWritable(row)); |
|
124 |
} |
|
125 |
||
126 |
//returns null, means no tool tip |
|
127 |
public String getToolTip(int row, int column) { |
|
128 |
return null; |
|
129 |
} |
|
130 |
||
131 |
/** |
|
132 |
* This method sets read write rows to be blue, and other rows to be their |
|
133 |
* default rendered colour. |
|
134 |
*/ |
|
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
135 |
@Override |
2 | 136 |
public TableCellRenderer getCellRenderer(int row, int column) { |
137 |
DefaultTableCellRenderer tcr = |
|
138 |
(DefaultTableCellRenderer) super.getCellRenderer(row,column); |
|
139 |
tcr.setToolTipText(getToolTip(row,column)); |
|
140 |
if (defaultColor == null) { |
|
141 |
defaultColor = tcr.getForeground(); |
|
142 |
editableColor = Color.blue; |
|
143 |
errorColor = Color.red; |
|
144 |
// this sometimes happens for some reason |
|
145 |
if (defaultColor == null) { |
|
146 |
return tcr; |
|
147 |
} |
|
148 |
} |
|
149 |
if (column != VALUE_COLUMN) { |
|
150 |
tcr.setForeground(defaultColor); |
|
151 |
return tcr; |
|
152 |
} |
|
153 |
if (isCellError(row,column)) { |
|
154 |
tcr.setForeground(errorColor); |
|
155 |
} else if (isCellEditable(row, column)) { |
|
156 |
tcr.setForeground(editableColor); |
|
157 |
} else { |
|
158 |
tcr.setForeground(defaultColor); |
|
159 |
} |
|
160 |
return tcr; |
|
161 |
} |
|
162 |
||
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
163 |
@Override |
2 | 164 |
public Component prepareRenderer(TableCellRenderer renderer, |
165 |
int row, int column) { |
|
166 |
Component comp = super.prepareRenderer(renderer, row, column); |
|
167 |
||
168 |
if (normalFont == null) { |
|
169 |
normalFont = comp.getFont(); |
|
170 |
boldFont = normalFont.deriveFont(Font.BOLD); |
|
171 |
} |
|
172 |
||
173 |
if (column == VALUE_COLUMN && isAttributeViewable(row, VALUE_COLUMN)) { |
|
174 |
comp.setFont(boldFont); |
|
175 |
} else { |
|
176 |
comp.setFont(normalFont); |
|
177 |
} |
|
178 |
||
179 |
return comp; |
|
180 |
} |
|
181 |
} |