Exemple #1
0
  /** Create a new method with default type and name, without parameter. */
  public void addMethod() {
    final Method method =
        new Method("method", PrimitiveType.VOID_TYPE, Visibility.PUBLIC, component);
    prepareNewMethod(method);

    if (component.addMethod(method)) component.notifyObservers(UpdateMessage.ADD_METHOD);
  }
Exemple #2
0
  /** Create a new attribute with default type and name. */
  public void addAttribute() {
    final Attribute attribute = new Attribute("attribute", PrimitiveType.VOID_TYPE);
    prepareNewAttribute(attribute);

    component.addAttribute(attribute);
    component.notifyObservers(UpdateMessage.ADD_ATTRIBUTE);
  }
Exemple #3
0
  @Override
  public void update(Observable arg0, Object arg1) {
    boolean enable = false;
    if (arg1 != null && arg1.getClass() == UpdateMessage.class)
      switch ((UpdateMessage) arg1) {
        case SELECT:
          super.setSelected(true);
          break;

        case UNSELECT:
          super.setSelected(false);
          break;

        case ADD_ATTRIBUTE:
          enable = true;
        case ADD_ATTRIBUTE_NO_EDIT:
          addAttribute(component.getAttributes().getLast(), enable);
          break;

        case ADD_METHOD:
          enable = true;
        case ADD_METHOD_NO_EDIT:
          addMethod(component.getMethods().getLast(), enable);
          break;
      }
    else regenerateEntity();
  }
Exemple #4
0
  @Override
  public void setSelected(boolean select) {
    super.setSelected(select);

    component.select();

    if (select) component.notifyObservers(UpdateMessage.SELECT);
    else component.notifyObservers(UpdateMessage.UNSELECT);

    if (!select) for (final TextBox t : getAllTextBox()) t.setSelected(false);
  }
Exemple #5
0
  /**
   * Remove the method associated with TextBoxMethod from model (UML)
   *
   * @param tbMethod the method to remove.
   * @return true if component has been removed; false otherwise.
   */
  public boolean removeMethod(TextBoxMethod tbMethod) {
    if (component.removeMethod((Method) tbMethod.getAssociedComponent())) {
      component.notifyObservers();

      updateHeight();

      return true;
    }

    return false;
  }
Exemple #6
0
  /**
   * Remove the attribute associated with TextBoxAttribute from model (UML).
   *
   * @param tbAttribute the attribute to remove.
   * @return true if the attribute has been removed; false otherwise
   */
  public boolean removeAttribute(TextBoxAttribute tbAttribute) {
    if (component.removeAttribute((Attribute) tbAttribute.getAssociedComponent())) {
      component.notifyObservers();

      updateHeight();

      return true;
    }

    return false;
  }
