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.optaplanner.examples.coachshuttlegathering.swingui.CoachShuttleGatheringWorldPanel.java

public void resetPanel(CoachShuttleGatheringSolution solution) {
    translator = new LatitudeLongitudeTranslator();
    for (RoadLocation location : solution.getLocationList()) {
        translator.addCoordinates(location.getLatitude(), location.getLongitude());
    }/*from   w  w  w  .  j  a  va2 s .  c o  m*/

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

    Graphics2D g = createCanvas(width, height);
    g.setColor(TangoColorFactory.ORANGE_3);
    RoadLocation hubLocation = solution.getHub().getLocation();
    translator.drawSquare(g, hubLocation.getLongitude(), hubLocation.getLatitude(), 5);
    for (BusStop stop : solution.getStopList()) {
        RoadLocation location = stop.getLocation();
        g.setColor((stop.getPassengerQuantity() <= 0) ? TangoColorFactory.ALUMINIUM_4
                : (stop.getTransportTimeToHub() == null) ? TangoColorFactory.ORANGE_2
                        : (stop.getTransportTimeRemainder() < 0) ? TangoColorFactory.SCARLET_2
                                : TangoColorFactory.ORANGE_2);
        translator.drawSquare(g, location.getLongitude(), location.getLatitude(), 3, stop.getTransportLabel());
    }
    List<Bus> busList = solution.getBusList();
    g.setColor(TangoColorFactory.ALUMINIUM_2);
    g.setFont(g.getFont().deriveFont((float) LOCATION_NAME_TEXT_SIZE));
    for (Bus bus : busList) {
        RoadLocation location = bus.getLocation();
        g.setColor(bus instanceof Coach ? TangoColorFactory.ORANGE_1 : TangoColorFactory.ALUMINIUM_2);
        translator.drawSquare(g, location.getLongitude(), location.getLatitude(), 3,
                StringUtils.abbreviate(bus.getName(), 20));
    }
    int colorIndex = 0;
    for (Bus bus : busList) {
        g.setColor(TangoColorFactory.SEQUENCE_2[colorIndex]);
        BusStop lastStop = null;
        for (BusStop stop = bus.getNextStop(); stop != null; stop = stop.getNextStop()) {
            RoadLocation previousLocation = stop.getPreviousBusOrStop().getLocation();
            RoadLocation location = stop.getLocation();
            translator.drawRoute(g, previousLocation.getLongitude(), previousLocation.getLatitude(),
                    location.getLongitude(), location.getLatitude(), false, false);
            lastStop = stop;
        }
        if (lastStop != null || bus instanceof Coach) {
            RoadLocation lastStopLocation = lastStop == null ? bus.getLocation() : lastStop.getLocation();
            StopOrHub destination = bus.getDestination();
            if (destination != null) {
                RoadLocation destinationLocation = destination.getLocation();
                translator.drawRoute(g, lastStopLocation.getLongitude(), lastStopLocation.getLatitude(),
                        destinationLocation.getLongitude(), destinationLocation.getLatitude(), false, true);
            }
        }
        colorIndex = (colorIndex + 1) % TangoColorFactory.SEQUENCE_2.length;
    }
    repaint();
}

From source file:org.apache.fop.render.pcl.PCLGraphics2DAdapter.java

