| 1 | /*\r |
| 2 | GNU Lesser General Public License\r |
| 3 | \r |
| 4 | SymbolInputDialog\r |
| 5 | Copyright (C) 2000-2003 Howard Kistler\r |
| 6 | \r |
| 7 | This library is free software; you can redistribute it and/or\r |
| 8 | modify it under the terms of the GNU Lesser General Public\r |
| 9 | License as published by the Free Software Foundation; either\r |
| 10 | version 2.1 of the License, or (at your option) any later version.\r |
| 11 | \r |
| 12 | This library is distributed in the hope that it will be useful,\r |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of\r |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r |
| 15 | Lesser General Public License for more details.\r |
| 16 | \r |
| 17 | You should have received a copy of the GNU Lesser General Public\r |
| 18 | License along with this library; if not, write to the Free Software\r |
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r |
| 20 | */\r |
| 21 | \r |
| 22 | package com.hexidec.ekit.component;\r |
| 23 | \r |
| 24 | import com.hexidec.ekit.EkitCore;\r |
| 25 | import com.hexidec.util.Translatrix;\r |
| 26 | import java.awt.Container;\r |
| 27 | import java.awt.GridLayout;\r |
| 28 | import java.awt.event.ActionEvent;\r |
| 29 | import java.awt.event.ActionListener;\r |
| 30 | import javax.swing.border.*;\r |
| 31 | import javax.swing.BoxLayout;\r |
| 32 | import javax.swing.JButton;\r |
| 33 | import javax.swing.JToggleButton;\r |
| 34 | import javax.swing.ButtonGroup;\r |
| 35 | import javax.swing.JDialog;\r |
| 36 | import javax.swing.JPanel;\r |
| 37 | import javax.swing.WindowConstants;\r |
| 38 | import javax.swing.SwingConstants;\r |
| 39 | \r |
| 40 | public 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 |