001: /*
002: *****************************************************************************
003: * Copyright (C) 2000-2004, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *****************************************************************************
006: */
007: package com.ibm.rbm.gui;
008:
009: import java.awt.*;
010: import java.awt.event.*;
011:
012: import javax.swing.*;
013:
014: import com.ibm.rbm.*;
015:
016: /**
017: * A dialog for creating new Resource Files
018: */
019: class ResourceCreationDialog extends JDialog {
020: RBManager rbm;
021: RBManagerGUI gui;
022:
023: // Components
024: Box mainBox = new Box(BoxLayout.Y_AXIS);
025: Box infoBox = new Box(BoxLayout.Y_AXIS);
026: JPanel infoPanel = new JPanel();
027: JPanel infoTitlePanel = new JPanel();
028: JPanel infoCommentPanel = new JPanel();
029: JPanel infoManagerPanel = new JPanel();
030: JPanel langPanel = new JPanel();
031: JPanel counPanel = new JPanel();
032: JPanel variPanel = new JPanel();
033: JPanel buttPanel = new JPanel();
034:
035: JLabel instructionsLabel = new JLabel("");
036: JLabel titleLabel = new JLabel(Resources
037: .getTranslation("dialog_file_title"));
038: JLabel commentLabel = new JLabel(Resources
039: .getTranslation("dialog_file_comment"));
040: JLabel managerLabel = new JLabel(Resources
041: .getTranslation("dialog_file_manager"));
042: JLabel enc1Label = new JLabel(Resources
043: .getTranslation("dialog_encoding"));
044: JLabel enc2Label = new JLabel(Resources
045: .getTranslation("dialog_encoding"));
046: JLabel enc3Label = new JLabel(Resources
047: .getTranslation("dialog_encoding"));
048: JLabel nam1Label = new JLabel(Resources
049: .getTranslation("dialog_name"));
050: JLabel nam2Label = new JLabel(Resources
051: .getTranslation("dialog_name"));
052: JLabel nam3Label = new JLabel(Resources
053: .getTranslation("dialog_name"));
054:
055: JTextField titleField = new JTextField("");
056: JTextField commentField = new JTextField("");
057: JTextField managerField = new JTextField("");
058: JTextField enc1Field = new JTextField("");
059: JTextField enc2Field = new JTextField("");
060: JTextField enc3Field = new JTextField("");
061: JTextField nam1Field = new JTextField("");
062: JTextField nam2Field = new JTextField("");
063: JTextField nam3Field = new JTextField("");
064:
065: JCheckBox copyCheckBox = new JCheckBox(Resources
066: .getTranslation("dialog_checkbox_copy_elements"), true);
067:
068: JButton createButton = new JButton(Resources
069: .getTranslation("button_create"));
070: JButton cancelButton = new JButton(Resources
071: .getTranslation("button_cancel"));
072:
073: public ResourceCreationDialog(RBManager rbm, JFrame frame,
074: String title, boolean modal) {
075: super (frame, title, modal);
076: this .gui = (RBManagerGUI) frame;
077: this .rbm = rbm;
078: initComponents();
079: enableEvents(AWTEvent.KEY_EVENT_MASK);
080: }
081:
082: protected void processKeyEvent(KeyEvent ev) {
083: if (ev.getKeyCode() == KeyEvent.VK_ENTER) {
084: boolean success = createResource();
085: if (!success) {
086: String alert = Resources
087: .getTranslation("error_create_file")
088: + " "
089: + Resources
090: .getTranslation("error_try_again_file");
091: JOptionPane.showMessageDialog(this , alert, Resources
092: .getTranslation("error"),
093: JOptionPane.ERROR_MESSAGE);
094: } else {
095: setVisible(false);
096: dispose();
097: }
098: } else if (ev.getKeyCode() == KeyEvent.VK_CANCEL) {
099: closeWindow();
100: }
101: }
102:
103: boolean createResource() {
104: if (rbm == null)
105: return false;
106: String encoding = enc1Field.getText().trim();
107: String enc2 = enc2Field.getText().trim();
108: if (enc2 != null && !enc2.equals(""))
109: encoding += "_" + enc2;
110: String enc3 = enc3Field.getText().trim();
111: if (enc3 != null && !enc3.equals(""))
112: encoding += "_" + enc3;
113: boolean ret = rbm.createResource(titleField.getText().trim(),
114: commentField.getText().trim(), managerField.getText()
115: .trim(), encoding, nam1Field.getText().trim(),
116: nam2Field.getText().trim(), nam3Field.getText().trim(),
117: copyCheckBox.isSelected());
118: if (ret) {
119: gui.updateDisplayTree();
120: gui.updateProjectTree();
121: gui.updateProjectPanels();
122: }
123: return ret;
124: }
125:
126: public void initComponents() {
127: // Error check
128: if (rbm == null) {
129: String alert = Resources
130: .getTranslation("error_no_bundle_for_file");
131: JOptionPane
132: .showMessageDialog(this , alert, Resources
133: .getTranslation("error"),
134: JOptionPane.ERROR_MESSAGE);
135: closeWindow();
136: return;
137: }
138:
139: // Initialize values
140: int tempWidth = 175;
141: Dimension labelDim = new Dimension(tempWidth, 30);
142: titleLabel.setPreferredSize(labelDim);
143: commentLabel.setPreferredSize(labelDim);
144: managerLabel.setPreferredSize(labelDim);
145:
146: infoPanel.setBorder(BorderFactory.createTitledBorder(
147: BorderFactory.createEtchedBorder(), Resources
148: .getTranslation("dialog_file_info")));
149: langPanel.setBorder(BorderFactory.createTitledBorder(
150: BorderFactory.createEtchedBorder(), Resources
151: .getTranslation("dialog_language")));
152: counPanel.setBorder(BorderFactory.createTitledBorder(
153: BorderFactory.createEtchedBorder(), Resources
154: .getTranslation("dialog_country")));
155: variPanel.setBorder(BorderFactory.createTitledBorder(
156: BorderFactory.createEtchedBorder(), Resources
157: .getTranslation("dialog_variant")));
158:
159: titleField.setColumns(30);
160: commentField.setColumns(30);
161: managerField.setColumns(30);
162:
163: enc1Field.setColumns(3);
164: enc2Field.setColumns(3);
165: enc3Field.setColumns(3);
166: nam1Field.setColumns(20);
167: nam2Field.setColumns(20);
168: nam3Field.setColumns(20);
169:
170: // Set up the components
171: infoTitlePanel.add(titleLabel);
172: infoTitlePanel.add(titleField);
173: infoCommentPanel.add(commentLabel);
174: infoCommentPanel.add(commentField);
175: infoManagerPanel.add(managerLabel);
176: infoManagerPanel.add(managerField);
177: infoBox.add(infoTitlePanel);
178: infoBox.add(infoCommentPanel);
179: infoBox.add(infoManagerPanel);
180: infoPanel.add(infoBox);
181:
182: langPanel.add(enc1Label);
183: langPanel.add(enc1Field);
184: langPanel.add(nam1Label);
185: langPanel.add(nam1Field);
186: counPanel.add(enc2Label);
187: counPanel.add(enc2Field);
188: counPanel.add(nam2Label);
189: counPanel.add(nam2Field);
190: variPanel.add(enc3Label);
191: variPanel.add(enc3Field);
192: variPanel.add(nam3Label);
193: variPanel.add(nam3Field);
194:
195: buttPanel.add(createButton);
196: buttPanel.add(cancelButton);
197:
198: // Add the appropriate listeners
199: cancelButton.addActionListener(new ActionListener() {
200: public void actionPerformed(ActionEvent ev) {
201: JDialog dialog = (JDialog) ((JButton) ev.getSource())
202: .getParent().getParent().getParent()
203: .getParent().getParent().getParent();
204: dialog.setVisible(false);
205: dialog.dispose();
206: }
207: });
208:
209: createButton.addActionListener(new ActionListener() {
210: public void actionPerformed(ActionEvent ev) {
211: ResourceCreationDialog dialog = (ResourceCreationDialog) ((JButton) ev
212: .getSource()).getParent().getParent()
213: .getParent().getParent().getParent()
214: .getParent();
215: boolean success = dialog.createResource();
216: if (!success) {
217: String alert = Resources
218: .getTranslation("error_create_file")
219: + " "
220: + Resources
221: .getTranslation("error_try_again_file");
222: JOptionPane.showMessageDialog(dialog, alert,
223: Resources.getTranslation("error"),
224: JOptionPane.ERROR_MESSAGE);
225: } else {
226: dialog.setVisible(false);
227: dialog.dispose();
228: }
229: }
230: });
231: getRootPane().setDefaultButton(createButton);
232:
233: // Complete the component layout
234: mainBox.removeAll();
235: //mainBox.add(instructionsLabel);
236: mainBox.add(infoPanel);
237: mainBox.add(langPanel);
238: mainBox.add(counPanel);
239: mainBox.add(variPanel);
240: mainBox.add(copyCheckBox);
241: mainBox.add(buttPanel);
242:
243: setLocation(new java.awt.Point(50, 50));
244: getContentPane().add(mainBox, BorderLayout.CENTER);
245: validateTree();
246: pack();
247: setVisible(true);
248: //setResizable(false);
249: }
250:
251: void closeWindow() {
252: setVisible(false);
253: dispose();
254: }
255: }
|