Source Code Cross Referenced for VisualMargin.java in  » Swing-Library » substance-look-feel » contrib » ch » randelshofer » quaqua » 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 » Swing Library » substance look feel » contrib.ch.randelshofer.quaqua 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)VisualMargin.java  2.2  2005-10-01
003:         *
004:         * Copyright (c) 2004-2005 Werner Randelshofer
005:         * Staldenmattweg 2, Immensee, CH-6405, Switzerland.
006:         * All rights reserved.
007:         *
008:         * This software is the confidential and proprietary information of
009:         * Werner Randelshofer. ("Confidential Information").  You shall not
010:         * disclose such Confidential Information and shall use it only in
011:         * accordance with the terms of the license agreement you entered into
012:         * with Werner Randelshofer.
013:         */
014:
015:        package contrib.ch.randelshofer.quaqua;
016:
017:        import java.awt.*;
018:        import javax.swing.*;
019:        import javax.swing.border.*;
020:        import javax.swing.plaf.*;
021:
022:        /**
023:         * The VisualMargin is used to visually align components using bounds
024:         * based on other criterias than the clip bounds of the component.
025:         *
026:         * For example: The clip bounds of a JButton includes its cast shadow and its
027:         * focus ring. When we align the JButton with a JLabel, we want to align the
028:         * baseline of the Text of the JButton with the text in the JLabel.
029:         *
030:         * The visual margin may be quite large. We allow to programmatically set a
031:         * smaller margin using the client property "Quaqua.Component.margin".
032:         *
033:         * @author  Werner Randelshofer
034:         * @version 2.2 2005-10-01 Added method getVisualMargin.
035:         * <br>2.1 2005-06-21 Implements UIResource.
036:         * <br>2.0 2005-05-08 Renamed from BorderMargin to VisualMargin. Reworked
037:         * API.
038:         * <br>1.0  31 March 2005  Created.
039:         */
040:        public class VisualMargin extends AbstractBorder implements  UIResource {
041:            /**
042:             * Defines the margin from the clip bounds of the
043:             * component to its visually perceived borderline.
044:             */
045:            private Insets layoutMargin;
046:
047:            /**
048:             * The UIManager Property to be used for the default margin.
049:             */
050:            private String uiManagerPropertyName = "Component.visualMargin";
051:            /**
052:             * The Client Property to be used for the default margin.
053:             */
054:            private String propertyName = "Quaqua.Component.visualMargin";
055:
056:            private boolean isTopFixed, isLeftFixed, isBottomFixed,
057:                    isRightFixed;
058:
059:            /**
060:             * Creates a new VisualMargin.
061:             */
062:            public VisualMargin() {
063:                layoutMargin = new Insets(0, 0, 0, 0);
064:            }
065:
066:            /**
067:             * The UIManager Property to be used for the default margin.
068:             */
069:            public void setPropertyName(String propertyName) {
070:                //  this.propertyName = propertyName;
071:            }
072:
073:            /*
074:             * Specifies SwingConstants.TOP, LEFT, BOTTOM, RIGHT to be fixed.
075:             * Set to false to unfix.
076:             */
077:            public void setFixed(boolean top, boolean left, boolean bottom,
078:                    boolean right) {
079:                isTopFixed = top;
080:                isLeftFixed = left;
081:                isBottomFixed = bottom;
082:                isRightFixed = right;
083:            }
084:
085:            /**
086:             * Creates a new VisualMargin.
087:             *
088:             * @param top Defines the margin from the clip bounds of the
089:             * component to its visual bounds.
090:             * @param left Defines the margin from the clip bounds of the
091:             * component to its visual bounds.
092:             * @param bottom Defines the margin from the clip bounds of the
093:             * component to its visual bounds.
094:             * @param right Defines the margin from the clip bounds of the
095:             * component to its visual bounds.
096:             */
097:            public VisualMargin(int top, int left, int bottom, int right) {
098:                layoutMargin = new Insets(top, left, bottom, right);
099:            }
100:
101:            public VisualMargin(int top, int left, int bottom, int right,
102:                    boolean ftop, boolean fleft, boolean fbottom, boolean fright) {
103:                layoutMargin = new Insets(top, left, bottom, right);
104:                isTopFixed = ftop;
105:                isLeftFixed = fleft;
106:                isBottomFixed = fbottom;
107:                isRightFixed = fright;
108:            }
109:
110:            public VisualMargin(boolean ftop, boolean fleft, boolean fbottom,
111:                    boolean fright) {
112:                layoutMargin = new Insets(0, 0, 0, 0);
113:                isTopFixed = ftop;
114:                isLeftFixed = fleft;
115:                isBottomFixed = fbottom;
116:                isRightFixed = fright;
117:            }
118:
119:            /**
120:             * Creates a new VisualMargin.
121:             *
122:             * @param layoutMargin Defines the margin from the clip bounds of the
123:             * component to its visual bounds. The margin has usually negative values!
124:             */
125:            public VisualMargin(Insets layoutMargin) {
126:                this .layoutMargin = layoutMargin;
127:            }
128:
129:            public Insets getVisualMargin(Component c) {
130:                Insets insets = new Insets(layoutMargin.top, layoutMargin.left,
131:                        layoutMargin.bottom, layoutMargin.right);
132:
133:                if (c instanceof  JComponent) {
134:                    Insets componentMargin = (Insets) ((JComponent) c)
135:                            .getClientProperty(propertyName);
136:                    if (componentMargin == null && propertyName != null) {
137:                        componentMargin = UIManager
138:                                .getInsets(uiManagerPropertyName);
139:                    }
140:                    if (componentMargin != null) {
141:                        if (!isTopFixed)
142:                            insets.top = componentMargin.top;
143:                        if (!isLeftFixed)
144:                            insets.left = componentMargin.left;
145:                        if (!isBottomFixed)
146:                            insets.bottom = componentMargin.bottom;
147:                        if (!isRightFixed)
148:                            insets.right = componentMargin.right;
149:                    }
150:                }
151:                return insets;
152:            }
153:
154:            public Insets getBorderInsets(Component c) {
155:                return getBorderInsets(c, new Insets(0, 0, 0, 0));
156:            }
157:
158:            /**
159:             * Reinitializes the insets parameter with this Border's current Insets.
160:             * @param c the component for which this border insets value applies
161:             * @param insets the object to be reinitialized
162:             * @return the <code>insets</code> object
163:             */
164:            public Insets getBorderInsets(Component c, Insets insets) {
165:                return getVisualMargin(c, insets);
166:            }
167:
168:            /**
169:             * Reinitializes the insets parameter with this Border's current Insets.
170:             * @param c the component for which this border insets value applies
171:             * @param insets the object to be reinitialized
172:             * @return the <code>insets</code> object
173:             */
174:            protected Insets getVisualMargin(Component c, Insets insets) {
175:                insets.top = -layoutMargin.top;
176:                insets.left = -layoutMargin.left;
177:                insets.bottom = -layoutMargin.bottom;
178:                insets.right = -layoutMargin.right;
179:
180:                if (c instanceof  JComponent) {
181:                    Insets componentMargin = (Insets) ((JComponent) c)
182:                            .getClientProperty(propertyName);
183:                    if (componentMargin == null && propertyName != null) {
184:                        componentMargin = UIManager
185:                                .getInsets(uiManagerPropertyName);
186:                    }
187:                    if (componentMargin != null) {
188:                        if (!isTopFixed)
189:                            insets.top += componentMargin.top;
190:                        if (!isLeftFixed)
191:                            insets.left += componentMargin.left;
192:                        if (!isBottomFixed)
193:                            insets.bottom += componentMargin.bottom;
194:                        if (!isRightFixed)
195:                            insets.right += componentMargin.right;
196:                    }
197:                }
198:                return insets;
199:            }
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.