當前位置: 首頁>>代碼示例>>Java>>正文


Java Dimension2D類代碼示例

本文整理匯總了Java中java.awt.geom.Dimension2D的典型用法代碼示例。如果您正苦於以下問題:Java Dimension2D類的具體用法?Java Dimension2D怎麽用?Java Dimension2D使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Dimension2D類屬於java.awt.geom包,在下文中一共展示了Dimension2D類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: applyTransforms

import java.awt.geom.Dimension2D; //導入依賴的package包/類
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();
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:18,代碼來源:Group.java

示例2: getPageSize

import java.awt.geom.Dimension2D; //導入依賴的package包/類
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;
        }
    };
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:36,代碼來源:PrintPreviewComponent.java

示例3: setFitZoom

import java.awt.geom.Dimension2D; //導入依賴的package包/類
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);
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:18,代碼來源:PrintPreviewComponent.java

示例4: toImage

import java.awt.geom.Dimension2D; //導入依賴的package包/類
/** @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));
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:CImage.java

示例5: mouseDragged

import java.awt.geom.Dimension2D; //導入依賴的package包/類
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;
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:26,代碼來源:CanvasBoundedDragHandler.java

示例6: updateLayout

import java.awt.geom.Dimension2D; //導入依賴的package包/類
@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 );
    }
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:17,代碼來源:GameCanvas.java

示例7: ProbeNode

import java.awt.geom.Dimension2D; //導入依賴的package包/類
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 );
        }
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:18,代碼來源:ConductivityTesterNode.java

示例8: createRoundedEdgeNode

import java.awt.geom.Dimension2D; //導入依賴的package包/類
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;
    }
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:20,代碼來源:MembraneChannelNode.java

示例9: BodyGraphic

import java.awt.geom.Dimension2D; //導入依賴的package包/類
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 ) );
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:23,代碼來源:MeasuringTape.java

示例10: EndGraphic

import java.awt.geom.Dimension2D; //導入依賴的package包/類
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 );
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:22,代碼來源:MeasuringTape.java

示例11: main

import java.awt.geom.Dimension2D; //導入依賴的package包/類
/**
 * 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 );
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:29,代碼來源:TiltPredictionSelectorNode.java

示例12: main

import java.awt.geom.Dimension2D; //導入依賴的package包/類
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 );
    }
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:24,代碼來源:EnergyChunkNode2.java

示例13: SettingsNode

import java.awt.geom.Dimension2D; //導入依賴的package包/類
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 );
    }
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:18,代碼來源:SettingsNode.java

示例14: getDimension

import java.awt.geom.Dimension2D; //導入依賴的package包/類
@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();
	}
}
 
開發者ID:TIBCOSoftware,項目名稱:jasperreports,代碼行數:19,代碼來源:BarbecueRendererImpl.java

示例15: updateAutoSize

import java.awt.geom.Dimension2D; //導入依賴的package包/類
/**
 * 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);
            }
        }
    }
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:39,代碼來源:JGraph.java


注:本文中的java.awt.geom.Dimension2D類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。