1 6 7 package com.quikj.client.beans; 8 9 import java.awt.*; 10 11 15 public class ListDialog extends java.awt.Dialog 16 { 17 18 19 public ListDialog(java.awt.Frame parent, 20 String label, 21 String [] list, 22 String ok_button_label, 23 String cancel_button_label, 24 ListListenerInterface listener) 25 { 26 super(parent); 27 28 if (listener == null) 29 { 30 setModal(true); 31 } 32 else 33 { 34 setModal(false); 35 } 36 37 this.listener = listener; 38 39 initComponents(); 40 41 listHeaderWidget.setText(label); 42 43 for (int i = 0; i < list.length; i++) 44 { 45 listWidget.add(list[i]); 46 } 47 48 if (ok_button_label != null) 49 { 50 okButton.setLabel(ok_button_label); 51 } 52 53 if (cancel_button_label != null) 54 { 55 cancelButton.setLabel(cancel_button_label); 56 } 57 58 Rectangle pbounds = parent.getBounds(); 60 Point mid = new Point(pbounds.x + (pbounds.width/2), pbounds.y + (pbounds.height/2)); 61 Rectangle bounds = getBounds(); 62 int x = mid.x - (bounds.width/2); 63 int y = mid.y - (bounds.height/2); 64 if (x < 0) x = pbounds.x; 65 if (y < 0) y = pbounds.y; 66 setBounds(x, y, bounds.width, bounds.height); 67 68 show(); 69 } 70 71 76 private void initComponents() { 78 java.awt.GridBagConstraints gridBagConstraints; 79 80 listHeaderWidget = new java.awt.Label (); 81 listWidget = new java.awt.List (); 82 panel1 = new java.awt.Panel (); 83 okButton = new java.awt.Button (); 84 cancelButton = new java.awt.Button (); 85 86 setLayout(new java.awt.GridBagLayout ()); 87 88 setForeground(java.awt.Color.black); 89 setBackground(java.awt.Color.white); 90 addWindowListener(new java.awt.event.WindowAdapter () 91 { 92 public void windowClosing(java.awt.event.WindowEvent evt) 93 { 94 closeDialog(evt); 95 } 96 }); 97 98 listHeaderWidget.setText("List Header"); 99 gridBagConstraints = new java.awt.GridBagConstraints (); 100 gridBagConstraints.gridx = 0; 101 gridBagConstraints.gridy = 0; 102 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 103 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 104 gridBagConstraints.weightx = 100.0; 105 gridBagConstraints.insets = new java.awt.Insets (10, 10, 0, 10); 106 add(listHeaderWidget, gridBagConstraints); 107 108 listWidget.setBackground(new java.awt.Color (255, 255, 255)); 109 listWidget.setForeground(new java.awt.Color (0, 51, 51)); 110 gridBagConstraints = new java.awt.GridBagConstraints (); 111 gridBagConstraints.gridx = 0; 112 gridBagConstraints.gridy = 1; 113 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 114 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 115 gridBagConstraints.weightx = 100.0; 116 gridBagConstraints.weighty = 100.0; 117 gridBagConstraints.insets = new java.awt.Insets (0, 10, 0, 10); 118 add(listWidget, gridBagConstraints); 119 120 panel1.setLayout(new java.awt.GridBagLayout ()); 121 122 panel1.setBackground(new java.awt.Color (255, 255, 255)); 123 okButton.setLabel(" OK "); 124 okButton.addActionListener(new java.awt.event.ActionListener () 125 { 126 public void actionPerformed(java.awt.event.ActionEvent evt) 127 { 128 okButtonActionPerformed(evt); 129 } 130 }); 131 132 gridBagConstraints = new java.awt.GridBagConstraints (); 133 gridBagConstraints.gridx = 0; 134 gridBagConstraints.gridy = 0; 135 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 20); 136 panel1.add(okButton, gridBagConstraints); 137 138 cancelButton.setLabel("Cancel"); 139 cancelButton.addActionListener(new java.awt.event.ActionListener () 140 { 141 public void actionPerformed(java.awt.event.ActionEvent evt) 142 { 143 cancelButtonActionPerformed(evt); 144 } 145 }); 146 147 gridBagConstraints = new java.awt.GridBagConstraints (); 148 gridBagConstraints.gridx = 1; 149 gridBagConstraints.gridy = 0; 150 gridBagConstraints.insets = new java.awt.Insets (0, 20, 0, 0); 151 panel1.add(cancelButton, gridBagConstraints); 152 153 gridBagConstraints = new java.awt.GridBagConstraints (); 154 gridBagConstraints.gridx = 0; 155 gridBagConstraints.gridy = 2; 156 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 157 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 158 gridBagConstraints.weightx = 100.0; 159 gridBagConstraints.insets = new java.awt.Insets (10, 10, 10, 10); 160 add(panel1, gridBagConstraints); 161 162 pack(); 163 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 164 setSize(new java.awt.Dimension (400, 300)); 165 setLocation((screenSize.width-400)/2,(screenSize.height-300)/2); 166 } 168 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 172 } 174 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) { selectedIndex = listWidget.getSelectedIndex(); 178 if (listener == null) 179 { 180 okSelected = true; 181 182 dispose(); 183 } 184 else 185 { 186 if (selectedIndex >= 0) 187 { 188 listener.actionPerformed(selectedIndex); 189 } 190 } 192 } 194 195 private void closeDialog(java.awt.event.WindowEvent evt) { } 199 202 public int getSelectedIndex() 203 { 204 return selectedIndex; 205 } 206 207 210 public void setSelectedIndex(int selectedIndex) 211 { 212 this.selectedIndex = selectedIndex; 213 } 214 215 public boolean isOkSelected() 216 { 217 return okSelected; 218 } 219 220 private java.awt.Label listHeaderWidget; 222 private java.awt.Button okButton; 223 private java.awt.Button cancelButton; 224 private java.awt.List listWidget; 225 private java.awt.Panel panel1; 226 228 private ListListenerInterface listener = null; 229 private boolean okSelected = false; 230 private int selectedIndex = -1; 231 } 232 | Popular Tags |