java.awt.Dimension#getWidth ( )源码实例Demo

下面列出了java.awt.Dimension#getWidth ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Lottery   文件: MagickImageScale.java
public static void imageMark(File srcFile, File destFile, int minWidth,
		int minHeight, int pos, int offsetX, int offsetY,
		String markContent, Color markColor, int markSize, int alpha)
		throws IOException, MagickException {
	ImageInfo info = new ImageInfo(srcFile.getAbsolutePath());
	MagickImage image = new MagickImage(info);

	Dimension dim = image.getDimension();
	int width = (int) dim.getWidth();
	int height = (int) dim.getHeight();
	if (width < minWidth || height < minHeight) {
		image.destroyImages();
		if (!srcFile.equals(destFile)) {
			FileUtils.copyFile(srcFile, destFile);
		}
	} else {
		imageMark(image, info, width, height, pos, offsetX, offsetY,
				markContent, markColor, markSize, alpha);
		image.setFileName(destFile.getAbsolutePath());
		image.writeImage(info);
		image.destroyImages();
	}
}
 
源代码2 项目: Shuffle-Move   文件: EditRosterService.java
@SuppressWarnings("serial")
private Component makeCenterPanel() {
   rosterEntryPanel = new JPanel(new WrapLayout()) {
      // Fix to make it play nice with the scroll bar.
      @Override
      public Dimension getPreferredSize() {
         Dimension d = super.getPreferredSize();
         d.width = (int) (d.getWidth() - 20);
         return d;
      }
   };
   final JScrollPane ret = new JScrollPane(rosterEntryPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
         ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
   ret.addComponentListener(new ComponentAdapter() {
      @Override
      public void componentResized(ComponentEvent e) {
         ret.revalidate();
      }
   });
   ret.getVerticalScrollBar().setUnitIncrement(27);
   return ret;
}
 
源代码3 项目: FoxTelem   文件: ProgressPanel.java
public ProgressPanel(JFrame owner, String message, boolean modal) {
		super(owner, modal);
		title = message;
		setTitle(message);
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
//		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		int x = 100;
		int y = 100;
		if (MainWindow.frame != null) {
			x = MainWindow.frame.getX() + MainWindow.frame.getWidth()/2 - (message.length()*9)/2;
			y = MainWindow.frame.getY() + MainWindow.frame.getHeight()/2;
		} else {
			Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
			x = (int) ((dimension.getWidth() - this.getWidth()) / 2);
			y = (int) ((dimension.getHeight() - this.getHeight()) / 2);
		}
		setBounds(100, 100, message.length()*11, 10);
	
		    this.setLocation(x, y);
	}
 
源代码4 项目: ccu-historian   文件: TextBlockPanel.java
/**
 * Paints the panel.
 *
 * @param g  the graphics device.
 */
public void paintComponent(final Graphics g) {

    super.paintComponent(g);
    final Graphics2D g2 = (Graphics2D) g;

    final Dimension size = getSize();
    final Insets insets = getInsets();
    final Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top,
                                  size.getWidth() - insets.left - insets.right,
                                  size.getHeight() - insets.top - insets.bottom);

    final double x = available.getX();
    final double y = available.getY();
    final float width = (float) available.getWidth();
    final TextBlock block = TextUtilities.createTextBlock(
        this.text, this.font, Color.black, width, new G2TextMeasurer(g2)
    );
    g2.setPaint(Color.black);
    block.draw(g2, (float) x, (float) y, TextBlockAnchor.TOP_LEFT, 0.0f, 0.0f, 0.0);

}
 
