KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > FormLayoutFactory


1 /*******************************************************************************
2  * Copyright (c) 2007 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
12 package org.eclipse.pde.internal.ui.editor;
13
14 import org.eclipse.swt.layout.GridLayout;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Display;
17 import org.eclipse.ui.forms.widgets.TableWrapLayout;
18
19 /**
20  * FormLayoutFactory
21  *
22  */

23 public class FormLayoutFactory {
24
25     // Used in place of 0. If 0 is used, widget borders will appear clipped
26
// on some platforms (e.g. Windows XP Classic Theme).
27
// Form tool kit requires parent composites containing the widget to have
28
// at least 1 pixel border margins in order to paint the flat borders.
29
// The form toolkit paints flat borders on a given widget when native
30
// borders are not painted by SWT. See FormToolkit#paintBordersFor()
31
public static final int DEFAULT_CLEAR_MARGIN = 2;
32     
33     // Required to allow space for field decorations
34
public static final int CONTROL_HORIZONTAL_INDENT = 3;
35     
36     // UI Forms Standards
37

38     // FORM BODY
39
public static final int FORM_BODY_MARGIN_TOP = 12;
40     public static final int FORM_BODY_MARGIN_BOTTOM = 12;
41     public static final int FORM_BODY_MARGIN_LEFT = 6;
42     public static final int FORM_BODY_MARGIN_RIGHT = 6;
43     public static final int FORM_BODY_HORIZONTAL_SPACING = 20;
44     // Should be 20; but, we minus 3 because the section automatically pads the
45
// bottom margin by that amount
46
public static final int FORM_BODY_VERTICAL_SPACING = 17;
47     public static final int FORM_BODY_MARGIN_HEIGHT = 0;
48     public static final int FORM_BODY_MARGIN_WIDTH = 0;
49     
50     // SECTION CLIENT
51
public static final int SECTION_CLIENT_MARGIN_TOP = 5;
52     public static final int SECTION_CLIENT_MARGIN_BOTTOM = 5;
53     // Should be 6; but, we minus 4 because the section automatically pads the
54
// left margin by that amount
55
public static final int SECTION_CLIENT_MARGIN_LEFT = 2;
56     // Should be 6; but, we minus 4 because the section automatically pads the
57
// right margin by that amount
58
public static final int SECTION_CLIENT_MARGIN_RIGHT = 2;
59     public static final int SECTION_CLIENT_HORIZONTAL_SPACING = 5;
60     public static final int SECTION_CLIENT_VERTICAL_SPACING = 5;
61     public static final int SECTION_CLIENT_MARGIN_HEIGHT = 0;
62     public static final int SECTION_CLIENT_MARGIN_WIDTH = 0;
63
64     public static final int SECTION_HEADER_VERTICAL_SPACING = 6;
65
66     // CLEAR
67
public static final int CLEAR_MARGIN_TOP = DEFAULT_CLEAR_MARGIN;
68     public static final int CLEAR_MARGIN_BOTTOM = DEFAULT_CLEAR_MARGIN;
69     public static final int CLEAR_MARGIN_LEFT = DEFAULT_CLEAR_MARGIN;
70     public static final int CLEAR_MARGIN_RIGHT = DEFAULT_CLEAR_MARGIN;
71     public static final int CLEAR_HORIZONTAL_SPACING = 0;
72     public static final int CLEAR_VERTICAL_SPACING = 0;
73     public static final int CLEAR_MARGIN_HEIGHT = 0;
74     public static final int CLEAR_MARGIN_WIDTH = 0;
75     
76     // FORM PANE
77
public static final int FORM_PANE_MARGIN_TOP = 0;
78     public static final int FORM_PANE_MARGIN_BOTTOM = 0;
79     public static final int FORM_PANE_MARGIN_LEFT = 0;
80     public static final int FORM_PANE_MARGIN_RIGHT = 0;
81     public static final int FORM_PANE_HORIZONTAL_SPACING = FORM_BODY_HORIZONTAL_SPACING;
82     public static final int FORM_PANE_VERTICAL_SPACING = FORM_BODY_VERTICAL_SPACING;
83     public static final int FORM_PANE_MARGIN_HEIGHT = 0;
84     public static final int FORM_PANE_MARGIN_WIDTH = 0;
85     
86     // MASTER DETAILS
87
public static final int MASTER_DETAILS_MARGIN_TOP = 0;
88     public static final int MASTER_DETAILS_MARGIN_BOTTOM = 0;
89     // Used only by masters part. Details part margin dynamically calculated
90
public static final int MASTER_DETAILS_MARGIN_LEFT = 0;
91     // Used only by details part. Masters part margin dynamically calcualated
92
public static final int MASTER_DETAILS_MARGIN_RIGHT = 1;
93     public static final int MASTER_DETAILS_HORIZONTAL_SPACING = FORM_BODY_HORIZONTAL_SPACING;
94     public static final int MASTER_DETAILS_VERTICAL_SPACING = FORM_BODY_VERTICAL_SPACING;
95     public static final int MASTER_DETAILS_MARGIN_HEIGHT = 0;
96     public static final int MASTER_DETAILS_MARGIN_WIDTH = 0;
97     
98     /**
99      *
100      */

101     private FormLayoutFactory() {
102         // NO-OP
103
}
104     
105     /**
106      * For form bodies.
107      * @param makeColumnsEqualWidth
108      * @param numColumns
109      * @return
110      */

111     public static GridLayout createFormGridLayout(boolean makeColumnsEqualWidth,
112             int numColumns) {
113         GridLayout layout = new GridLayout();
114
115         layout.marginHeight = FORM_BODY_MARGIN_HEIGHT;
116         layout.marginWidth = FORM_BODY_MARGIN_WIDTH;
117
118         layout.marginTop = FORM_BODY_MARGIN_TOP;
119         layout.marginBottom = FORM_BODY_MARGIN_BOTTOM;
120         layout.marginLeft = FORM_BODY_MARGIN_LEFT;
121         layout.marginRight = FORM_BODY_MARGIN_RIGHT;
122
123         layout.horizontalSpacing = FORM_BODY_HORIZONTAL_SPACING;
124         layout.verticalSpacing = FORM_BODY_VERTICAL_SPACING;
125         
126         layout.makeColumnsEqualWidth = makeColumnsEqualWidth;
127         layout.numColumns = numColumns;
128         
129         return layout;
130     }
131
132     /**
133      * For miscellaneous grouping composites.
134      * For sections (as a whole - header plus client).
135      * @param makeColumnsEqualWidth
136      * @param numColumns
137      * @return
138      */

139     public static GridLayout createClearGridLayout(boolean makeColumnsEqualWidth,
140             int numColumns) {
141         GridLayout layout = new GridLayout();
142
143         layout.marginHeight = CLEAR_MARGIN_HEIGHT;
144         layout.marginWidth = CLEAR_MARGIN_WIDTH;
145
146         layout.marginTop = CLEAR_MARGIN_TOP;
147         layout.marginBottom = CLEAR_MARGIN_BOTTOM;
148         layout.marginLeft = CLEAR_MARGIN_LEFT;
149         layout.marginRight = CLEAR_MARGIN_RIGHT;
150
151         layout.horizontalSpacing = CLEAR_HORIZONTAL_SPACING;
152         layout.verticalSpacing = CLEAR_VERTICAL_SPACING;
153         
154         layout.makeColumnsEqualWidth = makeColumnsEqualWidth;
155         layout.numColumns = numColumns;
156         
157         return layout;
158     }
159     
160     /**
161      * For form bodies.
162      * @param makeColumnsEqualWidth
163      * @param numColumns
164      * @return
165      */

166     public static TableWrapLayout createFormTableWrapLayout(
167             boolean makeColumnsEqualWidth,
168             int numColumns) {
169         TableWrapLayout layout = new TableWrapLayout();
170         
171         layout.topMargin = FORM_BODY_MARGIN_TOP;
172         layout.bottomMargin = FORM_BODY_MARGIN_BOTTOM;
173         layout.leftMargin = FORM_BODY_MARGIN_LEFT;
174         layout.rightMargin = FORM_BODY_MARGIN_RIGHT;
175
176         layout.horizontalSpacing = FORM_BODY_HORIZONTAL_SPACING;
177         layout.verticalSpacing = FORM_BODY_VERTICAL_SPACING;
178
179         layout.makeColumnsEqualWidth = makeColumnsEqualWidth;
180         layout.numColumns = numColumns;
181
182         return layout;
183     }
184     
185     /**
186      * For composites used to group sections in left and right panes.
187      * @param makeColumnsEqualWidth
188      * @param numColumns
189      * @return
190      */

191     public static TableWrapLayout createFormPaneTableWrapLayout(
192             boolean makeColumnsEqualWidth,
193             int numColumns) {
194         TableWrapLayout layout = new TableWrapLayout();
195         
196         layout.topMargin = FORM_PANE_MARGIN_TOP;
197         layout.bottomMargin = FORM_PANE_MARGIN_BOTTOM;
198         layout.leftMargin = FORM_PANE_MARGIN_LEFT;
199         layout.rightMargin = FORM_PANE_MARGIN_RIGHT;
200
201         layout.horizontalSpacing = FORM_PANE_HORIZONTAL_SPACING;
202         layout.verticalSpacing = FORM_PANE_VERTICAL_SPACING;
203
204         layout.makeColumnsEqualWidth = makeColumnsEqualWidth;
205         layout.numColumns = numColumns;
206
207         return layout;
208     }
209     
210     /**
211      * For composites used to group sections in left and right panes.
212      * @param makeColumnsEqualWidth
213      * @param numColumns
214      * @return
215      */

216     public static GridLayout createFormPaneGridLayout(boolean makeColumnsEqualWidth,
217             int numColumns) {
218         GridLayout layout = new GridLayout();
219
220         layout.marginHeight = FORM_PANE_MARGIN_HEIGHT;
221         layout.marginWidth = FORM_PANE_MARGIN_WIDTH;
222
223         layout.marginTop = FORM_PANE_MARGIN_TOP;
224         layout.marginBottom = FORM_PANE_MARGIN_BOTTOM;
225         layout.marginLeft = FORM_PANE_MARGIN_LEFT;
226         layout.marginRight = FORM_PANE_MARGIN_RIGHT;
227
228         layout.horizontalSpacing = FORM_PANE_HORIZONTAL_SPACING;
229         layout.verticalSpacing = FORM_PANE_VERTICAL_SPACING;
230         
231         layout.makeColumnsEqualWidth = makeColumnsEqualWidth;
232         layout.numColumns = numColumns;
233         
234         return layout;
235     }
236     
237     /**
238      * For miscellaneous grouping composites.
239      * For sections (as a whole - header plus client).
240      * @param makeColumnsEqualWidth
241      * @param numColumns
242      * @return
243      */

244     public static TableWrapLayout createClearTableWrapLayout(
245             boolean makeColumnsEqualWidth,
246             int numColumns) {
247         TableWrapLayout layout = new TableWrapLayout();
248         
249         layout.topMargin = CLEAR_MARGIN_TOP;
250         layout.bottomMargin = CLEAR_MARGIN_BOTTOM;
251         layout.leftMargin = CLEAR_MARGIN_LEFT;
252         layout.rightMargin = CLEAR_MARGIN_RIGHT;
253         
254         layout.horizontalSpacing = CLEAR_HORIZONTAL_SPACING;
255         layout.verticalSpacing = CLEAR_VERTICAL_SPACING;
256
257         layout.makeColumnsEqualWidth = makeColumnsEqualWidth;
258         layout.numColumns = numColumns;
259         
260         return layout;
261     }
262     
263     /**
264      * For master sections belonging to a master details block.
265      * @param makeColumnsEqualWidth
266      * @param numColumns
267      * @return
268      */

269     public static GridLayout createMasterGridLayout(
270             boolean makeColumnsEqualWidth,
271             int numColumns) {
272         GridLayout layout = new GridLayout();
273
274         layout.marginHeight = MASTER_DETAILS_MARGIN_HEIGHT;
275         layout.marginWidth = MASTER_DETAILS_MARGIN_WIDTH;
276
277         layout.marginTop = MASTER_DETAILS_MARGIN_TOP;
278         layout.marginBottom = MASTER_DETAILS_MARGIN_BOTTOM;
279         layout.marginLeft = MASTER_DETAILS_MARGIN_LEFT;
280         // Cannot set layout on a sash form.
281
// In order to replicate the horizontal spacing between sections,
282
// divide the amount by 2 and set the master section right margin to
283
// half the amount and set the left details section margin to half
284
// the amount. The default sash width is currently set at 3.
285
// Minus 1 pixel from each half. Use the 1 left over pixel to separate
286
// the details section from the vertical scollbar.
287
int marginRight = MASTER_DETAILS_HORIZONTAL_SPACING;
288         if (marginRight > 0) {
289             marginRight = marginRight / 2;
290             if (marginRight > 0) {
291                 marginRight--;
292             }
293         }
294         layout.marginRight = marginRight;
295
296         layout.horizontalSpacing = MASTER_DETAILS_HORIZONTAL_SPACING;
297         layout.verticalSpacing = MASTER_DETAILS_VERTICAL_SPACING;
298         
299         layout.makeColumnsEqualWidth = makeColumnsEqualWidth;
300         layout.numColumns = numColumns;
301         
302         return layout;
303     }
304     
305     /**
306      * For details sections belonging to a master details block.
307      * @param makeColumnsEqualWidth
308      * @param numColumns
309      * @return
310      */

311     public static GridLayout createDetailsGridLayout(
312             boolean makeColumnsEqualWidth,
313             int numColumns) {
314         GridLayout layout = new GridLayout();
315
316         layout.marginHeight = MASTER_DETAILS_MARGIN_HEIGHT;
317         layout.marginWidth = MASTER_DETAILS_MARGIN_WIDTH;
318
319         layout.marginTop = MASTER_DETAILS_MARGIN_TOP;
320         layout.marginBottom = MASTER_DETAILS_MARGIN_BOTTOM;
321         // Cannot set layout on a sash form.
322
// In order to replicate the horizontal spacing between sections,
323
// divide the amount by 2 and set the master section right margin to
324
// half the amount and set the left details section margin to half
325
// the amount. The default sash width is currently set at 3.
326
// Minus 1 pixel from each half. Use the 1 left over pixel to separate
327
// the details section from the vertical scollbar.
328
int marginLeft = MASTER_DETAILS_HORIZONTAL_SPACING;
329         if (marginLeft > 0) {
330             marginLeft = marginLeft / 2;
331             if (marginLeft > 0) {
332                 marginLeft--;
333             }
334         }
335         layout.marginLeft = marginLeft;
336         layout.marginRight = MASTER_DETAILS_MARGIN_RIGHT;
337
338         layout.horizontalSpacing = MASTER_DETAILS_HORIZONTAL_SPACING;
339         layout.verticalSpacing = MASTER_DETAILS_VERTICAL_SPACING;
340         
341         layout.makeColumnsEqualWidth = makeColumnsEqualWidth;
342         layout.numColumns = numColumns;
343         
344         return layout;
345     }
346     
347     /**
348      * For composites set as section clients.
349      * For composites containg form text.
350      * @param makeColumnsEqualWidth
351      * @param numColumns
352      * @return
353      */

354     public static GridLayout createSectionClientGridLayout(boolean makeColumnsEqualWidth,
355             int numColumns) {
356         GridLayout layout = new GridLayout();
357
358         layout.marginHeight = SECTION_CLIENT_MARGIN_HEIGHT;
359         layout.marginWidth = SECTION_CLIENT_MARGIN_WIDTH;
360
361         layout.marginTop = SECTION_CLIENT_MARGIN_TOP;
362         layout.marginBottom = SECTION_CLIENT_MARGIN_BOTTOM;
363         layout.marginLeft = SECTION_CLIENT_MARGIN_LEFT;
364         layout.marginRight = SECTION_CLIENT_MARGIN_RIGHT;
365
366         layout.horizontalSpacing = SECTION_CLIENT_HORIZONTAL_SPACING;
367         layout.verticalSpacing = SECTION_CLIENT_VERTICAL_SPACING;
368         
369         layout.makeColumnsEqualWidth = makeColumnsEqualWidth;
370         layout.numColumns = numColumns;
371         
372         return layout;
373     }
374     
375     /**
376      * For composites set as section clients.
377      * For composites containg form text.
378      * @param makeColumnsEqualWidth
379      * @param numColumns
380      * @return
381      */

382     public static TableWrapLayout createSectionClientTableWrapLayout(boolean makeColumnsEqualWidth,
383             int numColumns) {
384         TableWrapLayout layout = new TableWrapLayout();
385         
386         layout.topMargin = SECTION_CLIENT_MARGIN_TOP;
387         layout.bottomMargin = SECTION_CLIENT_MARGIN_BOTTOM;
388         layout.leftMargin = SECTION_CLIENT_MARGIN_LEFT;
389         layout.rightMargin = SECTION_CLIENT_MARGIN_RIGHT;
390
391         layout.horizontalSpacing = SECTION_CLIENT_HORIZONTAL_SPACING;
392         layout.verticalSpacing = SECTION_CLIENT_VERTICAL_SPACING;
393
394         layout.makeColumnsEqualWidth = makeColumnsEqualWidth;
395         layout.numColumns = numColumns;
396         
397         return layout;
398     }
399     
400     /**
401      * Debug method.
402      *
403      * MAGENTA = 11
404      * CYAN = 13
405      * GREEN = 5
406      * @param container
407      * @param color
408      */

409     public static void visualizeLayoutArea(Composite container, int color) {
410         container.setBackground(Display.getCurrent().getSystemColor(color));
411     }
412 }
413
Popular Tags