Example usage for java.awt Dimension getHeight

List of usage examples for java.awt Dimension getHeight

Introduction

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

Prototype

public double getHeight() 

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.
 *//*ww w  .  j  a va2 s .com*/
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:PaintSample.java

/**
 * Fills the component with the current Paint.
 *
 * @param g  the graphics device.//from ww  w.  ja va2 s.c  o  m
 */
public void paintComponent(final Graphics g) {

    final Graphics2D g2 = (Graphics2D) g;
    final Dimension size = getSize();
    final Insets insets = getInsets();
    final double xx = insets.left;
    final double yy = insets.top;
    final double ww = size.getWidth() - insets.left - insets.right - 1;
    final double hh = size.getHeight() - insets.top - insets.bottom - 1;
    final Rectangle2D area = new Rectangle2D.Double(xx, yy, ww, hh);
    g2.setPaint(this.paint);
    g2.fill(area);
    g2.setPaint(Color.black);
    g2.draw(area);

}

From source file:GUI.ResponseStatistics.java

/** * Creates a sample dataset */

private void InitPieChart(JFreeChart chart) {
    ChartPanel chartPanel = new ChartPanel(chart);
    // default size
    chartPanel.setSize(560, 800);//from   w w  w.  j  a  v  a2 s . c  o m

    Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (int) ((dimension.getWidth() - chartPanel.getWidth()) / 2);
    int y = (int) ((dimension.getHeight() - chartPanel.getHeight()) / 2);

    chartPanel.setLocation(WIDTH, WIDTH);
    // add it to our application
    setContentPane(chartPanel);

    chartPanel.addChartMouseListener(new ChartMouseListener() {

        public void chartMouseClicked(ChartMouseEvent e) {

            wait = false;

        }

        public void chartMouseMoved(ChartMouseEvent e) {
        }

    });
}

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 w  w.  ja  v a2  s. co  m*/
        //            JTLogin.setText(CN.getPropriedades().getProperty("usuario"));
    } catch (NullPointerException e) {

    }
}

From source file:org.hyperic.hq.ui.taglib.NavMapTag.java

private ResourceTree _getResourceTree(AppdefEntityID[] eids, Integer ctype, int imageWidth)
        throws ServletException, SessionNotFoundException, SessionTimeoutException,
        AppdefEntityNotFoundException, PermissionException, RemoteException {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    ServletContext ctx = pageContext.getServletContext();
    int sessionId = RequestUtils.getSessionId(request).intValue();
    AppdefBoss ab = Bootstrap.getBean(AppdefBoss.class);
    ResourceTree tree = new ResourceTree(imageWidth);
    ResourceTreeNode[] data = null;// www .  j av  a  2s.c  o m

    if (null == ctype) {
        data = ab.getNavMapData(sessionId, eids[0]);
    } else {
        data = ab.getNavMapData(sessionId, eids, ctype.intValue());
    }

    if (data != null) {
        tree.addLevel(data);
    }

    // We must call getImage() here because it initializes the
    // tree such that the coordinates for the nodes can be
    // computed. A NullPointerException will result if getImage()
    // has not been called before calculateCoordinates().
    tree.getImage();
    tree.calculateCoordinates();

    // Ask the tree for the image dimensions and check them against
    // the max width and height parameters. If we're not within range
    // then auto-group any promotable nodes.
    Dimension dim = tree.getImageSize();

    if (dim.getHeight() > MAX_HEIGHT) {
        tree = new ResourceTree(imageWidth);
        ResourceTreeNode.autoGroupData(data);
        tree.addLevel(data);
        tree.getImage();
        tree.calculateCoordinates();
    }

    return tree;
}

From source file:Main.java

public void componentMoved(ComponentEvent evt) {
    Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
    int x = evt.getComponent().getX();
    int y = evt.getComponent().getY();
    if (y < 0) {
        y = 0;//from www .  java2 s  . c o  m
    }
    if (x < 0) {
        x = 0;
    }
    if (x > size.getWidth() - evt.getComponent().getWidth()) {
        x = (int) size.getWidth() - evt.getComponent().getWidth();
    }
    if (y > size.getHeight() - evt.getComponent().getHeight()) {
        y = (int) size.getHeight() - evt.getComponent().getHeight();
    }
    evt.getComponent().setLocation(x, y);
}

From source file:org.neo4j.bench.chart.GenerateOpsPerSecChart.java

private void generateChart() throws Exception {
    DefaultCategoryDataset dataset = generateDataset();
    JFreeChart chart = ChartFactory.createBarChart("Performance chart", "Bench case", "Operations per sec",
            dataset, PlotOrientation.VERTICAL, true, true, false);

    Dimension dimensions = new Dimension(1600, 900);
    File chartFile = new File(outputFilename);
    if (alarm) {/*from  www .  jav a2  s .c  om*/
        chart.setBackgroundPaint(Color.RED);
    }
    ChartUtilities.saveChartAsPNG(chartFile, chart, (int) dimensions.getWidth(), (int) dimensions.getHeight());
}

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

/**
 * Paints the panel./*from www  . j  a  va2s .c o m*/
 *
 * @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:net.lmxm.ute.gui.validation.AbstractInputValidator.java

/**
 * Display messages dialog.//w ww . ja v a 2s .  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:fedora.client.Uploader.java

/**
 * Send a file to the server, getting back the identifier.
 *///from   w  w  w.j  a  va 2s . c om
public String upload(File file) throws IOException {
    if (Administrator.INSTANCE == null) {
        return fc.uploadFile(file);
    } else {
        // paint initial status to the progress bar
        String msg = "Uploading " + file.length() + " bytes to " + fc.getUploadURL();
        Dimension d = Administrator.PROGRESS.getSize();
        Administrator.PROGRESS.setString(msg);
        Administrator.PROGRESS.setValue(100);
        Administrator.PROGRESS.paintImmediately(0, 0, (int) d.getWidth() - 1, (int) d.getHeight() - 1);

        // then start the thread, passing parms in
        HashMap<String, Object> PARMS = new HashMap<String, Object>();
        PARMS.put("fc", fc);
        PARMS.put("file", file);
        SwingWorker worker = new SwingWorker(PARMS) {

            @Override
            public Object construct() {
                try {
                    FedoraClient fc = (FedoraClient) parms.get("fc");
                    File file = (File) parms.get("file");
                    return fc.uploadFile(file);
                } catch (IOException e) {
                    thrownException = e;
                    return "";
                }
            }
        };
        worker.start();

        // keep updating status till the worker's finished
        int ms = 200;
        while (!worker.done) {
            try {
                Administrator.PROGRESS.setValue(ms);
                Administrator.PROGRESS.paintImmediately(0, 0, (int) d.getWidth() - 1, (int) d.getHeight() - 1);
                Thread.sleep(100);
                ms = ms + 100;
                if (ms >= 2000) {
                    ms = 200;
                }
            } catch (InterruptedException ie) {
            }
        }

        // reset the status bar to normal
        Administrator.PROGRESS.setValue(2000);
        Administrator.PROGRESS.paintImmediately(0, 0, (int) d.getWidth() - 1, (int) d.getHeight() - 1);
        try {
            Thread.sleep(100);
        } catch (InterruptedException ie) {
        }

        // report if there was an error; otherwise return the response
        if (worker.thrownException != null) {
            throw (IOException) worker.thrownException;
        } else {
            return (String) worker.getValue();
        }

    }
}