Exemple #7
0
  @Override
  public void actionPerformed(ActionEvent e) {
    super.actionPerformed(e);

    if ("AddMethod".equals(e.getActionCommand())) addMethod();
    else if ("AddAttribute".equals(e.getActionCommand())) addAttribute();
    else if ("Delete".equals(e.getActionCommand())) {
      if (SMessageDialog.showQuestionMessageYesNo(
              "Are you sur to delete this component and all its associated components?")
          == JOptionPane.NO_OPTION) return;

      if (pressedTextBox != null) removeTextBox(pressedTextBox);
      else delete();
    } else if ("ViewAttribute".equals(e.getActionCommand())) {
      parent.showAttributsForSelectedEntity(true);
      parent.showMethodsForSelectedEntity(false);
    } else if ("ViewMethods".equals(e.getActionCommand())) {
      parent.showAttributsForSelectedEntity(false);
      parent.showMethodsForSelectedEntity(true);
    } else if ("ViewAll".equals(e.getActionCommand())) {
      parent.showAttributsForSelectedEntity(true);
      parent.showMethodsForSelectedEntity(true);
    } else if ("ViewNothing".equals(e.getActionCommand())) {
      parent.showAttributsForSelectedEntity(false);
      parent.showMethodsForSelectedEntity(false);
    } else if ("ViewTypeAndName".equals(e.getActionCommand()))
      methodViewChangeClicked(ParametersViewStyle.TYPE_AND_NAME);
    else if ("ViewType".equals(e.getActionCommand()))
      methodViewChangeClicked(ParametersViewStyle.TYPE);
    else if ("ViewName".equals(e.getActionCommand()))
      methodViewChangeClicked(ParametersViewStyle.NAME);
    else if ("ViewMethodNothing".equals(e.getActionCommand()))
      methodViewChangeClicked(ParametersViewStyle.NOTHING);
    else if (Slyum.ACTION_TEXTBOX_UP.equals(e.getActionCommand())
        || Slyum.ACTION_TEXTBOX_DOWN.equals(e.getActionCommand())) {
      int offset = 1;

      if (Slyum.ACTION_TEXTBOX_UP.equals(e.getActionCommand())) offset = -1;

      if (pressedTextBox.getClass() == TextBoxAttribute.class) {
        final Attribute attribute =
            (Attribute) ((TextBoxAttribute) pressedTextBox).getAssociedComponent();
        component.moveAttributePosition(attribute, offset);
      } else if (pressedTextBox.getClass() == TextBoxMethod.class) {
        final Method method = (Method) ((TextBoxMethod) pressedTextBox).getAssociedComponent();
        component.moveMethodPosition(method, offset);
      }

      component.notifyObservers();
    }
  }
Exemple #8
0
  @Override
  public void maybeShowPopup(MouseEvent e, JPopupMenu popupMenu) {
    if (e.isPopupTrigger()) {
      String text = "Delete ";

      // if context menu is requested on a TextBox, customize popup menu.
      if (pressedTextBox != null) {
        text += pressedTextBox.getText();
        menuItemMoveUp.setEnabled(
            attributesView.indexOf(pressedTextBox) != 0
                && methodsView.indexOf(pressedTextBox) != 0);
        menuItemMoveDown.setEnabled(
            (attributesView.size() == 0
                    || attributesView.indexOf(pressedTextBox) != attributesView.size() - 1)
                && (methodsView.size() == 0
                    || methodsView.indexOf(pressedTextBox) != methodsView.size() - 1));
      } else {
        text += component.getName();
        menuItemMoveUp.setEnabled(false);
        menuItemMoveDown.setEnabled(false);
      }
      menuItemDelete.setText(text);
    }

    super.maybeShowPopup(e, popupMenu);
  }
Exemple #9
0
  /** Delete all TextBox and regenerate them. !! This method take time !! */
  public void regenerateEntity() {
    boolean isStopRepaint = parent.getStopRepaint();
    parent.setStopRepaint(true);

    methodsView.clear();
    attributesView.clear();

    entityName.setText(component.getName());

    for (final Attribute a : component.getAttributes()) addAttribute(a, false);

    for (final Method m : component.getMethods()) addMethod(m, false);

    if (!isStopRepaint) parent.goRepaint();

    updateHeight();
  }
Exemple #10
0
  /**
   * Compute the height of the class with margin and content.
   *
   * @param classNameHeight the height of class name
   * @param stereotypeHeight the height of stereotype
   * @param elementsHeight the height of each element (methods, attributes)
   * @return the height of the class
   */
  public int computeHeight(int classNameHeight, int stereotypeHeight, int elementsHeight) {
    int height = VERTICAL_SPACEMENT;

    if (!component.getStereotype().isEmpty()) height += stereotypeHeight;

    height += classNameHeight;

    if (displayMethods) height += elementsHeight * methodsView.size();

    if (displayAttributes) height += elementsHeight * attributesView.size();

    return height + 30;
  }
