View Javadoc
1 package org.neuclear.commons.swing; 2 3 /* 4 * The NeuClear Project and it's libraries are 5 * (c) 2002-2004 Antilles Software Ventures SA 6 * For more information see: http://neuclear.org 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 */ 22 23 import com.jgoodies.forms.builder.PanelBuilder; 24 import com.jgoodies.forms.layout.CellConstraints; 25 import com.jgoodies.forms.layout.FormLayout; 26 import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; 27 28 import javax.swing.*; 29 import java.awt.*; 30 31 /*** 32 * User: pelleb 33 * Date: May 18, 2004 34 * Time: 11:55:51 AM 35 */ 36 public class SimpleProcessDialog extends ProcessDialog { 37 public SimpleProcessDialog(Frame frame) throws HeadlessException { 38 super(frame, "simple"); 39 input.addKeyListener(keyValidator); 40 input.addActionListener(okAction); 41 } 42 43 44 protected boolean validateForm() { 45 return input.getText().length() > 0; 46 } 47 48 protected Component buildPanel() { 49 FormLayout layout = new FormLayout("right:pref, 3dlu, pref:grow ", 50 "pref,5dlu:grow"); 51 PanelBuilder builder = new PanelBuilder(layout); 52 CellConstraints cc = new CellConstraints(); 53 54 builder.setDefaultDialogBorder(); 55 input = new JTextField(); 56 57 builder.addLabel("Input", cc.xy(1, 1)).setLabelFor(input); 58 builder.add(input, cc.xy(3, 1)); 59 return builder.getPanel(); 60 } 61 62 protected void initializeForm() { 63 input.requestFocus(); 64 } 65 66 public String getInput() throws UserCancellationException { 67 return (String) openAndWait(new SimpleProcessRunner()); 68 } 69 70 private JTextField input; 71 72 private class SimpleProcessRunner extends LongChildProcess { 73 74 /*** 75 * When an object implementing interface <code>Runnable</code> is used 76 * to create a thread, starting the thread causes the object's 77 * <code>run</code> method to be called in that separately executing 78 * thread. 79 * <p/> 80 * The general contract of the method <code>run</code> is that it may 81 * take any action whatsoever. 82 * 83 * @see Thread#run() 84 */ 85 public void run() { 86 try { 87 Thread.sleep(3000); 88 parent.setResult(input.getText()); 89 } catch (InterruptedException e) { 90 parent.cancel(); 91 } 92 } 93 94 } 95 96 public static void main(String args[]) { 97 SimpleProcessDialog dia = new SimpleProcessDialog(new JFrame()); 98 try { 99 System.out.println(dia.getInput()); 100 System.out.println(dia.getInput()); 101 } catch (UserCancellationException e) { 102 System.out.println("User Cancelled"); 103 } 104 System.exit(0); 105 } 106 }

This page was automatically generated by Maven