Mercurial > hg > ccmieditor
view 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 |
line wrap: on
line source
/* CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package uk.ac.qmul.eecs.ccmi.utils; import java.awt.GridBagConstraints; /** * * A Utility class providing static method to quickly arrange components, laid out by * a GridBagLayout, in the following way: one component per row and * either taking the whole column or just the right part of it, if preceded by a label. * * */ public class GridBagUtilities { public GridBagUtilities(){ labelPad = DEFAULT_LABEL_PAD; row = 0; } public GridBagConstraints label(int pad){ GridBagConstraints c ; c = new GridBagConstraints(); c.anchor = GridBagConstraints.WEST; c.gridx = 0; c.gridy = row; c.insets = new java.awt.Insets(PAD,PAD,PAD,pad); return c; } public GridBagConstraints label(){ return label(labelPad); } public void setLabelPad(int labelPad){ this.labelPad = labelPad; } public GridBagConstraints field(){ GridBagConstraints c; c = new GridBagConstraints(); c.anchor = GridBagConstraints.CENTER; c.gridx = 1; c.gridy = row++; c.insets = new java.awt.Insets(PAD,PAD,PAD,PAD); c.fill = GridBagConstraints.HORIZONTAL; return c; } public GridBagConstraints all(){ GridBagConstraints c; c = new GridBagConstraints(); c.gridy = row++; c.anchor = GridBagConstraints.CENTER; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; c.insets = new java.awt.Insets(PAD,PAD,PAD,PAD); return c; } private int labelPad; private int row; public static final int DEFAULT_LABEL_PAD = 50; public static final int PAD = 2; }