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 a svg element by specifiying its parameters
   *
   * @param handle the current svg handle
   * @param text the text for the new element
   * @return the created svg element
   */
  public Element createElement(SVGHandle handle, String text) {

    // the edited document
    Document doc = handle.getScrollPane().getSVGCanvas().getDocument();

    // creating the text element
    final Element element =
        doc.createElementNS(doc.getDocumentElement().getNamespaceURI(), handledElementTagName);

    // getting the last color that has been used by the user
    String colorString = Editor.getColorChooser().getColorString(ColorManager.getCurrentColor());
    element.setAttributeNS(null, "style", "fill:" + colorString + ";stroke:none;");
    element.setAttributeNS(null, "style", "font-size:12pt;fill:" + colorString + ";");

    EditorToolkit.setAttributeValue(element, xAtt, drawingPoint.getX());
    EditorToolkit.setAttributeValue(element, yAtt, drawingPoint.getY());

    // creating the text node
    Text textValue = doc.createTextNode(text);
    element.appendChild(textValue);

    // inserting the element in the document and handling the undo/redo
    // support
    insertShapeElement(handle, element);
    handle.getSelection().handleSelection(element, false, false);

    return element;
  }
Exemplo n.º 3
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.º 4
0
  /**
   * the constructor of the class
   *
   * @param editor the editor
   */
  public TextShape(Editor editor) {

    super(editor);

    shapeModuleId = "TextShape";
    handledElementTagName = "text";
    retrieveLabels();
    createMenuAndToolItems();

    // creating the text dialog
    if (Editor.getParent() instanceof JDialog) {

      textDialog = new TextDialog(this, (JDialog) Editor.getParent());

    } else if (Editor.getParent() instanceof Frame) {

      textDialog = new TextDialog(this, (Frame) Editor.getParent());
    }
  }
Exemplo n.º 5
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.º 6
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.º 7
0
  /** notifies all the selection managers that the drawing mode has been enabled */
  public void notifyDrawingMode() {

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