public BufferedImage[] createUI(TComponent component, int w, int h) {
    BufferedImage[] ui = GraphicsUtil.createImage(3, w, h, Transparency.OPAQUE);

    String[] color =
        new String[] {
          "Background Color", "Background Disabled Color", "Background Uneditable Color"
        };
    String[] border =
        new String[] {
          "Background Border Color",
          "Background Border Disabled Color",
          "Background Border Uneditable Color"
        };

    for (int i = 0; i < ui.length; i++) {
      Graphics2D g = ui[i].createGraphics();

      g.setColor((Color) get(color[i], component));
      g.fillRect(0, 0, w, h);

      g.setColor((Color) get(border[i], component));
      g.drawRect(0, 0, w - 1, h - 1);

      g.dispose();
    }

    return ui;
  }
Ejemplo n.º 2
0
public class SearchWidget extends Composite {

  private final String SEARCH_BUTTON_URI = GraphicsUtil.uri("search-button.png");

  TextBox searchBox = new TextBox();
  Image searchButtonImage = new Image(SEARCH_BUTTON_URI);

  public SearchWidget() {
    Label titleLabel = new Label("Search");
    titleLabel.setStyleName("istore-section-title");
    searchBox.setStyleName("istore-search-box");
    searchButtonImage.setStyleName("istore-search-button");

    FlowPanel flowPanel = new FlowPanel();
    flowPanel.add(titleLabel);
    flowPanel.add(searchBox);
    flowPanel.add(searchButtonImage);
    flowPanel.setStyleName("istore-search-panel");

    initWidget(flowPanel);

    setInProgress(false);

    // Translate the click event into a search event.
    searchButtonImage.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            setInProgress(true);
            SearchWidget.this.fireEvent(new SearchEvent(SearchWidget.this, searchBox.getText()));
          }
        });

    // Translate the enter key into a search event too.
    searchBox.addKeyPressHandler(
        new KeyPressHandler() {
          public void onKeyPress(KeyPressEvent event) {
            if (event.getCharCode() == 13) {
              setInProgress(true);
              SearchWidget.this.fireEvent(new SearchEvent(SearchWidget.this, searchBox.getText()));
            }
          }
        });
  }

  public void setInProgress(boolean inProgress) {
    if (inProgress) {
      searchButtonImage.addStyleName("istore-search-button-progress");
      searchBox.addStyleName("istore-search-box-progress");
    } else {
      searchButtonImage.removeStyleName("istore-search-button-progress");
      searchBox.removeStyleName("istore-search-box-progress");
    }
    searchBox.setReadOnly(inProgress);
  }

  public <T> void addSearchHandler(SearchHandler<T> handler) {
    addHandler(handler, SearchEvent.getType());
  }
}
Ejemplo n.º 3
0
  public static List<ContainerShape> findGroupedShapes(ContainerShape groupShape) {
    Diagram diagram = null;
    EObject parent = groupShape.eContainer();
    while (parent != null) {
      if (parent instanceof Diagram) {
        diagram = (Diagram) parent;
        break;
      }
      parent = parent.eContainer();
    }

    // find all shapes that are inside this Group
    // these will be moved along with the Group
    List<ContainerShape> list = new ArrayList<ContainerShape>();
    if (diagram != null && isGroupShape(groupShape)) {
      TreeIterator<EObject> iter = diagram.eAllContents();
      while (iter.hasNext()) {
        EObject child = iter.next();
        if (child instanceof ContainerShape
            && child != groupShape
            && !list.contains(child)
            && !isLabelShape((ContainerShape) child)) {
          ContainerShape shape = (ContainerShape) child;
          if (isGroupShape(shape)) {
            if (GraphicsUtil.contains(groupShape, shape)) {
              if (!list.contains(shape)) {
                list.add(shape);
              }
            }
          } else if (GraphicsUtil.contains(groupShape, shape)) {
            if (!list.contains(shape)) {
              list.add(shape);
            }
            // find this shape's parent ContainerShape if it has one
            while (!(shape.getContainer() instanceof Diagram)) {
              shape = shape.getContainer();
            }
            if (!list.contains(shape) && shape != groupShape) {
              list.add(shape);
            }
          }
        }
      }
    }
    return list;
  }
