Author: bobtarling
Date: 2011-04-10 14:21:16-0700
New Revision: 19203

Added:
   
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/SelectionNodeClarifierWithAttributeButtons.java
Modified:
   
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionClass.java
   
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionInterface.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartment.java
   
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/SelectionNodeClarifiers2.java

Log:
Selection buttons for add attribute/operation - contributed by Katharina 
Fahnenbruck

Modified: 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionClass.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionClass.java?view=diff&pathrev=19203&r1=19202&r2=19203
==============================================================================
--- 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionClass.java
   (original)
+++ 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionClass.java
   2011-04-10 14:21:16-0700
@@ -51,11 +51,13 @@
 import org.tigris.gef.base.Globals;
 import org.tigris.gef.base.ModeCreateEdgeAndNode;
 import org.tigris.gef.presentation.Fig;
+import org.argouml.uml.diagram.ui.SelectionNodeClarifierWithAttributeButtons;
+
 
 /**
  * @author [email protected]
  */
-public class SelectionClass extends SelectionNodeClarifiers2 {
+public class SelectionClass extends SelectionNodeClarifierWithAttributeButtons 
{
 
     private static Icon inherit =
         ResourceLoaderWrapper.lookupIconResource("Generalization");

Modified: 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionInterface.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionInterface.java?view=diff&pathrev=19203&r1=19202&r2=19203
==============================================================================
--- 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionInterface.java
       (original)
+++ 
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionInterface.java
       2011-04-10 14:21:16-0700
@@ -44,11 +44,13 @@
 import org.argouml.model.Model;
 import org.argouml.uml.diagram.ui.SelectionNodeClarifiers2;
 import org.tigris.gef.presentation.Fig;
+import org.argouml.uml.diagram.ui.SelectionNodeClarifierWithAttributeButtons;
 
 /**
  * @author [email protected]
  */
-public class SelectionInterface extends SelectionNodeClarifiers2 {
+public class SelectionInterface extends
+        SelectionNodeClarifierWithAttributeButtons {
 
     private static Icon realiz =
         ResourceLoaderWrapper.lookupIconResource("Realization");

Modified: 
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartment.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartment.java?view=diff&pathrev=19203&r1=19202&r2=19203
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartment.java    
(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartment.java    
2011-04-10 14:21:16-0700
@@ -46,9 +46,9 @@
 
 import org.apache.log4j.Logger;
 import org.argouml.kernel.Project;
+import org.argouml.model.Defaults;
 import org.argouml.model.InvalidElementException;
 import org.argouml.model.Model;
-import org.argouml.model.Defaults;
 import org.argouml.notation.NotationProvider;
 import org.argouml.ui.targetmanager.TargetManager;
 import org.argouml.uml.diagram.DiagramSettings;
@@ -88,7 +88,11 @@
      */
     private Fig externalSeparatorFig = new FigSeparator(X0, Y0, 11, 
LINE_WIDTH);
 
-
+    /**
+     * If true the last element will be editable when the populate method 
completes
+     */
+    private boolean editOnRedraw;
+    
     private void constructFigs(int x, int y, int w, int h) {
         bigPort = new FigPort(X0, Y0, w, h);
         bigPort.setFilled(false);
@@ -344,8 +348,25 @@
 
         if (comp != null) {
             comp.setBotMargin(6); // the last one needs extra space below it
+            
+            if (editOnRedraw) {
+                comp.startTextEditor(null);
+                editOnRedraw = false;
+            }
         }
     }
+
+    /**
+     * Set the editOnRedraw state. When this mode is turned on the compartment
+     * will place the last element in edit mode the next time the component
+     * draws (typically as the result of some event such as having a new item
+     * added)
+     * 
+     * @param editOnRedraw
+     */
+    public void setEditOnRedraw(final boolean editOnRedraw) {
+        this.editOnRedraw = editOnRedraw;
+    }
     
     
     /**

Added: 
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/SelectionNodeClarifierWithAttributeButtons.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/SelectionNodeClarifierWithAttributeButtons.java?view=markup&pathrev=19203
==============================================================================
--- (empty file)
+++ 
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/SelectionNodeClarifierWithAttributeButtons.java
        2011-04-10 14:21:16-0700
@@ -0,0 +1,156 @@
+/* $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:
+ *    katharina
+ 
*******************************************************************************
+ */
+
+package org.argouml.uml.diagram.ui;
+
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.awt.event.MouseEvent;
+
+import javax.swing.Icon;
+
+import org.argouml.application.helpers.ResourceLoaderWrapper;
+import org.argouml.model.Model;
+import org.argouml.uml.diagram.static_structure.ui.FigClassifierBox;
+import org.tigris.gef.presentation.Fig;
+import org.tigris.gef.presentation.Handle;
+
+/**
+ * This class adds two buttons to the class-element. They are shown when the
+ * mouse is over the selelected element. The upper button is for adding new
+ * attributes. The lower button is for adding new operations.
+ * 
+ * @author katharina
+ */
+public abstract class SelectionNodeClarifierWithAttributeButtons extends
+        SelectionNodeClarifiers2 {
+
+    /** Upper right corner Handle */
+    protected static final int UPPER_RIGHT = 2;
+
+    /** Lower right corner Handle */
+    protected static final int LOWER_RIGHT = 7;
+
+    private int localPressedButton;
+
+    private static Icon addIcon = 
+        ResourceLoaderWrapper.lookupIconResource("Add");
+
+    /**
+     * @param f
+     *            the given Fig
+     */
+    public SelectionNodeClarifierWithAttributeButtons(Fig f) {
+       
+        super(f);
+    }
+
+    /**
+     * Handle h: handle in which to return selected Handle information (output
+     * parameter). A handle index of -1 indicates that the cursor is not over
+     * any GEF handle. If the mouse is over the new buttons nevertheless the
+     * index is -1. There the hitHandle() is overridden (see above)
+     */
+    @Override
+    public void hitHandle(Rectangle cursor, Handle h) {
+        super.hitHandle(cursor, h);
+
+        int cx = getContent().getX();
+        int cy = getContent().getY();
+        int cw = getContent().getWidth();
+        int ch = getContent().getHeight();
+
+        // super returns -1 if any of GEFs buttons was hit
+        // (but maybe one of the not-GEF-buttons)
+        if (h.index == -1) {
+            if (hitBelow(cx + cw - (addIcon.getIconWidth() / 2), cy + 25,
+                    addIcon.getIconWidth() + 5, addIcon.getIconHeight() + 3,
+                    cursor)) {
+                h.index = UPPER_RIGHT;
+            } else if (hitAbove(cx + cw - (addIcon.getIconWidth() / 2),
+                    cy + ch, addIcon.getIconWidth() + 3,
+                    addIcon.getIconHeight() + 5,
+                    cursor)) {
+                h.index = LOWER_RIGHT;
+            }
+        }
+    }
+
+    /**
+     * Handle h: handle in which to return selected Handle information (output
+     * parameter). A handle index of -1 indicates that the cursor is not over
+     * any GEF handle. If the mouse is over the new buttons nevertheless the
+     * index is -1. There the hitHandle() is overridden.
+     */
+    public void mousePressed(MouseEvent me) {
+        super.mousePressed(me);
+        Handle h = new Handle(-1);
+        hitHandle(me.getX(), me.getY(), 0, 0, h);
+
+        // get the index of the pressed button
+        localPressedButton = h.index;
+    }
+
+    @Override
+    public void mouseReleased(MouseEvent me) {
+        super.mouseReleased(me);
+
+        if (localPressedButton != UPPER_RIGHT
+                && localPressedButton != LOWER_RIGHT) {
+            return;
+        }
+
+        Handle h = new Handle(-1);
+        hitHandle(me.getX(), me.getY(), 0, 0, h);
+
+        // see if mouse was released on the same button
+        if (localPressedButton == h.index) {
+
+            if (localPressedButton == UPPER_RIGHT) {
+                onButtonClicked(Model.getMetaTypes().getAttribute());
+            }
+            if (localPressedButton == LOWER_RIGHT) {
+                onButtonClicked(Model.getMetaTypes().getOperation());
+            }
+
+            me.consume();
+        }
+    }
+    
+    /**
+     * Adds new element to the class
+     */
+    private void onButtonClicked(Object metaType) {
+        FigClassifierBox fcb = (FigClassifierBox) getContent();
+        FigCompartment fc = fcb.getCompartment(metaType);
+        fc.setEditOnRedraw(true);
+        fc.createModelElement();
+    }
+
+    /*
+     * @see org.tigris.gef.base.SelectionButtons#paintButtons(Graphics)
+     */
+    @Override
+    public void paintButtons(Graphics g) {
+
+        super.paintButtons(g);
+
+        int cx = getContent().getX();
+        int cy = getContent().getY();
+        int cw = getContent().getWidth();
+        int ch = getContent().getHeight();
+
+        paintButtonLeft(addIcon, g, cx + cw, cy + 35, UPPER_RIGHT);
+        paintButtonLeft(addIcon, g, cx + cw, cy + ch - 10, LOWER_RIGHT);
+    }
+}

Modified: 
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/SelectionNodeClarifiers2.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/SelectionNodeClarifiers2.java?view=diff&pathrev=19203&r1=19202&r2=19203
==============================================================================
--- 
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/SelectionNodeClarifiers2.java
  (original)
+++ 
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/SelectionNodeClarifiers2.java
  2011-04-10 14:21:16-0700
@@ -125,7 +125,7 @@
     /*
      * @see org.tigris.gef.base.SelectionButtons#paintButtons(Graphics)
      */
-    public final void paintButtons(Graphics g) {
+    public void paintButtons(Graphics g) {
         final Mode topMode = Globals.curEditor().getModeManager().top();
         if (!(topMode instanceof ModePlace)) {
             // If the user has selected ModePlace either by a diagram

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

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

Reply via email to