예제 #1
0
  /**
   * Create a new method view with the given method. If editing is a true, the new method view will
   * be in editing mode while it created.
   *
   * @param method the method UML
   * @param editing true if creating a new method view in editing mode; false otherwise
   */
  public void addMethod(Method method, boolean editing) {
    final TextBoxMethod newTextBox = new TextBoxMethod(parent, method);
    methodsView.add(newTextBox);

    updateHeight();

    if (editing) newTextBox.editing();
  }
예제 #2
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;
  }
예제 #3
0
 /**
  * Change the display style of parameters for the pressed TextBox if exists, or for all otherwise.
  *
  * @param newStyle the new display style
  */
 private void methodViewChangeClicked(ParametersViewStyle newStyle) {
   if (pressedTextBox instanceof TextBoxMethod)
     ((TextBoxMethod) pressedTextBox).setParametersViewStyle(newStyle);
   else
     for (final AbstractEntityView ev : parent.getSelectedEntities())
       if (ev instanceof ClassEntityView) {
         ((ClassEntityView) ev).methodViewChange(newStyle);
       } else {
         JOptionPane.showMessageDialog(null, "ERREUR #875");
       }
 }
예제 #4
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);
  }
예제 #5
0
 /**
  * Change the display style of parameters for all methods.
  *
  * @param newStyle the new display style
  */
 public void methodViewChange(ParametersViewStyle newStyle) {
   for (final TextBoxMethod tbm : methodsView) tbm.setParametersViewStyle(newStyle);
 }