Source Code Cross Referenced for XScrollPane.java in  » Swing-Library » wings3 » org » wingx » 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 » Swing Library » wings3 » org.wingx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.wingx;
002:
003:        import org.wings.*;
004:        import org.wingx.table.TruncatableModel;
005:
006:        import javax.swing.*;
007:        import javax.swing.table.TableModel;
008:        import java.awt.*;
009:        import java.awt.event.*;
010:        import java.text.MessageFormat;
011:        import java.util.*;
012:
013:        /**
014:         * XScrollPane
015:         *
016:         * @author jdenzel
017:         */
018:        public class XScrollPane extends SScrollPane {
019:
020:            private ExtentComboModel extentModel = new ExtentComboModel(
021:                    new Vector<Integer>(Arrays.asList(8, 10, 12, 14, 16, 18,
022:                            20, 22, 24, 26, 28, 30, 32)));
023:
024:            protected SComboBox extentCombo = new SComboBox(extentModel);
025:            protected final XPageScroller pageScroller = new XPageScroller();
026:            protected final SLabel extentComboLabel = new SLabel();
027:            protected final SLabel totalLabel = new SLabel();
028:            private STable tableComponent;
029:            private String visibleSectionLabel = "{0} .. {1} of {2}";
030:
031:            public XScrollPane() {
032:                this (null);
033:            }
034:
035:            public XScrollPane(STable tableComponent) {
036:                this (tableComponent, 10);
037:            }
038:
039:            public XScrollPane(STable tableComponent, int verticalExtent) {
040:                setPreferredSize(SDimension.FULLAREA);
041:                setVerticalAlignment(SConstants.TOP_ALIGN);
042:
043:                extentCombo.addActionListener(new ExtentComboActionListener());
044:
045:                pageScroller.add(totalLabel);
046:                pageScroller.add(extentComboLabel);
047:                pageScroller.add(extentCombo);
048:                pageScroller.add(new SLabel(" "), 1d);
049:
050:                pageScroller
051:                        .addAdjustmentListener(new PageAdjustmentListener());
052:                pageScroller.setExtent(verticalExtent);
053:                pageScroller.setHorizontalAlignment(SConstants.LEFT_ALIGN);
054:
055:                setHorizontalScrollBar(pageScroller);
056:                setHorizontalScrollBarPolicy(SScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
057:                setVerticalScrollBar(null);
058:                setVerticalScrollBarPolicy(SScrollPane.VERTICAL_SCROLLBAR_NEVER);
059:                setMode(SScrollPane.MODE_PAGING);
060:
061:                setHorizontalExtent(20);
062:                setVerticalExtent(verticalExtent);
063:
064:                if (tableComponent != null)
065:                    setViewportView(tableComponent);
066:            }
067:
068:            /**
069:             * Sets the horizontal scrollbar.
070:             *
071:             * @param sb         the scrollbar that controls the viewport's horizontal view position
072:             * @param constraint the constraint for the {@link LayoutManager} of this {@link SContainer}.
073:             *                   The {@link LayoutManager} is per default {@link SScrollPaneLayout}.
074:             */
075:            public void setHorizontalScrollBar(Adjustable sb, String constraint) {
076:                if (horizontalScrollBar != null) {
077:                    if (horizontalScrollBar instanceof  SAbstractAdjustable)
078:                        ((SAbstractAdjustable) horizontalScrollBar)
079:                                .setModel(new SDefaultBoundedRangeModel());
080:                    else if (horizontalScrollBar instanceof  XPageScroller)
081:                        ((XPageScroller) horizontalScrollBar)
082:                                .setModel(new SDefaultBoundedRangeModel());
083:
084:                    if (horizontalScrollBar instanceof  SComponent)
085:                        remove((SComponent) horizontalScrollBar);
086:                }
087:
088:                horizontalScrollBar = sb;
089:
090:                if (horizontalScrollBar != null) {
091:                    if (horizontalScrollBar instanceof  SComponent)
092:                        addComponent((SComponent) horizontalScrollBar,
093:                                constraint, getComponentCount());
094:
095:                    if (horizontalScrollBar instanceof  SAbstractAdjustable) {
096:                        SAbstractAdjustable scrollbar = (SAbstractAdjustable) horizontalScrollBar;
097:                        if (scrollbar.getOrientation() == SConstants.HORIZONTAL)
098:                            scrollbar.setModel(horizontalModel);
099:                        else
100:                            scrollbar.setModel(verticalModel);
101:                    } else if (horizontalScrollBar instanceof  XPageScroller) {
102:                        XPageScroller scrollbar = (XPageScroller) horizontalScrollBar;
103:                        if (scrollbar.getOrientation() == SConstants.HORIZONTAL)
104:                            scrollbar.setModel(horizontalModel);
105:                        else
106:                            scrollbar.setModel(verticalModel);
107:                    }
108:
109:                    adoptScrollBarVisibility(horizontalScrollBar,
110:                            horizontalScrollBarPolicy);
111:                }
112:
113:                reload();
114:            }
115:
116:            /**
117:             * Sets the vertical scrollbar.
118:             *
119:             * @param sb         the scrollbar that controls the viewport's vertical view position
120:             * @param constraint the constraint for the {@link LayoutManager} of this {@link SContainer}.
121:             *                   The {@link LayoutManager} is per default {@link SScrollPaneLayout}.
122:             */
123:            public void setVerticalScrollBar(Adjustable sb, String constraint) {
124:                if (verticalScrollBar != null) {
125:                    if (verticalScrollBar instanceof  SAbstractAdjustable)
126:                        ((SAbstractAdjustable) verticalScrollBar)
127:                                .setModel(new SDefaultBoundedRangeModel());
128:                    else if (verticalScrollBar instanceof  XPageScroller)
129:                        ((XPageScroller) verticalScrollBar)
130:                                .setModel(new SDefaultBoundedRangeModel());
131:
132:                    if (verticalScrollBar instanceof  SComponent)
133:                        remove((SComponent) verticalScrollBar);
134:                }
135:
136:                verticalScrollBar = sb;
137:
138:                if (verticalScrollBar != null) {
139:                    if (verticalScrollBar instanceof  SComponent)
140:                        addComponent((SComponent) verticalScrollBar,
141:                                constraint, getComponentCount());
142:
143:                    if (verticalScrollBar instanceof  SAbstractAdjustable) {
144:                        SAbstractAdjustable scrollbar = (SAbstractAdjustable) verticalScrollBar;
145:                        if (scrollbar.getOrientation() == SConstants.HORIZONTAL)
146:                            scrollbar.setModel(horizontalModel);
147:                        else
148:                            scrollbar.setModel(verticalModel);
149:                    } else if (verticalScrollBar instanceof  XPageScroller) {
150:                        XPageScroller scrollbar = (XPageScroller) verticalScrollBar;
151:                        if (scrollbar.getOrientation() == SConstants.HORIZONTAL)
152:                            scrollbar.setModel(horizontalModel);
153:                        else
154:                            scrollbar.setModel(verticalModel);
155:                    }
156:
157:                    adoptScrollBarVisibility(verticalScrollBar,
158:                            verticalScrollBarPolicy);
159:                }
160:
161:                reload();
162:            }
163:
164:            public void setExtentLabel(String label) {
165:                extentComboLabel.setText(label);
166:            }
167:
168:            public String getVisibleSectionLabel() {
169:                return visibleSectionLabel;
170:            }
171:
172:            public void setVisibleSectionLabel(String visibleSectionLabel) {
173:                this .visibleSectionLabel = visibleSectionLabel;
174:            }
175:
176:            /**
177:             * @inheritDoc
178:             */
179:            public void setViewportView(SComponent view) {
180:                if (view == null) {
181:                    throw new NullPointerException();
182:                }
183:                if (getScrollable() != null) {
184:                    throw new RuntimeException(
185:                            "error: this component is not reinitializable");
186:                }
187:                if (!(view instanceof  XTable)) {
188:                    throw new RuntimeException(
189:                            "the inner component must be of type XTable");
190:                }
191:                tableComponent = (XTable) view;
192:                tableComponent.setVerticalAlignment(SConstants.TOP_ALIGN);
193:
194:                super .setViewportView(view);
195:                refresh();
196:            }
197:
198:            public void setExtents(Integer[] extents) {
199:                extentModel.setExtents(extents);
200:                reload();
201:            }
202:
203:            public void setVerticalExtent(int extent) {
204:                super .setVerticalExtent(extent);
205:                extentModel.addExtent(extent);
206:                extentCombo.setSelectedItem(extent);
207:            }
208:
209:            public void addAdjustmentListener(AdjustmentListener al) {
210:                pageScroller.addAdjustmentListener(al);
211:            }
212:
213:            public void refresh() {
214:                scrollable.getViewportSize().height = verticalExtent;
215:                refreshTotalLabel();
216:            }
217:
218:            private void refreshTotalLabel() {
219:                if (tableComponent == null)
220:                    return;
221:
222:                Rectangle viewportSize = tableComponent.getViewportSize();
223:                if (viewportSize == null) {
224:                    totalLabel.setText(null);
225:                    return;
226:                }
227:
228:                int startRow = viewportSize.y;
229:                int endRow = tableComponent.getRowCount();
230:                endRow = Math.min(startRow + viewportSize.height, endRow);
231:
232:                String text;
233:                if (endRow > 0) {
234:                    TableModel tableModel = tableComponent.getModel();
235:                    int rowCount = tableModel.getRowCount();
236:                    text = MessageFormat.format(visibleSectionLabel,
237:                            startRow + 1, endRow, rowCount);
238:
239:                    if (tableModel instanceof  TruncatableModel) {
240:                        if (((TruncatableModel) tableModel).isTruncated())
241:                            text += "  (+)";
242:                    }
243:                } else {
244:                    text = null;
245:                }
246:
247:                totalLabel.setText(text);
248:            }
249:
250:            class PageAdjustmentListener implements  AdjustmentListener {
251:                public void adjustmentValueChanged(AdjustmentEvent e) {
252:                    refreshTotalLabel();
253:                    //pageScroller.reload();
254:                }
255:            }
256:
257:            class ExtentComboActionListener implements  ActionListener {
258:                public void actionPerformed(ActionEvent e) {
259:                    if (tableComponent == null)
260:                        return;
261:                    Integer extent = (Integer) extentCombo.getSelectedItem();
262:                    assert extent != null;
263:                    setVerticalExtent(extent.intValue());
264:                }
265:            }
266:
267:            class ExtentComboModel extends DefaultComboBoxModel {
268:                private Vector<Integer> extents;
269:
270:                public ExtentComboModel(Vector<Integer> extents) {
271:                    super (extents);
272:                    this .extents = extents;
273:                }
274:
275:                public void setExtents(Integer[] extents) {
276:                    this .extents.removeAllElements();
277:                    this .extents.addAll(Arrays.asList(extents));
278:                    if (!addExtent((Integer) getSelectedItem())) {
279:                        ;
280:                        fireContentsChanged(this , -1, -1);
281:                    }
282:                }
283:
284:                public boolean addExtent(int extent) {
285:                    if (!extents.contains(extent)) {
286:                        extents.add(extent);
287:                        Collections.sort(extents);
288:                        fireContentsChanged(this , -1, -1);
289:                        return true;
290:                    }
291:                    return false;
292:                }
293:            }
294:
295:            public XPageScroller getPageScroller() {
296:                return pageScroller;
297:            }
298:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.