Exemple #11
0
  @Override
  public void paintComponent(Graphics2D g2) {
    if (!isVisible()) return;

    final Color textColor = new Color(40, 40, 40);
    final Color borderColor = new Color(65, 65, 65);
    final GradientPaint backGradient =
        new GradientPaint(
            bounds.x,
            bounds.y,
            getColor(),
            bounds.x + bounds.width,
            bounds.y + bounds.height,
            getColor().darker());

    final String className = component.getName();

    final FontMetrics classNameMetrics = g2.getFontMetrics(entityName.getEffectivFont());
    final int classNameWidth = classNameMetrics.stringWidth(className);
    final int classNameHeight = classNameMetrics.getHeight();

    final Dimension classNameSize = new Dimension(classNameWidth, classNameHeight);

    stereotypeFont = stereotypeFont.deriveFont(stereotypeFontBasic.getSize() * parent.getZoom());

    g2.setFont(stereotypeFont);
    final String stereotype =
        Utility.truncate(g2, "<<" + component.getStereotype() + " >>", bounds.width - 15);

    final FontMetrics stereotypeMetrics = g2.getFontMetrics(stereotypeFont);
    final int stereotypeWidth = stereotypeMetrics.stringWidth(stereotype);
    final int stereotypeHeight = stereotypeMetrics.getHeight();

    final Dimension stereotypeSize = new Dimension(stereotypeWidth, stereotypeHeight);

    final FontMetrics metrics = g2.getFontMetrics(entityName.getEffectivFont());
    final int textBoxHeight = metrics.getHeight();

    bounds.height = computeHeight(classNameSize.height, stereotypeHeight, textBoxHeight);

    final Rectangle bounds = getBounds();

    int offset = bounds.y + VERTICAL_SPACEMENT / 2;
    final int stereotypeLocationWidth = bounds.x + (bounds.width - stereotypeSize.width) / 2;

    entityName.setBounds(new Rectangle(1, 1, bounds.width - 15, textBoxHeight + 2));
    final Rectangle entityNameBounds = entityName.getBounds();
    final int classNameLocationX = bounds.x + (bounds.width - entityNameBounds.width) / 2;

    // draw background
    g2.setPaint(backGradient);
    g2.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);

    // draw border
    g2.setStroke(new BasicStroke(BORDER_WIDTH));
    g2.setColor(borderColor);
    g2.drawRect(bounds.x, bounds.y, bounds.width, bounds.height);

    // draw stereotype
    if (!component.getStereotype().isEmpty()) {
      offset += stereotypeSize.height;

      g2.setFont(stereotypeFont);
      g2.setColor(textColor);
      g2.drawString(stereotype, stereotypeLocationWidth, offset);
    }

    // draw class name
    offset += /* classNameSize.height + */ VERTICAL_SPACEMENT / 2;

    entityName.setBounds(
        new Rectangle(classNameLocationX, offset, bounds.width - 15, textBoxHeight + 2));
    entityName.paintComponent(g2);

    offset += entityNameBounds.height;

    // draw separator
    offset += 10;
    g2.setStroke(new BasicStroke(BORDER_WIDTH));
    g2.setColor(borderColor);
    g2.drawLine(bounds.x, offset, bounds.x + bounds.width, offset);

    // draw attributes
    if (displayAttributes && attributesView.size() > 0)
      // draw methods
      for (final TextBoxAttribute tb : attributesView) {
        tb.setBounds(new Rectangle(bounds.x + 8, offset + 2, bounds.width - 15, textBoxHeight + 2));
        tb.paintComponent(g2);

        offset += textBoxHeight;
      }

    // draw separator
    offset += 10;
    g2.setStroke(new BasicStroke(BORDER_WIDTH));
    g2.setColor(borderColor);
    g2.drawLine(bounds.x, offset, bounds.x + bounds.width, offset);

    // draw methods
    if (displayMethods && methodsView.size() > 0)
      // draw methods
      for (final TextBoxMethod tb : methodsView) {
        tb.setBounds(new Rectangle(bounds.x + 8, offset + 2, bounds.width - 15, textBoxHeight + 2));
        tb.paintComponent(g2);

        offset += textBoxHeight;
      }

    // is component selected? -> draw selected style
    if (parent.getSelectedComponents().contains(this)) drawSelectedStyle(g2);
  }
