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:MWC.GUI.JFreeChart.StepperChartPanel.java

/**
 * Paints the component by drawing the chart to fill the entire component,
 * but allowing for the insets (which will be non-zero if a border has been
 * set for this component).  To increase performance (at the expense of
 * memory), an off-screen buffer image can be used.
 *
 * @param g  the graphics device for drawing on.
 *///w  w w .j  a  va2  s.  c o m
public void paintWMFComponent(final Graphics g) {

    final Graphics2D g2 = (Graphics2D) g;

    // first determine the size of the chart rendering area...
    final Dimension size = getSize();
    final Insets insets = getInsets();
    available.setRect(insets.left, insets.top, size.getWidth() - insets.left - insets.right,
            size.getHeight() - insets.top - insets.bottom);

    // work out if scaling is required...
    boolean scale = false;
    double drawWidth = available.getWidth();
    double drawHeight = available.getHeight();
    double scaleX = 1.0;
    double scaleY = 1.0;

    if (drawWidth < this.getMinimumDrawWidth()) {
        scaleX = drawWidth / getMinimumDrawWidth();
        drawWidth = getMinimumDrawWidth();
        scale = true;
    } else if (drawWidth > this.getMaximumDrawWidth()) {
        scaleX = drawWidth / getMaximumDrawWidth();
        drawWidth = getMaximumDrawWidth();
        scale = true;
    }

    if (drawHeight < this.getMinimumDrawHeight()) {
        scaleY = drawHeight / getMinimumDrawHeight();
        drawHeight = getMinimumDrawHeight();
        scale = true;
    } else if (drawHeight > this.getMaximumDrawHeight()) {
        scaleY = drawHeight / getMaximumDrawHeight();
        drawHeight = getMaximumDrawHeight();
        scale = true;
    }

    chartArea.setRect(0.0, 0.0, drawWidth, drawHeight);

    final AffineTransform saved = g2.getTransform();
    g2.translate(insets.left, insets.right);
    if (scale) {
        final AffineTransform st = AffineTransform.getScaleInstance(scaleX, scaleY);
        g2.transform(st);
    }
    getChart().draw(g2, chartArea, this.getChartRenderingInfo());
    g2.setTransform(saved);

}

From source file:org.jfree.demo.TextBlockPanel.java

/**
 * Paints the panel.//from  w  w  w.j a va2  s.  c  om
 *
 * @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);

}

From source file:tk.egsf.ddns.login.java

private void inicializar() {
    Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();

    int x = (int) ((dimension.getWidth() - this.getWidth()) / 2);
    int y = (int) ((dimension.getHeight() - this.getHeight()) / 2);

    this.setLocation(x, y);

    try {//from  w ww  . j a  v  a 2  s  . c o  m
        //            JTLogin.setText(CN.getPropriedades().getProperty("usuario"));
    } catch (NullPointerException e) {

    }
}

From source file:test.be.fedict.eid.applet.JGraphTest.java

private 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);
    LOG.debug("width: " + width);
    LOG.debug("height: " + height);
    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 .  j  a  va2 s  . co m*/
    visualization.setBounds(0, 0, 900, 650);
    visualization.paint(graphics);
    graphics.dispose();
    ImageIO.write(bufferedImage, "png", file);
}

From source file:org.ajax4jsf.resource.AnimationResource.java

