Showing the changes to java/pkg/sun/tools/jconsole/inspector/XTextFieldEditor.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,156 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved. | |
| 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 | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 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 | + * | |
| 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. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package sun.tools.jconsole.inspector; | |
| 27 | + | |
| 28 | +import java.awt.Component; | |
| 29 | +import java.awt.event.ActionEvent; | |
| 30 | +import java.awt.event.FocusAdapter; | |
| 31 | +import java.awt.event.FocusEvent; | |
| 32 | +import java.awt.event.FocusListener; | |
| 33 | +import java.util.EventObject; | |
| 34 | +import javax.swing.JMenuItem; | |
| 35 | +import javax.swing.JTable; | |
| 36 | +import javax.swing.JTextField; | |
| 37 | +import javax.swing.event.CellEditorListener; | |
| 38 | +import javax.swing.event.ChangeEvent; | |
| 39 | +import javax.swing.event.EventListenerList; | |
| 40 | +import javax.swing.table.TableCellEditor; | |
| 41 | + | |
| 42 | +@SuppressWarnings("serial") | |
| 43 | +public class XTextFieldEditor extends XTextField implements TableCellEditor { | |
| 44 | + | |
| 45 | + protected EventListenerList evtListenerList = new EventListenerList(); | |
| 46 | + protected ChangeEvent changeEvent = new ChangeEvent(this); | |
| 47 | + | |
| 48 | + private FocusListener editorFocusListener = new FocusAdapter() { | |
| 49 | + @Override | |
| 50 | + public void focusLost(FocusEvent e) { | |
| 51 | + // fireEditingStopped(); | |
| 52 | + // must not call fireEditingStopped() here! | |
| 53 | + } | |
| 54 | + }; | |
| 55 | + | |
| 56 | + public XTextFieldEditor() { | |
| 57 | + super(); | |
| 58 | + textField.addFocusListener(editorFocusListener); | |
| 59 | + } | |
| 60 | + | |
| 61 | + //edition stopped ou JMenuItem selection & JTextField selection | |
| 62 | + @Override | |
| 63 | + public void actionPerformed(ActionEvent e) { | |
| 64 | + super.actionPerformed(e); | |
| 65 | + if ((e.getSource() instanceof JMenuItem) || | |
| 66 | + (e.getSource() instanceof JTextField)) { | |
| 67 | + fireEditingStopped(); | |
| 68 | + } | |
| 69 | + } | |
| 70 | + | |
| 71 | + //edition stopped on drag & drop success | |
| 72 | + protected void dropSuccess() { | |
| 73 | + fireEditingStopped(); | |
| 74 | + } | |
| 75 | + | |
| 76 | + //TableCellEditor implementation | |
| 77 | + | |
| 78 | + public void addCellEditorListener(CellEditorListener listener) { | |
| 79 | + evtListenerList.add(CellEditorListener.class,listener); | |
| 80 | + } | |
| 81 | + | |
| 82 | + public void removeCellEditorListener(CellEditorListener listener) { | |
| 83 | + evtListenerList.remove(CellEditorListener.class, listener); | |
| 84 | + } | |
| 85 | + | |
| 86 | + protected void fireEditingStopped() { | |
| 87 | + CellEditorListener listener; | |
| 88 | + Object[] listeners = evtListenerList.getListenerList(); | |
| 89 | + for (int i=0;i< listeners.length;i++) { | |
| 90 | + if (listeners[i] == CellEditorListener.class) { | |
| 91 | + listener = (CellEditorListener) listeners[i+1]; | |
| 92 | + listener.editingStopped(changeEvent); | |
| 93 | + } | |
| 94 | + } | |
| 95 | + } | |
| 96 | + | |
| 97 | + protected void fireEditingCanceled() { | |
| 98 | + CellEditorListener listener; | |
| 99 | + Object[] listeners = evtListenerList.getListenerList(); | |
| 100 | + for (int i=0;i< listeners.length;i++) { | |
| 101 | + if (listeners[i] == CellEditorListener.class) { | |
| 102 | + listener = (CellEditorListener) listeners[i+1]; | |
| 103 | + listener.editingCanceled(changeEvent); | |
| 104 | + } | |
| 105 | + } | |
| 106 | + } | |
| 107 | + | |
| 108 | + public void cancelCellEditing() { | |
| 109 | + fireEditingCanceled(); | |
| 110 | + } | |
| 111 | + | |
| 112 | + public boolean stopCellEditing() { | |
| 113 | + fireEditingStopped(); | |
| 114 | + return true; | |
| 115 | + } | |
| 116 | + | |
| 117 | + public boolean isCellEditable(EventObject event) { | |
| 118 | + return true; | |
| 119 | + } | |
| 120 | + | |
| 121 | + public boolean shouldSelectCell(EventObject event) { | |
| 122 | + return true; | |
| 123 | + } | |
| 124 | + | |
| 125 | + public Object getCellEditorValue() { | |
| 126 | + Object object = getValue(); | |
| 127 | + | |
| 128 | + if (object instanceof XObject) { | |
| 129 | + return ((XObject) object).getObject(); | |
| 130 | + } | |
| 131 | + else { | |
| 132 | + return object; | |
| 133 | + } | |
| 134 | + } | |
| 135 | + | |
| 136 | + public Component getTableCellEditorComponent(JTable table, | |
| 137 | + Object value, | |
| 138 | + boolean isSelected, | |
| 139 | + int row, | |
| 140 | + int column) { | |
| 141 | + String className; | |
| 142 | + if (table instanceof XTable) { | |
| 143 | + XTable mytable = (XTable) table; | |
| 144 | + className = mytable.getClassName(row); | |
| 145 | + } else { | |
| 146 | + className = String.class.getName(); | |
| 147 | + } | |
| 148 | + try { | |
| 149 | + init(value,Utils.getClass(className)); | |
| 150 | + } | |
| 151 | + catch(Exception e) {} | |
| 152 | + | |
| 153 | + return this; | |
| 154 | + } | |
| 155 | + | |
| 156 | +} | |