@Action(object = ObjectType.APP, desc ="Move the mouse to the location [<Data>]", input =InputType.YES)
public void moveMouseTO() {
    try {
        Robot r = new Robot();
        int x = Integer.valueOf(Data.split(",")[0]);
        int y = Integer.valueOf(Data.split(",")[1]);
        //use graphic environment lib. if its is a multi SCREEN 
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        if (x < 0) {
            x += screenSize.getWidth();//x pixels left of right end
        }
        if (y < 0) {
            y += screenSize.getHeight();//y pixels above bottom end
        }
        r.mouseMove(x, y);
        Report.updateTestLog(Action, "Mouse moved to '" + x + "," + y + "' ", Status.DONE);
    } catch (Exception ex) {
        Report.updateTestLog(Action, ex.getMessage(), Status.FAIL);
        Logger.getLogger(Mouse.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
源代码6 项目: netbeans   文件: DragWindow.java
private BufferedImage createContentImage( Component c, Dimension contentSize ) {
    GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice().getDefaultConfiguration();

    BufferedImage res = config.createCompatibleImage(contentSize.width, contentSize.height);
    Graphics2D g = res.createGraphics();
    //some components may be non-opaque so just black rectangle would be painted then
    g.setColor( Color.white );
    g.fillRect(0, 0, contentSize.width, contentSize.height);
    if( WinSysPrefs.HANDLER.getBoolean(WinSysPrefs.DND_SMALLWINDOWS, true) && c.getWidth() > 0 && c.getHeight() > 0 ) {
        double xScale = contentSize.getWidth() / c.getWidth();
        double yScale = contentSize.getHeight() / c.getHeight();
        g.setTransform(AffineTransform.getScaleInstance(xScale, yScale) );
    }
    c.paint(g);
    return res;
}
 
源代码7 项目: PeerWasp   文件: JTrayIcons.java
/**
 * gets the tray size for the icons
 */
private void initSize() {
	Dimension trayDim = java.awt.SystemTray.getSystemTray().getTrayIconSize();
	if (trayDim == null || trayDim.getWidth() < 1.0 || trayDim.getWidth() < 1.0) {
		traySize.setSize(24.0, 24.0);
	} else {
		traySize.setSize(trayDim);
	}
}
 
源代码8 项目: stendhal   文件: ImageViewWindow.java
/**
 * Calculate maximum size for a window that fits on the game screen.
 *
 * @return size
 */
private Dimension genMaxSize() {
	Dimension displaySize = stendhal.getDisplaySize();
	final int width = (int) (displaySize.getWidth() - PADDING);
	final int height = (int) (displaySize.getHeight() - PADDING);
	return new Dimension(width, height);
}
 
源代码9 项目: chipster   文件: ScrollGroup.java
@Override
public Dimension getMinimumSize() {
	//Set minimum height to preferred height for small tracks, because there is not point to scroll them
	//Minimum height for larger scroll groups is 250 pixels, because smaller view port is not that useful 
	//either
	Dimension pref = super.getPreferredSize();			
	
	if (pref.getHeight() < 250) {
		return pref;
	}
	return new Dimension((int) pref.getWidth(), 250);
	
}
 
源代码10 项目: chipster   文件: LayoutManager.java
/** 
 * Returns the farthest vertex position added by default margins.
 * Relies on the getGraphSize()-method. 
 * 
 * @return the coordinates for the next root
 */
public Point getNewRootPosition(){
	Dimension dim = graph.getGraphSize();
	int x = (int)dim.getWidth();
	
	//Snap to left border if close enough
	if(x < 60){
		x = 10;
	}
	return new Point(x, 10);
}
 
源代码11 项目: microba   文件: Birdview.java
/**
 * Addjusts {@link #panRect} to be postitionsed with the centter at a given
 * point if possible. This methods ensures that {@link #panRect} fits
 * entirely in {@link #paintRect}.
 * 
 * @param point
 *            the desired panRect center
 */
private void panRectTo(Point point) {

	Dimension viewSize = peerScroller.getViewport().getViewSize();
	Rectangle viewRect = peerScroller.getViewport().getViewRect();

	double panHalfWidth = panRect.getWidth() / 2;
	double panHalfHeight = panRect.getHeight() / 2;

	Point2D panOrigin = new Point2D.Double(point.x - panHalfWidth, point.y
			- panHalfHeight);
	double xk = panOrigin.getX() / paintRect.getWidth();
	double yk = panOrigin.getY() / paintRect.getHeight();

	Point viewPos = new Point((int) (viewSize.getWidth() * xk), (int) (viewSize
			.getHeight() * yk));

	// make sure we do not pan past the bounds:
	if (viewPos.x < 0)
		viewPos.x = 0;
	if (viewPos.y < 0)
		viewPos.y = 0;

	int wd = (viewPos.x + viewRect.width) - viewSize.width;
	int hd = (viewPos.y + viewRect.height) - viewSize.height;

	if (wd > 0)
		viewPos.x -= wd;
	if (hd > 0)
		viewPos.y -= hd;

	// pan it
	peerScroller.getViewport().setViewPosition(viewPos);

	update();
	repaint();
}
 
源代码12 项目: MeteoInfo   文件: Draw.java
/**
 * Graphics transform
 *
 * @param g Graphics2D
 * @param x X location
 * @param y Y location
 * @param s String
 * @param x_align X align
 * @param y_align Y align
 * @param angle Angle
 * @return AffineTransform
 */
public static AffineTransform transform_bak(Graphics2D g, float x, float y, String s, XAlign x_align, YAlign y_align, float angle) {
    Dimension dim = getStringDimension(s, g);
    AffineTransform tempTrans = g.getTransform();
    //AffineTransform myTrans = new AffineTransform();
    AffineTransform myTrans = (AffineTransform) tempTrans.clone();
    switch (x_align) {
        case CENTER:
            x -= (float)(dim.getWidth() * 0.5);
            break;
        case RIGHT:
            x -= (float)dim.getWidth();
            break;
    }
    switch (y_align) {
        case TOP:
            y += (float)dim.getHeight();
            break;
        case CENTER:
            y += (float)(dim.getHeight() * 0.5);
            break;
    }
    //myTrans.translate(tempTrans.getTranslateX() + x, tempTrans.getTranslateY() + y);
    myTrans.translate(x, y);
    myTrans.rotate(-angle * Math.PI / 180);

    return myTrans;
}
 
源代码13 项目: jdk8u_jdk   文件: JDialog705.java
@Override
public void windowOpened(WindowEvent windowEvent) {

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    Dimension shotSize;

    shotSize = windowAncestor.getSize();
    int expectedX = (int) (shotSize.getWidth() / 4);
    int expectedY = (int) (shotSize.getHeight() / 4);
    int maxWidth = (int) (shotSize.getWidth() / 2);
    int maxHeight = (int) (shotSize.getHeight() / 2);
    boolean popupRes = checkImage(windowAncestor, shotSize, expectedX, expectedY, maxWidth, maxHeight);

    shotSize = modalBlocker.getContentPane().getSize();
    expectedX = (int) (shotSize.getWidth() / 2 + shotSize.getWidth() / 4);
    expectedY = (int) (shotSize.getHeight() / 2 + shotSize.getHeight() / 4);
    maxWidth = (int) (shotSize.getWidth());
    maxHeight = (int) (shotSize.getHeight());
    boolean modalBlockerRes = checkImage(modalBlocker.getContentPane(), shotSize, expectedX,
            expectedY, maxWidth, maxHeight);

    String msg = "";

    if (!popupRes) msg = "The popup must be above the frame.";
    if (!modalBlockerRes) msg += "The modal blocker must be above the popup.";

    if (!popupRes || !modalBlockerRes)
        throw new RuntimeException(msg);

    modalBlocker.dispose();
    jFrame.dispose();
}
 
源代码14 项目: ramus   文件: PrintPreviewComponent.java
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);
}
 
源代码15 项目: MeteoInfo   文件: Draw.java
/**
 * Draw label point
 *
 * @param x X
 * @param y Y
 * @param font Font
 * @param text Text
 * @param color Color
 * @param g Graphics2D
 * @param angle Angle
 */
public static void drawTickLabel(float x, float y, Font font, String text, Color color, float angle, Graphics2D g) {
    g.setColor(color);
    g.setFont(font);
    Dimension labSize = Draw.getStringDimension(text, g);
    if (angle == 0) {
        x = x - (float) labSize.getWidth() / 2;
        y -= (float) labSize.getHeight() / 2;
        Draw.drawString(g, text, x, y + labSize.height / 2);
    } else {
        AffineTransform tempTrans = g.getTransform();
        //AffineTransform myTrans = new AffineTransform();
        AffineTransform myTrans = (AffineTransform) tempTrans.clone();
        myTrans.translate(x, y);
        myTrans.translate(tempTrans.getTranslateX() + x, tempTrans.getTranslateY() + y);
        myTrans.rotate(-angle * Math.PI / 180);
        g.setTransform(myTrans);
        if (angle == 90) {
            x = -(float) (labSize.getWidth() - 10);
            y = (float) (labSize.getHeight() / 3);
        } else {
            x = -(float) (labSize.getWidth() - 5);
            y = 0;
        }
        Draw.drawString(g, text, x, y);
        g.setTransform(tempTrans);
    }
}
 
源代码16 项目: swift-explorer   文件: SwiftExplorer.java
private static void openMainWindow(final MainPanel cp) throws IOException {
    JFrame frame = new JFrame(Configuration.INSTANCE.getAppName());
    
    Dimension screenSize =  java.awt.Toolkit.getDefaultToolkit().getScreenSize() ;
    
    float ratio = (float) 0.8 ;
    Dimension windowSize = new Dimension ((int)(screenSize.getWidth() * ratio), (int)(screenSize.getHeight() * ratio)) ;

    frame.setSize(windowSize.getSize());
    frame.setLocationByPlatform(true);
    frame.setIconImage(ImageIO.read(SwiftExplorer.class.getResource("/icons/logo.png")));
    frame.getContentPane().add(cp);
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            if (cp.onClose()) {
                System.exit(0);
            }
        }
    });
    cp.setOwner(frame);
    frame.setJMenuBar(cp.createMenuBar());
    
    // center the frame
    int x = (int) ((screenSize.getWidth() - frame.getWidth()) / 2);
    int y = (int) ((screenSize.getHeight() - frame.getHeight()) / 2);
    frame.setLocation(x, y);
    
    frame.setVisible(true);
}
 
