src/jdk.jconsole/share/classes/sun/tools/jconsole/inspector/XTextFieldEditor.java
author vlivanov
Thu, 18 Jan 2018 02:25:18 +0300
changeset 48596 860326263d1f
parent 47216 71c04702a3d5
permissions -rw-r--r--
8194963: SystemDictionary::link_method_handle_constant() can't link MethodHandle.invoke()/invokeExact() Reviewed-by: kvn, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1017
diff changeset
     2
 * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1017
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1017
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1017
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1017
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1017
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    25
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.jconsole.inspector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Component;
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    29
import java.awt.event.ActionEvent;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    30
import java.awt.event.FocusAdapter;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    31
import java.awt.event.FocusEvent;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    32
import java.awt.event.FocusListener;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.EventObject;
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    34
import javax.swing.JMenuItem;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    35
import javax.swing.JTable;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    36
import javax.swing.JTextField;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    37
import javax.swing.event.CellEditorListener;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    38
import javax.swing.event.ChangeEvent;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    39
import javax.swing.event.EventListenerList;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    40
import javax.swing.table.TableCellEditor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class XTextFieldEditor extends XTextField implements TableCellEditor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    45
    protected EventListenerList evtListenerList = new EventListenerList();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    protected ChangeEvent changeEvent = new ChangeEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private FocusListener editorFocusListener = new FocusAdapter() {
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    49
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        public void focusLost(FocusEvent e) {
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    51
            // fireEditingStopped();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    52
            // must not call fireEditingStopped() here!
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public XTextFieldEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        textField.addFocusListener(editorFocusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    //edition stopped ou JMenuItem selection & JTextField selection
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    62
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public void  actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        super.actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        if ((e.getSource() instanceof JMenuItem) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            (e.getSource() instanceof JTextField)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            fireEditingStopped();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    //edition stopped on drag & drop success
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected void dropSuccess() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        fireEditingStopped();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    //TableCellEditor implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public void addCellEditorListener(CellEditorListener listener) {
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    79
        evtListenerList.add(CellEditorListener.class,listener);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public void removeCellEditorListener(CellEditorListener listener) {
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    83
        evtListenerList.remove(CellEditorListener.class, listener);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    protected void fireEditingStopped() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        CellEditorListener listener;
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    88
        Object[] listeners = evtListenerList.getListenerList();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        for (int i=0;i< listeners.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            if (listeners[i] == CellEditorListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                listener = (CellEditorListener) listeners[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                listener.editingStopped(changeEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    protected void fireEditingCanceled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        CellEditorListener listener;
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    99
        Object[] listeners = evtListenerList.getListenerList();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        for (int i=0;i< listeners.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            if (listeners[i] == CellEditorListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                listener = (CellEditorListener) listeners[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                listener.editingCanceled(changeEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public void cancelCellEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        fireEditingCanceled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public boolean stopCellEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        fireEditingStopped();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public boolean isCellEditable(EventObject event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public boolean shouldSelectCell(EventObject event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public Object getCellEditorValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        Object object = getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (object instanceof XObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            return ((XObject) object).getObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            return object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public Component getTableCellEditorComponent(JTable table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                                 Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                                 boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                                 int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                                 int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        String className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (table instanceof XTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            XTable mytable = (XTable) table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            className = mytable.getClassName(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            className = String.class.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            init(value,Utils.getClass(className));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        catch(Exception e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
}