Exemplo n.º 1
0
  /** resets the drawing tool after the drawing action is the mode is not the remanent mode */
  public void resetDrawing() {

    if (!Editor.getEditor().getRemanentModeManager().isRemanentMode()) {

      Editor.getEditor().getSelectionManager().setToRegularMode();
    }
  }
Exemplo n.º 2
0
  /** creates the menu and tool items */
  protected void createMenuAndToolItems() {

    // creating the listener to the menu and tool items
    ActionListener listener =
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {

            notifyDrawingMode();

            if (e.getSource().equals(shapeCreatorMenuItem)) {

              shapeCreatorToolItem.removeActionListener(this);
              shapeCreatorToolItem.setSelected(true);
              shapeCreatorToolItem.addActionListener(this);
            }
          }
        };

    // getting the icons for the items
    shapeCreatorIcon = ResourcesManager.getIcon(shapeModuleId, false);
    shapeCreatorDisabledIcon = ResourcesManager.getIcon(shapeModuleId, true);

    // creating the menu item
    shapeCreatorMenuItem = new JMenuItem(itemLabel, shapeCreatorIcon);
    shapeCreatorMenuItem.setDisabledIcon(shapeCreatorDisabledIcon);
    shapeCreatorMenuItem.addActionListener(listener);
    shapeCreatorMenuItem.setEnabled(false);

    // creating the tool item
    shapeCreatorToolItem = new JToggleButton(shapeCreatorIcon);
    shapeCreatorToolItem.setDisabledIcon(shapeCreatorDisabledIcon);
    shapeCreatorToolItem.setToolTipText(itemToolTip);
    shapeCreatorToolItem.addActionListener(listener);
    shapeCreatorToolItem.setEnabled(false);

    // adding the listener to the switches between the svg handles
    final HandlesManager svgHandleManager = Editor.getEditor().getHandlesManager();

    svgHandleManager.addHandlesListener(
        new HandlesListener() {

          @Override
          public void handleChanged(SVGHandle currentHandle, Set<SVGHandle> handles) {

            boolean isDrawingEnabled = isDrawingEnabled(currentHandle);

            shapeCreatorMenuItem.setEnabled(isDrawingEnabled);
            shapeCreatorToolItem.setEnabled(isDrawingEnabled);
            SelectionInfoManager selectionManager = Editor.getEditor().getSelectionManager();

            if (selectionManager.getDrawingShape() != null
                && selectionManager.getDrawingShape().equals(AbstractShape.this)) {

              selectionManager.setToRegularMode();
            }
          }
        });
  }
