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