001: package org.netbeans.jemmy.testing;
002:
003: import java.awt.*;
004: import java.util.*;
005:
006: import java.awt.event.*;
007:
008: import javax.swing.*;
009: import javax.swing.border.*;
010: import javax.swing.event.*;
011: import javax.swing.tree.*;
012: import javax.swing.table.*;
013:
014: public class Application_027 extends TestFrame {
015:
016: String[] tableColumns;
017:
018: public Application_027() {
019: super ("Application_027");
020:
021: JTabbedPane tp = new JTabbedPane();
022:
023: //////////////////////////////////////////////////////////////////////
024: //table
025: //////////////////////////////////////////////////////////////////////
026: tableColumns = new String[5];
027: String[][] tableItems = new String[5][5];
028: for (int i = 0; i < tableColumns.length; i++) {
029: tableColumns[i] = Integer.toString(i);
030: for (int j = 0; j < tableItems[i].length; j++) {
031: tableItems[j][i] = Integer.toString(i)
032: + Integer.toString(j);
033: }
034: }
035: JTable tbl = new JTable(tableItems, tableColumns);
036: tbl.setCellSelectionEnabled(true);
037: tbl.setRowHeight(tbl.getRowHeight() * 2);
038:
039: TableCellRenderer renderer = new TableCellRenderer() {
040: public Component getTableCellRendererComponent(
041: JTable table, Object value, boolean isSelected,
042: boolean cellHasFocus, int row, int column) {
043: JPanel res = new JPanel();
044: if (isSelected) {
045: res.setBorder(new BevelBorder(BevelBorder.LOWERED));
046: res.add(new JLabel("!" + value.toString() + "!"));
047: } else {
048: res.add(new JLabel(value.toString()));
049: }
050: return (res);
051: }
052: };
053:
054: TableCellEditor editor = new TableDualComboEditor();
055:
056: for (int i = 0; i < tableColumns.length; i++) {
057: tbl.getColumnModel().getColumn(i).setCellRenderer(renderer);
058: tbl.getColumnModel().getColumn(i).setCellEditor(editor);
059: }
060:
061: tp.add("Table Page", new JScrollPane(tbl));
062:
063: //////////////////////////////////////////////////////////////////////
064: //tree
065: //////////////////////////////////////////////////////////////////////
066: DefaultMutableTreeNode[][] subnodes = new DefaultMutableTreeNode[5][5];
067: DefaultMutableTreeNode[] nodes = new DefaultMutableTreeNode[5];
068: DefaultMutableTreeNode root = new DefaultMutableTreeNode();
069: root.setUserObject("00");
070: for (int i = 0; i < nodes.length; i++) {
071: nodes[i] = new DefaultMutableTreeNode();
072: nodes[i].setUserObject(Integer.toString(i) + "0");
073: for (int j = 0; j < subnodes[i].length; j++) {
074: subnodes[i][j] = new DefaultMutableTreeNode();
075: subnodes[i][j].setUserObject(Integer.toString(i)
076: + Integer.toString(j));
077: nodes[i].insert(subnodes[i][j], j);
078: }
079: root.insert(nodes[i], i);
080: }
081: JTree tr = new JTree(root);
082:
083: TreeCellRenderer treeRenderer = new TreeCellRenderer() {
084: public Component getTreeCellRendererComponent(JTree tree,
085: Object value, boolean isSelected,
086: boolean isExpanded, boolean isLeaf, int row,
087: boolean cellHasFocus) {
088: JPanel res = new JPanel();
089: if (isSelected) {
090: res.setBorder(new BevelBorder(BevelBorder.LOWERED));
091: res.add(new JLabel("!" + value.toString() + "!"));
092: } else {
093: res.add(new JLabel(value.toString()));
094: }
095: return (res);
096: }
097: };
098:
099: tr.setCellRenderer(treeRenderer);
100: tr.setCellEditor(new TreeDualComboEditor());
101:
102: tr.setEditable(true);
103: tp.add("Tree Page", new JScrollPane(tr));
104:
105: //////////////////////////////////////////////////////////////////////
106: //list
107: //////////////////////////////////////////////////////////////////////
108: String[] listItems = new String[5];
109: for (int i = 0; i < listItems.length; i++) {
110: listItems[i] = Integer.toString(i);
111: }
112: JList list = new JList(listItems);
113: list.setCellRenderer(new ListCellRenderer() {
114: public Component getListCellRendererComponent(JList list,
115: Object value, int index, boolean isSelected,
116: boolean cellHasFocus) {
117: JPanel res = new JPanel();
118: if (isSelected) {
119: res.setBorder(new BevelBorder(BevelBorder.LOWERED));
120: res.add(new JLabel("!" + value.toString() + "!"));
121: } else {
122: res.add(new JLabel(value.toString()));
123: }
124: return (res);
125: }
126: });
127:
128: tp.add("List Page", new JScrollPane(list));
129:
130: getContentPane().add(tp);
131:
132: setSize(600, 400);
133: }
134:
135: public static void main(String[] argv) {
136: (new Application_027()).show();
137: }
138:
139: class TableDualComboEditor implements TableCellEditor {
140: JComboBox fCombo, sCombo;
141: JPanel res;
142: int row, column;
143: JTable tbl;
144: Vector lists;
145:
146: public TableDualComboEditor() {
147: res = new JPanel();
148: fCombo = new JComboBox(tableColumns);
149: sCombo = new JComboBox(tableColumns);
150: res.add(fCombo);
151: res.add(sCombo);
152: lists = new Vector();
153: }
154:
155: public Component getTableCellEditorComponent(JTable table,
156: Object value, boolean isSelected, int row, int column) {
157: this .row = row;
158: this .column = column;
159: this .tbl = table;
160: fCombo.setSelectedIndex(new Integer(value.toString()
161: .substring(0, 1)).intValue());
162: sCombo.setSelectedIndex(new Integer(value.toString()
163: .substring(1)).intValue());
164: return (res);
165: }
166:
167: public void addCellEditorListener(CellEditorListener l) {
168: lists.add(l);
169: };
170:
171: public void cancelCellEditing() {
172: res.setVisible(false);
173: for (int i = 0; i < lists.size(); i++) {
174: ((CellEditorListener) lists.get(i))
175: .editingCanceled(new ChangeEvent(tbl));
176: }
177: }
178:
179: public Object getCellEditorValue() {
180: return (Integer.toString(fCombo.getSelectedIndex()) + Integer
181: .toString(sCombo.getSelectedIndex()));
182: }
183:
184: public boolean isCellEditable(EventObject anEvent) {
185: return (anEvent instanceof MouseEvent && ((MouseEvent) anEvent)
186: .getClickCount() > 1);
187: }
188:
189: public void removeCellEditorListener(CellEditorListener l) {
190: lists.remove(l);
191: }
192:
193: public boolean shouldSelectCell(EventObject anEvent) {
194: return (true);
195: }
196:
197: public boolean stopCellEditing() {
198: tbl.getModel()
199: .setValueAt(getCellEditorValue(), row, column);
200: for (int i = 0; i < lists.size(); i++) {
201: ((CellEditorListener) lists.get(i))
202: .editingStopped(new ChangeEvent(tbl));
203: }
204: return (true);
205: }
206: }
207:
208: class TreeDualComboEditor implements TreeCellEditor {
209: JComboBox fCombo, sCombo;
210: JPanel res;
211: TreePath path;
212: JTree tree;
213: Vector lists;
214:
215: public TreeDualComboEditor() {
216: res = new JPanel();
217: fCombo = new JComboBox(tableColumns);
218: fCombo.setPopupVisible(false);
219: sCombo = new JComboBox(tableColumns);
220: sCombo.setPopupVisible(false);
221: res.add(fCombo);
222: res.add(sCombo);
223: lists = new Vector();
224: }
225:
226: public Component getTreeCellEditorComponent(JTree tree,
227: Object value, boolean isSelected, boolean isExpanded,
228: boolean isLeaf, int row) {
229: this .path = tree.getPathForRow(row);
230: this .tree = tree;
231: fCombo.setSelectedIndex(new Integer(value.toString()
232: .substring(0, 1)).intValue());
233: sCombo.setSelectedIndex(new Integer(value.toString()
234: .substring(1)).intValue());
235: res.setVisible(true);
236: return (res);
237: }
238:
239: public void addCellEditorListener(CellEditorListener l) {
240: lists.add(l);
241: };
242:
243: public void cancelCellEditing() {
244: res.setVisible(false);
245: ((DefaultMutableTreeNode) path.getLastPathComponent())
246: .setUserObject(getCellEditorValue());
247: for (int i = 0; i < lists.size(); i++) {
248: ((CellEditorListener) lists.get(i))
249: .editingCanceled(new ChangeEvent(tree));
250: }
251: }
252:
253: public Object getCellEditorValue() {
254: return (Integer.toString(fCombo.getSelectedIndex()) + Integer
255: .toString(sCombo.getSelectedIndex()));
256: }
257:
258: public boolean isCellEditable(EventObject anEvent) {
259: return (anEvent instanceof MouseEvent && ((MouseEvent) anEvent)
260: .getClickCount() > 1);
261: }
262:
263: public void removeCellEditorListener(CellEditorListener l) {
264: lists.remove(l);
265: }
266:
267: public boolean shouldSelectCell(EventObject anEvent) {
268: return (true);
269: }
270:
271: public boolean stopCellEditing() {
272: ((DefaultMutableTreeNode) path.getLastPathComponent())
273: .setUserObject(getCellEditorValue());
274: for (int i = 0; i < lists.size(); i++) {
275: ((CellEditorListener) lists.get(i))
276: .editingStopped(new ChangeEvent(tree));
277: }
278: return (true);
279: }
280: }
281:
282: }
|