Initial revision
[old-projects.git] / ekit / com / hexidec / ekit / component / SymbolDialog.java
1 /*
2 GNU Lesser General Public License
3
4 SymbolInputDialog
5 Copyright (C) 2000-2003 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 com.hexidec.ekit.EkitCore;
25 import com.hexidec.util.Translatrix;
26 import java.awt.Container;
27 import java.awt.GridLayout;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import javax.swing.border.*;
31 import javax.swing.BoxLayout;
32 import javax.swing.JButton;
33 import javax.swing.JToggleButton;
34 import javax.swing.ButtonGroup;
35 import javax.swing.JDialog;
36 import javax.swing.JPanel;
37 import javax.swing.WindowConstants;
38 import javax.swing.SwingConstants;
39
40 public class SymbolDialog extends JDialog implements ActionListener
41 {
42 private final static String SYMBOLS = Translatrix.getTranslationString("Symbols");
43
44 private EkitCore parentEkit;
45 private ButtonGroup buttonGroup;
46 private String returnSymbol;
47
48 public SymbolDialog(EkitCore peKit, String title, boolean bModal)
49 {
50 super(peKit.getFrame(), title, bModal);
51 parentEkit = peKit;
52 init();
53 }
54
55 public void actionPerformed(ActionEvent e)
56 {
57 if(e.getActionCommand().equals("accept"))
58 {
59 setVisible(false);
60 if(buttonGroup.getSelection() == null)
61 {
62 returnSymbol = null;
63 }
64 else
65 {
66 returnSymbol = buttonGroup.getSelection().getActionCommand();
67 }
68 }
69 else if(e.getActionCommand().equals("cancel"))
70 {
71 setVisible(false);
72 returnSymbol = null;
73 }
74 }
75
76 public void init()
77 {
78 Container contentPane = getContentPane();
79 contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
80 setBounds(100,100,400,300);
81 setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
82
83 JPanel centerPanel = new JPanel();
84 centerPanel.setLayout(new GridLayout(0, 8, 0, 0));
85 buttonGroup = new ButtonGroup();
86 for(int i = 0; i < SYMBOLS.length(); i++)
87 {
88 String symbol = Character.toString(SYMBOLS.charAt(i));
89 JToggleButton b = new JToggleButton(symbol);
90 b.getModel().setActionCommand(symbol);
91 centerPanel.add(b);
92 buttonGroup.add(b);
93 }
94
95 JPanel buttonPanel= new JPanel();
96 buttonPanel.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));
97
98 JButton saveButton = new JButton(Translatrix.getTranslationString("DialogAccept"));
99 saveButton.setActionCommand("accept");
100 saveButton.addActionListener(this);
101
102 JButton cancelButton = new JButton(Translatrix.getTranslationString("DialogCancel"));
103 cancelButton.setActionCommand("cancel");
104 cancelButton.addActionListener(this);
105
106 buttonPanel.add(saveButton);
107 buttonPanel.add(cancelButton);
108
109 contentPane.add(centerPanel);
110 contentPane.add(buttonPanel);
111
112 this.pack();
113 this.setVisible(true);
114 }
115
116 public String getInputText()
117 {
118 return returnSymbol;
119 }
120
121 }
122