public void applyTransforms() { double scaleX = getScaleX(); double scaleY = getScaleY(); for (Bounds bounds : this.bounds) { if (bounds instanceof QBounds) { QBounds qBounds = (QBounds) bounds; Point2D point = qBounds.getLocation(); qBounds.setLocation(new Point2D.Double(point.getX() + translate.getX(), point.getY() + translate.getY())); Dimension2D d = qBounds.getSize(); qBounds.setSize(new Dimension2DImpl(d.getWidth() * scaleX, d .getHeight() * scaleY)); } } clear(); }
public Dimension2D getPageSize() { int pageCount = printable.getPageCount(); double pageWidth = 0; double pageHeight = 0; PageFormat pageFormat = new PageFormat(); for (int i = 0; i < pageCount; i++) { pageFormat = printable.getPageFormat(pageFormat, i); double w = pageFormat.getWidth(); double h = pageFormat.getHeight(); if (pageWidth < w) pageWidth = w; if (pageHeight < h) pageHeight = h; } final double fw = pageWidth; final double fh = pageHeight; return new Dimension2D() { @Override public void setSize(double width, double height) { } @Override public double getWidth() { return fw; } @Override public double getHeight() { return fh; } }; }
public void setFitZoom(Dimension size) { Dimension2D pageSize = getPageSize(); int pageCount = printable.getPageCount(); if (pageCount == 0) return; double xy = (pageSize.getWidth() + W_SPACE) * (pageSize.getHeight() + W_SPACE) * (pageCount + 1); double mxy = size.getWidth() * size.getHeight(); double zoom = Math.sqrt(mxy / xy); int columnCount = (int) (size.getWidth() / ((pageSize.getWidth() + W_SPACE / zoom) * zoom)); if (columnCount <= 0) columnCount = 1; if (columnCount > pageCount) columnCount = pageCount; setup(columnCount, zoom); }
/** @return A MultiResolution image created from nsImagePtr, or null. */ private Image toImage() { if (ptr == 0) return null; final Dimension2D size = nativeGetNSImageSize(ptr); final int w = (int)size.getWidth(); final int h = (int)size.getHeight(); Dimension2D[] sizes = nativeGetNSImageRepresentationSizes(ptr, size.getWidth(), size.getHeight()); return sizes == null || sizes.length < 2 ? new MultiResolutionCachedImage(w, h, (width, height) -> toImage(w, h, width, height)) : new MultiResolutionCachedImage(w, h, sizes, (width, height) -> toImage(w, h, width, height)); }
public void mouseDragged( final PInputEvent event ) { //Some clients such as the LaserNode only pass messages through the mouseDragged function, //so check first and see if we need to get the initial location if ( lastLocation == null ) { mousePressed( event ); } //Compute the global coordinate for where the drag is supposed to take the node Point2D newDragPosition = event.getPositionRelativeTo( node.getParent().getParent() );//see note in constructor newDragPosition = node.getParent().getParent().localToGlobal( newDragPosition ); //Bound the desired point within the canvas, accounting for some insets (so some part will always be visible) final int inset = 10; final ImmutableRectangle2D immutableRectangle2D = new ImmutableRectangle2D( inset, inset, event.getSourceSwingEvent().getComponent().getWidth() - inset * 2, event.getSourceSwingEvent().getComponent().getHeight() - inset * 2 ); Point2D constrained = immutableRectangle2D.getClosestPoint( newDragPosition ); Dimension2D delta = new PDimension( constrained.getX() - lastLocation.getX(), constrained.getY() - lastLocation.getY() ); //Convert from global to the node parent frame delta = node.globalToLocal( delta ); delta = node.localToParent( delta ); //Translate the node and get ready for next event dragNode( new DragEvent( event, new PDimension( delta.getWidth(), delta.getHeight() ) ) ); lastLocation = constrained; }
@Override protected void updateLayout() { super.updateLayout(); Dimension2D worldSize = getWorldSize(); if ( worldSize.getWidth() > 0 && worldSize.getHeight() > 0 ) { // make the reward animation fill the play area PBounds newBounds = new PBounds( 0, 0, worldSize.getWidth(), worldSize.getHeight() ); gameRewardNode.setBounds( newBounds ); // center top-level nodes centerNode( gameSettingsNode ); centerNode( gameOverNode ); centerNode( gamePlayParentNode ); } }
public ProbeNode( Dimension2D size, Color color, String label, Color labelColor ) { PPath pathNode = new PPath( new Rectangle2D.Double( -size.getWidth() / 2, -size.getHeight(), size.getWidth(), Math.abs( size.getHeight() ) ) ); pathNode.setStroke( PROBE_STROKE ); pathNode.setStrokePaint( PROBE_STROKE_COLOR ); pathNode.setPaint( color ); addChild( pathNode ); PText labelNode = new PText( label ); labelNode.setTextPaint( labelColor ); labelNode.setFont( PROBE_LABEL_FONT ); addChild( labelNode ); double x = pathNode.getFullBoundsReference().getCenterX() - ( labelNode.getFullBoundsReference().getWidth() / 2 ); double y = pathNode.getFullBoundsReference().getMaxY() - labelNode.getFullBoundsReference().getHeight() - 3; labelNode.setOffset( x, y ); }
private PPath createRoundedEdgeNode( Dimension2D size, Color color ) { GeneralPath path = new GeneralPath(); float width = (float) size.getWidth(); float height = (float) size.getHeight(); path.moveTo( -width / 2, height / 4 ); path.curveTo( -width / 2, height * 0.6f, width / 2, height * 0.6f, width / 2, height / 4 ); path.lineTo( width / 2, -height / 4 ); path.curveTo( width / 2, -height * 0.6f, -width / 2, -height * 0.6f, -width / 2, -height / 4 ); path.closePath(); PPath edgeNode = new PPath( path ); edgeNode.setPaint( color ); edgeNode.setStrokePaint( ColorUtils.darkerColor( color, 0.3 ) ); return edgeNode; }
public BodyGraphic() { try { imageGraphic = new PImage( ImageLoader.loadBufferedImage( MEASURING_TAPE_IMAGE ) ); } catch ( IOException e ) { e.printStackTrace(); } addChild( imageGraphic ); addInputEventListener( new PBasicInputEventHandler() { public void mouseDragged( PInputEvent event ) { Dimension2D dx = getDelta( event ); translateAll( dx.getWidth(), dx.getHeight() ); } } ); int crossHairLength = 10; CrossHairGraphic crossHairGraphic = new CrossHairGraphic( crossHairLength ); addChild( crossHairGraphic ); crossHairGraphic.setOffset( imageGraphic.getWidth() - crossHairLength / 2, imageGraphic.getHeight() - crossHairLength / 2 ); addInputEventListener( new CursorHandler( Cursor.HAND_CURSOR ) ); }
public EndGraphic() { Ellipse2D.Double shape = new Ellipse2D.Double( 0, 0, 15, 15 ); phetShapeGraphic = new PPath( shape ); phetShapeGraphic.setPaint( Color.black ); addChild( phetShapeGraphic ); addInputEventListener( new PBasicInputEventHandler() { public void mouseDragged( PInputEvent event ) { Dimension2D dx = getDelta( event ); MeasuringTape.this.translateEndPoint( dx.getWidth(), dx.getHeight() ); } } ); addInputEventListener( new CursorHandler( Cursor.HAND_CURSOR ) ); int crossHairSize = 10; CrossHairGraphic crossHairGraphic = new CrossHairGraphic( crossHairSize ); crossHairGraphic.setPaint( Color.yellow ); addChild( crossHairGraphic ); crossHairGraphic.setOffset( phetShapeGraphic.getWidth() / 2 - crossHairSize / 2, phetShapeGraphic.getHeight() / 2 - crossHairSize / 2 ); }
/** * Main routine that constructs a PhET Piccolo canvas in a window. * * @param args */ public static void main( String[] args ) { Dimension2D stageSize = new PDimension( 500, 300 ); PhetPCanvas canvas = new PhetPCanvas(); // Set up the canvas-screen transform. canvas.setWorldTransformStrategy( new PhetPCanvas.CenteredStage( canvas, stageSize ) ); ModelViewTransform mvt = ModelViewTransform.createSinglePointScaleInvertedYMapping( new Point2D.Double( 0, 0 ), new Point( (int) Math.round( stageSize.getWidth() * 0.5 ), (int) Math.round( stageSize.getHeight() * 0.50 ) ), 1 ); // "Zoom factor" - smaller zooms out, larger zooms in. canvas.getLayer().addChild( new TiltPredictionSelectorNode( new Property<BalanceGameModel.GameState>( BalanceGameModel.GameState.PRESENTING_INTERACTIVE_CHALLENGE ) ) ); // Boiler plate app stuff. JFrame frame = new JFrame(); frame.setContentPane( canvas ); frame.setSize( (int) stageSize.getWidth(), (int) stageSize.getHeight() ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setLocationRelativeTo( null ); // Center. frame.setVisible( true ); }
public static void main( String[] args ) { Dimension2D stageSize = new PDimension( 200, 100 ); PhetPCanvas canvas = new PhetPCanvas(); // Set up the canvas-screen transform. canvas.setWorldTransformStrategy( new PhetPCanvas.CenteredStage( canvas, stageSize ) ); ModelViewTransform mvt = ModelViewTransform.createSinglePointScaleInvertedYMapping( new Point2D.Double( 0, 0 ), new Point( (int) Math.round( stageSize.getWidth() * 0.5 ), (int) Math.round( stageSize.getHeight() * 0.50 ) ), 1 ); // "Zoom factor" - smaller zooms out, larger zooms in. canvas.getLayer().addChild( new EnergyChunkNode2( new EnergyChunk( EnergyType.ELECTRICAL, 0, 0, new BooleanProperty( true ) ), mvt ) ); // Boiler plate app stuff. JFrame frame = new JFrame(); frame.setContentPane( canvas ); frame.setSize( (int) stageSize.getWidth(), (int) stageSize.getHeight() ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setLocationRelativeTo( null ); // Center. frame.setVisible( true ); }
public SettingsNode( final LineGameModel model, Dimension2D stageSize ) { // the standard game settings panel PNode panelNode = new PSwing( new GameSettingsPanel( model.settings, new VoidFunction0() { public void apply() { model.phase.set( GamePhase.PLAY ); } }, LineGameConstants.BUTTON_COLOR ) ); panelNode.scale( 1.5 ); addChild( panelNode ); // centered on stage setOffset( ( stageSize.getWidth() - getFullBoundsReference().getWidth() ) / 2, ( stageSize.getHeight() - getFullBoundsReference().getHeight() ) / 2 ); }
@Override public Dimension2D getDimension(JasperReportsContext jasperReportsContext) { if (rotation != null) { switch(rotation) { case LEFT: case RIGHT: return new Dimension((int)barcode.getSize().getHeight(),(int)barcode.getSize().getWidth()); default: return barcode.getSize(); } } else { return barcode.getSize(); } }
/** * Overwritten to freeze nodes to their center on * size changes. */ @Override public void updateAutoSize(CellView view) { if (view != null && !isEditing()) { Rectangle2D bounds = (view.getAttributes() != null) ? GraphConstants.getBounds(view.getAttributes()) : null; AttributeMap attrs = getModel().getAttributes(view.getCell()); if (bounds == null) { bounds = GraphConstants.getBounds(attrs); } if (bounds != null) { boolean autosize = GraphConstants.isAutoSize(view.getAllAttributes()); boolean resize = GraphConstants.isResize(view.getAllAttributes()); if (autosize || resize) { Dimension2D d = getPreferredSize(view); int inset = 2 * GraphConstants.getInset(view.getAllAttributes()); // adjust the x,y corner so that the center stays in place double shiftX = (bounds.getWidth() - d.getWidth() - inset) / 2; double shiftY = (bounds.getHeight() - d.getHeight() - inset) / 2; bounds.setFrame(bounds.getX() + shiftX, bounds.getY() + shiftY, d.getWidth(), d.getHeight()); // Remove resize attribute snap(bounds); if (resize) { if (view.getAttributes() != null) { view.getAttributes().remove(GraphConstants.RESIZE); } attrs.remove(GraphConstants.RESIZE); } view.refresh(getGraphLayoutCache(), getGraphLayoutCache(), false); } } } }
private Dimension2D getPreferredSize(CellView view) { Dimension2D result; JVertex<?> vertex = view instanceof JVertexView ? ((JVertexView) view).getCell() : null; if (vertex == null) { result = getUI().getPreferredSize(this, view); } else { if (vertex.isStale(VisualKey.TEXT_SIZE)) { result = getUI().getPreferredSize(this, view); vertex.putVisual(VisualKey.TEXT_SIZE, result); } else { result = vertex.getVisuals().getTextSize(); } } return result; }
@Override protected Point2D getEditorLocation(Object cell, Dimension2D editorSize, Point2D pt) { double scale = getJGraph().getScale(); // shift the location by the extra border space return super.getEditorLocation(cell, editorSize, new Point2D.Double( pt.getX() + scale * (EXTRA_BORDER_SPACE + 4) - 4, pt.getY() + scale * (EXTRA_BORDER_SPACE + 3) - 3)); }
/** * Factory method to construct a new nod layout out of an attribute map. * Parameters not provided in the attribute map receive a default value. * @param visuals the visual attribute map * @return a new node layout based on <code>jAttr</code> */ static public JVertexLayout newInstance(VisualMap visuals) { Dimension2D size = visuals.getNodeSize(); Point2D pos = visuals.getNodePos(); return new JVertexLayout(new Rectangle2D.Double(pos.getX() - size.getWidth() / 2, pos.getY() - size.getHeight() / 2, size.getWidth(), size.getHeight())); }
public void zoomToFit(Drawable3D drawable, Dimension size) { int w = (int) (size.getWidth() * (1.0 - this.margin)); int h = (int) (size.getHeight() * (1.0 - this.margin)); Dimension2D target = new Dimension(w, h); Dimension3D d3d = drawable.getDimensions(); float distance = drawable.getViewPoint().optimalDistance(target, d3d, drawable.getProjDistance()); drawable.getViewPoint().setRho(distance); }
public void setDiagramam(Diagram diagramam) { this.diagram = diagramam; Dimension2D size = diagramam.zoom(diagramam.getSize(), zoom); setSize((int) floor(size.getWidth()) + 2, (int) floor(size.getHeight()) + 2); setPreferredSize(getSize()); }
@Override public Dimension2D getSize() { double height = top * 2; for (int i = 0; i < components.length; i++) { XMLComponent component = (XMLComponent) components[i]; if (component.isY()) { height += ((QBounds) bounds[i]).getSize().getHeight(); } } final Dimension2DImpl size = new Dimension2DImpl(width + LEFT * 2, height); if (!size.equals(this.size)) { this.size = size; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (editor != null) { editor.setPreferredSize(new Dimension((int) size .getWidth(), (int) size.getHeight())); editor.revalidate(); editor.repaint(); } } }); } return size; }
public void applyComlumnsSize(QBounds tableBound, Diagram diagram) { double width = getMinWidth(); double w = width / columns.length; double x = tableBound.getLocation().getX(); for (TableColumn tableColumn : columns) { QBounds bounds = (QBounds) diagram.getBounds(tableColumn); Dimension2D size = bounds.getSize(); size.setSize(w, size.getHeight()); bounds.setLocation(new Point2D.Double(x, getColumnYLocation( tableBound, size))); tableColumn.setWidth(w); x += w; } }
public void applyComlumnsSize(QBounds tableBound, QBounds[] bounds) { double width = getMinWidth(); double w = width / columns.length; double x = tableBound.getLocation().getX(); for (int i = 0; i < columns.length; i++) { TableColumn tableColumn = columns[i]; Dimension2D size = bounds[i].getSize(); size.setSize(w, size.getHeight()); bounds[i].setLocation(new Point2D.Double(x, getColumnYLocation( tableBound, size))); tableColumn.setWidth(w); x += w; } }
public void setFitZoom(double zoom, Dimension size) { if (zoom > 10) zoom = 10; if (zoom < 0.1) zoom = 0.1; int columnCount = 1; Dimension2D pageSize = getPageSize(); while (((pageSize.getWidth() + W_SPACE / zoom) * columnCount + pageSize .getWidth()) * zoom < size.getWidth()) { columnCount++; } setup(columnCount, zoom); }
public void setOnePageZoom(Dimension size) { Dimension2D pageSize = getPageSize(); int pageCount = printable.getPageCount(); if (pageCount == 0) return; double zoom = size.getWidth() / (pageSize.getWidth()); int columnCount = 1; setup(columnCount, zoom); }
public MultiResolutionCachedImage(int baseImageWidth, int baseImageHeight, Dimension2D[] sizes, BiFunction<Integer, Integer, Image> mapper) { this.baseImageWidth = baseImageWidth; this.baseImageHeight = baseImageHeight; this.sizes = (sizes == null) ? null : Arrays.copyOf(sizes, sizes.length); this.mapper = mapper; }
private MultiResolutionCachedImage(int baseImageWidth, int baseImageHeight, Dimension2D[] sizes, BiFunction<Integer, Integer, Image> mapper, boolean copySizes) { this.baseImageWidth = baseImageWidth; this.baseImageHeight = baseImageHeight; this.sizes = (copySizes && sizes != null) ? Arrays.copyOf(sizes, sizes.length) : sizes; this.mapper = mapper; }
/** @return A MultiResolution image created from nsImagePtr, or null. */ private Image toImage() { if (ptr == 0) { return null; } AtomicReference<Dimension2D> sizeRef = new AtomicReference<>(); execute(ptr -> { sizeRef.set(nativeGetNSImageSize(ptr)); }); final Dimension2D size = sizeRef.get(); if (size == null) { return null; } final int w = (int)size.getWidth(); final int h = (int)size.getHeight(); AtomicReference<Dimension2D[]> repRef = new AtomicReference<>(); execute(ptr -> { repRef.set(nativeGetNSImageRepresentationSizes(ptr, size.getWidth(), size.getHeight())); }); Dimension2D[] sizes = repRef.get(); return sizes == null || sizes.length < 2 ? new MultiResolutionCachedImage(w, h, (width, height) -> toImage(w, h, width, height)) : new MultiResolutionCachedImage(w, h, sizes, (width, height) -> toImage(w, h, width, height)); }
/** * Creates an object based on the description. * * @return The object. */ public Object createObject() { final Dimension2D dim = new FloatDimension(); final float width = getFloatParameter("width"); final float height = getFloatParameter("height"); dim.setSize(width, height); return dim; }
protected void updateLayout() { Dimension2D worldSize = getWorldSize(); if ( worldSize.getWidth() <= 0 || worldSize.getHeight() <= 0 ) { // canvas hasn't been sized, blow off layout return; } else if ( TitrationConstants.DEBUG_CANVAS_UPDATE_LAYOUT ) { System.out.println( "TitrateCanvas.updateLayout worldSize=" + worldSize );//XXX } //XXX lay out nodes }
public void testLocalToViewDimension2DTranslateView() { camera.translateView(10.0d, 20.0d); Dimension2D local = new Dimension(0, 0); camera.localToView(local); assertEquals(0.0d, local.getWidth(), 0.1d); assertEquals(0.0d, local.getHeight(), 0.1d); }
/** * This method is called to re-scale the chart, which generally occurs * when the overall size of the simulation is changed. * * @param */ private void updateSize( Dimension2D size ) { if ( size.getWidth() == 0 || size.getHeight() == 0 ) { // Ignore unreasonable bounds. return; } // Set the scale factor such that this chart fits in the given bounds, // but do not change the aspect ratio. setScale( 1 ); setScale( Math.min( size.getWidth() / _backgroundNode.getFullBoundsReference().width, size.getHeight() / _backgroundNode.getFullBoundsReference().height ) ); }
/** * Draws dashed lines between the upper-left and lower-left corners of the "tiny box" and the "big box". * * @param tinyBoxOrigin * @param tinyBoxSize * @param bigBoxOrigin * @param bigBoxSize */ public void update( Point2D tinyBoxOrigin, Dimension2D tinyBoxSize, Point2D bigBoxOrigin, Dimension2D bigBoxSize ) { removeAllChildren(); double x1 = tinyBoxOrigin.getX(); double y1 = tinyBoxOrigin.getY(); double x2 = bigBoxOrigin.getX(); double y2 = bigBoxOrigin.getY(); double x3 = tinyBoxOrigin.getX(); double y3 = tinyBoxOrigin.getY() + tinyBoxSize.getHeight(); double x4 = bigBoxOrigin.getX(); double y4 = bigBoxOrigin.getY() + bigBoxSize.getHeight(); PPath topLine = new PPath(); topLine.setPathTo( new Line2D.Double( x1, y1, x2, y2 ) ); topLine.setStroke( STROKE ); topLine.setStrokePaint( Color.WHITE ); addChild( topLine ); PPath bottomLine = new PPath(); bottomLine.setPathTo( new Line2D.Double( x3, y3, x4, y4 ) ); bottomLine.setStroke( STROKE ); bottomLine.setStrokePaint( Color.WHITE ); addChild( bottomLine ); }
public void setSize( Dimension2D size ) { if ( width != size.getWidth() || height != size.getHeight() ) { width = size.getWidth(); height = size.getHeight(); notifySizeChanged(); } }
/** * Test harness. * * @param args */ public static void main( String[] args ) { Dimension2D stageSize = new PDimension( 500, 400 ); PhetPCanvas canvas = new PhetPCanvas(); // Set up the canvas-screen transform. canvas.setWorldTransformStrategy( new PhetPCanvas.CenteredStage( canvas, stageSize ) ); // Add the default knob to the canvas. canvas.addWorldChild( new KnobNode() {{ setOffset( 10, 10 ); }} ); // Add a node that is typical as of 4/3/2012. This was taken from // the VSliderNode class as it looked at the time of this writing. canvas.addWorldChild( new KnobNode( new KnobNode.ColorScheme( new Color( 115, 217, 255 ) ) ) {{ setOffset( 10, 50 ); }} ); // Add a disabled version that uses a common color scheme. canvas.addWorldChild( new KnobNode( new KnobNode.ColorScheme( new Color( 115, 217, 255 ) ) ) {{ setOffset( 10, 90 ); setEnabled( false ); }} ); // Boiler plate app stuff. JFrame frame = new JFrame(); frame.setContentPane( canvas ); frame.setSize( (int) stageSize.getWidth(), (int) stageSize.getHeight() ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setLocationRelativeTo( null ); // Center. frame.setVisible( true ); }
protected void updateLayout() { Dimension2D worldSize = getWorldSize(); if ( worldSize.getWidth() <= 0 || worldSize.getHeight() <= 0 ) { // canvas hasn't been sized, blow off layout return; } else if ( GeneNetworkConstants.DEBUG_CANVAS_UPDATE_LAYOUT ) { System.out.println( "cavas worldSize=" + worldSize ); } // Place the legend where it needs to go. legend.setOffset(getWidth() - legend.getFullBoundsReference().getWidth() - 10, 10); }
public CloseOnMovingTargetMotionStrategy(IModelElement targetElement, Dimension2D offsetFromTarget, Rectangle2D bounds) { super(bounds); this.targetElement = targetElement; this.offsetFromTarget = offsetFromTarget; targetElement.addListener(targetListener); updateDestination(); }