Source Code Cross Referenced for TextPane.java in  » XML-UI » xmlgui » org » beryl » gui » widgets » 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 » XML UI » xmlgui » org.beryl.gui.widgets 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Beryl - A web platform based on XML, XSLT and Java
003:         * This file is part of the Beryl XML GUI
004:         *
005:         * Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) 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 GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107  USA
020:         */
021:
022:        package org.beryl.gui.widgets;
023:
024:        import java.awt.Color;
025:        import java.awt.Component;
026:        import java.awt.Dimension;
027:
028:        import javax.swing.ImageIcon;
029:        import javax.swing.JScrollPane;
030:        import javax.swing.JTextPane;
031:        import javax.swing.event.DocumentEvent;
032:        import javax.swing.event.DocumentListener;
033:        import javax.swing.text.BadLocationException;
034:        import javax.swing.text.Document;
035:        import javax.swing.text.Style;
036:        import javax.swing.text.StyleConstants;
037:        import javax.swing.text.StyleContext;
038:        import javax.swing.text.StyleConstants.ColorConstants;
039:
040:        import org.beryl.gui.GUIException;
041:        import org.beryl.gui.Widget;
042:        import org.beryl.gui.WidgetInfo;
043:        import org.beryl.gui.model.MapChangeEvent;
044:        import org.beryl.gui.model.MapDataModel;
045:        import org.beryl.gui.model.ModelChangeEvent;
046:
047:        public class TextPane extends Widget {
048:            protected static WidgetInfo textPaneInfo = null;
049:            private JTextPane textPane = null;
050:            private JScrollPane scrollPane = null;
051:            private String key = null;
052:            private Document document = null;
053:            private boolean sendEvents = true;
054:            private int counter = 0;
055:
056:            static {
057:                textPaneInfo = new WidgetInfo(TextPane.class, widgetInfo);
058:                textPaneInfo.addProperty("key", "string", "");
059:                textPaneInfo.addProperty("verticalScrollBar", "bool",
060:                        Boolean.FALSE);
061:                textPaneInfo.addProperty("horizontalScrollBar", "bool",
062:                        Boolean.FALSE);
063:            };
064:
065:            public TextPane(Widget parent, String name) throws GUIException {
066:                super (parent, name);
067:                textPane = new JTextPane();
068:                document = textPane.getDocument();
069:                scrollPane = new JScrollPane(textPane);
070:
071:                Style def = StyleContext.getDefaultStyleContext().getStyle(
072:                        StyleContext.DEFAULT_STYLE);
073:
074:                Style black = textPane.addStyle("black", def);
075:                ColorConstants.setForeground(black, Color.black);
076:
077:                Style white = textPane.addStyle("white", def);
078:                ColorConstants.setForeground(white, Color.white);
079:
080:                Style gray = textPane.addStyle("gray", def);
081:                ColorConstants.setForeground(gray, Color.gray);
082:
083:                Style blue = textPane.addStyle("blue", def);
084:                ColorConstants.setForeground(blue, Color.blue);
085:
086:                Style cyan = textPane.addStyle("cyan", def);
087:                ColorConstants.setForeground(cyan, Color.cyan);
088:
089:                Style yellow = textPane.addStyle("yellow", def);
090:                ColorConstants.setForeground(yellow, Color.yellow);
091:
092:                Style green = textPane.addStyle("green", def);
093:                ColorConstants.setForeground(green, Color.green);
094:
095:                Style darkGreen = textPane.addStyle("darkgreen", def);
096:                ColorConstants.setForeground(darkGreen, new Color(0, 100, 0));
097:
098:                Style red = textPane.addStyle("red", def);
099:                ColorConstants.setForeground(red, Color.red);
100:            }
101:
102:            public void setProperty(String name, Object value)
103:                    throws GUIException {
104:                if ("key".equals(name))
105:                    key = (String) value;
106:                else if ("verticalScrollBar".equals(name))
107:                    scrollPane
108:                            .setVerticalScrollBarPolicy(((Boolean) value)
109:                                    .booleanValue() ? JScrollPane.VERTICAL_SCROLLBAR_ALWAYS
110:                                    : JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
111:                else if ("horizontalScrollBar".equals(name))
112:                    scrollPane
113:                            .setHorizontalScrollBarPolicy(((Boolean) value)
114:                                    .booleanValue() ? JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS
115:                                    : JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
116:                else
117:                    super .setProperty(name, value);
118:            }
119:
120:            private void reload() {
121:                MapDataModel model = getDataModel();
122:                if (model != null) {
123:                    String value = (String) model.getValue(key);
124:                    if (value != null)
125:                        textPane.setText(value);
126:                }
127:            }
128:
129:            public void modelChanged(ModelChangeEvent e) throws GUIException {
130:                sendEvents = false;
131:                try {
132:                    if (e.getSource() == this ) {
133:                        /* New data model */
134:                        reload();
135:                    } else if (e instanceof  MapChangeEvent) {
136:                        MapChangeEvent event = (MapChangeEvent) e;
137:                        if (event.getKey() == null) {
138:                            reload();
139:                        } else if (event.getKey().equals(key)) {
140:                            textPane.setText((String) event.getNewValue());
141:                        }
142:                    }
143:                } finally {
144:                    sendEvents = true;
145:                }
146:            }
147:
148:            public void finalizeConstruction() {
149:                textPane.setPreferredSize(new Dimension(MAX_WIDTH,
150:                        DEFAULT_HEIGHT));
151:                document.addDocumentListener(new DocumentListener() {
152:                    public void insertUpdate(DocumentEvent e) {
153:                        changedUpdate(e);
154:                    }
155:
156:                    public void removeUpdate(DocumentEvent e) {
157:                        changedUpdate(e);
158:                    }
159:
160:                    public void changedUpdate(DocumentEvent e) {
161:                        if (sendEvents) {
162:                            try {
163:                                sendEvents = false;
164:                                MapDataModel model = getDataModel();
165:                                if (model != null && key != null) {
166:                                    String text = null;
167:                                    text = textPane.getText();
168:                                    model.setValue(TextPane.this , key, text);
169:                                }
170:                            } catch (GUIException ex) {
171:                                throw new RuntimeException(ex);
172:                            } finally {
173:                                sendEvents = true;
174:                            }
175:                        }
176:                    }
177:                });
178:            }
179:
180:            public void addIcon(ImageIcon icon) throws GUIException {
181:                String name = "icon" + counter;
182:                Style style = textPane.addStyle(name, null);
183:                StyleConstants.setIcon(style, icon);
184:                addText(name, name);
185:                counter++;
186:            }
187:
188:            public void addText(String text) throws GUIException {
189:                addText(text, null);
190:            }
191:
192:            public final void addText(String text, String style)
193:                    throws GUIException {
194:                try {
195:                    document.insertString(document.getLength(), text,
196:                            style == null ? null : textPane.getStyle(style));
197:                } catch (BadLocationException e) {
198:                    throw new GUIException("Error while inserting text", e);
199:                }
200:            }
201:
202:            public Component getWidget() {
203:                return scrollPane;
204:            }
205:
206:            public Component getRealWidget() {
207:                return textPane;
208:            }
209:
210:            public void setEnabled(boolean enabled) throws GUIException {
211:                super .setEnabled(enabled);
212:                textPane.setEnabled(enabled);
213:            }
214:
215:            public WidgetInfo getWidgetInfo() {
216:                return textPaneInfo;
217:            }
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.