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:org.neo4j.bench.chart.AbstractJFreeChart.java

public void open(Reader input, Args options) throws IOException {
    final T dataset = instantiateDataset();
    ResultHandler handler = new ResultHandler() {
        public void newResult(Map<String, String> header) {
        }//  w ww.  j  a  va2s  .  c  o m

        public void value(Map<String, String> header, double value, int numberOfIterations, String benchCase,
                String timer) {
            addValue(dataset, header, (int) value, numberOfIterations, benchCase, timer);
        }

        public void endResult() {
        }
    };

    Map<String, Collection<String>> aggregations = RunUtil.loadAggregations(options);
    if (aggregations != null) {
        handler = new AggregatedResultHandler(handler, aggregations);
    }

    ResultParser parser = new ResultParser(handler);
    parser.parse(input, options);

    JFreeChart chart = createChart(dataset);
    ChartPanel chartPanel = new ChartPanel(chart);
    Dimension dimensions = getDimensions();
    chartPanel.setPreferredSize(dimensions);
    File chartFile = new File(
            "chart-" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + ".jpg");
    ChartUtilities.saveChartAsJPEG(chartFile, chart, (int) dimensions.getWidth(), (int) dimensions.getHeight());
}

From source file:pt.lsts.neptus.plugins.wg.WgCtdLayer.java

private boolean isVisibleInRender(Point2D sPos, StateRenderer2D renderer) {
    Dimension rendDim = renderer.getSize();
    if (sPos.getX() < 0 && sPos.getY() < 0)
        return false;
    else if (sPos.getX() > rendDim.getWidth() && sPos.getY() > rendDim.getHeight())
        return false;

    return true;/* w  ww .j a va  2  s  . c  o m*/
}

From source file:org.photovault.swingui.tag.TagEditor2.java

/**
 * Show the autocomplete popup menu/*from ww  w  .  j  ava2 s  .  co m*/
 */
private void showPopup() {
    log.debug("showPopup()");
    if (nameField.isShowing()) {
        if (popup != null) {
            hidePopup();
        }
        popup = new JPopupMenu();
        popup.setFocusable(false);
        popup.add(suggestionList);
        suggestionList.setPreferredSize(null);
        Dimension prefSize = suggestionList.getPreferredSize();
        System.err.println("popup pref height" + prefSize.getHeight());
        prefSize = new Dimension(nameField.getWidth(), prefSize.height);
        suggestionList.setPreferredSize(prefSize);
        popup.show(nameField, 0, nameField.getHeight());
    }
}

From source file:org.optaplanner.examples.tsp.swingui.TspWorldPanel.java

