/**
   * Creates toolbars for the application. This class always returns an empty list. Subclasses may
   * return other values.
   */
  @Override
  public List<JToolBar> createToolBars(Application a, @Nullable View pr) {
    ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels");
    DrawView p = (DrawView) pr;

    DrawingEditor editor;
    if (p == null) {
      editor = getSharedEditor();
    } else {
      editor = p.getEditor();
    }

    LinkedList<JToolBar> list = new LinkedList<JToolBar>();
    JToolBar tb;
    tb = new JToolBar();
    addCreationButtonsTo(tb, editor);
    tb.setName(labels.getString("window.drawToolBar.title"));
    list.add(tb);
    tb = new JToolBar();
    ButtonFactory.addAttributesButtonsTo(tb, editor);
    tb.setName(labels.getString("window.attributesToolBar.title"));
    list.add(tb);
    tb = new JToolBar();
    ButtonFactory.addAlignmentButtonsTo(tb, editor);
    tb.setName(labels.getString("window.alignmentToolBar.title"));
    list.add(tb);
    return list;
  }
예제 #2
0
  private void addCreationButtonsTo(JToolBar tb, final DrawingEditor editor) {
    // AttributeKeys for the entitie sets
    HashMap<AttributeKey, Object> attributes;

    ResourceBundleUtil drawLabels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels");

    ButtonFactory.addSelectionToolTo(
        tb, editor, ButtonFactory.createDrawingActions(editor), createSelectionActions(editor));
    tb.addSeparator();

    attributes = new HashMap<AttributeKey, Object>();
    attributes.put(AttributeKeys.FILL_COLOR, Color.white);
    attributes.put(AttributeKeys.STROKE_COLOR, Color.black);
    ButtonFactory.addToolTo(
        tb,
        editor,
        new CreationTool(new SVGRectFigure(), attributes),
        "edit.createRectangle",
        drawLabels);
    ButtonFactory.addToolTo(
        tb,
        editor,
        new CreationTool(new SVGEllipseFigure(), attributes),
        "edit.createEllipse",
        drawLabels);
    ButtonFactory.addToolTo(
        tb,
        editor,
        new PathTool(new SVGPathFigure(), new SVGBezierFigure(true), attributes),
        "edit.createPolygon",
        drawLabels);
    attributes = new HashMap<AttributeKey, Object>();
    attributes.put(AttributeKeys.FILL_COLOR, null);
    attributes.put(AttributeKeys.STROKE_COLOR, Color.black);
    ButtonFactory.addToolTo(
        tb,
        editor,
        new CreationTool(new SVGPathFigure(), attributes),
        "edit.createLine",
        drawLabels);
    ButtonFactory.addToolTo(
        tb,
        editor,
        new PathTool(new SVGPathFigure(), new SVGBezierFigure(false), attributes),
        "edit.createScribble",
        drawLabels);
    attributes = new HashMap<AttributeKey, Object>();
    attributes.put(AttributeKeys.FILL_COLOR, Color.black);
    attributes.put(AttributeKeys.STROKE_COLOR, null);
    ButtonFactory.addToolTo(
        tb,
        editor,
        new CreationTool(new SVGTextFigure(), attributes),
        "edit.createText",
        drawLabels);
    TextAreaCreationTool tat = new TextAreaCreationTool(new SVGTextAreaFigure(), attributes);
    tat.setRubberbandColor(Color.BLACK);
    ButtonFactory.addToolTo(tb, editor, tat, "edit.createTextArea", drawLabels);
  }
예제 #3
0
  @Override
  public Collection<Action> getActions(Point2D.Double p) {
    LinkedList<Action> actions = new LinkedList<Action>();
    if (get(TRANSFORM) != null) {
      ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.samples.odg.Labels");
      actions.add(
          new AbstractAction(labels.getString("edit.removeTransform.text")) {
            private static final long serialVersionUID = 1L;

            public void actionPerformed(ActionEvent evt) {
              willChange();
              fireUndoableEditHappened(TRANSFORM.setUndoable(ODGAttributedFigure.this, null));
              changed();
            }
          });
    }
    return actions;
  }
 public String getToolTipText(Point p) {
   ConnectionFigure f = (ConnectionFigure) getOwner();
   if (f.getLiner() == null && savedLiner == null) {
     ResourceBundleUtil labels = ResourceBundleUtil.getLAFBundle("org.jhotdraw.draw.Labels");
     BezierPath.Node node = getBezierNode();
     return (node == null)
         ? null
         : labels.getFormatted(
             "bezierNodeHandle.tip",
             labels.getFormatted(
                 (node.getMask() == 0)
                     ? "bezierNode.linearNode"
                     : ((node.getMask() == BezierPath.C1C2_MASK)
                         ? "bezierNode.cubicNode"
                         : "bezierNode.quadraticNode")));
   } else {
     return null;
   }
 }
