1 24 25 package org.objectweb.cjdbc.console.gui.frames; 26 27 import java.awt.BorderLayout ; 28 import java.awt.Color ; 29 import java.awt.Container ; 30 import java.awt.Dimension ; 31 import java.awt.Font ; 32 import java.awt.Frame ; 33 import java.awt.HeadlessException ; 34 import java.awt.Toolkit ; 35 import java.awt.event.ActionListener ; 36 import java.awt.event.WindowEvent ; 37 import java.awt.event.WindowListener ; 38 import java.awt.event.WindowStateListener ; 39 40 import javax.swing.BorderFactory ; 41 import javax.swing.JButton ; 42 import javax.swing.JDialog ; 43 import javax.swing.JLabel ; 44 import javax.swing.JList ; 45 import javax.swing.JPanel ; 46 import javax.swing.JScrollPane ; 47 import javax.swing.JTextField ; 48 import javax.swing.border.Border ; 49 import javax.swing.event.ListSelectionEvent ; 50 import javax.swing.event.ListSelectionListener ; 51 52 import org.objectweb.cjdbc.common.i18n.GuiTranslate; 53 import org.objectweb.cjdbc.console.gui.FrameConfirmKeyListener; 54 import org.objectweb.cjdbc.console.gui.constants.GuiCommands; 55 import org.objectweb.cjdbc.console.gui.constants.GuiConstants; 56 57 63 public class GuiInputBackupFrame extends JDialog 64 implements 65 WindowListener , 66 WindowStateListener 67 { 68 private JList sampleJList; 69 private JTextField valueField; 70 private FrameConfirmKeyListener keyListener; 71 72 75 public void windowActivated(WindowEvent e) 76 { 77 78 } 79 80 83 public void windowClosed(WindowEvent e) 84 { 85 this.setVisible(false); 86 valueField = null; 87 } 88 89 92 public void windowClosing(WindowEvent e) 93 { 94 valueField = null; 95 } 96 97 100 public void windowDeactivated(WindowEvent e) 101 { 102 103 } 104 105 108 public void windowDeiconified(WindowEvent e) 109 { 110 111 } 112 113 116 public void windowIconified(WindowEvent e) 117 { 118 119 } 120 121 124 public void windowOpened(WindowEvent e) 125 { 126 127 } 128 129 132 public void windowStateChanged(WindowEvent e) 133 { 134 135 } 136 137 145 public GuiInputBackupFrame(Frame owner, String [] entries, 146 ActionListener listener) throws HeadlessException 147 { 148 super(owner, GuiTranslate.get("frame.backup.title"), true); 149 150 Toolkit toolkit = Toolkit.getDefaultToolkit(); 152 Dimension dim = toolkit.getScreenSize(); 153 int screenHeight = dim.height; 154 int screenWidth = dim.width; 155 int frameWidth = 550; 156 int frameHeight = 50; 157 this.setBounds((screenWidth - frameWidth) / 2, 158 (screenHeight - frameHeight) / 2, frameWidth, frameHeight); 159 160 this.addWindowListener(this); 161 this.addWindowStateListener(this); 162 163 JButton optionConfirm = new JButton (GuiTranslate.get("frame.ok")); 164 optionConfirm.setActionCommand(GuiCommands.COMMAND_HIDE_BACKUP_FRAME); 165 optionConfirm.addActionListener(listener); 166 167 keyListener = new FrameConfirmKeyListener(optionConfirm); 168 this.addKeyListener(keyListener); 169 170 Container content = getContentPane(); 171 sampleJList = new JList (entries); 172 sampleJList.setVisibleRowCount(4); 173 Font displayFont = new Font ("Serif", Font.BOLD, 10); 174 sampleJList.setFont(displayFont); 175 sampleJList.addListSelectionListener(new ValueReporter()); 176 sampleJList.addKeyListener(keyListener); 177 JScrollPane listPane = new JScrollPane (sampleJList); 178 179 JPanel listPanel = new JPanel (); 180 listPanel.setEnabled(false); 181 listPanel.setBackground(Color.white); 182 Border listPanelBorder = BorderFactory.createTitledBorder(GuiTranslate 183 .get("frame.backup.list")); 184 listPanel.setBorder(listPanelBorder); 185 listPanel.add(listPane); 186 content.add(listPanel, BorderLayout.CENTER); 187 JLabel valueLabel = new JLabel (GuiTranslate.get("frame.backup.selection")); 188 valueLabel.setFont(displayFont); 189 valueField = new JTextField (GuiConstants.BACKEND_NO_CHECKPOINT, 7); 190 valueField.setFont(displayFont); 191 valueField.addKeyListener(keyListener); 192 193 JPanel valuePanel = new JPanel (); 194 valuePanel.setBackground(Color.white); 195 Border valuePanelBorder = BorderFactory.createTitledBorder(GuiTranslate 196 .get("frame.backup")); 197 valuePanel.setBorder(valuePanelBorder); 198 valuePanel.add(valueLabel); 199 valuePanel.add(valueField); 200 content.add(valuePanel, BorderLayout.NORTH); 201 202 JPanel selectPanel = new JPanel (); 203 selectPanel.setBackground(Color.white); 204 Border selectPanelBorder = BorderFactory.createTitledBorder(GuiTranslate 205 .get("frame.select")); 206 selectPanel.setBorder(selectPanelBorder); 207 208 209 selectPanel.add(optionConfirm); 210 content.add(selectPanel, BorderLayout.SOUTH); 211 pack(); 212 } 213 214 private class ValueReporter implements ListSelectionListener 215 { 216 219 public void valueChanged(ListSelectionEvent event) 220 { 221 if (!event.getValueIsAdjusting()) 222 valueField.setText(sampleJList.getSelectedValue().toString()); 223 } 224 } 225 226 231 public JTextField getValueField() 232 { 233 return valueField; 234 } 235 236 241 public final void setValue(String value) 242 { 243 valueField.setText(value); 244 valueField.repaint(); 245 } 246 } | Popular Tags |