public void resetPanel(TravelingSalesmanTour travelingSalesmanTour) {
    translator = new LatitudeLongitudeTranslator();
    for (Location location : travelingSalesmanTour.getLocationList()) {
        translator.addCoordinates(location.getLatitude(), location.getLongitude());
    }/*  w  w w .  j  a v a 2s.c o m*/

    Dimension size = getSize();
    double width = size.getWidth();
    double height = size.getHeight();
    translator.prepareFor(width, height);

    Graphics2D g = createCanvas(width, height);
    String tourName = travelingSalesmanTour.getName();
    if (tourName.startsWith("europe")) {
        g.drawImage(europaBackground.getImage(), 0, 0, translator.getImageWidth(), translator.getImageHeight(),
                this);
    }
    g.setFont(g.getFont().deriveFont((float) LOCATION_NAME_TEXT_SIZE));
    g.setColor(TangoColorFactory.PLUM_2);
    List<Visit> visitList = travelingSalesmanTour.getVisitList();
    for (Visit visit : visitList) {
        Location location = visit.getLocation();
        int x = translator.translateLongitudeToX(location.getLongitude());
        int y = translator.translateLatitudeToY(location.getLatitude());
        g.fillRect(x - 1, y - 1, 3, 3);
        if (location.getName() != null && visitList.size() <= 500) {
            g.drawString(StringUtils.abbreviate(location.getName(), 20), x + 3, y - 3);
        }
    }
    g.setColor(TangoColorFactory.ALUMINIUM_4);
    Domicile domicile = travelingSalesmanTour.getDomicile();
    Location domicileLocation = domicile.getLocation();
    int domicileX = translator.translateLongitudeToX(domicileLocation.getLongitude());
    int domicileY = translator.translateLatitudeToY(domicileLocation.getLatitude());
    g.fillRect(domicileX - 2, domicileY - 2, 5, 5);
    if (domicileLocation.getName() != null && visitList.size() <= 500) {
        g.drawString(domicileLocation.getName(), domicileX + 3, domicileY - 3);
    }
    Set<Visit> needsBackToDomicileLineSet = new HashSet<Visit>(visitList);
    for (Visit trailingVisit : visitList) {
        if (trailingVisit.getPreviousStandstill() instanceof Visit) {
            needsBackToDomicileLineSet.remove(trailingVisit.getPreviousStandstill());
        }
    }
    g.setColor(TangoColorFactory.CHOCOLATE_1);
    for (Visit visit : visitList) {
        if (visit.getPreviousStandstill() != null) {
            Location previousLocation = visit.getPreviousStandstill().getLocation();
            Location location = visit.getLocation();
            translator.drawRoute(g, previousLocation.getLongitude(), previousLocation.getLatitude(),
                    location.getLongitude(), location.getLatitude(), location instanceof AirLocation, false);
            // Back to domicile line
            if (needsBackToDomicileLineSet.contains(visit)) {
                translator.drawRoute(g, location.getLongitude(), location.getLatitude(),
                        domicileLocation.getLongitude(), domicileLocation.getLatitude(),
                        location instanceof AirLocation, true);
            }
        }
    }
    // Drag
    if (dragSourceStandstill != null) {
        g.setColor(TangoColorFactory.CHOCOLATE_2);
        Location sourceLocation = dragSourceStandstill.getLocation();
        Location targetLocation = dragTargetStandstill.getLocation();
        translator.drawRoute(g, sourceLocation.getLongitude(), sourceLocation.getLatitude(),
                targetLocation.getLongitude(), targetLocation.getLatitude(),
                sourceLocation instanceof AirLocation, dragTargetStandstill instanceof Domicile);
    }
    // Legend
    g.setColor(TangoColorFactory.ALUMINIUM_4);
    g.fillRect(5, (int) height - 15 - TEXT_SIZE, 5, 5);
    g.drawString("Domicile", 15, (int) height - 10 - TEXT_SIZE);
    g.setColor(TangoColorFactory.PLUM_2);
    g.fillRect(6, (int) height - 9, 3, 3);
    g.drawString("Visit", 15, (int) height - 5);
    g.setColor(TangoColorFactory.ALUMINIUM_5);
    String locationsSizeString = travelingSalesmanTour.getLocationList().size() + " locations";
    g.drawString(locationsSizeString, ((int) width - g.getFontMetrics().stringWidth(locationsSizeString)) / 2,
            (int) height - 5);
    if (travelingSalesmanTour.getDistanceType() == DistanceType.AIR_DISTANCE) {
        String leftClickString = "Left click and drag between 2 locations to connect them.";
        g.drawString(leftClickString, (int) width - 5 - g.getFontMetrics().stringWidth(leftClickString),
                (int) height - 10 - TEXT_SIZE);
        String rightClickString = "Right click anywhere on the map to add a visit.";
        g.drawString(rightClickString, (int) width - 5 - g.getFontMetrics().stringWidth(rightClickString),
                (int) height - 5);
    }
    // Show soft score
    g.setColor(TangoColorFactory.ORANGE_3);
    SimpleLongScore score = travelingSalesmanTour.getScore();
    if (score != null) {
        String distanceString = travelingSalesmanTour.getDistanceString(NUMBER_FORMAT);
        g.setFont(g.getFont().deriveFont(Font.BOLD, (float) TEXT_SIZE * 2));
        g.drawString(distanceString, (int) width - g.getFontMetrics().stringWidth(distanceString) - 10,
                (int) height - 15 - 2 * TEXT_SIZE);
    }
    repaint();
}

From source file:com.projity.pm.graphic.network.rendering.FormComponent.java

public void paint(Graphics g) {
    /*CommonGraphCell cell=(CommonGraphCell)view.getCell();
    if (cell.getNode().isVoid()) return;*/

    Graphics2D g2 = (Graphics2D) g;
    Dimension d = getSize();
    double w = d.getWidth();
    double h = d.getHeight();

    paintSelectedBars(g2, w - 1, h - 1);
    //      ImageIcon link=IconManager.getIcon("common.link.image");
    //      g2.drawImage(link.getImage(),(int)(w-link.getIconWidth()),(int)(h-link.getIconHeight()),this);
    //x=w and y=h are outside

    try {/*  w  w w  .  jav a  2 s . c  om*/
        //if (preview && !isDoubleBuffered)
        //   setOpaque(false);
        super.paint(g);
        //paintSelectionBorder(g);
    } catch (IllegalArgumentException e) {
        // JDK Bug: Zero length string passed to TextLayout constructor
    }
}

From source file:edu.purdue.cc.bionet.ui.layout.MultipleCirclesLayout.java

/**
 * Sets the initial position of the Graph nodes.
 *//* w ww  .  j av  a2  s  . c  om*/