Ejemplo n.º 4
0
  public void draw(Graphics g) {
    if (isInitial()) {
      double dx = x - RADIUS / Math.sqrt(2.0);
      double dy = y + RADIUS / Math.sqrt(2.0);
      double th = 0.75 * Math.PI;
      int[] xp = {
        (int) (dx + Transition.ARROW_LEN * Math.cos(th + Transition.ARROW_THETA)),
        (int) dx,
        (int) (dx + Transition.ARROW_LEN * Math.cos(th - Transition.ARROW_THETA)),
      };
      int[] yp = {
        (int) (dy + Transition.ARROW_LEN * Math.sin(th + Transition.ARROW_THETA)),
        (int) dy,
        (int) (dy + Transition.ARROW_LEN * Math.sin(th - Transition.ARROW_THETA)),
      };

      GraphicsUtil.switchToWidth(g, 3);
      g.setColor(Color.blue);
      g.drawPolyline(xp, yp, 3);
      g.drawLine((int) (dx - INITARROW_LEN), (int) (dy + INITARROW_LEN), (int) dx, (int) dy);
    }

    Color bg = getAutomaton().getCurrentDraw().contains(this) ? Color.green : Color.red;
    GraphicsUtil.switchToWidth(g, 3);
    if (isFinal()) {
      g.setColor(Color.white);
      g.fillOval(x - RADIUS, y - RADIUS, 2 * RADIUS, 2 * RADIUS);
      g.setColor(bg);
      g.fillOval(x - RADIUS + 6, y - RADIUS + 6, 2 * RADIUS - 12, 2 * RADIUS - 12);
      g.setColor(Color.black);
      g.drawOval(x - RADIUS, y - RADIUS, 2 * RADIUS, 2 * RADIUS);
      g.drawOval(x - RADIUS + 5, y - RADIUS + 5, 2 * RADIUS - 10, 2 * RADIUS - 10);
      g.drawString(getName(), x - 8, y + 4);
    } else {
      g.setColor(bg);
      g.fillOval(x - RADIUS + 1, y - RADIUS + 1, 2 * RADIUS - 2, 2 * RADIUS - 2);
      g.setColor(Color.black);
      g.drawOval(x - RADIUS, y - RADIUS, 2 * RADIUS, 2 * RADIUS);
      g.drawString(getName(), x - 8, y + 4);
    }
  }
