001: /*
002: * argun 1.0
003: * Web 2.0 delivery framework
004: * Copyright (C) 2007 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.biz
021: * e-Mail: support@hammurapi.biz
022: */
023: package biz.hammurapi.web.statemachine;
024:
025: import java.awt.GridBagConstraints;
026: import java.awt.GridBagLayout;
027: import java.awt.Insets;
028: import java.awt.event.ActionEvent;
029: import java.awt.event.ActionListener;
030: import java.util.Collection;
031: import java.util.Iterator;
032:
033: import javax.swing.ComboBoxModel;
034: import javax.swing.DefaultComboBoxModel;
035: import javax.swing.JButton;
036: import javax.swing.JComboBox;
037: import javax.swing.JEditorPane;
038: import javax.swing.JFrame;
039: import javax.swing.JLabel;
040: import javax.swing.JScrollPane;
041: import javax.swing.JTabbedPane;
042: import javax.swing.JTextField;
043: import javax.swing.JTextPane;
044:
045: /**
046: * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
047: * Builder, which is free for non-commercial use. If Jigloo is being used
048: * commercially (ie, by a corporation, company or business for any purpose
049: * whatever) then you should purchase a license for each developer using Jigloo.
050: * Please visit www.cloudgarden.com for details. Use of Jigloo implies
051: * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
052: * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
053: * ANY CORPORATE OR COMMERCIAL PURPOSE.
054: */
055: public class StateMachinePropertiesDialog extends javax.swing.JDialog {
056: private JButton okButton;
057:
058: private JButton cancelButton;
059:
060: private JLabel nameLabel;
061:
062: private JEditorPane descriptionEditorPane;
063:
064: private JScrollPane descriptionScrollPane;
065:
066: private JTabbedPane tabbedPanel;
067: private JLabel initialStateLabel;
068: private JComboBox jInitialStateComboBox;
069:
070: private JTextField nameField;
071:
072: private StateMachine data;
073:
074: /**
075: * Auto-generated main method to display this JDialog
076: */
077: public static void main(String[] args) {
078: JFrame frame = new JFrame();
079: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
080: StateMachinePropertiesDialog inst = new StateMachinePropertiesDialog(
081: frame, null);
082: inst.setVisible(true);
083: frame.dispose();
084: //System.exit(0);
085: }
086:
087: public StateMachinePropertiesDialog(JFrame frame, StateMachine data) {
088: super (frame);
089: this .data = data;
090: initGUI();
091: nameField.setText(data.getName());
092: //descriptionEditorPane.setEditorKit(new HTMLEditorKit());
093: descriptionEditorPane.setText(data.getDescription());
094: Collection stateNames = data.getStateNames();
095: if (stateNames.isEmpty()) {
096: jInitialStateComboBox.setEnabled(false);
097: } else {
098: Iterator it = stateNames.iterator();
099: while (it.hasNext()) {
100: jInitialStateComboBox.addItem(it.next());
101: }
102: if (data.getInitialState() != null) {
103: jInitialStateComboBox.setSelectedItem(data
104: .getInitialState());
105: }
106: }
107: }
108:
109: private void initGUI() {
110: try {
111: GridBagLayout this Layout = new GridBagLayout();
112: this Layout.rowWeights = new double[] { 0.0, 0.0, 0.1, 0.0 };
113: this Layout.rowHeights = new int[] { 32, 22, 285, 7 };
114: this Layout.columnWeights = new double[] { 0.0, 0.1, 0.0 };
115: this Layout.columnWidths = new int[] { 75, 340, 7 };
116: getContentPane().setLayout(this Layout);
117: this .setName("Properties");
118: this .setModal(true);
119: this .setTitle("Properties");
120: this .setFocusable(false);
121: {
122: nameField = new JTextField();
123: getContentPane().add(
124: nameField,
125: new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0,
126: GridBagConstraints.WEST,
127: GridBagConstraints.HORIZONTAL,
128: new Insets(0, 0, 0, 0), 0, 0));
129: nameField.setText("Task name");
130: nameField.setSize(200, 20);
131: }
132: {
133: okButton = new JButton();
134: getContentPane().add(
135: okButton,
136: new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0,
137: GridBagConstraints.EAST,
138: GridBagConstraints.NONE, new Insets(3,
139: 0, 3, 3), 0, 0));
140: okButton.setText("OK");
141: okButton.addActionListener(new ActionListener() {
142: public void actionPerformed(ActionEvent evt) {
143: okButtonActionPerformed(evt);
144: }
145: });
146: }
147: {
148: cancelButton = new JButton();
149: getContentPane().add(
150: cancelButton,
151: new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0,
152: GridBagConstraints.WEST,
153: GridBagConstraints.NONE, new Insets(3,
154: 0, 3, 3), 0, 0));
155: cancelButton.setText("Cancel");
156: cancelButton.addActionListener(new ActionListener() {
157: public void actionPerformed(ActionEvent evt) {
158: cancelButtonActionPerformed(evt);
159: }
160: });
161: }
162: {
163: tabbedPanel = new JTabbedPane();
164: getContentPane().add(
165: tabbedPanel,
166: new GridBagConstraints(0, 2, 3, 1, 0.0, 0.0,
167: GridBagConstraints.NORTHWEST,
168: GridBagConstraints.BOTH, new Insets(0,
169: 0, 0, 0), 0, 0));
170: {
171: descriptionScrollPane = new JScrollPane();
172: tabbedPanel.addTab("Description", null,
173: descriptionScrollPane, null);
174: descriptionScrollPane
175: .setPreferredSize(new java.awt.Dimension(
176: 360, 159));
177: descriptionScrollPane.setAutoscrolls(true);
178: {
179: descriptionEditorPane = new JTextPane();
180: descriptionScrollPane
181: .setViewportView(descriptionEditorPane);
182: descriptionEditorPane.setText("Description");
183: descriptionEditorPane
184: .setPreferredSize(new java.awt.Dimension(
185: 185, 74));
186: }
187: }
188: }
189: {
190: nameLabel = new JLabel();
191: getContentPane().add(
192: nameLabel,
193: new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
194: GridBagConstraints.EAST,
195: GridBagConstraints.NONE, new Insets(0,
196: 0, 0, 5), 0, 0));
197: nameLabel.setText("Name");
198: }
199: {
200: initialStateLabel = new JLabel();
201: getContentPane().add(
202: initialStateLabel,
203: new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
204: GridBagConstraints.EAST,
205: GridBagConstraints.NONE, new Insets(0,
206: 0, 0, 5), 0, 0));
207: initialStateLabel.setText("Initial state");
208: }
209: {
210: ComboBoxModel jInitialStateComboBoxModel = new DefaultComboBoxModel();
211: jInitialStateComboBox = new JComboBox();
212: getContentPane().add(
213: jInitialStateComboBox,
214: new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0,
215: GridBagConstraints.WEST,
216: GridBagConstraints.HORIZONTAL,
217: new Insets(0, 0, 0, 0), 0, 0));
218: jInitialStateComboBox
219: .setModel(jInitialStateComboBoxModel);
220: }
221: this .setSize(500, 400);
222: } catch (Exception e) {
223: e.printStackTrace();
224: }
225: }
226:
227: private void okButtonActionPerformed(ActionEvent evt) {
228: data.setName(nameField.getText());
229: data.setDescription(descriptionEditorPane.getText());
230: data.getApplet().modelChanged();
231: data.setInitialState((String) jInitialStateComboBox
232: .getSelectedItem());
233: cancelButtonActionPerformed(evt);
234: }
235:
236: private void cancelButtonActionPerformed(ActionEvent evt) {
237: setVisible(false);
238: dispose();
239: }
240: }
|