public void initialize() {
    if (this.sampleGroups != null) {
        Dimension d = this.getSize();
        List<List<V>> moleculeGroups = new ArrayList<List<V>>();
        for (int i = 0; i < 3; i++) {
            moleculeGroups.add(new ArrayList<V>());
        }
        if (d != null) {
            double height = d.getHeight();
            double width = d.getWidth();

            String groupName;
            for (V v : this.getGraph().getVertices()) {
                if (this.isUpRegulated(sampleGroups, v))
                    moleculeGroups.get(1).add(v);
                else if (this.isDownRegulated(sampleGroups, v))
                    moleculeGroups.get(2).add(v);
                else
                    moleculeGroups.get(0).add(v);
            }

            this.radius = (Math.min(height, width)) * 0.3;
            int groupRadius = (int) (this.radius / Math.sqrt(moleculeGroups.size()));

            int j = 0, x, y;
            Point2D.Double graphCenter = new Point2D.Double(width / 2.0, height / 2.0);
            PolarPoint2D center = new PolarPoint2D(0, 0, graphCenter);
            PolarPoint2D coord = new PolarPoint2D(0, 0, center);
            double theta;

            for (List<V> group : moleculeGroups) {
                theta = (2 * Math.PI * j) / moleculeGroups.size();
                j++;
                center.setLocation(this.radius, theta, PolarPoint2D.POLAR);
                int i = 0;
                for (V vertex : group) {
                    theta = (2 * Math.PI * i) / group.size();
                    coord.setLocation(groupRadius, theta, PolarPoint2D.POLAR);
                    this.setLocation(vertex, coord);
                    i++;
                }
            }
        }
    }
}

From source file:org.richfaces.component.InputNumberSpinnerComponentTest.java

public void testImages() throws Exception {
    InternetResource image = InternetResourceBuilder.getInstance().createResource(null,
            SpinnerFieldGradient.class.getName());
    Dimension imageDim = ((Java2Dresource) image).getDimensions(facesContext, null);
    assertTrue(imageDim.getWidth() == 30 && imageDim.getHeight() == 50);

    image = InternetResourceBuilder.getInstance().createResource(null, SpinnerButtonGradient.class.getName());
    imageDim = ((Java2Dresource) image).getDimensions(facesContext, null);
    assertTrue(imageDim.getWidth() == 30 && imageDim.getHeight() == 50);

    image = InternetResourceBuilder.getInstance().createResource(null, SpinnerButtonDown.class.getName());
    imageDim = ((Java2Dresource) image).getDimensions(facesContext, null);
    assertTrue(imageDim.getWidth() == 14 && imageDim.getHeight() == 7);

    image = InternetResourceBuilder.getInstance().createResource(null, SpinnerButtonUp.class.getName());
    imageDim = ((Java2Dresource) image).getDimensions(facesContext, null);
    assertTrue(imageDim.getWidth() == 14 && imageDim.getHeight() == 7);
}

From source file:util.NewStreamBlobUtil.java

/**
* Returns scaled blob//from  w  ww  .j av  a2 s  . com
* @param b byte stream
* @param type that is "jpeg", "gif", "png"
* @param width width of the image
* @param height height of the image
* @param scale boolean yes or no
* @return scaled byte stream
*/
public synchronized byte[] streamBlob(byte[] b, int width, int height, boolean doIScale)
        throws BasicObjException {

    if (b == null) {
        return null;
    }
    try {
        initializeImageInfo();
        ImgMetadata scaled = null;
        if (doIScale) {
            // scale the image
            InputStream imageInputStream = new ByteArrayInputStream(b);
            // read in the original image from an input stream
            SeekableStream seekableImageStream = SeekableStream.wrapInputStream(imageInputStream, true);
            RenderedOp originalImage = JAI.create(JAI_STREAM_ACTION, seekableImageStream);
            //RenderedOp originalImage = JAI.create("stream", seekableImageStream, true);
            Dimension d = new Dimension(originalImage.getWidth(), originalImage.getHeight());
            d = WebUtil.getDimension(d, width, height);
            ImgMetadata data = imageHelper.makeImg(b);
            scaled = imageHelper.scaleImg(data, (int) d.getWidth(), (int) d.getHeight());
        } else {
            // don't scale the image
            ImgMetadata data = imageHelper.makeImg(b);
            scaled = imageHelper.scaleImg(data, width, height);
        }
        if (scaled != null) {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            int quality = 75;
            String type = "jpeg"; // any output encoding
            scaled.writeTo(os, type, quality); //calls JAI.create("encode", result, fos, type, null);
            return os.toByteArray();
        }
    } catch (Exception e) {
        throw new BasicObjException("Error writing image stream ", e);
    }
    return null;
}

From source file:genlib.output.gui.Graph2D.java

