public void applyTo(Shape shape, int i) {
   int setting = (int) elements[i].getValue();
   if (setting == 1) {
     shape.setEnabled(true);
   } else {
     shape.setEnabled(false);
   }
 }
  protected void removeHighlight() {
    Set<IFigure> colorFigures = figureToColor.keySet();
    for (IFigure colorFigure : colorFigures) {
      Color oldColor = figureToColor.get(colorFigure);
      colorFigure.setForegroundColor(oldColor);
    }

    Set<Shape> lineStyleShapes = shapeToLineStyle.keySet();
    for (Shape lineStyleShape : lineStyleShapes) {
      int lineStyle = shapeToLineStyle.get(lineStyleShape);
      lineStyleShape.setLineStyle(lineStyle);
    }

    figureToColor.clear();
    shapeToLineStyle.clear();
  }
  protected void showHighlight() {
    // remove previous highlight
    removeHighlight();

    // determine new highlight-values
    Color newForeground = GFColorConstants.HANDLE_BG;
    int newLineStyle = Graphics.LINE_DASH;

    if (getHost() != null && getHost().getModel() instanceof Connection) {
      Connection connection = (Connection) getHost().getModel();
      IToolBehaviorProvider tbp =
          getConfigurationProvider().getDiagramTypeProvider().getCurrentToolBehaviorProvider();
      ISelectionInfo selectionInfo = tbp.getSelectionInfoForConnection(connection);
      if (selectionInfo != null) {
        IColorConstant selectionColor = selectionInfo.getColor();
        if (selectionColor != null) {
          newForeground =
              DataTypeTransformation.toSwtColor(
                  getConfigurationProvider().getResourceRegistry(), selectionColor);
        }
        LineStyle selectionLineStyle = selectionInfo.getLineStyle();
        if (selectionLineStyle != null) {
          newLineStyle = DataTypeTransformation.toDraw2dLineStyle(selectionLineStyle);
        }
      }
    }

    // store old highlight-values and set new highlight-values
    // important: get old colors via getLocalForeGround() to ignore parent
    Collection<Shape> connectionFigures = getConnectionFigures();
    for (Shape connectionFigure : connectionFigures) {
      figureToColor.put(connectionFigure, connectionFigure.getLocalForegroundColor());
      connectionFigure.setForegroundColor(newForeground);
      shapeToLineStyle.put(connectionFigure, connectionFigure.getLineStyle());
      connectionFigure.setLineStyle(newLineStyle);

      if (connectionFigure instanceof GFPolylineConnection) {
        GFPolylineConnection polylineConnection = (GFPolylineConnection) connectionFigure;
        List<IFigure> allDecorations = polylineConnection.getAllDecorations();
        for (IFigure decoration : allDecorations) {
          if (decoration != null) {
            figureToColor.put(decoration, decoration.getLocalForegroundColor());
            decoration.setForegroundColor(newForeground);
            if (decoration instanceof Shape) {
              Shape decorationShape = (Shape) decoration;
              shapeToLineStyle.put(decorationShape, new Integer(decorationShape.getLineStyle()));
              decorationShape.setLineStyle(newLineStyle);
            }
          }
        }
      }
    }
  }
  /** @see IFigure#validate() */
  @Override
  public void validate() {
    super.validate();
    Rectangle r = new Rectangle();
    r.setBounds(getBounds());
    r.crop(getInsets());
    r.resize(-1, -1);
    int size;
    switch (direction & (NORTH | SOUTH)) {
      case 0: // East or west.
        size = Math.min(r.height / 2, r.width);
        r.x += (r.width - size) / 2;
        break;
      default: // North or south
        size = Math.min(r.height, r.width / 2);
        r.y += (r.height - size) / 2;
        break;
    }

    size = Math.max(size, 1); // Size cannot be negative

    Point head, p2, p3;

    switch (direction) {
      case NORTH:
        head = new Point(r.x + r.width / 2, r.y);
        p2 = new Point(head.x - size, head.y + size);
        p3 = new Point(head.x + size, head.y + size);
        break;
      case SOUTH:
        head = new Point(r.x + r.width / 2, r.y + size);
        p2 = new Point(head.x - size, head.y - size);
        p3 = new Point(head.x + size, head.y - size);
        break;
      case WEST:
        head = new Point(r.x, r.y + r.height / 2);
        p2 = new Point(head.x + size, head.y - size);
        p3 = new Point(head.x + size, head.y + size);
        break;
      default:
        head = new Point(r.x + size, r.y + r.height / 2);
        p2 = new Point(head.x - size, head.y - size);
        p3 = new Point(head.x - size, head.y + size);
    }
    triangle.removeAllPoints();
    triangle.addPoint(head);
    triangle.addPoint(p2);
    triangle.addPoint(p3);
  }