Ejemplo n.º 5
0
 public static IDimension getExpandedSize(PictogramElement pe) {
   IDimension size = GraphicsUtil.calculateSize(pe);
   String property = Graphiti.getPeService().getPropertyValue(pe, GraphitiConstants.EXPANDED_SIZE);
   if (property != null) {
     int index = property.indexOf(',');
     int w = Integer.parseInt(property.substring(0, index));
     int h = Integer.parseInt(property.substring(index + 1));
     size.setWidth(w);
     size.setHeight(h);
   }
   return size;
 }
  /*.................................................................................................................*/
  public Object doCommand(String commandName, String arguments, CommandChecker checker) {
    Tree trt = treeDisplay.getTree();
    MesquiteTree t = null;
    if (trt instanceof MesquiteTree) t = (MesquiteTree) trt;
    if (checker.compare(
        this.getClass(),
        "Adjust tool has touched branch",
        "[branch number][x coordinate touched][y coordinate touched][modifiers]",
        commandName,
        "touchedPositionAdjust")) {
      if (t == null) return null;
      MesquiteInteger io = new MesquiteInteger(0);
      int node = MesquiteInteger.fromString(arguments, io);
      int x = MesquiteInteger.fromString(arguments, io);
      int y = MesquiteInteger.fromString(arguments, io);
      String mod = ParseUtil.getRemaining(arguments, io);

      Point newOnLine = treeDisplay.getTreeDrawing().projectionOnLine(node, x, y);
      originalX = newOnLine.x;
      originalY = newOnLine.y;
      // lastX= newOnLine.x;
      // lastY = newOnLine.y;
      Graphics g = null;
      if (GraphicsUtil.useXORMode(null, false)) {
        g = treeDisplay.getGraphics();
        g.setXORMode(Color.white);
        g.setColor(Color.red);
      }
      // double bX = treeDisplay.getTreeDrawing().lineBaseX[node];
      // double bY = treeDisplay.getTreeDrawing().lineBaseY[node];
      // Math.sqrt((originalY-bY)*(originalY-bY) + (originalX-bX)*(originalX-bX));
      lastBL = tree.getBranchLength(node);
      double shortestAbove = MesquiteDouble.unassigned;
      for (int daughter = t.firstDaughterOfNode(node);
          t.nodeExists(daughter);
          daughter = t.nextSisterOfNode(daughter))
        shortestAbove = MesquiteDouble.minimum(shortestAbove, tree.getBranchLength(daughter));
      if (shortestAbove == MesquiteDouble.unassigned) upperLimit = MesquiteDouble.infinite;
      else if (MesquiteDouble.isCombinable(lastBL)) upperLimit = shortestAbove + lastBL;
      else upperLimit = shortestAbove + 1.0;
      int ibX = treeDisplay.getTreeDrawing().lineBaseX[node];
      int ibY = treeDisplay.getTreeDrawing().lineBaseY[node];
      lastX = treeDisplay.getTreeDrawing().lineTipX[node];
      lastY = treeDisplay.getTreeDrawing().lineTipY[node];
      if (GraphicsUtil.useXORMode(null, false)) {
        drawThickLine(g, ibX, ibY, lastX, lastY);
        for (int daughter = t.firstDaughterOfNode(node);
            t.nodeExists(daughter);
            daughter = t.nextSisterOfNode(daughter))
          drawThickLine(
              g,
              treeDisplay.getTreeDrawing().lineTipX[daughter],
              treeDisplay.getTreeDrawing().lineTipY[daughter],
              lastX,
              lastY);
        g.fillOval(
            lastX - ovalRadius,
            lastY - ovalRadius,
            ovalRadius + ovalRadius,
            ovalRadius + ovalRadius);
        try {
          g.drawString(MesquiteDouble.toString(lastBL), lastX + 10, lastY);
        } catch (InternalError e) { // workaround for bug on windows java 1.7.
        } catch (Throwable e) {
        }
        lineOn = true;
        g.dispose();
      }
    } else if (checker.compare(
        this.getClass(),
        "Adjust tool has been dropped",
        "[branch number][x coordinate dropped][y coordinate dropped]",
        commandName,
        "droppedPositionAdjust")) {
      if (t == null) return null;
      if (editorOn) return null;
      MesquiteInteger io = new MesquiteInteger(0);
      int node = MesquiteInteger.fromString(arguments, io);
      int x = MesquiteInteger.fromString(arguments, io);
      int y = MesquiteInteger.fromString(arguments, io);
      if (lineOn) {
        Point newOnLine = treeDisplay.getTreeDrawing().projectionOnLine(node, x, y);
        double bX = treeDisplay.getTreeDrawing().lineBaseX[node];
        double bY = treeDisplay.getTreeDrawing().lineBaseY[node];
        double tX = treeDisplay.getTreeDrawing().lineTipX[node];
        double tY = treeDisplay.getTreeDrawing().lineTipY[node];
        double lengthLine =
            Math.sqrt((originalY - bY) * (originalY - bY) + (originalX - bX) * (originalX - bX));
        double bL;
        if (lengthLine != 0) {
          double extension =
              Math.sqrt(
                      (newOnLine.y - bY) * (newOnLine.y - bY)
                          + (newOnLine.x - bX) * (newOnLine.x - bX))
                  / lengthLine;
          if (t.getBranchLength(node) == 0 || t.branchLengthUnassigned(node)) bL = extension;
          else bL = t.getBranchLength(node) * extension;
        } else bL = 1;

        if (bL > upperLimit) bL = upperLimit;
        else if (bL < lowerLimit) bL = lowerLimit;
        double oldBL = t.getBranchLength(node);
        if (!MesquiteDouble.isCombinable(oldBL)) oldBL = 1.0;
        t.setBranchLength(node, bL, false);
        double difference = oldBL - t.getBranchLength(node);
        for (int daughter = t.firstDaughterOfNode(node);
            t.nodeExists(daughter);
            daughter = t.nextSisterOfNode(daughter))
          if (MesquiteDouble.isCombinable(t.getBranchLength(daughter)))
            t.setBranchLength(daughter, t.getBranchLength(daughter) + difference, false);
        t.notifyListeners(this, new Notification(MesquiteListener.BRANCHLENGTHS_CHANGED));
        Graphics g = treeDisplay.getGraphics();
        g.setPaintMode();
        g.dispose();
        treeDisplay.pleaseUpdate(true);
        lineOn = false;
      }
    } else if (checker.compare(
        this.getClass(),
        "Adjust tool is being dragged",
        "[branch number][x coordinate][y coordinate]",
        commandName,
        "draggedPositionAdjust")) {
      if (t == null) return null;
      if (editorOn) return null;
      MesquiteInteger io = new MesquiteInteger(0);
      int node = MesquiteInteger.fromString(arguments, io);
      int x = MesquiteInteger.fromString(arguments, io);
      int y = MesquiteInteger.fromString(arguments, io);
      if (lineOn) {
        Point newOnLine = treeDisplay.getTreeDrawing().projectionOnLine(node, x, y);
        // WARNING":  This shouldn't result in length increase if simple click and release with no
        // drag; must subtract original X, Y
        Graphics g = null;
        if (GraphicsUtil.useXORMode(null, false)) {
          g = treeDisplay.getGraphics();
          g.setXORMode(Color.white);
          g.setColor(Color.red);
        }
        // g.fillOval(lastX-ovalRadius, lastY-ovalRadius, ovalRadius + ovalRadius, ovalRadius +
        // ovalRadius);
        // g.fillOval(newOnLine.x-ovalRadius, newOnLine.y -ovalRadius, ovalRadius + ovalRadius,
        // ovalRadius + ovalRadius);

        // g.drawLine(originalX, originalY, lastX, lastY);
        // g.drawLine(originalX, originalY, newOnLine.x, newOnLine.y);

        //				if decreasing, & unassigned involved: push unassigned down and assign values to
        // unassigned above; if increasing, push unassigne up
        int ibX = treeDisplay.getTreeDrawing().lineBaseX[node];
        int ibY = treeDisplay.getTreeDrawing().lineBaseY[node];
        int itX = treeDisplay.getTreeDrawing().lineTipX[node];
        int itY = treeDisplay.getTreeDrawing().lineTipY[node];

        double bX = ibX;
        double bY = ibY;
        double tX = itX;
        double tY = itY;
        double lengthLine =
            Math.sqrt((originalY - bY) * (originalY - bY) + (originalX - bX) * (originalX - bX));
        if (lengthLine != 0) {
          if (GraphicsUtil.useXORMode(null, false)) {
            if (MesquiteTrunk.isMacOSX()
                && MesquiteTrunk.getJavaVersionAsDouble() >= 1.5
                && MesquiteTrunk.getJavaVersionAsDouble() < 1.6) // due to a JVM bug
            g.fillRect(lastX, lastY - 20, 100, 20);
            g.drawString(MesquiteDouble.toString(lastBL), lastX + 10, lastY);
            if (MesquiteTrunk.isMacOSX()
                && MesquiteTrunk.getJavaVersionAsDouble() >= 1.5
                && MesquiteTrunk.getJavaVersionAsDouble() < 1.6) // due to a JVM bug
            g.fillRect(lastX, lastY - 20, 100, 20);
          }
          double extension =
              Math.sqrt(
                      (newOnLine.y - bY) * (newOnLine.y - bY)
                          + (newOnLine.x - bX) * (newOnLine.x - bX))
                  / lengthLine;
          double bL;
          if (t.getBranchLength(node) == 0 || t.branchLengthUnassigned(node)) bL = extension;
          else bL = t.getBranchLength(node) * extension;
          if (bL > upperLimit) {
            bL = upperLimit;
            if (t.getBranchLength(node) == 0 || t.branchLengthUnassigned(node))
              extension = upperLimit;
            else extension = upperLimit / t.getBranchLength(node);
          } else if (bL < lowerLimit) {
            bL = lowerLimit;
            if (t.getBranchLength(node) == 0 || t.branchLengthUnassigned(node))
              extension = lowerLimit;
            else extension = lowerLimit / t.getBranchLength(node);
          }
          lastBL = bL;
          if (GraphicsUtil.useXORMode(null, false)) {
            drawThickLine(g, ibX, ibY, lastX, lastY);
            for (int daughter = t.firstDaughterOfNode(node);
                t.nodeExists(daughter);
                daughter = t.nextSisterOfNode(daughter))
              drawThickLine(
                  g,
                  treeDisplay.getTreeDrawing().lineTipX[daughter],
                  treeDisplay.getTreeDrawing().lineTipY[daughter],
                  lastX,
                  lastY);
            g.fillOval(
                lastX - ovalRadius,
                lastY - ovalRadius,
                ovalRadius + ovalRadius,
                ovalRadius + ovalRadius);
          }
          int newX = ibX + (int) (extension * (tX - bX));
          int newY = ibY + (int) (extension * (tY - bY));
          if (GraphicsUtil.useXORMode(null, false)) {
            g.drawString(MesquiteDouble.toString(bL), newX + 10, newY);
            drawThickLine(g, ibX, ibY, newX, newY);
            for (int daughter = t.firstDaughterOfNode(node);
                t.nodeExists(daughter);
                daughter = t.nextSisterOfNode(daughter))
              drawThickLine(
                  g,
                  treeDisplay.getTreeDrawing().lineTipX[daughter],
                  treeDisplay.getTreeDrawing().lineTipY[daughter],
                  newX,
                  newY);
            g.fillOval(
                newX - ovalRadius,
                newY - ovalRadius,
                ovalRadius + ovalRadius,
                ovalRadius + ovalRadius);
          }
          lastX = newX;
          lastY = newY;
        }

        // lastX= newOnLine.x;
        // lastY = newOnLine.y;
      }
    }
    return null;
  }
