001: /*
002: * Copyright (c) 2001-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.looks;
032:
033: import java.awt.Insets;
034:
035: import javax.swing.plaf.InsetsUIResource;
036:
037: /**
038: * A factory that vends predefined MicroLayout instances.
039: *
040: * @author Karsten Lentzsch
041: * @version $Revision: 1.2 $
042: *
043: * @see MicroLayout
044: * @see MicroLayoutPolicy
045: * @see MicroLayoutPolicies
046: *
047: * @since 2.1
048: */
049: public final class MicroLayouts {
050:
051: private MicroLayouts() {
052: // Override default constructor; prevents instantation.
053: }
054:
055: // Plastic and Plastic3D MicroLayouts *************************************
056:
057: private static final InsetsUIResource PLASTIC_MENU_ITEM_MARGIN = new InsetsUIResource(
058: 3, 0, 3, 0);
059:
060: private static final InsetsUIResource PLASTIC_MENU_MARGIN = new InsetsUIResource(
061: 2, 4, 2, 4);
062:
063: private static final InsetsUIResource PLASTIC_CHECK_BOX_MARGIN = new InsetsUIResource(
064: 2, 0, 2, 1);
065:
066: public static MicroLayout createPlasticLowResMicroLayout() {
067: return new MicroLayout(new InsetsUIResource(1, 1, 2, 1), // text insets
068: new InsetsUIResource(2, 2, 2, 1), // wrapped text insets
069: new InsetsUIResource(1, 1, 2, 1), // combo box editor insets
070: -1, // combo border size
071: 1, // combo popup border size
072: new Insets(2, 3, 3, 3), // button border insets
073: getButtonMargin(1, 1), // button margin
074: getButtonMargin(1, 1), // commit button margin
075: PLASTIC_CHECK_BOX_MARGIN, // check box margin
076: PLASTIC_MENU_ITEM_MARGIN, // menu item margin
077: PLASTIC_MENU_MARGIN, // menu margin
078: null // popup menu separator margin
079: );
080: }
081:
082: public static MicroLayout createPlasticHiResMicroLayout() {
083: return new MicroLayout(new InsetsUIResource(1, 1, 2, 1), // text insets
084: new InsetsUIResource(2, 2, 2, 1), // wrapped text insets
085: new InsetsUIResource(1, 1, 2, 1), // combo box editor insets
086: -1, // combo border size
087: 1, // combo popup border size
088: new Insets(1, 3, 1, 3), // button border insets
089: getButtonMargin(2, 3), // button margin
090: getButtonMargin(2, 3), // commit button margin
091: PLASTIC_CHECK_BOX_MARGIN, // check box margin
092: PLASTIC_MENU_ITEM_MARGIN, // menu item margin
093: PLASTIC_MENU_MARGIN, // menu margin
094: null // popup menu separator margin
095: );
096: }
097:
098: public static MicroLayout createPlasticVistaMicroLayout() {
099: return new MicroLayout(new InsetsUIResource(1, 1, 1, 1), // text insets
100: new InsetsUIResource(1, 2, 1, 1), // wrapped text insets
101: new InsetsUIResource(1, 1, 1, 1), // combo box editor insets
102: -1, // combo border size
103: 1, // combo popup border size
104: new Insets(2, 3, 3, 3), // button border insets
105: getButtonMargin(0, 1), // button margin
106: getButtonMargin(0, 1), // commit button margin
107: PLASTIC_CHECK_BOX_MARGIN, // check box margin
108: PLASTIC_MENU_ITEM_MARGIN, // menu item margin
109: PLASTIC_MENU_MARGIN, // menu margin
110: null // popup menu separator margin
111: );
112: }
113:
114: public static MicroLayout createPlasticVistaClassicMicroLayout() {
115: return new MicroLayout(new InsetsUIResource(1, 1, 2, 1), // text insets
116: new InsetsUIResource(2, 2, 2, 1), // wrapped text insets
117: new InsetsUIResource(1, 1, 2, 1), // combo box editor insets
118: -1, // combo border size
119: 1, // combo popup border size
120: new Insets(3, 3, 3, 3), // button border insets
121: getButtonMargin(0, 1), // button margin
122: getButtonMargin(0, 1), // commit button margin
123: PLASTIC_CHECK_BOX_MARGIN, // check box margin
124: PLASTIC_MENU_ITEM_MARGIN, // menu item margin
125: PLASTIC_MENU_MARGIN, // menu margin
126: null // popup menu separator margin
127: );
128: }
129:
130: // PlasticXP MicroLayouts *************************************************
131:
132: public static MicroLayout createPlasticXPLowResMicroLayout() {
133: return new MicroLayout(new InsetsUIResource(2, 2, 3, 2), // text insets
134: new InsetsUIResource(2, 2, 3, 2), // wrapped text insets
135: new InsetsUIResource(2, 2, 3, 2), // combo box editor insets
136: -1, // combo border size
137: 1, // combo popup border size
138: new Insets(3, 2, 3, 2), // button border insets
139: getButtonMargin(0, 1), // button margin
140: getButtonMargin(0, 1), // commit button margin
141: PLASTIC_CHECK_BOX_MARGIN, // check box margin
142: PLASTIC_MENU_ITEM_MARGIN, // menu item margin
143: PLASTIC_MENU_MARGIN, // menu margin
144: null // popup menu separator margin
145: );
146: }
147:
148: public static MicroLayout createPlasticXPHiResMicroLayout() {
149: return new MicroLayout(new InsetsUIResource(2, 2, 3, 2), // text insets
150: new InsetsUIResource(2, 2, 3, 2), // wrapped text insets
151: new InsetsUIResource(2, 2, 3, 2), // combo box editor insets
152: -1, // combo border size
153: 1, // combo popup border size
154: new Insets(2, 2, 2, 2), // button border insets
155: getButtonMargin(1, 2), // button margin
156: getButtonMargin(1, 2), // commit button margin
157: PLASTIC_CHECK_BOX_MARGIN, // check box margin
158: PLASTIC_MENU_ITEM_MARGIN, // menu item margin
159: PLASTIC_MENU_MARGIN, // menu margin
160: null // popup menu separator margin
161: );
162: }
163:
164: public static MicroLayout createPlasticXPVistaMicroLayout() {
165: return new MicroLayout(new InsetsUIResource(1, 2, 2, 2), // text insets
166: new InsetsUIResource(1, 2, 2, 2), // wrapped text insets
167: new InsetsUIResource(1, 2, 2, 2), // combo box editor insets
168: -1, // combo border size
169: 1, // combo popup border size
170: new Insets(2, 2, 3, 2), // button border insets
171: getButtonMargin(0, 0), // button margin
172: getButtonMargin(0, 0), // commit button margin
173: PLASTIC_CHECK_BOX_MARGIN, // check box margin
174: PLASTIC_MENU_ITEM_MARGIN, // menu item margin
175: PLASTIC_MENU_MARGIN, // menu margin
176: null // popup menu separator margin
177: );
178: }
179:
180: public static MicroLayout createPlasticXPVistaClassicMicroLayout() {
181: return new MicroLayout(new InsetsUIResource(2, 2, 3, 2), // text insets
182: new InsetsUIResource(2, 2, 3, 2), // wrapped text insets
183: new InsetsUIResource(2, 2, 3, 2), // combo box editor insets
184: -1, // combo border size
185: 1, // combo popup border size
186: new Insets(3, 2, 4, 2), // button border insets
187: getButtonMargin(0, 0), // button margin
188: getButtonMargin(0, 0), // commit button margin
189: PLASTIC_CHECK_BOX_MARGIN, // check box margin
190: PLASTIC_MENU_ITEM_MARGIN, // menu item margin
191: PLASTIC_MENU_MARGIN, // menu margin
192: null // popup menu separator margin
193: );
194: }
195:
196: // Windows MicroLayouts ***************************************************
197:
198: private static final InsetsUIResource WINDOWS_CHECK_BOX_MARGIN = new InsetsUIResource(
199: 2, 0, 2, 0);
200:
201: public static MicroLayout createWindowsClassicLowResMicroLayout() {
202: return new MicroLayout(new InsetsUIResource(1, 2, 2, 2), // text insets
203: new InsetsUIResource(1, 2, 2, 2), // wrapped text insets
204: new InsetsUIResource(1, 2, 2, 2), // combo box editor insets
205: 2, // combo border size
206: 1, // combo popup border size
207: new Insets(3, 2, 4, 2), // button border insets
208: getButtonMargin(1, 1), // button margin
209: getButtonMargin(1, 1), // commit button margin
210: WINDOWS_CHECK_BOX_MARGIN, // check box margin
211: new InsetsUIResource(3, 0, 3, 0), // menu item margin
212: new InsetsUIResource(2, 3, 2, 3), // menu margin
213: new InsetsUIResource(2, 0, 3, 0) // popup menu separator margin
214: );
215: }
216:
217: public static MicroLayout createWindowsClassicHiResMicroLayout() {
218: return new MicroLayout(new InsetsUIResource(1, 2, 2, 2), // text insets
219: new InsetsUIResource(1, 2, 2, 2), // wrapped text insets
220: new InsetsUIResource(1, 2, 2, 2), // combo box editor insets
221: 2, // combo border size
222: 1, // combo popup border size
223: new Insets(3, 2, 4, 2), // button border insets
224: getButtonMargin(1, 1), // button margin
225: getButtonMargin(1, 1), // commit button margin
226: WINDOWS_CHECK_BOX_MARGIN, // check box margin
227: new InsetsUIResource(2, 0, 2, 0), // menu item margin
228: new InsetsUIResource(2, 4, 2, 4), // menu margin
229: new InsetsUIResource(3, 0, 4, 0) // popup menu separator margin
230: );
231: }
232:
233: public static MicroLayout createWindowsXPLowResMicroLayout() {
234: return new MicroLayout(new InsetsUIResource(2, 2, 3, 2), // text insets
235: new InsetsUIResource(2, 2, 3, 2), // wrapped text insets
236: new InsetsUIResource(2, 2, 3, 2), // combo box editor insets
237: 1, // combo border size
238: 1, // combo popup border size
239: new Insets(3, 2, 4, 2), // button border insets
240: getButtonMargin(2, 3), // button margin
241: getButtonMargin(2, 3), // commit button margin
242: WINDOWS_CHECK_BOX_MARGIN, // check box margin
243: new InsetsUIResource(3, 0, 3, 0), // menu item margin
244: new InsetsUIResource(2, 3, 2, 4), // menu margin
245: new InsetsUIResource(2, 3, 3, 3) // popup menu separator margin
246: );
247: }
248:
249: public static MicroLayout createWindowsXPHiResMicroLayout() {
250: return new MicroLayout(new InsetsUIResource(2, 2, 3, 2), // text insets
251: new InsetsUIResource(2, 2, 3, 2), // wrapped text insets
252: new InsetsUIResource(2, 2, 3, 2), // combo box editor insets
253: 1, // combo border size
254: 1, // combo popup border size
255: new Insets(3, 2, 4, 2), // button border insets
256: getButtonMargin(2, 3), // button margin
257: getButtonMargin(2, 3), // commit button margin
258: WINDOWS_CHECK_BOX_MARGIN, // check box margin
259: new InsetsUIResource(2, 0, 2, 0), // menu item margin
260: new InsetsUIResource(2, 5, 2, 6), // menu margin
261: new InsetsUIResource(3, 3, 4, 3) // popup menu separator margin
262: );
263: }
264:
265: public static MicroLayout createWindowsVistaLowResMicroLayout() {
266: return new MicroLayout(new InsetsUIResource(1, 2, 2, 2), // text insets
267: new InsetsUIResource(1, 2, 2, 2), // wrapped text insets
268: new InsetsUIResource(1, 2, 2, 2), // combo box editor insets
269: 1, // combo border size
270: 1, // combo popup border size
271: new Insets(3, 2, 4, 2), // button border insets
272: getButtonMargin(1, 2), // button margin
273: getButtonMargin(1, 2), // commit button margin
274: WINDOWS_CHECK_BOX_MARGIN, // check box margin
275: new InsetsUIResource(3, 0, 3, 0), // menu item margin
276: new InsetsUIResource(2, 3, 2, 4), // menu margin
277: new InsetsUIResource(2, 3, 3, 3) // popup menu separator margin
278: );
279: }
280:
281: public static MicroLayout createWindowsVistaHiResMicroLayout() {
282: return new MicroLayout(new InsetsUIResource(1, 2, 2, 2), // text insets
283: new InsetsUIResource(1, 2, 2, 2), // wrapped text insets
284: new InsetsUIResource(1, 2, 2, 2), // combo box editor insets
285: 1, // combo border size
286: 1, // combo popup border size
287: new Insets(3, 2, 4, 2), // button border insets
288: getButtonMargin(1, 2), // button margin
289: getButtonMargin(1, 2), // commit button margin
290: WINDOWS_CHECK_BOX_MARGIN, // check box margin
291: new InsetsUIResource(2, 0, 2, 0), // menu item margin
292: new InsetsUIResource(2, 5, 2, 6), // menu margin
293: new InsetsUIResource(3, 3, 4, 3) // popup menu separator margin
294: );
295: }
296:
297: // Helper Code ************************************************************
298:
299: private static InsetsUIResource getButtonMargin(int top, int bottom) {
300: int pad = Options.getUseNarrowButtons() ? 4 : 14;
301: return new InsetsUIResource(top, pad, bottom, pad);
302: }
303:
304: }
|