源代码17 项目: collect-earth   文件: PropertiesDialog.java
private void centreWindow() {
	Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
	int x = (int) ((dimension.getWidth() - getWidth()) / 2);
	int y = (int) ((dimension.getHeight() - getHeight()) / 2);
	setLocation(x, y);
}
 
源代码18 项目: blog-codes   文件: mxGraphOutline.java
/**
 * Returns true if the scale or translate has changed.
 */
public boolean updateScaleAndTranslate()
{
	double newScale = 1;
	int dx = 0;
	int dy = 0;

	if (this.graphComponent != null)
	{
		Dimension graphSize = graphComponent.getGraphControl().getSize();
		Dimension outlineSize = getSize();

		int gw = (int) graphSize.getWidth();
		int gh = (int) graphSize.getHeight();

		if (gw > 0 && gh > 0)
		{
			boolean magnifyPage = graphComponent.isPageVisible()
					&& isFitPage()
					&& graphComponent.getHorizontalScrollBar().isVisible()
					&& graphComponent.getVerticalScrollBar().isVisible();
			double graphScale = graphComponent.getGraph().getView()
					.getScale();
			mxPoint trans = graphComponent.getGraph().getView()
					.getTranslate();

			int w = (int) outlineSize.getWidth() - 2 * outlineBorder;
			int h = (int) outlineSize.getHeight() - 2 * outlineBorder;

			if (magnifyPage)
			{
				gw -= 2 * Math.round(trans.getX() * graphScale);
				gh -= 2 * Math.round(trans.getY() * graphScale);
			}

			newScale = Math.min((double) w / gw, (double) h / gh);

			dx += (int) Math
					.round((outlineSize.getWidth() - gw * newScale) / 2);
			dy += (int) Math
					.round((outlineSize.getHeight() - gh * newScale) / 2);

			if (magnifyPage)
			{
				dx -= Math.round(trans.getX() * newScale * graphScale);
				dy -= Math.round(trans.getY() * newScale * graphScale);
			}
		}
	}

	if (newScale != scale || translate.x != dx || translate.y != dy)
	{
		scale = newScale;
		translate.setLocation(dx, dy);

		return true;
	}
	else
	{
		return false;
	}
}
 
源代码19 项目: openjdk-8-source   文件: Util.java
public static Point getTitlePoint(Window decoratedWindow) {
    Point p = decoratedWindow.getLocationOnScreen();
    Dimension d = decoratedWindow.getSize();
    return new Point(p.x + (int)(d.getWidth()/2),
                     p.y + (int)(decoratedWindow.getInsets().top/2));
}
 
@Override
public void setSize(Dimension d) {
	newW=(int)d.getWidth();
	newH=(int)d.getHeight();
}