Source Code Cross Referenced for JGraphpadStatusBar.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: JGraphpadStatusBar.java,v 1.2 2005/08/05 19:56:23 gaudenz 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.Component;
013:        import java.awt.GridBagConstraints;
014:        import java.awt.GridBagLayout;
015:        import java.awt.event.MouseEvent;
016:        import java.awt.event.MouseMotionListener;
017:        import java.beans.PropertyChangeEvent;
018:        import java.beans.PropertyChangeListener;
019:        import java.text.NumberFormat;
020:
021:        import javax.swing.BorderFactory;
022:        import javax.swing.JLabel;
023:        import javax.swing.JPanel;
024:        import javax.swing.event.TreeModelEvent;
025:
026:        import org.jgraph.JGraph;
027:        import org.w3c.dom.Node;
028:
029:        import com.jgraph.JGraphEditor;
030:        import com.jgraph.editor.JGraphEditorFile;
031:        import com.jgraph.editor.JGraphEditorModel;
032:        import com.jgraph.editor.JGraphEditorResources;
033:        import com.jgraph.editor.factory.JGraphEditorDiagramPane;
034:        import com.jgraph.editor.factory.JGraphEditorFactoryMethod;
035:        import com.jgraph.pad.util.JGraphpadFocusManager;
036:        import com.jgraph.pad.util.JGraphpadTreeModelAdapter;
037:
038:        /**
039:         * Status bar to display general information about the focused graph.
040:         */
041:        public class JGraphpadStatusBar extends JPanel {
042:
043:            /**
044:             * Holds the shared number formatter.
045:             * 
046:             * @see NumberFormat#getInstance()
047:             */
048:            public static final NumberFormat numberFormat = NumberFormat
049:                    .getInstance();
050:
051:            /**
052:             * Holds the labels contained in the status bar.
053:             */
054:            protected JLabel infoLabel = new JLabel(getString("NoDocument")),
055:                    modifiedLabel = new JLabel(" "),
056:                    editableLabel = new JLabel(" "),
057:                    zoomLabel = new JLabel(" "), mouseLabel = new JLabel(" "),
058:                    spareLabel = new JLabel(" ");
059:
060:            /**
061:             * Constructs a new repository panel for the specified editor.
062:             */
063:            public JGraphpadStatusBar(JGraphEditor editor) {
064:                setBorder(BorderFactory.createEmptyBorder(4, 5, 5, 4));
065:                setLayout(new GridBagLayout());
066:                numberFormat.setMaximumFractionDigits(0);
067:
068:                GridBagConstraints c = new GridBagConstraints();
069:                c.anchor = GridBagConstraints.NORTHWEST;
070:                c.fill = GridBagConstraints.HORIZONTAL;
071:                c.ipadx = 4;
072:                c.ipady = 2;
073:                c.weighty = 0.0;
074:                c.weightx = 1.0;
075:                c.gridwidth = 1;
076:                c.gridx = 0;
077:                c.gridy = 0;
078:                c.weightx = 4;
079:                add(infoLabel, c);
080:
081:                c.gridx = 1;
082:                c.weightx = 1;
083:                add(modifiedLabel, c);
084:
085:                c.gridx = 2;
086:                c.weightx = 1;
087:                add(editableLabel, c);
088:
089:                c.gridx = 3;
090:                c.weightx = 1;
091:                add(zoomLabel, c);
092:
093:                c.gridx = 4;
094:                c.weightx = 1;
095:                add(mouseLabel, c);
096:
097:                c.gridx = 5;
098:                c.weightx = 3;
099:                add(spareLabel, c);
100:
101:                // Installs a listener to update the mouse location
102:                JGraphpadFocusManager.getCurrentGraphFocusManager()
103:                        .addMouseMotionListener(new MouseMotionListener() {
104:
105:                            /*
106:                             * (non-Javadoc)
107:                             */
108:                            public void mouseDragged(MouseEvent e) {
109:                                mouseLabel.setText(e.getX() + " : " + e.getY());
110:                            }
111:
112:                            /*
113:                             * (non-Javadoc)
114:                             */
115:                            public void mouseMoved(MouseEvent e) {
116:                                mouseLabel.setText(e.getX() + " : " + e.getY());
117:                            }
118:                        });
119:
120:                // Installs a listener to listen to the focused graph and react
121:                // to all kinds of changes, such as selection, model, cache etc.
122:                JGraphpadFocusManager.getCurrentGraphFocusManager()
123:                        .addPropertyChangeListener(
124:                                new PropertyChangeListener() {
125:
126:                                    /*
127:                                     * (non-Javadoc)
128:                                     */
129:                                    public void propertyChange(
130:                                            PropertyChangeEvent e) {
131:                                        updateLabels();
132:                                    }
133:                                });
134:
135:                // Installs a listener to update the file state
136:                editor.getModel().addTreeModelListener(
137:                        new JGraphpadTreeModelAdapter() {
138:
139:                            /*
140:                             * (non-Javadoc)
141:                             */
142:                            public void treeNodesInserted(TreeModelEvent e) {
143:                                treeNodesChanged(e);
144:                            }
145:
146:                            /*
147:                             * (non-Javadoc)
148:                             */
149:                            public void treeNodesRemoved(TreeModelEvent e) {
150:                                treeNodesChanged(e);
151:                            }
152:
153:                            /*
154:                             * (non-Javadoc)
155:                             */
156:                            public void treeNodesChanged(TreeModelEvent e) {
157:                                updateLabels();
158:                            }
159:                        });
160:            }
161:
162:            /**
163:             * Shortcut method to {@link JGraphEditorResources#getString(String)}.
164:             * 
165:             * @param key
166:             *            The key to return the resource string for.
167:             */
168:            public static String getString(String key) {
169:                return JGraphEditorResources.getString(key);
170:            }
171:
172:            /**
173:             * Invoked by the various listeners to update the labels. This
174:             * implementation does not update the mouse label as it is updated by other
175:             * means.
176:             */
177:            protected void updateLabels() {
178:                JGraphpadFocusManager focusedGraph = JGraphpadFocusManager
179:                        .getCurrentGraphFocusManager();
180:
181:                // Fetches the focused graph by first trying the permanent focus
182:                // owner and if that is null, the last focused graph.
183:                JGraph graph = focusedGraph.getFocusedGraph();
184:                if (graph != null) {
185:
186:                    // Updates the various graph-related labels
187:                    // Shows selection or graph details in the info label
188:                    if (graph.isSelectionEmpty())
189:                        infoLabel.setText(graph.getModel().getRootCount() + " "
190:                                + getString("Roots"));
191:                    else
192:                        infoLabel.setText(graph.getSelectionCount() + " "
193:                                + getString("Selected"));
194:
195:                    // Shows the editable state and zoom level in the respective labels
196:                    editableLabel
197:                            .setText((graph.isEditable()) ? getString("Editable")
198:                                    : getString("ReadOnly"));
199:                    zoomLabel.setText((int) (graph.getScale() * 100) + "%");
200:
201:                    // Updates the modified label (file state)
202:                    JGraphEditorDiagramPane diagramPane = JGraphEditorDiagramPane
203:                            .getParentDiagramPane(graph);
204:                    if (diagramPane != null) {
205:                        JGraphEditorFile file = JGraphEditorModel
206:                                .getParentFile(diagramPane.getDiagram());
207:                        if (file != null) { // may be removed from file
208:                            modifiedLabel
209:                                    .setText((file.isModified()) ? getString("Modified")
210:                                            : (file.isNew()) ? getString("New")
211:                                                    : getString("Saved"));
212:                        }
213:                    }
214:                }
215:
216:                // Shows some memory usage details in the spare label
217:                Runtime runtime = Runtime.getRuntime();
218:                double freeMemory = runtime.freeMemory() / 1024;
219:                double totalMemory = runtime.totalMemory() / 1024;
220:                double usedMemory = totalMemory - freeMemory;
221:
222:                spareLabel.setText(numberFormat.format(usedMemory)
223:                        + getString("KBFree") + " / "
224:                        + numberFormat.format(totalMemory)
225:                        + getString("KBTotal"));
226:            }
227:
228:            /**
229:             * Provides a factory method to construct a status bar for an editor.
230:             */
231:            public static class FactoryMethod extends JGraphEditorFactoryMethod {
232:
233:                /**
234:                 * Defines the default name for factory methods of this kind.
235:                 */
236:                public static String NAME = "createStatusBar";
237:
238:                /**
239:                 * References the enclosing editor.
240:                 */
241:                protected JGraphEditor editor;
242:
243:                /**
244:                 * Constructs a new factory method for the specified enclosing editor
245:                 * using {@link #NAME}.
246:                 * 
247:                 * @param editor
248:                 *            The editor that contains the factory method.
249:                 */
250:                public FactoryMethod(JGraphEditor editor) {
251:                    super (NAME);
252:                    this .editor = editor;
253:                }
254:
255:                /*
256:                 * (non-Javadoc)
257:                 */
258:                public Component createInstance(Node configuration) {
259:                    return new JGraphpadStatusBar(editor);
260:                }
261:
262:            }
263:
264:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.