1 package uk.ac.roe.antigen.dialogs; 2 3 import java.awt.BorderLayout ; 4 import java.awt.Dimension ; 5 import java.awt.FlowLayout ; 6 import java.awt.GridLayout ; 7 import java.awt.Point ; 8 import java.awt.Toolkit ; 9 import java.awt.event.ActionEvent ; 10 import java.awt.event.ActionListener ; 11 import java.util.Iterator ; 12 import java.util.Vector ; 13 14 import javax.swing.BorderFactory ; 15 import javax.swing.BoxLayout ; 16 import javax.swing.ButtonGroup ; 17 import javax.swing.ImageIcon ; 18 import javax.swing.JButton ; 19 import javax.swing.JFrame ; 20 import javax.swing.JPanel ; 21 import javax.swing.JRadioButton ; 22 import javax.swing.JTextArea ; 23 import javax.swing.SwingConstants ; 24 import javax.swing.border.BevelBorder ; 25 import javax.swing.border.TitledBorder ; 26 27 import org.apache.tools.ant.BuildException; 28 import org.apache.tools.ant.input.InputHandler; 29 import org.apache.tools.ant.input.InputRequest; 30 import org.apache.tools.ant.input.MultipleChoiceInputRequest; 31 32 import uk.ac.roe.antigen.utils.Config; 33 34 35 public class RadioPropertyInputHandler extends javax.swing.JDialog implements 36 InputHandler { 37 private JRadioButton propertyValue2; 38 39 private JRadioButton propertyValue1; 40 41 private JPanel propertyValuesPnl; 42 43 private JPanel jPanel3; 44 45 private JButton okBtn; 46 47 private JTextArea propertyNameLbl; 48 49 private JPanel jPanel2; 50 51 private String chosen; 52 private JPanel jPanel1; 53 54 57 public static void main(String [] args) { 58 Config.load("/config.properties"); 59 JFrame frame = new JFrame (); 60 frame.setVisible(true); 61 RadioPropertyInputHandler inst = new RadioPropertyInputHandler(frame); 62 inst.setVisible(true); 63 } 64 65 public RadioPropertyInputHandler(JFrame frame) { 66 super(frame); 67 initGUI(); 68 } 69 70 private void initGUI() { 71 try { 72 setSize(600, 250); 73 setUndecorated(true); 74 { 75 jPanel2 = new JPanel (); 76 this.getContentPane().add(jPanel2, BorderLayout.CENTER); 77 BorderLayout jPanel2Layout = new BorderLayout (); 78 jPanel2.setOpaque(false); 79 jPanel2.setLayout(jPanel2Layout); 80 { 81 jPanel3 = new JPanel (); 82 jPanel2.add(jPanel3, BorderLayout.SOUTH); 83 FlowLayout jPanel3Layout = new FlowLayout (); 84 jPanel3.setOpaque(false); 85 jPanel3.setLayout(jPanel3Layout); 86 { 87 okBtn = new JButton (); 88 jPanel3.add(okBtn); 89 okBtn.setText("Next"); 90 okBtn.setIcon(new ImageIcon (getClass().getClassLoader().getResource("img/rightarrow.png"))); 91 okBtn.addActionListener(new ActionListener () { 92 public void actionPerformed(ActionEvent evt) { 93 okPressed = true; 94 } 95 }); 96 } 97 } 98 { 99 jPanel1 = new JPanel (); 100 jPanel2.add(jPanel1, BorderLayout.CENTER); 101 BoxLayout jPanel1Layout = new BoxLayout (jPanel1, BoxLayout.PAGE_AXIS); 102 String borderTitle = Config.getProperty("antigen.dialog.bordertitle","antigen"); 103 jPanel1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(BevelBorder.RAISED, null, null), borderTitle, TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font ("Eurostile",0,12), new java.awt.Color (0,0,255))); 104 jPanel1.setLayout(jPanel1Layout); 105 { 106 propertyNameLbl = new JTextArea (); 107 propertyNameLbl.setWrapStyleWord(true); 108 propertyNameLbl.setLineWrap(true); 109 jPanel1.add(propertyNameLbl); 110 propertyNameLbl.setText("property name very long very long very long very long very longvery long very long very long very long very long"); 111 propertyNameLbl.setFont(new java.awt.Font ( 112 "Dialoginput", 113 0, 114 12)); 115 propertyNameLbl.setOpaque(false); 116 propertyNameLbl.setSize(580, 2); 117 propertyNameLbl.setEditable(false); 118 } 119 { 120 propertyValuesPnl = new JPanel (); 121 jPanel1.add(propertyValuesPnl); 122 GridLayout jPanel4Layout = new GridLayout (2, 1); 123 propertyValuesPnl.setOpaque(false); 124 jPanel4Layout.setColumns(1); 125 jPanel4Layout.setRows(2); 126 propertyValuesPnl.setLayout(jPanel4Layout); 127 { 128 propertyValue1 = new JRadioButton (); 129 propertyValuesPnl.add(propertyValue1); 130 propertyValue1 131 .setText("value1 very long very long very long"); 132 propertyValue1.setBounds(155, 10, 60, 30); 133 propertyValue1.setOpaque(false); 134 propertyValue1.setSelected(true); 135 } 136 { 137 propertyValue2 = new JRadioButton (); 138 propertyValuesPnl.add(propertyValue2); 139 propertyValue2.setText("value2"); 140 propertyValue2.setOpaque(false); 141 propertyValue2 142 .setHorizontalAlignment(SwingConstants.CENTER); 143 propertyValue2 144 .setHorizontalTextPosition(SwingConstants.LEADING); 145 } 146 } 147 } 148 } 149 } catch (Exception e) { 150 e.printStackTrace(); 151 } 152 this.setLocation(getDialogLocation().width, getDialogLocation().height); 153 } 154 155 boolean okPressed = false; 156 157 162 public void handleInput(InputRequest requestIn) throws BuildException { 163 164 MultipleChoiceInputRequest request = (MultipleChoiceInputRequest) requestIn; 168 okPressed = false; 169 170 Vector choices = request.getChoices(); 171 String def = request.getDefault(); 172 173 propertyValuesPnl.removeAll(); 174 propertyValuesPnl.setLayout(new GridLayout (choices.size(), 1)); 175 ButtonGroup buttonGroup1 = new ButtonGroup (); 176 Iterator it = choices.iterator(); 177 while (it.hasNext()) { 178 final String choice = (String ) it.next(); 179 JRadioButton button = new JRadioButton (); 180 button.addActionListener(new ActionListener () { 181 public void actionPerformed(ActionEvent evt) { 182 chosen = choice; 183 } 184 }); 185 button.setLabel(choice); 186 187 if (choice.equals(def)) { 188 button.setSelected(true); 189 } 190 buttonGroup1.add(button); 191 propertyValuesPnl.add(button); 192 } 193 194 this.setVisible(true); 196 propertyNameLbl.setText(request.getPrompt()); 197 while (!okPressed) { 198 try { 199 Thread.sleep(100); 200 } catch (InterruptedException ie) { 201 } 202 } 203 204 requestIn.setInput(chosen); 205 this.setVisible(false); 206 } 207 private Dimension getDialogLocation() { 208 Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); 210 Dimension dlgInputDim = this.getSize(); 211 Dimension splashDim = getOwner().getSize(); 212 Point splashLoc = getOwner().getLocationOnScreen(); 213 214 int dlgInputX = (int) 215 ((screenDim.getWidth() - dlgInputDim.getWidth()) / 2); 216 int dlgInputY = (int) 217 splashLoc.y+splashDim.height; 218 return new Dimension (dlgInputX, dlgInputY); 219 } 220 } | Popular Tags |