List of usage examples for java.awt Dimension getHeight
public double getHeight()
From source file:org.geoserver.wms.legendgraphic.ColorMapLegendCreator.java
/** * @param graphics/*from www . jav a 2 s .co m*/ */ private void cycleBodyRows(Graphics2D graphics) { for (ColorMapEntryLegendBuilder row : bodyRows) { // // row number i // // color element final Cell cm = row.getColorManager(); final Dimension colorDim = cm.getPreferredDimension(graphics); rowH = Math.max(rowH, colorDim.getHeight()); colorW = Math.max(colorW, colorDim.getWidth()); // rule if (forceRule) { final Cell ruleM = row.getRuleManager(); final Dimension ruleDim = ruleM.getPreferredDimension(graphics); rowH = Math.max(rowH, ruleDim.getHeight()); ruleW = Math.max(ruleW, ruleDim.getWidth()); } // label final Cell labelM = row.getLabelManager(); if (labelM == null) continue; final Dimension labelDim = labelM.getPreferredDimension(graphics); rowH = Math.max(rowH, labelDim.getHeight()); labelW = Math.max(labelW, labelDim.getWidth()); } }
From source file:hydrograph.ui.graph.figure.ComponentFigure.java
private void showStatusToolTip(org.eclipse.swt.graphics.Point location) { if (!componentCanvas.isFocused()) return;/*from ww w.j a v a 2s . c o m*/ componentCanvas = getComponentCanvas(); if (componentCanvas.getComponentTooltip() == null) { componentToolTip = getStatusToolTip(componentCanvas.getCanvasControl().getShell(), location); componentBounds = getComponentBounds(); componentCanvas.issueToolTip(componentToolTip, componentBounds); componentToolTip.setVisible(true); setStatusToolTipFocusListener(); org.eclipse.swt.graphics.Point tooltipSize = componentToolTip.computeSizeHint(); // componentToolTip.setSizeConstraints(300, 100); if (tooltipSize.x > 300) { tooltipSize.x = 300; } componentToolTip.setSize(tooltipSize.x, tooltipSize.y); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); double width = screenSize.getWidth(); double height = screenSize.getHeight(); int newX, newY; int offset = 10; if ((componentToolTip.getBounds().x + componentToolTip.getBounds().width) > width) { newX = componentToolTip.getBounds().x - (int) ((componentToolTip.getBounds().x + componentToolTip.getBounds().width) - width) - offset; } else { newX = componentToolTip.getBounds().x; } if ((componentToolTip.getBounds().y + componentToolTip.getBounds().height) > height) { newY = componentToolTip.getBounds().y - getBounds().height - componentToolTip.getBounds().height - offset; } else { newY = componentToolTip.getBounds().y; } org.eclipse.swt.graphics.Point newLocation = new org.eclipse.swt.graphics.Point(newX, newY); componentToolTip.setLocation(newLocation); } }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java
@Override public void paintComponent(Graphics g) { super.paintComponent(g); if (getChart() == null) { return;/*from w ww. java2 s.com*/ } Graphics2D g2 = (Graphics2D) g.create(); // first determine the size of the chart rendering area... Dimension size = getSize(); Insets insets = getInsets(); Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); // work out if scaling is required... boolean scale = false; double drawWidth = available.getWidth(); double drawHeight = available.getHeight(); setChartFieldValue(getChartFieldByName("scaleX"), 1.0); // this.scaleX = 1.0; setChartFieldValue(getChartFieldByName("scaleY"), 1.0); // this.scaleY = 1.0; if (drawWidth < getMinimumDrawWidth()) { setChartFieldValue(getChartFieldByName("scaleX"), drawWidth / getMinimumDrawWidth()); // this.scaleX = drawWidth / getMinimumDrawWidth(); drawWidth = getMinimumDrawWidth(); scale = true; } else if (drawWidth > getMaximumDrawWidth()) { setChartFieldValue(getChartFieldByName("scaleX"), drawWidth / getMaximumDrawWidth()); // this.scaleX = drawWidth / getMaximumDrawWidth(); drawWidth = getMaximumDrawWidth(); scale = true; } if (drawHeight < getMinimumDrawHeight()) { setChartFieldValue(getChartFieldByName("scaleY"), drawHeight / getMinimumDrawHeight()); // this.scaleY = drawHeight / getMinimumDrawHeight(); drawHeight = getMinimumDrawHeight(); scale = true; } else if (drawHeight > getMaximumDrawHeight()) { setChartFieldValue(getChartFieldByName("scaleY"), drawHeight / getMaximumDrawHeight()); // this.scaleY = drawHeight / getMaximumDrawHeight(); drawHeight = getMaximumDrawHeight(); scale = true; } Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight); // are we using the chart buffer? if ((Boolean) getChartFieldValueByName("useBuffer")) { // do we need to resize the buffer? if ((getChartFieldValueByName("chartBuffer") == null) || ((Integer) getChartFieldValueByName("chartBufferWidth") != available.getWidth()) || ((Integer) getChartFieldValueByName("chartBufferHeight") != available.getHeight())) { setChartFieldValue(getChartFieldByName("chartBufferWidth"), (int) available.getWidth()); // this.chartBufferWidth = (int) available.getWidth(); setChartFieldValue(getChartFieldByName("chartBufferHeight"), (int) available.getHeight()); // this.chartBufferHeight = (int) available.getHeight(); GraphicsConfiguration gc = g2.getDeviceConfiguration(); setChartFieldValue(getChartFieldByName("chartBuffer"), gc.createCompatibleImage((Integer) getChartFieldValueByName("chartBufferWidth"), (Integer) getChartFieldValueByName("chartBufferHeight"), Transparency.TRANSLUCENT)); // this.chartBuffer = gc.createCompatibleImage(this.chartBufferWidth, // this.chartBufferHeight, Transparency.TRANSLUCENT); setRefreshBuffer(true); } // do we need to redraw the buffer? if (getRefreshBuffer()) { setRefreshBuffer(false); // clear the flag Rectangle2D bufferArea = new Rectangle2D.Double(0, 0, (Integer) getChartFieldValueByName("chartBufferWidth"), (Integer) getChartFieldValueByName("chartBufferHeight")); Graphics2D bufferG2 = (Graphics2D) ((Image) getChartFieldValueByName("chartBuffer")).getGraphics(); Rectangle r = new Rectangle(0, 0, (Integer) getChartFieldValueByName("chartBufferWidth"), (Integer) getChartFieldValueByName("chartBufferHeight")); bufferG2.setPaint(getBackground()); bufferG2.fill(r); if (scale) { AffineTransform saved = bufferG2.getTransform(); AffineTransform st = AffineTransform.getScaleInstance( (Double) getChartFieldValueByName("scaleX"), (Double) getChartFieldValueByName("scaleY")); bufferG2.transform(st); getChart().draw(bufferG2, chartArea, getAnchor(), getChartRenderingInfo()); bufferG2.setTransform(saved); } else { getChart().draw(bufferG2, bufferArea, getAnchor(), getChartRenderingInfo()); } } // zap the buffer onto the panel... g2.drawImage((Image) getChartFieldValueByName("chartBuffer"), insets.left, insets.top, this); } // or redrawing the chart every time... else { AffineTransform saved = g2.getTransform(); g2.translate(insets.left, insets.top); if (scale) { AffineTransform st = AffineTransform.getScaleInstance((Double) getChartFieldValueByName("scaleX"), (Double) getChartFieldValueByName("scaleY")); g2.transform(st); } getChart().draw(g2, chartArea, getAnchor(), getChartRenderingInfo()); g2.setTransform(saved); } Iterator iterator = ((List) getChartFieldValueByName("overlays")).iterator(); while (iterator.hasNext()) { Overlay overlay = (Overlay) iterator.next(); overlay.paintOverlay(g2, this); } // redraw the zoom rectangle (if present) - if useBuffer is false, // we use XOR so we can XOR the rectangle away again without redrawing // the chart drawZoomRectangle(g2, !(Boolean) getChartFieldValueByName("useBuffer")); g2.dispose(); setAnchor(null); setVerticalTraceLine(null); setHorizontalTraceLine(null); }
From source file:ome.services.ThumbnailCtx.java
/** * Bulk loads thumbnail metadata.//from ww w.j ava 2s . c o m * @param dimensions X-Y dimensions to bulk load metdata for. * @param pixelsIds Pixels IDs to bulk load metadata for. * @return List of thumbnail objects with <code>thumbnail.pixels</code> and * <code>thumbnail.details.updateEvent</code> loaded. */ private List<Thumbnail> bulkLoadMetadata(Dimension dimensions, Set<Long> pixelsIds) { Parameters params = new Parameters(); params.addInteger("x", (int) dimensions.getWidth()); params.addInteger("y", (int) dimensions.getHeight()); params.addLong("o_id", userId); params.addIds(pixelsIds); StopWatch s1 = new CommonsLogStopWatch("omero.bulkLoadMetadata"); List<Thumbnail> toReturn = queryService.findAllByQuery("select t from Thumbnail as t " + "join t.pixels " + "join fetch t.details.updateEvent " + "where t.sizeX = :x and t.sizeY = :y " + "and t.details.owner.id = :o_id " + "and t.pixels.id in (:ids)", params); s1.stop(); return toReturn; }
From source file:ome.services.ThumbnailCtx.java
/** * Bulk loads thumbnail metadata that is owned by the owner of the Pixels * set..// w w w.j a v a 2 s .com * @param dimensions X-Y dimensions to bulk load metadata for. * @param pixelsIds Pixels IDs to bulk load metadata for. * @return List of thumbnail objects with <code>thumbnail.pixels</code> and * <code>thumbnail.details.updateEvent</code> loaded. */ private List<Thumbnail> bulkLoadOwnerMetadata(Dimension dimensions, Set<Long> pixelsIds) { Parameters params = new Parameters(); params.addInteger("x", (int) dimensions.getWidth()); params.addInteger("y", (int) dimensions.getHeight()); params.addIds(pixelsIds); StopWatch s1 = new CommonsLogStopWatch("omero.bulkLoadOwnerMetadata"); List<Thumbnail> toReturn = queryService .findAllByQuery( "select t from Thumbnail as t " + "join t.pixels as p " + "join fetch t.details.updateEvent " + "where t.sizeX = :x and t.sizeY = :y " + "and t.details.owner.id = p.details.owner.id " + "and t.pixels.id in (:ids)", params); s1.stop(); return toReturn; }
From source file:org.pentaho.di.trans.steps.exceloutput.ExcelOutput.java
private void setFonts() throws Exception { // --- Set Header font int headerFontSize = Const.toInt(environmentSubstitute(meta.getHeaderFontSize()), ExcelOutputMeta.DEFAULT_FONT_SIZE); // Set font name FontName headerFontName = ExcelFontMap.getFontName(meta.getHeaderFontName()); // Set UnderlineStyle UnderlineStyle underline = ExcelFontMap.getUnderlineStyle(meta.getHeaderFontUnderline()); WritableFont writableHeaderFont = null; if (meta.isHeaderFontBold()) { writableHeaderFont = new WritableFont(headerFontName, headerFontSize, WritableFont.BOLD, meta.isHeaderFontItalic(), underline); } else {//from ww w. j av a 2 s .com writableHeaderFont = new WritableFont(headerFontName, headerFontSize, WritableFont.NO_BOLD, meta.isHeaderFontItalic(), underline); } // Header font color Colour fontHeaderColour = ExcelFontMap.getColour(meta.getHeaderFontColor(), Colour.BLACK); if (!fontHeaderColour.equals(Colour.BLACK)) { writableHeaderFont.setColour(fontHeaderColour); } data.headerCellFormat = new WritableCellFormat(writableHeaderFont); // Header background color if (meta.getHeaderBackGroundColor() != ExcelOutputMeta.FONT_COLOR_NONE) { data.headerCellFormat.setBackground(ExcelFontMap.getColour(meta.getHeaderBackGroundColor(), null)); } // Set alignment data.headerCellFormat = ExcelFontMap.getAlignment(meta.getHeaderAlignment(), data.headerCellFormat); data.headerCellFormat = ExcelFontMap.getOrientation(meta.getHeaderFontOrientation(), data.headerCellFormat); // Do we need to put a image on the header if (!Const.isEmpty(data.realHeaderImage)) { FileObject imageFile = null; try { imageFile = KettleVFS.getFileObject(data.realHeaderImage); if (!imageFile.exists()) { throw new KettleException( BaseMessages.getString(PKG, "ExcelInputLog.ImageFileNotExists", data.realHeaderImage)); } data.realHeaderImage = KettleVFS.getFilename(imageFile); // Put an image Dimension m = ExcelFontMap.getImageDimension(data.realHeaderImage); data.headerImageWidth = m.getWidth() * 0.016; data.headerImageHeight = m.getHeight() * 0.0625; byte[] imageData = new byte[(int) imageFile.getContent().getSize()]; KettleVFS.getInputStream(imageFile).read(imageData); data.headerImage = new WritableImage(0, 0, data.headerImageWidth, data.headerImageHeight, imageData); } catch (Exception e) { throw new KettleException(e); } finally { if (imageFile != null) { try { imageFile.close(); } catch (Exception e) { // Ignore; } } } } // --- Set rows font // Set font size int rowFontSize = Const.toInt(environmentSubstitute(meta.getRowFontSize()), ExcelOutputMeta.DEFAULT_FONT_SIZE); // Set font name FontName rowFontName = ExcelFontMap.getFontName(meta.getRowFontName()); data.writableFont = new WritableFont(rowFontName, rowFontSize, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE); // Row font color Colour rowFontColour = ExcelFontMap.getColour(meta.getRowFontColor(), Colour.BLACK); if (!fontHeaderColour.equals(Colour.BLACK)) { data.writableFont.setColour(rowFontColour); } // Set rows background color if needed if (meta.getRowBackGroundColor() != ExcelOutputMeta.FONT_COLOR_NONE) { data.rowFontBackgoundColour = ExcelFontMap.getColour(meta.getRowBackGroundColor(), null); } }
From source file:org.kepler.gui.KeplerGraphFrame.java
/** * Return the size of the visible part of the canvas, in canvas coordinates. * // w ww.j av a 2 s.co m * @return Rectangle2D */ public Rectangle2D getVisibleSize() { AffineTransform current = _jgraph.getGraphPane().getCanvas().getCanvasPane().getTransformContext() .getTransform(); AffineTransform inverse; try { inverse = current.createInverse(); } catch (NoninvertibleTransformException e) { throw new RuntimeException(e.toString()); } Dimension size = _jgraph.getGraphPane().getCanvas().getSize(); Rectangle2D visibleRect = new Rectangle2D.Double(0, 0, size.getWidth(), size.getHeight()); return ShapeUtilities.transformBounds(visibleRect, inverse); }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowChartJDialog.java
private void loadDimension() { java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); Dimension dimension = org.yccheok.jstock.gui.Utils.fromXML(Dimension.class, org.yccheok.jstock.gui.Utils.getUserDataDirectory() + "config" + File.separator + "cashflowchartjdialog.xml"); if (dimension != null) { setBounds((screenSize.width - (int) dimension.getWidth()) / 2, (screenSize.height - (int) dimension.getHeight()) / 2, (int) dimension.getWidth(), (int) dimension.getHeight()); } else {//from w ww . j av a 2s . c om // There is a bit hack here. This line of code should be used within // initComponents. However, currently, we are using pack. This is // caused by x-axis scaling problem may occur in certain case, if we // do not call pack. Hence, the hacking is, we will first call pack // (to resolve x-axis scaling problem), followed by setBounds. setBounds((screenSize.width - 750) / 2, (screenSize.height - 500) / 2, 750, 500); } }
From source file:com.brainflow.application.toplevel.Brainflow.java
private void initializeWorkspace() throws Exception { log.info("initializing workspace"); brainFrame.getDockingManager().getWorkspace().setLayout(new BorderLayout()); brainFrame.getDockingManager().getWorkspace().add(documentPane, "Center"); JComponent canvas = DisplayManager.getInstance().getSelectedCanvas().getComponent(); canvas.setRequestFocusEnabled(true); canvas.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); documentPane.setTabPlacement(DocumentPane.BOTTOM); documentPane.openDocument(new DocumentComponent(new JScrollPane(canvas), "Canvas-1")); documentPane.setActiveDocument("Canvas-1"); log.info("initializing loading dock"); initLoadingDock();/*from w ww.ja va2s . com*/ log.info("initializing project view"); initProjectView(); log.info("initializing image table view"); initLoadableImageTableView(); log.info("initializing control panel"); initControlPanel(); log.info("initializing event monitor"); initEventBusMonitor(); log.info("initializing log monitor"); initLogMonitor(); brainFrame.getDockingManager().beginLoadLayoutData(); brainFrame.getDockingManager().setInitSplitPriority(DefaultDockingManager.SPLIT_EAST_WEST_SOUTH_NORTH); brainFrame.getDockingManager().loadLayoutData(); brainFrame.toFront(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); brainFrame.setSize((int) screenSize.getWidth(), (int) screenSize.getHeight() - 50); brainFrame.setVisible(true); CanvasBar2 cbar = new CanvasBar2(); /// TODO add automatic updating of canvas to Canvas Bar via EventBus //cbar.setImageCanvas(canvas); //////////////////////////////////////////////////////////////////// canvas.add(cbar.getComponent(), BorderLayout.NORTH); }
From source file:RadialLayout.java
/** * This is called when the panel is first displayed, and every time its size * changes./*from w ww.ja v a2 s. c o m*/ * Note: You CAN'T assume preferredLayoutSize or minimumLayoutSize will be * called -- in the case of applets, at least, they probably won't be. * * @param parent the parent. * @see LayoutManager */ public void layoutContainer(final Container parent) { final Insets insets = parent.getInsets(); final int maxWidth = parent.getSize().width - (insets.left + insets.right); final int maxHeight = parent.getSize().height - (insets.top + insets.bottom); final int nComps = parent.getComponentCount(); int x = 0; int y = 0; // Go through the components' sizes, if neither preferredLayoutSize nor // minimumLayoutSize has been called. if (this.sizeUnknown) { setSizes(parent); } if (nComps < 2) { final Component c = parent.getComponent(0); if (c.isVisible()) { final Dimension d = c.getPreferredSize(); c.setBounds(x, y, d.width, d.height); } } else { double radialCurrent = Math.toRadians(90); final double radialIncrement = 2 * Math.PI / nComps; final int midX = maxWidth / 2; final int midY = maxHeight / 2; final int a = midX - this.maxCompWidth; final int b = midY - this.maxCompHeight; for (int i = 0; i < nComps; i++) { final Component c = parent.getComponent(i); if (c.isVisible()) { final Dimension d = c.getPreferredSize(); x = (int) (midX - (a * Math.cos(radialCurrent)) - (d.getWidth() / 2) + insets.left); y = (int) (midY - (b * Math.sin(radialCurrent)) - (d.getHeight() / 2) + insets.top); // Set the component's size and position. c.setBounds(x, y, d.width, d.height); } radialCurrent += radialIncrement; } } }