Author: bobtarling
Date: 2011-04-11 04:15:17-0700
New Revision: 19208

Added:
   
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionAttribute.java
Modified:
   
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigAttribute.java
   
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/CompartmentFigText.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartmentBox.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/TabDiagram.java

Log:
Allow a compartment text fig to be selected

Modified: 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigAttribute.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigAttribute.java?view=diff&pathrev=19208&r1=19207&r2=19208
==============================================================================
--- 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigAttribute.java
     (original)
+++ 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigAttribute.java
     2011-04-11 04:15:17-0700
@@ -38,10 +38,12 @@
 
 package org.argouml.uml.diagram.static_structure.ui;
 
+import java.awt.Graphics;
 import java.awt.Rectangle;
 
 import org.argouml.notation.NotationProviderFactory2;
 import org.argouml.uml.diagram.DiagramSettings;
+import org.tigris.gef.base.Selection;
 
 /**
  * Fig with specific knowledge of Attribute display. <p>
@@ -71,4 +73,12 @@
     protected int getNotationProviderType() {
         return NotationProviderFactory2.TYPE_ATTRIBUTE;
     }
+    
+    public Selection makeSelection() {
+        return new SelectionAttribute(this);
+    }
+
+    public boolean isResizable() {
+        return false;
+    }
 }

Modified: 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java?view=diff&pathrev=19208&r1=19207&r2=19208
==============================================================================
--- 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java
 (original)
+++ 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java
 2011-04-11 04:15:17-0700
@@ -167,16 +167,6 @@
     }
 
     @Override
-    protected CompartmentFigText unhighlight() {
-        CompartmentFigText fc = super.unhighlight();
-        if (fc == null) {
-            // TODO: Try unhighlighting our child compartments
-//            fc = unhighlight(getAttributesFig());
-        }
-        return fc;
-    }
-
-    @Override
     protected void updateListeners(Object oldOwner, Object newOwner) {
         
         Set<Object[]> listeners = new HashSet<Object[]>();

Added: 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionAttribute.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionAttribute.java?view=markup&pathrev=19208
==============================================================================
--- (empty file)
+++ 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionAttribute.java
       2011-04-11 04:15:17-0700
@@ -0,0 +1,86 @@
+/* $Id: SelectionClass.java 19205 2011-04-10 21:31:56Z bobtarling $
+ *****************************************************************************
+ * Copyright (c) 2009-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:
+ *    Michiel van der Wulp
+ *    Katharina Fahnenbruck
+ *****************************************************************************
+ *
+ * Some portions of this file was previously release using the BSD License:
+ */
+
+// Copyright (c) 1996-2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies.  This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason.  IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.uml.diagram.static_structure.ui;
+
+import javax.swing.Icon;
+
+import org.argouml.model.Model;
+import org.tigris.gef.presentation.Fig;
+import org.argouml.uml.diagram.ui.SelectionNodeClarifiers2;
+
+/**
+ * @author [email protected]
+ */
+public class SelectionAttribute extends SelectionNodeClarifiers2 {
+
+    /**
+     * Construct a new SelectionClass for the given Fig.
+     *
+     * @param f The given Fig.
+     */
+    public SelectionAttribute(Fig f) { 
+        super(f);
+    }
+
+    @Override
+    protected Icon[] getIcons() {
+        return null;
+    }
+    
+    @Override
+    protected String getInstructions(int index) {
+        return "";
+    }
+
+    @Override
+    protected Object getNewNodeType(int i) {
+        return Model.getMetaTypes().getAttribute();
+    }
+
+    @Override
+    protected Object getNewEdgeType(int i) {
+        return null;
+    }
+
+    @Override
+    protected boolean isDraggableHandle(int index) {
+        return false;
+    }
+}

Modified: 
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/CompartmentFigText.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/CompartmentFigText.java?view=diff&pathrev=19208&r1=19207&r2=19208
==============================================================================
--- 
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/CompartmentFigText.java    
    (original)
+++ 
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/CompartmentFigText.java    
    2011-04-11 04:15:17-0700
@@ -41,13 +41,8 @@
 import java.awt.Color;
 import java.awt.Graphics;
 import java.awt.Rectangle;
-import java.util.Arrays;
-
-import org.argouml.ui.targetmanager.TargetEvent;
-import org.argouml.ui.targetmanager.TargetListener;
 import org.argouml.ui.targetmanager.TargetManager;
 import org.argouml.uml.diagram.DiagramSettings;
-import org.tigris.gef.base.Globals;
 import org.tigris.gef.presentation.Fig;
 import org.tigris.gef.presentation.FigGroup;
 import org.tigris.gef.presentation.FigText;
@@ -56,15 +51,11 @@
  * A single line FigText class extension for editable 
  * FigClass/FigInterface/FigUseCase
  * compartments that use notation. 
