Source Code Cross Referenced for TabbedPane.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.Component;
025:        import java.awt.Graphics;
026:        import java.awt.event.MouseAdapter;
027:        import java.awt.event.MouseEvent;
028:        import java.util.HashMap;
029:
030:        import javax.swing.Icon;
031:        import javax.swing.ImageIcon;
032:        import javax.swing.JTabbedPane;
033:
034:        import org.beryl.gui.GUIEvent;
035:        import org.beryl.gui.GUIEventListener;
036:        import org.beryl.gui.GUIException;
037:        import org.beryl.gui.ImageIconFactory;
038:        import org.beryl.gui.Widget;
039:        import org.beryl.gui.WidgetInfo;
040:
041:        public class TabbedPane extends Widget {
042:            protected static WidgetInfo tabbedInfo = null;
043:            private JTabbedPane pane = null;
044:            private HashMap paneInfo = null;
045:            private boolean isConstructed = false;
046:            private ImageIcon closeIcon = null;
047:
048:            static {
049:                tabbedInfo = new WidgetInfo(TabbedPane.class, widgetInfo);
050:                tabbedInfo.addEvent("rightclick");
051:                tabbedInfo.addEvent("close");
052:                try {
053:                    tabbedInfo.addProperty("closeicon", "icon",
054:                            ImageIconFactory.getIcon("remove_tab"));
055:                } catch (Exception e) {
056:                    throw new RuntimeException(e);
057:                }
058:            }
059:
060:            private static class CloseIcon implements  Icon {
061:                private Icon icon;
062:                private int x = 0;
063:                private int y = 0;
064:                private int height = 10;
065:                private int width = 10;
066:
067:                public CloseIcon(ImageIcon icon) {
068:                    this .icon = icon;
069:
070:                    if (icon != null) {
071:                        height = icon.getIconHeight();
072:                        width = icon.getIconWidth();
073:                    }
074:                }
075:
076:                public int getIconHeight() {
077:                    return height;
078:                }
079:
080:                public int getIconWidth() {
081:                    return width;
082:                }
083:
084:                public void paintIcon(Component c, Graphics g, int x, int y) {
085:                    this .x = x;
086:                    this .y = y;
087:
088:                    if (icon != null) {
089:                        icon.paintIcon(c, g, x, y + 1);
090:                    } else {
091:                        g.drawRect(x, y + 1, width, height);
092:                    }
093:                }
094:
095:                public boolean contains(int x2, int y2) {
096:                    if (!(x2 >= x) || !(x2 <= x + width))
097:                        return false;
098:                    if (!(y2 >= y) || !(y2 <= y + height))
099:                        return false;
100:                    return true;
101:                }
102:            }
103:
104:            public TabbedPane(Widget parent, String name) throws GUIException {
105:                super (parent, name);
106:                pane = new JTabbedPane();
107:                paneInfo = new HashMap();
108:            }
109:
110:            public void addChild(Widget widget, Object constraint)
111:                    throws GUIException {
112:                String name = widget.getName();
113:                if (constraint != null)
114:                    throw new GUIException(
115:                            "Anchors not supported inside a tabbed pane");
116:                if (!(widget instanceof  Panel))
117:                    throw new GUIException(
118:                            "Only panels can be added to a tabbed pane");
119:
120:                String title = (String) paneInfo.get(name + ".title");
121:                if (title == null)
122:                    title = "(unnamed)";
123:
124:                Icon icon = (Icon) paneInfo.get(name + ".icon");
125:                if (icon == null && closeIcon != null)
126:                    icon = new CloseIcon(closeIcon);
127:                pane.addTab(title, icon, widget.getWidget(), (String) paneInfo
128:                        .get(name + ".tooltip"));
129:                addChild(widget);
130:            }
131:
132:            public void removeChildWidget(Widget widget) throws GUIException {
133:                pane.remove(widget.getWidget());
134:                super .removeChildWidget(widget);
135:            }
136:
137:            public Widget getSelectedWidget() {
138:                return getChild(pane.getSelectedIndex());
139:            }
140:
141:            public void setSelectedWidget(Widget widget) {
142:                pane.setSelectedIndex(getChildIndex(widget));
143:            }
144:
145:            public void setProperty(String name, Object value)
146:                    throws GUIException {
147:                if (name.endsWith(".title") || name.endsWith(".icon")
148:                        || name.endsWith(".tooltip")) {
149:                    String widgetName = name
150:                            .substring(0, name.lastIndexOf('.'));
151:
152:                    paneInfo.put(name, value);
153:                    if (isConstructed) {
154:                        Widget widget = getWidget(widgetName);
155:                        if (widget != null) {
156:                            int index = pane.indexOfComponent(widget
157:                                    .getWidget());
158:                            if (index == -1)
159:                                throw new GUIException(
160:                                        "That widget is not a child of the tabbed pane");
161:                            pane.removeTabAt(index);
162:
163:                            String title = (String) paneInfo.get(widgetName
164:                                    + ".title");
165:                            if (title == null)
166:                                title = "(unnamed)";
167:                            Icon icon = (Icon) paneInfo.get(widgetName
168:                                    + ".icon");
169:                            if (icon == null && closeIcon != null)
170:                                icon = new CloseIcon(closeIcon);
171:                            pane.insertTab(title, icon, widget.getWidget(),
172:                                    (String) paneInfo.get(widgetName
173:                                            + ".tooltip"), index);
174:                        } else {
175:                            throw new GUIException("A tab named [" + widgetName
176:                                    + "] was not found");
177:                        }
178:                    }
179:                } else if (name.equals("closeicon")) {
180:                    closeIcon = (ImageIcon) value;
181:                } else {
182:                    super .setProperty(name, value);
183:                }
184:            }
185:
186:            public void addListener(String event, final String name,
187:                    final GUIEventListener listener) throws GUIException {
188:                if ("rightclick".equals(event)) {
189:                    pane.addMouseListener(new MouseAdapter() {
190:                        public void mousePressed(MouseEvent e) {
191:                            if (e.isPopupTrigger()) {
192:                                if (pane.getSelectedIndex() >= 0) {
193:                                    listener.eventOccured(new GUIEvent(
194:                                            TabbedPane.this , name, e));
195:                                }
196:                            }
197:                        }
198:
199:                        public void mouseReleased(MouseEvent e) {
200:                            mousePressed(e);
201:                        }
202:                    });
203:                } else if ("close".equals(event)) {
204:                    pane.addMouseListener(new MouseAdapter() {
205:                        public void mouseClicked(MouseEvent e) {
206:                            int i = pane.getSelectedIndex();
207:
208:                            if (i == -1 || e.isPopupTrigger())
209:                                return;
210:
211:                            if (pane.getIconAt(i) instanceof  CloseIcon) {
212:                                CloseIcon icon = (CloseIcon) pane.getIconAt(i);
213:
214:                                if (icon != null
215:                                        && icon.contains(e.getX(), e.getY())) {
216:                                    listener.eventOccured(new GUIEvent(
217:                                            TabbedPane.this , name, e));
218:                                }
219:                            }
220:                        }
221:                    });
222:                } else {
223:                    super .addListener(event, name, listener);
224:                }
225:            }
226:
227:            public void finalizeConstruction() throws GUIException {
228:                isConstructed = true;
229:            }
230:
231:            public Component getWidget() {
232:                return pane;
233:            }
234:
235:            public WidgetInfo getWidgetInfo() {
236:                return tabbedInfo;
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.