Author: bobtarling Date: 2011-05-15 10:50:21-0700 New Revision: 19429 Added: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldOpaqueExpressionDialog.java Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationModel.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationPanel.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationPanelOptional.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldLiteralBoolean.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldOpaqueExpression.java
Log: Allow different types of initial value to be specified Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationModel.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationModel.java?view=diff&pathrev=19429&r1=19428&r2=19429 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationModel.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationModel.java 2011-05-15 10:50:21-0700 @@ -38,15 +38,6 @@ class UMLValueSpecificationModel implements PropertyChangeListener { - /* - * TODO: Don't use them find an other way to do this - */ - public final static String LITERAL_BOOLEAN =" LiteralBoolean"; - public final static String LITERAL_NULL = "LiteralNull"; - public final static String LITERAL_STRING = "LiteralString"; - public final static String LITERAL_INTEGER = "LiteralInteger"; - public final static String LITERAL_UNATURAL = "LiteralUnlimitedNatural"; - private static final Logger LOG = Logger.getLogger(UMLValueSpecificationModel.class); Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationPanel.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationPanel.java?view=diff&pathrev=19429&r1=19428&r2=19429 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationPanel.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationPanel.java 2011-05-15 10:50:21-0700 @@ -15,8 +15,11 @@ package org.argouml.core.propertypanels.ui; import java.awt.Component; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.lang.reflect.Constructor; import java.util.Collection; import javax.swing.JComboBox; @@ -25,7 +28,6 @@ import org.apache.log4j.Logger; import org.argouml.model.Model; -import org.tigris.swidgets.LabelledLayout; /** * The panel that shows a value specification for an other UML element. @@ -74,7 +76,8 @@ public UMLValueSpecificationPanel(UMLValueSpecificationModel model, String title) { - super(new LabelledLayout()); + //super(new LabelledLayout()); + super(new GridBagLayout()); LOG.debug(">>New ValueSpecification panel created"); TitledBorder border = new TitledBorder(title); @@ -82,10 +85,21 @@ this.model = model; + GridBagConstraints c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + // c.insets = new Insets(1, 1, 1, 1); + c.gridx = 0; + c.gridy = 0; + c.gridwidth = GridBagConstraints.RELATIVE; + c.weightx = 1; + c.weighty = 0; + JComboBox combo = uiSelect(); - add(combo); + add(combo, c); this.valueField = createField((String) combo.getSelectedItem()); + + } @@ -102,19 +116,26 @@ UMLValueSpecificationValueField ret = null; - // TODO: All type. Use Introspection ? - if (sType.equals(UMLValueSpecificationModel.LITERAL_BOOLEAN)) { - ret = new UMLValueSpecificationValueFieldLiteralBoolean(model, true); - } else if (sType.equals(UMLValueSpecificationModel.LITERAL_STRING)) { - ret = new UMLValueSpecificationValueFieldLiteralString(model, true); - } else { - // Opaque Expression (default) - ret = new UMLValueSpecificationValueFieldOpaqueExpression(model, - true); + try { + Class<?> oClass= Class.forName("org.argouml.core.propertypanels.ui.UMLValueSpecificationValueField"+sType); + Constructor<?> constructeur = oClass.getConstructor (new Class [] {UMLValueSpecificationModel.class,boolean.class}); + ret=(UMLValueSpecificationValueField) constructeur.newInstance (new Object [] {model, true}); + } catch (Exception e) { + LOG.error("Unknow type "+sType+" : "+e, e); + return null; } scrollPane = ret.getComponent(); - add(scrollPane); + + GridBagConstraints c = new GridBagConstraints(); + c.fill = GridBagConstraints.BOTH; + c.gridx = 0; + c.gridy = 1; + c.gridwidth = GridBagConstraints.RELATIVE; + c.gridwidth = GridBagConstraints.RELATIVE; + c.weightx = 1; + c.weighty = 1; + add(scrollPane, c); return ret; } Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationPanelOptional.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationPanelOptional.java?view=diff&pathrev=19429&r1=19428&r2=19429 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationPanelOptional.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationPanelOptional.java 2011-05-15 10:50:21-0700 @@ -58,7 +58,9 @@ public UMLValueSpecificationPanelOptional( UMLValueSpecificationModel aModel, String title) { - super(new LabelledLayout()); + // super(new LabelledLayout()); + super(new GridBagLayout()); + LOG.debug(">>New Optional ValueSpecification panel created"); TitledBorder border = new TitledBorder(title); @@ -95,19 +97,18 @@ uvsPanel = new UMLValueSpecificationPanel(model, ""); uvsPanel.setVisible(valueExists.isSelected()); - this.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); - c.fill = GridBagConstraints.HORIZONTAL; + c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 0; - c.weightx = 5; - c.weighty = 1; + c.weightx = 0; + c.weighty = 0; add(valueExists, c); - c.fill = GridBagConstraints.HORIZONTAL; + c.fill = GridBagConstraints.BOTH; c.gridx = 1; c.gridy = 0; - c.weightx = 95; + c.weightx = 1; c.weighty = 1; add(uvsPanel, c); Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldLiteralBoolean.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldLiteralBoolean.java?view=diff&pathrev=19429&r1=19428&r2=19429 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldLiteralBoolean.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldLiteralBoolean.java 2011-05-15 10:50:21-0700 @@ -16,18 +16,28 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import javax.swing.JCheckBox; +import javax.swing.ButtonGroup; +import javax.swing.JPanel; +import javax.swing.JRadioButton; import javax.swing.JScrollPane; +import org.argouml.i18n.Translator; import org.argouml.ui.LookAndFeelMgr; public class UMLValueSpecificationValueFieldLiteralBoolean extends UMLValueSpecificationValueField { + private JRadioButton trueButton; + + private JRadioButton falseButton; + + private ButtonGroup trueFalseGroup; + /** - * checkbox: Field + * true if we can call UpdateModele + * false : We have read the model, so we have to update field. Don't update Modele a new. */ - private JCheckBox checkbox; + private boolean activeUpdateModele; /** * @@ -38,7 +48,7 @@ UMLValueSpecificationModel model, boolean notify) { super(model, notify); - + activeUpdateModele = true; } /** @@ -52,15 +62,27 @@ // Build the field // /////////////////////////////////////// - checkbox = new JCheckBox(); - // TODO ? find a Tool tips, add a label - // checkbox.setToolTipText(Translator.localize("label.body.tooltip")); - checkbox.setFont(LookAndFeelMgr.getInstance().getStandardFont()); + trueButton = new JRadioButton(Translator.localize("misc.boolean.true")); + falseButton = new JRadioButton(Translator + .localize("misc.boolean.false")); + + trueFalseGroup = new ButtonGroup(); + trueFalseGroup.add(trueButton); + trueFalseGroup.add(falseButton); + + trueButton.setFont(LookAndFeelMgr.getInstance().getStandardFont()); + falseButton.setFont(LookAndFeelMgr.getInstance().getStandardFont()); /** * on change : Change the value in the model */ - checkbox.addActionListener(new ActionListener() { + trueButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + updateModel(); + } + }); + + falseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { updateModel(); } @@ -69,7 +91,10 @@ // /////////////////////////////////////// // Add field(s) to panel // /////////////////////////////////////// - this.allField = new JScrollPane(checkbox); + JPanel panel = new JPanel(); + panel.add(trueButton); + panel.add(falseButton); + this.allField = new JScrollPane(panel); } @@ -78,13 +103,20 @@ * @see org.argouml.core.propertypanels.ui.UMLValueSpecificationValueField#updateModel() */ protected void updateModel() { - // The checkbox have only one information: the value (true or false) - Boolean[] values = new Boolean[1]; - values[0] = checkbox.isSelected(); - - // Update the model, and then notify - getModel().setValue(values); + if (activeUpdateModele) { + boolean oldSelected = trueButton.isSelected(); + boolean newSelected = isToCheck(); + + // click on the already selected value must not call setValue + if (oldSelected != newSelected) { + // The 2 Radios have only one information. + Boolean[] values = new Boolean[1]; + values[0] = trueButton.isSelected(); + // Update the model, and then notify + getModel().setValue(values); + } + } } /** @@ -92,14 +124,27 @@ * @see org.argouml.core.propertypanels.ui.UMLValueSpecificationValueField#updateFields() */ protected void updateFields() { - boolean oldSelected = checkbox.isSelected(); + boolean oldSelected = trueButton.isSelected(); boolean newSelected = isToCheck(); if (oldSelected != newSelected) { - checkbox.setSelected(isToCheck()); + boolean oldActiveUpdateModele = activeUpdateModele; + activeUpdateModele = false; + trueButton.setSelected(newSelected); + falseButton.setSelected(!newSelected); + activeUpdateModele = oldActiveUpdateModele; + } else { + // When call by contructor : no one is selected + oldSelected = falseButton.isSelected(); + if (oldSelected == false && newSelected == false) { + boolean oldActiveUpdateModele = activeUpdateModele; + activeUpdateModele = false; + falseButton.setSelected(true); + activeUpdateModele = oldActiveUpdateModele; + } } } - + /** * return if the value in model is "true" or not. * Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldOpaqueExpression.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldOpaqueExpression.java?view=diff&pathrev=19429&r1=19428&r2=19429 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldOpaqueExpression.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldOpaqueExpression.java 2011-05-15 10:50:21-0700 @@ -16,7 +16,10 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; @@ -29,10 +32,10 @@ /** * An OpaqueExpression can have n body n language * - * When display to user, we only show one body. + * When display to user, we only show one body. A "..." button is enabled for + * edit other. * - * TODO: How to add/delete/search a language for edit it TODO: Can we, by Import - * XMI, have 0 language ? + * TODO: Can we, by Import XMI, have 0 language/body ? * * @author Laurent Braud */ @@ -54,12 +57,17 @@ private int currentText; /** + * true if we can call UpdateModele + * false : We have read the model, so we have to update field. Don't update Modele a new. + */ + private boolean activeUpdateModele; + /** * The constructor. */ public UMLValueSpecificationValueFieldOpaqueExpression( UMLValueSpecificationModel model, boolean notify) { super(model, notify); - + activeUpdateModele=true; } /** @@ -80,29 +88,55 @@ .localize("label.language.tooltip")); curLanguage.getDocument().addDocumentListener(this); + // Create other panel element + JButton button = new JButton("..."); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + UMLValueSpecificationValueFieldOpaqueExpressionDialog dialog = new UMLValueSpecificationValueFieldOpaqueExpressionDialog( + getModel(), currentText); + dialog.setVisible(true); + + // TODO ? if this class listen the model, it will be able to + // change in live as it is done in the figs (diagram) + updateFields(); + } + }); + // create Panel containing the previous field JPanel panel = new JPanel(); panel.setFont(LookAndFeelMgr.getInstance().getStandardFont()); - panel.setLayout(new GridBagLayout()); + GridBagLayout layout = new GridBagLayout(); + panel.setLayout(layout); + + // TODO : Redo it (curBody should be as long as curLanguage+button) GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.insets = new Insets(1, 1, 1, 1); c.gridx = 0; c.gridy = 0; - c.weightx = 100; + c.weightx = 1; panel.add(curLanguage, c); - c.fill = GridBagConstraints.HORIZONTAL; + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.insets = new Insets(0, 0, 0, 0); + c.gridx = 1; + c.gridy = 0; + c.weightx = 0; + panel.add(button, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.BOTH; c.insets = new Insets(1, 1, 1, 1); - c.ipady = 40; - // c.weightx = 0.0; - // c.gridwidth = 3; c.gridx = 0; c.gridy = 1; + c.gridwidth = GridBagConstraints.RELATIVE; + c.gridheight = GridBagConstraints.RELATIVE; + c.weightx = 1; + c.weighty = 1; panel.add(curBody, c); - // this.allField = panel; } @@ -112,6 +146,7 @@ * @see org.argouml.core.propertypanels.ui.UMLValueSpecificationValueField#updateFields() */ public void updateFields() { + activeUpdateModele=false; String oldText = curBody.getText(); String[] newTabText = (String[]) getModel().getValue(); String newText = ""; @@ -136,7 +171,7 @@ curLanguage.setText(newText); } } - + activeUpdateModele=true; } /* @@ -155,10 +190,12 @@ } protected void updateModel() { - String[] tabValues = (String[]) getModel().getValue(); - tabValues[2 * currentText] = curBody.getText(); - tabValues[2 * currentText + 1] = curLanguage.getText(); - getModel().setValue(tabValues); + if(activeUpdateModele){ + String[] tabValues = (String[]) getModel().getValue(); + tabValues[2 * currentText] = curBody.getText(); + tabValues[2 * currentText + 1] = curLanguage.getText(); + getModel().setValue(tabValues); + } } } Added: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldOpaqueExpressionDialog.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldOpaqueExpressionDialog.java?view=markup&pathrev=19429 ============================================================================== --- (empty file) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldOpaqueExpressionDialog.java 2011-05-15 10:50:21-0700 @@ -0,0 +1,456 @@ +/* $Id$ + ******************************************************************************* + * Copyright (c) 2011 Contributors - see below + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Laurent Braud + ******************************************************************************* + */ + +package org.argouml.core.propertypanels.ui; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +import org.argouml.i18n.Translator; +import org.argouml.util.ArgoDialog; + +/** + * + * A dialog to edit OpaqueExpression (usefull for more than one language/Body) + * + * TODO ? Review the layout + * + */ +public class UMLValueSpecificationValueFieldOpaqueExpressionDialog extends + ArgoDialog { + + /** + * The serial version. + */ + private static final long serialVersionUID = -5429439639242117770L; + + /** + * + */ + private UMLValueSpecificationModel model; + + /** + * current index of body/language at call + */ + private int currentIndexCall; + + /** + * current index of body/language display + */ + private int currentIndex; + + /** + * The Language field + */ + private JTextField curLanguage; + + /** + * + */ + private JTextArea curBody; + + /** + * + */ + private JList list; + /** + * Model for JList, containing all the language value for this Property + */ + private DefaultListModel listModel; + + public UMLValueSpecificationValueFieldOpaqueExpressionDialog( + UMLValueSpecificationModel aModel, int currentIndex) { + + super("OpaqueExpression", true); //$NON-NLS-1$ + + this.model = aModel; + + this.currentIndexCall = currentIndex; + this.currentIndex = currentIndex; + + setSize(450, 300); + buildFirstPanel(); + + updateFields(); + } + + private void buildFirstPanel() { + JPanel contentPanel = new JPanel(new GridBagLayout()); + add(contentPanel); + + // The 5 main component : 2 label, a panel for langage , a panel with + // button, a textarea + JLabel labelLangage = new JLabel(Translator + .localize("label.language.tooltip")); + JLabel labelBody = new JLabel(Translator.localize("label.body.tooltip")); + + curBody = new JTextArea(); + curBody.setToolTipText(Translator.localize("label.body.tooltip")); + curBody.setRows(2); // make it stretch vertically + // TODO: The curBody must notify modification + + JPanel languagePanel = buildLanguagePanel(); + + JPanel paneBtn = buildBoutonPanel(); + + // Layout + GridBagConstraints c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.insets = new Insets(1, 1, 1, 1); + c.gridx = 0; + c.gridy = 0; + c.weightx = 0.5; + c.weighty = 0; + contentPanel.add(labelLangage, c); + + c = new GridBagConstraints(); + c.insets = new Insets(1, 1, 1, 1); + c.fill = GridBagConstraints.HORIZONTAL; + c.gridx = 2; + c.gridy = 0; + c.weightx = 0.5; + c.weighty = 0; + contentPanel.add(labelBody, c); + + c = new GridBagConstraints(); + c.insets = new Insets(1, 1, 1, 1); + c.fill = GridBagConstraints.HORIZONTAL; + c.gridx = 0; + c.gridy = 1; + c.weightx = 0.5; + c.weighty = 0; + c.anchor = GridBagConstraints.NORTHEAST; + contentPanel.add(languagePanel, c); + + c = new GridBagConstraints(); + c.insets = new Insets(1, 1, 1, 1); + c.fill = GridBagConstraints.BOTH; + c.gridx = 2; + c.gridy = 1; + c.weightx = 0.5; + c.weighty = 1; + contentPanel.add(curBody, c); + + c = new GridBagConstraints(); + c.insets = new Insets(1, 1, 1, 1); + c.fill = GridBagConstraints.NONE; + c.gridx = 1; + c.gridy = 1; + contentPanel.add(paneBtn, c); + + } + + private JPanel buildBoutonPanel() { + JPanel paneBtn = new JPanel(new GridBagLayout()); + + // Save the model (current) + JButton btnApply = new JButton(Translator.localize("button.ok")); + btnApply.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + String[] tabValues = (String[]) model.getValue(); + boolean bContinue = true; + if (!curLanguage.getText().equals( + tabValues[2 * currentIndex + 1])) { + // Language has changed + bContinue = isUniqueLanguage(tabValues, curLanguage + .getText()); + + } + if (bContinue) { + tabValues[2 * currentIndex] = curBody.getText(); + tabValues[2 * currentIndex + 1] = curLanguage.getText(); + model.setValue(tabValues); + updateFields(); + } + // TODO: else : alert + + } + }); + + // Add a new entry in the list and select it. + // Translator.localize("button.add") + JButton btnAdd = new JButton("+"); // + + btnAdd.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + String[] tabValues = (String[]) model.getValue(); + + int num = getEmptyLanguage(tabValues); + if (num == -1) { + String[] newTabValues = new String[tabValues.length + 2]; + System.arraycopy(tabValues, 0, newTabValues, 0, + tabValues.length); + newTabValues[tabValues.length] = ""; + newTabValues[tabValues.length + 1] = ""; + model.setValue(newTabValues); + + currentIndex = newTabValues.length / 2 - 1; + + updateFields(); + } else { + // A language must be unique + // So, select the current empty language. + // TODO ? Alert + currentIndex = num; + updateFields(); + + } + + } + }); + + // Translator.localize("button.delete") + JButton btnDel = new JButton("-"); + btnDel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + String[] tabValues = (String[]) model.getValue(); + if (tabValues.length > 2) { + String[] newTabValues = new String[tabValues.length - 2]; + + if (currentIndex > 0) { + // Copy previous element + System.arraycopy(tabValues, 0, newTabValues, 0, + currentIndex * 2); + } + if (currentIndex < tabValues.length / 2) { + // Copy next element + System.arraycopy(tabValues, currentIndex * 2 + 2, + newTabValues, currentIndex * 2, + tabValues.length - (currentIndex * 2 + 2)); + } + + model.setValue(newTabValues); + + if (currentIndex * 2 > newTabValues.length) { + currentIndex = newTabValues.length / 2 - 1; + } + + updateFields(); + + } else { + String[] newTabValues = new String[2]; + newTabValues[0] = ""; + newTabValues[1] = ""; + model.setValue(newTabValues); + updateFields(); + } + + } + }); + + // Translator.localize("button.move-up") + JButton btnUp = new JButton("/\\"); + btnUp.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + if (currentIndex > 0) { + String[] tabValues = (String[]) model.getValue(); + String[] savTabValues = new String[2]; + // Copy in memory the current + System.arraycopy(tabValues, currentIndex * 2, savTabValues, + 0, 2); + + // Copy the previous value in the current + tabValues[currentIndex * 2] = tabValues[currentIndex * 2 - 2]; + tabValues[currentIndex * 2 + 1] = tabValues[currentIndex * 2 - 1]; + + // Copy the current in the previous + tabValues[(currentIndex - 1) * 2] = savTabValues[0]; + tabValues[(currentIndex - 1) * 2 + 1] = savTabValues[1]; + + model.setValue(tabValues); + + currentIndex = currentIndex - 1; + updateFields(); + + } + + } + }); + + // Translator.localize("button.move-down") + JButton btnDown = new JButton("\\/"); + btnDown.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + + if (currentIndex + 1 < listModel.size()) { + String[] tabValues = (String[]) model.getValue(); + String[] savTabValues = new String[2]; + // Copy in memory the current + System.arraycopy(tabValues, currentIndex * 2, savTabValues, + 0, 2); + + // Copy the next value in the current + tabValues[currentIndex * 2] = tabValues[(currentIndex + 1) * 2]; + tabValues[currentIndex * 2 + 1] = tabValues[(currentIndex + 1) * 2 + 1]; + + // Copy the current in the next + tabValues[(currentIndex + 1) * 2] = savTabValues[0]; + tabValues[(currentIndex + 1) * 2 + 1] = savTabValues[1]; + + model.setValue(tabValues); + + currentIndex = currentIndex + 1; + updateFields(); + + } + + } + }); + // Layout + GridBagConstraints c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.gridx = 0; + c.gridy = 0; + paneBtn.add(btnApply, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.gridx = 0; + c.gridy = 1; + paneBtn.add(btnAdd, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.gridx = 0; + c.gridy = 2; + paneBtn.add(btnDel, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.gridx = 0; + c.gridy = 3; + paneBtn.add(btnUp, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.gridx = 0; + c.gridy = 4; + paneBtn.add(btnDown, c); + + return paneBtn; + } + + private JPanel buildLanguagePanel() { + JPanel panel = new JPanel(new GridBagLayout()); + + // The 2 component: a textField and a list + curLanguage = new JTextField(); + + listModel = new DefaultListModel(); + list = new JList(listModel); + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + list.setSelectedIndex(currentIndex); + + list.addListSelectionListener(new ListSelectionListener() { + + public void valueChanged(ListSelectionEvent arg0) { + if (list.getSelectedIndex() != -1) { + if (list.getSelectedIndex() != currentIndex) { + currentIndex = list.getSelectedIndex(); + updateFields(); + } + + } + + } + }); + + // Layout + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(1, 1, 1, 1); + c.fill = GridBagConstraints.HORIZONTAL; + c.gridx = 0; + c.gridy = 0; + c.weightx = 1; + panel.add(curLanguage, c); + + c = new GridBagConstraints(); + c.insets = new Insets(1, 1, 1, 1); + c.fill = GridBagConstraints.BOTH; + c.gridx = 0; + c.gridy = 1; + c.weightx = 1; + c.weighty = 1; + c.anchor = GridBagConstraints.NORTHEAST; + panel.add(list, c); + + return panel; + + } + + private void updateFields() { + String[] newTabText = (String[]) this.model.getValue(); + + if (newTabText != null) { + listModel.removeAllElements(); + for (int i = 1; i < newTabText.length; i += 2) { + listModel.addElement(newTabText[i]); + } + + if (currentIndex * 2 < newTabText.length) { + + list.setSelectedIndex(currentIndex); + + curBody.setText(newTabText[2 * currentIndex]); + curLanguage.setText(newTabText[2 * currentIndex + 1]); + + } + } + + } + + private boolean isUniqueLanguage(String[] tabValues, String newLanguage) { + // Language must be unique + // TODO: do it in the model (if don't use the dialog, and + // change the first) + boolean bContinue = true; + for (int i = 1; i < tabValues.length && bContinue; i += 2) { + if (i != currentIndex) { + bContinue = !tabValues[i].equals(newLanguage); + } + + } + return bContinue; + } + + /** + * Return the language which is empty + * + * @param tabValues + * @return -1 if it doesn't exist a such language + * + */ + private int getEmptyLanguage(String[] tabValues) { + int num = -1; + for (int i = 1; i < tabValues.length && num == -1; i += 2) { + if (tabValues[i].equals("")) { + num = (i - 1) / 2; + } + } + return num; + } + +} \ No newline at end of file ------------------------------------------------------ http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2737588 To unsubscribe from this discussion, e-mail: [[email protected]].