- * When selected, this compartment is highlighted.<p>
- *
- * This implementation now supports the extension point compartment in
- * a use case.
  *
  * @author thn
  */
 public abstract class CompartmentFigText extends FigSingleLineTextWithNotation
-        implements TargetListener {
+        implements Clarifiable {
     
     private static final int MARGIN = 3;
 
@@ -77,11 +68,6 @@
     private Fig refFig;
 
     /**
-     * Set if the user has selected this component Fig inside the FigNode.
-     */
-    private boolean highlighted;
-    
-    /**
      * Construct a CompartmentFigText.
      * 
      * @param element owning uml element
@@ -91,7 +77,6 @@
     public CompartmentFigText(Object element, Rectangle bounds,
             DiagramSettings settings) {
         super(element, bounds, settings, true);
-        TargetManager.getInstance().addTargetListener(this);
 
         setJustification(FigText.JUSTIFY_LEFT);
         setRightMargin(MARGIN);
@@ -133,7 +118,6 @@
     public CompartmentFigText(Object owner, Rectangle bounds, 
             DiagramSettings settings, String[] properties) {
         super(owner, bounds, settings, true, properties);
-        TargetManager.getInstance().addTargetListener(this);
     }
     
     /*
@@ -147,7 +131,6 @@
             ((FigGroup) fg).removeFig(this);
             setGroup(null);
         }
-        TargetManager.getInstance().removeTargetListener(this);
     }
 
     /**
@@ -175,19 +158,6 @@
     }
 
     /**
-     * This is actually used to mark this Fig as selected, however setSelected
-     * is set final in GEF.
-     * TODO: Can setSelected be used without side-effect if GEF is adjusted?
-     * Otherwise consider renaming as setSelectedChild and try to make
-     * protected.
-     * @param flag  <code>true</code> if the entry is to be highlighted,
-     *              <code>false</code> otherwise.
-     */
-    public void setHighlighted(boolean flag) {
-        highlighted = flag;
-    }
-    
-    /**
      * Extends the normal paint function in order to display a similar
      * selection-box to that given for a non-resizable FigNode.
      * @param g the graphics object
@@ -196,55 +166,8 @@
     @Override
     public void paint(Graphics g) {
         super.paint(g);
-        if (highlighted) {
-            final int x = getX();
-            final int y = getY();
-            final int w = getWidth();
-            final int h = getHeight();
-            g.setColor(Globals.getPrefs().handleColorFor(this));
-            
-            g.drawRect(x - 1, y - 1, w + 2, h + 2);
-            g.drawRect(x, y, w, h);
-        }
-    }
-
-    /**
-     * Return whether this item is highlighted.<p>
-     *
-     * @return  <code>true</code> if the entry is highlighted,
-     *          <code>false</code> otherwise.
-     */
-    public boolean isHighlighted() {
-        return highlighted;
-    }
-    
-    /**
-     * Called when text editing has completed on this Fig.
-     */
-    protected void textEdited() {
-        setHighlighted(true);
-        super.textEdited();
-    }
-    
-    public void targetAdded(TargetEvent e) {
-        if (Arrays.asList(e.getNewTargets()).contains(getOwner())) {
-            setHighlighted(true);
-            this.damage();
-        }
-    }
-
-    public void targetRemoved(TargetEvent e) {
-        if (e.getRemovedTargetCollection().contains(getOwner())) {
-            setHighlighted(false);
-            this.damage();
-        }
     }
 
-    public void targetSet(TargetEvent e) {
-        /* This is needed for when the selection changes from 
-         * one compartment fig to an other object. 
-         * Without this, the selection indicators would stay on the screen.
-         * See issue 5681. */
-        
setHighlighted((Arrays.asList(e.getNewTargets()).contains(getOwner())));
+    public void paintClarifiers(Graphics g) {
     }
 }

Modified: 
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartmentBox.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartmentBox.java?view=diff&pathrev=19208&r1=19207&r2=19208
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartmentBox.java 
(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartmentBox.java 
2011-04-11 04:15:17-0700
@@ -99,11 +99,6 @@
             X0, Y0 + 20 /* 20 = height of name fig ?*/, 
             WIDTH, ROWHEIGHT + 2 /* 2*LINE_WIDTH?  or extra padding? */ );
     
-    /**
-     * Text highlighted by mouse actions on the diagram.<p>
-     */
-    private static CompartmentFigText highlightedFigText = null;
-
     private List<FigCompartment> compartments = 
         new ArrayList<FigCompartment>();
 
@@ -494,7 +489,6 @@
                 ((SelectionButtons) sel).hideButtons();
             }
         }
