2 GNU Lesser General Public License
5 Copyright (C) 2003 Howard Kistler
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.
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.
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
22 package com
.hexidec
.ekit
.component
;
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 java
.util
.Hashtable
;
30 import java
.util
.Iterator
;
31 import java
.util
.StringTokenizer
;
32 import javax
.swing
.JCheckBox
;
33 import javax
.swing
.JComboBox
;
34 import javax
.swing
.JDialog
;
35 import javax
.swing
.JOptionPane
;
36 import javax
.swing
.JTextField
;
38 import com
.hexidec
.util
.Translatrix
;
40 /** Class for providing a dialog that lets the user specify values for tag attributes
42 public class PropertiesDialog
extends JDialog
44 private JOptionPane jOptionPane
;
45 private Hashtable htInputFields
;
47 public PropertiesDialog(Frame parent
, String
[] fields
, String
[] types
, String
[] values
, String title
, boolean bModal
)
49 super(parent
, title
, bModal
);
50 htInputFields
= new Hashtable();
51 final Object
[] buttonLabels
= { Translatrix
.getTranslationString("DialogAccept"), Translatrix
.getTranslationString("DialogCancel") };
52 Object
[] panelContents
= new Object
[(fields
.length
* 2)];
54 for(int iter
= 0; iter
< fields
.length
; iter
++)
56 String fieldName
= fields
[iter
];
57 String fieldType
= types
[iter
];
58 Object fieldComponent
;
59 if(fieldType
.equals("text"))
61 fieldComponent
= new JTextField(3);
62 if(values
[iter
] != null
&& values
[iter
].length() > 0)
64 ((JTextField
)(fieldComponent
)).setText(values
[iter
]);
67 else if(fieldType
.equals("bool"))
69 fieldComponent
= new JCheckBox();
70 if(values
[iter
] != null
)
72 ((JCheckBox
)(fieldComponent
)).setSelected(values
[iter
] == "true");
75 else if(fieldType
.equals("combo"))
77 fieldComponent
= new JComboBox();
78 if(values
[iter
] != null
)
80 StringTokenizer stParse
= new StringTokenizer(values
[iter
], ",", false
);
81 while(stParse
.hasMoreTokens())
83 ((JComboBox
)(fieldComponent
)).addItem(stParse
.nextToken());
89 fieldComponent
= new JTextField(3);
91 htInputFields
.put(fieldName
, fieldComponent
);
92 panelContents
[objectCount
] = fieldName
; // Translatrix.getTranslationString(fieldName);
93 panelContents
[objectCount
+ 1] = fieldComponent
;
96 jOptionPane
= new JOptionPane(panelContents
, JOptionPane
.QUESTION_MESSAGE
, JOptionPane
.OK_CANCEL_OPTION
, null
, buttonLabels
, buttonLabels
[0]);
98 setContentPane(jOptionPane
);
99 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE
);
101 jOptionPane
.addPropertyChangeListener(new PropertyChangeListener() {
102 public void propertyChange(PropertyChangeEvent e
)
104 String prop
= e
.getPropertyName();
105 if(isVisible() && (e
.getSource() == jOptionPane
) && (prop
.equals(JOptionPane
.VALUE_PROPERTY
) || prop
.equals(JOptionPane
.INPUT_VALUE_PROPERTY
)))
107 Object value
= jOptionPane
.getValue();
108 if(value
== JOptionPane
.UNINITIALIZED_VALUE
)
112 if(value
.equals(buttonLabels
[0]))
126 public PropertiesDialog(Frame parent
, String
[] fields
, String
[] types
, String title
, boolean bModal
)
128 this(parent
, fields
, types
, new String
[fields
.length
], title
, bModal
);
131 public String
getFieldValue(String fieldName
)
133 Object dataField
= htInputFields
.get(fieldName
);
134 if(dataField
instanceof JTextField
)
136 return ((JTextField
)dataField
).getText();
138 else if(dataField
instanceof JCheckBox
)
140 if(((JCheckBox
)dataField
).isSelected())
149 else if(dataField
instanceof JComboBox
)
151 return (String
)(((JComboBox
)dataField
).getSelectedItem());
159 public String
getDecisionValue()
161 return jOptionPane
.getValue().toString();