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:fr.pasteque.pos.sales.restaurant.Place.java

public void setButtonBounds() {
    Dimension d = m_btn.getPreferredSize();
    d.setSize(d.getWidth() + 30, d.getHeight());
    m_btn.setBounds(m_ix - d.width / 2, m_iy - d.height / 2, d.width, d.height);
}

From source file:ShapeMover.java

public void update(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Dimension dim = getSize();
    int w = (int) dim.getWidth();
    int h = (int) dim.getHeight();
    g2.setStroke(new BasicStroke(8.0f));

    if (isFirstTime) {
        area = new Rectangle(dim);
        rect.setLocation(w / 2 - 50, h / 2 - 25);
        isFirstTime = false;/*from  w  ww  .  ja  v a  2 s.c o m*/
    }

    // Clears the rectangle that was previously drawn.
    g2.setPaint(Color.white);
    g2.fillRect(0, 0, w, h);

    g2.setColor(Color.red);
    g2.draw(rect);
    g2.setColor(Color.black);
    g2.fill(rect);
}

From source file:org.optaplanner.examples.flightcrewscheduling.swingui.FlightCrewSchedulingWorldPanel.java

public void resetPanel(FlightCrewSolution solution) {
    translator = new LatitudeLongitudeTranslator();
    for (Airport airport : solution.getAirportList()) {
        translator.addCoordinates(airport.getLatitude(), airport.getLongitude());
    }//from   w w w  . j  a v  a  2  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.setFont(g.getFont().deriveFont((float) LOCATION_NAME_TEXT_SIZE));
    g.setColor(TangoColorFactory.PLUM_2);
    for (Airport airport : solution.getAirportList()) {
        int x = translator.translateLongitudeToX(airport.getLongitude());
        int y = translator.translateLatitudeToY(airport.getLatitude());
        g.fillRect(x - 1, y - 1, 3, 3);
        g.drawString(StringUtils.abbreviate(airport.getCode(), 20), x + 3, y - 3);
    }
    g.setColor(TangoColorFactory.CHOCOLATE_1);
    for (Flight flight : solution.getFlightList()) {
        Airport departureAirport = flight.getDepartureAirport();
        Airport arrivalAirport = flight.getArrivalAirport();
        translator.drawRoute(g, departureAirport.getLongitude(), departureAirport.getLatitude(),
                arrivalAirport.getLongitude(), arrivalAirport.getLatitude(), true, false);
    }
    g.setFont(g.getFont().deriveFont((float) TEXT_SIZE));
    // Legend
    g.setColor(TangoColorFactory.PLUM_2);
    g.fillRect(6, (int) height - 11, 3, 3);
    g.drawString("Airport", 15, (int) height - 5);
    repaint();
}

From source file:org.jamwiki.parser.image.ImageUtil.java

/**
 * Determine the scaled dimensions, given a max width and height.  For example, if
 * the original dimensions are 800x400 and the max width height are 200, the result
 * is 200x100.// ww  w .jav a  2s . co m
 */
private static Dimension calculateScaledDimensions(Dimension originalDimensions, int maxWidth, int maxHeight) {
    if (maxWidth <= 0 && maxHeight <= 0) {
        return originalDimensions;
    }
    double heightScalingFactor = ((double) maxHeight / (double) originalDimensions.getHeight());
    double widthScalingFactor = ((double) maxWidth / (double) originalDimensions.getWidth());
    // scale by whichever is proportionally smaller
    int width, height;
    if (maxWidth <= 0) {
        width = (int) Math.round(heightScalingFactor * (double) originalDimensions.getWidth());
        height = (int) Math.round(heightScalingFactor * (double) originalDimensions.getHeight());
    } else if (maxHeight <= 0) {
        width = (int) Math.round(widthScalingFactor * (double) originalDimensions.getWidth());
        height = (int) Math.round(widthScalingFactor * (double) originalDimensions.getHeight());
    } else if (heightScalingFactor < widthScalingFactor) {
        width = (int) Math.round(heightScalingFactor * (double) originalDimensions.getWidth());
        height = (int) Math.round(heightScalingFactor * (double) originalDimensions.getHeight());
    } else {
        width = (int) Math.round(widthScalingFactor * (double) originalDimensions.getWidth());
        height = (int) Math.round(widthScalingFactor * (double) originalDimensions.getHeight());
    }
    return new Dimension(width, height);
}

From source file:org.mentawai.rule.ImageMinSizeRule.java

