KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > layout > LayoutConstants


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jface.layout;
12
13 import org.eclipse.jface.dialogs.Dialog;
14 import org.eclipse.jface.dialogs.IDialogConstants;
15 import org.eclipse.jface.resource.JFaceResources;
16 import org.eclipse.swt.graphics.FontMetrics;
17 import org.eclipse.swt.graphics.GC;
18 import org.eclipse.swt.graphics.Point;
19 import org.eclipse.swt.widgets.Display;
20
21 /**
22  * Contains various layout constants
23  *
24  * @since 3.2
25  */

26 public final class LayoutConstants {
27     private static Point dialogMargins = null;
28     private static Point dialogSpacing = null;
29     private static Point minButtonSize = null;
30     
31     private static void initializeConstants() {
32         if (dialogMargins != null) {
33             return;
34         }
35         
36         GC gc = new GC(Display.getCurrent());
37         gc.setFont(JFaceResources.getDialogFont());
38         FontMetrics fontMetrics = gc.getFontMetrics();
39
40         dialogMargins = new Point(Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN),
41                 Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN));
42
43         dialogSpacing = new Point(Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING),
44                 Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING));
45
46         minButtonSize = new Point(Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH), 0);
47         
48         gc.dispose();
49     }
50     
51     /**
52      * Returns the default dialog margins, in pixels
53      *
54      * @return the default dialog margins, in pixels
55      */

56     public static final Point getMargins() {
57         initializeConstants();
58         return dialogMargins;
59     }
60
61     /**
62      * Returns the default dialog spacing, in pixels
63      *
64      * @return the default dialog spacing, in pixels
65      */

66     public static final Point getSpacing() {
67         initializeConstants();
68         return dialogSpacing;
69     }
70
71     /**
72      * Returns the default minimum button size, in pixels
73      *
74      * @return the default minimum button size, in pixels
75      */

76     public static final Point getMinButtonSize() {
77         initializeConstants();
78         return minButtonSize;
79     }
80 }
81
Popular Tags