History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/tools/jconsole/inspector/XTextField.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/tools/jconsole/inspector/XTextField.java+248−0
@@ -0,0 +1,248 @@
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.*;
29+import java.awt.dnd.*;
30+import java.awt.event.*;
31+import java.awt.datatransfer.*;
32+import java.io.*;
33+import java.util.*;
34+import javax.swing.plaf.*;
35+import javax.swing.event.*;
36+import javax.swing.*;
37+
38+
39+/**
40+ * This list implements the drag and drop functionality.
41+ */
42+@SuppressWarnings("serial")
43+public class XTextField extends JPanel
44+ implements DocumentListener,
45+ ActionListener {
46+
47+ private static final Color selF = Color.red;
48+ private static final Color selB = Color.yellow;
49+ private Color fore=null, back=null;
50+ private HashMap items = null; //used for popup menu selection
51+ private XObject selectedObject;
52+ private XObject currentObject;
53+ private Class expectedClass;
54+ private Object value;
55+ protected JTextField textField;
56+ private JButton browseObjects;
57+
58+ private static boolean allowNullSelection = false;
59+
60+ protected final static int COMPATIBLE_VALUE = 1;
61+ protected final static int CURRENT_VALUE = 2;
62+ protected final static int NULL_VALUE = 3;
63+
64+ private JButton button;
65+ private XOperations operation;
66+
67+ //used in XTestFieldEditor
68+ public XTextField() {
69+ super(new BorderLayout());
70+ add(textField = new JTextField(),BorderLayout.CENTER);
71+ textField.addActionListener(this);
72+ //
73+ }
74+
75+ public XTextField(Object value) {
76+ this(value,value.toString().length());
77+ }
78+
79+ public XTextField(Object value, int colWidth) {
80+ this(value,value.getClass(),colWidth, true, null, null);
81+ }
82+
83+ public XTextField(Object value,
84+ Class expectedClass,
85+ int colWidth,
86+ boolean isCallable,
87+ JButton button,
88+ XOperations operation) {
89+ super(new BorderLayout());
90+ this.expectedClass = expectedClass;
91+ this.button = button;
92+ this.operation = operation;
93+ add(textField = new JTextField(value.toString(),colWidth),
94+ BorderLayout.CENTER);
95+ if(isCallable)
96+ textField.addActionListener(this);
97+
98+ boolean fieldEditable = Utils.isEditableType(expectedClass.getName());
99+ if (fieldEditable && isCallable) {
100+ textField.setEditable(true);
101+ }
102+ else {
103+ textField.setEditable(false);
104+ }
105+ }
106+
107+ public static void setNullSelectionAllowed(boolean allowNullSelection) {
108+ XTextField.allowNullSelection = allowNullSelection;
109+ }
110+
111+ public static boolean getNullSelectionAllowed() {
112+ return allowNullSelection;
113+ }
114+
115+ protected void init(Object value, Class expectedClass) {
116+ this.expectedClass = expectedClass;
117+ this.value = value;
118+ boolean fieldEditable = Utils.isEditableType(expectedClass.getName());
119+ clearObject();
120+ if (value != null) {
121+ currentObject = new XObject(value);
122+ textField.setText(value.toString());
123+ }
124+ else {
125+ currentObject = XObject.NULL_OBJECT;
126+ //null String value for the moment
127+ textField.setText("");
128+ }
129+ textField.setToolTipText(null);
130+ if (fieldEditable) {
131+ if (!textField.isEditable()) {
132+ textField.setEditable(true);
133+ }
134+
135+ }
136+ else {
137+ if (textField.isEditable()) {
138+ textField.setEditable(false);
139+ }
140+ }
141+ }
142+
143+
144+
145+
146+
147+ private synchronized void setObject(XObject object) {
148+ clearObject();
149+ selectedObject = object;
150+ currentObject = object;
151+ setSelectedColors();
152+ textField.setText(object.getText());
153+ textField.getDocument().addDocumentListener(this);
154+ paintImmediately(getVisibleRect());
155+ }
156+
157+ private synchronized void clearObject() {
158+ textField.getDocument().removeDocumentListener(this);
159+ selectedObject = null;
160+ currentObject = null;
161+ setDefaultColors();
162+ }
163+
164+ private synchronized void setSelectedColors() {
165+ // fore = textField.getForeground();
166+ // back = textField.getBackground();
167+
168+ //textField.setForeground(Color.red);
169+ // textField.setBackground(Color.yellow);
170+ }
171+
172+ private synchronized void setDefaultColors() {
173+ // if (fore != null) textField.setForeground(fore);
174+ // if (back != null) textField.setBackground(back);
175+ }
176+
177+ public void setHorizontalAlignment(int h) {
178+ textField.setHorizontalAlignment(h);
179+ }
180+
181+ //can be overwritten
182+ protected JMenuItem buildJMenuItem(XObject xobject, int valueType) {
183+ if (valueType == COMPATIBLE_VALUE) {
184+ return new JMenuItem(xobject.getText());
185+ }
186+ else if (valueType == CURRENT_VALUE) {
187+ return new JMenuItem("> "+xobject.getText());
188+ }
189+ else if (valueType == NULL_VALUE) {
190+ return new JMenuItem("null");
191+ }
192+ else {
193+ return null;
194+ }
195+ }
196+
197+ private JPopupMenu buildEditPopupMenu() {
198+ JPopupMenu menu = new JPopupMenu();
199+ return menu;
200+ }
201+
202+
203+ // ACTIONLISTENER IMPLEMENTATION
204+ public void actionPerformed(ActionEvent e) {
205+ if (e.getSource() instanceof JTextField) {
206+ if(operation != null)
207+ operation.performInvokeRequest(button);
208+ }
209+ }
210+
211+ /**
212+ * This method returns either the user inputted String, or an XObject
213+ * if one was dropped on the input field.
214+ */
215+ public Object getValue() {
216+ if (selectedObject!=null) {
217+ if (selectedObject == XObject.NULL_OBJECT) {
218+ //null case
219+ return null;
220+ }
221+ else {
222+ return selectedObject;
223+ }
224+ }
225+ else {
226+ return textField.getText();
227+ }
228+ }
229+
230+ public void changedUpdate(DocumentEvent e) {
231+ // the user typed something, so remove references
232+ // to the obejct that was dropped.
233+ clearObject();
234+ }
235+
236+ public void removeUpdate(DocumentEvent e) {
237+ // the user typed something, so remove references
238+ // to the obejct that was dropped.
239+ clearObject();
240+ }
241+
242+ public void insertUpdate(DocumentEvent e) {
243+ // the user typed something, so remove references
244+ // to the obejct that was dropped.
245+ clearObject();
246+ }
247+
248+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t