Exemple #12
0
  public ClassEntityView(final GraphicView parent, Entity component) {
    super(parent);

    if (component == null) throw new IllegalArgumentException("component is null");

    this.component = component;

    // Create a textBox for display the entity name.
    entityName = new TextBoxEntityName(parent, component);

    // Create the popup menu.
    JMenuItem menuItem;

    popupMenu.addSeparator();

    menuItem = makeMenuItem("Add attribute", "AddAttribute", "attribute");
    popupMenu.add(menuItem);

    menuItem = makeMenuItem("Add method", "AddMethod", "method");
    popupMenu.add(menuItem);

    popupMenu.addSeparator();

    menuItemMoveUp = menuItem = makeMenuItem("Move up", Slyum.ACTION_TEXTBOX_UP, "direction_up");
    menuItemMoveUp.setEnabled(false);
    popupMenu.add(menuItem);

    menuItemMoveDown =
        menuItem = makeMenuItem("Move down", Slyum.ACTION_TEXTBOX_DOWN, "direction_down");
    menuItemMoveDown.setEnabled(false);
    popupMenu.add(menuItem);

    popupMenu.addSeparator();

    menuItemDelete = menuItem = makeMenuItem("Delete", "Delete", "delete16");
    popupMenu.add(menuItem);

    popupMenu.addSeparator();

    JMenu subMenu = new JMenu("View");
    subMenu.setIcon(PersonalizedIcon.createImageIcon(Slyum.ICON_PATH + "visibility.png"));
    ButtonGroup group = new ButtonGroup();

    JRadioButtonMenuItem rbMenuItem = makeRadioButtonMenuItem("All", "ViewAll", group);
    rbMenuItem.setSelected(true);
    subMenu.add(rbMenuItem);

    rbMenuItem = makeRadioButtonMenuItem("Only Attributes", "ViewAttribute", group);
    subMenu.add(rbMenuItem, 1);

    rbMenuItem = makeRadioButtonMenuItem("Only Methods", "ViewMethods", group);
    subMenu.add(rbMenuItem, 2);

    rbMenuItem = makeRadioButtonMenuItem("Nothing", "ViewNothing", group);
    subMenu.add(rbMenuItem);

    popupMenu.add(subMenu);

    subMenu = new JMenu("Methods View");
    subMenu.setIcon(PersonalizedIcon.createImageIcon("resources/icon/visibility.png"));
    group = new ButtonGroup();

    rbMenuItem = makeRadioButtonMenuItem("Type and Name", "ViewTypeAndName", group);
    rbMenuItem.setSelected(true);
    subMenu.add(rbMenuItem);

    rbMenuItem = makeRadioButtonMenuItem("Type", "ViewType", group);
    subMenu.add(rbMenuItem, 1);

    rbMenuItem = makeRadioButtonMenuItem("Name", "ViewName", group);
    subMenu.add(rbMenuItem, 2);

    rbMenuItem = makeRadioButtonMenuItem("Nothing", "ViewMethodNothing", group);
    subMenu.add(rbMenuItem);

    popupMenu.add(subMenu);

    popupMenu.addSeparator();

    SPanelZOrder p = SPanelZOrder.getInstance();
    menuItem = makeMenuItem("Move top", "ZOrderTOP", "top");
    p.getBtnTop().linkComponent(menuItem);
    popupMenu.add(menuItem);

    menuItem = makeMenuItem("Up", "ZOrderUP", "up");
    p.getBtnUp().linkComponent(menuItem);
    popupMenu.add(menuItem);

    menuItem = makeMenuItem("Down", "ZOrderDown", "down");
    p.getBtnDown().linkComponent(menuItem);
    popupMenu.add(menuItem);

    menuItem = makeMenuItem("Move bottom", "ZOrderBottom", "bottom");
    p.getBtnBottom().linkComponent(menuItem);
    popupMenu.add(menuItem);

    component.addObserver(this);

    setColor(getBasicColor());
  }