Ejemplo n.º 7
0
 public static void updateCollapsedSize(PictogramElement pe) {
   IDimension size = GraphicsUtil.calculateSize(pe);
   FeatureSupport.setCollapsedSize(pe, size);
 }
Ejemplo n.º 8
0
  /**
   * Draws a box container in the node's position in camera space.
   *
   * @param g2d
   * @param nodeData
   * @param colorNode
   * @param colorShadow
   * @param innerBox
   * @param colorInterior
   * @param shadow
   * @param selected
   */
  public static void drawNodeBox(
      Graphics2D g2d,
      int x,
      int y,
      int width,
      int height,
      Color colorNode,
      Color colorShadow,
      boolean innerBox,
      Color colorInterior,
      boolean shadow,
      boolean selected,
      int headerOffset,
      GraphCamera camera) {
    // Get the last color to set when done with operations.
    Color lastColor = g2d.getColor();

    // Get the last stroke.
    Stroke lastStroke = g2d.getStroke();

    // Gradient color.
    Color colorGradient = GraphicsUtil.getColorDifference(colorNode, -20);
    Color colorHeader = GraphicsUtil.getColorDifference(colorNode, 20);

    Paint paintHeader =
        new GradientPaint(
            x,
            y + (int) ((headerOffset) * camera.getScale()),
            colorHeader,
            x,
            y + (int) ((headerOffset + 4) * camera.getScale()),
            colorGradient);

    // Set our stroke to a line with 6 pixels in width.
    g2d.setStroke(new BasicStroke(6));

    /*
     * If we want to draw a shadow, AND if the node is NOT selected, draw
     * our shadow.
     */
    if (shadow && !selected) {
      // Set the shadow color.
      g2d.setColor(colorShadow);

      /*
       * Draw a rectangle slightly downward and right, slightly larger
       * with larger corner curves to have a nice cosmetic shadow effect.
       */
      g2d.fillRoundRect(x + 1, y + 1, width + 4, height + 4, 24, 24);
    }

    // Set our color to the default node's color.
    g2d.setColor(colorNode);
    g2d.setPaint(paintHeader);
    // Draw our base rectangle.
    g2d.fillRoundRect(x, y, width, height, 16, 16);
    g2d.setPaint(null);
    // Set our color to shadow again.
    g2d.setColor(colorShadow);

    // Set our stroke to a line with 2 pixels in width.
    g2d.setStroke(new BasicStroke(2));

    /*
     * Draw a line around the edge of our base rectangle for cosmetics /
     * outlining.
     */
    g2d.drawRoundRect(x, y, width - 1, height - 1, 16, 16);

    // If we want to draw a inner box or not.
    if (innerBox) {
      // Set our color to black. TODO: Color option for inner box.
      g2d.setColor(colorInterior);
      // Draw our inner box 4 pixels inside the base rectangle.
      g2d.fillRoundRect(x + 4, y + 4, width - 8, height - 8, 8, 8);
    }

    // Sets the graphics object's original parameters back.
    g2d.setStroke(lastStroke);
    g2d.setColor(lastColor);
  }