Example usage for java.awt Dimension getWidth

List of usage examples for java.awt Dimension getWidth

Introduction

In this page you can find the example usage for java.awt Dimension getWidth.

Prototype

public double getWidth() 

Source Link

Usage

From source file:org.nekorp.workflow.desktop.servicio.imp.ImageServiceImp.java

public static Dimension getScaledDimension(Dimension imgDimension, Dimension boundary) {
    double width;
    double height;
    if (imgDimension.getWidth() > boundary.getWidth()) {
        width = boundary.getWidth();// w w  w.  jav a  2  s. com
        height = (width * imgDimension.getHeight()) / imgDimension.getWidth();
        if (!(height > boundary.getHeight())) {
            return new Dimension((int) width, (int) height);
        }
    }
    if (imgDimension.getHeight() > boundary.getHeight()) {
        height = boundary.getHeight();
        width = (height * imgDimension.getWidth()) / imgDimension.getHeight();
        return new Dimension((int) width, (int) height);
    }
    return new Dimension((int) imgDimension.getWidth(), (int) imgDimension.getHeight());
}

From source file:org.swiftexplorer.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);//from  w  w  w  .j av a2  s  . c  o  m
    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);
}

From source file:org.fao.geonet.services.region.GetMap.java

public static AffineTransform worldToScreenTransform(Envelope mapExtent, Dimension screenSize) {
    double scaleX = screenSize.getWidth() / mapExtent.getWidth();
    double scaleY = screenSize.getHeight() / mapExtent.getHeight();

    double tx = -mapExtent.getMinX() * scaleX;
    double ty = (mapExtent.getMinY() * scaleY) + screenSize.getHeight();

    AffineTransform at = new AffineTransform(scaleX, 0.0d, 0.0d, -scaleY, tx, ty);

    return at;//from   w  w  w .j  a  v  a  2 s  .c  o m
}

From source file:se.trixon.almond.GraphicsHelper.java

public static Image scaleImage(Image image, Dimension dimension) {
    Image newImage;/*from w ww  .  j a v  a  2 s .c  o m*/
    int height = image.getHeight(null);
    int width = image.getWidth(null);

    if (width > height) {
        newImage = image.getScaledInstance((int) dimension.getWidth(),
                (int) (dimension.getWidth() * height) / width, Image.SCALE_SMOOTH);
    } else {
        newImage = image.getScaledInstance((int) (dimension.getWidth() * width) / height,
                (int) dimension.getWidth(), Image.SCALE_SMOOTH);
    }

    return newImage;
}

From source file:com.clank.launcher.swing.SwingHelper.java

/**
 * Equalize the width of the given components.
 *
 * @param component component//from  w ww.  ja  v a 2  s. co  m
 */
public static void equalWidth(Component... component) {
    double widest = 0;
    for (Component comp : component) {
        Dimension dim = comp.getPreferredSize();
        if (dim.getWidth() > widest) {
            widest = dim.getWidth();
        }
    }

    for (Component comp : component) {
        Dimension dim = comp.getPreferredSize();
        comp.setPreferredSize(new Dimension((int) widest, (int) dim.getHeight()));
    }
}

From source file:org.processmining.analysis.performance.fsmevaluator.FSMEvaluationMenuUI.java

protected static JPanel packHorizontallyLeftAligned(Component[] components, int leftOffset) {
    JPanel packed = new JPanel();
    packed.setOpaque(false);//from w  ww . jav  a 2s. c o  m
    packed.setLayout(new BoxLayout(packed, BoxLayout.X_AXIS));
    if (leftOffset > 0) {
        packed.add(Box.createHorizontalStrut(leftOffset));
    }
    int minW = 0, minH = 0;
    for (Component comp : components) {
        packed.add(comp);
        Dimension dim = comp.getMinimumSize();
        minW += dim.getWidth();
        minH = Math.max(minH, (int) dim.getHeight());
    }
    packed.add(Box.createHorizontalGlue());
    packed.setMinimumSize(new Dimension(minW, minH));
    packed.setMaximumSize(new Dimension(4000, minH));
    packed.setPreferredSize(new Dimension(4000, minH));
    return packed;
}

From source file:ro.nextreports.designer.util.ImageUtil.java

public static void drawImage(String imageName, boolean withShadow, Graphics2D g2, int x, int y) {
    BufferedImage img = toBufferedImage(getImage(imageName));
    g2.drawImage(img, null, x, y);/*from  w w w.j  a v a 2 s.  c o m*/
    if (withShadow) {
        BufferedImage shadow = createDropShadow(img);
        if (shadow != null) {
            Dimension d = ImageUtil.computeShadowPosition(30, 5);
            g2.drawImage(shadow, x + (int) d.getWidth(), y + (int) d.getHeight(), null);
        }
    }

}

From source file:Main.java

/**
 * Zentriert ein Window relativ zu dem Parent-Window
 * /*from  w  ww  . j  a  v  a2  s.  c om*/
 * @param parent
 *            Parent-Window, wenn null, dann wird relativ zu dem Bildschirm
 *            zentriert
 * @param child
 *            Window das zentrirt werden soll.
 */
static public void centreWindow(Window parent, Window child) {
    if (child == null)
        return;
    Point parentLocation = null;
    Dimension parentSize = null;
    if (parent == null) {
        parentLocation = new Point(0, 0);
        parentSize = child.getToolkit().getScreenSize();
    } else {
        parentLocation = parent.getLocationOnScreen();
        parentSize = parent.getSize();
    }
    Dimension childSize = child.getSize();
    child.setLocation((int) (parentLocation.getX() + parentSize.getWidth() / 2 - childSize.getWidth() / 2),
            (int) (parentLocation.getY() + parentSize.getHeight() / 2 - childSize.getHeight() / 2));
}

From source file:org.xsystem.sql2.http.impl.ImgHelper.java

public static void resaize(String format, int IMG_SIZE, InputStream sorce, OutputStream target)
        throws IOException {
    BufferedImage originalImage = ImageIO.read(sorce);
    int type = format.equalsIgnoreCase("gif") || (originalImage.getType() == 0) ? BufferedImage.TYPE_INT_ARGB
            : originalImage.getType();//  w w w  . j  a  va 2s.c  o m
    Dimension new_dim = //new Dimension(IMG_SIZE, IMG_SIZE);
            getScaledDimension(new Dimension(originalImage.getWidth(), originalImage.getHeight()),
                    new Dimension(IMG_SIZE, IMG_SIZE));
    BufferedImage resizedImage = new BufferedImage((int) new_dim.getWidth(), (int) new_dim.getHeight(), type);
    Graphics2D g2 = resizedImage.createGraphics();
    g2.drawImage(originalImage, 0, 0, (int) new_dim.getWidth(), (int) new_dim.getHeight(), null);
    g2.dispose();
    ImageIO.write(resizedImage, format, target);
}

From source file:be.fedict.eid.applet.maven.DocbookMojo.java

private static void graphToFile(BasicVisualizationServer<String, String> visualization, File file)
        throws IOException {
    Dimension size = visualization.getSize();
    int width = (int) (size.getWidth() + 1);
    int height = (int) (size.getHeight() + 1);
    BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = bufferedImage.createGraphics();
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics.setColor(Color.WHITE);
    graphics.fillRect(0, 0, 900, 650);/*from  w w w  .ja v  a 2 s.  c  o m*/
    visualization.setBounds(0, 0, 900, 650);
    visualization.paint(graphics);
    graphics.dispose();
    ImageIO.write(bufferedImage, "png", file);
}