Source Code Cross Referenced for OutputPanel.java in  » J2EE » enhydra-IDE-plugin » org » enhydra » kelp » common » swing » 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 » J2EE » enhydra IDE plugin » org.enhydra.kelp.common.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server Project
003:         *
004:         * The contents of this file are subject to the Enhydra Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License on
007:         * the Enhydra web site ( http://www.enhydra.org/ ).
008:         *
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011:         * the License for the specific terms governing rights and limitations
012:         * under the License.
013:         *
014:         * The Initial Developer of the Enhydra Application Server is Lutris
015:         * Technologies, Inc. The Enhydra Application Server and portions created
016:         * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017:         * All Rights Reserved.
018:         *
019:         * Contributor(s):
020:         * Paul Mahar
021:         *
022:         */
023:        package org.enhydra.kelp.common.swing;
024:
025:        // Kelp imports
026:        import org.enhydra.kelp.common.Constants;
027:        import org.enhydra.kelp.common.event.WriteEvent;
028:        import org.enhydra.kelp.common.event.WriteListener;
029:        import org.enhydra.kelp.common.node.OtterProject;
030:
031:        // ToolBox imports
032:        import org.enhydra.tool.common.PathHandle;
033:
034:        // Standard imports
035:        import javax.swing.*;
036:        import javax.swing.text.BadLocationException;
037:        import java.awt.*;
038:        import java.awt.event.*;
039:        import java.beans.Beans;
040:        import java.io.File;
041:        import java.io.FileWriter;
042:        import java.lang.ref.WeakReference;
043:        import java.util.ResourceBundle;
044:
045:        //
046:        public class OutputPanel extends JPanel implements  WriteListener {
047:
048:            //
049:            public static ResourceBundle res = ResourceBundle
050:                    .getBundle("org.enhydra.kelp.common.Res"); // nores
051:            private JScrollPane scrollOutput;
052:            private JTextArea textAreaOutput;
053:            private BorderLayout layoutMain;
054:            private WeakReference projectRef;
055:            private int waitCount = 0;
056:
057:            /**
058:             * Constructor declaration
059:             *
060:             */
061:            public OutputPanel() {
062:                try {
063:                    jbInit();
064:                } catch (Exception e) {
065:                    e.printStackTrace();
066:                }
067:            }
068:
069:            public void clearAll() {
070:                clearOutput();
071:                if (projectRef != null) {
072:                    projectRef.clear();
073:                    projectRef = null;
074:                }
075:                removeAll();
076:            }
077:
078:            /**
079:             * Method declaration
080:             *
081:             *
082:             * @param event
083:             */
084:            public void onWrite(WriteEvent event) {
085:                String out = event.getString();
086:
087:                if (event.getType() == WriteEvent.CLEAR) {
088:                    clearOutput();
089:                } else {
090:                    if (File.separatorChar == '\\') {
091:
092:                        // string not to be resourced
093:                        if (out.indexOf(":\\") > 0) {
094:                            out = out.replace('\\', '/');
095:                        }
096:                    }
097:                    addOutput(out);
098:                }
099:            }
100:
101:            public void clearOutput() {
102:                OutputClear clearRun = null;
103:
104:                clearRun = new OutputClear(textAreaOutput, scrollOutput);
105:                try {
106:                    if (SwingUtilities.isEventDispatchThread()) {
107:                        clearRun.run();
108:                    } else {
109:                        SwingUtilities.invokeAndWait(clearRun);
110:                    }
111:                } catch (Exception e) {
112:                    e.printStackTrace();
113:                }
114:            }
115:
116:            public void scrollToBottom() {
117:                OutputScroll runSwing = null;
118:
119:                runSwing = new OutputScroll(scrollOutput);
120:                try {
121:                    if (SwingUtilities.isEventDispatchThread()) {
122:                        runSwing.run();
123:                    } else {
124:                        SwingUtilities.invokeAndWait(runSwing);
125:                    }
126:                } catch (Exception e) {
127:                    e.printStackTrace();
128:                }
129:                try {
130:                    Thread.sleep(500);
131:                } catch (InterruptedException e) {
132:
133:                    //
134:                }
135:            }
136:
137:            public OtterProject getProject() {
138:                OtterProject project = null;
139:
140:                if (projectRef != null) {
141:                    project = (OtterProject) projectRef.get();
142:                }
143:                return project;
144:            }
145:
146:            public void setProject(OtterProject project) {
147:                projectRef = new WeakReference(project);
148:            }
149:
150:            public int getRows() {
151:                return textAreaOutput.getRows();
152:            }
153:
154:            public void setRows(int i) {
155:                textAreaOutput.setRows(i);
156:            }
157:
158:            //
159:            // PRIVATE
160:            //
161:            private void addOutput(final String output) {
162:                OutputAdd adder = null;
163:
164:                adder = new OutputAdd(textAreaOutput, scrollOutput, output);
165:                try {
166:                    if (SwingUtilities.isEventDispatchThread()) {
167:                        adder.run();
168:                    } else {
169:                        waitCount++;
170:                        if (waitCount == 10) {
171:                            waitCount = 0;
172:                            SwingUtilities.invokeAndWait(adder);
173:                        } else {
174:                            SwingUtilities.invokeLater(adder);
175:                        }
176:                    }
177:                } catch (Exception e) {
178:                    e.printStackTrace(System.err);
179:                }
180:                projectLog(output);
181:            }
182:
183:            private void projectLog(final String output) {
184:                PathHandle log = null;
185:
186:                if (getProject() != null) {
187:                    log = PathHandle.createPathHandle(getProject()
188:                            .getOutputFilename());
189:                    if (log.hasExtension("txt") && log.getFile().canWrite()) {
190:                        try {
191:                            FileWriter writer = null;
192:
193:                            writer = new FileWriter(log.getPath(), true);
194:                            writer.write(output); // line + new Character((char)13) + new Character((char)10));
195:                            writer.close();
196:                        } catch (java.io.IOException e) {
197:                            e.printStackTrace(System.err);
198:                        }
199:                    }
200:                }
201:            }
202:
203:            /**
204:             * Method declaration
205:             *
206:             *
207:             * @throws Exception
208:             */
209:            private void jbInit() throws Exception {
210:                textAreaOutput = (JTextArea) Beans.instantiate(getClass()
211:                        .getClassLoader(), JTextArea.class.getName());
212:                textAreaOutput.setEditable(false);
213:                textAreaOutput.setRows(15);
214:                scrollOutput = new JScrollPane(textAreaOutput);
215:                layoutMain = (BorderLayout) Beans.instantiate(getClass()
216:                        .getClassLoader(), BorderLayout.class.getName());
217:                this .setLayout(layoutMain);
218:                this .add(scrollOutput, BorderLayout.CENTER);
219:            }
220:
221:            //
222:            private class OutputAdd implements  Runnable {
223:                private JTextArea textArea = null;
224:                private JScrollPane scroll = null;
225:                private String out = null;
226:
227:                protected OutputAdd(JTextArea ta, JScrollPane sc, String o) {
228:                    textArea = ta;
229:                    scroll = sc;
230:                    out = o;
231:                }
232:
233:                synchronized public void run() {
234:                    int start = 0;
235:                    int end = 0;
236:
237:                    if (textArea.getLineCount() > 2000) {
238:                        try {
239:                            start = textArea.getLineStartOffset(0);
240:                            end = textArea.getLineEndOffset(0);
241:                        } catch (BadLocationException e) {
242:                            start = 0;
243:                            end = 0;
244:                        }
245:                        textArea.replaceRange(null, start, end);
246:                    }
247:                    textArea.append(out);
248:                    scroll.getVerticalScrollBar().setValue(
249:                            scroll.getVerticalScrollBar().getMaximum());
250:                    textArea.repaint();
251:                    repaint();
252:                }
253:
254:            }
255:
256:            //
257:            private class OutputClear implements  Runnable {
258:                private JTextArea textArea = null;
259:                private JScrollPane scroll = null;
260:
261:                protected OutputClear(JTextArea ta, JScrollPane sc) {
262:                    textArea = ta;
263:                    scroll = sc;
264:                }
265:
266:                synchronized public void run() {
267:                    textArea.setText(new String());
268:                    scroll.getVerticalScrollBar().setValue(
269:                            scroll.getVerticalScrollBar().getMaximum());
270:                    textArea.repaint();
271:                    repaint();
272:                }
273:
274:            }
275:
276:            //
277:            private class OutputScroll implements  Runnable {
278:                private JScrollPane scroll = null;
279:
280:                protected OutputScroll(JScrollPane sc) {
281:                    scroll = sc;
282:                }
283:
284:                synchronized public void run() {
285:                    scroll.getVerticalScrollBar().setValue(
286:                            scroll.getVerticalScrollBar().getMaximum());
287:                }
288:
289:            }
290:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.