Source Code Cross Referenced for GraphDesktopPane.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » plugins » graph » 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 » Database Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.plugins.graph 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.plugins.graph;
002:
003:        import net.sourceforge.squirrel_sql.client.gui.ScrollableDesktopPane;
004:
005:        import javax.swing.*;
006:        import java.awt.*;
007:        import java.awt.geom.AffineTransform;
008:        import java.awt.print.Printable;
009:        import java.awt.print.PageFormat;
010:        import java.awt.print.PrinterException;
011:        import java.util.Vector;
012:        import java.util.Arrays;
013:
014:        public class GraphDesktopPane extends ScrollableDesktopPane implements 
015:                GraphPrintable {
016:            private static final long serialVersionUID = 1L;
017:            private Vector<GraphComponent> _graphComponents = new Vector<GraphComponent>();
018:            private ConstraintViewListener _constraintViewListener;
019:
020:            /////////////////////////////////////////////////////////
021:            // Printing
022:            private double _formatWidthInPixel;
023:            private double _formatHeightInPixel;
024:            private double _formatScale;
025:            private boolean _isPrinting;
026:
027:            //
028:            /////////////////////////////////////////////////////////
029:
030:            public GraphDesktopPane() {
031:                _constraintViewListener = new ConstraintViewListener() {
032:                    public void foldingPointMoved(ConstraintView source) {
033:                        revalidate();
034:                    }
035:                };
036:            }
037:
038:            public void paint(Graphics g) {
039:                super .paintComponent(g);
040:                super .paintBorder(g);
041:
042:                paintGraphComponents(g);
043:
044:                super .paintChildren(g);
045:            }
046:
047:            private void paintGraphComponents(Graphics g) {
048:                for (int i = 0; i < _graphComponents.size(); i++) {
049:                    GraphComponent comp = _graphComponents.elementAt(i);
050:                    if (comp instanceof  EdgesGraphComponent) {
051:                        ((EdgesGraphComponent) comp).setBounds(getWidth(),
052:                                getHeight());
053:                    }
054:
055:                    comp.paint(g, _isPrinting);
056:                }
057:            }
058:
059:            public void putGraphComponents(GraphComponent[] graphComponents) {
060:                for (int i = 0; i < graphComponents.length; i++) {
061:                    if (false == _graphComponents.contains(graphComponents[i])) {
062:                        if (graphComponents[i] instanceof  ConstraintView) {
063:                            ((ConstraintView) graphComponents[i])
064:                                    .addConstraintViewListener(_constraintViewListener);
065:                        }
066:
067:                        _graphComponents.add(graphComponents[i]);
068:                    }
069:                }
070:            }
071:
072:            public void removeGraphComponents(GraphComponent[] graphComponents) {
073:                _graphComponents.removeAll(Arrays.asList(graphComponents));
074:            }
075:
076:            public Vector<GraphComponent> getGraphComponents() {
077:                return _graphComponents;
078:            }
079:
080:            public Dimension getRequiredSize() {
081:                Dimension reqSize = super .getRequiredSize();
082:                for (int i = 0; i < _graphComponents.size(); i++) {
083:                    GraphComponent graphComponent = _graphComponents
084:                            .elementAt(i);
085:                    Dimension buf = graphComponent.getRequiredSize();
086:
087:                    if (buf.width > reqSize.width) {
088:                        reqSize.width = buf.width;
089:                    }
090:
091:                    if (buf.height > reqSize.height) {
092:                        reqSize.height = buf.height;
093:                    }
094:                }
095:
096:                return reqSize;
097:
098:            }
099:
100:            ////////////////////////////////////////////////////////////////////////////////////////
101:            // Printing
102:            public void initPrint(double formatWidthInCm,
103:                    double formatHeightInCm, double formatScale) {
104:                int pixelByCm = (int) (Toolkit.getDefaultToolkit()
105:                        .getScreenResolution()
106:                        * EdgesGraphComponent.CM_BY_INCH + 0.5);
107:                _formatWidthInPixel = formatWidthInCm * pixelByCm;
108:                _formatHeightInPixel = formatHeightInCm * pixelByCm;
109:                _formatScale = formatScale;
110:            }
111:
112:            public Dimension initPrintNoScaleSinglePage() {
113:                Dimension size = getSize();
114:                _formatWidthInPixel = size.width;
115:                _formatHeightInPixel = size.height;
116:                _formatScale = 1;
117:
118:                return size;
119:
120:            }
121:
122:            public int print(Graphics graphics, PageFormat pageFormat,
123:                    int pageIndex) throws PrinterException {
124:                double edgesWitdthInPixel = _formatWidthInPixel * _formatScale;
125:                double edgesHeightInPixel = _formatHeightInPixel * _formatScale;
126:
127:                int pageCountHorizontal = getPageCountHorizontal(edgesWitdthInPixel);
128:                int pageCountVertical = getPageCountVertical(edgesHeightInPixel);
129:
130:                if (pageIndex >= pageCountHorizontal * pageCountVertical) {
131:                    return Printable.NO_SUCH_PAGE;
132:                }
133:
134:                Graphics2D g2d = (Graphics2D) graphics;
135:
136:                AffineTransform oldTransform = g2d.getTransform();
137:
138:                boolean origDoubleBufferingEnabled = RepaintManager
139:                        .currentManager(this ).isDoubleBufferingEnabled();
140:
141:                try {
142:                    _isPrinting = true;
143:                    RepaintManager.currentManager(this )
144:                            .setDoubleBufferingEnabled(false);
145:
146:                    double tx = -getPageWidthInPixel(pageFormat)
147:                            * (pageIndex % pageCountHorizontal)
148:                            + pageFormat.getImageableX();
149:                    double ty = -getPageHeightInPixel(pageFormat)
150:                            * (pageIndex / pageCountHorizontal)
151:                            + pageFormat.getImageableY();
152:
153:                    g2d.translate(tx, ty);
154:
155:                    double sx = getPageWidthInPixel(pageFormat)
156:                            / edgesWitdthInPixel;
157:                    double sy = getPageHeightInPixel(pageFormat)
158:                            / edgesHeightInPixel;
159:
160:                    g2d.scale(sx, sy);
161:
162:                    paintGraphComponents(g2d);
163:                    super .paintChildren(g2d);
164:
165:                } finally {
166:                    g2d.setTransform(oldTransform);
167:                    RepaintManager.currentManager(this )
168:                            .setDoubleBufferingEnabled(
169:                                    origDoubleBufferingEnabled);
170:                    _isPrinting = false;
171:                }
172:
173:                return Printable.PAGE_EXISTS;
174:            }
175:
176:            private double getPageHeightInPixel(PageFormat pageFormat) {
177:                return pageFormat.getImageableHeight();
178:            }
179:
180:            private double getPageWidthInPixel(PageFormat pageFormat) {
181:                return pageFormat.getImageableWidth();
182:            }
183:
184:            public int getPageCountHorizontal(double pageWidthInPixel) {
185:                return roundPageCount(getRequiredSize().width
186:                        / pageWidthInPixel);
187:            }
188:
189:            public int getPageCountVertical(double pageHeightInPixel) {
190:                return roundPageCount(getRequiredSize().height
191:                        / pageHeightInPixel);
192:            }
193:
194:            private int roundPageCount(double d) {
195:                return 0 < d - (int) d ? (int) (d + 1) : (int) d;
196:            }
197:            //
198:            ///////////////////////////////////////////////////////////////////////////////////////
199:
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.