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: import javax.swing.text.JTextComponent;
014:
015: import com.ibm.rbm.*;
016:
017: /**
018: * The class used to display statistics
019: */
020: class RBStatisticsPanel extends JPanel {
021: RBManager rbm;
022: Bundle bundle;
023:
024: // Components - Bundle
025: JLabel jLabelStatsTitle;
026:
027: JLabel jLabelStatsName;
028: JLabel jLabelStatsComment;
029: JLabel jLabelStatsManager;
030: JLabel jLabelStatsLanguage;
031: JLabel jLabelStatsCountry;
032: JLabel jLabelStatsVariant;
033: JLabel jLabelStatsNumTrans;
034: JLabel jLabelStatsNumUntrans;
035:
036: JTextField jTextFieldStatsName;
037: JTextField jTextFieldStatsComment;
038: JTextField jTextFieldStatsManager;
039: JTextField jTextFieldStatsLanguage;
040: JTextField jTextFieldStatsCountry;
041: JTextField jTextFieldStatsVariant;
042:
043: JButton updateButton;
044:
045: Box boxStatsLeftRight1;
046: Box boxStatsLeftRight2;
047:
048: // Components - bundle manager
049: JLabel titleLabel;
050: JLabel numFileLabel;
051: JLabel numDupLabel;
052: JLabel numGroupLabel;
053: JLabel numItemLabel;
054:
055: JList groupList;
056: JList fileList;
057: JList dupList;
058:
059: JScrollPane groupScroll;
060: JScrollPane dupScroll;
061: JScrollPane fileScroll;
062:
063: JPanel filePanel;
064: JPanel itemPanel;
065: JPanel groupPanel;
066:
067: JButton fileButton;
068: JButton groupButton;
069: JButton itemButton;
070:
071: Box mainBox;
072: Box dupBox;
073:
074: public void setBundle(Bundle b) {
075: rbm = null;
076: if (bundle == null) {
077: bundle = b;
078: initComponents();
079: } else if (bundle != b) {
080: bundle = b;
081: updateComponents();
082: }
083: }
084:
085: public void setManager(RBManager m) {
086: bundle = null;
087: if (rbm == null) {
088: rbm = m;
089: initComponents();
090: } else if (rbm != m) {
091: rbm = m;
092: updateComponents();
093: }
094: }
095:
096: public void removeElements() {
097: if (rbm != null || bundle != null) {
098: rbm = null;
099: bundle = null;
100: initComponents();
101: }
102: }
103:
104: public void initComponents() {
105: // Initialize components
106: if (bundle != null) {
107: RBManagerGUI
108: .debugMsg("Initializing components for Resource File");
109: int untranslated = bundle.getUntranslatedItemsSize();
110:
111: jLabelStatsTitle = new JLabel(bundle.name);
112:
113: jLabelStatsName = new JLabel(Resources
114: .getTranslation("languagestats_title"));
115: jLabelStatsComment = new JLabel(Resources
116: .getTranslation("languagestats_comment"));
117: jLabelStatsManager = new JLabel(Resources
118: .getTranslation("languagestats_manager"));
119: jLabelStatsLanguage = new JLabel(Resources
120: .getTranslation("languagestats_language"));
121: jLabelStatsCountry = new JLabel(Resources
122: .getTranslation("languagestats_country"));
123: jLabelStatsVariant = new JLabel(Resources
124: .getTranslation("languagestats_variant"));
125: jLabelStatsNumTrans = new JLabel(Resources
126: .getTranslation("languagestats_item_count")
127: + " " + String.valueOf(bundle.allItems.size()));
128: jLabelStatsNumUntrans = new JLabel(Resources
129: .getTranslation("languagestats_translation_count")
130: + String.valueOf(untranslated));
131:
132: jTextFieldStatsName = new JTextField(
133: (bundle.name == null ? Resources
134: .getTranslation("untitled") : bundle.name));
135: jTextFieldStatsComment = new JTextField(
136: (bundle.comment == null ? "" : bundle.comment));
137: jTextFieldStatsManager = new JTextField(
138: (bundle.manager == null ? "" : bundle.manager));
139: jTextFieldStatsLanguage = new JTextField(
140: (bundle.language == null ? "" : bundle.language),
141: 25);
142: jTextFieldStatsCountry = new JTextField(
143: (bundle.country == null ? "" : bundle.country), 25);
144: jTextFieldStatsVariant = new JTextField(
145: (bundle.variant == null ? "" : bundle.variant), 25);
146:
147: boxStatsLeftRight1 = new Box(BoxLayout.X_AXIS);
148: boxStatsLeftRight2 = new Box(BoxLayout.X_AXIS);
149:
150: updateButton = new JButton(Resources
151: .getTranslation("button_update"));
152: updateButton.setMnemonic(RBManagerMenuBar
153: .getKeyEventKey(Resources
154: .getTranslation("button_update_trigger")));
155:
156: // Set up the components
157: jLabelStatsTitle.setFont(new Font("SansSerif", Font.PLAIN,
158: 18));
159:
160: ButtonEnablerFocusListener befl = new ButtonEnablerFocusListener(
161: updateButton);
162:
163: // Add listeners
164: updateButton.addActionListener(new ActionListener() {
165: public void actionPerformed(ActionEvent ev) {
166: updateBundleInfo();
167: }
168: });
169:
170: jTextFieldStatsName.addFocusListener(befl);
171: jTextFieldStatsComment.addFocusListener(befl);
172: jTextFieldStatsManager.addFocusListener(befl);
173: jTextFieldStatsLanguage.addFocusListener(befl);
174: jTextFieldStatsCountry.addFocusListener(befl);
175: jTextFieldStatsVariant.addFocusListener(befl);
176:
177: jTextFieldStatsName.setColumns(35);
178: jTextFieldStatsComment.setColumns(35);
179: jTextFieldStatsManager.setColumns(35);
180: jTextFieldStatsLanguage.setColumns(25);
181: jTextFieldStatsCountry.setColumns(25);
182: jTextFieldStatsVariant.setColumns(25);
183:
184: //updateButton.setEnabled(false);
185:
186: // Update the display
187: if (mainBox != null) {
188: mainBox.removeAll();
189: } else {
190: mainBox = new Box(BoxLayout.Y_AXIS);
191: }
192: if (dupBox != null)
193: dupBox.removeAll();
194: removeAll();
195: mainBox.add(jLabelStatsTitle);
196: mainBox.add(Box.createVerticalStrut(10));
197: mainBox.add(jLabelStatsName);
198: mainBox.add(jTextFieldStatsName);
199: mainBox.add(Box.createVerticalStrut(5));
200: mainBox.add(jLabelStatsComment);
201: mainBox.add(jTextFieldStatsComment);
202: mainBox.add(Box.createVerticalStrut(5));
203: mainBox.add(jLabelStatsManager);
204: mainBox.add(jTextFieldStatsManager);
205: mainBox.add(Box.createVerticalStrut(5));
206: mainBox.add(jLabelStatsLanguage);
207: mainBox.add(jTextFieldStatsLanguage);
208: mainBox.add(Box.createVerticalStrut(5));
209: mainBox.add(jLabelStatsCountry);
210: mainBox.add(jTextFieldStatsCountry);
211: mainBox.add(Box.createVerticalStrut(5));
212: mainBox.add(jLabelStatsVariant);
213: mainBox.add(jTextFieldStatsVariant);
214: mainBox.add(Box.createVerticalStrut(5));
215: mainBox.add(jLabelStatsNumTrans);
216: mainBox.add(Box.createVerticalStrut(5));
217: mainBox.add(jLabelStatsNumUntrans);
218: mainBox.add(Box.createVerticalStrut(10));
219: mainBox.add(updateButton);
220: mainBox.add(Box.createHorizontalGlue());
221: if (!(getLayout() instanceof FlowLayout)) {
222: setLayout(new FlowLayout());
223: }
224: add(mainBox);
225: } else if (rbm != null) {
226: RBManagerGUI
227: .debugMsg("Initializing components for Resource Bundle");
228: titleLabel = new JLabel(rbm.getBaseClass() + " - "
229: + Resources.getTranslation("baseclass"));
230:
231: numFileLabel = new JLabel(Resources
232: .getTranslation("basestats_file_count")
233: + " " + rbm.getNumberLanguages());
234: numGroupLabel = new JLabel(Resources
235: .getTranslation("basestats_group_count")
236: + " " + rbm.getNumberGroups());
237: numItemLabel = new JLabel(Resources
238: .getTranslation("basestats_item_count")
239: + " " + rbm.getNumberTotalTranslations());
240: numDupLabel = new JLabel(Resources
241: .getTranslation("basestats_duplicates_count")
242: + " " + rbm.getNumberDuplicates());
243:
244: fileList = new JList(rbm.getLanguageListingVector());
245: groupList = new JList(rbm.getGroupListingVector());
246: dupList = new JList(rbm.getDuplicatesListingVector());
247:
248: fileButton = new JButton(Resources
249: .getTranslation("button_add_file"));
250: groupButton = new JButton(Resources
251: .getTranslation("button_add_group"));
252: itemButton = new JButton(Resources
253: .getTranslation("button_add_resource"));
254:
255: filePanel = new JPanel();
256: groupPanel = new JPanel();
257: itemPanel = new JPanel();
258:
259: fileScroll = new JScrollPane(fileList);
260: groupScroll = new JScrollPane(groupList);
261: dupScroll = new JScrollPane(dupList);
262:
263: if (mainBox == null) {
264: mainBox = new Box(BoxLayout.Y_AXIS);
265: } else {
266: mainBox.removeAll();
267: }
268: dupBox = new Box(BoxLayout.Y_AXIS);
269:
270: // Set up the components
271: filePanel.setLayout(new BorderLayout());
272: groupPanel.setLayout(new BorderLayout());
273: itemPanel.setLayout(new BorderLayout());
274:
275: filePanel.setBorder(BorderFactory.createTitledBorder(
276: BorderFactory.createEtchedBorder(), Resources
277: .getTranslation("basestats_file_group")));
278: groupPanel.setBorder(BorderFactory.createTitledBorder(
279: BorderFactory.createEtchedBorder(), Resources
280: .getTranslation("basestats_group_group")));
281: itemPanel.setBorder(BorderFactory.createTitledBorder(
282: BorderFactory.createEtchedBorder(), Resources
283: .getTranslation("basestats_item_group")));
284:
285: titleLabel.setFont(new Font("SansSerif", Font.PLAIN, 18));
286:
287: fileButton
288: .setMnemonic(RBManagerMenuBar
289: .getKeyEventKey(Resources
290: .getTranslation("button_add_file_trigger")));
291: groupButton
292: .setMnemonic(RBManagerMenuBar
293: .getKeyEventKey(Resources
294: .getTranslation("button_add_group_trigger")));
295: itemButton
296: .setMnemonic(RBManagerMenuBar
297: .getKeyEventKey(Resources
298: .getTranslation("button_add_resource_trigger")));
299:
300: // Add listeners
301: fileButton.addActionListener(new ActionListener() {
302: public void actionPerformed(ActionEvent ev) {
303: Container c = ((JButton) ev.getSource())
304: .getParent();
305: RBManagerGUI gui = null;
306: while (!(c.getParent() instanceof RBManagerGUI))
307: c = c.getParent();
308: gui = (RBManagerGUI) c.getParent();
309: gui.createResourceFile();
310: }
311: });
312:
313: groupButton.addActionListener(new ActionListener() {
314: public void actionPerformed(ActionEvent ev) {
315: Container c = ((JButton) ev.getSource())
316: .getParent();
317: RBManagerGUI gui = null;
318: while (!(c.getParent() instanceof RBManagerGUI))
319: c = c.getParent();
320: gui = (RBManagerGUI) c.getParent();
321: gui.createBundleGroup();
322: }
323: });
324:
325: itemButton.addActionListener(new ActionListener() {
326: public void actionPerformed(ActionEvent ev) {
327: Container c = ((JButton) ev.getSource())
328: .getParent();
329: RBManagerGUI gui = null;
330: while (!(c.getParent() instanceof RBManagerGUI))
331: c = c.getParent();
332: gui = (RBManagerGUI) c.getParent();
333: gui.createBundleItem();
334: }
335: });
336:
337: // Update the display
338: filePanel.removeAll();
339: filePanel.add(numFileLabel, BorderLayout.NORTH);
340: filePanel.add(fileScroll, BorderLayout.CENTER);
341: filePanel.add(fileButton, BorderLayout.SOUTH);
342:
343: groupPanel.removeAll();
344: groupPanel.add(numGroupLabel, BorderLayout.NORTH);
345: groupPanel.add(groupScroll, BorderLayout.CENTER);
346: groupPanel.add(groupButton, BorderLayout.SOUTH);
347:
348: dupBox.removeAll();
349: dupBox.add(numDupLabel);
350: dupBox.add(dupScroll);
351:
352: itemPanel.removeAll();
353: itemPanel.add(numItemLabel, BorderLayout.NORTH);
354: itemPanel.add(dupBox, BorderLayout.CENTER);
355: itemPanel.add(itemButton, BorderLayout.SOUTH);
356:
357: mainBox.removeAll();
358: mainBox.add(titleLabel);
359: mainBox.add(Box.createVerticalStrut(10));
360: mainBox.add(filePanel);
361: mainBox.add(Box.createVerticalStrut(10));
362: mainBox.add(groupPanel);
363: mainBox.add(Box.createVerticalStrut(10));
364: mainBox.add(itemPanel);
365:
366: removeAll();
367: if (!(getLayout() instanceof BorderLayout))
368: setLayout(new BorderLayout());
369: add(mainBox, BorderLayout.CENTER);
370: updateComponents();
371: } else {
372: removeAll();
373: }
374: repaint();
375: }
376:
377: public void updateComponents() {
378: if (bundle != null) {
379: int untranslated = bundle.getUntranslatedItemsSize();
380:
381: jLabelStatsTitle.setText(bundle.name);
382:
383: jTextFieldStatsName.setText(bundle.name == null ? Resources
384: .getTranslation("untitled") : bundle.name);
385: jTextFieldStatsComment.setText(bundle.comment == null ? ""
386: : bundle.comment);
387: jTextFieldStatsManager.setText(bundle.manager == null ? ""
388: : bundle.manager);
389: jTextFieldStatsLanguage
390: .setText(bundle.language == null ? ""
391: : bundle.language);
392: jTextFieldStatsCountry.setText(bundle.country == null ? ""
393: : bundle.country);
394: jTextFieldStatsVariant.setText(bundle.variant == null ? ""
395: : bundle.variant);
396: jLabelStatsNumTrans.setText(Resources
397: .getTranslation("languagestats_item_count")
398: + " " + String.valueOf(bundle.allItems.size()));
399: jLabelStatsNumUntrans.setText(Resources
400: .getTranslation("languagestats_translation_count")
401: + String.valueOf(untranslated));
402: } else if (rbm == null) {
403: removeAll();
404: }
405:
406: }
407:
408: void updateBundleInfo() {
409: bundle.name = jTextFieldStatsName.getText().trim();
410: bundle.comment = jTextFieldStatsComment.getText().trim();
411: bundle.manager = jTextFieldStatsManager.getText().trim();
412: bundle.language = jTextFieldStatsLanguage.getText().trim();
413: bundle.country = jTextFieldStatsCountry.getText().trim();
414: bundle.variant = jTextFieldStatsVariant.getText().trim();
415: updateButton.setEnabled(false);
416: }
417:
418: public RBStatisticsPanel() {
419: super ();
420: bundle = null;
421: rbm = null;
422: }
423:
424: }
425:
426: class ButtonEnablerFocusListener implements FocusListener {
427: JButton button;
428: String beforeText = null;
429:
430: public ButtonEnablerFocusListener(JButton button) {
431: super ();
432: this .button = button;
433: }
434:
435: public void focusGained(FocusEvent ev) {
436: Object o = ev.getSource();
437: if (o instanceof JTextComponent) {
438: JTextComponent jtc = (JTextComponent) o;
439: beforeText = jtc.getText();
440: }
441: }
442:
443: public void focusLost(FocusEvent ev) {
444: Object o = ev.getSource();
445: if (o instanceof JTextComponent) {
446: JTextComponent jtc = (JTextComponent) o;
447: String afterText = jtc.getText();
448: if (!afterText.equals(beforeText))
449: button.setEnabled(true);
450: } else
451: button.setEnabled(true);
452: }
453: }
|