001: /*--
002:
003: Copyright (C) 2002 Anthony Eden.
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: 1. Redistributions of source code must retain the above copyright
011: notice, this list of conditions, and the following disclaimer.
012:
013: 2. Redistributions in binary form must reproduce the above copyright
014: notice, this list of conditions, and the disclaimer that follows
015: these conditions in the documentation and/or other materials
016: provided with the distribution.
017:
018: 3. The names "OBE" and "Open Business Engine" must not be used to
019: endorse or promote products derived from this software without prior
020: written permission. For written permission, please contact
021: me@anthonyeden.com.
022:
023: 4. Products derived from this software may not be called "OBE" or
024: "Open Business Engine", nor may "OBE" or "Open Business Engine"
025: appear in their name, without prior written permission from
026: Anthony Eden (me@anthonyeden.com).
027:
028: In addition, I request (but do not require) that you include in the
029: end-user documentation provided with the redistribution and/or in the
030: software itself an acknowledgement equivalent to the following:
031: "This product includes software developed by
032: Anthony Eden (http://www.anthonyeden.com/)."
033:
034: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
038: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
039: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
040: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
041: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
042: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
043: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
044: POSSIBILITY OF SUCH DAMAGE.
045:
046: For more information on OBE, please see <http://obe.sourceforge.net/>.
047:
048: */
049:
050: package org.obe.designer.panel;
051:
052: import java.awt.Insets;
053: import java.awt.GridBagLayout;
054: import java.awt.GridBagConstraints;
055: import java.net.URL;
056: import java.net.MalformedURLException;
057:
058: import javax.swing.JPanel;
059: import javax.swing.JLabel;
060: import javax.swing.JTextField;
061: import javax.swing.BorderFactory;
062:
063: import org.obe.xpdl.model.pkg.PackageHeader;
064: import org.obe.xpdl.model.pkg.PackageHeader;
065: import org.obe.designer.util.Constants;
066:
067: public class PackageHeaderPanel extends JPanel {
068:
069: private PackageHeader packageHeader;
070:
071: private JLabel documentationLabel;
072: private JTextField documentationField;
073: private JLabel priorityLabel;
074: private JTextField priorityField;
075: private JLabel costLabel;
076: private JTextField costField;
077:
078: public PackageHeaderPanel() {
079: init();
080: packageHeader = new PackageHeader();
081: revert();
082: }
083:
084: public PackageHeader getPackageHeader() {
085: return packageHeader;
086: }
087:
088: public void setPackageHeader(PackageHeader packageHeader) {
089: this .packageHeader = packageHeader;
090: revert();
091: }
092:
093: public boolean save() {
094: try {
095: packageHeader.setDocumentation(new URL(documentationField
096: .getText()));
097: } catch (MalformedURLException e) {
098: return false;
099: }
100:
101: packageHeader.setPriorityUnit(priorityField.getText());
102: packageHeader.setCostUnit(costField.getText());
103:
104: return true;
105: }
106:
107: public void revert() {
108: URL documentation = packageHeader.getDocumentation();
109: if (documentation != null) {
110: documentationField.setText(documentation.toString());
111: }
112:
113: priorityField.setText(packageHeader.getPriorityUnit());
114: costField.setText(packageHeader.getCostUnit());
115: }
116:
117: private void init() {
118: GridBagLayout gbl = new GridBagLayout();
119: GridBagConstraints gbc = new GridBagConstraints();
120: setLayout(gbl);
121:
122: gbc.insets = new Insets(2, 2, 2, 2);
123: gbc.anchor = GridBagConstraints.WEST;
124: gbc.fill = GridBagConstraints.HORIZONTAL;
125:
126: documentationLabel = new JLabel("Documentation");
127: gbc.weightx = 0;
128: gbc.gridwidth = 1;
129: gbl.setConstraints(documentationLabel, gbc);
130: add(documentationLabel);
131:
132: documentationField = new JTextField();
133: documentationField.setColumns(Constants.DEFAULT_COLUMNS);
134: gbc.weightx = 1;
135: gbc.gridwidth = GridBagConstraints.REMAINDER;
136: gbl.setConstraints(documentationField, gbc);
137: add(documentationField);
138:
139: priorityLabel = new JLabel("Priority");
140: gbc.weightx = 0;
141: gbc.gridwidth = 1;
142: gbl.setConstraints(priorityLabel, gbc);
143: add(priorityLabel);
144:
145: priorityField = new JTextField();
146: gbc.weightx = 1;
147: gbc.gridwidth = GridBagConstraints.REMAINDER;
148: gbl.setConstraints(priorityField, gbc);
149: add(priorityField);
150:
151: costLabel = new JLabel("Cost");
152: gbc.weightx = 0;
153: gbc.gridwidth = 1;
154: gbl.setConstraints(costLabel, gbc);
155: add(costLabel);
156:
157: costField = new JTextField();
158: gbc.weightx = 1;
159: gbc.gridwidth = GridBagConstraints.REMAINDER;
160: gbl.setConstraints(costField, gbc);
161: add(costField);
162:
163: /*
164: JPanel p = new JPanel();
165: gbc.weighty = 1;
166: gbl.setConstraints(p, gbc);
167: add(p);
168: */
169: }
170:
171: }
|