Package com.cburch.draw.shapes

Examples of com.cburch.draw.shapes.Text


  public void mousePressed(Canvas canvas, MouseEvent e) {
    if (curText != null) {
      commitText(canvas);
    }

    Text clicked = null;
    boolean found = false;
    int mx = e.getX();
    int my = e.getY();
    Location mloc = Location.create(mx, my);
    for (CanvasObject o : canvas.getModel().getObjectsFromTop()) {
      if (o instanceof Text && o.contains(mloc, true)) {
        clicked = (Text) o;
        found = true;
        break;
      }
    }
    if (!found) {
      clicked = attrs.applyTo(new Text(mx, my, ""));
    }

    curText = clicked;
    curCanvas = canvas;
    isTextNew = !found;
    clicked.getLabel().configureTextField(field, canvas.getZoomFactor());
    field.setText(clicked.getText());
    canvas.add(field);

    Point fieldLoc = field.getLocation();
    double zoom = canvas.getZoomFactor();
    fieldLoc.x = (int) Math.round(mx * zoom - fieldLoc.x);
    fieldLoc.y = (int) Math.round(my * zoom - fieldLoc.y);
    int caret = field.viewToModel(fieldLoc);
    if (caret >= 0) {
      field.setCaretPosition(caret);
    }
    field.requestFocus();
   
    canvas.getSelection().setSelected(clicked, true);
    canvas.getSelection().setHidden(Collections.singleton(clicked), true);
    clicked.addAttributeListener(fieldListener);
    canvas.repaint();
  }
View Full Code Here


    canvas.repaint();
  }
 
  @Override
  public void zoomFactorChanged(Canvas canvas) {
    Text t = curText;
    if (t != null) {
      t.getLabel().configureTextField(field, canvas.getZoomFactor());
    }
  }
View Full Code Here

  public void draw(Canvas canvas, Graphics g) {
    ; // actually, there's nothing to do here - it's handled by the field
  }

  private void cancelText(Canvas canvas) {
    Text cur = curText;
    if (cur != null) {
      curText = null;
      cur.removeAttributeListener(fieldListener);
      canvas.remove(field);
      canvas.getSelection().clearSelected();
      canvas.repaint();
    }
  }
View Full Code Here

      canvas.repaint();
    }
  }

  private void commitText(Canvas canvas) {
    Text cur = curText;
    boolean isNew = isTextNew;
    String newText = field.getText();
    if (cur == null) {
      return;
    }
    cancelText(canvas);

    if (isNew) {
      if (!newText.equals("")) {
        cur.setText(newText);
        canvas.doAction(new ModelAddAction(canvas.getModel(), cur));
      }
    } else {
      String oldText = cur.getText();
      if (newText.equals("")) {
        canvas.doAction(new ModelRemoveAction(canvas.getModel(), cur));
      } else if (!oldText.equals(newText)) {
        canvas.doAction(new ModelEditTextAction(canvas.getModel(), cur,
            newText));
View Full Code Here

    public void actionPerformed(ActionEvent e) {
      commitText(curCanvas);
    }

    public void attributeListChanged(AttributeEvent e) {
      Text cur = curText;
      if (cur != null) {
        double zoom = curCanvas.getZoomFactor();
        cur.getLabel().configureTextField(field, zoom);
        curCanvas.repaint();
      }
    }
View Full Code Here

    public void mousePressed(Canvas canvas, MouseEvent e) {
        if (curText != null) {
            commitText(canvas);
        }

        Text clicked = null;
        boolean found = false;
        int mx = e.getX();
        int my = e.getY();
        Location mloc = Location.create(mx, my);
        for (CanvasObject o : canvas.getModel().getObjectsFromTop()) {
            if (o instanceof Text && o.contains(mloc, true)) {
                clicked = (Text) o;
                found = true;
                break;
            }
        }
        if (!found) {
            clicked = attrs.applyTo(new Text(mx, my, ""));
        }

        curText = clicked;
        curCanvas = canvas;
        isTextNew = !found;
        clicked.getLabel().configureTextField(field, canvas.getZoomFactor());
        field.setText(clicked.getText());
        canvas.add(field);

        Point fieldLoc = field.getLocation();
        double zoom = canvas.getZoomFactor();
        fieldLoc.x = (int) Math.round(mx * zoom - fieldLoc.x);
        fieldLoc.y = (int) Math.round(my * zoom - fieldLoc.y);
        int caret = field.viewToModel(fieldLoc);
        if (caret >= 0) {
            field.setCaretPosition(caret);
        }
        field.requestFocus();

        canvas.getSelection().setSelected(clicked, true);
        canvas.getSelection().setHidden(Collections.singleton(clicked), true);
        clicked.addAttributeListener(fieldListener);
        canvas.repaint();
    }
View Full Code Here

        canvas.repaint();
    }

    @Override
    public void zoomFactorChanged(Canvas canvas) {
        Text t = curText;
        if (t != null) {
            t.getLabel().configureTextField(field, canvas.getZoomFactor());
        }
    }
View Full Code Here

        // actually, there's nothing to do here - it's handled by the field
        ;
    }

    private void cancelText(Canvas canvas) {
        Text cur = curText;
        if (cur != null) {
            curText = null;
            cur.removeAttributeListener(fieldListener);
            canvas.remove(field);
            canvas.getSelection().clearSelected();
            canvas.repaint();
        }
    }
View Full Code Here

            canvas.repaint();
        }
    }

    private void commitText(Canvas canvas) {
        Text cur = curText;
        boolean isNew = isTextNew;
        String newText = field.getText();
        if (cur == null) {
            return;
        }
        cancelText(canvas);

        if (isNew) {
            if (!newText.equals("")) {
                cur.setText(newText);
                canvas.doAction(new ModelAddAction(canvas.getModel(), cur));
            }
        } else {
            String oldText = cur.getText();
            if (newText.equals("")) {
                canvas.doAction(new ModelRemoveAction(canvas.getModel(), cur));
            } else if (!oldText.equals(newText)) {
                canvas.doAction(new ModelEditTextAction(canvas.getModel(), cur,
                        newText));
View Full Code Here

            commitText(curCanvas);
        }

        @Override
        public void attributeListChanged(AttributeEvent e) {
            Text cur = curText;
            if (cur != null) {
                double zoom = curCanvas.getZoomFactor();
                cur.getLabel().configureTextField(field, zoom);
                curCanvas.repaint();
            }
        }
View Full Code Here

TOP

Related Classes of com.cburch.draw.shapes.Text

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.