Tabnine Logo
DrawingView
Code IndexAdd Tabnine to your IDE (free)

How to use
DrawingView
in
org.jhotdraw.draw

Best Java code snippets using org.jhotdraw.draw.DrawingView (Showing top 20 results out of 315)

origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

public void updateCursor(DrawingView view, Point p) {
  if (view.isEnabled()) {
    Handle handle = view.findHandle(p);
    if (handle != null) {
      view.setCursor(handle.getCursor());
    } else {
      Figure figure = view.findFigure(p);
      Point2D.Double point = view.viewToDrawing(p);
      Drawing drawing = view.getDrawing();
      while (figure != null && !figure.isSelectable()) {
        figure = drawing.findFigureBehind(point, figure);
      }
      if (figure != null) {
        view.setCursor(figure.getCursor(view.viewToDrawing(p)));
      } else {
        view.setCursor(Cursor.getDefaultCursor());
      }
    }
  } else {
    view.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  }
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

@Override
public void propertyChange(PropertyChangeEvent evt) {
  String name = evt.getPropertyName();
  if (name == DrawingEditor.ACTIVE_VIEW_PROPERTY) {
    if (view != null) {
      view.removePropertyChangeListener(this);
      view.removeFigureSelectionListener(this);
    }
    view = (DrawingView) evt.getNewValue();
    if (view != null) {
      view.addPropertyChangeListener(this);
      view.addFigureSelectionListener(this);
    }
    updateVisibility();
  } else if (name == DrawingEditor.TOOL_PROPERTY) {
    updateVisibility();
  }
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

@Override
public void setTool(Tool newValue) {
  Tool oldValue = tool;
  if (newValue == tool) {
    return;
  }
  if (tool != null) {
    for (DrawingView v : views) {
      v.removeMouseListener(tool);
      v.removeMouseMotionListener(tool);
      v.removeKeyListener(tool);
    }
    tool.deactivate(this);
    tool.removeToolListener(toolHandler);
  }
  tool = newValue;
  if (tool != null) {
    tool.activate(this);
    for (DrawingView v : views) {
      v.addMouseListener(tool);
      v.addMouseMotionListener(tool);
      v.addKeyListener(tool);
    }
    tool.addToolListener(toolHandler);
  }
  firePropertyChange(TOOL_PROPERTY, oldValue, newValue);
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

  @Override
  public void updateCursor(DrawingView view, Point p) {
    if (view.isEnabled()) {
      view.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
    } else {
      view.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    }
  }
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

@Override
public void add(DrawingView view) {
  views.add(view);
  view.addNotify(this);
  view.getComponent().addFocusListener(focusHandler);
  if (tool != null) {
    view.addMouseListener(tool);
    view.addMouseMotionListener(tool);
    view.addKeyListener(tool);
  }
  updateActiveView();
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

/**
 * Hook method which can be overriden by subclasses to provide
 * specialised behaviour in the event of a multi-click.
 */
protected void handleMultiClick(MouseEvent evt) {
  if (DEBUG) {
    System.out.println("DelegationSelectionTool.handleMultiClick " + evt);
  }
  DrawingView v = getView();
  Point pos = new Point(evt.getX(), evt.getY());
  Handle handle = v.findHandle(pos);
  if (handle == null) {
    v.setHandleDetailLevel(v.getHandleDetailLevel() + 1);
  }
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

@Override
public void mousePressed(MouseEvent evt) {
  if (getView() != null && getView().isEnabled()) {
    super.mousePressed(evt);
    DrawingView view = getView();
    Handle handle = view.findHandle(anchor);
    Tool newTracker = null;
    if (handle != null) {
    } else {
      Figure figure;
      Drawing drawing = view.getDrawing();
      Point2D.Double p = view.viewToDrawing(anchor);
      if (isSelectBehindEnabled() &&
          (evt.getModifiersEx() &
          (InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)) != 0) {
        figure = view.findFigure(anchor);
        while (figure != null && !figure.isSelectable()) {
          figure = drawing.findFigureBehind(p, figure);
        HashSet<Figure> ignoredFigures = new HashSet<Figure>(view.getSelectedFigures());
        ignoredFigures.add(figure);
        Figure figureBehind = view.getDrawing().findFigureBehind(
            view.viewToDrawing(anchor), ignoredFigures);
        if (figureBehind != null) {
          figure = figureBehind;
          for (Figure f : view.getSelectedFigures()) {
            if (f.contains(p)) {
origin: net.imagej/ij-ui-swing

  protected boolean maybeSwitchTool(final MouseEvent event) {
    if (activeTool != null && activeTool.isConstructing()) return false;
    anchor = new Point(event.getX(), event.getY());
    JHotDrawTool tool = creationTool;
    final DrawingView view = getView();
    if (view != null && view.isEnabled()) {
      if (view.findHandle(anchor) != null ||
        (view.findFigure(anchor) != null && view.findFigure(anchor)
          .isSelectable()))
      {
        tool = selectionTool;
      }
    }

    if (activeTool != tool) {
      if (activeTool != null) {
        activeTool.deactivate(getEditor());
      }
      if (tool != null) {
        tool.activate(getEditor());
        if (!isActive()) {
          tool.deactivate(getEditor());
        }
      }
      activeTool = tool;
      return true;
    }
    return false;
  }
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

Handle handle = v.findHandle(pos);
if (handle != null) {
  if (DEBUG) {
    for (Figure f : v.getSelectedFigures()) {
      if (f.contains(p)) {
        figure = f;
    figure = v.findFigure(pos);
    } else {
      if (outerFigure.handleMouseClick(p, evt, getView())) {
        v.clearSelection();
        v.addToSelection(outerFigure);
      } else {
        v.clearSelection();
        v.addToSelection(outerFigure);
        v.setHandleDetailLevel(v.getHandleDetailLevel() + 1);
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

@Override
public void mouseDragged(MouseEvent e) {
  DrawingView v = getView();
  Figure f = v.findFigure(e.getPoint());
  if (f != null) {
    if (!v.getSelectedFigures().contains(f)) {
      v.clearSelection();
      v.addToSelection(f);
    }
    v.getComponent().getTransferHandler().exportAsDrag(v.getComponent(), e, DnDConstants.ACTION_MOVE);
  }
  fireToolDone();
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

@Override
public void keyTyped(KeyEvent evt) {
  if (getView() != null && getView().isEnabled()) {
    tracker.keyTyped(evt);
  }
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

@Override
public void mouseMoved(MouseEvent evt) {
  clearRubberBand();
  Point point = evt.getPoint();
  DrawingView view = editor.findView((Container) evt.getSource());
  updateCursor(view, point);
  if (view == null || editor.getActiveView() != view) {
    clearHoverHandles();
  } else {
    // Search first, if one of the selected figures contains
    // the current mouse location, and is selectable. 
    // Only then search for other
    // figures. This search sequence is consistent with the
    // search sequence of the SelectionTool.
    Figure figure = null;
    Point2D.Double p = view.viewToDrawing(point);
    for (Figure f : view.getSelectedFigures()) {
      if (f.contains(p)) {
        figure = f;
      }
    }
    if (figure == null) {
      figure = view.findFigure(point);
      while (figure != null && !figure.isSelectable()) {
        figure = view.getDrawing().findFigureBehind(p, figure);
      }
    }
    updateHoverHandles(view, figure);
  }
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

  @Override
  public String getToolTipText(DrawingView view, MouseEvent evt) {
    Handle handle = view.findHandle(evt.getPoint());
    if (handle != null) {
      return handle.getToolTipText(evt.getPoint());
    }
    Figure figure = view.findFigure(evt.getPoint());
    if (figure != null) {
      return figure.getToolTipText(viewToDrawing(evt.getPoint()));
    }
    return null;
  }
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

Figure f = view.findFigure(me.getPoint());
if (view.getSelectedFigures().contains(f)) {
  transferFigures.addAll(view.getSelectedFigures());
} else {
  transferFigures.add(f);
Rectangle viewArea = view.drawingToView(drawingArea);
Point imageOffset = me.getPoint();
imageOffset.x = viewArea.x - imageOffset.x;
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

@Override
public void updateEnabledState() {
  if (getView() != null) {
    setEnabled(getView().isEnabled() &&
        getView().getSelectionCount() > 1
        );
  } else {
    setEnabled(false);
  }
}
@Override
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

public SelectionComponentRepainter(DrawingEditor editor, JComponent component) {
  this.editor = editor;
  this.component = component;
  if (editor != null) {
    if (editor.getActiveView() != null) {
      DrawingView view = editor.getActiveView();
      view.addPropertyChangeListener(this);
      view.addFigureSelectionListener(this);
      if (view.getDrawing() != null) {
        view.getDrawing().addFigureListener(this);
      }
    }
    editor.addPropertyChangeListener(this);
  }
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

/**
 * Hook method which can be overriden by subclasses to provide
 * specialised behaviour in the event of a popup trigger.
 */
protected void handlePopupMenu(MouseEvent evt) {
  Point p = new Point(evt.getX(), evt.getY());
  Figure figure = getView().findFigure(p);
  if (figure != null || drawingActions.size() > 0) {
    showPopupMenu(figure, p, evt.getComponent());
  } else {
    popupMenu = null;
  }
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

DrawingView view = (DrawingView) evt.getOldValue();
if (view != null) {
  view.removePropertyChangeListener(this);
  if (view.getDrawing() != null) {
    view.getDrawing().removeFigureListener(this);
  view.addPropertyChangeListener(this);
  if (view.getDrawing() != null) {
    view.getDrawing().addFigureListener(this);
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

gridSizeField.setFormatterFactory(JavaNumberFormatter.createFormatterFactory(0d, 1000d, 1d, true));
gridSizeField.setHorizontalAlignment(JTextField.LEADING);
final GridConstrainer constrainer = (GridConstrainer) view.getVisibleConstrainer();
gridSizeField.addPropertyChangeListener(new PropertyChangeListener() {
scaleFactorField.setFormatterFactory(new DefaultFormatterFactory(formatter));
scaleFactorField.setHorizontalAlignment(JTextField.LEADING);
scaleFactorField.setValue(view.getScaleFactor());
scaleFactorField.addPropertyChangeListener(new PropertyChangeListener() {
view.addPropertyChangeListener(new PropertyChangeListener() {
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

  /** Registers the event handler from the drawing editor and the
   * active drawing view.
   */
  private void registerEventHandler() {
    if (specificView != null) {
      specificView.addPropertyChangeListener(eventHandler);
    } else {
      if (editor != null) {
        editor.addPropertyChangeListener(new WeakPropertyChangeListener(eventHandler));
        if (activeView != null) {
          activeView.removePropertyChangeListener(eventHandler);
        }
        activeView = editor.getActiveView();
        if (activeView != null) {
          activeView.addPropertyChangeListener(eventHandler);
        }
      }
    }
  }
}
org.jhotdraw.drawDrawingView

Javadoc

A drawing view paints a Drawing on a JComponent. A drawing view can hold only one drawing at a time, but a drawing can be in multiple drawing views at the same time.

To support editing, a drawing view needs to be added to a DrawingEditor. The current org.jhotdraw.draw.tool.Tool of the drawing editor receives mouse and key events from all drawing views of the drawing editor.

DrawingView can paint the drawing with a scale factor. It supports conversion between view coordinates and drawing coordinates.

DrawingView maintains a selection of the Figures contained in the drawing. The selected figures can be the target of the current tool of the drawing editor.

The painting process of DrawingView view usually involves the following steps:

  1. Paint the background of the drawing view.
  2. Invoke Drawing#drawCanvas.
  3. Invoke Constrainer#draw if a constrainer is set.
  4. Invoke Drawing#draw.
  5. Invoke org.jhotdraw.draw.handle.Handle#draw on the handles of selected figures.
  6. Invoke org.jhotdraw.draw.tool.Tool#draw if the drawing view is the active view of the DrawingEditor.

Design Patterns

Framework
The following interfaces define the contracts of a framework for structured drawing editors:
Contract: Drawing, Figure, DrawingView, DrawingEditor, org.jhotdraw.draw.handle.Handle and org.jhotdraw.draw.tool.Tool.

Chain of responsibility
Mouse and keyboard events of the user occur on the drawing view, and are preprocessed by the DragTracker of a SelectionTool. In turn org.jhotdraw.draw.selectiontool.DragTracker invokes "track" methods on a Handle which in turn changes an aspect of a figure.
Client: org.jhotdraw.draw.tool.SelectionTool; Handler: org.jhotdraw.draw.tool.DragTracker, org.jhotdraw.draw.handle.Handle.

Mediator
DrawingEditor acts as a mediator for coordinating drawing tools and drawing views:
Mediator: DrawingEditor; Colleagues: DrawingView, org.jhotdraw.draw.tool.Tool.

Model-View-Controller
The following classes implement together the Model-View-Controller design pattern:
Model: Drawing; View: DrawingView; Controller: DrawingEditor.

Observer
Selection changes of DrawingView are observed by user interface components which act on selected figures.
Subject: org.jhotdraw.draw.DrawingView; Observer: org.jhotdraw.draw.event.FigureSelectionListener; Event: org.jhotdraw.draw.event.FigureSelectionEvent.

Observer
State changes of figures can be observed by other objects. Specifically CompositeFigure observes area invalidations and remove requests of its child figures. DrawingView also observes area invalidations of its drawing object. Subject: Figure; Observer: org.jhotdraw.draw.event.FigureListener; Event: org.jhotdraw.draw.event.FigureEvent; Concrete Observer: CompositeFigure, DrawingView.

Observer
State changes of handles can be observed by other objects. Specifically DrawingView observes area invalidations and remove requests of handles.
Subject: Handle; Observer: org.jhotdraw.draw.event.HandleListener; Event: org.jhotdraw.draw.event.HandleEvent; Concrete Observer: DrawingView.

Strategy
Editing can be constrained by a constrainer which is associated to a drawing view.
Context: DrawingView; Strategy: Constrainer.


Most used methods

  • findFigure
    Finds a figure at the given point.
  • findHandle
    Finds a handle at the given coordinates.
  • isEnabled
    Gets the enabled state of the drawing view. This is a bound property.
  • addFigureSelectionListener
    Add a listener for selection changes in this DrawingView.
  • addKeyListener
    Adds a key listener to the drawing view.
  • addMouseListener
    Adds a mouse listener to the drawing view.
  • addMouseMotionListener
    Adds a mouse motion listener to the drawing view.
  • addNotify
    Informs the view that it has been added to the specified editor. The view must draw the tool of the
  • addPropertyChangeListener
    Adds a property change listener to the drawing view.
  • addToSelection
    Adds a figure to the current selection.
  • clearSelection
    Clears the current selection.
  • drawingToView
    Converts drawing coordinates to view coordinates.
  • clearSelection,
  • drawingToView,
  • findFiguresWithin,
  • getActiveHandle,
  • getCompatibleHandles,
  • getComponent,
  • getConstrainer,
  • getDrawing,
  • getDrawingToViewTransform,
  • getEditor

Popular in Java

  • Start an intent from android
  • getResourceAsStream (ClassLoader)
  • onRequestPermissionsResult (Fragment)
  • getApplicationContext (Context)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • SortedSet (java.util)
    SortedSet is a Set which iterates over its elements in a sorted order. The order is determined eithe
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now