1 import java.applet.Applet; 2 import java.awt.*; 3 import java.io.*; 4 import java.awt.event.*; 5 import javax.swing.*; 6 import javax.swing.event.*; 7 import java.lang.*; 8 9 class nwchem_MD_control extends JPanel { 10 11 /////////////////////////////////////////////////////////////////////// 12 // Variables that all the panels share. 13 ////////////////////////////////////////////////////////////////////// 14 Font defaultfont; 15 Font disabledfont; 16 JLabel fixlabel; 17 JLabel printlabel; 18 JLabel steplabel; 19 JLabel statlabel; 20 JLabel expectlabel; 21 JLabel controllabel; 22 JLabel loadlabel; 23 JLabel cnodeslabel; 24 JLabel mwmlabel; 25 JLabel testlabel; 26 JLabel boxeslabel; 27 JLabel extralabel; 28 JLabel msalabel; 29 JLabel debuglabel; 30 JLabel memorylabel; 31 JLabel stacklabel; 32 JLabel heaplabel; 33 JLabel globallabel; 34 JLabel limitlabel; 35 JLabel maxuplabel; 36 JLabel scalelabel; 37 JLabel calculationlabel; 38 JLabel fillerlabel; 39 40 JRadioButton resetradio; 41 JRadioButton lnoneradio; 42 JRadioButton pairsradio; 43 JRadioButton boxsizeradio; 44 JRadioButton verifyradio; 45 JRadioButton extraradio; 46 JRadioButton energyradio; 47 48 IntegerField expectfield; 49 IntegerField nodes1field; 50 IntegerField nodes2field; 51 IntegerField nodes3field; 52 IntegerField mwmfield; 53 IntegerField testfield; 54 IntegerField boxes1field; 55 IntegerField boxes2field; 56 IntegerField boxes3field; 57 IntegerField extrafield; 58 IntegerField msafield; 59 IntegerField debugfield; 60 IntegerField limitfield; 61 IntegerField maxupfield; 62 DoubleField scalefield; 63 64 private nwchem_Task task = null; 65 66 //////////////////////////////////////////////////////////////////////// 67 // Building constraints for panel with settings common between 68 // all calculations 69 /////////////////////////////////////////////////////////////////////// 70 nwchem_MD_control(nwchem_Task t)71 public nwchem_MD_control(nwchem_Task t) { 72 73 defaultfont = new Font("Dialog", Font.BOLD,12); 74 disabledfont = new Font("Dialog", Font.PLAIN,12); 75 task = t; 76 77 GridBagLayout commonlayout = new GridBagLayout(); 78 GridBagConstraints commonconstraints = new GridBagConstraints(); 79 setLayout(commonlayout); 80 81 printlabel = new JLabel("Print:"); 82 printlabel.setFont(defaultfont); 83 printlabel.setForeground(Color.black); 84 addComponent(this,printlabel,0,0,4,1,20,1, 85 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 86 87 expectlabel = new JLabel("expect:"); 88 expectlabel.setFont(defaultfont); 89 expectlabel.setForeground(Color.black); 90 addComponent(this,expectlabel,4,0,1,1,5,1, 91 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 92 93 expectfield = new IntegerField(task.prt_expect,1,5); 94 addComponent(this,expectfield,5,0,1,1,5,1, 95 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 96 expectfield.addFocusListener(new FocusListener(){ 97 public void focusLost(FocusEvent e){task.prt_expect=expectfield.getValue();}; 98 public void focusGained(FocusEvent e){} 99 }); 100 101 loadlabel = new JLabel("Load balance:"); 102 loadlabel.setFont(defaultfont); 103 loadlabel.setForeground(Color.black); 104 addComponent(this,loadlabel,0,1,2,1,10,1, 105 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 106 107 lnoneradio = new JRadioButton("none"); 108 lnoneradio.setSelected(task.load_none); 109 addComponent(this,lnoneradio,4,1,1,1,5,1, 110 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 111 lnoneradio.addActionListener(new ActionListener(){ 112 public void actionPerformed(ActionEvent e){ 113 task.load_none=lnoneradio.isSelected(); 114 enableSelections(task); 115 }}); 116 117 resetradio = new JRadioButton("reset"); 118 resetradio.setSelected(task.load_reset); 119 addComponent(this,resetradio,4,2,1,1,5,1, 120 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 121 resetradio.addActionListener(new ActionListener(){ 122 public void actionPerformed(ActionEvent e){ 123 task.load_reset=resetradio.isSelected(); 124 enableSelections(task); 125 }}); 126 127 pairsradio = new JRadioButton("pairs:"); 128 pairsradio.setSelected(task.load_pair); 129 addComponent(this,pairsradio,5,1,1,1,5,1, 130 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 131 pairsradio.addActionListener(new ActionListener(){ 132 public void actionPerformed(ActionEvent e){ 133 task.load_pair=pairsradio.isSelected(); 134 enableSelections(task); 135 }}); 136 137 boxsizeradio = new JRadioButton("boxsize"); 138 boxsizeradio.setSelected(task.load_size); 139 addComponent(this,boxsizeradio,5,2,1,1,5,1, 140 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 141 boxsizeradio.addActionListener(new ActionListener(){ 142 public void actionPerformed(ActionEvent e){ 143 task.load_size=boxsizeradio.isSelected(); 144 enableSelections(task); 145 }}); 146 147 scalelabel = new JLabel("scale:"); 148 scalelabel.setFont(defaultfont); 149 scalelabel.setForeground(Color.gray); 150 addComponent(this,scalelabel,6,2,1,1,5,1, 151 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 152 153 scalefield = new DoubleField(task.load_factor,0.75,5); 154 addComponent(this,scalefield,7,2,1,1,5,1, 155 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 156 scalefield.addFocusListener(new FocusListener(){ 157 public void focusLost(FocusEvent e){task.load_factor=scalefield.getValue();}; 158 public void focusGained(FocusEvent e){} 159 }); 160 161 maxuplabel = new JLabel("maxup:"); 162 maxuplabel.setFont(defaultfont); 163 maxuplabel.setForeground(Color.gray); 164 addComponent(this,maxuplabel,6,1,1,1,5,1, 165 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 166 167 maxupfield = new IntegerField(task.load_num_pair,5,5); 168 addComponent(this,maxupfield,7,1,1,1,5,1, 169 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 170 maxupfield.setEnabled(false); 171 maxupfield.addFocusListener(new FocusListener(){ 172 public void focusLost(FocusEvent e){task.load_num_pair=maxupfield.getValue();}; 173 public void focusGained(FocusEvent e){} 174 }); 175 176 177 controllabel = new JLabel("Decomposition:"); 178 controllabel.setFont(defaultfont); 179 controllabel.setForeground(Color.black); 180 addComponent(this,controllabel,0,3,4,1,20,1, 181 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 182 183 cnodeslabel = new JLabel("nodes:"); 184 cnodeslabel.setFont(defaultfont); 185 cnodeslabel.setForeground(Color.black); 186 addComponent(this,cnodeslabel,4,3,1,1,5,1, 187 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 188 189 nodes1field = new IntegerField(task.npx,0,5); 190 nodes2field = new IntegerField(task.npy,0,5); 191 nodes3field = new IntegerField(task.npz,0,5); 192 addComponent(this,nodes1field,5,3,1,1,5,1, 193 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 194 addComponent(this,nodes2field,6,3,1,1,5,1, 195 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 196 addComponent(this,nodes3field,7,3,1,1,5,1, 197 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 198 nodes1field.addFocusListener(new FocusListener(){ 199 public void focusLost(FocusEvent e){task.npx=nodes1field.getValue();}; 200 public void focusGained(FocusEvent e){} 201 }); 202 nodes2field.addFocusListener(new FocusListener(){ 203 public void focusLost(FocusEvent e){task.npy=nodes2field.getValue();}; 204 public void focusGained(FocusEvent e){} 205 }); 206 nodes3field.addFocusListener(new FocusListener(){ 207 public void focusLost(FocusEvent e){task.npz=nodes3field.getValue();}; 208 public void focusGained(FocusEvent e){} 209 }); 210 211 mwmlabel = new JLabel("mwm:"); 212 mwmlabel.setFont(defaultfont); 213 mwmlabel.setForeground(Color.black); 214 addComponent(this,mwmlabel,4,5,1,1,5,1, 215 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 216 217 mwmfield = new IntegerField(task.mwm,0,5); 218 addComponent(this,mwmfield,5,5,1,1,5,1, 219 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 220 mwmfield.addFocusListener(new FocusListener(){ 221 public void focusLost(FocusEvent e){task.mwm=mwmfield.getValue();}; 222 public void focusGained(FocusEvent e){} 223 }); 224 225 testlabel = new JLabel("test:"); 226 testlabel.setFont(defaultfont); 227 testlabel.setForeground(Color.red); 228 addComponent(this,testlabel,8,3,1,1,5,1, 229 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 230 231 testfield = new IntegerField(task.test,0,5); 232 addComponent(this,testfield,9,3,1,1,5,1, 233 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 234 testfield.addFocusListener(new FocusListener(){ 235 public void focusLost(FocusEvent e){task.test=testfield.getValue();}; 236 public void focusGained(FocusEvent e){} 237 }); 238 239 boxeslabel = new JLabel("boxes"); 240 boxeslabel.setFont(defaultfont); 241 boxeslabel.setForeground(Color.black); 242 addComponent(this,boxeslabel,4,4,1,1,5,1, 243 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 244 245 boxes1field = new IntegerField(task.nbx,0,5); 246 boxes2field = new IntegerField(task.nby,0,5); 247 boxes3field = new IntegerField(task.nbz,0,5); 248 addComponent(this,boxes1field,5,4,1,1,5,1, 249 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 250 addComponent(this,boxes2field,6,4,1,1,5,1, 251 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 252 addComponent(this,boxes3field,7,4,1,1,5,1, 253 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 254 boxes1field.addFocusListener(new FocusListener(){ 255 public void focusLost(FocusEvent e){task.nbx=boxes1field.getValue();}; 256 public void focusGained(FocusEvent e){} 257 }); 258 boxes2field.addFocusListener(new FocusListener(){ 259 public void focusLost(FocusEvent e){task.nby=boxes2field.getValue();}; 260 public void focusGained(FocusEvent e){} 261 }); 262 boxes3field.addFocusListener(new FocusListener(){ 263 public void focusLost(FocusEvent e){task.nbz=boxes3field.getValue();}; 264 public void focusGained(FocusEvent e){} 265 }); 266 267 msalabel = new JLabel("msa:"); 268 msalabel.setFont(defaultfont); 269 msalabel.setForeground(Color.black); 270 addComponent(this,msalabel,6,5,1,1,5,1, 271 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 272 273 msafield = new IntegerField(task.msa,0,5); 274 addComponent(this,msafield,7,5,1,1,5,1, 275 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 276 msafield.addFocusListener(new FocusListener(){ 277 public void focusLost(FocusEvent e){task.msa=msafield.getValue();}; 278 public void focusGained(FocusEvent e){} 279 }); 280 281 extralabel = new JLabel("extra"); 282 extralabel.setFont(defaultfont); 283 extralabel.setForeground(Color.red); 284 addComponent(this,extralabel,8,4,1,1,5,1, 285 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 286 287 extrafield = new IntegerField(task.mad,6,5); 288 addComponent(this,extrafield,9,4,1,1,5,1, 289 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 290 extrafield.addFocusListener(new FocusListener(){ 291 public void focusLost(FocusEvent e){task.mad=extrafield.getValue();}; 292 public void focusGained(FocusEvent e){} 293 }); 294 295 debuglabel = new JLabel("debug:"); 296 debuglabel.setFont(defaultfont); 297 debuglabel.setForeground(Color.red); 298 addComponent(this,debuglabel,8,5,1,1,5,1, 299 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 300 301 debugfield = new IntegerField(task.debug,0,5); 302 addComponent(this,debugfield,9,5,1,1,5,1, 303 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 304 debugfield.addFocusListener(new FocusListener(){ 305 public void focusLost(FocusEvent e){task.debug=debugfield.getValue();}; 306 public void focusGained(FocusEvent e){} 307 }); 308 309 memorylabel = new JLabel("Memory:"); 310 memorylabel.setFont(defaultfont); 311 memorylabel.setForeground(Color.black); 312 addComponent(this,memorylabel,0,6,4,1,20,1, 313 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 314 315 limitlabel = new JLabel("limit:"); 316 limitlabel.setFont(defaultfont); 317 limitlabel.setForeground(Color.black); 318 addComponent(this,limitlabel,4,6,1,1,5,1, 319 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 320 321 limitfield = new IntegerField(task.Limit,0,5); 322 addComponent(this,limitfield,5,6,1,1,5,1, 323 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 324 limitfield.addFocusListener(new FocusListener(){ 325 public void focusLost(FocusEvent e){task.Limit=limitfield.getValue();}; 326 public void focusGained(FocusEvent e){} 327 }); 328 329 fillerlabel = new JLabel(" "); 330 addComponent(this,fillerlabel,10,7,3,3,35,35, 331 GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER); 332 333 setVisible(true); 334 335 enableSelections(task); 336 } 337 enableSelections(nwchem_Task tsk)338 void enableSelections(nwchem_Task tsk){ 339 340 if(tsk.load_none){ 341 pairsradio.setEnabled(false); 342 boxsizeradio.setEnabled(false); 343 scalelabel.setForeground(Color.gray); 344 scalefield.setEnabled(false); 345 maxuplabel.setForeground(Color.gray); 346 maxupfield.setEnabled(false); 347 } else { 348 pairsradio.setEnabled(true); 349 boxsizeradio.setEnabled(true); 350 if(tsk.load_size){ 351 scalelabel.setForeground(Color.black); 352 scalefield.setEnabled(true); 353 if(tsk.load_pair){ 354 maxuplabel.setForeground(Color.black); 355 maxupfield.setEnabled(true); 356 }; 357 } else { 358 scalelabel.setForeground(Color.gray); 359 scalefield.setEnabled(false); 360 maxuplabel.setForeground(Color.gray); 361 maxupfield.setEnabled(false); 362 }; 363 if(tsk.load_pair){ 364 if(tsk.load_size){ 365 maxuplabel.setForeground(Color.black); 366 maxupfield.setEnabled(true); 367 }; 368 } else { 369 maxuplabel.setForeground(Color.gray); 370 maxupfield.setEnabled(false); 371 }; 372 }; 373 } 374 addComponent(Container container, Component component, int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int fill, int anchor)375 static void addComponent(Container container, Component component, 376 int gridx, int gridy, int gridwidth, 377 int gridheight, double weightx, 378 double weighty, int fill, int anchor) { 379 LayoutManager lm = container.getLayout(); 380 if(!(lm instanceof GridBagLayout)){ 381 System.out.println("Illegal layout"); System.exit(1); 382 } else { 383 GridBagConstraints gbc = new GridBagConstraints(); 384 gbc.gridx=gridx; 385 gbc.gridy=gridy; 386 gbc.gridwidth=gridwidth; 387 gbc.gridheight=gridheight; 388 gbc.weightx=weightx; 389 gbc.weighty=weighty; 390 gbc.fill=fill; 391 gbc.anchor=anchor; 392 container.add(component,gbc); 393 } 394 } 395 396 } 397