Java Code Examples for java.awt.Dimension#setSize()

The following examples show how to use java.awt.Dimension#setSize() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Get maximum tick label dimension
 * @param g Graphics2D
 * @return Maximum tick label dimension
 */
public Dimension getMaxTickDim(Graphics2D g) {
    this.updateTickLabels();
    Dimension dim = new Dimension();
    if (this.tickLabels.isEmpty()) {
        return dim;
    }
    
    Dimension dim1;
    double width = dim.getWidth(), height = dim.getHeight();
    for (int i = 0; i < this.tickLabels.size(); i++) {
        ChartText ct = this.tickLabels.get(i);
        ct.setAngle(this.tickLabelAngle);
        dim1 = ct.getTrueDimension(g);
        if (width < dim1.getWidth()){
            width = dim1.getWidth();
        }
        if (height < dim1.getHeight()) {
            height = dim1.getHeight();
        }
    }
    
    dim.setSize(width, height);
    return dim;
}
 
Example 2
Source Project: littleluck   File: LuckMenuItemUI.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * 重写方法,设置菜单的最小高度为20, 否则会出现菜单项大小不一致的情况。
 * </p>
 *
 * <p>
 * Rewrite method, set the minimum height of the menu is 20, otherwise the
 * menu item size will be inconsistent situation.
 * </p>
 */
@Override
protected Dimension getPreferredMenuItemSize(JComponent c,
                                             Icon checkIcon,
                                             Icon arrowIcon,
                                             int defaultTextIconGap)
{

    Dimension dimension = super.getPreferredMenuItemSize(c, checkIcon,
            arrowIcon, defaultTextIconGap);

    if (dimension != null && dimension.height < 20)
    {
        dimension.setSize(dimension.width, 20);
    }

    return dimension;
}
 
Example 3
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    double theta = Math.toRadians(15);
    double cos = Math.cos(theta);
    double sin = Math.sin(theta);
    double xsize = sin * h + cos * w;
    double ysize = sin * w + cos * h;
    double scale = Math.min(w / xsize, h / ysize);
    xsize *= scale;
    ysize *= scale;
    AffineTransform at = new AffineTransform();
    at.translate((w - xsize) / 2.0, (h - ysize) / 2.0);
    at.translate(sin * h * scale, 0.0);
    at.rotate(theta);
    g2d.transform(at);
    dim.setSize(scaleForTransform(at, dim));
}
 
Example 4
Source Project: bigtable-sql   File: SQLPanel.java    License: Apache License 2.0 6 votes vote down vote up
CopyLastButton(IApplication app)
{
	super();
	final SquirrelResources rsrc = app.getResources();
	final ImageIcon icon = rsrc.getIcon(SquirrelResources.IImageNames.COPY_SELECTED);
	setIcon(icon);
          // i18n[SQLPanel.copylastbutton.hint=Copy current SQL history to entry area]
	String hint = s_stringMgr.getString("SQLPanel.copylastbutton.hint");
          setToolTipText(hint);
	Dimension dm = getPreferredSize();
	dm.setSize(dm.height, dm.height);
	setPreferredSize(dm);
	addActionListener(new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			copySelectedItemToEntryArea();
		}
	});
}
 
Example 5
/**
 * <p>
 * 重写方法,设置菜单的最小高度为20, 否则会出现菜单项大小不一致的情况。
 * </p>
 *
 * <p>
 * Rewrite method, set the minimum height of the menu is 20, otherwise the
 * menu item size will be inconsistent situation.
 * </p>
 */
protected Dimension getPreferredMenuItemSize(JComponent c,
                                             Icon checkIcon,
                                             Icon arrowIcon,
                                             int defaultTextIconGap)
{
    Dimension dimension = super.getPreferredMenuItemSize(c, checkIcon,
            arrowIcon, defaultTextIconGap);

    if (dimension != null && dimension.height < 20)
    {
        dimension.setSize(dimension.width, 20);
    }

    return dimension;
}
 
