001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.cleverphl.gui;
025:
026: import jacareto.cleverphl.CleverPHL;
027: import jacareto.system.Customization;
028: import jacareto.system.Language;
029:
030: import java.awt.BorderLayout;
031: import java.awt.GridBagConstraints;
032: import java.awt.GridBagLayout;
033: import java.awt.Point;
034: import java.awt.event.ActionEvent;
035: import java.awt.event.ActionListener;
036:
037: import javax.swing.JButton;
038: import javax.swing.JCheckBox;
039: import javax.swing.JDialog;
040: import javax.swing.JPanel;
041: import javax.swing.border.EmptyBorder;
042:
043: /**
044: * Dialog for editing the key event mask.
045: *
046: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
047: * @version 1.0
048: */
049: public class KeyEventMaskDialog extends JDialog {
050: /** CleverPHL. */
051: private CleverPHL cleverPHL;
052:
053: /** The checkbox for "key pressed". */
054: private JCheckBox keyPressedChkBox;
055:
056: /** The checkbox for "key released". */
057: private JCheckBox keyReleasedChkBox;
058:
059: /** The checkbox for "key typed". */
060: private JCheckBox keyTypedChkBox;
061:
062: /**
063: * Creates a new KeyEventMaskDialog ( initially visible ).
064: *
065: * @param cleverPHL the CleverPHL instance
066: */
067: public KeyEventMaskDialog(CleverPHL cleverPHL) {
068: super (cleverPHL.getMainFrame(), true);
069: this .cleverPHL = cleverPHL;
070: setName(cleverPHL.getCustomization().getString(
071: "Components.JacaretoComponent", "JACARETO_COMPONENT"));
072:
073: Language language = cleverPHL.getLanguage();
074:
075: setTitle(language
076: .getString("CleverPHL.KeyEventMaskDialog.Title"));
077:
078: JPanel chkBoxPanel = new JPanel();
079: chkBoxPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
080: chkBoxPanel.setLayout(new GridBagLayout());
081:
082: GridBagConstraints c = new GridBagConstraints();
083:
084: // key pressed checkbox
085: keyPressedChkBox = new JCheckBox(language
086: .getString("Events.KeyEvent.KeyPressed"));
087: c.gridx = 0;
088: c.gridy = 0;
089: c.gridwidth = 2;
090: c.gridheight = 1;
091: c.anchor = GridBagConstraints.WEST;
092: chkBoxPanel.add(keyPressedChkBox, c);
093:
094: // key released checkbox
095: keyReleasedChkBox = new JCheckBox(language
096: .getString("Events.KeyEvent.KeyReleased"));
097: c.gridy = 1;
098: chkBoxPanel.add(keyReleasedChkBox, c);
099:
100: // key typed checkbox
101: keyTypedChkBox = new JCheckBox(language
102: .getString("Events.KeyEvent.KeyTypedAWT"));
103: c.gridy = 2;
104: chkBoxPanel.add(keyTypedChkBox, c);
105:
106: // The panel with the two buttons
107: JPanel buttonPanel = new JPanel();
108: JButton okButton = new JButton(language.getString("General.Ok"));
109: okButton.addActionListener(new ActionListener() {
110: public void actionPerformed(ActionEvent e) {
111: changeCustomization();
112: dispose();
113: }
114: });
115:
116: JButton cancelButton = new JButton(language
117: .getString("General.Cancel"));
118: cancelButton.addActionListener(new ActionListener() {
119: public void actionPerformed(ActionEvent e) {
120: dispose();
121: }
122: });
123: buttonPanel.add(okButton);
124: buttonPanel.add(cancelButton);
125: buttonPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
126:
127: applyCustomization();
128:
129: // Add all to the content pane
130: getContentPane().setLayout(new BorderLayout());
131: getContentPane().add(chkBoxPanel, BorderLayout.NORTH);
132: getContentPane().add(buttonPanel, BorderLayout.CENTER);
133:
134: setResizable(false);
135: pack();
136:
137: Point ownerLoc = cleverPHL.getMainFrame().getLocation();
138: setLocation(((int) ownerLoc.getX()) + 30, ((int) ownerLoc
139: .getY()) + 30);
140:
141: setVisible(true);
142: }
143:
144: /**
145: * Apply the customization.
146: */
147: private void applyCustomization() {
148: Customization customization = cleverPHL.getCustomization();
149: keyPressedChkBox.setSelected(customization.getBoolean(
150: "KeyEventMask.Include.KeyPressed", false));
151: keyReleasedChkBox.setSelected(customization.getBoolean(
152: "KeyEventMask.Include.KeyReleased", false));
153: keyTypedChkBox.setSelected(customization.getBoolean(
154: "KeyEventMask.Include.KeyTyped", false));
155: }
156:
157: /**
158: * Change the customization.
159: */
160: void changeCustomization() {
161: Customization customization = cleverPHL.getCustomization();
162: customization.put("KeyEventMask.Include.KeyPressed",
163: keyPressedChkBox.isSelected());
164: customization.put("KeyEventMask.Include.KeyReleased",
165: keyReleasedChkBox.isSelected());
166: customization.put("KeyEventMask.Include.KeyTyped",
167: keyTypedChkBox.isSelected());
168: }
169: }
|