1 /*
2 * Copyright (c) 1997, 2011, 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
25
26 package javax.swing.plaf.basic;
27
28 import javax.swing.*;
29 import javax.swing.event.*;
30 import java.awt.*;
31 import java.awt.event.*;
32 import java.awt.datatransfer.*;
33 import java.beans.*;
34 import java.util.Enumeration;
35 import java.util.Hashtable;
36 import java.util.ArrayList;
37 import java.util.Collections;
38 import java.util.Comparator;
39 import javax.swing.plaf.ComponentUI;
40 import javax.swing.plaf.UIResource;
41 import javax.swing.plaf.TreeUI;
42 import javax.swing.tree.*;
43 import javax.swing.text.Position;
44 import javax.swing.plaf.basic.DragRecognitionSupport.BeforeDrag;
45 import sun.swing.SwingUtilities2;
46
47 import sun.swing.DefaultLookup;
48 import sun.swing.UIAction;
49
50 /**
51 * The basic L&F for a hierarchical data structure.
52 * <p>
53 *
54 * @author Scott Violet
55 * @author Shannon Hickey (drag and drop)
56 */
57
58 public class BasicTreeUI extends TreeUI
59 {
60 private static final StringBuilder BASELINE_COMPONENT_KEY =
61 new StringBuilder("Tree.baselineComponent");
62
63 // Old actions forward to an instance of this.
64 static private final Actions SHARED_ACTION = new Actions();
2148 editorSize.height != nodeBounds.height) {
2149 // Editor wants different width or height, invalidate
2150 // treeState and relayout.
2151 editorHasDifferentSize = true;
2152 treeState.invalidatePathBounds(path);
2153 updateSize();
2154 // To make sure x/y are updated correctly, fetch
2155 // the bounds again.
2156 nodeBounds = getPathBounds(tree, path);
2157 if (nodeBounds == null) {
2158 return false;
2159 }
2160 }
2161 else
2162 editorHasDifferentSize = false;
2163 tree.add(editingComponent);
2164 editingComponent.setBounds(nodeBounds.x, nodeBounds.y,
2165 nodeBounds.width,
2166 nodeBounds.height);
2167 editingPath = path;
2168 if (editingComponent instanceof JComponent) {
2169 ((JComponent)editingComponent).revalidate();
2170 } else {
2171 editingComponent.validate();
2172 }
2173 editingComponent.repaint();
2174 if(cellEditor.shouldSelectCell(event)) {
2175 stopEditingInCompleteEditing = false;
2176 tree.setSelectionRow(row);
2177 stopEditingInCompleteEditing = true;
2178 }
2179
2180 Component focusedComponent = SwingUtilities2.
2181 compositeRequestFocus(editingComponent);
2182 boolean selectAll = true;
2183
2184 if(event != null) {
2185 /* Find the component that will get forwarded all the
2186 mouse events until mouseReleased. */
2187 Point componentPoint = SwingUtilities.convertPoint
2188 (tree, new Point(event.getX(), event.getY()),
2189 editingComponent);
2190
2191 /* Create an instance of BasicTreeMouseListener to handle
2192 passing the mouse/motion events to the necessary
|
1 /*
2 * Copyright (c) 1997, 2013, 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
25
26 package javax.swing.plaf.basic;
27
28 import javax.swing.*;
29 import javax.swing.event.*;
30 import java.awt.*;
31 import java.awt.event.*;
32 import java.awt.datatransfer.*;
33 import java.beans.*;
34 import java.util.Enumeration;
35 import java.util.Hashtable;
36 import java.util.ArrayList;
37 import java.util.Collections;
38 import java.util.Comparator;
39 import javax.swing.plaf.ComponentUI;
40 import javax.swing.plaf.UIResource;
41 import javax.swing.plaf.TreeUI;
42 import javax.swing.tree.*;
43 import javax.swing.text.Position;
44 import javax.swing.plaf.basic.DragRecognitionSupport.BeforeDrag;
45 import sun.awt.AWTAccessor;
46 import sun.swing.SwingUtilities2;
47
48 import sun.swing.DefaultLookup;
49 import sun.swing.UIAction;
50
51 /**
52 * The basic L&F for a hierarchical data structure.
53 * <p>
54 *
55 * @author Scott Violet
56 * @author Shannon Hickey (drag and drop)
57 */
58
59 public class BasicTreeUI extends TreeUI
60 {
61 private static final StringBuilder BASELINE_COMPONENT_KEY =
62 new StringBuilder("Tree.baselineComponent");
63
64 // Old actions forward to an instance of this.
65 static private final Actions SHARED_ACTION = new Actions();
2149 editorSize.height != nodeBounds.height) {
2150 // Editor wants different width or height, invalidate
2151 // treeState and relayout.
2152 editorHasDifferentSize = true;
2153 treeState.invalidatePathBounds(path);
2154 updateSize();
2155 // To make sure x/y are updated correctly, fetch
2156 // the bounds again.
2157 nodeBounds = getPathBounds(tree, path);
2158 if (nodeBounds == null) {
2159 return false;
2160 }
2161 }
2162 else
2163 editorHasDifferentSize = false;
2164 tree.add(editingComponent);
2165 editingComponent.setBounds(nodeBounds.x, nodeBounds.y,
2166 nodeBounds.width,
2167 nodeBounds.height);
2168 editingPath = path;
2169 AWTAccessor.getComponentAccessor().revalidateSynchronously(editingComponent);
2170 editingComponent.repaint();
2171 if(cellEditor.shouldSelectCell(event)) {
2172 stopEditingInCompleteEditing = false;
2173 tree.setSelectionRow(row);
2174 stopEditingInCompleteEditing = true;
2175 }
2176
2177 Component focusedComponent = SwingUtilities2.
2178 compositeRequestFocus(editingComponent);
2179 boolean selectAll = true;
2180
2181 if(event != null) {
2182 /* Find the component that will get forwarded all the
2183 mouse events until mouseReleased. */
2184 Point componentPoint = SwingUtilities.convertPoint
2185 (tree, new Point(event.getX(), event.getY()),
2186 editingComponent);
2187
2188 /* Create an instance of BasicTreeMouseListener to handle
2189 passing the mouse/motion events to the necessary
|