public boolean check(String field, Action action) {

    Input input = action.getInput();/*from  ww  w.ja  va2s.c om*/

    Object value = input.getValue(field);

    if (value == null || value.toString().trim().equals("")) {

        // if we got to this point, it means that there is no RequiredRule
        // in front of this rule. Therefore this field is probably an OPTIONAL
        // field, so if it is NULL or EMPTY we don't want to do any
        // futher validation and return true to allow it.

        return true; // may be optional
    }

    if (value instanceof FileItem) {

        FileItem item = (FileItem) value;

        byte[] data = item.get();

        if (item.getSize() <= 0 || data == null || data.length <= 0) {

            throw new org.mentawai.util.RuntimeException("Cannot find image file to validate: " + field);

        }

        Dimension d = ImageUtils.getSize(data);

        if (d.getWidth() < width || d.getHeight() < height)
            return false;

        return true;

    } else {

        throw new org.mentawai.util.RuntimeException("Bad type for file upload: " + value.getClass());
    }
}

From source file:CenterLayout.java

public void layoutContainer(Container container) {
    int count = container.getComponentCount();
    if (count > 0) {
        Component child = container.getComponent(0);
        java.awt.Insets insets = container.getInsets();
        int availWidth = container.getWidth() - insets.left - insets.right;
        int availHeight = container.getHeight() - insets.top - insets.bottom;
        Dimension preferredSize = child.getPreferredSize();
        double preferredWidth = preferredSize.getWidth();
        double preferredHeight = preferredSize.getHeight();
        int width;
        int height;
        int x;//w w w . ja  v  a  2s .c o m
        int y;
        if (preferredWidth < availWidth) {
            x = (int) Math.round(insets.left + (availWidth - preferredWidth) / 2);
            width = (int) Math.round(preferredWidth);
        } else {
            x = insets.left;
            width = availWidth;
        }
        if (preferredHeight < availHeight) {
            y = (int) Math.round(insets.top + (availHeight - preferredHeight) / 2);
            height = (int) Math.round(preferredHeight);
        } else {
            y = insets.top;
            height = availHeight;
        }
        child.setBounds(x, y, width, height);
    }
}

From source file:modelibra.designer.metaconceptgraphic.MetaConceptGraphic.java

public void setSize(Dimension dimension) {
    Double widthDouble = dimension.getWidth();
    Integer width = new Integer(widthDouble.intValue());
    setWidth(width);/*from w  ww .ja va  2 s .c  om*/

    Double heightDouble = dimension.getWidth();
    Integer height = new Integer(heightDouble.intValue());
    setHeight(height);
}

From source file:org.opennms.features.topology.app.internal.jung.TopoFRLayoutAlgorithm.java

@Override
public void updateLayout(final GraphContainer graphContainer) {

    Graph g = graphContainer.getGraph();

    final Layout graphLayout = g.getLayout();

    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();

    Collection<Vertex> vertices = g.getDisplayVertices();

    for (Vertex v : vertices) {
        jungGraph.addVertex(v);//from w  w  w  .  j av a  2 s . c om
    }

    Collection<Edge> edges = g.getDisplayEdges();

    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }

    TopoFRLayout<VertexRef, EdgeRef> layout = new TopoFRLayout<VertexRef, EdgeRef>(jungGraph);
    // Initialize the vertex positions to the last known positions from the layout
    Dimension size = selectLayoutSize(graphContainer);
    layout.setInitializer(initializer(graphLayout, (int) size.getWidth() / 2, (int) size.getHeight() / 2));
    // Resize the graph to accommodate the number of vertices
    layout.setSize(size);

    while (!layout.done()) {
        layout.step();
    }

    // Store the new positions in the layout
    for (Vertex v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v) - (size.getWidth() / 2),
                (int) layout.getY(v) - (size.getHeight() / 2)));
    }
}

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.
 *///  ww  w.j a va2s.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()));
}

From source file:org.opennms.features.topology.app.internal.jung.FRLayoutAlgorithm.java

@Override
public void updateLayout(final GraphContainer graphContainer) {

    Graph g = graphContainer.getGraph();

    final Layout graphLayout = g.getLayout();

    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();

    Collection<Vertex> vertices = g.getDisplayVertices();

    for (Vertex v : vertices) {
        jungGraph.addVertex(v);/*w w  w . j  av  a  2 s .  c  o  m*/
    }

    Collection<Edge> edges = g.getDisplayEdges();

    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }

    FRLayout<VertexRef, EdgeRef> layout = new FRLayout<VertexRef, EdgeRef>(jungGraph);
    // Initialize the vertex positions to the last known positions from the layout
    Dimension size = selectLayoutSize(graphContainer);
    layout.setInitializer(initializer(graphLayout, (int) size.getWidth() / 2, (int) size.getHeight() / 2));
    // Resize the graph to accommodate the number of vertices
    layout.setSize(size);

    while (!layout.done()) {
        layout.step();
    }

    // Store the new positions in the layout
    for (Vertex v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v) - (size.getWidth() / 2),
                (int) layout.getY(v) - (size.getHeight() / 2)));
    }
}