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.ButtonBarBuilder; 24 import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; 25 import org.neuclear.commons.crypto.passphraseagents.icons.IconTools; 26 import org.neuclear.commons.crypto.passphraseagents.swing.MessageLabel; 27 28 import javax.swing.*; 29 import java.awt.*; 30 import java.awt.event.*; 31 32 /*** 33 * User: pelleb 34 * Date: May 14, 2004 35 * Time: 12:11:53 PM 36 */ 37 public abstract class NeuClearDialog extends JDialog { 38 public NeuClearDialog(Frame frame, final String name) { 39 this(frame, name, IconTools.getOK()); 40 } 41 42 public NeuClearDialog(Frame frame, final String id, Icon okIcon) throws HeadlessException { 43 super(frame, true); 44 this.id = id; 45 SwingTools.setLAF(); 46 setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); 47 setTitle(Messages.getTitle(id)); 48 ok = new JButton(Messages.getOK(id)); 49 ok.setToolTipText(Messages.getOKToolTip(id)); 50 ok.setIcon(okIcon); 51 ok.setEnabled(false); 52 cancel = new JButton(Messages.getText("cancel")); 53 cancel.setIcon(IconTools.getCancel()); 54 message = new MessageLabel(); 55 banner = new com.l2fprod.common.swing.BannerPanel(); 56 banner.setIcon(IconTools.getLogo()); 57 banner.setTitle(Messages.getTitle(id)); 58 banner.setSubtitle(Messages.getDescription(id)); 59 contents = new JPanel(); 60 contents.setLayout(new BorderLayout()); 61 getContentPane().setLayout(new BorderLayout()); 62 getContentPane().add(contents, BorderLayout.CENTER); 63 contents.add(banner, BorderLayout.NORTH); 64 contents.add(buildPanel(), BorderLayout.CENTER); 65 contents.add(buildButtonBar(), BorderLayout.SOUTH); 66 pack(); 67 setResizable(false); 68 69 closeAction = new ActionListener() { 70 public void actionPerformed(final ActionEvent actionEvent) { 71 clear(); 72 hide(); 73 runner.cancel(); 74 75 } 76 }; 77 cancel.addActionListener(closeAction); 78 79 okAction = new ActionListener() { 80 public void actionPerformed(final ActionEvent actionEvent) { 81 if (validateForm()) { 82 runner.execute(); 83 } 84 85 } 86 }; 87 88 ok.addActionListener(okAction); 89 keyValidator = new KeyListener() { 90 public void keyPressed(KeyEvent e) { 91 92 } 93 94 public void keyReleased(KeyEvent e) { 95 ok.setEnabled(validateForm()); 96 } 97 98 public void keyTyped(KeyEvent e) { 99 100 } 101 }; 102 ((JComponent) contents).registerKeyboardAction(closeAction, 103 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), 104 JComponent.WHEN_IN_FOCUSED_WINDOW); 105 106 addWindowListener(new WindowAdapter() { 107 public void windowClosing(WindowEvent e) { 108 clear(); 109 runner.cancel(); 110 } 111 }); 112 113 114 } 115 116 protected void clear() { 117 } 118 119 abstract protected boolean validateForm(); 120 121 abstract protected Component buildPanel(); 122 123 protected JPanel buildButtonBar() { 124 ButtonBarBuilder bb = new ButtonBarBuilder(); 125 addExtraButtons(bb); 126 bb.addGlue(); 127 bb.addUnrelatedGap(); 128 bb.addGridded(ok); 129 bb.addGridded(cancel); 130 final JPanel buttonpanel = bb.getPanel(); 131 final JPanel panel = new JPanel(); 132 panel.setLayout(new BorderLayout()); 133 panel.add(buttonpanel, BorderLayout.CENTER); 134 panel.add(message, BorderLayout.NORTH); 135 return panel; 136 } 137 138 protected void addExtraButtons(ButtonBarBuilder bb) { 139 140 } 141 142 protected void open() { 143 switchToMain(); 144 initializeForm(); 145 pack(); 146 message.clear(); 147 com.l2fprod.common.swing.UIUtilities.centerOnScreen(dia); 148 show(); 149 toFront(); 150 } 151 152 protected void initializeForm() { 153 154 } 155 156 protected Object openAndWait(WaitForInput wait) throws UserCancellationException { 157 runner = wait; 158 new Thread(wait).start(); 159 return wait.getResult(); 160 } 161 162 protected void switchToMain() { 163 getContentPane().removeAll(); 164 getContentPane().add(contents); 165 pack(); 166 } 167 168 169 private final com.l2fprod.common.swing.BannerPanel banner; 170 protected final JButton ok; 171 private final JButton cancel; 172 protected final MessageLabel message; 173 protected WaitForInput runner; 174 protected Dialog dia = this; 175 176 177 protected JPanel contents; 178 protected KeyListener keyValidator; 179 protected ActionListener closeAction; 180 protected ActionListener okAction; 181 protected final String id; 182 183 184 } 185

This page was automatically generated by Maven