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:
031: import javax.swing.JButton;
032: import javax.swing.JEditorPane;
033: import javax.swing.JFrame;
034: import javax.swing.JLabel;
035: import javax.swing.JOptionPane;
036: import javax.swing.JScrollPane;
037: import javax.swing.JTabbedPane;
038: import javax.swing.JTextArea;
039: import javax.swing.JTextField;
040: import javax.swing.JTextPane;
041:
042: /**
043: * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
044: * Builder, which is free for non-commercial use. If Jigloo is being used
045: * commercially (ie, by a corporation, company or business for any purpose
046: * whatever) then you should purchase a license for each developer using Jigloo.
047: * Please visit www.cloudgarden.com for details. Use of Jigloo implies
048: * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
049: * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
050: * ANY CORPORATE OR COMMERCIAL PURPOSE.
051: */
052: public class StatePropertiesDialog extends javax.swing.JDialog {
053: private JButton okButton;
054:
055: private JButton cancelButton;
056:
057: private JTextArea actionTextArea;
058:
059: private JScrollPane actionScrollPane;
060:
061: private JLabel nameLabel;
062:
063: private JEditorPane descriptionEditorPane;
064:
065: private JScrollPane descriptionScrollPane;
066:
067: private JTabbedPane tabbedPanel;
068:
069: private JTextField nameField;
070:
071: private State data;
072:
073: /**
074: * Auto-generated main method to display this JDialog
075: */
076: public static void main(String[] args) {
077: JFrame frame = new JFrame();
078: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
079: StatePropertiesDialog inst = new StatePropertiesDialog(frame,
080: null);
081: inst.setVisible(true);
082: frame.dispose();
083: //System.exit(0);
084: }
085:
086: public StatePropertiesDialog(JFrame frame, State data) {
087: super (frame);
088: this .data = data;
089: initGUI();
090: nameField.setText(data.getName());
091: descriptionEditorPane.setText(data.getDescription());
092: actionTextArea.setText(data.getAction());
093: }
094:
095: private void initGUI() {
096: try {
097: GridBagLayout this Layout = new GridBagLayout();
098: this Layout.rowWeights = new double[] { 0.0, 0.1, 0.0 };
099: this Layout.rowHeights = new int[] { 32, 303, 7 };
100: this Layout.columnWeights = new double[] { 0.0, 0.1, 0.0 };
101: this Layout.columnWidths = new int[] { 45, 354, 7 };
102: getContentPane().setLayout(this Layout);
103: this .setName("Properties");
104: this .setModal(true);
105: this .setTitle("Properties");
106: {
107: nameField = new JTextField();
108: getContentPane().add(
109: nameField,
110: new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0,
111: GridBagConstraints.WEST,
112: GridBagConstraints.HORIZONTAL,
113: new Insets(0, 0, 0, 0), 0, 0));
114: nameField.setText("State name");
115: nameField.setSize(200, 20);
116: }
117: {
118: okButton = new JButton();
119: getContentPane().add(
120: okButton,
121: new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
122: GridBagConstraints.EAST,
123: GridBagConstraints.NONE, new Insets(3,
124: 0, 3, 3), 0, 0));
125: okButton.setText("OK");
126: okButton.addActionListener(new ActionListener() {
127: public void actionPerformed(ActionEvent evt) {
128: okButtonActionPerformed(evt);
129: }
130: });
131: }
132: {
133: cancelButton = new JButton();
134: getContentPane().add(
135: cancelButton,
136: new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0,
137: GridBagConstraints.WEST,
138: GridBagConstraints.NONE, new Insets(3,
139: 0, 3, 3), 0, 0));
140: cancelButton.setText("Cancel");
141: cancelButton.addActionListener(new ActionListener() {
142: public void actionPerformed(ActionEvent evt) {
143: cancelButtonActionPerformed(evt);
144: }
145: });
146: }
147: {
148: tabbedPanel = new JTabbedPane();
149: getContentPane().add(
150: tabbedPanel,
151: new GridBagConstraints(0, 1, 3, 1, 0.0, 0.0,
152: GridBagConstraints.NORTHWEST,
153: GridBagConstraints.BOTH, new Insets(0,
154: 0, 0, 0), 0, 0));
155: {
156: descriptionScrollPane = new JScrollPane();
157: tabbedPanel.addTab("Description", null,
158: descriptionScrollPane, null);
159: descriptionScrollPane
160: .setPreferredSize(new java.awt.Dimension(
161: 360, 159));
162: descriptionScrollPane.setAutoscrolls(true);
163: {
164: descriptionEditorPane = new JTextPane();
165: descriptionScrollPane
166: .setViewportView(descriptionEditorPane);
167: descriptionEditorPane.setText("Description");
168: descriptionEditorPane
169: .setPreferredSize(new java.awt.Dimension(
170: 185, 74));
171: }
172: }
173: {
174: actionScrollPane = new JScrollPane();
175: tabbedPanel.addTab("Action", null,
176: actionScrollPane, null);
177: {
178: actionTextArea = new JTextArea();
179: actionScrollPane
180: .setViewportView(actionTextArea);
181: actionTextArea
182: .setText("// Put action code here");
183: actionTextArea.setFont(new java.awt.Font(
184: "Courier New", 0, 11));
185: actionTextArea.setTabSize(4);
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.CENTER,
195: GridBagConstraints.NONE, new Insets(0,
196: 0, 0, 5), 0, 0));
197: nameLabel.setText("Name");
198: }
199: this .setSize(500, 400);
200: } catch (Exception e) {
201: e.printStackTrace();
202: }
203: }
204:
205: public static boolean compareStrings(String str1, String str2) {
206: if (str1 == str2) {
207: return true;
208: }
209: if (str1 == null || str1.trim().length() == 0) {
210: return str2 == null || str2.trim().length() == 0;
211: }
212:
213: return str1.equals(str2);
214: }
215:
216: private void okButtonActionPerformed(ActionEvent evt) {
217: if (data instanceof State) {
218: if (nameField.getText() == null
219: || nameField.getText().trim().length() == 0) {
220: JOptionPane.showMessageDialog(this ,
221: "State name shall not be blank");
222: return;
223: } else if (!compareStrings(nameField.getText(), data
224: .getName())
225: && data.getStateMachine().checkDuplicateStateName(
226: nameField.getText())) {
227:
228: JOptionPane.showMessageDialog(this ,
229: "Duplicate state name");
230: return;
231: }
232: }
233:
234: data.setName(nameField.getText());
235: data.setDescription(descriptionEditorPane.getText());
236: data.setAction(actionTextArea.getText());
237: data.getStateMachine().getApplet().modelChanged();
238: cancelButtonActionPerformed(evt);
239: }
240:
241: private void cancelButtonActionPerformed(ActionEvent evt) {
242: setVisible(false);
243: dispose();
244: }
245: }
|