/** {@inheritDoc} */
public void paintImage(Graphics2DImagePainter painter, RendererContext context, int x, int y, int width,
        int height) throws IOException {
    PCLRendererContext pclContext = PCLRendererContext.wrapRendererContext(context);
    PCLRenderer pcl = (PCLRenderer) context.getRenderer();
    PCLGenerator gen = pcl.gen;/*from w w  w .ja  v  a  2  s  .co  m*/

    // get the 'width' and 'height' attributes of the image/document
    Dimension dim = painter.getImageSize();
    float imw = (float) dim.getWidth();
    float imh = (float) dim.getHeight();

    boolean painted = false;
    boolean paintAsBitmap = pclContext.paintAsBitmap();
    if (!paintAsBitmap) {
        ByteArrayOutputStream baout = new ByteArrayOutputStream();
        PCLGenerator tempGen = new PCLGenerator(baout, gen.getMaximumBitmapResolution());
        try {
            GraphicContext ctx = (GraphicContext) pcl.getGraphicContext().clone();

            AffineTransform prepareHPGL2 = new AffineTransform();
            prepareHPGL2.scale(0.001, 0.001);
            ctx.setTransform(prepareHPGL2);

            PCLGraphics2D graphics = new PCLGraphics2D(tempGen);
            graphics.setGraphicContext(ctx);
            graphics.setClippingDisabled(pclContext.isClippingDisabled());
            Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
            painter.paint(graphics, area);

            //If we arrive here, the graphic is natively paintable, so write the graphic
            pcl.saveGraphicsState();
            pcl.setCursorPos(x, y);
            gen.writeCommand(
                    "*c" + gen.formatDouble4(width / 100f) + "x" + gen.formatDouble4(height / 100f) + "Y");
            gen.writeCommand("*c0T");
            gen.enterHPGL2Mode(false);
            gen.writeText("\nIN;");
            gen.writeText("SP1;");
            //One Plotter unit is 0.025mm!
            double scale = imw / UnitConv.mm2pt(imw * 0.025);
            gen.writeText("SC0," + gen.formatDouble4(scale) + ",0,-" + gen.formatDouble4(scale) + ",2;");
            gen.writeText("IR0,100,0,100;");
            gen.writeText("PU;PA0,0;\n");
            baout.writeTo(gen.getOutputStream()); //Buffer is written to output stream
            gen.writeText("\n");

            gen.enterPCLMode(false);
            pcl.restoreGraphicsState();
            painted = true;
        } catch (UnsupportedOperationException uoe) {
            log.debug("Cannot paint graphic natively. Falling back to bitmap painting. Reason: "
                    + uoe.getMessage());
        }
    }

    if (!painted) {
        //Fallback solution: Paint to a BufferedImage
        int resolution = Math.round(context.getUserAgent().getTargetResolution());
        BufferedImage bi = paintToBufferedImage(painter, pclContext, resolution, !pclContext.isColorCanvas(),
                false);

        pcl.setCursorPos(x, y);
        gen.paintBitmap(bi, new Dimension(width, height), pclContext.isSourceTransparency());
    }
}

From source file:layout.GridLayoutDemo.java

public void addComponentsToPane(final Container pane) {
    initGaps();//from   w  w  w .ja v  a 2  s.  c  o m
    final JPanel compsToExperiment = new JPanel();
    compsToExperiment.setLayout(experimentLayout);
    JPanel controls = new JPanel();
    controls.setLayout(new GridLayout(2, 3));

    //Set up components preferred size
    JButton b = new JButton("Just fake button");
    Dimension buttonSize = b.getPreferredSize();
    compsToExperiment.setPreferredSize(new Dimension((int) (buttonSize.getWidth() * 2.5) + maxGap,
            (int) (buttonSize.getHeight() * 3.5) + maxGap * 2));

    //Add buttons to experiment with Grid Layout
    compsToExperiment.add(new JButton("Button 1"));
    compsToExperiment.add(new JButton("Button 2"));
    compsToExperiment.add(new JButton("Button 3"));
    compsToExperiment.add(new JButton("Long-Named Button 4"));
    compsToExperiment.add(new JButton("5"));

    //Add controls to set up horizontal and vertical gaps
    controls.add(new Label("Horizontal gap:"));
    controls.add(new Label("Vertical gap:"));
    controls.add(new Label(" "));
    controls.add(horGapComboBox);
    controls.add(verGapComboBox);
    controls.add(applyButton);

    //Process the Apply gaps button press
    applyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //Get the horizontal gap value
            String horGap = (String) horGapComboBox.getSelectedItem();
            //Get the vertical gap value
            String verGap = (String) verGapComboBox.getSelectedItem();
            //Set up the horizontal gap value
            experimentLayout.setHgap(Integer.parseInt(horGap));
            //Set up the vertical gap value
            experimentLayout.setVgap(Integer.parseInt(verGap));
            //Set up the layout of the buttons
            experimentLayout.layoutContainer(compsToExperiment);
        }
    });
    pane.add(compsToExperiment, BorderLayout.NORTH);
    pane.add(new JSeparator(), BorderLayout.CENTER);
    pane.add(controls, BorderLayout.SOUTH);
}

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

