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:gda.plots.BlockWrapper.java

/**
 * Usually this returns the Size2D that the object would like to have given the constraints applied - we just return
 * the width and height of our wrapped JComponent.
 * /*w ww  . j ava2s .  c o  m*/
 * @param g2
 *            the Graphics2D into which the object will be drawn
 * @param constraint
 *            a set of constraints (ignored here)
 * @return a Size2D that the object requires for successful drawing.
 */
@Override
public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) {
    logger.debug("BW constraint is " + constraint);
    Size2D rtrn = new Size2D(jc.getWidth(), jc.getHeight());
    logger.debug("BW rtrn is " + rtrn);
    Dimension d = jc.getPreferredSize();
    rtrn = new Size2D(d.getWidth(), d.getHeight());
    logger.debug("BW rtrn is " + d);
    return rtrn;
}

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());
    }/*  w  w w.  ja  va2s .  c  om*/

    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.epsilonlabs.workflow.execution.example.GraphOutput.java

public GraphOutput(String appname, String graphname, String x, String y) {
    super(appname);
    barChart = ChartFactory.createBarChart(graphname, x, y, dataset, PlotOrientation.VERTICAL, false, true,
            false);/* w ww .  j av a2s.co  m*/

    ChartPanel chartPanel = new ChartPanel(barChart);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int width = new Double(screenSize.getWidth()).intValue() - 100;
    chartPanel.setMaximumDrawHeight(500);
    chartPanel.setMaximumDrawWidth(width);
    chartPanel.setPreferredSize(new java.awt.Dimension(width, 500));
    setContentPane(chartPanel);

    Font font = new Font("Dialog", Font.PLAIN, 15);
    barChart.getCategoryPlot().getDomainAxis().setTickLabelFont(font);
    barChart.getCategoryPlot().setColumnRenderingOrder(SortOrder.DESCENDING);

}

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 ww . j a v a2 s.  c o 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  om*/
    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:fr.lig.sigma.astral.gui.graph.sugiyama.Node.java

public Node(E e, Layout<E, ?> layout, Transformer<E, String> labelTransformer) {
    this.e = e;/*from  w  w w .j  a  v  a  2s. c  o  m*/
    this.layout = layout;
    lbl.setText(labelTransformer.transform(e));

    Dimension size = lbl.getPreferredSize();
    //if(size.getWidth() == 0)
    //    nodeSize = new Point(100, 25);
    nodeSize = new Point(size.getWidth(), size.getHeight());

}

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  w  w  w .j ava  2 s  .  c  om*/
    }
    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:unikn.dbis.univis.explorer.VSplashScreen.java

/**
 * Zentriert die <code>SplashScreen</code> im sichtbaren Bereich des Bildschirms.
 *//* w  w  w  .ja  va2  s. c o  m*/
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.ajax4jsf.resource.Java2Dresource.java

/**
 * Create {@link RenderedImage} for send to client. can be used as Java2d or
 * Java Advanced Imaging./*w  ww  . j av  a 2s  .c o m*/
 * 
 * @param context
 * @return image to send.
 */
protected RenderedImage getImage(ResourceContext context) {
    ImageRenderer renderer = (ImageRenderer) getRenderer(null);
    Dimension imageDimensions = getDimensions(context);
    BufferedImage image = null;
    if (imageDimensions.getHeight() > 0.0 && imageDimensions.getWidth() > 0.0) {
        image = renderer.createImage(imageDimensions.width, imageDimensions.height);
        Graphics2D graphics = image.createGraphics();
        paint(context, graphics);
        graphics.dispose();

    }
    return image;
}

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

public void resetPanel(RockTourSolution solution) {
    translator = new LatitudeLongitudeTranslator();
    RockBus bus = solution.getBus();// w ww .  j  a va  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();
}