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 37 import javax.swing.BorderFactory ; 38 import javax.swing.JButton ; 39 import javax.swing.JDialog ; 40 import javax.swing.JLabel ; 41 import javax.swing.JList ; 42 import javax.swing.JPanel ; 43 import javax.swing.JScrollPane ; 44 import javax.swing.JTextField ; 45 import javax.swing.border.Border ; 46 import javax.swing.event.ListSelectionEvent ; 47 import javax.swing.event.ListSelectionListener ; 48 49 import org.objectweb.cjdbc.common.i18n.GuiTranslate; 50 import org.objectweb.cjdbc.console.gui.FrameConfirmKeyListener; 51 import org.objectweb.cjdbc.console.gui.constants.GuiCommands; 52 53 61 public class GuiSelectShutdownFrame extends JDialog 62 { 63 private JList sampleJList; 64 private JTextField valueField; 65 private final String [] entries = new String []{ 66 GuiCommands.COMMAND_SHUTDOWN_SAFE, GuiCommands.COMMAND_SHUTDOWN_WAIT, 67 GuiCommands.COMMAND_SHUTDOWN_FORCE }; 68 69 private FrameConfirmKeyListener keyListener; 70 71 78 public GuiSelectShutdownFrame(Frame owner, ActionListener listener) 79 throws HeadlessException 80 { 81 super(owner, GuiTranslate.get("frame.shutdown.title"), true); 82 83 Toolkit toolkit = Toolkit.getDefaultToolkit(); 85 Dimension dim = toolkit.getScreenSize(); 86 int screenHeight = dim.height; 87 int screenWidth = dim.width; 88 int frameWidth = 450; 89 int frameHeight = 50; 90 this.setBounds((screenWidth - frameWidth) / 2, 91 (screenHeight - frameHeight) / 2, frameWidth, frameHeight); 92 93 JButton optionConfirm = new JButton (GuiTranslate.get("frame.ok")); 94 optionConfirm.setActionCommand(GuiCommands.COMMAND_HIDE_SHUTDOWN_FRAME); 95 optionConfirm.addActionListener(listener); 96 97 keyListener = new FrameConfirmKeyListener(optionConfirm); 98 this.addKeyListener(keyListener); 99 100 Container content = getContentPane(); 101 sampleJList = new JList (entries); 102 sampleJList.setVisibleRowCount(4); 103 Font displayFont = new Font ("Serif", Font.BOLD, 12); 104 sampleJList.setFont(displayFont); 105 sampleJList.addListSelectionListener(new ValueReporter()); 106 sampleJList.addKeyListener(keyListener); 107 JScrollPane listPane = new JScrollPane (sampleJList); 108 109 JPanel listPanel = new JPanel (); 110 listPanel.setBackground(Color.white); 111 Border listPanelBorder = BorderFactory.createTitledBorder(GuiTranslate 112 .get("frame.shutdown.levels")); 113 listPanel.setBorder(listPanelBorder); 114 listPanel.add(listPane); 115 content.add(listPanel, BorderLayout.CENTER); 116 JLabel valueLabel = new JLabel (GuiTranslate.get("frame.shutdown.selection")); 117 valueLabel.setFont(displayFont); 118 valueField = new JTextField (GuiCommands.COMMAND_SHUTDOWN_SAFE, 7); 119 valueField.setEditable(false); 120 valueField.setFont(displayFont); 121 valueField.addKeyListener(keyListener); 122 123 JPanel valuePanel = new JPanel (); 124 valuePanel.setBackground(Color.white); 125 Border valuePanelBorder = BorderFactory.createTitledBorder(GuiTranslate 126 .get("frame.shutdown")); 127 valuePanel.setBorder(valuePanelBorder); 128 valuePanel.add(valueLabel); 129 valuePanel.add(valueField); 130 content.add(valuePanel, BorderLayout.NORTH); 131 132 JPanel selectPanel = new JPanel (); 133 selectPanel.setBackground(Color.white); 134 Border selectPanelBorder = BorderFactory.createTitledBorder(GuiTranslate 135 .get("frame.select")); 136 selectPanel.setBorder(selectPanelBorder); 137 138 selectPanel.add(optionConfirm); 139 content.add(selectPanel, BorderLayout.SOUTH); 140 pack(); 141 } 142 143 private class ValueReporter implements ListSelectionListener 144 { 145 148 public void valueChanged(ListSelectionEvent event) 149 { 150 if (!event.getValueIsAdjusting()) 151 valueField.setText(sampleJList.getSelectedValue().toString()); 152 } 153 } 154 155 160 public JList getSampleJList() 161 { 162 return sampleJList; 163 } 164 165 170 public JTextField getValueField() 171 { 172 return valueField; 173 } 174 } | Popular Tags |