Example 6
public void tooglePanel(){
	Dimension size = simulatePanel_.getPreferredSize();
	hideBar_ = !hideBar_;
	if(hideBar_){
		//simulatePanel_.getHideBar_().setText("<");
		size.setSize(0, size.height < 800? 800: size.height);
	}
	else{
		//simulatePanel_.getHideBar_().setText(">");
		size.setSize(size.width+155, size.height < 800? 800: size.height);
	}
	setMinimumSize(new Dimension(size.width+50,400));
	editPanel_.setMinimumSize(new Dimension(size.width, size.height));
	//editPanel_.setSize(new Dimension(size.width, size.height));
	this.revalidate();
	this.repaint();
}
 
Example 7
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    double theta = Math.toRadians(15);
    double cos = Math.cos(theta);
    double sin = Math.sin(theta);
    double xsize = sin * h + cos * w;
    double ysize = sin * w + cos * h;
    double scale = Math.min(w / xsize, h / ysize);
    xsize *= scale;
    ysize *= scale;
    AffineTransform at = new AffineTransform();
    at.translate((w - xsize) / 2.0, (h - ysize) / 2.0);
    at.translate(sin * h * scale, 0.0);
    at.rotate(theta);
    g2d.transform(at);
    dim.setSize(scaleForTransform(at, dim));
}
 
Example 8
/**
 *  Calculate the width needed to display the maximum line number
 */
private void setPreferredWidth()
{
	Element root = component.getDocument().getDefaultRootElement();
	int lines = root.getElementCount();
	int digits = Math.max(String.valueOf(lines).length(), minimumDisplayDigits);

	//  Update sizes when number of digits in the line number changes

	if (lastDigits != digits)
	{
		lastDigits = digits;
		FontMetrics fontMetrics = getFontMetrics( getFont() );
		int width = fontMetrics.charWidth( '0' ) * digits;
		Insets insets = getInsets();
		int preferredWidth = insets.left + insets.right + width;

		Dimension d = getPreferredSize();
		d.setSize(preferredWidth, HEIGHT);
		setPreferredSize( d );
		setSize( d );
	}
}
 
Example 9
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.translate(0.0, (h - (w*h)/(w + h*0.1)) / 2);
    at.shear(0.1, 0.0);
    g2d.transform(at);
    dim.setSize(scaleForTransform(at, dim));
}
 
Example 10
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.scale(2.0, 2.0);
    g2d.transform(at);
    dim.setSize(w/2, h/2);
    ctx.pixscale = 4;
}
 
Example 11
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.translate(1.5, 1.5);
    g2d.transform(at);
    dim.setSize(w-3, h-3);
}
 
Example 12
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.translate(0.0, (h - (w*h)/(w + h*0.1)) / 2);
    at.shear(0.1, 0.0);
    g2d.transform(at);
    dim.setSize(scaleForTransform(at, dim));
}
 
Example 13
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.scale(2.0, 2.0);
    g2d.transform(at);
    dim.setSize(w/2, h/2);
    ctx.pixscale = 4;
}
 
Example 14
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.scale(2.0, 2.0);
    g2d.transform(at);
    dim.setSize(w/2, h/2);
    ctx.pixscale = 4;
}
 
Example 15
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.scale(2.0, 2.0);
    g2d.transform(at);
    dim.setSize(w/2, h/2);
    ctx.pixscale = 4;
}
 
Example 16
/**
 * Compute the source region and destination dimensions taking any
 * parameter settings into account.
 */
private static void computeRegions(Rectangle sourceBounds,
                                   Dimension destSize,
                                   ImageWriteParam p) {
    ImageWriteParam param;
    int periodX = 1;
    int periodY = 1;
    if (p != null) {
        int[] sourceBands = p.getSourceBands();
        if (sourceBands != null &&
            (sourceBands.length != 1 ||
             sourceBands[0] != 0)) {
            throw new IllegalArgumentException("Cannot sub-band image!");
        }

        // Get source region and subsampling factors
        Rectangle sourceRegion = p.getSourceRegion();
        if (sourceRegion != null) {
            // Clip to actual image bounds
            sourceRegion = sourceRegion.intersection(sourceBounds);
            sourceBounds.setBounds(sourceRegion);
        }

        // Adjust for subsampling offsets
        int gridX = p.getSubsamplingXOffset();
        int gridY = p.getSubsamplingYOffset();
        sourceBounds.x += gridX;
        sourceBounds.y += gridY;
        sourceBounds.width -= gridX;
        sourceBounds.height -= gridY;

        // Get subsampling factors
        periodX = p.getSourceXSubsampling();
        periodY = p.getSourceYSubsampling();
    }

    // Compute output dimensions
    destSize.setSize((sourceBounds.width + periodX - 1)/periodX,
                     (sourceBounds.height + periodY - 1)/periodY);
    if (destSize.width <= 0 || destSize.height <= 0) {
        throw new IllegalArgumentException("Empty source region!");
    }
}
 