-        unhighlight();
 
         Rectangle r =
             new Rectangle(
@@ -508,63 +502,11 @@
             FigCompartment figCompartment = (FigCompartment) f;
             f = figCompartment.hitFig(r);
             if (f instanceof CompartmentFigText) {
-                if (highlightedFigText != null && highlightedFigText != f) {
-                    highlightedFigText.setHighlighted(false);
-                    if (highlightedFigText.getGroup() != null) {
-                        /* Preventing NullPointerException. */
-                        highlightedFigText.getGroup().damage();
-                    }
-                }
-                ((CompartmentFigText) f).setHighlighted(true);
-                highlightedFigText = (CompartmentFigText) f;
                 TargetManager.getInstance().setTarget(f);
             }
         }
     }
 
-    /**
-     * Remove the highlight from the currently highlit FigText.
-     *
-     * @return the FigText that had highlight removed
-     */
-    protected CompartmentFigText unhighlight() {
-        Fig fc;
-        // Search all feature compartments for a text fig to unhighlight
-        for (int i = 1; i < getFigs().size(); i++) {
-            fc = getFigAt(i);
-            if (fc instanceof FigCompartment) {
-                CompartmentFigText ft = 
-                    unhighlight((FigCompartment) fc);
-                if (ft != null) {
-                    return ft;
-                }
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Search the given compartment for a highlighted CompartmentFigText
-     * and unhighlight it.
-     * 
-     * @param fc compartment to search for highlight item
-     * @return item that was unhighlighted or null if no action was taken
-     */
-    protected final CompartmentFigText unhighlight(
-            FigCompartment fc) {
-        Fig ft;
-        for (int i = 1; i < fc.getFigs().size(); i++) {
-            ft = fc.getFigAt(i);
-            if (ft instanceof CompartmentFigText
-                    && ((CompartmentFigText) ft).isHighlighted()) {
-                ((CompartmentFigText) ft).setHighlighted(false);
-                ft.getGroup().damage();
-                return ((CompartmentFigText) ft);
-            }
-        }
-        return null;
-    }
-
     protected void createContainedModelElement(FigGroup fg, InputEvent ie) {
         if (!(fg instanceof FigCompartment)) {
             return;
@@ -585,17 +527,8 @@
         if (figList.size() > 0) {
             Fig fig = (Fig) figList.get(figList.size() - 1);
             if (fig != null && fig instanceof CompartmentFigText) {
-                if (highlightedFigText != null) {
-                    highlightedFigText.setHighlighted(false);
-                    if (highlightedFigText.getGroup() != null) {
-                        /* Preventing NullPointerException. */
-                        highlightedFigText.getGroup().damage();
-                    }
-                }
                 CompartmentFigText ft = (CompartmentFigText) fig;
                 ft.startTextEditor(ie);
-                ft.setHighlighted(true);
-                highlightedFigText = ft;
             }
         }
         ie.consume();

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/TabDiagram.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/TabDiagram.java?view=diff&pathrev=19208&r1=19207&r2=19208
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/TabDiagram.java        
(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/TabDiagram.java        
2011-04-11 04:15:17-0700
@@ -60,6 +60,7 @@
 import org.argouml.application.api.AbstractArgoJPanel;
 import org.argouml.application.api.Argo;
 import org.argouml.configuration.Configuration;
+import org.argouml.model.Model;
 import org.argouml.ui.TabModelTarget;
 import org.argouml.ui.targetmanager.TargetEvent;
 import org.argouml.ui.targetmanager.TargetManager;
@@ -410,6 +411,11 @@
         }
     }
     
+    /**
+     * If the model element targets have changed then make sure the selection
+     * on the diagram changes to match.
+     * @param targets
+     */
     private void select(Object[] targets) {
         LayerManager manager = graph.getEditor().getLayerManager();
         List<Fig> figList = new ArrayList<Fig>();
@@ -420,7 +426,28 @@
                        && manager.getActiveLayer().getContents().contains(
                                targets[i])) {
                    theTarget = (Fig) targets[i];
+                } else if (Model.getFacade().isAAttribute(targets[i])
+                        || Model.getFacade().isAEnumerationLiteral(targets[i])
+                        || Model.getFacade().isAOperation(targets[i])) {
+                    // Assuming the target is some model element.
+                    Object container = 
Model.getFacade().getModelElementContainer(targets[i]);
+                    FigCompartmentBox theContainer =
+                        (FigCompartmentBox) manager.presentationFor(container);
+                    if (theContainer != null) {
+                        for (FigCompartment fc : 
theContainer.getCompartments()) {
+                            for (Object o : fc.getFigs()) {
+                                if (((Fig) o).getOwner() == targets[i]) {
+                                    theTarget = (Fig) o;
+                                    break;
+                                }
+                            }
+                            if (theTarget != null) {
+                                break;
+                            }
+                        }
+                    }
                 } else {
+                    // Assuming the target is some model element.
                    theTarget = manager.presentationFor(targets[i]);
                 }

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2718822

To unsubscribe from this discussion, e-mail: 
[[email protected]].

Reply via email to