@Override
public BufferedImage resizeToStandarSize(BufferedImage image) {
    Dimension boundary = new Dimension(imageWidth, imageHeight);
    Dimension originalDimension = new Dimension(image.getWidth(), image.getHeight());
    Dimension newDimension = ImageServiceImp.getScaledDimension(originalDimension, boundary);
    ResampleOp resampleOp = new ResampleOp((int) newDimension.getWidth(), (int) newDimension.getHeight());
    resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Normal);
    BufferedImage rescaled = resampleOp.filter(image, null);
    return rescaled;
}

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

@Override
public BufferedImage getThumbnail(BufferedImage image) {
    Dimension boundary = new Dimension(thumbWidth, thumbHeight);
    Dimension originalDimension = new Dimension(image.getWidth(), image.getHeight());
    Dimension newDimension = ImageServiceImp.getScaledDimension(originalDimension, boundary);
    ResampleOp resampleOp = new ResampleOp((int) newDimension.getWidth(), (int) newDimension.getHeight());
    resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Normal);
    BufferedImage rescaled = resampleOp.filter(image, null);
    return rescaled;
}

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

public void send(ResourceContext context) throws IOException {
    try {//  w w  w  .ja va  2  s  . c  om
        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:unikn.dbis.univis.explorer.VSplashScreen.java

/**
 * Zentriert die <code>SplashScreen</code> im sichtbaren Bereich des Bildschirms.
 *///from   w  w  w  . j  a v  a  2s . com
private void center() {

    // Gre der eingestellten Bildschirmauflsung.
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    double width = screenSize.getWidth();
    double height = screenSize.getHeight();

    width -= image.getWidth();
    height -= image.getHeight();

    setSize(new Dimension(image.getWidth(), image.getHeight()));

    setLocation((int) width / 2, (int) height / 2);
}

From source file:org.broad.igv.ui.action.SetTrackHeightMenuAction.java

/**
 * Method description/*from w w  w.  java 2  s . c  om*/
 */
final public void doSetTrackHeight() {

    boolean doRefresh = false;
    try {
        JPanel container = new JPanel();
        JLabel trackHeightLabel = new JLabel("Track Height (pixels)");
        JTextField trackHeightField = new JTextField();
        Dimension preferredSize = trackHeightField.getPreferredSize();
        trackHeightField.setPreferredSize(new Dimension(50, (int) preferredSize.getHeight()));
        container.add(trackHeightLabel);
        container.add(trackHeightField);

        int repTrackHeight = getRepresentativeTrackHeight();
        trackHeightField.setText(String.valueOf(repTrackHeight));

        int status = JOptionPane.showConfirmDialog(mainFrame.getMainFrame(), container, "Set Track Height",
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null);

        if ((status == JOptionPane.CANCEL_OPTION) || (status == JOptionPane.CLOSED_OPTION)) {
            return;
        }

        try {
            int newTrackHeight = Integer.parseInt(trackHeightField.getText().trim());
            IGV.getInstance().setAllTrackHeights(newTrackHeight);
            lastTrackHeight = newTrackHeight;
            doRefresh = true;
        } catch (NumberFormatException numberFormatException) {
            JOptionPane.showMessageDialog(mainFrame.getMainFrame(), "Track height must be an integer number.");
        }

    } finally {

        // Refresh view
        if (doRefresh) {

            // Update the state of the current tracks for drawing purposes

            mainFrame.doRefresh();
        }
        mainFrame.resetStatusMessage();
    }

}

From source file:org.optaplanner.examples.rocktour.swingui.RockTourWorldPanel.java

public void resetPanel(RockTourSolution solution) {
    translator = new LatitudeLongitudeTranslator();
    RockBus bus = solution.getBus();/*from   w  ww  . j a  v a  2  s  .  co m*/
    translator.addCoordinates(bus.getStartLocation().getLatitude(), bus.getStartLocation().getLongitude());
    translator.addCoordinates(bus.getEndLocation().getLatitude(), bus.getEndLocation().getLongitude());
    for (RockShow show : solution.getShowList()) {
        translator.addCoordinates(show.getLocation().getLatitude(), show.getLocation().getLongitude());
    }

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

    Graphics2D g = createCanvas(width, height);
    g.setFont(g.getFont().deriveFont((float) LOCATION_NAME_TEXT_SIZE));
    List<RockShow> showList = solution.getShowList();
    int maxAvailableDateSetSize = showList.stream().mapToInt(show -> show.getAvailableDateSet().size()).max()
            .orElse(-1);
    for (RockShow show : showList) {
        RockLocation location = show.getLocation();
        int x = translator.translateLongitudeToX(location.getLongitude());
        int y = translator.translateLatitudeToY(location.getLatitude());
        double percentage = (double) show.getAvailableDateSet().size() / maxAvailableDateSetSize;
        g.setColor(TangoColorFactory.buildPercentageColor(TangoColorFactory.PLUM_3, TangoColorFactory.PLUM_1,
                percentage));
        g.fillRect(x - 1, y - 1, 3, 3);
        if (location.getCityName() != null && showList.size() <= 500) {
            g.drawString(StringUtils.abbreviate(location.getCityName(), 20), x + 3, y - 3);
        }
        if (show.getDate() != null) {
            g.drawString(DAY_FORMATTER.format(show.getDate()), x + 3, y - 3 + LOCATION_NAME_TEXT_SIZE * 3 / 2);
        }
    }
    g.setColor(TangoColorFactory.ALUMINIUM_4);
    RockLocation busStartLocation = bus.getStartLocation();
    int domicileX = translator.translateLongitudeToX(busStartLocation.getLongitude());
    int domicileY = translator.translateLatitudeToY(busStartLocation.getLatitude());
    g.fillRect(domicileX - 2, domicileY - 2, 5, 5);
    if (busStartLocation.getCityName() != null && showList.size() <= 500) {
        g.drawString(busStartLocation.getCityName(), domicileX + 3, domicileY - 3);
    }
    Set<RockShow> needsBackToDomicileLineSet = new HashSet<>(showList);
    for (RockShow trailingShow : showList) {
        if (trailingShow.getPreviousStandstill() instanceof RockShow) {
            needsBackToDomicileLineSet.remove(trailingShow.getPreviousStandstill());
        }
    }
    g.setColor(TangoColorFactory.CHOCOLATE_1);
    for (RockShow show : showList) {
        if (show.getPreviousStandstill() != null) {
            RockLocation previousLocation = show.getPreviousStandstill().getDepartureLocation();
            RockLocation location = show.getLocation();
            translator.drawRoute(g, previousLocation.getLongitude(), previousLocation.getLatitude(),
                    location.getLongitude(), location.getLatitude(), true, false);
            // Back to bus line
            if (needsBackToDomicileLineSet.contains(show)) {
                translator.drawRoute(g, location.getLongitude(), location.getLatitude(),
                        busStartLocation.getLongitude(), busStartLocation.getLatitude(), true, true);
            }
        }
    }
    g.setFont(g.getFont().deriveFont((float) TEXT_SIZE));
    // Legend
    g.setColor(TangoColorFactory.ALUMINIUM_4);
    g.fillRect(5, (int) height - 17 - TEXT_SIZE, 5, 5);
    g.drawString("Bus start", 15, (int) height - 10 - TEXT_SIZE);
    g.setColor(TangoColorFactory.PLUM_2);
    g.fillRect(6, (int) height - 11, 3, 3);
    g.drawString("Show (darker means less available)", 15, (int) height - 5);
    repaint();
}

From source file:org.github.jipsg.sanselan.BaseSanselanTest.java

/**
 * Some quick and dirty image scaling - please note that for best performance
 * and quality you should use image rescaling libraries.
 *///w  w  w.  j ava 2  s.  c o m
@Override
public BufferedImage resample(BufferedImage bufferedImage, int width, int height) {

    Dimension imageDimension = new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight());
    Dimension boundaryDimension = new Dimension(width, height);
    Dimension scaledDimension = BufferedImageUtils.getScaledDimension(imageDimension, boundaryDimension);

    double scaleX = scaledDimension.getWidth() / bufferedImage.getWidth();
    double scaleY = scaledDimension.getHeight() / bufferedImage.getHeight();

    AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY);
    AffineTransformOp biLinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);

    return biLinearScaleOp.filter(bufferedImage,
            new BufferedImage(scaledDimension.width, scaledDimension.height, bufferedImage.getType()));
}