Source Code Cross Referenced for InsetsChooserPanel.java in  » Graphic-Library » jcommon-components » org » jfree » ui » 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 » jcommon components » org.jfree.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ========================================================================
002:         * JCommon : a free general purpose class library for the Java(tm) platform
003:         * ========================================================================
004:         *
005:         * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006:         * 
007:         * Project Info:  http://www.jfree.org/jcommon/index.html
008:         *
009:         * This library is free software; you can redistribute it and/or modify it 
010:         * under the terms of the GNU Lesser General Public License as published by 
011:         * the Free Software Foundation; either version 2.1 of the License, or 
012:         * (at your option) any later version.
013:         *
014:         * This library is distributed in the hope that it will be useful, but 
015:         * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017:         * License for more details.
018:         *
019:         * You should have received a copy of the GNU Lesser General Public
020:         * License along with this library; if not, write to the Free Software
021:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022:         * USA.  
023:         *
024:         * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025:         * in the United States and other countries.]
026:         * 
027:         * -----------------------
028:         * InsetsChooserPanel.java
029:         * -----------------------
030:         * (C) Copyright 2000-2005, by Andrzej Porebski and Contributors.
031:         *
032:         * Original Author:  Andrzej Porebski;
033:         * Contributor(s):   David Gilbert (for Object Refinery Limited);
034:         *                   Arnaud Lelievre;
035:         *
036:         * $Id: InsetsChooserPanel.java,v 1.6 2005/11/16 15:58:41 taqua Exp $
037:         *
038:         * Changes (from 7-Nov-2001)
039:         * -------------------------
040:         * 07-Nov-2001 : Added to com.jrefinery.ui package (DG);
041:         * 14-Oct-2002 : Fixed errors reported by Checkstyle (DG);
042:         * 03-Feb-2003 : Added Math.abs() to ensure no negative insets can be set (DG);
043:         * 08-Sep-2003 : Added internationalization via use of properties 
044:         *               resourceBundle (RFE 690236) (AL);
045:         * 07-Oct-2005 : Renamed getInsets() --> getInsetsValue() to avoid conflict 
046:         *               with JComponent's getInsets() (DG);
047:         *
048:         */
049:
050:        package org.jfree.ui;
051:
052:        import java.awt.BorderLayout;
053:        import java.awt.GridBagConstraints;
054:        import java.awt.GridBagLayout;
055:        import java.awt.Insets;
056:        import java.util.ResourceBundle;
057:
058:        import javax.swing.JLabel;
059:        import javax.swing.JPanel;
060:        import javax.swing.JTextField;
061:        import javax.swing.border.TitledBorder;
062:
063:        /**
064:         * A component for editing an instance of the Insets class.
065:         *
066:         * @author Andrzej Porebski
067:         */
068:        public class InsetsChooserPanel extends JPanel {
069:
070:            /** A text field for the 'top' setting. */
071:            private JTextField topValueEditor;
072:
073:            /** A text field for the 'left' setting. */
074:            private JTextField leftValueEditor;
075:
076:            /** A text field for the 'bottom' setting. */
077:            private JTextField bottomValueEditor;
078:
079:            /** A text field for the 'right' setting. */
080:            private JTextField rightValueEditor;
081:
082:            /** The resourceBundle for the localization. */
083:            protected static ResourceBundle localizationResources = ResourceBundle
084:                    .getBundle("org.jfree.ui.LocalizationBundle");
085:
086:            /**
087:             * Creates a chooser panel that allows manipulation of Insets values.
088:             * The values are initialized to the empty insets (0,0,0,0).
089:             */
090:            public InsetsChooserPanel() {
091:                this (new Insets(0, 0, 0, 0));
092:            }
093:
094:            /**
095:             * Creates a chooser panel that allows manipulation of Insets values.
096:             * The values are initialized to the current values of provided insets.
097:             *
098:             * @param current  the insets.
099:             */
100:            public InsetsChooserPanel(Insets current) {
101:                current = (current == null) ? new Insets(0, 0, 0, 0) : current;
102:
103:                this .topValueEditor = new JTextField(new IntegerDocument(), ""
104:                        + current.top, 0);
105:                this .leftValueEditor = new JTextField(new IntegerDocument(), ""
106:                        + current.left, 0);
107:                this .bottomValueEditor = new JTextField(new IntegerDocument(),
108:                        "" + current.bottom, 0);
109:                this .rightValueEditor = new JTextField(new IntegerDocument(),
110:                        "" + current.right, 0);
111:
112:                final JPanel panel = new JPanel(new GridBagLayout());
113:                panel.setBorder(new TitledBorder(localizationResources
114:                        .getString("Insets")));
115:
116:                // First row
117:                panel.add(new JLabel(localizationResources.getString("Top")),
118:                        new GridBagConstraints(1, 0, 3, 1, 0.0, 0.0,
119:                                GridBagConstraints.CENTER,
120:                                GridBagConstraints.NONE,
121:                                new Insets(0, 0, 0, 0), 0, 0));
122:
123:                // Second row
124:                panel.add(new JLabel(" "),
125:                        new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
126:                                GridBagConstraints.CENTER,
127:                                GridBagConstraints.BOTH, new Insets(0, 12, 0,
128:                                        12), 8, 0));
129:                panel.add(this .topValueEditor, new GridBagConstraints(2, 1, 1,
130:                        1, 0.0, 0.0, GridBagConstraints.CENTER,
131:                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
132:                        0, 0));
133:                panel.add(new JLabel(" "),
134:                        new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0,
135:                                GridBagConstraints.CENTER,
136:                                GridBagConstraints.BOTH, new Insets(0, 12, 0,
137:                                        11), 8, 0));
138:
139:                // Third row
140:                panel.add(new JLabel(localizationResources.getString("Left")),
141:                        new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
142:                                GridBagConstraints.CENTER,
143:                                GridBagConstraints.BOTH,
144:                                new Insets(0, 4, 0, 4), 0, 0));
145:                panel.add(this .leftValueEditor, new GridBagConstraints(1, 2, 1,
146:                        1, 0.0, 0.0, GridBagConstraints.CENTER,
147:                        GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
148:                panel.add(new JLabel(" "),
149:                        new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0,
150:                                GridBagConstraints.CENTER,
151:                                GridBagConstraints.NONE, new Insets(0, 12, 0,
152:                                        12), 8, 0));
153:                panel.add(this .rightValueEditor, new GridBagConstraints(3, 2,
154:                        1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
155:                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
156:                        0, 0));
157:                panel.add(new JLabel(localizationResources.getString("Right")),
158:                        new GridBagConstraints(4, 2, 1, 1, 0.0, 0.0,
159:                                GridBagConstraints.CENTER,
160:                                GridBagConstraints.NONE,
161:                                new Insets(0, 4, 0, 4), 0, 0));
162:
163:                // Fourth row
164:                panel.add(this .bottomValueEditor, new GridBagConstraints(2, 3,
165:                        1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
166:                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
167:                        0, 0));
168:
169:                // Fifth row
170:                panel.add(
171:                        new JLabel(localizationResources.getString("Bottom")),
172:                        new GridBagConstraints(1, 4, 3, 1, 0.0, 0.0,
173:                                GridBagConstraints.CENTER,
174:                                GridBagConstraints.NONE,
175:                                new Insets(0, 0, 0, 0), 0, 0));
176:                setLayout(new BorderLayout());
177:                add(panel, BorderLayout.CENTER);
178:
179:            }
180:
181:            /**
182:             * Returns a new <code>Insets</code> instance to match the values entered
183:             * on the panel.
184:             *
185:             * @return The insets.
186:             */
187:            public Insets getInsetsValue() {
188:                return new Insets(Math.abs(stringToInt(this .topValueEditor
189:                        .getText())), Math.abs(stringToInt(this .leftValueEditor
190:                        .getText())), Math
191:                        .abs(stringToInt(this .bottomValueEditor.getText())),
192:                        Math.abs(stringToInt(this .rightValueEditor.getText())));
193:            }
194:
195:            /**
196:             * Converts a string representing an integer into its numerical value.
197:             * If this string does not represent a valid integer value, value of 0
198:             * is returned.
199:             *
200:             * @param value  the string.
201:             *
202:             * @return the value.
203:             */
204:            protected int stringToInt(String value) {
205:                value = value.trim();
206:                if (value.length() == 0) {
207:                    return 0;
208:                } else {
209:                    try {
210:                        return Integer.parseInt(value);
211:                    } catch (NumberFormatException e) {
212:                        return 0;
213:                    }
214:                }
215:            }
216:
217:            /**
218:             * Calls super removeNotify and removes all subcomponents from this panel.
219:             */
220:            public void removeNotify() {
221:                super.removeNotify();
222:                removeAll();
223:            }
224:
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.