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 GuiSelectCheckpointFrame 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 GuiSelectCheckpointFrame(Frame owner, String [] entries, 146 ActionListener listener) throws HeadlessException 147 { 148 super(owner, GuiTranslate.get("frame.checkpoint.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 = 450; 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_CHECKPOINT_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, 12); 174 sampleJList.setFont(displayFont); 175 sampleJList.addListSelectionListener(new ValueReporter()); 176 JScrollPane listPane = new JScrollPane (sampleJList); 177 sampleJList.addKeyListener(keyListener); 178 179 JPanel listPanel = new JPanel (); 180 listPanel.setBackground(Color.white); 181 Border listPanelBorder = BorderFactory.createTitledBorder(GuiTranslate 182 .get("frame.checkpoint.list")); 183 listPanel.setBorder(listPanelBorder); 184 listPanel.add(listPane); 185 content.add(listPanel, BorderLayout.CENTER); 186 JLabel valueLabel = new JLabel (GuiTranslate 187 .get("frame.checkpoint.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.checkpoint")); 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 selectPanel.add(optionConfirm); 209 content.add(selectPanel, BorderLayout.SOUTH); 210 pack(); 211 } 212 213 private class ValueReporter implements ListSelectionListener 214 { 215 218 public void valueChanged(ListSelectionEvent event) 219 { 220 if (!event.getValueIsAdjusting()) 221 valueField.setText(sampleJList.getSelectedValue().toString()); 222 } 223 } 224 225 230 public JTextField getValueField() 231 { 232 return valueField; 233 } 234 } | Popular Tags |