/**
 * open a window with one or more plot-collections
 *
 * @param rows count of rows//w  w w .  ja v a2s  .  c o  m
 * @param cols count of columns
 * @param gap size of gaps between Plots (in pixel)
 * @param percentSizeOfScreen the size of the complete window in per-cent of the windows
 * @param plots the plot-collections, can have null's inside,then there is empty space on the window
 * @return the window-object
 * @throws IllegalArgumentException if rows or cols lower than 1, gap lower than 0, percentSizeOfScreen lower than 0.001 or higher than 1 or number of plots not the same as rows*cols
 */
public static Graph2D open(int rows, int cols, int gap, double percentSizeOfScreen, PlotCollection... plots) {
    if (rows <= 0)
        throw new IllegalArgumentException("invalid rows-count: '" + rows + "'.");
    if (cols <= 0)
        throw new IllegalArgumentException("invalid cols-count: '" + cols + "'.");
    if (gap < 0)
        throw new IllegalArgumentException("invalid gap: '" + gap + "'.");
    if (percentSizeOfScreen < 0.001 || percentSizeOfScreen > 1)
        throw new IllegalArgumentException("invalid percentSizeOfScreen: '" + percentSizeOfScreen + "'.");
    if (plots == null || plots.length != rows * cols)
        throw new IllegalArgumentException("length of plots is not rows*cols.");

    //the window-title is a concatenation of all plots
    //but first, we have to ignore all null-plots
    String windowTitle = "";
    List<PlotCollection> plotsNotNull = new ArrayList();
    for (PlotCollection plot : plots)
        if (plot != null)
            plotsNotNull.add(plot);

    if (plotsNotNull.isEmpty())
        windowTitle = "no plots";
    else
        for (int i = 0; i < plotsNotNull.size(); i++)
            windowTitle += (i > 0 ? ", " : "") + plotsNotNull.get(i).title;

    //create the window
    Graph2D ret = new Graph2D(windowTitle);

    //and create the row-col-layout
    JPanel grid = new JPanel();
    grid.setLayout(new GridLayout(rows, cols, gap, gap));
    for (PlotCollection plot : plots)
        if (plot == null)
            grid.add(new JLabel(""));
        else
            grid.add(plot.getGUIElement());

    //some other attributes of the window
    grid.setBackground(Color.BLACK);
    ret.setContentPane(grid);
    ret.pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    ret.setSize(new Dimension((int) (screenSize.getWidth() * percentSizeOfScreen),
            (int) (screenSize.getHeight() * percentSizeOfScreen)));
    RefineryUtilities.centerFrameOnScreen(ret);
    ret.setVisible(true);

    return ret;
}

From source file:org.yamj.core.service.artwork.ArtworkProcessorService.java

private boolean checkArtworkQuality(ArtworkLocated located) {
    if (StringUtils.isNotBlank(located.getUrl())) {

        if (located.getWidth() <= 0 || located.getHeight() <= 0) {
            // retrieve dimension
            try {
                // get dimension
                Dimension dimension = GraphicTools.getDimension(located.getUrl());
                if (dimension.getHeight() <= 0 || dimension.getWidth() <= 0) {
                    LOG.warn("No valid image dimension determined: {}", located);
                    return Boolean.FALSE;
                }/*  ww w. ja v  a  2s. c o m*/

                // set values for later usage
                located.setWidth((int) dimension.getWidth());
                located.setHeight((int) dimension.getHeight());
            } catch (IOException ex) {
                LOG.warn("Could not determine image dimension cause invalid image: {}", located);
                LOG.trace("Invalid image error", ex);
                return Boolean.FALSE;
            }
        }

        // TODO: check quality of artwork?

        /*
         float urlAspect = (float) urlWidth / (float) urlHeight;
         if (urlAspect > 1.0) {
         LOG.info("{} rejected: URL is wrong aspect (portrait/landscape)", located);
         return Boolean.FALSE;
         }
                
         // Adjust artwork width / height by the ValidateMatch figure
         int newArtworkWidth = artworkWidth * (artworkValidateMatch / 100);
         int newArtworkHeight = artworkHeight * (artworkValidateMatch / 100);
                
         if (urlWidth < newArtworkWidth) {
         logger.debug(LOG_MESSAGE + artworkImage + " rejected: URL width (" + urlWidth + ") is smaller than artwork width (" + newArtworkWidth + ")");
         return Boolean.FALSE;
         }
                
         if (urlHeight < newArtworkHeight) {
         logger.debug(LOG_MESSAGE + artworkImage + " rejected: URL height (" + urlHeight + ") is smaller than artwork height (" + newArtworkHeight + ")");
         return Boolean.FALSE;
         }
         */
    } else {
        // TODO: stage file needs no validation??
        LOG.trace("Located URL was blank for {}", located.toString());
    }

    return Boolean.TRUE;
}