Example 17
/**
 * Compute the source region and destination dimensions taking any
 * parameter settings into account.
 */
private static void computeRegions(Rectangle sourceBounds,
                                   Dimension destSize,
                                   ImageWriteParam p) {
    ImageWriteParam param;
    int periodX = 1;
    int periodY = 1;
    if (p != null) {
        int[] sourceBands = p.getSourceBands();
        if (sourceBands != null &&
            (sourceBands.length != 1 ||
             sourceBands[0] != 0)) {
            throw new IllegalArgumentException("Cannot sub-band image!");
        }

        // Get source region and subsampling factors
        Rectangle sourceRegion = p.getSourceRegion();
        if (sourceRegion != null) {
            // Clip to actual image bounds
            sourceRegion = sourceRegion.intersection(sourceBounds);
            sourceBounds.setBounds(sourceRegion);
        }

        // Adjust for subsampling offsets
        int gridX = p.getSubsamplingXOffset();
        int gridY = p.getSubsamplingYOffset();
        sourceBounds.x += gridX;
        sourceBounds.y += gridY;
        sourceBounds.width -= gridX;
        sourceBounds.height -= gridY;

        // Get subsampling factors
        periodX = p.getSourceXSubsampling();
        periodY = p.getSourceYSubsampling();
    }

    // Compute output dimensions
    destSize.setSize((sourceBounds.width + periodX - 1)/periodX,
                     (sourceBounds.height + periodY - 1)/periodY);
    if (destSize.width <= 0 || destSize.height <= 0) {
        throw new IllegalArgumentException("Empty source region!");
    }
}
 
Example 18
Source Project: JDKSourceCode1.8   File: GIFImageWriter.java    License: MIT License 4 votes vote down vote up
/**
 * Compute the source region and destination dimensions taking any
 * parameter settings into account.
 */
private static void computeRegions(Rectangle sourceBounds,
                                   Dimension destSize,
                                   ImageWriteParam p) {
    ImageWriteParam param;
    int periodX = 1;
    int periodY = 1;
    if (p != null) {
        int[] sourceBands = p.getSourceBands();
        if (sourceBands != null &&
            (sourceBands.length != 1 ||
             sourceBands[0] != 0)) {
            throw new IllegalArgumentException("Cannot sub-band image!");
        }

        // Get source region and subsampling factors
        Rectangle sourceRegion = p.getSourceRegion();
        if (sourceRegion != null) {
            // Clip to actual image bounds
            sourceRegion = sourceRegion.intersection(sourceBounds);
            sourceBounds.setBounds(sourceRegion);
        }

        // Adjust for subsampling offsets
        int gridX = p.getSubsamplingXOffset();
        int gridY = p.getSubsamplingYOffset();
        sourceBounds.x += gridX;
        sourceBounds.y += gridY;
        sourceBounds.width -= gridX;
        sourceBounds.height -= gridY;

        // Get subsampling factors
        periodX = p.getSourceXSubsampling();
        periodY = p.getSourceYSubsampling();
    }

    // Compute output dimensions
    destSize.setSize((sourceBounds.width + periodX - 1)/periodX,
                     (sourceBounds.height + periodY - 1)/periodY);
    if (destSize.width <= 0 || destSize.height <= 0) {
        throw new IllegalArgumentException("Empty source region!");
    }
}
 
Example 19
Source Project: azure-devops-intellij   File: SwingHelper.java    License: MIT License 4 votes vote down vote up
public static void setPreferredHeight(final JComponent component, final int height) {
    final Dimension size = component.getPreferredSize();
    size.setSize(size.getWidth(), JBUI.scale(height));
    component.setPreferredSize(size);
}
 
Example 20
@Override
public Dimension getPreferredSize() {
	Dimension prefSize = super.getPreferredSize();
	prefSize.setSize(prefSize.getWidth() + 75, prefSize.getHeight() + 20);
	return prefSize;
}