Source Code Cross Referenced for JGraphpadComboBox.java in  » Graphic-Library » jgraphpad » com » jgraph » pad » factory » 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 » Graphic Library » jgraphpad » com.jgraph.pad.factory 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * $Id: JGraphpadComboBox.java,v 1.4 2006/02/03 14:32:46 david Exp $
003:         * Copyright (c) 2001-2005, Gaudenz Alder
004:         * 
005:         * All rights reserved.
006:         * 
007:         * See LICENSE file for license details. If you are unable to locate
008:         * this file please contact info (at) jgraph (dot) com.
009:         */
010:        package com.jgraph.pad.factory;
011:
012:        import java.awt.Color;
013:        import java.awt.Component;
014:        import java.awt.geom.Rectangle2D;
015:        import java.util.Hashtable;
016:        import java.util.Map;
017:
018:        import javax.swing.JComboBox;
019:
020:        import org.jgraph.graph.AbstractCellView;
021:        import org.jgraph.graph.GraphConstants;
022:        import org.w3c.dom.Node;
023:
024:        import com.jgraph.editor.JGraphEditorResources;
025:        import com.jgraph.editor.factory.JGraphEditorComboBox;
026:        import com.jgraph.editor.factory.JGraphEditorFactoryMethod;
027:        import com.jgraph.editor.factory.JGraphEditorComboBox.ComboBoxListener;
028:        import com.jgraph.pad.dialog.JGraphpadDialogs;
029:        import com.jgraph.pad.graph.JGraphpadGraphConstants;
030:        import com.jgraph.pad.graph.JGraphpadVertexRenderer;
031:        import com.jgraph.pad.graph.JGraphpadVertexView;
032:
033:        /**
034:         * Combo box factory methods with special dialogs and custom cell views for
035:         * specific attributes (shape).
036:         */
037:        public class JGraphpadComboBox {
038:
039:            /**
040:             * Defines the combo box types for {@link ColorComboFactoryMethod}.
041:             */
042:            public static final int TYPE_BACKGROUND = 0, TYPE_GRADIENT = 1,
043:                    TYPE_LINECOLOR = 2;
044:
045:            /**
046:             * Default array of colors.
047:             */
048:            public static Color[] defaultColors = new Color[] { Color.black,
049:                    Color.blue, Color.cyan, Color.darkGray, Color.gray,
050:                    Color.green, Color.lightGray, Color.magenta, Color.orange,
051:                    Color.pink, Color.red, Color.white, Color.yellow };
052:
053:            /**
054:             * Default array of shapes.
055:             */
056:            public static int[] defaultShapes = new int[] {
057:                    JGraphpadVertexRenderer.SHAPE_RECTANGLE,
058:                    JGraphpadVertexRenderer.SHAPE_ROUNDED,
059:                    JGraphpadVertexRenderer.SHAPE_CIRCLE,
060:                    JGraphpadVertexRenderer.SHAPE_DIAMOND,
061:                    JGraphpadVertexRenderer.SHAPE_TRIANGLE,
062:                    JGraphpadVertexRenderer.SHAPE_CYLINDER };
063:
064:            /**
065:             * Provides a factory method to construct a color combo box.
066:             */
067:            public static class ColorComboFactoryMethod extends
068:                    JGraphEditorFactoryMethod {
069:
070:                /**
071:                 * Defines the default name for factory methods of this kind.
072:                 */
073:                public static String NAME = "createBackgroundCombo";
074:
075:                /**
076:                 * Specifies the type of the color combo box.
077:                 */
078:                protected int type = 0;
079:
080:                /**
081:                 * Constructs a color combo box of type {@link #TYPE_BACKGROUND} using
082:                 * {@link #NAME}.
083:                 */
084:                public ColorComboFactoryMethod() {
085:                    this (NAME, TYPE_BACKGROUND);
086:                }
087:
088:                /**
089:                 * Constructs a color combo box of the specified type.
090:                 * 
091:                 * @param type
092:                 *            The type of the combo box to be created.
093:                 */
094:                public ColorComboFactoryMethod(String name, int type) {
095:                    super (name);
096:                    this .type = type;
097:                }
098:
099:                /*
100:                 * (non-Javadoc)
101:                 */
102:                public Component createInstance(Node configuration) {
103:                    Map[] attrs = new Hashtable[defaultColors.length + 2];
104:
105:                    // Adds a special entry that displays a color bucket
106:                    // icon. Below a special listener is installed to handle
107:                    // clicks on this special entry. The renderer bridge
108:                    // takes care of displaying the icon.
109:                    attrs[0] = new Hashtable();
110:                    GraphConstants.setIcon(attrs[0], JGraphEditorResources
111:                            .getImage("/com/jgraph/pad/images/color.gif"));
112:
113:                    // Adds special entries to remove the color properties
114:                    // from the selection cells.
115:                    attrs[1] = new Hashtable();
116:                    if (type == TYPE_BACKGROUND)
117:                        GraphConstants.setRemoveAttributes(attrs[1],
118:                                new Object[] { GraphConstants.BACKGROUND,
119:                                        GraphConstants.OPAQUE });
120:                    else if (type == TYPE_GRADIENT)
121:                        GraphConstants.setRemoveAttributes(attrs[1],
122:                                new Object[] { GraphConstants.GRADIENTCOLOR,
123:                                        GraphConstants.OPAQUE });
124:                    else
125:                        GraphConstants.setRemoveAttributes(attrs[1],
126:                                new Object[] { GraphConstants.LINECOLOR });
127:                    GraphConstants.setIcon(attrs[1], JGraphEditorResources
128:                            .getImage("/com/jgraph/pad/images/delete.gif"));
129:
130:                    // Adds the standard entries for each color
131:                    for (int i = 0; i < defaultColors.length; i++) {
132:                        Map m = attrs[i + 2] = new Hashtable(4);
133:                        setColor(m, defaultColors[i]);
134:                    }
135:
136:                    // Overrides the default action listener's getSelection hook
137:                    // to return a specially created map which uses the color
138:                    // value from a dialog. This behaviour is for the first
139:                    // entry, which is displayed with a color bucket icon.
140:                    JGraphEditorComboBox comboBox = new JGraphEditorComboBox(
141:                            attrs, type == TYPE_LINECOLOR);
142:                    comboBox.addActionListener(new ComboBoxListener() {
143:                        protected Object getSelection(JComboBox box) {
144:                            if (box.getSelectedIndex() == 0) {
145:                                Color color = JGraphpadDialogs
146:                                        .getSharedInstance()
147:                                        .colorDialog(
148:                                                box,
149:                                                JGraphEditorResources
150:                                                        .getString("SelectColor"),
151:                                                null);
152:                                if (color != null) {
153:                                    Map map = new Hashtable(2);
154:                                    setColor(map, color);
155:                                    return map;
156:                                } else {
157:                                    return null;
158:                                }
159:                            } else if (box.getSelectedIndex() == 1) {
160:                                Object obj = super .getSelection(box);
161:                                if (obj instanceof  Map) {
162:                                    Map map = new Hashtable((Map) obj);
163:                                    map.remove(GraphConstants.ICON);
164:                                    return map;
165:                                } else {
166:                                    return obj;
167:                                }
168:                            }
169:                            return super .getSelection(box);
170:                        }
171:                    });
172:                    comboBox.setFocusable(false);
173:                    return comboBox;
174:                }
175:
176:                /**
177:                 * Sets the specified color in <code>map</code> according to the type
178:                 * of the combo box.
179:                 * 
180:                 * @param m
181:                 *            The map to set the color in.
182:                 * @param color
183:                 *            The color to be set.
184:                 */
185:                protected void setColor(Map m, Color color) {
186:                    if (type == TYPE_GRADIENT) {
187:                        GraphConstants.setGradientColor(m, color);
188:                        GraphConstants.setOpaque(m, true);
189:                    } else if (type == TYPE_LINECOLOR) {
190:                        GraphConstants.setLineColor(m, color);
191:                    } else {
192:                        GraphConstants.setBackground(m, color);
193:                        GraphConstants.setOpaque(m, true);
194:                    }
195:                }
196:
197:            }
198:
199:            /**
200:             * Provides a factory method to construct a shape combo box.
201:             */
202:            public static class VertexShapeComboFactoryMethod extends
203:                    JGraphEditorFactoryMethod {
204:
205:                /**
206:                 * Defines the default name for factory methods of this kind.
207:                 */
208:                public static String NAME = "createVertexShapeCombo";
209:
210:                /**
211:                 * Constructs a new border combo factory method using {@link #NAME}.
212:                 */
213:                public VertexShapeComboFactoryMethod() {
214:                    super (NAME);
215:                }
216:
217:                /*
218:                 * (non-Javadoc)
219:                 */
220:                public Component createInstance(Node configuration) {
221:                    Map[] attrs = new Hashtable[defaultShapes.length];
222:                    for (int i = 0; i < defaultShapes.length; i++) {
223:                        attrs[i] = new Hashtable(2);
224:                        JGraphpadGraphConstants.setVertexShape(attrs[i],
225:                                defaultShapes[i]);
226:                    }
227:                    AbstractCellView view = new JGraphpadVertexView("");
228:                    GraphConstants.setBorderColor(view.getAttributes(),
229:                            Color.BLACK);
230:                    Rectangle2D bounds = new Rectangle2D.Double(0, 0, 14, 14);
231:                    GraphConstants.setBounds(view.getAttributes(), bounds);
232:                    JGraphEditorComboBox comboBox = new JGraphEditorComboBox(
233:                            attrs, view, false);
234:                    comboBox
235:                            .addActionListener(new JGraphEditorComboBox.ComboBoxListener());
236:                    comboBox.setFocusable(false);
237:                    return comboBox;
238:                }
239:
240:            }
241:
242:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.