| | 1 | /* |
| | 2 | GNU Lesser General Public License |
| | 3 | |
| | 4 | TableInputDialog |
| | 5 | Copyright (C) 2000 Howard Kistler |
| | 6 | |
| | 7 | This library is free software; you can redistribute it and/or |
| | 8 | modify it under the terms of the GNU Lesser General Public |
| | 9 | License as published by the Free Software Foundation; either |
| | 10 | version 2.1 of the License, or (at your option) any later version. |
| | 11 | |
| | 12 | This library is distributed in the hope that it will be useful, |
| | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| | 15 | Lesser General Public License for more details. |
| | 16 | |
| | 17 | You should have received a copy of the GNU Lesser General Public |
| | 18 | License along with this library; if not, write to the Free Software |
| | 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| | 20 | */ |
| | 21 | |
| | 22 | package com.hexidec.ekit.component; |
| | 23 | |
| | 24 | import java.awt.Frame; |
| | 25 | import java.awt.event.WindowAdapter; |
| | 26 | import java.awt.event.WindowEvent; |
| | 27 | import java.beans.PropertyChangeEvent; |
| | 28 | import java.beans.PropertyChangeListener; |
| | 29 | import javax.swing.JDialog; |
| | 30 | import javax.swing.JOptionPane; |
| | 31 | import javax.swing.JTextField; |
| | 32 | |
| | 33 | import com.hexidec.util.Translatrix; |
| | 34 | |
| | 35 | /** Class for providing a dialog that lets the user specify values for tag attributes |
| | 36 | */ |
| | 37 | public class TableInputDialog extends JDialog |
| | 38 | { |
| | 39 | private String inputRows = new String(); |
| | 40 | private String inputCols = new String(); |
| | 41 | private String inputBorder = new String(); |
| | 42 | private String inputSpace = new String(); |
| | 43 | private String inputPad = new String(); |
| | 44 | private JOptionPane jOptionPane; |
| | 45 | |
| | 46 | public TableInputDialog(Frame parent, String title, boolean bModal) |
| | 47 | { |
| | 48 | super(parent, title, bModal); |
| | 49 | final JTextField jtxfRows = new JTextField(3); |
| | 50 | final JTextField jtxfCols = new JTextField(3); |
| | 51 | final JTextField jtxfBorder = new JTextField(3); |
| | 52 | final JTextField jtxfSpace = new JTextField(3); |
| | 53 | final JTextField jtxfPad = new JTextField(3); |
| | 54 | final Object[] buttonLabels = { Translatrix.getTranslationString("DialogAccept"), Translatrix.getTranslationString("DialogCancel") }; |
| | 55 | Object[] panelContents = { |
| | 56 | Translatrix.getTranslationString("TableRows"), jtxfRows, |
| | 57 | Translatrix.getTranslationString("TableColumns"), jtxfCols, |
| | 58 | Translatrix.getTranslationString("TableBorder"), jtxfBorder, |
| | 59 | Translatrix.getTranslationString("TableCellSpacing"), jtxfSpace, |
| | 60 | Translatrix.getTranslationString("TableCellPadding"), jtxfPad |
| | 61 | }; |
| | 62 | jOptionPane = new JOptionPane(panelContents, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, buttonLabels, buttonLabels[0]); |
| | 63 | |
| | 64 | setContentPane(jOptionPane); |
| | 65 | setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); |
| | 66 | |
| | 67 | addWindowListener(new WindowAdapter() { |
| | 68 | public void windowClosing(WindowEvent we) |
| | 69 | { |
| | 70 | jOptionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION)); |
| | 71 | } |
| | 72 | }); |
| | 73 | |
| | 74 | jOptionPane.addPropertyChangeListener(new PropertyChangeListener() { |
| | 75 | public void propertyChange(PropertyChangeEvent e) |
| | 76 | { |
| | 77 | String prop = e.getPropertyName(); |
| | 78 | if(isVisible() |
| | 79 | && (e.getSource() == jOptionPane) |
| | 80 | && (prop.equals(JOptionPane.VALUE_PROPERTY) || prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) |
| | 81 | { |
| | 82 | Object value = jOptionPane.getValue(); |
| | 83 | if(value == JOptionPane.UNINITIALIZED_VALUE) |
| | 84 | { |
| | 85 | return; |
| | 86 | } |
| | 87 | jOptionPane.setValue(JOptionPane.UNINITIALIZED_VALUE); |
| | 88 | if(value.equals(buttonLabels[0])) |
| | 89 | { |
| | 90 | inputRows = jtxfRows.getText(); |
| | 91 | inputCols = jtxfCols.getText(); |
| | 92 | inputBorder = jtxfBorder.getText(); |
| | 93 | inputSpace = jtxfSpace.getText(); |
| | 94 | inputPad = jtxfPad.getText(); |
| | 95 | setVisible(false); |
| | 96 | } |
| | 97 | else |
| | 98 | { |
| | 99 | inputRows = ""; |
| | 100 | inputCols = ""; |
| | 101 | inputBorder = ""; |
| | 102 | inputSpace = ""; |
| | 103 | inputPad = ""; |
| | 104 | setVisible(false); |
| | 105 | } |
| | 106 | } |
| | 107 | } |
| | 108 | }); |
| | 109 | this.pack(); |
| | 110 | } |
| | 111 | |
| | 112 | public int getRows() |
| | 113 | { |
| | 114 | try |
| | 115 | { |
| | 116 | return Integer.parseInt(inputRows); |
| | 117 | } |
| | 118 | catch(NumberFormatException nfe) |
| | 119 | { |
| | 120 | return -1; |
| | 121 | } |
| | 122 | } |
| | 123 | |
| | 124 | public int getCols() |
| | 125 | { |
| | 126 | try |
| | 127 | { |
| | 128 | return Integer.parseInt(inputCols); |
| | 129 | } |
| | 130 | catch(NumberFormatException nfe) |
| | 131 | { |
| | 132 | return -1; |
| | 133 | } |
| | 134 | } |
| | 135 | |
| | 136 | public int getBorder() |
| | 137 | { |
| | 138 | try |
| | 139 | { |
| | 140 | return Integer.parseInt(inputBorder); |
| | 141 | } |
| | 142 | catch(NumberFormatException nfe) |
| | 143 | { |
| | 144 | return -1; |
| | 145 | } |
| | 146 | } |
| | 147 | |
| | 148 | public int getSpacing() |
| | 149 | { |
| | 150 | try |
| | 151 | { |
| | 152 | return Integer.parseInt(inputSpace); |
| | 153 | } |
| | 154 | catch(NumberFormatException nfe) |
| | 155 | { |
| | 156 | return -1; |
| | 157 | } |
| | 158 | } |
| | 159 | |
| | 160 | public int getPadding() |
| | 161 | { |
| | 162 | try |
| | 163 | { |
| | 164 | return Integer.parseInt(inputPad); |
| | 165 | } |
| | 166 | catch(NumberFormatException nfe) |
| | 167 | { |
| | 168 | return -1; |
| | 169 | } |
| | 170 | } |
| | 171 | } |
| | 172 | |