List of usage examples for java.awt Dimension getWidth
public double getWidth()
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 .ja v a 2 s . 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.igormaznitsa.sciareto.ui.editors.MMDEditor.java
public void topicToCentre(@Nullable final Topic topic) { if (topic != null) { SwingUtilities.invokeLater(new Runnable() { @Override//from w w w. j a v a 2 s .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: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 ww w . j ava 2 s . c o m*/ 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:org.kepler.gui.KeplerGraphFrame.java
/** * Return the size of the visible part of the canvas, in canvas coordinates. * /*from ww w . j av a2 s . c o 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:ubic.basecode.graphics.MatrixDisplay.java
/** * @param g/*from w w w.j av a 2s .c om*/ * @param d */ protected void drawScaleBar(Graphics g, Dimension d, double displayMin, double displayMax) { /* * FIXME this is all a bit of a hack */ g.setColor(Color.white); int upperLeftScalebarGutter = 10; int scaleBarHeight = 10; // these and text height have to total < SCALE_BAR_ROOM int desiredScaleBarLength = (int) Math.min(DEFAULT_SCALE_BAR_WIDTH, d.getWidth()); if (desiredScaleBarLength < 10) { return; } g.drawRect(upperLeftScalebarGutter, upperLeftScalebarGutter, desiredScaleBarLength, upperLeftScalebarGutter); JGradientLabel scalebar = new JGradientLabel(new ColorMap(this.getColorMap()).getPalette()); scalebar.setBackground(Color.white); scalebar.setSize(new Dimension(desiredScaleBarLength, scaleBarHeight)); int actualWidth = scalebar.drawAtLocation(g, upperLeftScalebarGutter, upperLeftScalebarGutter); g.setColor(Color.black); g.drawString(String.format("%.2g", displayMin), 0, upperLeftScalebarGutter + scaleBarHeight + m_fontGutter + g.getFontMetrics().getHeight()); g.drawString(String.format("%.2g", displayMax), actualWidth, upperLeftScalebarGutter + scaleBarHeight + m_fontGutter + g.getFontMetrics().getHeight()); g.drawRect(upperLeftScalebarGutter, upperLeftScalebarGutter, actualWidth, scaleBarHeight); }
From source file:figs.treeVisualization.gui.TimeAxisTree2DPanel.java
/** * Paint this Component using the Tree2DPainter with TimeBars * * @param g the graphics device/*from ww w.ja v a 2 s . co m*/ */ @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g.create(); /** * Enable antialiased graphics. */ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); Dimension currentSize = this.getSize(); /** * Check to see if this component has changed size or if this * is our first time drawing. */ if (this.fDimension == null || !this.fDimension.equals(currentSize) || this.fTreeArea == null || this.fLeftTreeArea == null || this.fEstMaxDateWidth == null) { this.fDimension = currentSize; this.fTreeArea = new Rectangle2D.Double(0, 0, currentSize.getWidth(), currentSize.getHeight()); /** Adjust the width ratio using the maximum date width. */ this.refreshLeafNodes(); this.estimateMaximumDateWidth(g2); if ((this.fEstMaxDateWidth * 2) > (this.fTreeArea.getWidth() * this.fTreeWidthRatio) - this.fTreeArea.getWidth()) { this.fTreeWidthRatio = (this.fTreeArea.getWidth() - (this.fEstMaxDateWidth * 2)) / this.fTreeArea.getWidth(); } /** Make left tree area for tree. */ this.fLeftTreeArea = new Rectangle2D.Double(0, 0, this.fTreeArea.getWidth() * this.fTreeWidthRatio, this.fTreeArea.getHeight()); /** Now, clear the right tree area so that it will be recalculated. */ this.fRightTreeArea = null; } /** Paint the tree. */ this.fTreePainter.drawTree(g2, this.fLeftTreeArea); /** * Check to see if we have calculated the date data. * The order of this is very important. We need to have * called the painter before we can get the coordinates. */ if (this.fLeafNodes.isEmpty() || this.fLeafDates.isEmpty()) /** Just calculate the Leaf data. */ this.refreshLeafNodes(); /** * Draw the date axis and lines to the leaf nodes. */ if (fTopLeafDate != null || fBottomLeafDate != null) { if (this.fRightTreeArea == null) { calculateDateMargins(); this.fRightTreeArea = new Rectangle2D.Double(this.fTreeArea.getWidth() * this.fTreeWidthRatio, this.fTopLeafPt.getY(), this.fTreeArea.getWidth(), this.fBottomLeafPt.getY()); } double cursor = this.fRightTreeArea.getX() + ((this.fRightTreeArea.getWidth() - this.fRightTreeArea.getX()) / 2); drawDateAxis(g2, cursor, this.fRightTreeArea); drawDatesToLeafs(g2, cursor, this.fRightTreeArea); } else { // g2."No TIME INFORMATION AVAILABLE // g2.drawString("NO TIME INFORMATION AVAILABLE", x, y); System.out.println("TimeBarPanel: No time information available!"); } if (this.fMousePressed && this.fMouseSelectionRect != null) { /** Color of line varies depending on image colors. */ g2.setXORMode(Color.white); g2.drawRect(this.fMouseSelectionRect.x, this.fMouseSelectionRect.y, this.fMouseSelectionRect.width - 1, this.fMouseSelectionRect.height - 1); } }
From source file:org.geoserver.wms.legendgraphic.ColorMapLegendCreator.java
private void cycleFooterRows(Graphics2D graphics) { int numRows = this.footerRows.size(), i = 0; footerW = Double.NEGATIVE_INFINITY; for (i = 0; i < numRows; i++) { ////from www .j a va2s .c om // row number i // // color element final Cell cell = this.footerRows.get(i); final Dimension cellDim = cell.getPreferredDimension(graphics); rowH = Math.max(rowH, cellDim.getHeight()); footerW = Math.max(footerW, cellDim.getWidth()); } }
From source file:org.apache.jmeter.visualizers.RespTimeGraphVisualizer.java
public void makeGraph() { Dimension size = graphPanel.getSize(); // canvas size int width = (int) size.getWidth(); int height = (int) size.getHeight(); if (!dynamicGraphSize.isSelected()) { String wstr = graphWidth.getText(); String hstr = graphHeight.getText(); if (wstr.length() != 0) { width = Integer.parseInt(wstr); }/*w w w .j a v a 2s . c o m*/ if (hstr.length() != 0) { height = Integer.parseInt(hstr); } } String yAxisStr = maxValueYAxisLabel.getText(); int maxYAxisScale = yAxisStr.length() == 0 ? 0 : Integer.parseInt(yAxisStr); graphPanel.setData(this.getData()); graphPanel.setTitle(graphTitle.getText()); graphPanel.setMaxYAxisScale(maxYAxisScale); graphPanel.setYAxisLabels(Y_AXIS_LABEL); graphPanel.setYAxisTitle(Y_AXIS_TITLE); graphPanel.setXAxisLabels(getXAxisLabels()); graphPanel.setLegendLabels(getLegendLabels()); graphPanel.setColor(getLinesColors()); graphPanel.setShowGrouping(numberShowGrouping.isSelected()); graphPanel.setLegendPlacement( StatGraphProperties.getPlacementNameMap().get(legendPlacementList.getSelectedItem()).intValue()); graphPanel.setPointShape(StatGraphProperties.getPointShapeMap().get(pointShapeLine.getSelectedItem())); graphPanel.setStrokeWidth(Float.parseFloat((String) strokeWidthList.getSelectedItem())); graphPanel.setTitleFont( new Font(StatGraphProperties.getFontNameMap().get(titleFontNameList.getSelectedItem()), StatGraphProperties.getFontStyleMap().get(titleFontStyleList.getSelectedItem()).intValue(), Integer.parseInt((String) titleFontSizeList.getSelectedItem()))); graphPanel.setLegendFont(new Font(StatGraphProperties.getFontNameMap().get(fontNameList.getSelectedItem()), StatGraphProperties.getFontStyleMap().get(fontStyleList.getSelectedItem()).intValue(), Integer.parseInt((String) fontSizeList.getSelectedItem()))); graphPanel.setHeight(height); graphPanel.setWidth(width); graphPanel.setIncrYAxisScale(getIncrScaleYAxis()); // Draw the graph graphPanel.repaint(); }
From source file:org.geoserver.wms.legendgraphic.ColorMapLegendCreator.java
/** * @param graphics/*from w ww . j a v a2s.c o 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()); } }