List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
From source file:org.squidy.designer.zoom.impl.DataTypeShape.java
/** * TODO [RR]: Needs refactoring for automatically computes visual hierarchy. */// w ww . ja v a 2s. co m private void buildDataHierarchy() { PBounds bounds = getBoundsReference(); Rectangle2D rectBounds = roundedRectangleShape.getBounds2D(); DataItemShape iData = new DataItemShape(IData.class, true); iData.setBounds(rectBounds); iData.setOffset(bounds.getCenterX() - rectBounds.getCenterX(), 0); addChild(iData); Class<? extends IData>[] typesFirstRow = DataUtility.DATA_FIRST_LEVEL; int amount = typesFirstRow.length; double spacing = (bounds.getWidth() - (amount * rectBounds.getWidth())) / (amount - 1); for (int i = 0; i < amount; i++) { boolean selected = dataTypes.contains(typesFirstRow[i]); DataItemShape item = new DataItemShape(typesFirstRow[i], selected); item.setBounds(rectBounds); item.setOffset((i * rectBounds.getWidth()) + (i * spacing), rectBounds.getHeight() + 200); addChild(item); } Class<? extends IData>[] typesSecondRow = DataUtility.DATA_SECOND_LEVEL; amount = typesSecondRow.length; spacing = (bounds.getWidth() - (amount * rectBounds.getWidth())) / (amount - 1); for (int i = 0; i < amount; i++) { boolean selected = dataTypes.contains(typesSecondRow[i]); DataItemShape item = new DataItemShape(typesSecondRow[i], selected); item.setBounds(rectBounds); item.setOffset((i * rectBounds.getWidth()) + (i * spacing), (2 * rectBounds.getHeight()) + (2 * 200)); addChild(item); } amount = 4; spacing = (bounds.getWidth() - (amount * rectBounds.getWidth())) / (amount - 1); boolean selected = dataTypes.contains(DataUtility.DATA_THIRD_LEVEL[0]); DataItemShape item = new DataItemShape(DataUtility.DATA_THIRD_LEVEL[0], selected); item.setBounds(rectBounds); item.setOffset((1 * rectBounds.getWidth()) + (1 * spacing), (3 * rectBounds.getHeight()) + (3 * 200)); addChild(item); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.SpectraPanel.java
public void updateChart() { // auto zoom/*ww w. ja va2 s .c om*/ if (theDocument.getNoScans() > 0) { Range mz_range = thePlot.getDomainAxis().getRange(); // update data double mz_toll = screenToDataX(1.); double[][] data = theDocument.getPeakDataAt(current_ind).getData(mz_range, mz_toll); // update visible data and compute intensity range visibleData.clear(); double min_int = (data[0].length > 0) ? data[1][0] : 0.; double max_int = (data[0].length > 0) ? data[1][0] : 0.; for (int i = 0; i < data[0].length; i++) { min_int = Math.min(min_int, data[1][i]); max_int = Math.max(max_int, data[1][i]); visibleData.put(data[0][i], data[1][i]); } //Range new_int_range = new Range(min_int,max_int); Range new_int_range = new Range(0., max_int); // make space for annotations Rectangle2D data_area = theChartPanel.getScreenDataArea(); if (data_area.getHeight() > 0) new_int_range = Range.expand(new_int_range, 0., 12. / data_area.getHeight()); // resize y axis thePlot.getRangeAxis().setRange(new_int_range); // reload dataset //theDataset.removeSeries("intensities"); theDataset.addSeries("intensities", data); /* for( int i=0; i<theDataset.getSeriesCount(); i++ ) { if( theDataset.getSeriesKey(i).equals("intensities") ) thePlot.getRenderer().setSeriesPaint(i,Color.red); else thePlot.getRenderer().setSeriesPaint(i,Color.blue); } */ } else { thePlot.getRangeAxis().setRange(new Range(0., 1.)); for (int i = 0; i < theDataset.getSeriesCount(); i++) theDataset.removeSeries(theDataset.getSeriesKey(i)); } // restore annotation shapes showSelection(); }
From source file:com.igormaznitsa.sciareto.ui.editors.MMDEditor.java
public void topicToCentre(@Nullable final Topic topic) { if (topic != null) { SwingUtilities.invokeLater(new Runnable() { @Override//www.j a v a 2s. c o m public void run() { final AbstractElement element = (AbstractElement) Assertions.assertNotNull(topic).getPayload(); if (element != null) { final Rectangle2D bounds = element.getBounds(); final Dimension viewPortSize = getViewport().getExtentSize(); final int x = Math.max(0, (int) Math .round(bounds.getX() - (viewPortSize.getWidth() - bounds.getWidth()) / 2)); final int y = Math.max(0, (int) Math .round(bounds.getY() - (viewPortSize.getHeight() - bounds.getHeight()) / 2)); getViewport().setViewPosition(new Point(x, y)); } } }); } }
From source file:edu.dlnu.liuwenpeng.render.BarRenderer.java
/** * Calculates the coordinate of the first "side" of a bar. This will be * the minimum x-coordinate for a vertical bar, and the minimum * y-coordinate for a horizontal bar. * /*from w ww .ja v a2 s . co m*/ * @param plot the plot. * @param orientation the plot orientation. * @param dataArea the data area. * @param domainAxis the domain axis. * @param state the renderer state (has the bar width precalculated). * @param row the row index. * @param column the column index. * * @return The coordinate. */ protected double calculateBarW0(CategoryPlot plot, PlotOrientation orientation, Rectangle2D dataArea, CategoryAxis domainAxis, CategoryItemRendererState state, int row, int column) { // calculate bar width... double space = 0.0; if (orientation == PlotOrientation.HORIZONTAL) { space = dataArea.getHeight(); } else { space = dataArea.getWidth(); } double barW0 = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); int seriesCount = getRowCount(); int categoryCount = getColumnCount(); if (seriesCount > 1) { double seriesGap = space * getItemMargin() / (categoryCount * (seriesCount - 1)); double seriesW = calculateSeriesWidth(space, domainAxis, categoryCount, seriesCount); barW0 = barW0 + row * (seriesW + seriesGap) + (seriesW / 2.0) - (state.getBarWidth() / 2.0); } else { barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - state.getBarWidth() / 2.0; } return barW0; }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java
@Override public void zoom(Rectangle2D selection) { // get the origin of the zoom selection in the Java2D space used for // drawing the chart (that is, before any scaling to fit the panel) Point2D selectOrigin = translateScreenToJava2D( new Point((int) Math.ceil(selection.getX()), (int) Math.ceil(selection.getY()))); PlotRenderingInfo plotInfo = getChartRenderingInfo().getPlotInfo(); Rectangle2D scaledDataArea = getScreenDataArea((int) selection.getCenterX(), (int) selection.getCenterY()); if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) { double hLower = (selection.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth(); double hUpper = (selection.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth(); double vLower = (scaledDataArea.getMaxY() - selection.getMaxY()) / scaledDataArea.getHeight(); double vUpper = (scaledDataArea.getMaxY() - selection.getMinY()) / scaledDataArea.getHeight(); Plot p = getChart().getPlot();/* w w w . j a va2 s .c o m*/ if (p instanceof LinkAndBrushPlot) { PlotOrientation orientation = null; if (p instanceof XYPlot) { XYPlot xyPlot = (XYPlot) p; orientation = xyPlot.getOrientation(); } if (p instanceof CategoryPlot) { CategoryPlot categoryPlot = (CategoryPlot) p; orientation = categoryPlot.getOrientation(); } // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... boolean savedNotify = p.isNotify(); p.setNotify(false); LinkAndBrushPlot LABPlot = (LinkAndBrushPlot) p; List<Pair<Integer, Range>> zoomedDomainAxisRanges = new LinkedList<Pair<Integer, Range>>(); List<Pair<Integer, Range>> zoomedRangeAxisRanges = new LinkedList<Pair<Integer, Range>>(); if (orientation == PlotOrientation.HORIZONTAL) { zoomedDomainAxisRanges .addAll(LABPlot.calculateDomainAxesZoom(vLower, vUpper, zoomOnLinkAndBrushSelection)); zoomedRangeAxisRanges.addAll(LABPlot.calculateRangeAxesZoom(hLower, hUpper, plotInfo, selectOrigin, zoomOnLinkAndBrushSelection)); } else { zoomedDomainAxisRanges .addAll(LABPlot.calculateDomainAxesZoom(hLower, hUpper, zoomOnLinkAndBrushSelection)); zoomedRangeAxisRanges.addAll(LABPlot.calculateRangeAxesZoom(vLower, vUpper, plotInfo, selectOrigin, zoomOnLinkAndBrushSelection)); } p.setNotify(savedNotify); if (zoomOnLinkAndBrushSelection) { informLinkAndBrushSelectionListeners(new LinkAndBrushSelection(SelectionType.ZOOM_IN, zoomedDomainAxisRanges, zoomedRangeAxisRanges)); } else { informLinkAndBrushSelectionListeners(new LinkAndBrushSelection(SelectionType.SELECTION, zoomedDomainAxisRanges, zoomedRangeAxisRanges)); } } else { super.zoom(selection); } } }
From source file:net.java.sip.communicator.gui.AuthenticationSplash.java
private void registrationEqualizeButtonSizes() { JButton[] buttons = new JButton[] { cancelButton, registerButton }; String[] labels = new String[buttons.length]; for (int i = 0; i < labels.length; i++) { labels[i] = buttons[i].getText(); }/*from w w w . j a v a2 s .co m*/ // Get the largest width and height int i = 0; Dimension maxSize = new Dimension(0, 0); Rectangle2D textBounds = null; Dimension textSize = null; FontMetrics metrics = buttons[0].getFontMetrics(buttons[0].getFont()); Graphics g = getGraphics(); for (i = 0; i < labels.length; ++i) { textBounds = metrics.getStringBounds(labels[i], g); maxSize.width = Math.max(maxSize.width, (int) textBounds.getWidth()); maxSize.height = Math.max(maxSize.height, (int) textBounds.getHeight()); } Insets insets = buttons[0].getBorder().getBorderInsets(buttons[0]); maxSize.width += insets.left + insets.right; maxSize.height += insets.top + insets.bottom; // reset preferred and maximum size since BoxLayout takes both // into account for (i = 0; i < buttons.length; ++i) { buttons[i].setPreferredSize((Dimension) maxSize.clone()); buttons[i].setMaximumSize((Dimension) maxSize.clone()); } }
From source file:net.java.sip.communicator.gui.AuthenticationSplash.java
/** * Sets the buttons along the bottom of the dialog to be the * same size. This is done dynamically by setting each button's * preferred and maximum sizes after the buttons are created. * This way, the layout automatically adjusts to the locale- * specific strings./*from www . j a va 2 s.c om*/ */ private void equalizeButtonSizes() { JButton[] buttons = new JButton[] { loginButton, cancelButton, registerButton }; String[] labels = new String[buttons.length]; for (int i = 0; i < labels.length; i++) { labels[i] = buttons[i].getText(); } // Get the largest width and height int i = 0; Dimension maxSize = new Dimension(0, 0); Rectangle2D textBounds = null; Dimension textSize = null; FontMetrics metrics = buttons[0].getFontMetrics(buttons[0].getFont()); Graphics g = getGraphics(); for (i = 0; i < labels.length; ++i) { textBounds = metrics.getStringBounds(labels[i], g); maxSize.width = Math.max(maxSize.width, (int) textBounds.getWidth()); maxSize.height = Math.max(maxSize.height, (int) textBounds.getHeight()); } Insets insets = buttons[0].getBorder().getBorderInsets(buttons[0]); maxSize.width += insets.left + insets.right; maxSize.height += insets.top + insets.bottom; // reset preferred and maximum size since BoxLayout takes both // into account for (i = 0; i < buttons.length; ++i) { buttons[i].setPreferredSize((Dimension) maxSize.clone()); buttons[i].setMaximumSize((Dimension) maxSize.clone()); } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.visio.informationflow.VisioInformationFlowExport.java
private void setTitlePos(Rectangle2D graphAreaBounds, Shape title, List<Shape> queryInfo) { double titleTopY = graphAreaBounds.getY() + graphAreaBounds.getHeight() + DISTANCE_TO_MARGIN_INCHES * 2.8 + title.getHeight() + getQueryInfoHeight(queryInfo); setTitlePosAndSize(title, graphAreaBounds.getX(), titleTopY, null); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java
public void mouseDragged(MouseEvent e) { if (mouse_start_point != null && theDocument.size() > 0) { if (is_moving) { // moving double mz_delta = screenToDataX(mouse_start_point.getX() - e.getPoint().getX()); if (mz_delta > 0.) { double old_upper_bound = thePlot.getDomainAxis().getUpperBound(); double old_lower_bound = thePlot.getDomainAxis().getLowerBound(); double new_upper_bound = Math.min(old_upper_bound + mz_delta, theDocument.getMaxMZ()); double new_lower_bound = old_lower_bound + new_upper_bound - old_upper_bound; thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); } else { double old_upper_bound = thePlot.getDomainAxis().getUpperBound(); double old_lower_bound = thePlot.getDomainAxis().getLowerBound(); double new_lower_bound = Math.max(old_lower_bound + mz_delta, theDocument.getMinMZ()); double new_upper_bound = old_upper_bound + new_lower_bound - old_lower_bound; thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); }/*from w w w . j av a 2s.c o m*/ mouse_start_point = e.getPoint(); } else { // zooming Graphics2D g2 = (Graphics2D) theChartPanel.getGraphics(); g2.setXORMode(java.awt.Color.gray); // delete old rectangle if (zoom_rectangle != null) g2.draw(zoom_rectangle); // create new rectangle double start_x = Math.min(e.getX(), mouse_start_point.getX()); double end_x = Math.max(e.getX(), mouse_start_point.getX()); Rectangle2D data_area = theChartPanel.getScreenDataArea((int) start_x, (int) mouse_start_point.getY()); double xmax = Math.min(end_x, data_area.getMaxX()); zoom_rectangle = new Rectangle2D.Double(start_x, data_area.getMinY(), xmax - start_x, data_area.getHeight()); // draw new rectangle g2.draw(zoom_rectangle); g2.dispose(); } } }
From source file:figs.treeVisualization.gui.PhyloDateAxis.java
/** * Translates the data value to the display coordinates (Java 2D User Space) * of the chart.//from w ww. ja v a 2 s . c o m * * @param value the date to be plotted. * @param area the rectangle (in Java2D space) where the data is to be * plotted. * @param edge the axis location. * * @return The coordinate corresponding to the supplied data value. * * Original method is in <code>org.jfree.chart.axis.DateAxis</code> */ @Override public double valueToJava2D(double value, Rectangle2D area, RectangleEdge edge) { Timeline timeline = this.getTimeline(); value = timeline.toTimelineValue((long) value); DateRange range = (DateRange) getRange(); double axisMin = timeline.toTimelineValue(range.getLowerDate()); double axisMax = timeline.toTimelineValue(range.getUpperDate()); double result = 0.0; if (RectangleEdge.isTopOrBottom(edge)) { double minX = area.getX(); double maxX = area.getMaxX(); if (isInverted()) { result = maxX + ((value - axisMin) / (axisMax - axisMin)) * (minX - maxX); } else { result = minX + ((value - axisMin) / (axisMax - axisMin)) * (maxX - minX); } } else if (RectangleEdge.isLeftOrRight(edge)) { //double minY = area.getMinY(); //double maxY = area.getMaxY(); double minY = area.getY(); double maxY = area.getHeight(); if (isInverted()) { result = minY + (((value - axisMin) / (axisMax - axisMin)) * (maxY - minY)); } else { result = maxY - (((value - axisMin) / (axisMax - axisMin)) * (maxY - minY)); } } return result; }