Example #1
0
  /*
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent ae) {
    ArgoDiagram diagram = DiagramUtils.getActiveDiagram();
    List nodes = diagram.getNodes();

    if (!nodes.isEmpty()) {
      Object target = TargetManager.getInstance().getTarget();
      if (target != null) {
        RenameBox box = new RenameBox(Translator.localize("action.rename"), target);

        // LOG.info(target.getClass().getName());

        //    		if (target != null && target instanceof UmlClass) {
        //    			UmlClass ele = (UmlClass) target;
        //    			String name = ele.getName();
        //
        //    			box.setRenameNode();
        //    		} else {
        //    			// This is what we are not doing currently.
        //    			box.addNodes(nodes);
        //    		}
        box.setVisible(true);
      }
    } else {
      // OptionPane.showMessageDialog(diagram, "here comes the text.");
    }
  }
  // TODO: Move to different class?
  public static void jumpToDiagramShowing(List targets) {

    if (targets == null || targets.size() == 0) {
      return;
    }
    Object first = targets.get(0);
    if (first instanceof ArgoDiagram && targets.size() > 1) {
      setTarget(first);
      setTarget(targets.get(1));
      return;
    }
    if (first instanceof ArgoDiagram && targets.size() == 1) {
      setTarget(first);
      return;
    }

    // TODO: This should get the containing project from the list of
    // targets, not from some global
    Project project = ProjectManager.getManager().getCurrentProject();
    if (project == null) {
      return;
    }

    List<ArgoDiagram> diagrams = project.getDiagramList();
    Object target = TargetManager.getInstance().getTarget();
    if ((target instanceof ArgoDiagram)
        && ((ArgoDiagram) target).countContained(targets) == targets.size()) {
      setTarget(first);
      return;
    }

    ArgoDiagram bestDiagram = null;
    int bestNumContained = 0;
    for (ArgoDiagram d : diagrams) {
      int nc = d.countContained(targets);
      if (nc > bestNumContained) {
        bestNumContained = nc;
        bestDiagram = d;
      }
      if (nc == targets.size()) {
        break;
      }
    }
    if (bestDiagram != null) {
      if (!DiagramUtils.getActiveDiagram().equals(bestDiagram)) {
        setTarget(bestDiagram);
      }
      setTarget(first);
    }
    // making it possible to jump to the modelroots
    if (project.getRoots().contains(first)) {
      setTarget(first);
    }

    // and finally, adjust the scrollbars to show the Fig
    Object f = TargetManager.getInstance().getFigTarget();
    if (f instanceof Fig) {
      Globals.curEditor().scrollToShow((Fig) f);
    }
  }
 /*
  * @see org.argouml.uml.ui.UMLPlainTextDocument#getProperty()
  */
 protected String getProperty() {
   Object target = DiagramUtils.getActiveDiagram();
   if (target instanceof ArgoDiagram) {
     return ((ArgoDiagram) target).getName();
   }
   return "";
 }
 /*
  * @see org.argouml.uml.ui.UMLPlainTextDocument#setProperty(java.lang.String)
  */
 protected void setProperty(String text) {
   Object target = DiagramUtils.getActiveDiagram();
   if (target instanceof ArgoDiagram) {
     try {
       ((ArgoDiagram) target).setName(text);
     } catch (PropertyVetoException e) {
       // TODO: what shall we do with the exception?
     }
   }
 }
 /*
  * @see javax.swing.Action#isEnabled()
  */
 @Override
 public boolean isEnabled() {
   ArgoDiagram dia = DiagramUtils.getActiveDiagram();
   if (dia == null) {
     return false;
   }
   MutableGraphModel gm = (MutableGraphModel) dia.getGraphModel();
   for (Object o : objects) {
     if (gm.canAddNode(o)) {
       return true;
     }
   }
   return false;
 }
Example #6
0
  /*
   * @see org.argouml.ui.TabTarget#shouldBeEnabled(java.lang.Object)
   */
  public boolean shouldBeEnabled(Object targetItem) {

    if (!(targetItem instanceof Fig)) {
      if (Model.getFacade().isAModelElement(targetItem)) {
        ArgoDiagram diagram = DiagramUtils.getActiveDiagram();
        if (diagram == null) {
          shouldBeEnabled = false;
          return false;
        }

        Fig f = diagram.presentationFor(targetItem);
        if (f == null) {
          shouldBeEnabled = false;
          return false;
        }
        targetItem = f;
      } else {
        shouldBeEnabled = false;
        return false;
      }
    }

    shouldBeEnabled = true;

    // TODO: It would be better to defer this initialization until the panel
    // actually needs to be displayed. Perhaps optimistically always return
    // true and figure out later if we've got something to display - tfm -
    // 20070110
    Class targetClass = targetItem.getClass();
    stylePanel = findPanelFor(targetClass);
    targetClass = targetClass.getSuperclass();

    if (stylePanel == null) {
      shouldBeEnabled = false;
    }

    return shouldBeEnabled;
  }
