12e5b6d6dSopenharmony_ci/* 22e5b6d6dSopenharmony_ci ***************************************************************************** 32e5b6d6dSopenharmony_ci * Copyright (C) 2000-2004, International Business Machines Corporation and * 42e5b6d6dSopenharmony_ci * others. All Rights Reserved. * 52e5b6d6dSopenharmony_ci ***************************************************************************** 62e5b6d6dSopenharmony_ci */ 72e5b6d6dSopenharmony_cipackage com.ibm.rbm.gui; 82e5b6d6dSopenharmony_ci 92e5b6d6dSopenharmony_ciimport java.awt.*; 102e5b6d6dSopenharmony_ciimport java.awt.event.*; 112e5b6d6dSopenharmony_ciimport java.util.Vector; 122e5b6d6dSopenharmony_ci 132e5b6d6dSopenharmony_ciimport javax.swing.*; 142e5b6d6dSopenharmony_ci 152e5b6d6dSopenharmony_ciimport com.ibm.rbm.*; 162e5b6d6dSopenharmony_ci 172e5b6d6dSopenharmony_ci/** 182e5b6d6dSopenharmony_ci */ 192e5b6d6dSopenharmony_ciclass RBProjectItemPanel extends JPanel implements ActionListener { 202e5b6d6dSopenharmony_ci RBManagerGUI gui; 212e5b6d6dSopenharmony_ci 222e5b6d6dSopenharmony_ci // Visual Components 232e5b6d6dSopenharmony_ci Box mainBox; 242e5b6d6dSopenharmony_ci JTextField itemFields[]; 252e5b6d6dSopenharmony_ci JLabel itemLabels[]; 262e5b6d6dSopenharmony_ci JButton commitButtons[]; 272e5b6d6dSopenharmony_ci JButton commitButton; 282e5b6d6dSopenharmony_ci JLabel titleLabel; 292e5b6d6dSopenharmony_ci JLabel keyLabel; 302e5b6d6dSopenharmony_ci JLabel commentLabel; 312e5b6d6dSopenharmony_ci 322e5b6d6dSopenharmony_ci public RBProjectItemPanel(RBManagerGUI gui) { 332e5b6d6dSopenharmony_ci super(); 342e5b6d6dSopenharmony_ci this.gui = gui; 352e5b6d6dSopenharmony_ci initComponents(); 362e5b6d6dSopenharmony_ci } 372e5b6d6dSopenharmony_ci 382e5b6d6dSopenharmony_ci public void actionPerformed(ActionEvent ev) { 392e5b6d6dSopenharmony_ci JButton button = (JButton)ev.getSource(); 402e5b6d6dSopenharmony_ci String buttonName = button.getName(); 412e5b6d6dSopenharmony_ci if (buttonName == null) { 422e5b6d6dSopenharmony_ci // Save all components 432e5b6d6dSopenharmony_ci RBManager bundle = gui.getSelectedProjectBundle(); 442e5b6d6dSopenharmony_ci Vector bundles = bundle.getBundles(); 452e5b6d6dSopenharmony_ci for (int i=0; i < itemFields.length; i++) { 462e5b6d6dSopenharmony_ci String encoding = commitButtons[i].getName(); 472e5b6d6dSopenharmony_ci String translation = itemFields[i].getText(); 482e5b6d6dSopenharmony_ci String key = itemFields[i].getName(); 492e5b6d6dSopenharmony_ci for (int j=0; j < bundles.size(); j++) { 502e5b6d6dSopenharmony_ci Bundle rbundle = (Bundle)bundles.elementAt(j); 512e5b6d6dSopenharmony_ci if (rbundle.encoding.equals(encoding)) { 522e5b6d6dSopenharmony_ci BundleItem item = rbundle.getBundleItem(key); 532e5b6d6dSopenharmony_ci if (item != null) item.setTranslation(translation); 542e5b6d6dSopenharmony_ci break; 552e5b6d6dSopenharmony_ci } 562e5b6d6dSopenharmony_ci } 572e5b6d6dSopenharmony_ci } 582e5b6d6dSopenharmony_ci gui.saveResources(bundle); 592e5b6d6dSopenharmony_ci } else { 602e5b6d6dSopenharmony_ci // Save a particular encoding 612e5b6d6dSopenharmony_ci String encoding = buttonName; 622e5b6d6dSopenharmony_ci RBManager bundle = gui.getSelectedProjectBundle(); 632e5b6d6dSopenharmony_ci int index = -1; 642e5b6d6dSopenharmony_ci for (int i=0; i < commitButtons.length; i++) { 652e5b6d6dSopenharmony_ci if (commitButtons[i] == button) { 662e5b6d6dSopenharmony_ci index = i; 672e5b6d6dSopenharmony_ci break; 682e5b6d6dSopenharmony_ci } 692e5b6d6dSopenharmony_ci } 702e5b6d6dSopenharmony_ci String translation = itemFields[index].getText(); 712e5b6d6dSopenharmony_ci String key = itemFields[index].getName(); 722e5b6d6dSopenharmony_ci Vector bundles = bundle.getBundles(); 732e5b6d6dSopenharmony_ci for (int i=0; i < bundles.size(); i++) { 742e5b6d6dSopenharmony_ci Bundle rbundle = (Bundle)bundles.elementAt(i); 752e5b6d6dSopenharmony_ci if (rbundle.encoding.equals(encoding)) { 762e5b6d6dSopenharmony_ci BundleItem item = rbundle.getBundleItem(key); 772e5b6d6dSopenharmony_ci if (item != null) { 782e5b6d6dSopenharmony_ci item.setTranslation(translation); 792e5b6d6dSopenharmony_ci RBManagerGUI.debugMsg("Set translation to : " + translation); 802e5b6d6dSopenharmony_ci } 812e5b6d6dSopenharmony_ci else 822e5b6d6dSopenharmony_ci RBManagerGUI.debugMsg("Item was null"); 832e5b6d6dSopenharmony_ci break; 842e5b6d6dSopenharmony_ci } 852e5b6d6dSopenharmony_ci RBManagerGUI.debugMsg("Compared " + rbundle.encoding + " with " + encoding); 862e5b6d6dSopenharmony_ci } 872e5b6d6dSopenharmony_ci gui.saveResources(bundle, encoding); 882e5b6d6dSopenharmony_ci } 892e5b6d6dSopenharmony_ci updateComponents(); 902e5b6d6dSopenharmony_ci } 912e5b6d6dSopenharmony_ci 922e5b6d6dSopenharmony_ci private void initComponents() { 932e5b6d6dSopenharmony_ci setLayout(new BorderLayout()); 942e5b6d6dSopenharmony_ci JPanel topPanel = new JPanel(new GridLayout(2,1)); 952e5b6d6dSopenharmony_ci titleLabel = new JLabel(Resources.getTranslation("project_panel_default_title"), SwingConstants.CENTER); 962e5b6d6dSopenharmony_ci titleLabel.setFont(new Font("serif",Font.BOLD,18)); 972e5b6d6dSopenharmony_ci JPanel commentPanel = new JPanel(new GridLayout(2,1)); 982e5b6d6dSopenharmony_ci JLabel commentLabel2 = new JLabel(Resources.getTranslation("project_panel_comment"), SwingConstants.LEFT); 992e5b6d6dSopenharmony_ci commentLabel = new JLabel(Resources.getTranslation("project_panel_comment_none"), SwingConstants.LEFT); 1002e5b6d6dSopenharmony_ci commentPanel.add(commentLabel2); 1012e5b6d6dSopenharmony_ci commentPanel.add(commentLabel); 1022e5b6d6dSopenharmony_ci topPanel.add(titleLabel); 1032e5b6d6dSopenharmony_ci topPanel.add(commentPanel); 1042e5b6d6dSopenharmony_ci JPanel centerPanel = new JPanel(new BorderLayout()); 1052e5b6d6dSopenharmony_ci mainBox = new Box(BoxLayout.Y_AXIS); 1062e5b6d6dSopenharmony_ci JScrollPane scrollPane = new JScrollPane(mainBox, 1072e5b6d6dSopenharmony_ci ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, 1082e5b6d6dSopenharmony_ci ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); 1092e5b6d6dSopenharmony_ci centerPanel.add(scrollPane, BorderLayout.NORTH); 1102e5b6d6dSopenharmony_ci centerPanel.setBorder(BorderFactory.createEtchedBorder()); 1112e5b6d6dSopenharmony_ci JPanel botPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); 1122e5b6d6dSopenharmony_ci commitButton = new JButton(Resources.getTranslation("project_panel_commit_button_all")); 1132e5b6d6dSopenharmony_ci commitButton.addActionListener(this); 1142e5b6d6dSopenharmony_ci botPanel.add(commitButton); 1152e5b6d6dSopenharmony_ci add(topPanel, BorderLayout.NORTH); 1162e5b6d6dSopenharmony_ci add(centerPanel, BorderLayout.CENTER); 1172e5b6d6dSopenharmony_ci add(botPanel, BorderLayout.SOUTH); 1182e5b6d6dSopenharmony_ci 1192e5b6d6dSopenharmony_ci updateComponents(); 1202e5b6d6dSopenharmony_ci } 1212e5b6d6dSopenharmony_ci 1222e5b6d6dSopenharmony_ci public void updateComponents() { 1232e5b6d6dSopenharmony_ci BundleItem item = gui.getSelectedProjectBundleItem(); 1242e5b6d6dSopenharmony_ci 1252e5b6d6dSopenharmony_ci if (item == null) { 1262e5b6d6dSopenharmony_ci commentLabel.setText(Resources.getTranslation("project_panel_comment_none")); 1272e5b6d6dSopenharmony_ci titleLabel.setText(Resources.getTranslation("project_panel_default_title")); 1282e5b6d6dSopenharmony_ci itemFields = null; 1292e5b6d6dSopenharmony_ci itemLabels = null; 1302e5b6d6dSopenharmony_ci commitButtons = null; 1312e5b6d6dSopenharmony_ci commitButton.setEnabled(false); 1322e5b6d6dSopenharmony_ci } else { 1332e5b6d6dSopenharmony_ci String comment = item.getComment(); 1342e5b6d6dSopenharmony_ci String key = item.getKey(); 1352e5b6d6dSopenharmony_ci commentLabel.setText(comment); 1362e5b6d6dSopenharmony_ci titleLabel.setText(Resources.getTranslation("project_panel_title", key)); 1372e5b6d6dSopenharmony_ci 1382e5b6d6dSopenharmony_ci RBManager manager = gui.getSelectedProjectBundle(); 1392e5b6d6dSopenharmony_ci Vector bundles = manager.getBundles(); 1402e5b6d6dSopenharmony_ci itemFields = new JTextField[bundles.size()]; 1412e5b6d6dSopenharmony_ci itemLabels = new JLabel[bundles.size()]; 1422e5b6d6dSopenharmony_ci commitButtons = new JButton[bundles.size()]; 1432e5b6d6dSopenharmony_ci for (int i=0; i < bundles.size(); i++) { 1442e5b6d6dSopenharmony_ci Bundle bundle = (Bundle)bundles.elementAt(i); 1452e5b6d6dSopenharmony_ci BundleItem bundleItem = bundle.getBundleItem(key); 1462e5b6d6dSopenharmony_ci //boolean translated = bundleItem.isTranslated(); 1472e5b6d6dSopenharmony_ci JLabel encodingLabel = new JLabel(Resources.getTranslation("project_panel_bundle", bundle.toString()), 1482e5b6d6dSopenharmony_ci SwingConstants.LEFT); 1492e5b6d6dSopenharmony_ci if (bundleItem == null || !bundleItem.isTranslated()) { 1502e5b6d6dSopenharmony_ci encodingLabel.setText(Resources.getTranslation("project_panel_bundle_untranslated", 1512e5b6d6dSopenharmony_ci bundle.toString())); 1522e5b6d6dSopenharmony_ci } 1532e5b6d6dSopenharmony_ci String fieldText = (bundleItem == null ? Resources.getTranslation("project_panel_item_inherits") : 1542e5b6d6dSopenharmony_ci bundleItem.getTranslation()); 1552e5b6d6dSopenharmony_ci JTextField itemField = new JTextField(fieldText); 1562e5b6d6dSopenharmony_ci itemField.setMaximumSize(new Dimension(this.getSize().width-150, 200)); 1572e5b6d6dSopenharmony_ci itemField.setName(key); 1582e5b6d6dSopenharmony_ci JButton commitItemButton = new JButton(Resources.getTranslation("project_panel_commit_button")); 1592e5b6d6dSopenharmony_ci commitItemButton.addActionListener(this); 1602e5b6d6dSopenharmony_ci commitItemButton.setName(bundle.encoding); 1612e5b6d6dSopenharmony_ci itemFields[i] = itemField; 1622e5b6d6dSopenharmony_ci itemLabels[i] = encodingLabel; 1632e5b6d6dSopenharmony_ci commitButtons[i] = commitItemButton; 1642e5b6d6dSopenharmony_ci } 1652e5b6d6dSopenharmony_ci commitButton.setEnabled(true); 1662e5b6d6dSopenharmony_ci } 1672e5b6d6dSopenharmony_ci 1682e5b6d6dSopenharmony_ci mainBox.removeAll(); 1692e5b6d6dSopenharmony_ci if (itemFields != null) { 1702e5b6d6dSopenharmony_ci for (int i=0; i < itemFields.length; i++) { 1712e5b6d6dSopenharmony_ci JPanel bundlePanel = new JPanel(new BorderLayout()); 1722e5b6d6dSopenharmony_ci bundlePanel.setBorder(BorderFactory.createLineBorder(Color.darkGray)); 1732e5b6d6dSopenharmony_ci bundlePanel.add(itemLabels[i], BorderLayout.NORTH); 1742e5b6d6dSopenharmony_ci bundlePanel.add(itemFields[i], BorderLayout.CENTER); 1752e5b6d6dSopenharmony_ci bundlePanel.add(commitButtons[i], BorderLayout.EAST); 1762e5b6d6dSopenharmony_ci mainBox.add(bundlePanel); 1772e5b6d6dSopenharmony_ci } 1782e5b6d6dSopenharmony_ci } 1792e5b6d6dSopenharmony_ci 1802e5b6d6dSopenharmony_ci revalidate(); 1812e5b6d6dSopenharmony_ci } 1822e5b6d6dSopenharmony_ci} 1832e5b6d6dSopenharmony_ci 184