Source Code Cross Referenced for Utils.java in  » Profiler » ejp » ejp » presenter » gui » 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 » Profiler » ejp » ejp.presenter.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         $Id: Utils.java,v 1.6 2005/02/14 12:06:20 vauclair Exp $
003:
004:         Copyright (C) 2002-2005 Sebastien Vauclair
005:
006:         This file is part of Extensible Java Profiler.
007:
008:         Extensible Java Profiler is free software; you can redistribute it and/or
009:         modify it under the terms of the GNU General Public License as published by
010:         the Free Software Foundation; either version 2 of the License, or
011:         (at your option) any later version.
012:
013:         Extensible Java Profiler is distributed in the hope that it will be useful,
014:         but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         GNU General Public License for more details.
017:
018:         You should have received a copy of the GNU General Public License
019:         along with Extensible Java Profiler; if not, write to the Free Software
020:         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
021:         */
022:
023:        package ejp.presenter.gui;
024:
025:        import java.awt.Dialog;
026:        import java.awt.Dimension;
027:        import java.awt.Font;
028:        import java.awt.GridBagConstraints;
029:        import java.awt.Insets;
030:        import java.awt.Point;
031:        import java.awt.Window;
032:        import java.awt.event.ActionEvent;
033:        import java.awt.event.KeyEvent;
034:
035:        import javax.accessibility.AccessibleContext;
036:        import javax.swing.AbstractAction;
037:        import javax.swing.JButton;
038:        import javax.swing.JComponent;
039:        import javax.swing.JDialog;
040:        import javax.swing.JLabel;
041:        import javax.swing.JPanel;
042:        import javax.swing.JTextField;
043:        import javax.swing.KeyStroke;
044:
045:        /**
046:         * Various GUI utilities methods.
047:         * 
048:         * @author Sebastien Vauclair
049:         * @version <code>$Revision: 1.6 $<br>$Date: 2005/02/14 12:06:20 $</code>
050:         */
051:        public abstract class Utils {
052:            public static final Font FONT_11 = new Font("Default", 0, 11);
053:
054:            public static final Insets INSETS_5 = new Insets(5, 5, 5, 5);
055:
056:            public static void setCommonProperties(JComponent aComponent) {
057:                aComponent.setDoubleBuffered(true);
058:                aComponent.setFont(FONT_11);
059:            }
060:
061:            public static void recursiveSetFont(AccessibleContext aContext) {
062:                aContext.getAccessibleComponent().setFont(FONT_11);
063:                int nb = aContext.getAccessibleChildrenCount();
064:                for (int i = 0; i < nb; i++)
065:                    recursiveSetFont(aContext.getAccessibleChild(i)
066:                            .getAccessibleContext());
067:            }
068:
069:            public static void centerDialog(Dialog aDialog, Window aParent) {
070:                Point parentLoc = aParent.getLocation();
071:                Dimension parentDim = aParent.getSize();
072:                int x = (int) (parentLoc.getX() + (parentDim.getWidth() - aDialog
073:                        .getWidth()) / 2);
074:                int y = (int) (parentLoc.getY() + (parentDim.getHeight() - aDialog
075:                        .getHeight()) / 2);
076:                aDialog.setLocation((x < 0 ? 0 : x), (y < 0 ? 0 : y));
077:            }
078:
079:            public static void setSameSize(JButton[] aButtons) {
080:                int maxX = Integer.MIN_VALUE;
081:                int maxY = Integer.MIN_VALUE;
082:                for (int i = 0; i < aButtons.length; i++) {
083:                    Dimension d = aButtons[i].getPreferredSize();
084:                    int x = (int) d.getWidth();
085:                    if (x > maxX)
086:                        maxX = x;
087:                    int y = (int) d.getHeight();
088:                    if (y > maxY)
089:                        maxY = y;
090:                }
091:                Dimension max = new Dimension(maxX, maxY);
092:                for (int i = 0; i < aButtons.length; i++)
093:                    aButtons[i].setPreferredSize(max);
094:            }
095:
096:            /**
097:             * @param aPanel
098:             *          a panel with using a <code>GridBagLayout</code>
099:             */
100:            protected static JTextField addTextField(JPanel aPanel,
101:                    String aDescription, int aColumns, boolean aReadOnly,
102:                    int aGridY, String aToolTip) {
103:                // description
104:                JLabel jlTemp = new JLabel(aDescription);
105:                setCommonProperties(jlTemp);
106:                GridBagConstraints gbcTemp = new GridBagConstraints();
107:                gbcTemp.anchor = GridBagConstraints.NORTHWEST;
108:                gbcTemp.gridx = 0;
109:                gbcTemp.gridy = aGridY;
110:                gbcTemp.insets = INSETS_5;
111:                aPanel.add(jlTemp, gbcTemp);
112:
113:                // value
114:                JTextField result = new JTextField(aColumns);
115:                setCommonProperties(result);
116:                result.setEditable(!aReadOnly);
117:                result.setToolTipText(aToolTip);
118:                gbcTemp.gridx = 1;
119:                gbcTemp.fill = GridBagConstraints.BOTH;
120:                gbcTemp.weightx = 1;
121:                gbcTemp.weighty = 1;
122:                aPanel.add(result, gbcTemp);
123:
124:                return result;
125:            }
126:
127:            // ///////////////////////////////////////////////////////////////////////////
128:            // SET A COMPONENT'S TEXT WHILE KEEPING ITS PREFERRED SIZE
129:            // ///////////////////////////////////////////////////////////////////////////
130:
131:            /**
132:             * Sets a button's text while keeping its preferred size
133:             */
134:            protected static void setButtonText(JButton aButton, String aText) {
135:                Dimension size = aButton.getPreferredSize();
136:                aButton.setText(aText);
137:                aButton.setPreferredSize(size);
138:            }
139:
140:            /**
141:             * Sets a text field's text while keeping its preferred size
142:             * 
143:             * This method is <b>very </b> important since if the text is set directly and
144:             * it exceeds text field's current size, the whole window will collapse.
145:             */
146:            public static void setTextFieldText(JTextField aTextField,
147:                    String aText, String aDefaultText) {
148:                Dimension size = aTextField.getPreferredSize();
149:
150:                if (aText == null || aText.length() == 0)
151:                    aTextField.setText(aDefaultText);
152:                else
153:                    aTextField.setText(aText);
154:                aTextField.setCaretPosition(0); // ensure beginning of text is readable
155:
156:                aTextField.setPreferredSize(size);
157:            }
158:
159:            public static void setTextFieldText(JTextField aTextField,
160:                    String aText) {
161:                setTextFieldText(aTextField, aText, null);
162:            }
163:
164:            /**
165:             * Registers the ESCAPE key to close dialog.
166:             */
167:            public static void registerEscapeKey(JDialog dialog_,
168:                    final JButton cancelButton_) {
169:                dialog_.getRootPane().getActionMap().put("close",
170:                        new AbstractAction() {
171:                            public void actionPerformed(ActionEvent e) {
172:                                cancelButton_.doClick();
173:                            }
174:                        });
175:                dialog_.getRootPane().getInputMap().put(
176:                        KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close");
177:            }
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.