Exemplo n.º 3
0
  /**
   * returns the resize transform corresponding to the parameters
   *
   * @param handle a svg handle
   * @param bounds the bounds of the area to be resized
   * @param item the selection item
   * @param firstPoint the first point
   * @param secondPoint the second point
   * @return the resize transform corresponding to the parameters
   */
  protected AffineTransform getResizeTransform(
      SVGHandle handle,
      Rectangle2D bounds,
      SelectionItem item,
      Point2D firstPoint,
      Point2D secondPoint) {

    // getting the diff point
    Point2D diff =
        new Point2D.Double(
            secondPoint.getX() - firstPoint.getX(), secondPoint.getY() - firstPoint.getY());

    // getting the scale and the translation factors
    double sx = 1.0, sy = 1.0, tx = 0, ty = 0;
    int type = item.getType();

    if (Editor.getEditor().getSquareModeManager().isSquareMode()) {

      switch (type) {
        case SelectionItem.NORTH:
          diff = new Point2D.Double(diff.getY(), diff.getY());
          sy = 1 - diff.getY() / bounds.getHeight();
          sx = sy;
          tx = (bounds.getX() + bounds.getWidth() / 2) * (1 - sx);
          ty = (bounds.getY() + bounds.getHeight()) * (1 - sy);
          break;

        case SelectionItem.SOUTH:
          diff = new Point2D.Double(diff.getY(), diff.getY());
          sy = 1 + diff.getY() / bounds.getHeight();
          sx = sy;
          tx = (bounds.getX() + bounds.getWidth() / 2) * (1 - sx);
          ty = bounds.getY() * (1 - sy);
          break;

        case SelectionItem.EAST:
          diff = new Point2D.Double(diff.getX(), diff.getX());
          sx = 1 + diff.getX() / bounds.getWidth();
          sy = sx;
          tx = bounds.getX() * (1 - sx);
          ty = (bounds.getY() + bounds.getHeight() / 2) * (1 - sy);
          break;

        case SelectionItem.WEST:
          diff = new Point2D.Double(diff.getX(), -diff.getX());
          sx = 1 - diff.getX() / bounds.getWidth();
          sy = sx;
          tx = (bounds.getX() + bounds.getWidth()) * (1 - sx);
          ty = (bounds.getY() + bounds.getHeight() / 2) * (1 - sy);
          break;

        case SelectionItem.NORTH_EAST:
          diff = new Point2D.Double(diff.getX(), -diff.getX());

          sx = 1 + diff.getX() / bounds.getWidth();
          sy = sx;
          tx = (bounds.getX()) * (1 - sx);
          ty = (bounds.getY() + bounds.getHeight()) * (1 - sy);
          break;

        case SelectionItem.NORTH_WEST:
          diff = new Point2D.Double(diff.getY(), diff.getY());
          sy = 1 - diff.getY() / bounds.getHeight();
          sx = sy;
          tx = (bounds.getX() + bounds.getWidth()) * (1 - sx);
          ty = (bounds.getY() + bounds.getHeight()) * (1 - sy);
          break;

        case SelectionItem.SOUTH_EAST:
          diff = new Point2D.Double(diff.getY(), diff.getY());
          sy = 1 + diff.getY() / bounds.getHeight();
          sx = sy;
          tx = bounds.getX() * (1 - sx);
          ty = bounds.getY() * (1 - sy);
          break;

        case SelectionItem.SOUTH_WEST:
          diff = new Point2D.Double(diff.getX(), -diff.getX());
          sx = 1 - diff.getX() / bounds.getWidth();
          sy = sx;
          tx = (bounds.getX() + bounds.getWidth()) * (1 - sx);
          ty = (bounds.getY()) * (1 - sy);
          break;
      }

    } else {

      switch (type) {
        case SelectionItem.NORTH:
          sy = 1 - diff.getY() / bounds.getHeight();
          ty = (bounds.getY() + bounds.getHeight()) * (1 - sy);
          break;

        case SelectionItem.SOUTH:
          sy = 1 + diff.getY() / bounds.getHeight();
          ty = bounds.getY() * (1 - sy);
          break;

        case SelectionItem.EAST:
          sx = 1 + diff.getX() / bounds.getWidth();
          tx = bounds.getX() * (1 - sx);
          break;

        case SelectionItem.WEST:
          sx = 1 - diff.getX() / bounds.getWidth();
          tx = (bounds.getX() + bounds.getWidth()) * (1 - sx);
          break;

        case SelectionItem.NORTH_EAST:
          sx = 1 + diff.getX() / bounds.getWidth();
          sy = 1 - diff.getY() / bounds.getHeight();
          tx = (bounds.getX()) * (1 - sx);
          ty = (bounds.getY() + bounds.getHeight()) * (1 - sy);
          break;

        case SelectionItem.NORTH_WEST:
          sx = 1 - diff.getX() / bounds.getWidth();
          sy = 1 - diff.getY() / bounds.getHeight();
          tx = (bounds.getX() + bounds.getWidth()) * (1 - sx);
          ty = (bounds.getY() + bounds.getHeight()) * (1 - sy);
          break;

        case SelectionItem.SOUTH_EAST:
          sx = 1 + diff.getX() / bounds.getWidth();
          sy = 1 + diff.getY() / bounds.getHeight();
          tx = bounds.getX() * (1 - sx);
          ty = bounds.getY() * (1 - sy);
          break;

        case SelectionItem.SOUTH_WEST:
          sx = 1 - diff.getX() / bounds.getWidth();
          sy = 1 + diff.getY() / bounds.getHeight();
          tx = (bounds.getX() + bounds.getWidth()) * (1 - sx);
          ty = (bounds.getY()) * (1 - sy);
          break;
      }
    }

    // creating the transform
    AffineTransform af = new AffineTransform();
    af.preConcatenate(AffineTransform.getScaleInstance(sx, sy));
    af.preConcatenate(AffineTransform.getTranslateInstance(tx, ty));

    return af;
  }
Exemplo n.º 4
0
  /** notifies all the selection managers that the items action mode has been enabled */
  public void notifyItemsActionMode() {

    Editor.getEditor()
        .getSelectionManager()
        .setSelectionMode(SelectionInfoManager.ITEMS_ACTION_MODE, this);
  }
Exemplo n.º 5
0
  /** notifies all the selection managers that the drawing mode has been enabled */
  public void notifyDrawingMode() {

    Editor.getEditor()
        .getSelectionManager()
        .setSelectionMode(SelectionInfoManager.DRAWING_MODE, this);
  }