Author: thn Date: 2011-04-19 00:44:36-0700 New Revision: 19261 Added: 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/UMLValueSpecificationValueFieldLiteralString.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldOpaqueExpression.java Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java 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/UMLValueSpecificationValueField.java
Log: UML2: partial solution for issue 6215 Patch obtained from Laurent Braud Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java?view=diff&pathrev=19261&r1=19260&r2=19261 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java 2011-04-19 00:44:36-0700 @@ -40,7 +40,6 @@ package org.argouml.core.propertypanels.ui; import java.util.Collection; -import java.util.List; import javax.swing.BoxLayout; import javax.swing.JComboBox; @@ -224,7 +223,8 @@ } else { UMLValueSpecificationModel model = new UMLValueSpecificationModel(target, "initialValue"); - p = new UMLValueSpecificationPanel(model, propertyName); + //p = new UMLValueSpecificationPanel(model, propertyName); + p = new UMLValueSpecificationPanelOptional(model, propertyName); } control = p; } else if ("defaultValue".equals(propertyName)) { 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=19261&r1=19260&r2=19261 ============================================================================== --- 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-04-19 00:44:36-0700 @@ -8,6 +8,7 @@ * * Contributors: * Thomas Neustupny + * Laurent Braud ******************************************************************************* */ @@ -37,6 +38,15 @@ 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); @@ -110,7 +120,7 @@ /** * @return the expression */ - private Object getExpression() { + public Object getExpression() { return Model.getFacade().getInitialValue(getTarget()); } @@ -134,6 +144,7 @@ /** * @return The value text of the value specification. + * @deprecated I don't use it. */ public String getText() { Object expression = getExpression(); @@ -143,59 +154,58 @@ return Model.getFacade().getBody(expression).toString(); } + /** - * @param text the value text of the value specification + * Get the ValueSpecification + * @return */ - public void setText(String text) { - - Object expression = getExpression(); - boolean mustChange = true; - if (expression != null) { - Object oldValue = Model.getFacade().getBody(expression).toString(); - if (oldValue != null && oldValue.equals(text)) { - mustChange = false; - } - } - if (mustChange) { - String lang = null; - if (expression != null) { - lang = Model.getDataTypesHelper().getLanguage(expression); - } - if (lang == null) { - lang = EMPTYSTRING; - } - - setExpression(lang, text); - } + public Object[] getValue(){ + return Model.getDataTypesHelper().getValueSpecificationValues(getExpression()); } - /** - * This is only called if we already know that the values differ. - * - * @param lang the language of the expression - * @param body the body text of the expression + * Set ValueSpecification + * + * @param tabValues: A formated array depends on type of ValueSpecification. */ - private void setExpression(String lang, String body) { - assert lang != null; - assert body != null; - + public void setValue(Object tabValues[]) { // Expressions are DataTypes, not independent model elements // be careful not to reuse them rememberExpression = getExpression(); + + // stopListeningForModelChanges(); - if (rememberExpression != null) { - Model.getUmlFactory().delete(rememberExpression); - } - if (lang.length() == 0 && body.length()==0) { + if (tabValues == null) { + if (rememberExpression != null) { + Model.getUmlFactory().delete(rememberExpression); + } rememberExpression = null; + + setExpression(rememberExpression); } else { - rememberExpression = newExpression(lang, body); + Model.getDataTypesHelper().modifyValueSpecification(rememberExpression, tabValues); + // We need to to this otherwise there is no notification + // and diagram isn't change + Model.getCoreHelper().setInitialValue(target, rememberExpression); + + } - setExpression(rememberExpression); + startListeningForModelChanges(); } /** + * + * @param sType + */ + public void createValueSpecification(String sType) { + + Object exp=Model.getDataTypesHelper().createValueSpecification(getTarget(),sType); + // needed for notification + Model.getCoreHelper().setInitialValue(target,exp); + + } + + /** * Adds a <code>ChangeListener</code>. * The change listeners are run each * time the expression changes. 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=19261&r1=19260&r2=19261 ============================================================================== --- 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-04-19 00:44:36-0700 @@ -8,31 +8,69 @@ * * Contributors: * Thomas Neustupny + * Laurent Braud ******************************************************************************* */ package org.argouml.core.propertypanels.ui; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Collection; + +import javax.swing.JComboBox; import javax.swing.JPanel; -import javax.swing.JScrollPane; import javax.swing.border.TitledBorder; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; 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. + * + * + * TODO: Do we need to implements ChangeListener If yes => ok If no => Can't be + * use without *Optional class, or the *Optional don't need to ! + * */ -class UMLValueSpecificationPanel extends JPanel implements ChangeListener { +class UMLValueSpecificationPanel extends JPanel { + + /** + * Generated UID. + */ + private static final long serialVersionUID = 1494398250907085817L; private static final Logger LOG = Logger .getLogger(UMLValueSpecificationPanel.class); + /** + * + */ private final UMLValueSpecificationModel model; - private final UMLValueSpecificationValueField valueField; + /** + * The component for view/change the type. + */ + private JComboBox typeInstanceValueList; + + /** + * This contains a panel to display (A checkbox for boolean, ...) + */ + private UMLValueSpecificationValueField valueField; + + /** + * + * TODO: Try to use valueField.getComponent() + */ + private Component scrollPane; + + /** + * + * @param model + * @param title + */ public UMLValueSpecificationPanel(UMLValueSpecificationModel model, String title) { @@ -43,21 +81,126 @@ this.setBorder(border); this.model = model; - this.valueField = new UMLValueSpecificationValueField(model, true); - add(new JScrollPane(valueField)); + JComboBox combo = uiSelect(); + add(combo); + + this.valueField = createField((String) combo.getSelectedItem()); + + } + + /** + * + * @param sType + * @return + */ + private UMLValueSpecificationValueField createField(String sType) { + + if (scrollPane != null) { + remove(scrollPane); + } + + 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); + } + + scrollPane = ret.getComponent(); + add(scrollPane); - model.addChangeListener(this); + return ret; } - @Override - public void removeNotify() { - model.removeChangeListener(this); - super.removeNotify(); + /** + * Create the combobox wich display available ValueSpecification (type) + * + * TODO LiteralNull,Expression, InstanceValue,... TODO ? Use something else + * that a combobox. TODO ? If combobox, can we restrict list ? For instance, + * can we create a Boolean for a Integer Value ? + * + * TODO + * + * @return + */ + private JComboBox uiSelect() { + + // Get the list: OpaqueExpression, LiteralString,... + Collection<String> listVS = Model.getDataTypesHelper() + .getValueSpecifications(); + Object[] typeInstanceValue = listVS.toArray(); + + typeInstanceValueList = new JComboBox(typeInstanceValue); + + int iSel = 0;// By default, the first value of the combobox is selected. + + if (model != null) { + // Get current InitialValue + Object expression = this.model.getExpression(); + + if (expression != null) { + // Select the Current type in the combobox + + // if "expression" implements one of the combobox, select it + // TODO ? Do it in eUML module project ? + Class<?>[] interfaces = expression.getClass().getInterfaces(); + iSel = -1; + for (int iInterf = 0; iInterf < interfaces.length && iSel == -1; iInterf++) { + for (int iVS = 0; iVS < typeInstanceValue.length + && iSel == -1; iVS++) { + if (interfaces[iInterf].getSimpleName().equals( + typeInstanceValue[iVS])) { + iSel = iVS; + } + } + } + } + + } + + typeInstanceValueList.setSelectedIndex(iSel); + + /** + * When we change the type, we need to create a new Initial Value. And + * to display the Panel + * + * TODO: if we select the same type that the current, do nothing. + */ + typeInstanceValueList.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent ae) { + + if (ae.getActionCommand().equals("comboBoxChanged")) { + + JComboBox lst = (JComboBox) ae.getSource(); + String sTypeVS = (String) lst.getSelectedItem(); + model.createValueSpecification(sTypeVS); + createField(sTypeVS); + // TODO: When the attribute isn't in the diagram + // , for exemple: select attribut by Explorer + // Then, the refresh isn't auto: we had to click !! + } + + } + }); + + return typeInstanceValueList; } - public void stateChanged(ChangeEvent e) { - LOG.debug(">>Values shown on panel are changed"); - valueField.update(); + /** + * Select element in a combo. + */ + public void selectDefaultVS() { + // default : 0 => OpaqueExpression + // set to 1 for test + typeInstanceValueList.setSelectedIndex(0); } + } Added: 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=markup&pathrev=19261 ============================================================================== --- (empty file) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationPanelOptional.java 2011-04-19 00:44:36-0700 @@ -0,0 +1,139 @@ +/* $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 (issue 6215) + ******************************************************************************* + */ + +package org.argouml.core.propertypanels.ui; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JCheckBox; +import javax.swing.JPanel; +import javax.swing.border.TitledBorder; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import org.apache.log4j.Logger; +import org.tigris.swidgets.LabelledLayout; + +/** + * Checkbox creates or nulls the instance of valueSpecificationPanel + * + * @author BRAUD (issue 6215) + * + * Do we need : ChangeListener + */ +public class UMLValueSpecificationPanelOptional extends JPanel implements + ChangeListener { + + private static final Logger LOG = Logger + .getLogger(UMLValueSpecificationPanel.class); + + /** + * + */ + private JCheckBox valueExists; + + /** + * Is null if valueExists isn't check + */ + private UMLValueSpecificationPanel uvsPanel; + + /** + * + */ + private final UMLValueSpecificationModel model; + + public UMLValueSpecificationPanelOptional( + UMLValueSpecificationModel aModel, String title) { + + super(new LabelledLayout()); + LOG.debug(">>New Optional ValueSpecification panel created"); + + TitledBorder border = new TitledBorder(title); + this.setBorder(border); + + this.model = aModel; + + // TODO : ?? use an other CheckBox (defines in Argo and extends + // JCheckBox ) + valueExists = new JCheckBox(); + + // + boolean withDefault = model.getExpression() != null; + valueExists.setSelected(withDefault); + + valueExists.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + uvsPanel.setVisible(valueExists.isSelected()); + if (valueExists.isSelected()) { + // Create it [Here, OpaqueExpression which is the first + // choice] + // Note that if we edit the Initial value in the diagram + // (double clic) + // it was replaced by an OpaqueExpression + uvsPanel.selectDefaultVS(); + } else { + // Destroy it + model.setValue(null); + } + } + }); + + // title = "" because already done for Optional + uvsPanel = new UMLValueSpecificationPanel(model, ""); + uvsPanel.setVisible(valueExists.isSelected()); + + this.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.gridx = 0; + c.gridy = 0; + c.weightx = 5; + c.weighty = 1; + add(valueExists, c); + + c.fill = GridBagConstraints.HORIZONTAL; + c.gridx = 1; + c.gridy = 0; + c.weightx = 95; + c.weighty = 1; + add(uvsPanel, c); + + model.addChangeListener(this); + + } + + /** + * TODO: Is is really used ? + * + * @see javax.swing.JComponent#removeNotify() + */ + @Override + public void removeNotify() { + model.removeChangeListener(this); + super.removeNotify(); + } + + /** + * TODO: Is is really used ? + * + * @see javax.swing.JComponent#removeNotify() + */ + public void stateChanged(ChangeEvent e) { + LOG.debug(">>Values shown on panel are changed"); + + } + +} Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueField.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueField.java?view=diff&pathrev=19261&r1=19260&r2=19261 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueField.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueField.java 2011-04-19 00:44:36-0700 @@ -8,88 +8,87 @@ * * Contributors: * Thomas Neustupny + * Laurent Braud ******************************************************************************* */ package org.argouml.core.propertypanels.ui; -import javax.swing.JTextArea; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; +import java.awt.Component; import org.apache.log4j.Logger; -import org.argouml.i18n.Translator; -import org.argouml.ui.LookAndFeelMgr; -/** - * This text field shows the value of a UML value specification. - * - */ -class UMLValueSpecificationValueField extends JTextArea implements - DocumentListener { +public abstract class UMLValueSpecificationValueField { /** - * Logger. + * TODO: see if protected or need to be present in each subclass */ - private static final Logger LOG = Logger + protected static final Logger LOG = Logger .getLogger(UMLValueSpecificationValueField.class); + /** + * + */ private UMLValueSpecificationModel model; + + /** + * TODO: Use it notify Set to true to forward events to model. Only one of + * Language and Body fields should have this set to true. + */ private boolean notifyModel; + protected Component allField; + /** - * The constructor. + * Constructor which create the Component * * @param model - * ValueSpecification model, should be shared between the fields * @param notify - * Set to true to forward events to model. Only one of Language - * and Body fields should have this set to true. */ - public UMLValueSpecificationValueField(UMLValueSpecificationModel model, + public UMLValueSpecificationValueField(UMLValueSpecificationModel aModel, boolean notify) { - this.model = model; + this.model = aModel; this.notifyModel = notify; - getDocument().addDocumentListener(this); - setToolTipText(Translator.localize("label.body.tooltip")); - setFont(LookAndFeelMgr.getInstance().getStandardFont()); - setRows(2); // make it stretch vertically - update(); - } + buildPanel(); + updateFields(); - void update() { - String oldText = getText(); - String newText = model.getText(); - - if (oldText == null || newText == null || !oldText.equals(newText)) { - if (oldText != newText) { - setText(newText); - } - } } - /* - * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event. - * DocumentEvent) + /** + * Update all the Field in the Component "allField", which are display, with + * the value of the model + * */ - public void changedUpdate(final DocumentEvent p1) { - model.setText(getText()); - } + protected abstract void updateFields(); - /* - * @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event. - * DocumentEvent) + /** + * Update the model with the field If field aren't display, need to get the + * current value before update */ - public void removeUpdate(final DocumentEvent p1) { - model.setText(getText()); - } + protected abstract void updateModel(); + + /** + * build the panel for the ValueSpecification's type + */ + public abstract void buildPanel(); - /* - * @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event. - * DocumentEvent) + /** + * Return a component with all field need to display and modify this + * ValueSpecification + * + * @return */ - public void insertUpdate(final DocumentEvent p1) { - model.setText(getText()); + public Component getComponent() { + return allField; + } + + public boolean isNotifyModel() { + return notifyModel; } + + public UMLValueSpecificationModel getModel() { + return model; + } + } Added: 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=markup&pathrev=19261 ============================================================================== --- (empty file) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldLiteralBoolean.java 2011-04-19 00:44:36-0700 @@ -0,0 +1,113 @@ +/* $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.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JCheckBox; +import javax.swing.JScrollPane; + +import org.argouml.ui.LookAndFeelMgr; + +public class UMLValueSpecificationValueFieldLiteralBoolean extends + UMLValueSpecificationValueField { + + /** + * checkbox: Field + */ + private JCheckBox checkbox; + + /** + * + * @param model + * @param notify + */ + public UMLValueSpecificationValueFieldLiteralBoolean( + UMLValueSpecificationModel model, boolean notify) { + + super(model, notify); + + } + + /** + * The panel consist of: One CheckBox + * + * @see org.argouml.core.propertypanels.ui.UMLValueSpecificationValueField#buildPanel() + */ + @Override + public void buildPanel() { + // /////////////////////////////////////// + // 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()); + + /** + * on change : Change the value in the model + */ + checkbox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + updateModel(); + } + }); + + // /////////////////////////////////////// + // Add field(s) to panel + // /////////////////////////////////////// + this.allField = new JScrollPane(checkbox); + + } + + /** + * + * @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); + + } + + /** + * + * @see org.argouml.core.propertypanels.ui.UMLValueSpecificationValueField#updateFields() + */ + protected void updateFields() { + boolean oldSelected = checkbox.isSelected(); + boolean newSelected = isToCheck(); + + if (oldSelected != newSelected) { + checkbox.setSelected(isToCheck()); + } + } + + /** + * return if the value in model is "true" or not. + * + * @return + */ + public boolean isToCheck() { + Boolean[] values = (Boolean[]) getModel().getValue(); + return values[0]; + } + +} Added: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldLiteralString.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldLiteralString.java?view=markup&pathrev=19261 ============================================================================== --- (empty file) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldLiteralString.java 2011-04-19 00:44:36-0700 @@ -0,0 +1,106 @@ +/* $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 javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +import org.argouml.ui.LookAndFeelMgr; + +public class UMLValueSpecificationValueFieldLiteralString extends + UMLValueSpecificationValueField implements DocumentListener { + + /** + * Field TODO: TextArea or TextField + */ + private JTextArea stringField; + + /** + * The constructor. + * + * @param model + * ValueSpecification model, should be shared between the fields + * @param notify + * Set to true to forward events to model. Only one of Language + * and Body fields should have this set to true. + */ + public UMLValueSpecificationValueFieldLiteralString( + UMLValueSpecificationModel model, boolean notify) { + super(model, notify); + + } + + /** + * @see org.argouml.core.propertypanels.ui.UMLValueSpecificationValueField#buildPanel() + */ + @Override + public void buildPanel() { + stringField = new JTextArea(); + stringField.getDocument().addDocumentListener(this); + // TODO: review the tool tips ? + // stringField.setToolTipText(Translator.localize("label.body.tooltip")); + stringField.setFont(LookAndFeelMgr.getInstance().getStandardFont()); + stringField.setRows(2); // make it stretch vertically + + allField = new JScrollPane(stringField); + + } + + /** + * + * @see org.argouml.core.propertypanels.ui.UMLValueSpecificationValueField#updateFields() + */ + public void updateFields() { + String oldText = stringField.getText(); + String[] tabNewText = (String[]) getModel().getValue(); + String newText = tabNewText[0]; + if (oldText == null || newText == null || !oldText.equals(newText)) { + if (oldText != newText) { + stringField.setText(newText); + } + } + } + + @Override + protected void updateModel() { + String[] tabValues = new String[] { stringField.getText() }; + getModel().setValue(tabValues); + } + + /* + * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event. + * DocumentEvent) TODO: Are the 3 methods uses ? + */ + public void changedUpdate(final DocumentEvent p1) { + updateModel(); + } + + /* + * @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event. + * DocumentEvent) + */ + public void removeUpdate(final DocumentEvent p1) { + updateModel(); + } + + /* + * @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event. + * DocumentEvent) + */ + public void insertUpdate(final DocumentEvent p1) { + updateModel(); + } +} Added: 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=markup&pathrev=19261 ============================================================================== --- (empty file) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLValueSpecificationValueFieldOpaqueExpression.java 2011-04-19 00:44:36-0700 @@ -0,0 +1,164 @@ +/* $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 javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +import org.argouml.i18n.Translator; +import org.argouml.ui.LookAndFeelMgr; + +/** + * An OpaqueExpression can have n body n language + * + * When display to user, we only show one body. + * + * TODO: How to add/delete/search a language for edit it TODO: Can we, by Import + * XMI, have 0 language ? + * + * @author Laurent Braud + */ +public class UMLValueSpecificationValueFieldOpaqueExpression extends + UMLValueSpecificationValueField implements DocumentListener { + + /** + * The body display at the moment + */ + private JTextArea curBody; + /** + * The Language display at the moment + */ + private JTextField curLanguage; + + /** + * The number of the currentBody and currentLangage + */ + private int currentText; + + /** + * The constructor. + */ + public UMLValueSpecificationValueFieldOpaqueExpression( + UMLValueSpecificationModel model, boolean notify) { + super(model, notify); + + } + + /** + * + * + * @see org.argouml.core.propertypanels.ui.UMLValueSpecificationValueField#buildPanel() + */ + public void buildPanel() { + currentText = 0; + // Create the body and language Field + curBody = new JTextArea(); + curBody.setToolTipText(Translator.localize("label.body.tooltip")); + curBody.setRows(2); // make it stretch vertically + curBody.getDocument().addDocumentListener(this); + + curLanguage = new JTextField(); + curLanguage.setToolTipText(Translator + .localize("label.language.tooltip")); + curLanguage.getDocument().addDocumentListener(this); + + // create Panel containing the previous field + JPanel panel = new JPanel(); + panel.setFont(LookAndFeelMgr.getInstance().getStandardFont()); + + panel.setLayout(new GridBagLayout()); + 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; + panel.add(curLanguage, c); + + c.fill = GridBagConstraints.HORIZONTAL; + c.insets = new Insets(1, 1, 1, 1); + c.ipady = 40; + // c.weightx = 0.0; + // c.gridwidth = 3; + c.gridx = 0; + c.gridy = 1; + panel.add(curBody, c); + + // + this.allField = panel; + + } + + /*** + * + * @see org.argouml.core.propertypanels.ui.UMLValueSpecificationValueField#updateFields() + */ + public void updateFields() { + String oldText = curBody.getText(); + String[] newTabText = (String[]) getModel().getValue(); + String newText = ""; + if (newTabText != null) { + newText = newTabText[2 * currentText]; + } + + if (oldText == null || newText == null || !oldText.equals(newText)) { + if (oldText != newText) { + curBody.setText(newText); + } + } + + oldText = curLanguage.getText(); + newText = ""; + if (newTabText != null) { + newText = newTabText[2 * currentText + 1]; + } + + if (oldText == null || newText == null || !oldText.equals(newText)) { + if (oldText != newText) { + curLanguage.setText(newText); + } + } + + } + + /* + * TODO: Are the 3 methods uses ? + */ + public void changedUpdate(DocumentEvent arg0) { + updateModel(); + } + + public void insertUpdate(DocumentEvent arg0) { + updateModel(); + } + + public void removeUpdate(DocumentEvent arg0) { + updateModel(); + } + + protected void updateModel() { + String[] tabValues = (String[]) getModel().getValue(); + tabValues[2 * currentText] = curBody.getText(); + tabValues[2 * currentText + 1] = curLanguage.getText(); + getModel().setValue(tabValues); + } + +} ------------------------------------------------------ http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2721294 To unsubscribe from this discussion, e-mail: [[email protected]].
