KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > corbaclient > NTVDPanel


1 package org.enhydra.shark.corbaclient;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import java.util.*;
6
7 import javax.swing.*;
8
9 import org.omg.WfBase.*;
10 import org.omg.CORBA.*;
11
12 /**
13  * Used to show one workflow variable and edit it.
14  *
15  * @author Sasa Bojanic
16  * @version 1.0
17  */

18 public class NTVDPanel extends ActionPanel {
19
20    private static Dimension labelFieldDimension=new Dimension(250,20);
21    private static Dimension textFieldDimension=new Dimension(250,20);
22    private static Dimension buttonFieldDimension=new Dimension(50,25);
23
24    private NameValue nameValue;
25    private String JavaDoc varName;
26
27    private JLabel name=new JLabel();
28    private JLabel type=new JLabel();
29    private JTextField value;
30    private JComboBox choices;
31    private JTextField vDay;
32    private JTextField vMonth;
33    private JTextField vYear;
34    private JTextField vHour;
35    private JTextField vMinute;
36    private JTextField vSecond;
37    private JButton description;
38
39    private String JavaDoc typeKey;
40    private String JavaDoc desc;
41    private boolean isReadOnly;
42
43    public NTVDPanel(NameValue nv,String JavaDoc nm,String JavaDoc d,String JavaDoc typeKey,boolean isReadOnly) {
44       super();
45       this.nameValue=nv;
46       this.varName=nm;
47       this.desc=d;
48       this.typeKey=typeKey;
49       this.isReadOnly=isReadOnly;
50       super.init();
51    }
52
53    protected void createActions () {}
54
55    protected Component createCenterComponent () {
56       JPanel p=new JPanel();
57       p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS));
58       p.add(Box.createHorizontalStrut(5));
59       p.add(Box.createHorizontalGlue());
60       if (varName!=null && varName.trim().length()>0) {
61          name.setText(varName);
62       } else {
63          name.setText(nameValue.the_name);
64       }
65       name.setMinimumSize(new Dimension(labelFieldDimension));
66       name.setPreferredSize(new Dimension(labelFieldDimension));
67       name.setMaximumSize(new Dimension(labelFieldDimension));
68       p.add(name);
69       p.add(Box.createHorizontalStrut(5));
70
71       type.setText(ResourceManager.getLanguageDependentString(typeKey));
72       type.setMinimumSize(new Dimension(labelFieldDimension));
73       type.setPreferredSize(new Dimension(labelFieldDimension));
74       type.setMaximumSize(new Dimension(labelFieldDimension));
75       p.add(type);
76       p.add(Box.createHorizontalStrut(5));
77
78       java.lang.Object JavaDoc val="";
79       try {
80          val=WorkflowUtilities.exstractValueOfAnyObject(nameValue.the_value,typeKey);
81       } catch (Exception JavaDoc ex) {}
82
83       //System.out.println("Type="+typeKey);
84
if (typeKey.equals(WorkflowUtilities.UNKNOWN_KEY)) {
85          value=new JTextField();
86          value.setText(ResourceManager.getLanguageDependentString(
87                           WorkflowUtilities.UNKNOWN_KEY));
88          value.setEnabled(false);
89          value.setMinimumSize(new Dimension(textFieldDimension));
90          value.setPreferredSize(new Dimension(textFieldDimension));
91          value.setMaximumSize(new Dimension(textFieldDimension));
92          //value.setEnabled(!isReadOnly);
93
p.add(value);
94       } else if (typeKey.equals(WorkflowUtilities.BOOLEAN_KEY)) {
95          Vector vChc=new Vector();
96          vChc.add("true");
97          vChc.add("false");
98          choices=new JComboBox(vChc);
99          choices.setSelectedItem(val.toString());
100          choices.setMinimumSize(new Dimension(textFieldDimension));
101          choices.setPreferredSize(new Dimension(textFieldDimension));
102          choices.setMaximumSize(new Dimension(textFieldDimension));
103          choices.setEnabled(!isReadOnly);
104          p.add(choices);
105       } else {
106          if (val!=null && val instanceof Date) {
107             vDay=new JTextField();
108             vMonth=new JTextField();
109             vYear=new JTextField();
110             vHour=new JTextField();
111             vMinute=new JTextField();
112             vSecond=new JTextField();
113             Date dte=(Date)val;
114             Calendar c=Calendar.getInstance();
115             c.setTime(dte);
116
117             vYear.setText(String.valueOf(c.get(Calendar.YEAR)));
118             vMonth.setText(String.valueOf(c.get(Calendar.MONTH)+1));
119             vDay.setText(String.valueOf(c.get(Calendar.DAY_OF_MONTH)));
120             vHour.setText(String.valueOf(c.get(Calendar.HOUR_OF_DAY)));
121             vMinute.setText(String.valueOf(c.get(Calendar.MINUTE)));
122             vSecond.setText(String.valueOf(c.get(Calendar.SECOND)));
123             vYear.setMinimumSize(new Dimension((int)(2*(textFieldDimension.width-10)/8),textFieldDimension.height));
124             vYear.setPreferredSize(new Dimension((int)(2*(textFieldDimension.width-10)/8),textFieldDimension.height));
125             vYear.setMaximumSize(new Dimension((int)(2*(textFieldDimension.width-10)/8),textFieldDimension.height));
126             vYear.setEnabled(!isReadOnly);
127             vMonth.setMinimumSize(new Dimension((int)(1*(textFieldDimension.width-10)/8),textFieldDimension.height));
128             vMonth.setPreferredSize(new Dimension((int)(1*(textFieldDimension.width-10)/8),textFieldDimension.height));
129             vMonth.setMaximumSize(new Dimension((int)(1*(textFieldDimension.width-10)/8),textFieldDimension.height));
130             vMonth.setEnabled(!isReadOnly);
131             vDay.setMinimumSize(new Dimension((int)(1*(textFieldDimension.width-10)/8),textFieldDimension.height));
132             vDay.setPreferredSize(new Dimension((int)(1*(textFieldDimension.width-10)/8),textFieldDimension.height));
133             vDay.setMaximumSize(new Dimension((int)(1*(textFieldDimension.width-10)/8),textFieldDimension.height));
134             vDay.setEnabled(!isReadOnly);
135             vHour.setMinimumSize(new Dimension((int)(1*(textFieldDimension.width-10)/8),textFieldDimension.height));
136             vHour.setPreferredSize(new Dimension((int)(1*(textFieldDimension.width-10)/8),textFieldDimension.height));
137             vHour.setMaximumSize(new Dimension((int)(1*(textFieldDimension.width-10)/8),textFieldDimension.height));
138             vHour.setEnabled(!isReadOnly);
139             vMinute.setMinimumSize(new Dimension((int)(1*(textFieldDimension.width-10)/8),textFieldDimension.height));
140             vMinute.setPreferredSize(new Dimension((int)(1*(textFieldDimension.width-10)/8),textFieldDimension.height));
141             vMinute.setMaximumSize(new Dimension((int)(1*(textFieldDimension.width-10)/8),textFieldDimension.height));
142             vMinute.setEnabled(!isReadOnly);
143             vSecond.setMinimumSize(new Dimension((int)(1*(textFieldDimension.width-10)/8),textFieldDimension.height));
144             vSecond.setPreferredSize(new Dimension((int)(1*(textFieldDimension.width-10)/8),textFieldDimension.height));
145             vSecond.setMaximumSize(new Dimension((int)(1*(textFieldDimension.width-10)/8),textFieldDimension.height));
146             vSecond.setEnabled(!isReadOnly);
147
148             int ss=2;
149             p.add(vYear);
150             p.add(Box.createHorizontalStrut(ss));
151             p.add(new JLabel("-"));
152             p.add(Box.createHorizontalStrut(ss));
153             p.add(vMonth);
154             p.add(Box.createHorizontalStrut(ss));
155             p.add(new JLabel("-"));
156             p.add(Box.createHorizontalStrut(ss));
157             p.add(vDay);
158             p.add(Box.createHorizontalStrut(10));
159             p.add(vHour);
160             p.add(Box.createHorizontalStrut(ss));
161             p.add(new JLabel(":"));
162             p.add(Box.createHorizontalStrut(ss));
163             p.add(vMinute);
164             p.add(Box.createHorizontalStrut(ss));
165             p.add(new JLabel(":"));
166             p.add(Box.createHorizontalStrut(ss));
167             p.add(vSecond);
168          } else {
169             value=new JTextField();
170             if (val==null) {
171                value.setText("");
172             } else {
173                value.setText(val.toString());
174             }
175             value.setMinimumSize(new Dimension(textFieldDimension));
176             value.setPreferredSize(new Dimension(textFieldDimension));
177             value.setMaximumSize(new Dimension(textFieldDimension));
178             value.setEnabled(!isReadOnly);
179             p.add(value);
180          }
181       }
182       p.add(Box.createHorizontalStrut(5));
183
184       description=(JButton)BarFactory.
185          createButton("VariableDescription",null,false);
186       description.setMinimumSize(new Dimension(buttonFieldDimension));
187       description.setPreferredSize(new Dimension(buttonFieldDimension));
188       description.setMaximumSize(new Dimension(buttonFieldDimension));
189       description.addActionListener(new ActionListener () {
190                public void actionPerformed (ActionEvent ae) {
191                   String JavaDoc dk=ResourceManager.getLanguageDependentString("DescriptionKey");
192                   ItemView iv=new ItemView(getWindow(),
193                                            dk+" - "+((varName==null || varName.trim().length()==0)?nameValue.the_name:varName),dk,desc);
194                   iv.showDialog();
195                }
196             });
197       description.setEnabled(true);
198       p.add(description);
199       p.add(Box.createHorizontalStrut(5));
200       return p;
201    }
202
203    public void requestFocus() {
204       super.requestFocus();
205       if (value!=null) {
206          value.requestFocus();
207       } else if (choices!=null) {
208          choices.requestFocus();
209       }
210    }
211
212    public boolean updateField () {
213       boolean updated=false;
214       if (isReadOnly) return false;
215       if (value!=null) {
216          Any a=WorkflowUtilities.insertValueIntoAnyObject(
217             nameValue.the_value,value.getText(),typeKey);
218          if (a!=null) {
219             updated=true;
220             nameValue.the_value=a;
221          }
222       } else if (choices!=null) {
223          Any a=WorkflowUtilities.insertValueIntoAnyObject(
224             nameValue.the_value,choices.getSelectedItem().toString(),typeKey);
225          if (a!=null) {
226             updated=true;
227             nameValue.the_value=a;
228          }
229       } else if (vYear!=null) {
230          String JavaDoc dte=vYear.getText()+"-"+vMonth.getText()+"-"+vDay.getText()+" "+vHour.getText()+":"+vMinute.getText()+":"+vSecond.getText();
231          Any a=WorkflowUtilities.insertValueIntoAnyObject(
232             nameValue.the_value,dte,typeKey);
233          if (a!=null) {
234             updated=true;
235             nameValue.the_value=a;
236          }
237       }
238       return (updated || typeKey.equals(WorkflowUtilities.UNKNOWN_KEY));
239    }
240
241    public String JavaDoc getTypeKey () {
242       return typeKey;
243    }
244
245    public boolean isReadOnly () {
246       return isReadOnly;
247    }
248
249 }
250
251
Popular Tags