public void send(ResourceContext context) throws IOException {
    try {// w  ww.j av  a 2  s.c  o  m
        DataOutputStream output = new DataOutputStream(context.getOutputStream());
        Dimension frameSize = getFrameSize(context);
        int numberOfFrames = getNumberOfFrames();
        BufferedImage frame = null;
        currFrameIndex = 0;
        if (frameSize.getHeight() > 0.0 && frameSize.getWidth() > 0.0 && numberOfFrames > 0) {
            AnimatedGifEncoder encoder = new AnimatedGifEncoder();
            encoder.start(output);
            encoder.setRepeat(getRepeat());
            int[] delays = getFrameDelays();
            ImageRenderer renderer = (ImageRenderer) getRenderer(null);
            while (currFrameIndex < numberOfFrames) {
                frame = renderer.createImage(frameSize.width, frameSize.height);
                Graphics2D graphics = frame.createGraphics();
                paint(context, graphics, currFrameIndex++);
                graphics.dispose();
                encoder.addFrame(frame);
                if (delays != null && delays.length > currFrameIndex) {
                    encoder.setDelay(delays[currFrameIndex]);
                }
            }
            encoder.finish();
        }
        output.flush();
        output.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:Main.java

public void componentMoved(ComponentEvent evt) {
    if (locked)//  w  w  w. ja va  2  s  .  c  om
        return;
    Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
    int nx = evt.getComponent().getX();
    int ny = evt.getComponent().getY();
    // top
    if (ny < 0 + sd) {
        ny = 0;
    }
    // left
    if (nx < 0 + sd) {
        nx = 0;
    }
    // right
    if (nx > size.getWidth() - evt.getComponent().getWidth() - sd) {
        nx = (int) size.getWidth() - evt.getComponent().getWidth();
    }
    // bottom
    if (ny > size.getHeight() - evt.getComponent().getHeight() - sd) {
        ny = (int) size.getHeight() - evt.getComponent().getHeight();
    }
    locked = true;
    evt.getComponent().setLocation(nx, ny);
    locked = false;
}

From source file:net.lmxm.ute.gui.validation.AbstractInputValidator.java

/**
 * Display messages dialog./*from  w w  w. j  ava 2  s  .c  o  m*/
 * 
 * @param component the component
 * @param messages the messages
 */
private void displayMessagesDialog(final JComponent component, final List<String> messages) {
    final JDialog dialog = getMessagesDialog();

    // Load dialog with messages.
    getMessagesLabel().setText(StringUtils.join(messages, "\n"));

    // Relocate dialog relative to the input component
    dialog.setSize(0, 0);
    dialog.setLocationRelativeTo(component);
    final Point location = dialog.getLocation();
    final Dimension componentSize = component.getSize();
    dialog.setLocation(location.x - (int) componentSize.getWidth() / 2,
            location.y + (int) componentSize.getHeight() / 2);
    dialog.pack();
    dialog.setVisible(true);
}

From source file:ddf.catalog.transformer.input.pptx.PptxInputTransformer.java

/**
 * If the slide show doesn't contain any slides, then return null. Otherwise, return jpeg
 * image data of the first slide in the deck.
 *
 * @param slideShow//w  w  w.j a  va  2  s .  c  o  m
 * @return jpeg thumbnail or null if thumbnail can't be created
 * @throws IOException
 */
private byte[] generatePptxThumbnail(XMLSlideShow slideShow) throws IOException {

    if (slideShow.getSlides().isEmpty()) {
        LOGGER.info("the powerpoint file does not contain any slides, skipping thumbnail generation");
        return null;
    }

    Dimension pgsize = slideShow.getPageSize();

    int largestDimension = (int) Math.max(pgsize.getHeight(), pgsize.getWidth());
    float scalingFactor = IMAGE_HEIGHTWIDTH / largestDimension;
    int scaledHeight = (int) (pgsize.getHeight() * scalingFactor);
    int scaledWidth = (int) (pgsize.getWidth() * scalingFactor);
    BufferedImage img = new BufferedImage(scaledWidth, scaledHeight, BufferedImage.TYPE_INT_RGB);

    Graphics2D graphics = img.createGraphics();

    try {
        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                RenderingHints.VALUE_FRACTIONALMETRICS_ON);

        graphics.scale(scalingFactor, scalingFactor);

        slideShow.getSlides().get(0).draw(graphics);

        try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
            ImageIOUtil.writeImage(img, FORMAT_NAME, outputStream, RESOLUTION_DPI, IMAGE_QUALITY);
            return outputStream.toByteArray();
        }
    } catch (RuntimeException e) {
        if (e.getCause() instanceof javax.imageio.IIOException) {
            LOGGER.warn("unable to generate thumbnail for PPTX file", e);
        } else {
            throw e;
        }
    } finally {
        graphics.dispose();
    }

    return null;
}

From source file:org.jfree.demo.DrawStringPanel.java

/**
 * Paints the panel./*  w w w.j  av  a2s. com*/
 *
 * @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.getCenterX();
    final double y = available.getCenterY();

    final Line2D line1 = new Line2D.Double(x - 2.0, y + 2.0, x + 2.0, y - 2.0);
    final Line2D line2 = new Line2D.Double(x - 2.0, y - 2.0, x + 2.0, y + 2.0);
    g2.setPaint(Color.red);
    g2.draw(line1);
    g2.draw(line2);

    g2.setFont(this.font);
    g2.setPaint(Color.black);
    if (this.rotate) {
        TextUtilities.drawRotatedString(this.text, g2, (float) x, (float) y, this.anchor, this.angle,
                this.rotationAnchor);
    } else {
        TextUtilities.drawAlignedString(this.text, g2, (float) x, (float) y, this.anchor);
    }

}

From source file:com.projity.pm.graphic.chart.TimeChartPanel.java

public void updateTimeScaleComponentSize() {
    Dimension dmain = viewport.getViewSize();

    if (dmain.equals(olddmain))
        return;/*w w w  .j a  va  2s. c o m*/
    olddmain = dmain;
    Dimension d = chartInfo.getAxisPanel().getPreferredSize();
    d.setSize(d.getWidth(), dmain.getHeight());
    chartInfo.getAxisPanel().revalidate();
}