KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > lf5 > viewer > categoryexplorer > CategoryImmediateEditor


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.log4j.lf5.viewer.categoryexplorer;
17
18 import javax.swing.*;
19 import javax.swing.tree.DefaultTreeCellEditor JavaDoc;
20 import javax.swing.tree.TreePath JavaDoc;
21 import java.awt.*;
22 import java.awt.event.MouseEvent JavaDoc;
23 import java.util.EventObject JavaDoc;
24
25 /**
26  * CategoryImmediateEditor
27  *
28  * @author Michael J. Sikorsky
29  * @author Robert Shaw
30  */

31
32 // Contributed by ThoughtWorks Inc.
33

34 public class CategoryImmediateEditor extends DefaultTreeCellEditor JavaDoc {
35   //--------------------------------------------------------------------------
36
// Constants:
37
//--------------------------------------------------------------------------
38

39   //--------------------------------------------------------------------------
40
// Protected Variables:
41
//--------------------------------------------------------------------------
42
private CategoryNodeRenderer renderer;
43   protected Icon editingIcon = null;
44
45   //--------------------------------------------------------------------------
46
// Private Variables:
47
//--------------------------------------------------------------------------
48

49   //--------------------------------------------------------------------------
50
// Constructors:
51
//--------------------------------------------------------------------------
52
public CategoryImmediateEditor(JTree tree,
53       CategoryNodeRenderer renderer,
54       CategoryNodeEditor editor) {
55     super(tree, renderer, editor);
56     this.renderer = renderer;
57     renderer.setIcon(null);
58     renderer.setLeafIcon(null);
59     renderer.setOpenIcon(null);
60     renderer.setClosedIcon(null);
61
62     super.editingIcon = null;
63   }
64
65   //--------------------------------------------------------------------------
66
// Public Methods:
67
//--------------------------------------------------------------------------
68
public boolean shouldSelectCell(EventObject JavaDoc e) {
69     boolean rv = false; // only mouse events
70

71     if (e instanceof MouseEvent JavaDoc) {
72       MouseEvent JavaDoc me = (MouseEvent JavaDoc) e;
73       TreePath JavaDoc path = tree.getPathForLocation(me.getX(),
74           me.getY());
75       CategoryNode node = (CategoryNode)
76           path.getLastPathComponent();
77
78       rv = node.isLeaf() /*|| !inCheckBoxHitRegion(me)*/;
79     }
80     return rv;
81   }
82
83   public boolean inCheckBoxHitRegion(MouseEvent JavaDoc e) {
84     TreePath JavaDoc path = tree.getPathForLocation(e.getX(),
85         e.getY());
86     if (path == null) {
87       return false;
88     }
89     CategoryNode node = (CategoryNode) path.getLastPathComponent();
90     boolean rv = false;
91
92     if (true) {
93       // offset and lastRow DefaultTreeCellEditor
94
// protected members
95

96       Rectangle bounds = tree.getRowBounds(lastRow);
97       Dimension checkBoxOffset =
98           renderer.getCheckBoxOffset();
99
100       bounds.translate(offset + checkBoxOffset.width,
101           checkBoxOffset.height);
102
103       rv = bounds.contains(e.getPoint());
104     }
105     return true;
106   }
107
108   //--------------------------------------------------------------------------
109
// Protected Methods:
110
//--------------------------------------------------------------------------
111

112   protected boolean canEditImmediately(EventObject JavaDoc e) {
113     boolean rv = false;
114
115     if (e instanceof MouseEvent JavaDoc) {
116       MouseEvent JavaDoc me = (MouseEvent JavaDoc) e;
117       rv = inCheckBoxHitRegion(me);
118     }
119
120     return rv;
121   }
122
123   protected void determineOffset(JTree tree, Object JavaDoc value,
124       boolean isSelected, boolean expanded,
125       boolean leaf, int row) {
126     // Very important: means that the tree won't jump around.
127
offset = 0;
128   }
129
130   //--------------------------------------------------------------------------
131
// Private Methods:
132
//--------------------------------------------------------------------------
133

134   //--------------------------------------------------------------------------
135
// Nested Top-Level Classes or Interfaces:
136
//--------------------------------------------------------------------------
137

138 }
139
140
141
142
143
144
145
Popular Tags