예제 #5
0
 /** Creates a new instance. */
 public TextFigure() {
   this(
       ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels")
           .getString("TextFigure.defaultText"));
 }
  public void addDefaultCreationButtonsTo(
      JToolBar tb,
      final DrawingEditor editor,
      Collection<Action> drawingActions,
      Collection<Action> selectionActions) {
    ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels");

    ButtonFactory.addSelectionToolTo(tb, editor, drawingActions, selectionActions);
    tb.addSeparator();

    AbstractAttributedFigure af;
    CreationTool ct;
    ConnectionTool cnt;
    ConnectionFigure lc;

    ButtonFactory.addToolTo(
        tb, editor, new CreationTool(new RectangleFigure()), "edit.createRectangle", labels);
    ButtonFactory.addToolTo(
        tb,
        editor,
        new CreationTool(new RoundRectangleFigure()),
        "edit.createRoundRectangle",
        labels);
    ButtonFactory.addToolTo(
        tb, editor, new CreationTool(new EllipseFigure()), "edit.createEllipse", labels);
    ButtonFactory.addToolTo(
        tb, editor, new CreationTool(new DiamondFigure()), "edit.createDiamond", labels);
    ButtonFactory.addToolTo(
        tb, editor, new CreationTool(new TriangleFigure()), "edit.createTriangle", labels);
    ButtonFactory.addToolTo(
        tb, editor, new CreationTool(new LineFigure()), "edit.createLine", labels);
    ButtonFactory.addToolTo(
        tb, editor, ct = new CreationTool(new LineFigure()), "edit.createArrow", labels);
    af = (AbstractAttributedFigure) ct.getPrototype();
    af.set(END_DECORATION, new ArrowTip(0.35, 12, 11.3));
    ButtonFactory.addToolTo(
        tb,
        editor,
        new ConnectionTool(new LineConnectionFigure()),
        "edit.createLineConnection",
        labels);
    ButtonFactory.addToolTo(
        tb,
        editor,
        cnt = new ConnectionTool(new LineConnectionFigure()),
        "edit.createElbowConnection",
        labels);
    lc = cnt.getPrototype();
    lc.setLiner(new ElbowLiner());
    ButtonFactory.addToolTo(
        tb,
        editor,
        cnt = new ConnectionTool(new LineConnectionFigure()),
        "edit.createCurvedConnection",
        labels);
    lc = cnt.getPrototype();
    lc.setLiner(new CurvedLiner());
    ButtonFactory.addToolTo(
        tb, editor, new BezierTool(new BezierFigure()), "edit.createScribble", labels);
    ButtonFactory.addToolTo(
        tb, editor, new BezierTool(new BezierFigure(true)), "edit.createPolygon", labels);
    ButtonFactory.addToolTo(
        tb, editor, new TextCreationTool(new TextFigure()), "edit.createText", labels);
    ButtonFactory.addToolTo(
        tb, editor, new TextAreaCreationTool(new TextAreaFigure()), "edit.createTextArea", labels);
    ButtonFactory.addToolTo(
        tb, editor, new ImageTool(new ImageFigure()), "edit.createImage", labels);
  }
예제 #7
0
  /** Creates new instance. */
  public ODGDrawingPanel() {
    ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels");
    initComponents();
    undoManager = new UndoRedoManager();
    editor = new DefaultDrawingEditor();
    editor.add(view);

    addCreationButtonsTo(creationToolbar, editor);
    ButtonFactory.addAttributesButtonsTo(attributesToolbar, editor);

    JPopupButton pb = new JPopupButton();
    pb.setItemFont(UIManager.getFont("MenuItem.font"));
    labels.configureToolBarButton(pb, "actions");
    pb.add(new DuplicateAction());
    pb.addSeparator();
    pb.add(new GroupAction(editor));
    pb.add(new UngroupAction(editor));
    pb.addSeparator();
    pb.add(new BringToFrontAction(editor));
    pb.add(new SendToBackAction(editor));
    pb.addSeparator();
    pb.add(new CutAction());
    pb.add(new CopyAction());
    pb.add(new PasteAction());
    pb.add(new SelectAllAction());
    pb.add(new SelectSameAction(editor));
    pb.addSeparator();
    pb.add(undoManager.getUndoAction());
    pb.add(undoManager.getRedoAction());
    // FIXME - We need a toggle grid action
    // pb.addSeparator();
    // pb.add(new ToggleGridAction(editor));

    JMenu m = new JMenu(labels.getString("view.zoomFactor.text"));
    JRadioButtonMenuItem rbmi;
    ButtonGroup group = new ButtonGroup();
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 0.1, null)));
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 0.25, null)));
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 0.5, null)));
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 0.75, null)));
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 1.0, null)));
    rbmi.setSelected(true);
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 1.25, null)));
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 1.5, null)));
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 2, null)));
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 3, null)));
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 4, null)));
    group.add(rbmi);
    pb.add(m);
    pb.setFocusable(false);
    creationToolbar.addSeparator();
    creationToolbar.add(pb);

    DefaultDrawing drawing = new DefaultDrawing();
    view.setDrawing(drawing);
    drawing.addUndoableEditListener(undoManager);
  }
