Initial revision
[old-projects.git] / ekit / com / hexidec / ekit / component / SymbolDialog.java
CommitLineData
6dd70280
JL
1/*\r
2GNU Lesser General Public License\r
3\r
4SymbolInputDialog\r
5Copyright (C) 2000-2003 Howard Kistler\r
6\r
7This library is free software; you can redistribute it and/or\r
8modify it under the terms of the GNU Lesser General Public\r
9License as published by the Free Software Foundation; either\r
10version 2.1 of the License, or (at your option) any later version.\r
11\r
12This library is distributed in the hope that it will be useful,\r
13but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
15Lesser General Public License for more details.\r
16\r
17You should have received a copy of the GNU Lesser General Public\r
18License along with this library; if not, write to the Free Software\r
19Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
20*/\r
21\r
22package com.hexidec.ekit.component;\r
23\r
24import com.hexidec.ekit.EkitCore;\r
25import com.hexidec.util.Translatrix;\r
26import java.awt.Container;\r
27import java.awt.GridLayout;\r
28import java.awt.event.ActionEvent;\r
29import java.awt.event.ActionListener;\r
30import javax.swing.border.*;\r
31import javax.swing.BoxLayout;\r
32import javax.swing.JButton;\r
33import javax.swing.JToggleButton;\r
34import javax.swing.ButtonGroup;\r
35import javax.swing.JDialog;\r
36import javax.swing.JPanel;\r
37import javax.swing.WindowConstants;\r
38import javax.swing.SwingConstants;\r
39\r
40public class SymbolDialog extends JDialog implements ActionListener\r
41{\r
42 private final static String SYMBOLS = Translatrix.getTranslationString("Symbols");\r
43 \r
44 private EkitCore parentEkit;\r
45 private ButtonGroup buttonGroup;\r
46 private String returnSymbol;\r
47\r
48 public SymbolDialog(EkitCore peKit, String title, boolean bModal)\r
49 {\r
50 super(peKit.getFrame(), title, bModal);\r
51 parentEkit = peKit;\r
52 init();\r
53 }\r
54\r
55 public void actionPerformed(ActionEvent e)\r
56 {\r
57 if(e.getActionCommand().equals("accept"))\r
58 {\r
59 setVisible(false);\r
60 if(buttonGroup.getSelection() == null)\r
61 {\r
62 returnSymbol = null;\r
63 }\r
64 else\r
65 {\r
66 returnSymbol = buttonGroup.getSelection().getActionCommand();\r
67 }\r
68 }\r
69 else if(e.getActionCommand().equals("cancel"))\r
70 {\r
71 setVisible(false);\r
72 returnSymbol = null;\r
73 }\r
74 }\r
75\r
76 public void init()\r
77 {\r
78 Container contentPane = getContentPane();\r
79 contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));\r
80 setBounds(100,100,400,300);\r
81 setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);\r
82\r
83 JPanel centerPanel = new JPanel();\r
84 centerPanel.setLayout(new GridLayout(0, 8, 0, 0));\r
85 buttonGroup = new ButtonGroup();\r
86 for(int i = 0; i < SYMBOLS.length(); i++)\r
87 {\r
88 String symbol = Character.toString(SYMBOLS.charAt(i));\r
89 JToggleButton b = new JToggleButton(symbol);\r
90 b.getModel().setActionCommand(symbol);\r
91 centerPanel.add(b);\r
92 buttonGroup.add(b);\r
93 }\r
94\r
95 JPanel buttonPanel= new JPanel();\r
96 buttonPanel.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));\r
97\r
98 JButton saveButton = new JButton(Translatrix.getTranslationString("DialogAccept"));\r
99 saveButton.setActionCommand("accept");\r
100 saveButton.addActionListener(this);\r
101\r
102 JButton cancelButton = new JButton(Translatrix.getTranslationString("DialogCancel"));\r
103 cancelButton.setActionCommand("cancel");\r
104 cancelButton.addActionListener(this);\r
105\r
106 buttonPanel.add(saveButton);\r
107 buttonPanel.add(cancelButton);\r
108\r
109 contentPane.add(centerPanel);\r
110 contentPane.add(buttonPanel);\r
111\r
112 this.pack();\r
113 this.setVisible(true);\r
114 }\r
115\r
116 public String getInputText()\r
117 {\r
118 return returnSymbol;\r
119 }\r
120\r
121}\r
122\r