List of usage examples for java.awt Dimension getHeight
public double getHeight()
From source file:AppPackage.Temperature.java
public Temperature() { try {/*w w w . j a va2 s . co m*/ JFrame window = new JFrame(); window.setSize(1000, 615); window.setBackground(Color.blue.darker()); double value = 55; Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - window.getWidth()) / 2); int y = (int) ((dimension.getHeight() - window.getHeight()) / 2); window.setLocation(x, y); DefaultValueDataset dataset = new DefaultValueDataset(value); ThermometerPlot thermometerplot = new ThermometerPlot(dataset); thermometerplot.setSubrangePaint(0, Color.green.darker()); thermometerplot.setSubrangePaint(1, Color.orange); thermometerplot.setSubrangePaint(2, Color.red); JFreeChart jfreechart = new JFreeChart("Temperature readings", JFreeChart.DEFAULT_TITLE_FONT, thermometerplot, true); thermometerplot.setInsets(new RectangleInsets(5D, 5D, 5D, 5D)); thermometerplot.setPadding(new RectangleInsets(10D, 10D, 10D, 10D)); thermometerplot.setThermometerStroke(new BasicStroke(2.0F)); thermometerplot.setThermometerPaint(Color.BLUE); thermometerplot.setGap(3); window.add(new ChartPanel(jfreechart), BorderLayout.CENTER); window.setVisible(true); } catch (Exception e) { System.out.print("Chart exception:" + e); } initComponents(); }
From source file:AppPackage.humidity.java
public humidity() { try {//from ww w .j av a 2 s . co m JFrame window = new JFrame(); window.setSize(1000, 615); window.setBackground(Color.blue.darker()); double value = 45; Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - window.getWidth()) / 2); int y = (int) ((dimension.getHeight() - window.getHeight()) / 2); window.setLocation(x, y); DefaultValueDataset dataset = new DefaultValueDataset(value); ThermometerPlot thermometerplot = new ThermometerPlot(dataset); thermometerplot.setSubrangePaint(0, Color.green.darker()); thermometerplot.setSubrangePaint(1, Color.orange); thermometerplot.setSubrangePaint(2, Color.red); JFreeChart jfreechart = new JFreeChart("Humidity readings", JFreeChart.DEFAULT_TITLE_FONT, thermometerplot, true); thermometerplot.setInsets(new RectangleInsets(5D, 5D, 5D, 5D)); thermometerplot.setPadding(new RectangleInsets(10D, 10D, 10D, 10D)); thermometerplot.setThermometerStroke(new BasicStroke(2.0F)); thermometerplot.setThermometerPaint(Color.BLUE); thermometerplot.setUnits(0); thermometerplot.setGap(3); window.add(new ChartPanel(jfreechart), BorderLayout.CENTER); window.setVisible(true); } catch (Exception e) { System.out.print("Chart exception:" + e); } initComponents(); }
From source file:org.mentawai.rule.ImageMinSizeRule.java
public boolean check(String field, Action action) { Input input = action.getInput();//from w w w.j a va 2 s . co m 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:org.ajax4jsf.resource.Java2Dresource.java
/** * Create {@link RenderedImage} for send to client. can be used as Java2d or * Java Advanced Imaging.//from w w w . j a v a 2s.co 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.flightcrewscheduling.swingui.FlightCrewSchedulingWorldPanel.java
public void resetPanel(FlightCrewSolution solution) { translator = new LatitudeLongitudeTranslator(); for (Airport airport : solution.getAirportList()) { translator.addCoordinates(airport.getLatitude(), airport.getLongitude()); }/* w w w . jav a2 s . co 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: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 w w. ja va2s .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.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 a v a 2 s.com } 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.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 a v a 2 s .com } 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))); } }
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;// w ww. j a v a 2 s . co 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: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;//from w w w .jav a 2s. co 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); } }