예제 #8
0
  /**
   * Displays a progress indicator and then invokes <code>loadDrawing</code> on a worker thread.
   * Displays the drawing panel when done successfully. Displays an error message when done
   * unsuccessfully.
   *
   * @see #loadDrawing
   */
  @Override
  public final void init() {
    // set the language of the applet
    if (getParameter("Locale") != null) {
      Locale.setDefault(new Locale(getParameter("Locale")));
    }

    final ResourceBundleUtil labels =
        ResourceBundleUtil.getBundle("org.jhotdraw.samples.svg.Labels");

    // Set look and feel
    // -----------------
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Throwable e) {
      // Do nothing.
      // If we can't set the desired look and feel, UIManager does
      // automaticaly the right thing for us.
    }

    // Set our own popup factory, because the one that comes with Mac OS X
    // creates translucent popups which is not useful for color selection
    // using pop menus.
    try {
      PopupFactory.setSharedInstance(new PopupFactory());
    } catch (Throwable e) {
      // If we can't set the popup factory, we have to use what is there.
    }

    // Display a progress indicator while we are loading the drawing
    // ----------------------------------------------------------
    Container c = getContentPane();
    final ProgressIndicator progress =
        new ProgressIndicator(getName(), labels.getString("progressInitializing"));
    c.add(progress);
    progress.revalidate();

    // Load the drawing using a worker thread
    // --------------------------------------
    new Worker<Drawing>() {

      @Override
      protected Drawing construct() throws Exception {
        Thread t =
            new Thread() {

              @Override
              public void run() {
                try {
                  drawingComponent = createDrawingComponent();
                } catch (Throwable t) {
                  t.printStackTrace();
                }
              }
            };
        t.start();
        try {
          progress.setNote(labels.getString("progressLoading"));
          Drawing drawing = loadDrawing(progress);
          progress.setNote(labels.getString("progressOpeningEditor"));
          progress.setIndeterminate(true);
          return drawing;
        } finally {
          t.join();
        }
      }

      @Override
      protected void done(Drawing result) {
        Container c = getContentPane();
        c.removeAll();
        c.setLayout(new BorderLayout());
        c.add(drawingComponent.getComponent());
        initComponents();
        if (result != null) {
          setDrawing(result);
        }
        drawingComponent.revalidate();
        ((JComponent) c).revalidate();
      }

      @Override
      protected void failed(Throwable error) {
        Drawing d = createDrawing();
        String message = (error.getMessage() == null) ? error.toString() : error.getMessage();
        SVGTextAreaFigure txt =
            new SVGTextAreaFigure(
                labels.getFormatted("messageLoadFailed", getParameter("DrawingURL"), message));
        txt.setBounds(new Point2D.Double(0, 0), new Point2D.Double(getWidth(), getHeight()));
        d.add(txt);
        done(d);
        /*
        Container c = getContentPane();
        c.setLayout(new BorderLayout());
        c.removeAll();
        Throwable error = result;
        error.printStackTrace();
        String message = (error.getMessage() == null) ? error.toString() : error.getMessage();
        MessagePanel mp = new MessagePanel(
        UIManager.getIcon("OptionPane.errorIcon"),
        labels.getFormatted("messageLoadFailed", htmlencode(getParameter("DrawingURL")), htmlencode(message)));
        c.add(mp);
        mp.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
        if ("close".equals(evt.getActionCommand())) {
        close();
        }
        }
        });
        mp.revalidate();
        */
      }

      @Override
      protected void finished() {
        long end = System.currentTimeMillis();
        System.out.println("AbstractDrawingApplet startup latency:" + (end - start));
      }
    }.start();
  }