Source Code Cross Referenced for PlainView_ChangesRTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » text » 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.text 
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 Alexey A. Ivanov
019:         * @version $Revision$
020:         */package javax.swing.text;
021:
022:        import java.awt.Component;
023:        import java.awt.Container;
024:        import java.awt.Rectangle;
025:        import java.awt.Shape;
026:        import javax.swing.BasicSwingTestCase;
027:        import javax.swing.JTextArea;
028:        import javax.swing.event.DocumentEvent;
029:        import javax.swing.event.DocumentListener;
030:        import javax.swing.text.PlainView_ChangesTest.LineRange;
031:
032:        public class PlainView_ChangesRTest extends BasicSwingTestCase
033:                implements  DocumentListener {
034:            private boolean callSuperDamageRange;
035:
036:            private Container container;
037:
038:            private Document doc;
039:
040:            private DocumentEvent event;
041:
042:            private LineRange lineRange;
043:
044:            private Rectangle paintRect;
045:
046:            private Element root;
047:
048:            private Shape shape;
049:
050:            private PlainView view;
051:
052:            /**
053:             * Tests for <code>PlainView.insertUpdate</code> throws NPE.
054:             * <p>
055:             * If a change occured outside the widest line and document structure
056:             * was not changed, <code>insertUpdate</code> throws NPE
057:             * when processing the notification.
058:             */
059:            public void testInsertUpdateNPE() throws BadLocationException {
060:                doc.insertString(0, "1:0123\n2:\n3:abcdefg", null);
061:                view.updateMetrics();
062:                doc.insertString(0, "^", null);
063:                view.insertUpdate(event, shape, null);
064:            }
065:
066:            /**
067:             * Tests for <code>PlainView</code> repaints more lines
068:             * than necessary.
069:             * <p>
070:             * If a character (not a new line) is inserted into document,
071:             * document structure will not change, or in other words the number of
072:             * text lines will stay the same.
073:             * In this case only the modified line needs to be repainted
074:             * but <code>PlainView</code> repaints all following lines as well.
075:             */
076:            public void testInsertUpdateExtraRepaint()
077:                    throws BadLocationException {
078:                doc.insertString(0, "1:0123\n2:\n3:abcdefg", null);
079:                view.updateMetrics();
080:                doc.insertString(0, "^", null);
081:                view.insertUpdate(event, shape, null);
082:                lineRange.check(0, 0, shape, container);
083:            }
084:
085:            /**
086:             * Tests for calling <code>nextTabStop()</code> leaves
087:             * <code>PlainView.metrics</code> field <code>null</code>.
088:             * This is because <code>nextTabStop()</code> forwards to
089:             * <code>paintParams</code> and updates <code>metrics</code> there,
090:             * and <code>setSize()</code> doesn't update the field in
091:             * the <code>PlainView</code>.
092:             */
093:            public void testNextTabStop05() {
094:                assertNull(view.metrics);
095:                if (isHarmony()) {
096:                    // Call to nextTabStop will lead to updateMetrics()
097:                    assertTrue("nextTabStop() must return value > 0", view
098:                            .nextTabStop(0, 0) > view.getTabSize());
099:                }
100:                view.setSize(100, 200);
101:                assertNotNull("Metrics must be not null after setSize",
102:                        view.metrics);
103:            }
104:
105:            @Override
106:            protected void setUp() throws Exception {
107:                super .setUp();
108:                doc = new PlainDocument();
109:                root = doc.getDefaultRootElement();
110:                view = new PlainView(root) {
111:                    @Override
112:                    public Container getContainer() {
113:                        if (container == null) {
114:                            container = new JTextArea() {
115:                                private static final long serialVersionUID = 1L;
116:
117:                                @Override
118:                                public void repaint(final int x, final int y,
119:                                        final int w, final int h) {
120:                                    if (paintRect == null) {
121:                                        paintRect = new Rectangle(x, y, w, h);
122:                                    } else {
123:                                        paintRect
124:                                                .add(new Rectangle(x, y, w, h));
125:                                    }
126:                                }
127:                            };
128:                        }
129:                        return container;
130:                    }
131:
132:                    @Override
133:                    protected void damageLineRange(final int line0,
134:                            final int line1, final Shape shape,
135:                            final Component host) {
136:                        if (callSuperDamageRange) {
137:                            super .damageLineRange(line0, line1, shape, host);
138:                        } else {
139:                            lineRange = new LineRange(line0, line1, shape, host);
140:                        }
141:                    }
142:                };
143:                shape = new Rectangle(500, 500);
144:                doc.addDocumentListener(this );
145:            }
146:
147:            public void changedUpdate(final DocumentEvent changes) {
148:                fail("changedUpdate isn't supposed to be called");
149:            }
150:
151:            public void insertUpdate(final DocumentEvent changes) {
152:                event = changes;
153:            }
154:
155:            public void removeUpdate(final DocumentEvent changes) {
156:                event = changes;
157:            }
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.