annotate java/src/uk/ac/qmul/eecs/ccmi/utils/GridBagUtilities.java @ 8:ea7885bd9bff tip

fixed bug : render solid line as dotted/dashed when moving the stylus from dotted/dashed to solid
author ccmi-guest
date Thu, 03 Jul 2014 16:12:20 +0100
parents d66dd5880081
children
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 public class GridBagUtilities {
fiore@0 31 public GridBagUtilities(){
fiore@0 32 labelPad = DEFAULT_LABEL_PAD;
fiore@0 33 row = 0;
fiore@0 34 }
fiore@0 35
fiore@3 36 /**
fiore@3 37 * Provides the {@code GridBagConstrains} for a label. The label is placed
fiore@3 38 * on the left
fiore@3 39 * @param pad the pad between the label and the left margin of the component containing
fiore@3 40 * it
fiore@3 41 * @return a {@code GridBagConstrains} object to pass to the {@code add} method of {@code JComponent}
fiore@3 42 */
fiore@0 43 public GridBagConstraints label(int pad){
fiore@0 44 GridBagConstraints c ;
fiore@0 45
fiore@0 46 c = new GridBagConstraints();
fiore@0 47 c.anchor = GridBagConstraints.WEST;
fiore@0 48 c.gridx = 0;
fiore@0 49 c.gridy = row;
fiore@0 50 c.insets = new java.awt.Insets(PAD,PAD,PAD,pad);
fiore@0 51
fiore@0 52 return c;
fiore@0 53 }
fiore@0 54
fiore@3 55 /**
fiore@3 56 * Equivalent to {@link #label(int)} passing as argument the value previously
fiore@3 57 * set by {@link #setLabelPad(int)} or {@link #DEFAULT_LABEL_PAD} otherwise.
fiore@5 58 *
fiore@5 59 * @return a {@code GridBagConstrains} object to pass to the {@code add} method of {@code JComponent}
fiore@3 60 */
fiore@0 61 public GridBagConstraints label(){
fiore@0 62 return label(labelPad);
fiore@0 63 }
fiore@0 64
fiore@3 65 /**
fiore@3 66 * Sets the value used by {@link #label()} as the pad between the label
fiore@3 67 * and the left margin of the component containing it
fiore@3 68 * @param labelPad the label pad
fiore@3 69 */
fiore@0 70 public void setLabelPad(int labelPad){
fiore@0 71 this.labelPad = labelPad;
fiore@0 72 }
fiore@0 73
fiore@5 74 /**
fiore@5 75 * Provides the {@code GridBagConstrains} for a component placed on the same row
fiore@5 76 * and on the right of a label.
fiore@5 77 *
fiore@5 78 * @return a {@code GridBagConstrains} object to pass to the {@code add} method of {@code JComponent}
fiore@5 79 */
fiore@0 80 public GridBagConstraints field(){
fiore@0 81 GridBagConstraints c;
fiore@0 82
fiore@0 83 c = new GridBagConstraints();
fiore@0 84 c.anchor = GridBagConstraints.CENTER;
fiore@0 85 c.gridx = 1;
fiore@0 86 c.gridy = row++;
fiore@0 87 c.insets = new java.awt.Insets(PAD,PAD,PAD,PAD);
fiore@0 88 c.fill = GridBagConstraints.HORIZONTAL;
fiore@0 89
fiore@0 90 return c;
fiore@0 91 }
fiore@0 92
fiore@5 93 /**
fiore@5 94 * Provides the {@code GridBagConstrains} for a component placed alone on a row.
fiore@5 95 *
fiore@5 96 * @return a {@code GridBagConstrains} object to pass to the {@code add} method of {@code JComponent}
fiore@5 97 */
fiore@0 98 public GridBagConstraints all(){
fiore@0 99 GridBagConstraints c;
fiore@0 100
fiore@0 101 c = new GridBagConstraints();
fiore@0 102 c.gridy = row++;
fiore@0 103 c.anchor = GridBagConstraints.CENTER;
fiore@0 104 c.gridwidth = GridBagConstraints.REMAINDER;
fiore@0 105 c.fill = GridBagConstraints.HORIZONTAL;
fiore@0 106 c.insets = new java.awt.Insets(PAD,PAD,PAD,PAD);
fiore@0 107 return c;
fiore@0 108 }
fiore@0 109
fiore@0 110 private int labelPad;
fiore@0 111 private int row;
fiore@0 112 public static final int DEFAULT_LABEL_PAD = 50;
fiore@0 113 public static final int PAD = 2;
fiore@0 114 }