List of usage examples for java.awt.geom Rectangle2D getWidth
public abstract double getWidth();
From source file:org.apache.pdfbox.rendering.TilingPaint.java
/** * Returns the pattern image in parent stream coordinates. */// w ww .j a v a 2 s . c om private BufferedImage getImage(PageDrawer drawer, PDTilingPattern pattern, PDColorSpace colorSpace, PDColor color, AffineTransform xform, Rectangle2D anchorRect) throws IOException { ColorSpace outputCS = ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorModel cm = new ComponentColorModel(outputCS, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); float width = (float) Math.abs(anchorRect.getWidth()); float height = (float) Math.abs(anchorRect.getHeight()); // device scale transform (i.e. DPI) (see PDFBOX-1466.pdf) Matrix xformMatrix = new Matrix(xform); float xScale = Math.abs(xformMatrix.getScalingFactorX()); float yScale = Math.abs(xformMatrix.getScalingFactorY()); width *= xScale; height *= yScale; int rasterWidth = Math.max(1, ceiling(width)); int rasterHeight = Math.max(1, ceiling(height)); // create raster WritableRaster raster = cm.createCompatibleWritableRaster(rasterWidth, rasterHeight); BufferedImage image = new BufferedImage(cm, raster, false, null); Graphics2D graphics = image.createGraphics(); // flip a -ve YStep around its own axis (see gs-bugzilla694385.pdf) if (pattern.getYStep() < 0) { graphics.translate(0, rasterHeight); graphics.scale(1, -1); } // flip a -ve XStep around its own axis if (pattern.getXStep() < 0) { graphics.translate(rasterWidth, 0); graphics.scale(-1, 1); } // device scale transform (i.e. DPI) graphics.scale(xScale, yScale); // apply only the scaling from the pattern transform, doing scaling here improves the // image quality and prevents large scale-down factors from creating huge tiling cells. Matrix newPatternMatrix; newPatternMatrix = Matrix.getScaleInstance(Math.abs(patternMatrix.getScalingFactorX()), Math.abs(patternMatrix.getScalingFactorY())); // move origin to (0,0) newPatternMatrix.concatenate(Matrix.getTranslateInstance(-pattern.getBBox().getLowerLeftX(), -pattern.getBBox().getLowerLeftY())); // render using PageDrawer drawer.drawTilingPattern(graphics, pattern, colorSpace, color, newPatternMatrix); graphics.dispose(); return image; }
From source file:com.hexidec.ekit.component.UnicodeDialog.java
public void init(int startIndex) { String customFont = Translatrix.getTranslationString("UnicodeDialogButtonFont"); if (customFont != null && customFont.length() > 0) { buttonFont = new Font(Translatrix.getTranslationString("UnicodeDialogButtonFont"), Font.PLAIN, 12); } else {//from w w w . ja v a2 s. c om buttonFont = new Font("Monospaced", Font.PLAIN, 12); } Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); JPanel centerPanel = new JPanel(); centerPanel.setLayout(new GridLayout(0, 17, 0, 0)); buttonGroup = new ButtonGroup(); int prefButtonWidth = 32; int prefButtonHeight = 32; centerPanel.add(new JLabel("")); for (int labelLoop = 0; labelLoop < 16; labelLoop++) { JLabel jlblMarker = new JLabel( "x" + (labelLoop > 9 ? "" + (char) (65 + (labelLoop - 10)) : "" + labelLoop)); jlblMarker.setHorizontalAlignment(SwingConstants.CENTER); jlblMarker.setVerticalAlignment(SwingConstants.CENTER); jlblMarker.setForeground(new Color(0.5f, 0.5f, 0.75f)); centerPanel.add(jlblMarker); } int labelcount = 0; for (int counter = 0; counter < UNICODEBLOCKSIZE; counter++) { if ((counter % 16) == 0) { JLabel jlblMarker = new JLabel( (labelcount > 9 ? "" + (char) (65 + (labelcount - 10)) : "" + labelcount) + "x"); jlblMarker.setHorizontalAlignment(SwingConstants.CENTER); jlblMarker.setVerticalAlignment(SwingConstants.CENTER); jlblMarker.setForeground(new Color(0.5f, 0.5f, 0.75f)); centerPanel.add(jlblMarker); labelcount++; } buttonArray[counter] = new JToggleButton(" "); buttonArray[counter].getModel().setActionCommand(""); buttonArray[counter].setFont(buttonFont); buttonArray[counter].setBorder( javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED)); buttonArray[counter].addActionListener(this); if (counter == 0) { FontRenderContext frcLocal = ((java.awt.Graphics2D) (parentEkit.getGraphics())) .getFontRenderContext(); Rectangle2D fontBounds = buttonFont.getMaxCharBounds(frcLocal); int maxCharWidth = (int) (Math.abs(fontBounds.getX())) + (int) (Math.abs(fontBounds.getWidth())); int maxCharHeight = (int) (Math.abs(fontBounds.getY())) + (int) (Math.abs(fontBounds.getHeight())); Insets buttonInsets = buttonArray[counter].getBorder().getBorderInsets(buttonArray[counter]); prefButtonWidth = maxCharWidth + buttonInsets.left + buttonInsets.right; prefButtonHeight = maxCharHeight + buttonInsets.top + buttonInsets.bottom; } buttonArray[counter].setPreferredSize(new Dimension(prefButtonWidth, prefButtonHeight)); centerPanel.add(buttonArray[counter]); buttonGroup.add(buttonArray[counter]); } JPanel selectorPanel = new JPanel(); jcmbBlockSelector = new JComboBox(unicodeBlocks); jcmbBlockSelector.setSelectedIndex(startIndex); jcmbBlockSelector.setActionCommand(CMDCHANGEBLOCK); jcmbBlockSelector.addActionListener(this); String[] sPages = { "1" }; jcmbPageSelector = new JComboBox(sPages); jcmbPageSelector.setSelectedIndex(0); jcmbPageSelector.setActionCommand(CMDCHANGEBLOCK); jcmbPageSelector.addActionListener(this); selectorPanel.add(new JLabel(Translatrix.getTranslationString("SelectorToolUnicodeBlock"))); selectorPanel.add(jcmbBlockSelector); selectorPanel.add(new JLabel(Translatrix.getTranslationString("SelectorToolUnicodePage"))); selectorPanel.add(jcmbPageSelector); JPanel buttonPanel = new JPanel(); JButton closeButton = new JButton(Translatrix.getTranslationString("DialogClose")); closeButton.setActionCommand("close"); closeButton.addActionListener(this); buttonPanel.add(closeButton); contentPane.add(centerPanel, BorderLayout.CENTER); contentPane.add(selectorPanel, BorderLayout.NORTH); contentPane.add(buttonPanel, BorderLayout.SOUTH); this.pack(); populateButtons(startIndex, 0); this.setVisible(true); }
From source file:edu.uci.ics.jung.visualization.picking.ShapePickSupport.java
/** * Retrieves the shape template for <code>e</code> and * transforms it according to the positions of its endpoints * in <code>layout</code>./*from w ww . j av a 2 s. c o m*/ * @param layout the <code>Layout</code> which specifies * <code>e</code>'s endpoints' positions * @param e the edge whose shape is to be returned * @return */ private Shape getTransformedEdgeShape(Layout<V, E> layout, E e) { Pair<V> pair = layout.getGraph().getEndpoints(e); V v1 = pair.getFirst(); V v2 = pair.getSecond(); boolean isLoop = v1.equals(v2); Point2D p1 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v1)); Point2D p2 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v2)); if (p1 == null || p2 == null) return null; float x1 = (float) p1.getX(); float y1 = (float) p1.getY(); float x2 = (float) p2.getX(); float y2 = (float) p2.getY(); // translate the edge to the starting vertex AffineTransform xform = AffineTransform.getTranslateInstance(x1, y1); Shape edgeShape = vv.getRenderContext().getEdgeShapeTransformer() .transform(Context.<Graph<V, E>, E>getInstance(vv.getGraphLayout().getGraph(), e)); if (isLoop) { // make the loops proportional to the size of the vertex Shape s2 = vv.getRenderContext().getVertexShapeTransformer().transform(v2); Rectangle2D s2Bounds = s2.getBounds2D(); xform.scale(s2Bounds.getWidth(), s2Bounds.getHeight()); // move the loop so that the nadir is centered in the vertex xform.translate(0, -edgeShape.getBounds2D().getHeight() / 2); } else { float dx = x2 - x1; float dy = y2 - y1; // rotate the edge to the angle between the vertices double theta = Math.atan2(dy, dx); xform.rotate(theta); // stretch the edge to span the distance between the vertices float dist = (float) Math.sqrt(dx * dx + dy * dy); xform.scale(dist, 1.0f); } // transform the edge to its location and dimensions edgeShape = xform.createTransformedShape(edgeShape); return edgeShape; }
From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java
private void renderDayMarkers(long pStart, long pEnd, Graphics2D pG2D) { Date d = new Date(pStart); d = DateUtils.setHours(d, 0);//from ww w .j a v a 2s.c om d = DateUtils.setMinutes(d, 0); d = DateUtils.setSeconds(d, 0); d = DateUtils.setMilliseconds(d, 0); for (long mark = d.getTime(); mark <= pEnd; mark += DateUtils.MILLIS_PER_HOUR) { int markerPos = Math.round((mark - pStart) / DateUtils.MILLIS_PER_MINUTE); pG2D.setColor(Color.YELLOW); pG2D.fillRect(markerPos, 20, 2, 10); pG2D.setColor(Color.WHITE); pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 10.0f)); pG2D.fillRect(markerPos - 5, 15, 12, 10); pG2D.setColor(Color.BLACK); Calendar cal = Calendar.getInstance(); cal.setTime(new Date(mark)); NumberFormat f = NumberFormat.getNumberInstance(); f.setMinimumIntegerDigits(2); f.setMaximumFractionDigits(2); pG2D.drawString(f.format(cal.get(Calendar.HOUR_OF_DAY)), markerPos - 5, 23); } long currentDay = d.getTime(); while (currentDay < pEnd) { currentDay += DateUtils.MILLIS_PER_DAY; int markerPos = Math.round((currentDay - pStart) / DateUtils.MILLIS_PER_MINUTE); pG2D.setColor(new Color(123, 123, 123)); pG2D.fillRect(markerPos, 15, 3, 30); SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy"); String dayLabel = f.format(currentDay); Rectangle2D labelBounds = pG2D.getFontMetrics().getStringBounds(dayLabel, pG2D); pG2D.setColor(Color.YELLOW); int labelWidth = (int) labelBounds.getWidth() + 5; pG2D.fillRect(markerPos - (int) Math.rint(labelWidth / 2), 15, labelWidth, 10); pG2D.setColor(Color.BLACK); pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 10.0f)); pG2D.drawString(dayLabel, markerPos - (int) Math.rint(labelWidth / 2) + 2, 23); } }
From source file:org.fhcrc.cpl.toolbox.gui.chart.ChartMouseAndMotionListener.java
/** * Transform a mouse X value into a value in the units of the X axis of the chart. * Note: if there were multiple subplots, this would need to take a MouseEvent to determine which one * Note: bounds the raw value by the boundaries of the chart. No using values off the ends, even if you're zoomed * @param rawValue//from ww w . j a va 2s. c o m * @return */ protected double transformMouseXValue(double rawValue) { Rectangle2D screenDataArea = _chartPanel.getScreenDataArea(); double boundedValue = Math.min(screenDataArea.getMaxX(), Math.max(screenDataArea.getMinX(), rawValue)); double leftmostOnAxis = domainAxis.getLowerBound(); double rightmostOnAxis = domainAxis.getUpperBound(); double leftmostonscreen = screenDataArea.getX(); double rightmostonscreen = leftmostonscreen + screenDataArea.getWidth(); double slope = (rightmostOnAxis - leftmostOnAxis) / (rightmostonscreen - leftmostonscreen); return ((slope * (boundedValue - leftmostonscreen)) + leftmostOnAxis); }
From source file:org.uva.itast.blended.omr.pages.PDFPageImage.java
private Rectangle2D toPDFUnits(Rectangle2D rect) { float ratioHeight = PREFERRED_PIXELS_HEIGHT_A4 / getPage().getHeight(); float ratioWidth = PREFERRED_PIXELS_WIDTH_A4 / getPage().getWidth(); Rectangle2D rectNew = new Rectangle(); rectNew.setFrame(rect.getX() / ratioWidth, rect.getY() / ratioHeight, rect.getWidth() / ratioWidth, rect.getHeight() / ratioHeight); return rectNew; }
From source file:org.dishevelled.brainstorm.BrainStorm.java
/** * Calculate the text area size in rows and columns based on the current * window size and text area font size.//from w ww .j av a2 s . c om */ private void calculateTextAreaSize() { double width = (double) getWidth(); FontRenderContext frc = new FontRenderContext(new AffineTransform(), true, true); TextLayout textLayout = new TextLayout("W", textArea.getFont(), frc); Rectangle2D textBounds = textLayout.getBounds(); int columns = Math.min(45, (int) (width / textBounds.getWidth()) - 4); textArea.setColumns(columns); }
From source file:org.tsho.dmc2.core.chart.DmcLyapunovPlot.java
public boolean renderVsTime(Graphics2D g2, Rectangle2D dataArea) { final int imageWidth = (int) dataArea.getWidth(); g2.setPaint(Color.red);//ww w .jav a2 s . c o m final int timeStep; if (Math.abs(upper - lower) >= imageWidth) { timeStep = ((int) upper - (int) lower) / imageWidth; } else { timeStep = 1; } CoreStatusEvent statusEv = new CoreStatusEvent(this); int prevX[] = new int[model.getNVar()]; int prevY[] = new int[model.getNVar()]; int ratio = (int) upper / 100; for (int i = (int) lower; i < (int) upper; i += timeStep) { double[] result; int transX, transY; result = Lua.evaluateLyapunovExponents(model, parameters, initialPoint, i); for (int j = 0; j < result.length; j++) { transX = (int) this.domainAxis.valueToJava2D(i, dataArea, RectangleEdge.BOTTOM); transY = (int) this.rangeAxis.valueToJava2D(result[j], dataArea, RectangleEdge.LEFT); // System.out.println("time: " + i); // System.out.println("ly[" + j + "] = " + result[j]); // System.out.println("x: " + transX + " y: " + transY); g2.setPaint(paintSequence[j]); //g2.fillRect(transX, transY, 1, 1); if (bigDots) { g2.fillRect(transX - 1, transY - 1, 3, 3); } else { g2.fillRect(transX, transY, 1, 1); } if (connectWithLines) { if (i > (int) lower) { g2.drawLine(transX, transY, prevX[j], prevY[j]); } prevX[j] = transX; prevY[j] = transY; } } if (stopped == true) { return false; } else if (ratio > 0) { statusEv.setPercent(i / ratio); statusEv.setType(CoreStatusEvent.COUNT | CoreStatusEvent.PERCENT); notifyCoreStatusListeners(statusEv); } } return true; }
From source file:org.jfree.chart.demo.GanttRenderer2.java
protected double calculateBarW0(CategoryPlot categoryplot, PlotOrientation plotorientation, Rectangle2D rectangle2d, CategoryAxis categoryaxis, CategoryItemRendererState categoryitemrendererstate, int i, int j) { double d = 0.0D; if (plotorientation == PlotOrientation.HORIZONTAL) d = rectangle2d.getHeight();/*from w ww.j ava 2 s . co m*/ else d = rectangle2d.getWidth(); double d1 = categoryaxis.getCategoryStart(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge()); int k = getRowCount(); int l = getColumnCount(); if (k > 1) { double d2 = (d * getItemMargin()) / (double) (l * (k - 1)); double d3 = calculateSeriesWidth(d, categoryaxis, l, k); d1 = (d1 + (double) i * (d3 + d2) + d3 / 2D) - categoryitemrendererstate.getBarWidth() / 2D; } else { d1 = categoryaxis.getCategoryMiddle(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge()) - categoryitemrendererstate.getBarWidth() / 2D; } return d1; }
From source file:org.zanata.util.TestEventForScreenshotListener.java
private Rectangle getScreenRectangle() { // http://stackoverflow.com/a/13380999/14379 Rectangle2D result = new Rectangle2D.Double(); GraphicsEnvironment localGE = GraphicsEnvironment.getLocalGraphicsEnvironment(); for (GraphicsDevice gd : localGE.getScreenDevices()) { for (GraphicsConfiguration graphicsConfiguration : gd.getConfigurations()) { Rectangle2D.union(result, graphicsConfiguration.getBounds(), result); }// ww w . j a v a 2s . co m } return new Rectangle((int) result.getWidth(), (int) result.getHeight()); }