Source Code Cross Referenced for DefaultTreeCellEditorTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » tree » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.swing.tree 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Anton Avtamonov
019:         * @version $Revision$
020:         */package javax.swing.tree;
021:
022:        import java.awt.Color;
023:        import java.awt.Dimension;
024:        import java.awt.Font;
025:        import java.awt.Rectangle;
026:        import java.awt.event.InputEvent;
027:        import java.awt.event.KeyEvent;
028:        import java.awt.event.MouseEvent;
029:        import java.util.EventObject;
030:        import javax.swing.BasicSwingTestCase;
031:        import javax.swing.BorderFactory;
032:        import javax.swing.DefaultCellEditor;
033:        import javax.swing.JTextField;
034:        import javax.swing.JTree;
035:        import javax.swing.UIManager;
036:        import javax.swing.border.Border;
037:        import javax.swing.event.CellEditorListener;
038:        import javax.swing.event.ChangeEvent;
039:        import javax.swing.event.TreeSelectionEvent;
040:        import javax.swing.plaf.ColorUIResource;
041:        import javax.swing.tree.DefaultTreeCellEditor.DefaultTextField;
042:
043:        public class DefaultTreeCellEditorTest extends BasicSwingTestCase {
044:            private DefaultTreeCellEditor editor;
045:
046:            private DefaultTreeCellRenderer renderer;
047:
048:            private JTree tree;
049:
050:            public DefaultTreeCellEditorTest(final String name) {
051:                super (name);
052:            }
053:
054:            @Override
055:            protected void setUp() throws Exception {
056:                tree = new JTree();
057:                renderer = new DefaultTreeCellRenderer();
058:                editor = new DefaultTreeCellEditor(tree, renderer);
059:            }
060:
061:            @Override
062:            protected void tearDown() throws Exception {
063:                editor = null;
064:                tree = null;
065:                renderer = null;
066:            }
067:
068:            public void testDefaultTextField() throws Exception {
069:                editor.getTreeCellEditorComponent(tree, "any", false, true,
070:                        false, 0);
071:                assertTrue(editor.editingComponent instanceof  DefaultTreeCellEditor.DefaultTextField);
072:                DefaultTreeCellEditor.DefaultTextField defaultTextField = (DefaultTreeCellEditor.DefaultTextField) editor.editingComponent;
073:                assertEquals(UIManager.getBorder("Tree.editorBorder"),
074:                        defaultTextField.border);
075:                Border b = BorderFactory.createBevelBorder(0);
076:                defaultTextField = editor.new DefaultTextField(b);
077:                assertSame(b, defaultTextField.border);
078:            }
079:
080:            public void testDefaultTextField_getSetBorder() throws Exception {
081:                Border b = BorderFactory.createBevelBorder(0);
082:                DefaultTreeCellEditor.DefaultTextField defaultTextField = editor.new DefaultTextField(
083:                        b);
084:                assertSame(b, defaultTextField.getBorder());
085:                propertyChangeController = new PropertyChangeController();
086:                defaultTextField
087:                        .addPropertyChangeListener(propertyChangeController);
088:                b = BorderFactory.createEmptyBorder();
089:                defaultTextField.setBorder(b);
090:                assertSame(b, defaultTextField.getBorder());
091:                assertTrue(propertyChangeController.isChanged("border"));
092:            }
093:
094:            public void testDefaultTextField_getFont() throws Exception {
095:                DefaultTreeCellEditor.DefaultTextField defaultTextField = editor.new DefaultTextField(
096:                        BorderFactory.createBevelBorder(0));
097:                assertEquals(UIManager.getFont("TextField.font"),
098:                        defaultTextField.getFont());
099:                Font f = new Font("font", 0, 30);
100:                defaultTextField.setFont(f);
101:                assertEquals(f, defaultTextField.getFont());
102:                defaultTextField.setFont(null);
103:                assertNull(defaultTextField.getFont());
104:                editor.setFont(f);
105:                assertNull(defaultTextField.getFont());
106:                editor.renderer.setFont(f);
107:                assertNull(defaultTextField.getFont());
108:                editor.tree.setFont(f);
109:                assertNull(defaultTextField.getFont());
110:            }
111:
112:            public void testDefaultTextField_getPreferredSize()
113:                    throws Exception {
114:                DefaultTreeCellEditor.DefaultTextField defaultTextField = editor.new DefaultTextField(
115:                        BorderFactory.createBevelBorder(0));
116:                defaultTextField.setText("value");
117:                assertEquals(new Dimension(new JTextField("value")
118:                        .getPreferredSize().width, 0), defaultTextField
119:                        .getPreferredSize());
120:                editor.renderer.setPreferredSize(new Dimension(100, 200));
121:                assertEquals(new Dimension(new JTextField("value")
122:                        .getPreferredSize().width, 200), defaultTextField
123:                        .getPreferredSize());
124:            }
125:
126:            public void testEditorContainer() throws Exception {
127:                DefaultTreeCellEditor.EditorContainer container = editor.new EditorContainer();
128:                assertEquals(0, container.getComponentCount());
129:                assertEquals(new Rectangle(), container.getBounds());
130:            }
131:
132:            public void testEditorContainer_getPreferredSize() throws Exception {
133:                DefaultTreeCellEditor.EditorContainer container = editor.new EditorContainer();
134:                assertEquals(new Dimension(), container.getPreferredSize());
135:                editor.editingComponent = new JTextField("a");
136:                assertEquals(new Dimension(100, editor.editingComponent
137:                        .getPreferredSize().height), container
138:                        .getPreferredSize());
139:                editor.offset = 1000;
140:                assertEquals(new Dimension(1000 + editor.editingComponent
141:                        .getPreferredSize().width + 5, editor.editingComponent
142:                        .getPreferredSize().height), container
143:                        .getPreferredSize());
144:                editor.renderer.setPreferredSize(new Dimension(2000, 10));
145:                assertEquals(new Dimension(1000 + editor.editingComponent
146:                        .getPreferredSize().width + 5, editor.editingComponent
147:                        .getPreferredSize().height), container
148:                        .getPreferredSize());
149:                editor.renderer.setPreferredSize(new Dimension(2000, 30));
150:                assertEquals(new Dimension(1000 + editor.editingComponent
151:                        .getPreferredSize().width + 5, 30), container
152:                        .getPreferredSize());
153:            }
154:
155:            public void testEditorContainer_doLayout() throws Exception {
156:                DefaultTreeCellEditor.EditorContainer container = editor.new EditorContainer();
157:                editor.editingComponent = new JTextField("any");
158:                assertEquals(new Rectangle(0, 0, 0, 0), editor.editingComponent
159:                        .getBounds());
160:                container.doLayout();
161:                assertEquals(new Rectangle(0, 0, 0, 0), editor.editingComponent
162:                        .getBounds());
163:                editor.offset = 10;
164:                container.doLayout();
165:                assertEquals(new Rectangle(10, 0, -10, 0),
166:                        editor.editingComponent.getBounds());
167:                container.setBounds(0, 0, 100, 100);
168:                container.doLayout();
169:                assertEquals(new Rectangle(10, 0, 90, 100),
170:                        editor.editingComponent.getBounds());
171:            }
172:
173:            public void testDefaultTreeCellEditor() throws Exception {
174:                assertNull(editor.borderSelectionColor);
175:                assertFalse(editor.canEdit);
176:                assertNull(editor.editingComponent);
177:                assertTrue(editor.editingContainer instanceof  DefaultTreeCellEditor.EditorContainer);
178:                assertNull(editor.editingIcon);
179:                assertNull(editor.font);
180:                assertNull(editor.lastPath);
181:                assertEquals(0, editor.lastRow);
182:                assertEquals(0, editor.offset);
183:                assertTrue(editor.realEditor instanceof  DefaultCellEditor);
184:                assertSame(renderer, editor.renderer);
185:                assertNull(editor.timer);
186:                assertSame(tree, editor.tree);
187:                assertEquals(1, ((DefaultCellEditor) editor.realEditor)
188:                        .getClickCountToStart());
189:                DefaultCellEditor realEditor = new DefaultCellEditor(
190:                        new JTextField());
191:                realEditor.setClickCountToStart(4);
192:                editor = new DefaultTreeCellEditor(tree, renderer, realEditor);
193:                assertSame(realEditor, editor.realEditor);
194:                assertEquals(4, ((DefaultCellEditor) editor.realEditor)
195:                        .getClickCountToStart());
196:            }
197:
198:            public void testGetSetBorderSelectionColor() throws Exception {
199:                assertNull(editor.getBorderSelectionColor());
200:                Color c = Color.RED;
201:                editor.setBorderSelectionColor(c);
202:                assertSame(c, editor.getBorderSelectionColor());
203:                c = new ColorUIResource(Color.BLUE);
204:                editor.setBorderSelectionColor(c);
205:                assertSame(c, editor.getBorderSelectionColor());
206:            }
207:
208:            public void testGetSetFont() throws Exception {
209:                assertNull(editor.getFont());
210:                Font font = new Font("font", 0, 20);
211:                renderer.setFont(font);
212:                assertNull(editor.getFont());
213:                assertSame(font, editor.getTreeCellEditorComponent(tree,
214:                        "value", false, false, false, 0).getFont());
215:                font = new Font("font", 0, 50);
216:                editor.setFont(font);
217:                assertSame(font, editor.getFont());
218:                assertSame(font, editor.getTreeCellEditorComponent(tree,
219:                        "value", false, false, false, 0).getFont());
220:            }
221:
222:            public void testGetTreeCellEditorComponent() throws Exception {
223:                Font font = new Font("font", 0, 30);
224:                tree.setFont(font);
225:                assertNull(editor.editingComponent);
226:                assertSame(editor.editingContainer, editor
227:                        .getTreeCellEditorComponent(tree, "value", false,
228:                                false, false, 0));
229:                assertEquals(1, editor.editingContainer.getComponentCount());
230:                assertSame(font, editor.editingContainer.getFont());
231:                assertSame(font, editor.editingComponent.getFont());
232:                assertSame(editor.realEditor.getTreeCellEditorComponent(tree,
233:                        "value", false, false, false, 0),
234:                        editor.editingContainer.getComponent(0));
235:                assertSame(editor.editingContainer.getComponent(0),
236:                        editor.editingComponent);
237:                assertTrue(editor.editingComponent instanceof  DefaultTreeCellEditor.DefaultTextField);
238:                DefaultTreeCellEditor.DefaultTextField textField = (DefaultTextField) editor.editingComponent;
239:                assertEquals("value", textField.getText());
240:                assertEquals(tree.getFont(), textField.getFont());
241:            }
242:
243:            public void testGetCellEditorValue() throws Exception {
244:                assertEquals("", editor.getCellEditorValue());
245:                editor.editingComponent = new JTextField("any");
246:                assertEquals("", editor.getCellEditorValue());
247:                editor.realEditor.getTreeCellEditorComponent(tree, "value",
248:                        false, false, false, 0);
249:                assertEquals("value", editor.getCellEditorValue());
250:                assertEquals("any", ((JTextField) editor.editingComponent)
251:                        .getText());
252:                editor.getTreeCellEditorComponent(tree, "value2", false, false,
253:                        false, 0);
254:                assertEquals("value2", editor.getCellEditorValue());
255:                assertEquals("value2", ((JTextField) editor.editingComponent)
256:                        .getText());
257:            }
258:
259:            public void testIsCellEditable() throws Exception {
260:                final Marker m = new Marker();
261:                editor = new DefaultTreeCellEditor(tree, renderer) {
262:                    @Override
263:                    protected void prepareForEditing() {
264:                        m.setOccurred();
265:                    }
266:                };
267:                assertTrue(editor.isCellEditable(null));
268:                assertTrue(m.isOccurred());
269:            }
270:
271:            public void testShouldSelectCell() throws Exception {
272:                final Marker m = new Marker();
273:                editor = new DefaultTreeCellEditor(tree, renderer) {
274:                    @Override
275:                    public boolean shouldSelectCell(final EventObject e) {
276:                        m.setOccurred();
277:                        m.setAuxiliary(e);
278:                        return true;
279:                    }
280:                };
281:                EventObject eo = new EventObject(this );
282:                assertTrue(editor.shouldSelectCell(eo));
283:                assertTrue(m.isOccurred());
284:                assertSame(eo, m.getAuxiliary());
285:            }
286:
287:            public void testStopCellEditing() throws Exception {
288:                editor.getTreeCellEditorComponent(tree, "value", false, false,
289:                        false, 0);
290:                assertNotNull(editor.editingComponent);
291:                assertEquals(1, editor.editingContainer.getComponentCount());
292:                assertTrue(editor.stopCellEditing());
293:                assertNull(editor.editingComponent);
294:                assertEquals(0, editor.editingContainer.getComponentCount());
295:            }
296:
297:            public void testCancelCellEditing() throws Exception {
298:                editor.getTreeCellEditorComponent(tree, "value", false, false,
299:                        false, 0);
300:                assertNotNull(editor.editingComponent);
301:                assertEquals(1, editor.editingContainer.getComponentCount());
302:                editor.cancelCellEditing();
303:                assertNull(editor.editingComponent);
304:                assertEquals(0, editor.editingContainer.getComponentCount());
305:            }
306:
307:            public void testAddRemoveGetCellEditorListener() throws Exception {
308:                assertEquals(0, editor.getCellEditorListeners().length);
309:                assertEquals(0, ((DefaultCellEditor) editor.realEditor)
310:                        .getCellEditorListeners().length);
311:                CellEditorListener l = new CellEditorListener() {
312:                    public void editingStopped(ChangeEvent e) {
313:                    }
314:
315:                    public void editingCanceled(ChangeEvent e) {
316:                    }
317:                };
318:                editor.addCellEditorListener(l);
319:                assertEquals(1, editor.getCellEditorListeners().length);
320:                assertEquals(1, ((DefaultCellEditor) editor.realEditor)
321:                        .getCellEditorListeners().length);
322:                editor.removeCellEditorListener(l);
323:                assertEquals(0, ((DefaultCellEditor) editor.realEditor)
324:                        .getCellEditorListeners().length);
325:            }
326:
327:            public void testValueChanged() throws Exception {
328:                TreePath treePath = new TreePath("root");
329:                editor.valueChanged(new TreeSelectionEvent(tree, treePath,
330:                        true, null, treePath));
331:                if (isHarmony()) {
332:                    assertEquals(treePath, editor.lastPath);
333:                } else {
334:                    assertNull(editor.lastPath);
335:                }
336:            }
337:
338:            public void testActionPerformed() throws Exception {
339:                editor.lastPath = new TreePath(tree.getModel().getRoot());
340:                editor.lastRow = 10;
341:                editor.actionPerformed(null);
342:                if (isHarmony()) {
343:                    assertEquals(0, editor.lastRow);
344:                } else {
345:                    assertEquals(10, editor.lastRow);
346:                }
347:            }
348:
349:            public void testSetTree() throws Exception {
350:                JTree anotherTree = new JTree();
351:                assertEquals(0, anotherTree.getTreeSelectionListeners().length);
352:                editor.setTree(anotherTree);
353:                assertEquals(1, anotherTree.getTreeSelectionListeners().length);
354:                assertSame(anotherTree, editor.tree);
355:            }
356:
357:            public void testShouldStartEditingTimer() throws Exception {
358:                assertFalse(editor.shouldStartEditingTimer(null));
359:                assertTrue(editor.shouldStartEditingTimer(new MouseEvent(tree,
360:                        MouseEvent.MOUSE_PRESSED, 0,
361:                        InputEvent.BUTTON1_DOWN_MASK, 1, 1, 1, false,
362:                        MouseEvent.BUTTON1)));
363:                assertFalse(editor.shouldStartEditingTimer(new MouseEvent(tree,
364:                        MouseEvent.MOUSE_PRESSED, 0,
365:                        InputEvent.BUTTON1_DOWN_MASK, 1, 1, 2, false,
366:                        MouseEvent.BUTTON1)));
367:            }
368:
369:            public void testStartEditingTimer() throws Exception {
370:                assertNull(editor.timer);
371:                editor.startEditingTimer();
372:                assertTrue(editor.timer.isRunning());
373:                assertEquals(1200, editor.timer.getDelay());
374:            }
375:
376:            @SuppressWarnings("deprecation")
377:            public void testCanEditimmediately() throws Exception {
378:                assertTrue(editor.canEditImmediately(null));
379:                assertTrue(editor.canEditImmediately(new MouseEvent(tree,
380:                        MouseEvent.MOUSE_PRESSED, 0, 0, 1, 1, 3, false,
381:                        MouseEvent.BUTTON1)));
382:                assertTrue(editor.canEditImmediately(new MouseEvent(tree,
383:                        MouseEvent.MOUSE_PRESSED, 0, 0, 1, 1, 4, false,
384:                        MouseEvent.BUTTON1)));
385:                assertFalse(editor.canEditImmediately(new MouseEvent(tree,
386:                        MouseEvent.MOUSE_PRESSED, 0, 0, 1, 1, 3, false,
387:                        MouseEvent.BUTTON2)));
388:                assertFalse(editor.canEditImmediately(new MouseEvent(tree,
389:                        MouseEvent.MOUSE_PRESSED, 0, 0, 1, 1, 2, false,
390:                        MouseEvent.BUTTON1)));
391:                assertFalse(editor.canEditImmediately(new KeyEvent(tree,
392:                        KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_1)));
393:            }
394:
395:            public void testInHitRegion() throws Exception {
396:                assertFalse(editor.inHitRegion(0, 0));
397:                assertTrue(editor.inHitRegion(1, 0));
398:                if (isHarmony()) {
399:                    assertFalse(editor.inHitRegion(1000, 1000));
400:                } else {
401:                    assertTrue(editor.inHitRegion(1000, 1000));
402:                }
403:                editor.offset = 30;
404:                assertFalse(editor.inHitRegion(30, 1));
405:                assertTrue(editor.inHitRegion(31, 1));
406:            }
407:
408:            public void testDetermineOffset() throws Exception {
409:                assertEquals(0, editor.offset);
410:                editor.determineOffset(tree, "value", false, false, false, 0);
411:                assertEquals(20, editor.offset);
412:                editor.offset = 10;
413:                editor.determineOffset(tree, "value", false, false, false, 0);
414:                assertEquals(20, editor.offset);
415:            }
416:
417:            public void testPrepareForEditing() throws Exception {
418:                assertEquals(0, editor.editingContainer.getComponentCount());
419:                editor.prepareForEditing();
420:                assertEquals(0, editor.editingContainer.getComponentCount());
421:                editor.editingComponent = new JTextField("any");
422:                editor.prepareForEditing();
423:                assertEquals(1, editor.editingContainer.getComponentCount());
424:            }
425:
426:            public void testCreateContainer() throws Exception {
427:                assertNotSame(editor.createContainer(), editor
428:                        .createContainer());
429:                assertTrue(editor.createContainer() instanceof  DefaultTreeCellEditor.EditorContainer);
430:            }
431:
432:            public void testCreateTreeCellEditor() throws Exception {
433:                assertNotSame(editor.createTreeCellEditor(), editor
434:                        .createTreeCellEditor());
435:                assertTrue(editor.createTreeCellEditor() instanceof  DefaultCellEditor);
436:                assertTrue(editor.createTreeCellEditor()
437:                        .getTreeCellEditorComponent(tree, "any", false, true,
438:                                false, 0) instanceof  DefaultTreeCellEditor.DefaultTextField);
439:                assertEquals(1, ((DefaultCellEditor) editor
440:                        .createTreeCellEditor()).getClickCountToStart());
441:            }
442:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.