annotate java/src/uk/ac/qmul/eecs/ccmi/utils/GridBagUtilities.java @ 4:2c67ac862920

bug fix (correct haptic painting after renaming nodes and after nodes deletion with an edge with more than 2 nodes)
author Fiore Martin <fiore@eecs.qmul.ac.uk>
date Tue, 29 May 2012 15:32:19 +0100
parents 9e67171477bc
children d66dd5880081
rev   line source
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@3 38 /**
fiore@3 39 * Provides the {@code GridBagConstrains} for a label. The label is placed
fiore@3 40 * on the left
fiore@3 41 * @param pad the pad between the label and the left margin of the component containing
fiore@3 42 * it
fiore@3 43 * @return a {@code GridBagConstrains} object to pass to the {@code add} method of {@code JComponent}
fiore@3 44 */
fiore@0 45 public GridBagConstraints label(int pad){
fiore@0 46 GridBagConstraints c ;
fiore@0 47
fiore@0 48 c = new GridBagConstraints();
fiore@0 49 c.anchor = GridBagConstraints.WEST;
fiore@0 50 c.gridx = 0;
fiore@0 51 c.gridy = row;
fiore@0 52 c.insets = new java.awt.Insets(PAD,PAD,PAD,pad);
fiore@0 53
fiore@0 54 return c;
fiore@0 55 }
fiore@0 56
fiore@3 57 /**
fiore@3 58 * Equivalent to {@link #label(int)} passing as argument the value previously
fiore@3 59 * set by {@link #setLabelPad(int)} or {@link #DEFAULT_LABEL_PAD} otherwise.
fiore@3 60 * @return
fiore@3 61 */
fiore@0 62 public GridBagConstraints label(){
fiore@0 63 return label(labelPad);
fiore@0 64 }
fiore@0 65
fiore@3 66 /**
fiore@3 67 * Sets the value used by {@link #label()} as the pad between the label
fiore@3 68 * and the left margin of the component containing it
fiore@3 69 * @param labelPad the label pad
fiore@3 70 */
fiore@0 71 public void setLabelPad(int labelPad){
fiore@0 72 this.labelPad = labelPad;
fiore@0 73 }
fiore@0 74
fiore@0 75 public GridBagConstraints field(){
fiore@0 76 GridBagConstraints c;
fiore@0 77
fiore@0 78 c = new GridBagConstraints();
fiore@0 79 c.anchor = GridBagConstraints.CENTER;
fiore@0 80 c.gridx = 1;
fiore@0 81 c.gridy = row++;
fiore@0 82 c.insets = new java.awt.Insets(PAD,PAD,PAD,PAD);
fiore@0 83 c.fill = GridBagConstraints.HORIZONTAL;
fiore@0 84
fiore@0 85 return c;
fiore@0 86 }
fiore@0 87
fiore@0 88 public GridBagConstraints all(){
fiore@0 89 GridBagConstraints c;
fiore@0 90
fiore@0 91 c = new GridBagConstraints();
fiore@0 92 c.gridy = row++;
fiore@0 93 c.anchor = GridBagConstraints.CENTER;
fiore@0 94 c.gridwidth = GridBagConstraints.REMAINDER;
fiore@0 95 c.fill = GridBagConstraints.HORIZONTAL;
fiore@0 96 c.insets = new java.awt.Insets(PAD,PAD,PAD,PAD);
fiore@0 97 return c;
fiore@0 98 }
fiore@0 99
fiore@0 100 private int labelPad;
fiore@0 101 private int row;
fiore@0 102 public static final int DEFAULT_LABEL_PAD = 50;
fiore@0 103 public static final int PAD = 2;
fiore@0 104 }