Example #5
0
  private void doUpdateFigure(Connection connection) {
    if (connection == null || this.isDisposed()) {
      return;
    }
    Shape connectionShape = (Shape) connection;

    connectionShape.setLineStyle(getLineStyle());

    if (this.getText() != null || this.getImage() != null) {
      if (this.getImage() != null) {
        this.connectionLabel.setIcon(this.getImage());
      }
      if (this.getText() != null) {
        this.connectionLabel.setText(this.getText());
      }
      this.connectionLabel.setFont(this.getFont());
    }

    if (highlighted) {
      connectionShape.setForegroundColor(getHighlightColor());
      connectionShape.setLineWidth(getLineWidth() * 2);
    } else {
      connectionShape.setForegroundColor(getLineColor());
      connectionShape.setLineWidth(getLineWidth());
    }

    if (connection instanceof PolylineArcConnection) {
      PolylineArcConnection arcConnection = (PolylineArcConnection) connection;
      arcConnection.setDepth(curveDepth);
    }
    if (connectionFigure != null) {
      applyConnectionRouter(connectionFigure);
    }
    if ((connectionStyle & ZestStyles.CONNECTIONS_DIRECTED) > 0) {
      PolygonDecoration decoration = new PolygonDecoration();
      if (getLineWidth() < 3) {
        decoration.setScale(9, 3);
      } else {
        double logLineWith = getLineWidth() / 2.0;
        decoration.setScale(7 * logLineWith, 3 * logLineWith);
      }
      ((PolylineConnection) connection).setTargetDecoration(decoration);
    }

    IFigure toolTip;
    if (this.getTooltip() == null
        && getText() != null
        && getText().length() > 0
        && hasCustomTooltip == false) {
      toolTip = new Label();
      ((Label) toolTip).setText(getText());
    } else {
      toolTip = this.getTooltip();
    }
    connection.setToolTip(toolTip);
  }
 /** @see Figure#primTranslate(int, int) */
 @Override
 public void primTranslate(int dx, int dy) {
   super.primTranslate(dx, dy);
   triangle.translate(dx, dy);
 }
 /** @generated */
 protected void setLineWidth(int width) {
   if (primaryShape instanceof Shape) {
     ((Shape) primaryShape).setLineWidth(getMapMode().DPtoLP(width));
   }
 }
Example #8
0
 @Override
 public void repaint() {
   super.repaint();
 }
Example #9
0
 @Override
 public void paint(Graphics graphics) {
   super.paint(graphics);
 }
 public void applyTo(Shape shape, int i) {
   shape.setAntialias((int) elements[i].getValue());
 }
 public void applyTo(Shape shape, int i) {
   shape.setLineMiterLimit(elements[i].getValue());
 }
 public void applyTo(Shape shape, int i) {
   shape.setLineCap((int) elements[i].getValue());
 }
 public void applyTo(Shape shape, int i) {
   shape.setLineWidthFloat(elements[i].getValue());
 }
  static void refreshGrid() {
    if (styleGrid != null) {
      styleGrid.dispose();
      shell.pack();
    }

    styleGrid = new Group(shell, SWT.NONE);
    styleGrid.setText(xAxis.getName() + " vs. " + yAxis.getName());
    styleGrid.setLayout(new GridLayout(xAxis.getCount() + 1, false));
    styleGrid.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1));

    // put blank label in top left corner
    Label label = new Label(styleGrid, SWT.NONE);

    // add x-axis labels
    for (int x = 0; x < xAxis.getCount(); x++) {
      label = new Label(styleGrid, SWT.NONE);
      label.setText(xAxis.getName() + " =\n" + xAxis.getAt(x).getName());
    }

    // iterate over the y-axis style settings
    for (int y = 1; y < yAxis.getCount() + 1; y++) {

      // add y-axis label for this row
      label = new Label(styleGrid, SWT.NONE);
      label.setText(yAxis.getName() + " =\n" + yAxis.getAt(y - 1).getName());

      // iterate over the x-axis style settings
      for (int x = 1; x < xAxis.getCount() + 1; x++) {

        // create a sample shape instance
        Shape shape;
        if (sampleShape == Polyline.class) {
          Polyline poly = new Polyline();
          poly.addPoint(new Point(20, 20));
          poly.addPoint(new Point(50, 80));
          poly.addPoint(new Point(10, 50));
          shape = poly;
        } else {
          try {
            shape = (Shape) sampleShape.getConstructor(null).newInstance(null);
          } catch (Exception e) {
            throw new RuntimeException(
                "Could not find a no args constructor for " + sampleShape.getName());
          }
          shape.setBounds(new Rectangle(0, 0, 100, 75));
        }

        // apply default style
        shape.setBackgroundColor(ColorConstants.orange());
        shape.setLineWidthFloat(defaultLineWidth);
        shape.setAntialias(SWT.ON);

        // apply styles imposed by each axis
        xAxis.applyTo(shape, x - 1);
        yAxis.applyTo(shape, y - 1);

        FigureCanvas figureBox = new FigureCanvas(styleGrid);
        figureBox.setContents(shape);
      }
    }
    shell.pack();
  }
 /** @generated */
 protected void setLineWidth(int width) {
   if (primaryShape instanceof Shape) {
     ((Shape) primaryShape).setLineWidth(width);
   }
 }
 /** @generated */
 protected void setLineType(int style) {
   if (primaryShape instanceof Shape) {
     ((Shape) primaryShape).setLineStyle(style);
   }
 }
 public void applyTo(Shape shape, int i) {
   shape.setLineDashOffset(elements[i].getValue());
 }