Source Code Cross Referenced for TextArea.java in  » Test-Coverage » salome-tmf » salomeTMF_plug » helpgui » gui » 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 » Test Coverage » salome tmf » salomeTMF_plug.helpgui.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * TextArea.java - The Area where date are written
003:         * Copyright (C) 2003 Alexandre THOMAS
004:         * alexthomas@free.fr
005:         * http://helpgui.sourceforge.net
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020:         */
021:
022:        package salomeTMF_plug.helpgui.gui;
023:
024:        import java.awt.Graphics;
025:        import java.awt.Graphics2D;
026:        import java.awt.Rectangle;
027:        import java.awt.Shape;
028:        import java.awt.print.PageFormat;
029:        import java.awt.print.Printable;
030:        import java.io.IOException;
031:        import java.net.URL;
032:
033:        import javax.swing.JTextPane;
034:        import javax.swing.text.View;
035:
036:        import org.objectweb.salome_tmf.api.Util;
037:
038:        import salomeTMF_plug.helpgui.page.Page;
039:        import salomeTMF_plug.helpgui.util.Out;
040:
041:        /**
042:         * Class where the date are showed
043:         * 
044:         * @author Alexandre THOMAS
045:         */
046:        public class TextArea extends JTextPane implements  Printable {
047:
048:            /* Attribut for printing */
049:            int currentPage = -1;
050:            double pageEndY = 0;
051:            double pageStartY = 0;
052:            boolean scaleWidthToFit = true;
053:
054:            /** Constructor */
055:            public TextArea() {
056:                super ();
057:                setEditable(false);
058:            }
059:
060:            /** Fonction call when a new page has to be show */
061:            public void update(Page page) {
062:                if (!page.isLeaf() && page.getTarget() == null) {
063:                    return;
064:                }
065:
066:                try {
067:                    URL url;
068:                    if (page.isPluginPage()) {
069:                        Util.log("[helpgui:page] Try open plug-in page : "
070:                                + MainPanel.pluginDir + "/"
071:                                + page.getPluginsName() + "/"
072:                                + MainPanel.helpDir + "/" + MainPanel.lang
073:                                + "/" + page.getLink());
074:                        try {
075:                            url = new URL(MainPanel.helpPath + "/"
076:                                    + MainPanel.pluginDir + "/"
077:                                    + page.getPluginsName() + "/"
078:                                    + MainPanel.helpDir + "/" + MainPanel.lang
079:                                    + "/" + page.getLink());
080:                            setPage(url);
081:                        } catch (Exception e1) {
082:                            Util
083:                                    .log("[helpgui:page] Error then try to open main page : "
084:                                            + MainPanel.pluginDir
085:                                            + "/"
086:                                            + page.getPluginsName()
087:                                            + "/"
088:                                            + MainPanel.helpDir
089:                                            + "/"
090:                                            + MainPanel.defaultlang
091:                                            + "/"
092:                                            + page.getLink());
093:                            url = new URL(MainPanel.helpPath + "/"
094:                                    + MainPanel.pluginDir + "/"
095:                                    + page.getPluginsName() + "/"
096:                                    + MainPanel.helpDir + "/"
097:                                    + MainPanel.defaultlang + "/"
098:                                    + page.getLink());
099:                            setPage(url);
100:                        }
101:                    } else {
102:                        Util.log("[helpgui:page] Try open main help page : "
103:                                + MainPanel.helpDir + "/" + MainPanel.lang
104:                                + "/" + page.getLink());
105:                        try {
106:                            url = new URL(MainPanel.helpPath + "/"
107:                                    + MainPanel.helpDir + "/" + MainPanel.lang
108:                                    + "/" + page.getLink());
109:                            setPage(url);
110:                        } catch (Exception e1) {
111:                            Util
112:                                    .log("[helpgui:page] Error then try open main page : "
113:                                            + MainPanel.helpDir
114:                                            + "/"
115:                                            + MainPanel.defaultlang
116:                                            + "/"
117:                                            + page.getLink());
118:                            url = new URL(MainPanel.helpPath + "/"
119:                                    + MainPanel.helpDir + "/"
120:                                    + MainPanel.defaultlang + "/"
121:                                    + page.getLink());
122:                            setPage(url);
123:                        }
124:                    }
125:                } catch (IOException e) {
126:                    Out.msg("Unable to show the page : " + e, Out.FAILED);
127:                    setText("Error in showing the page : " + e);
128:                } catch (Exception e) {
129:                    Out.msg("Error in showing the page", Out.FAILED);
130:                    setText("Error in showing the page : " + e);
131:                }
132:            }
133:
134:            /** Print the current page */
135:            //	 Adding code for print capacity
136:            public int print(Graphics graphics, PageFormat pageFormat,
137:                    int pageIndex) {
138:                //This function is the main printable overided function
139:
140:                double scale = 1.0;
141:                Graphics2D graphics2D;
142:                View rootView;
143:                graphics2D = (Graphics2D) graphics;
144:
145:                setSize((int) pageFormat.getImageableWidth(), Integer.MAX_VALUE);
146:                validate();
147:
148:                rootView = this .getUI().getRootView(this );
149:
150:                if ((scaleWidthToFit)
151:                        && (getMinimumSize().getWidth() > pageFormat
152:                                .getImageableWidth())) {
153:                    scale = pageFormat.getImageableWidth()
154:                            / getMinimumSize().getWidth();
155:                    graphics2D.scale(scale, scale);
156:                }
157:
158:                //The below four command lines shows that the content is clipped 
159:                //to the size of the printable page
160:
161:                graphics2D.setClip((int) (pageFormat.getImageableX() / scale),
162:                        (int) (pageFormat.getImageableY() / scale),
163:                        (int) (pageFormat.getImageableWidth() / scale),
164:                        (int) (pageFormat.getImageableHeight() / scale));
165:
166:                //The below if statement is to check to see if there is a new page to render
167:
168:                if (pageIndex > currentPage) {
169:                    currentPage = pageIndex;
170:                    pageStartY += pageEndY;
171:                    pageEndY = graphics2D.getClipBounds().getHeight();
172:                }
173:
174:                graphics2D.translate(graphics2D.getClipBounds().getX(),
175:                        graphics2D.getClipBounds().getY());
176:
177:                Rectangle allocation = new Rectangle(0, (int) -pageStartY,
178:                        (int) (getMinimumSize().getWidth()),
179:                        (int) (getPreferredSize().getHeight()));
180:
181:                //The below if else statements return PAGE_EXISTS only if the class 
182:                //sees that there are some contents in the document by calling the printView class 
183:
184:                if (printView(graphics2D, allocation, rootView)) {
185:                    return PAGE_EXISTS;
186:                }
187:
188:                else {
189:                    pageStartY = 0;
190:                    pageEndY = 0;
191:                    currentPage = -1;
192:                    return NO_SUCH_PAGE;
193:                }
194:            }
195:
196:            protected boolean printView(Graphics2D graphics2D,
197:                    Shape allocation, View view) {
198:                //This function paints the page if it exists
199:
200:                boolean pageExists = false;
201:                Rectangle clipRectangle = graphics2D.getClipBounds();
202:                Shape childAllocation;
203:                View childView;
204:
205:                if (view.getViewCount() > 0) {
206:                    for (int i = 0; i < view.getViewCount(); i++) {
207:                        childAllocation = view
208:                                .getChildAllocation(i, allocation);
209:                        if (childAllocation != null) {
210:                            childView = view.getView(i);
211:                            if (printView(graphics2D, childAllocation,
212:                                    childView)) {
213:                                pageExists = true;
214:                            }
215:                        }
216:
217:                    }
218:
219:                } else {
220:                    //The below if statement checks if there are pages currently to paint
221:                    if (allocation.getBounds().getMaxY() >= clipRectangle
222:                            .getY()) {
223:                        pageExists = true;
224:                        if ((allocation.getBounds().getHeight() > clipRectangle
225:                                .getHeight())
226:                                && (allocation.intersects(clipRectangle))) {
227:                            view.paint(graphics2D, allocation);
228:                        } else {
229:                            if (allocation.getBounds().getY() >= clipRectangle
230:                                    .getY()) {
231:                                if (allocation.getBounds().getMaxY() <= clipRectangle
232:                                        .getMaxY() - 15) {
233:                                    view.paint(graphics2D, allocation);
234:                                } else {
235:                                    if (allocation.getBounds().getY() < pageEndY) {
236:                                        pageEndY = allocation.getBounds()
237:                                                .getY();
238:                                    }
239:                                }
240:                            }
241:                        }
242:                    }
243:                }
244:                return pageExists;
245:            }
246:
247:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.