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