Source Code Cross Referenced for ScrollPaneAdjustableTest.java in  » Apache-Harmony-Java-SE » java-package » java » awt » 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 » java package » java.awt 
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 Dmitry A. Durnev
019:         * @version $Revision$
020:         */package java.awt;
021:
022:        import java.awt.event.AdjustmentEvent;
023:        import java.awt.event.AdjustmentListener;
024:
025:        import junit.framework.TestCase;
026:
027:        /**
028:         * ScrollPaneAdjustableTest
029:         */
030:        public class ScrollPaneAdjustableTest extends TestCase {
031:            ScrollPane scrollPane;
032:            Frame f;
033:            ScrollPaneAdjustable hAdjustable, vAdjustable;
034:            private final int HSIZE = 1500;
035:            private final int VSIZE = 200;
036:
037:            @SuppressWarnings("deprecation")
038:            @Override
039:            protected void setUp() throws Exception {
040:                super .setUp();
041:                f = new Frame();
042:                scrollPane = new ScrollPane();
043:                hAdjustable = (ScrollPaneAdjustable) scrollPane
044:                        .getHAdjustable();
045:                checkAdjustable(hAdjustable, Adjustable.HORIZONTAL, 0, 0, 0, 0,
046:                        1, 1);
047:                vAdjustable = (ScrollPaneAdjustable) scrollPane
048:                        .getVAdjustable();
049:                checkAdjustable(vAdjustable, Adjustable.VERTICAL, 0, 0, 0, 0,
050:                        1, 1);
051:                Button b = new Button();
052:                b.setPreferredSize(new Dimension(HSIZE, VSIZE));
053:                scrollPane.add(b);
054:                f.add(scrollPane);
055:                f.show();
056:            }
057:
058:            @Override
059:            protected void tearDown() throws Exception {
060:                super .tearDown();
061:                if (f != null) {
062:                    f.dispose();
063:                }
064:            }
065:
066:            private void checkAdjustable(Adjustable adj, int orient, int value,
067:                    int vis, int min, int max, int unit, int block) {
068:                assertEquals(orient, adj.getOrientation());
069:                assertEquals(value, adj.getValue());
070:                assertEquals(vis, adj.getVisibleAmount());
071:                assertEquals(min, adj.getMinimum());
072:                assertEquals(max, adj.getMaximum());
073:                assertEquals(unit, adj.getUnitIncrement());
074:                assertEquals(block, adj.getBlockIncrement());
075:            }
076:
077:            public final void testToString() {
078:                assertEquals("toString() format is correct", vAdjustable
079:                        .getClass().getName()
080:                        + "[" + vAdjustable.paramString() + "]", vAdjustable
081:                        .toString());
082:            }
083:
084:            public final void testGetValue() {
085:                assertEquals(0, vAdjustable.getValue());
086:                assertEquals(0, hAdjustable.getValue());
087:            }
088:
089:            public final void testSetValue() {
090:                int val = Integer.MIN_VALUE;
091:                vAdjustable.setValue(val);
092:                assertEquals(vAdjustable.getMinimum(), vAdjustable.getValue());
093:                vAdjustable.setValue(val = (VSIZE / 2));
094:                assertEquals(val, vAdjustable.getValue());
095:                vAdjustable.setValue(val = VSIZE);
096:                assertEquals(val - vAdjustable.getVisibleAmount(), vAdjustable
097:                        .getValue());
098:                vAdjustable.setValue(val = Integer.MAX_VALUE);
099:                assertEquals(vAdjustable.getMaximum()
100:                        - vAdjustable.getVisibleAmount(), vAdjustable
101:                        .getValue());
102:            }
103:
104:            public final void testGetBlockIncrement() {
105:                int vis = vAdjustable.getVisibleAmount();
106:                assertEquals(getBlockIncrFromVis(vis), vAdjustable
107:                        .getBlockIncrement());
108:                vis = hAdjustable.getVisibleAmount();
109:                assertEquals(getBlockIncrFromVis(vis), hAdjustable
110:                        .getBlockIncrement());
111:            }
112:
113:            private int getBlockIncrFromVis(int vis) {
114:                return Math.max(1, vis * 9 / 10);
115:            }
116:
117:            private int getVisFromSize(int size, int gap) {
118:                return Math.max(1, size - gap);
119:            }
120:
121:            public final void testGetMaximum() {
122:                assertEquals(VSIZE, vAdjustable.getMaximum());
123:                assertEquals(HSIZE, hAdjustable.getMaximum());
124:            }
125:
126:            public final void testGetMinimum() {
127:                assertEquals(0, vAdjustable.getMinimum());
128:                assertEquals(0, hAdjustable.getMinimum());
129:            }
130:
131:            public final void testGetOrientation() {
132:                assertEquals(Adjustable.HORIZONTAL, hAdjustable
133:                        .getOrientation());
134:                assertEquals(Adjustable.VERTICAL, vAdjustable.getOrientation());
135:            }
136:
137:            public final void testGetUnitIncrement() {
138:                assertEquals(1, vAdjustable.getUnitIncrement());
139:                assertEquals(1, hAdjustable.getUnitIncrement());
140:            }
141:
142:            public final void testGetValueIsAdjusting() {
143:                assertFalse(vAdjustable.getValueIsAdjusting());
144:                assertFalse(hAdjustable.getValueIsAdjusting());
145:            }
146:
147:            public final void testGetVisibleAmount() {
148:                int size = scrollPane.getHeight();
149:                Insets insets = scrollPane.getInsets();
150:                int vGap = insets.bottom + insets.top;
151:                int hGap = insets.left + insets.right;
152:                assertEquals(getVisFromSize(size, vGap), vAdjustable
153:                        .getVisibleAmount());
154:                size = scrollPane.getWidth();
155:                assertEquals(getVisFromSize(size, hGap), hAdjustable
156:                        .getVisibleAmount());
157:            }
158:
159:            public final void testParamString() {
160:                String hStr = hAdjustable.paramString();
161:                String vStr = vAdjustable.paramString();
162:                assertTrue(vStr.indexOf("vertical") >= 0);
163:                assertTrue(hStr.indexOf("horizontal") >= 0);
164:                assertTrue(vStr.indexOf(",val=0") > 0);
165:                assertTrue(vStr.indexOf(",vis="
166:                        + vAdjustable.getVisibleAmount()) > 0);
167:                assertTrue(vStr.indexOf(",[" + vAdjustable.getMinimum() + ".."
168:                        + vAdjustable.getMaximum() + "]") > 0);
169:                assertTrue(vStr.indexOf(",unit="
170:                        + vAdjustable.getUnitIncrement()) > 0);
171:                assertTrue(vStr.indexOf(",block="
172:                        + vAdjustable.getBlockIncrement()) > 0);
173:                assertTrue(vStr.indexOf(",isAdjusting=false") > 0);
174:            }
175:
176:            public final void testSetBlockIncrement() {
177:                int blockIncr = 25;
178:                hAdjustable.setBlockIncrement(blockIncr);
179:                assertEquals(blockIncr, hAdjustable.getBlockIncrement());
180:
181:                hAdjustable.setBlockIncrement(blockIncr = Integer.MIN_VALUE);
182:                assertEquals(blockIncr, hAdjustable.getBlockIncrement());
183:                hAdjustable.setBlockIncrement(blockIncr = Integer.MAX_VALUE);
184:                assertEquals(blockIncr, hAdjustable.getBlockIncrement());
185:            }
186:
187:            public final void testSetMaximum() {
188:                boolean errorCatched = false;
189:                try {
190:                    hAdjustable.setMaximum(256);
191:                } catch (AWTError err) {
192:                    errorCatched = true;
193:                }
194:                assertTrue(errorCatched);
195:            }
196:
197:            public final void testSetMinimum() {
198:                boolean errorCatched = false;
199:                try {
200:                    vAdjustable.setMinimum(-256);
201:                } catch (AWTError err) {
202:                    errorCatched = true;
203:                }
204:                assertTrue(errorCatched);
205:            }
206:
207:            public final void testSetUnitIncrement() {
208:                int unitIncr = 10;
209:                vAdjustable.setUnitIncrement(unitIncr);
210:                assertEquals(unitIncr, vAdjustable.getUnitIncrement());
211:
212:                vAdjustable.setUnitIncrement(unitIncr = Integer.MIN_VALUE);
213:                assertEquals(unitIncr, vAdjustable.getUnitIncrement());
214:                vAdjustable.setUnitIncrement(unitIncr = Integer.MAX_VALUE);
215:                assertEquals(unitIncr, vAdjustable.getUnitIncrement());
216:            }
217:
218:            public final void testSetValueIsAdjusting() {
219:                vAdjustable.setValueIsAdjusting(true);
220:                assertTrue(vAdjustable.getValueIsAdjusting());
221:                vAdjustable.setValueIsAdjusting(false);
222:                assertFalse(vAdjustable.getValueIsAdjusting());
223:            }
224:
225:            public final void testSetVisibleAmount() {
226:                boolean errorCatched = false;
227:                try {
228:                    hAdjustable.setVisibleAmount(HSIZE / 2);
229:                } catch (AWTError err) {
230:                    errorCatched = true;
231:                }
232:                assertTrue(errorCatched);
233:            }
234:
235:            public void testAddGetRemoveAdjustmentListener() {
236:                assertEquals(0, vAdjustable.getAdjustmentListeners().length);
237:
238:                AdjustmentListener listener = new AdjustmentListener() {
239:                    public void adjustmentValueChanged(AdjustmentEvent ae) {
240:                    }
241:                };
242:                vAdjustable.addAdjustmentListener(listener);
243:                assertEquals(1, vAdjustable.getAdjustmentListeners().length);
244:                assertSame(listener, vAdjustable.getAdjustmentListeners()[0]);
245:
246:                vAdjustable.removeAdjustmentListener(listener);
247:                assertEquals(0, vAdjustable.getAdjustmentListeners().length);
248:            }
249:
250:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.