001: /*
002: * Copyright (c) 1998-2002 Carnegie Mellon University. All rights
003: * reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * 1. Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * 2. Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in
014: * the documentation and/or other materials provided with the
015: * distribution.
016: *
017: * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
018: * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
019: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
020: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
021: * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
022: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
023: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
024: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
025: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
026: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
027: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: */
030:
031: package rcm.awt;
032:
033: import java.awt.*;
034:
035: public abstract class Constrain {
036:
037: public static void add(Container container, Component comp,
038: Object constraints) {
039: container.add(comp);
040: GridBagLayout layout = (GridBagLayout) container.getLayout();
041: GridBagConstraints c = (GridBagConstraints) constraints;
042: layout.setConstraints(comp, c);
043: }
044:
045: public static GridBagConstraints labelLike(int x, int y) {
046: GridBagConstraints c = new GridBagConstraints();
047: c.gridx = x;
048: c.gridy = y;
049: c.weightx = 0;
050: c.weighty = 0;
051: c.anchor = GridBagConstraints.NORTHWEST;
052: c.fill = GridBagConstraints.NONE;
053: return c;
054: }
055:
056: public static GridBagConstraints labelLike(int x, int y, int w) {
057: GridBagConstraints c = labelLike(x, y);
058: c.gridwidth = w;
059: return c;
060: }
061:
062: public static GridBagConstraints fieldLike(int x, int y) {
063: GridBagConstraints c = new GridBagConstraints();
064: c.gridx = x;
065: c.gridy = y;
066: c.weightx = 1.0;
067: c.weighty = 0.0;
068: c.anchor = GridBagConstraints.NORTHWEST;
069: c.fill = GridBagConstraints.HORIZONTAL;
070: return c;
071: }
072:
073: public static GridBagConstraints fieldLike(int x, int y, int w) {
074: GridBagConstraints c = fieldLike(x, y);
075: c.gridwidth = w;
076: return c;
077: }
078:
079: public static GridBagConstraints areaLike(int x, int y) {
080: GridBagConstraints c = new GridBagConstraints();
081: c.gridx = x;
082: c.gridy = y;
083: c.weightx = 1.0;
084: c.weighty = 1.0;
085: c.anchor = GridBagConstraints.NORTHWEST;
086: c.fill = GridBagConstraints.BOTH;
087: return c;
088: }
089:
090: public static GridBagConstraints areaLike(int x, int y, int w) {
091: GridBagConstraints c = areaLike(x, y);
092: c.gridwidth = w;
093: return c;
094: }
095:
096: public static GridBagConstraints rightJustify(GridBagConstraints c) {
097: c.anchor = GridBagConstraints.NORTHEAST;
098: return c;
099: }
100:
101: public static GridBagConstraints centered(GridBagConstraints c) {
102: c.anchor = GridBagConstraints.CENTER;
103: return c;
104: }
105:
106: public static GridBagConstraints anchor(GridBagConstraints c,
107: int anchor) {
108: c.anchor = anchor;
109: return c;
110: }
111:
112: public static Panel makeConstrainedPanel() {
113: Panel panel = new Panel();
114: panel.setLayout(new GridBagLayout());
115: return panel;
116: }
117:
118: public static Panel makeConstrainedPanel(int w, int h) {
119: Panel panel = makeConstrainedPanel();
120:
121: GridBagConstraints c = new GridBagConstraints();
122: c.gridx = 0;
123: c.gridy = h;
124: c.gridwidth = w;
125: c.weightx = 1.0;
126: c.weighty = 0.0;
127: c.anchor = GridBagConstraints.NORTHWEST;
128: c.fill = GridBagConstraints.VERTICAL;
129: add(panel, new Panel(), c);
130:
131: c = new GridBagConstraints();
132: c.gridx = w;
133: c.gridy = 0;
134: c.gridheight = h;
135: c.weightx = 0.0;
136: c.weighty = 1.0;
137: c.anchor = GridBagConstraints.NORTHWEST;
138: c.fill = GridBagConstraints.HORIZONTAL;
139: add(panel, new Panel(), c);
140:
141: return panel;
142: }
143:
144: }
|