Example #7
0
  /**
   * On mouse release add the elements to the diagram
   *
   * @param me the mouse event
   */
  @Override
  public void mouseReleased(final MouseEvent me) {
    if (me.isConsumed()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("MouseReleased but rejected as already consumed");
      }
      return;
    }
    // TODO: Use per-project undo manager, not global
    UndoManager.getInstance().addMementoLock(this);
    start();
    MutableGraphModel gm = (MutableGraphModel) editor.getGraphModel();

    final int x = me.getX();
    final int y = me.getY();
    editor.damageAll();
    final Point snapPt = new Point(x, y);
    editor.snap(snapPt);
    editor.damageAll();
    int count = 0;

    Layer lay = editor.getLayerManager().getActiveLayer();
    GraphNodeRenderer renderer = editor.getGraphNodeRenderer();

    final List<FigNode> placedFigs = new ArrayList<FigNode>(modelElements.size());

    ArgoDiagram diag = DiagramUtils.getActiveDiagram();
    if (diag instanceof UMLDiagram) {
      for (final Object node : modelElements) {
        if (((UMLDiagram) diag).doesAccept(node)) {
          final FigNode pers = renderer.getFigNodeFor(gm, lay, node, null);
          pers.setLocation(snapPt.x + (count++ * 100), snapPt.y);
          if (LOG.isDebugEnabled()) {
            LOG.debug("mouseMoved: Location set (" + pers.getX() + "," + pers.getY() + ")");
          }
          // TODO: Use per-project undo manager, not global
          UndoManager.getInstance().startChain();
          editor.add(pers);
          gm.addNode(node);
          if (addRelatedEdges) {
            gm.addNodeRelatedEdges(node);
          }

          Fig encloser = null;
          final Rectangle bbox = pers.getBounds();
          final List<Fig> otherFigs = lay.getContents();
          for (final Fig otherFig : otherFigs) {
            if (!(otherFig.getUseTrapRect())) {
              continue;
            }
            if (!(otherFig instanceof FigNode)) {
              continue;
            }
            if (!otherFig.isVisible()) {
              continue;
            }
            if (otherFig.equals(pers)) {
              continue;
            }
            final Rectangle trap = otherFig.getTrapRect();
            if (trap != null
                && trap.contains(bbox.x, bbox.y)
                && trap.contains(bbox.x + bbox.width, bbox.y + bbox.height)) {
              encloser = otherFig;
            }
          }
          pers.setEnclosingFig(encloser);

          placedFigs.add(pers);
        }
      }
    }

    // TODO: Use per-project undo manager, not global
    UndoManager.getInstance().removeMementoLock(this);
    if (UndoManager.getInstance().isGenerateMementos()) {
      AddToDiagramMemento memento = new AddToDiagramMemento(editor, placedFigs);
      UndoManager.getInstance().addMemento(memento);
    }
    UndoManager.getInstance().addMementoLock(this);
    editor.getSelectionManager().select(placedFigs);

    done();
    me.consume();
  }
Example #8
0
  /**
   * Sets the target of the style tab.
   *
   * @param t is the new target
   */
  public void setTarget(Object t) {
    if (target != null) {
      target.removePropertyChangeListener(this);
      if (target instanceof FigEdge) {
        // In this case, the bounds are determined by the FigEdge
        ((FigEdge) target).getFig().removePropertyChangeListener(this);
      }
      if (target instanceof FigAssociationClass) {
        // In this case, the bounds (of the box) are determined
        // by the FigClassAssociationClass
        FigClassAssociationClass ac = ((FigAssociationClass) target).getAssociationClass();
        // A newly created AssociationClass may not have all its parts
        // created by the time we are called
        if (ac != null) {
          ac.removePropertyChangeListener(this);
        }
      }
    }

    // TODO: Defer most of this work if the panel isn't visible - tfm

    // the responsibility of determining if the given target is a
    // correct one for this tab has been moved from the
    // DetailsPane to the member tabs of the details pane. Reason for
    // this is that the details pane is configurable and cannot
    // know what's the correct target for some tab.
    if (!(t instanceof Fig)) {
      if (Model.getFacade().isAModelElement(t)) {
        ArgoDiagram diagram = DiagramUtils.getActiveDiagram();
        if (diagram != null) {
          t = diagram.presentationFor(t);
        }
        if (!(t instanceof Fig)) {
          Project p = ProjectManager.getManager().getCurrentProject();
          Collection col = p.findFigsForMember(t);
          if (col == null || col.isEmpty()) {
            return;
          }
          t = col.iterator().next();
        }
        if (!(t instanceof Fig)) {
          return;
        }
      } else {
        return;
      }
    }

    target = (Fig) t;
    if (target != null) {
      target.addPropertyChangeListener(this);
      // TODO: This shouldn't know about the specific type of Fig that
      // is being displayed.  That couples it too strongly to things it
      // shouldn't need to know about - tfm - 20070924
      if (target instanceof FigEdge) {
        // In this case, the bounds are determined by the FigEdge
        ((FigEdge) target).getFig().addPropertyChangeListener(this);
      }
      if (target instanceof FigAssociationClass) {
        // In this case, the bounds (of the box) are determined
        // by the FigClassAssociationClass
        FigClassAssociationClass ac = ((FigAssociationClass) target).getAssociationClass();
        // A newly created AssociationClass may not have all its parts
        // created by the time we are called
        if (ac != null) {
          ac.addPropertyChangeListener(this);
        }
      }
    }
    if (lastPanel != null) {
      remove(lastPanel);
      if (lastPanel instanceof TargetListener) {
        removeTargetListener((TargetListener) lastPanel);
      }
    }
    if (t == null) {
      add(blankPanel, BorderLayout.NORTH);
      shouldBeEnabled = false;
      lastPanel = blankPanel;
      return;
    }
    shouldBeEnabled = true;
    stylePanel = null;
    Class targetClass = t.getClass();

    stylePanel = findPanelFor(targetClass);

    if (stylePanel != null) {
      removeTargetListener(stylePanel);
      addTargetListener(stylePanel);
      stylePanel.setTarget(target);
      add(stylePanel, BorderLayout.NORTH);
      shouldBeEnabled = true;
      lastPanel = stylePanel;
    } else {
      add(blankPanel, BorderLayout.NORTH);
      shouldBeEnabled = false;
      lastPanel = blankPanel;
    }
    validate();
    repaint();
  }