@Override public void draw(DrawRequest r) { Graphics2D g = r.getGraphics(); g.setColor(Color.LIGHT_GRAY); g.setStroke(new BasicStroke(0.02f)); Line2D l = new Line2D.Double(0, 0, origin.getX(), origin.getY()); g.draw(l); super.draw(r); }
void update(ControlPoint ctrlp) { TreeNode rootNode = getRootNode(); if (rootNode == null) return; rootNode.removeAllChildren(); DeviceList rootDevList = ctrlp.getDeviceList(); updateDeviceList(rootNode, rootDevList); ((DefaultTreeModel) getModel()).reload(); repaint(); }
public static void zoomToFit(Viewport2 viewport) { ViewDefinition viewdef = viewport.getViewDefinition(); // if (MainFrame.getInstance().getMeshToolBar().getMode() != MeshToolBar.VIEW_ZOOM) { // MainFrame.getInstance().getJPatchScreen().removeAllMouseListeners(); // MainFrame.getInstance().getJPatchScreen().addMouseListeners(new // ChangeViewMouseListener(MouseEvent.BUTTON1,ChangeViewMouseListener.ZOOM)); // MainFrame.getInstance().getMeshToolBar().setMode(MeshToolBar.VIEW_ZOOM); // } else { // MainFrame.getInstance().getMeshToolBar().reset(); // } Selection selection = MainFrame.getInstance().getSelection(); float left = Float.MAX_VALUE; float right = -Float.MAX_VALUE; float bottom = Float.MAX_VALUE; float top = -Float.MAX_VALUE; Point3f p3 = new Point3f(); Matrix4f m4View = viewdef.getScreenMatrix(); // Matrix3f m3RotScale = new Matrix3f(); // m4View.getRotationScale(m3RotScale); boolean doit = true; if (selection != null && !selection.isSingle()) { for (Iterator it = selection.getObjects().iterator(); it.hasNext(); ) { Object object = it.next(); if (object instanceof ControlPoint) { p3.set(((ControlPoint) object).getPosition()); m4View.transform(p3); if (p3.x < left) left = p3.x; if (p3.x > right) right = p3.x; if (p3.y < bottom) bottom = p3.y; if (p3.y > top) top = p3.y; } } } else { ArrayList heads = MainFrame.getInstance().getModel().allHeads(); int p = 0; for (Iterator it = heads.iterator(); it.hasNext(); ) { ControlPoint cp = (ControlPoint) it.next(); if (!cp.isHidden()) { p3.set(cp.getPosition()); m4View.transform(p3); if (p3.x < left) left = p3.x; if (p3.x > right) right = p3.x; if (p3.y < bottom) bottom = p3.y; if (p3.y > top) top = p3.y; p++; } } doit = (p >= 2); } if (doit) { // System.out.println(left + " " + right + " " + top + " " + bottom + " " + // viewdef.getScale()); // System.out.println(viewdef.getTranslateX() + " " + viewdef.getTranslateY()); float centerX = (left + right) / 2f; float centerY = (top + bottom) / 2f; float dimX = viewdef.getWidth() / 2f; float dimY = viewdef.getHeight() / 2f; float sizeX = right - centerX; float sizeY = top - centerY; if (sizeX > 0 || sizeY > 0) { // System.out.println(centerX + ":" + centerY); float scaleX = dimX / sizeX; float scaleY = dimY / sizeY; float scale = Math.min(scaleX, scaleY) * 0.9f; // viewdef.setScale(viewdef.getScale() * scale); viewdef.setLock(null); viewdef.moveView(-centerX / dimX + 1, (dimY - centerY) / dimX, false); viewdef.scaleView(scale); // viewdef.setTranslation(centerX, centerY); // viewdef.computeMatrix(); // viewport.render(); } } }
/** * Constructs a new {@link LayoutPoint} from the given event. The event must be from a {@link * DragSourceListener} associated with the {@link LayoutCanvas} such that the {@link * DragSourceEvent#x} and {@link DragSourceEvent#y} fields are relative to the canvas. * * @param canvas The {@link LayoutCanvas} this point is within. * @param event The mouse event to construct the {@link LayoutPoint} from. * @return A {@link LayoutPoint} which corresponds to the given {@link DragSourceEvent}. */ public static LayoutPoint create(LayoutCanvas canvas, DragSourceEvent event) { // The drag source event coordinates should already be relative to the // canvas widget. return ControlPoint.create(canvas, event).toLayout(); }
/** * Constructs a new {@link LayoutPoint} from the given event. The event must be from a {@link * MouseListener} associated with the {@link LayoutCanvas} such that the {@link MouseEvent#x} and * {@link MouseEvent#y} fields are relative to the canvas. * * @param canvas The {@link LayoutCanvas} this point is within. * @param event The mouse event to construct the {@link LayoutPoint} from. * @return A {@link LayoutPoint} which corresponds to the given {@link MouseEvent}. */ public static LayoutPoint create(LayoutCanvas canvas, MouseEvent event) { // The mouse event coordinates should already be relative to the canvas // widget. assert event.widget == canvas : event.widget; return ControlPoint.create(canvas, event).toLayout(); }
/** * Returns the equivalent {@link ControlPoint} to this {@link LayoutPoint}. * * @return The equivalent {@link ControlPoint} to this {@link LayoutPoint} */ public ControlPoint toControl() { int cx = mCanvas.getHorizontalTransform().translate(x); int cy = mCanvas.getVerticalTransform().translate(y); return ControlPoint.create(mCanvas, cx, cy); }