コード例 #1
0
  /**
   * 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
 /** Creates a new instance. */
 public IncreaseHandleDetailLevelAction(DrawingEditor editor) {
   super(editor);
   ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels");
   labels.configureAction(this, ID);
   // putValue(AbstractAction.NAME, labels.getString("editSelectSame"));
   //  putValue(AbstractAction.MNEMONIC_KEY, labels.getString("editSelectSameMnem"));
   updateEnabledState();
 }
コード例 #3
0
ファイル: NetView.java プロジェクト: ilyessou/jhotdraw
  /** Creates a new view. */
  public NetView() {
    initComponents();

    scrollPane.setLayout(new PlacardScrollPaneLayout());
    scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));

    setEditor(new DefaultDrawingEditor());
    undo = new UndoRedoManager();
    view.setDrawing(createDrawing());
    view.getDrawing().addUndoableEditListener(undo);
    initActions();
    undo.addPropertyChangeListener(
        new PropertyChangeListener() {

          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            setHasUnsavedChanges(undo.hasSignificantEdits());
          }
        });

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

    JPanel placardPanel = new JPanel(new BorderLayout());
    javax.swing.AbstractButton pButton;
    pButton = ButtonFactory.createZoomButton(view);
    pButton.putClientProperty("Quaqua.Button.style", "placard");
    pButton.putClientProperty("Quaqua.Component.visualMargin", new Insets(0, 0, 0, 0));
    pButton.setFont(UIManager.getFont("SmallSystemFont"));
    placardPanel.add(pButton, BorderLayout.WEST);
    toggleGridButton = pButton = ButtonFactory.createToggleGridButton(view);
    pButton.putClientProperty("Quaqua.Button.style", "placard");
    pButton.putClientProperty("Quaqua.Component.visualMargin", new Insets(0, 0, 0, 0));
    pButton.setFont(UIManager.getFont("SmallSystemFont"));
    labels.configureToolBarButton(pButton, "view.toggleGrid.placard");
    placardPanel.add(pButton, BorderLayout.EAST);
    scrollPane.add(placardPanel, JScrollPane.LOWER_LEFT_CORNER);

    toggleGridButton.setSelected(preferences.getBoolean("view.gridVisible", false));
    view.setScaleFactor(preferences.getDouble("view.scaleFactor", 1d));

    view.addPropertyChangeListener(
        new PropertyChangeListener() {

          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if ("scaleFactor".equals(name)) {
              preferences.putDouble("view.scaleFactor", (Double) evt.getNewValue());
              firePropertyChange("scaleFactor", evt.getOldValue(), evt.getNewValue());
            }
          }
        });
  }
コード例 #4
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);
  }
コード例 #5
0
  public void actionPerformed(ActionEvent evt) {
    ResourceBundleUtil labels = ResourceBundleUtil.getLAFBundle("org.jhotdraw.app.Labels");

    if (LineConnectionFigure.validateEnabled) {
      labels.configureAction(this, ID2);
      LineConnectionFigure.validateEnabled = false;
    } else {
      labels.configureAction(this, ID);
      LineConnectionFigure.validateEnabled = true;
    }

    DrawProject project = (DrawProject) getCurrentProject();
    for (Figure f : project.getEditor().getActiveView().getDrawing().getFigures()) {
      if (f instanceof LineConnectionFigure) {
        ((LineConnectionFigure) f).updateConnection();
      }
    }
  }
コード例 #6
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;
  }
コード例 #7
0
 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;
   }
 }
コード例 #8
0
  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);
  }
コード例 #9
0
 /** Creates a new instance. */
 public ClearRecentFilesAction(Application app) {
   super(app);
   ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.app.Labels");
   labels.configureAction(this, ID);
   updateEnabled();
 }
コード例 #10
0
 /** Creates a new instance. */
 public ValidateModelAction(Application app) {
   super(app);
   ResourceBundleUtil labels = ResourceBundleUtil.getLAFBundle("org.jhotdraw.app.Labels");
   labels.configureAction(this, ID2);
 }
コード例 #11
0
 /** Creates a new instance. */
 public LoadAction(Application app) {
   super(app);
   ResourceBundleUtil labels = ResourceBundleUtil.getLAFBundle("org.jhotdraw.app.Labels");
   labels.configureAction(this, "open");
 }
コード例 #12
0
 /**
  * Creates a new instance which acts on the specified component.
  *
  * @param target The target of the action. Specify null for the currently focused component.
  */
 public ClearSelectionAction(@Nullable JComponent target) {
   super(target);
   ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.app.Labels");
   labels.configureAction(this, ID);
 }
コード例 #13
0
 /** Creates a new instance. */
 public DuplicateAction() {
   ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.app.Labels");
   labels.configureAction(this, ID);
 }
コード例 #14
0
ファイル: SaveAsAction.java プロジェクト: vyloy/lnvc
 /** Creates a new instance. */
 public SaveAsAction(Application app) {
   super(app, true);
   ResourceBundleUtil labels = ResourceBundleUtil.getLAFBundle("org.jhotdraw.app.Labels");
   labels.configureAction(this, ID);
 }
コード例 #15
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);
  }
コード例 #16
0
ファイル: TextFigure.java プロジェクト: ilyessou/jhotdraw
 /** Creates a new instance. */
 public TextFigure() {
   this(
       ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels")
           .getString("TextFigure.defaultText"));
 }
コード例 #17
0
ファイル: SVGApplet.java プロジェクト: ilyessou/jhotdraw
  /**
   * 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();
  }