comparison java/src/uk/ac/qmul/eecs/ccmi/utils/GridBagUtilities.java @ 0:9418ab7b7f3f

Initial import
author Fiore Martin <fiore@eecs.qmul.ac.uk>
date Fri, 16 Dec 2011 17:35:51 +0000
parents
children 9e67171477bc
comparison
equal deleted inserted replaced
-1:000000000000 0:9418ab7b7f3f
1 /*
2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
3
4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package uk.ac.qmul.eecs.ccmi.utils;
21
22 import java.awt.GridBagConstraints;
23
24 /**
25 *
26 * A Utility class providing static method to quickly arrange components, laid out by
27 * a GridBagLayout, in the following way: one component per row and
28 * either taking the whole column or just the right part of it, if preceded by a label.
29 *
30 *
31 */
32 public class GridBagUtilities {
33 public GridBagUtilities(){
34 labelPad = DEFAULT_LABEL_PAD;
35 row = 0;
36 }
37
38 public GridBagConstraints label(int pad){
39 GridBagConstraints c ;
40
41 c = new GridBagConstraints();
42 c.anchor = GridBagConstraints.WEST;
43 c.gridx = 0;
44 c.gridy = row;
45 c.insets = new java.awt.Insets(PAD,PAD,PAD,pad);
46
47 return c;
48 }
49
50 public GridBagConstraints label(){
51 return label(labelPad);
52 }
53
54 public void setLabelPad(int labelPad){
55 this.labelPad = labelPad;
56 }
57
58 public GridBagConstraints field(){
59 GridBagConstraints c;
60
61 c = new GridBagConstraints();
62 c.anchor = GridBagConstraints.CENTER;
63 c.gridx = 1;
64 c.gridy = row++;
65 c.insets = new java.awt.Insets(PAD,PAD,PAD,PAD);
66 c.fill = GridBagConstraints.HORIZONTAL;
67
68 return c;
69 }
70
71 public GridBagConstraints all(){
72 GridBagConstraints c;
73
74 c = new GridBagConstraints();
75 c.gridy = row++;
76 c.anchor = GridBagConstraints.CENTER;
77 c.gridwidth = GridBagConstraints.REMAINDER;
78 c.fill = GridBagConstraints.HORIZONTAL;
79 c.insets = new java.awt.Insets(PAD,PAD,PAD,PAD);
80 return c;
81 }
82
83 private int labelPad;
84 private int row;
85 public static final int DEFAULT_LABEL_PAD = 50;
86 public static final int PAD = 2;
87 }