View Javadoc
1 package org.neuclear.commons.swing; 2 3 import com.jgoodies.forms.builder.PanelBuilder; 4 import com.jgoodies.forms.layout.CellConstraints; 5 import com.jgoodies.forms.layout.FormLayout; 6 import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; 7 8 import javax.swing.*; 9 import java.awt.*; 10 11 /* 12 * The NeuClear Project and it's libraries are 13 * (c) 2002-2004 Antilles Software Ventures SA 14 * For more information see: http://neuclear.org 15 * 16 * This library is free software; you can redistribute it and/or 17 * modify it under the terms of the GNU Lesser General Public 18 * License as published by the Free Software Foundation; either 19 * version 2.1 of the License, or (at your option) any later version. 20 * 21 * This library is distributed in the hope that it will be useful, 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 * Lesser General Public License for more details. 25 * 26 * You should have received a copy of the GNU Lesser General Public 27 * License along with this library; if not, write to the Free Software 28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 29 */ 30 31 /*** 32 * User: pelleb 33 * Date: May 18, 2004 34 * Time: 11:55:51 AM 35 */ 36 public class SimpleDialog extends NeuClearDialog { 37 public SimpleDialog(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 SimpleDialogRunner(this)); 68 } 69 70 private JTextField input; 71 72 private class SimpleDialogRunner extends AbstractDialogRunner { 73 public SimpleDialogRunner(NeuClearDialog dia) { 74 super(dia); 75 } 76 77 public void execute() { 78 setResult(input.getText()); 79 } 80 81 } 82 83 public static void main(String args[]) { 84 SimpleDialog dia = new SimpleDialog(new JFrame()); 85 try { 86 System.out.println(dia.getInput()); 87 } catch (UserCancellationException e) { 88 System.out.println("User Cancelled"); 89 } 90 System.exit(0); 91 } 92 }

This page was automatically generated by Maven