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: import java.util.Vector;
012:
013: import javax.swing.*;
014:
015: import com.ibm.rbm.*;
016:
017: /**
018: */
019: class RBProjectItemPanel extends JPanel implements ActionListener {
020: RBManagerGUI gui;
021:
022: // Visual Components
023: Box mainBox;
024: JTextField itemFields[];
025: JLabel itemLabels[];
026: JButton commitButtons[];
027: JButton commitButton;
028: JLabel titleLabel;
029: JLabel keyLabel;
030: JLabel commentLabel;
031:
032: public RBProjectItemPanel(RBManagerGUI gui) {
033: super ();
034: this .gui = gui;
035: initComponents();
036: }
037:
038: public void actionPerformed(ActionEvent ev) {
039: JButton button = (JButton) ev.getSource();
040: String buttonName = button.getName();
041: if (buttonName == null) {
042: // Save all components
043: RBManager bundle = gui.getSelectedProjectBundle();
044: Vector bundles = bundle.getBundles();
045: for (int i = 0; i < itemFields.length; i++) {
046: String encoding = commitButtons[i].getName();
047: String translation = itemFields[i].getText();
048: String key = itemFields[i].getName();
049: for (int j = 0; j < bundles.size(); j++) {
050: Bundle rbundle = (Bundle) bundles.elementAt(j);
051: if (rbundle.encoding.equals(encoding)) {
052: BundleItem item = rbundle.getBundleItem(key);
053: if (item != null)
054: item.setTranslation(translation);
055: break;
056: }
057: }
058: }
059: gui.saveResources(bundle);
060: } else {
061: // Save a particular encoding
062: String encoding = buttonName;
063: RBManager bundle = gui.getSelectedProjectBundle();
064: int index = -1;
065: for (int i = 0; i < commitButtons.length; i++) {
066: if (commitButtons[i] == button) {
067: index = i;
068: break;
069: }
070: }
071: String translation = itemFields[index].getText();
072: String key = itemFields[index].getName();
073: Vector bundles = bundle.getBundles();
074: for (int i = 0; i < bundles.size(); i++) {
075: Bundle rbundle = (Bundle) bundles.elementAt(i);
076: if (rbundle.encoding.equals(encoding)) {
077: BundleItem item = rbundle.getBundleItem(key);
078: if (item != null) {
079: item.setTranslation(translation);
080: RBManagerGUI.debugMsg("Set translation to : "
081: + translation);
082: } else
083: RBManagerGUI.debugMsg("Item was null");
084: break;
085: }
086: RBManagerGUI.debugMsg("Compared " + rbundle.encoding
087: + " with " + encoding);
088: }
089: gui.saveResources(bundle, encoding);
090: }
091: updateComponents();
092: }
093:
094: private void initComponents() {
095: setLayout(new BorderLayout());
096: JPanel topPanel = new JPanel(new GridLayout(2, 1));
097: titleLabel = new JLabel(Resources
098: .getTranslation("project_panel_default_title"),
099: SwingConstants.CENTER);
100: titleLabel.setFont(new Font("serif", Font.BOLD, 18));
101: JPanel commentPanel = new JPanel(new GridLayout(2, 1));
102: JLabel commentLabel2 = new JLabel(Resources
103: .getTranslation("project_panel_comment"),
104: SwingConstants.LEFT);
105: commentLabel = new JLabel(Resources
106: .getTranslation("project_panel_comment_none"),
107: SwingConstants.LEFT);
108: commentPanel.add(commentLabel2);
109: commentPanel.add(commentLabel);
110: topPanel.add(titleLabel);
111: topPanel.add(commentPanel);
112: JPanel centerPanel = new JPanel(new BorderLayout());
113: mainBox = new Box(BoxLayout.Y_AXIS);
114: JScrollPane scrollPane = new JScrollPane(mainBox,
115: ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
116: ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
117: centerPanel.add(scrollPane, BorderLayout.NORTH);
118: centerPanel.setBorder(BorderFactory.createEtchedBorder());
119: JPanel botPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
120: commitButton = new JButton(Resources
121: .getTranslation("project_panel_commit_button_all"));
122: commitButton.addActionListener(this );
123: botPanel.add(commitButton);
124: add(topPanel, BorderLayout.NORTH);
125: add(centerPanel, BorderLayout.CENTER);
126: add(botPanel, BorderLayout.SOUTH);
127:
128: updateComponents();
129: }
130:
131: public void updateComponents() {
132: BundleItem item = gui.getSelectedProjectBundleItem();
133:
134: if (item == null) {
135: commentLabel.setText(Resources
136: .getTranslation("project_panel_comment_none"));
137: titleLabel.setText(Resources
138: .getTranslation("project_panel_default_title"));
139: itemFields = null;
140: itemLabels = null;
141: commitButtons = null;
142: commitButton.setEnabled(false);
143: } else {
144: String comment = item.getComment();
145: String key = item.getKey();
146: commentLabel.setText(comment);
147: titleLabel.setText(Resources.getTranslation(
148: "project_panel_title", key));
149:
150: RBManager manager = gui.getSelectedProjectBundle();
151: Vector bundles = manager.getBundles();
152: itemFields = new JTextField[bundles.size()];
153: itemLabels = new JLabel[bundles.size()];
154: commitButtons = new JButton[bundles.size()];
155: for (int i = 0; i < bundles.size(); i++) {
156: Bundle bundle = (Bundle) bundles.elementAt(i);
157: BundleItem bundleItem = bundle.getBundleItem(key);
158: //boolean translated = bundleItem.isTranslated();
159: JLabel encodingLabel = new JLabel(Resources
160: .getTranslation("project_panel_bundle", bundle
161: .toString()), SwingConstants.LEFT);
162: if (bundleItem == null || !bundleItem.isTranslated()) {
163: encodingLabel.setText(Resources.getTranslation(
164: "project_panel_bundle_untranslated", bundle
165: .toString()));
166: }
167: String fieldText = (bundleItem == null ? Resources
168: .getTranslation("project_panel_item_inherits")
169: : bundleItem.getTranslation());
170: JTextField itemField = new JTextField(fieldText);
171: itemField.setMaximumSize(new Dimension(
172: this .getSize().width - 150, 200));
173: itemField.setName(key);
174: JButton commitItemButton = new JButton(Resources
175: .getTranslation("project_panel_commit_button"));
176: commitItemButton.addActionListener(this );
177: commitItemButton.setName(bundle.encoding);
178: itemFields[i] = itemField;
179: itemLabels[i] = encodingLabel;
180: commitButtons[i] = commitItemButton;
181: }
182: commitButton.setEnabled(true);
183: }
184:
185: mainBox.removeAll();
186: if (itemFields != null) {
187: for (int i = 0; i < itemFields.length; i++) {
188: JPanel bundlePanel = new JPanel(new BorderLayout());
189: bundlePanel.setBorder(BorderFactory
190: .createLineBorder(Color.darkGray));
191: bundlePanel.add(itemLabels[i], BorderLayout.NORTH);
192: bundlePanel.add(itemFields[i], BorderLayout.CENTER);
193: bundlePanel.add(commitButtons[i], BorderLayout.EAST);
194: mainBox.add(bundlePanel);
195: }
196: }
197:
198: revalidate();
199: }
200: }
|