List of usage examples for java.awt Dimension getWidth
public double getWidth()
From source file:org.rdv.viz.chart.ChartViz.java
/** * Takes the chart and puts it on the clipboard as an image. *///w w w. ja v a 2 s. c om private void copyChart() { // get the system clipboard Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); // create an image of the chart with the preferred dimensions Dimension preferredDimension = chartPanel.getPreferredSize(); Image image = chart.createBufferedImage((int) preferredDimension.getWidth(), (int) preferredDimension.getHeight()); // wrap image in the transferable and put on the clipboard ImageSelection contents = new ImageSelection(image); clipboard.setContents(contents, null); }
From source file:brainflow.app.toplevel.BrainFlow.java
private void initializeWorkspace() throws Exception { StopWatch watch = new StopWatch(); watch.start("laying out workspace"); log.info("initializing workspace"); //_frame.getDockableBarManager().getMainContainer().setLayout(new BorderLayout()); //_frame.getDockableBarManager().getMainContainer().add(_tabbedPane, BorderLayout.CENTER); //brainFrame.getMainPanel().add(documentPane, BorderLayout.CENTER); brainFrame.getDockingManager().getWorkspace().setLayout(new BorderLayout()); brainFrame.getDockingManager().getWorkspace().add(documentPane, BorderLayout.CENTER); brainFrame.getDockingManager().beginLoadLayoutData(); brainFrame.getDockingManager().setInitSplitPriority(DefaultDockingManager.SPLIT_EAST_WEST_SOUTH_NORTH); JComponent canvas = DisplayManager.get().getSelectedCanvas().getComponent(); canvas.setRequestFocusEnabled(true); canvas.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); watch.stopAndReport("laying out workspace"); watch.start("opening document"); documentPane.setTabPlacement(DocumentPane.BOTTOM); documentPane.openDocument(createCanvasDocument(DisplayManager.get().getSelectedCanvas(), "Canvas-1")); documentPane.setActiveDocument("Canvas-1"); watch.stopAndReport("opening document"); log.info("initializing loading dock"); watch.start("init loading dock"); initLoadingDock();// w w w. j av a2 s .c o m watch.stopAndReport("init loading dock"); log.info("initializing project view"); watch.start("init project view"); initProjectView(); watch.stopAndReport("init project view"); log.info("initializing image table view"); watch.start("init ploadable image table view"); initLoadableImageTableView(); watch.stopAndReport("init ploadable image table view"); log.info("initializing control panel"); watch.start("init control panel"); initControlPanel(); initCoordinatePanel(); watch.stopAndReport("init control panel"); log.info("initializing event monitor"); watch.start("event bus monitor"); initEventBusMonitor(); log.info("initializing log monitor"); watch.stopAndReport("event bus monitor"); watch.start("log monitor"); initLogMonitor(); watch.stopAndReport("log monitor"); watch.start("layout docks"); brainFrame.getDockableBarManager().loadLayoutData(); // brainFrame.toFront(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); brainFrame.setSize((int) screenSize.getWidth(), (int) screenSize.getHeight() - 50); watch.stopAndReport("layout docks"); watch.start("canvas bar"); CanvasBar cbar = new CanvasBar(); canvas.add(cbar.getComponent(), BorderLayout.NORTH); watch.stopAndReport("canvas bar"); brainFrame.getDockingManager().loadLayoutData(); }
From source file:org.photovault.swingui.PhotoCollectionThumbView.java
@Override public Dimension getPreferredSize() { int prefWidth = 0; int prefHeight = 0; if (columnCount > 0) { prefWidth = columnWidth * columnCount; prefHeight = rowHeight;/*from w w w . j a v a 2 s . co m*/ if (photos != null) { prefHeight += rowHeight * (int) (photos.size() / columnCount); } } else if (rowCount > 0) { prefHeight = rowHeight * rowCount; prefWidth = columnWidth; if (photos != null) { prefWidth += columnWidth * (int) (photos.size() / rowCount); } } else { prefWidth = 500; prefHeight = 500; Dimension compSize = getSize(); if (compSize.getWidth() > 0) { int columns = (int) (compSize.getWidth() / columnWidth); prefWidth = columnWidth * columns; prefHeight = rowHeight; if (photos != null) { prefHeight += rowHeight * (int) (photos.size() / columns); } } } // prefHeight += 10; return new Dimension(prefWidth, prefHeight); }
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * Paints the component by drawing the chart to fill the entire component, * but allowing for the insets (which will be non-zero if a border has been * set for this component). To increase performance (at the expense of * memory), an off-screen buffer image can be used. * * @param g the graphics device for drawing on. *///from www . ja v a 2s. c o m public void paintComponent(Graphics g) { super.paintComponent(g); if (this.chart == null) { return; } 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(); this.scaleX = 1.0; this.scaleY = 1.0; if (drawWidth < this.minimumDrawWidth) { this.scaleX = drawWidth / this.minimumDrawWidth; drawWidth = this.minimumDrawWidth; scale = true; } else if (drawWidth > this.maximumDrawWidth) { this.scaleX = drawWidth / this.maximumDrawWidth; drawWidth = this.maximumDrawWidth; scale = true; } if (drawHeight < this.minimumDrawHeight) { this.scaleY = drawHeight / this.minimumDrawHeight; drawHeight = this.minimumDrawHeight; scale = true; } else if (drawHeight > this.maximumDrawHeight) { this.scaleY = drawHeight / this.maximumDrawHeight; drawHeight = this.maximumDrawHeight; scale = true; } Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight); // are we using the chart buffer? if (this.useBuffer) { // if buffer is being refreshed, it needs clearing unless it is // new - use the following flag to track this... boolean clearBuffer = true; // do we need to resize the buffer? if ((this.chartBuffer == null) || (this.chartBufferWidth != available.getWidth()) || (this.chartBufferHeight != available.getHeight())) { this.chartBufferWidth = (int) available.getWidth(); this.chartBufferHeight = (int) available.getHeight(); this.chartBuffer = createImage(this.chartBufferWidth, this.chartBufferHeight); // GraphicsConfiguration gc = g2.getDeviceConfiguration(); // this.chartBuffer = gc.createCompatibleImage( // this.chartBufferWidth, this.chartBufferHeight, // Transparency.TRANSLUCENT); this.refreshBuffer = true; clearBuffer = false; // buffer is new, no clearing required } // do we need to redraw the buffer? if (this.refreshBuffer) { this.refreshBuffer = false; // clear the flag Rectangle2D bufferArea = new Rectangle2D.Double(0, 0, this.chartBufferWidth, this.chartBufferHeight); Graphics2D bufferG2 = (Graphics2D) this.chartBuffer.getGraphics(); if (clearBuffer) { bufferG2.clearRect(0, 0, this.chartBufferWidth, this.chartBufferHeight); } if (scale) { AffineTransform saved = bufferG2.getTransform(); AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); bufferG2.transform(st); this.chart.draw(bufferG2, chartArea, this.anchor, this.info); bufferG2.setTransform(saved); } else { this.chart.draw(bufferG2, bufferArea, this.anchor, this.info); } } g2.drawImage(this.chartBuffer, insets.left, insets.top, this); g2.draw((Shape) activeROI.getShapesList().get(1)); // Dibujar las rois que se encuentren activas } // or redrawing the chart every time... else { AffineTransform saved = g2.getTransform(); g2.translate(insets.left, insets.top); if (scale) { AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); g2.transform(st); } this.chart.draw(g2, chartArea, this.anchor, this.info); g2.drawImage(this.chartBuffer, insets.left, insets.top, this); // Se pintan las Roi activa drawsROIs(g2); g2.setTransform(saved); } g2.dispose(); this.anchor = null; }
From source file:com.aspose.showcase.qrcodegen.web.api.controller.QRCodeManagementController.java
/** * generateQRCode - Main API to generate QR Code * //from w w w . j av a2s .co m * @throws Exception * * */ @RequestMapping(value = "generate", method = RequestMethod.GET, produces = { MediaType.IMAGE_JPEG_VALUE, MediaType.IMAGE_PNG_VALUE, MediaType.IMAGE_GIF_VALUE, MEDIATYPE_IMAGE_TIFF_VALUE, MEDIATYPE_IMAGE_BMP_VALUE }) @ApiOperation(value = "Generate QR Code.") public ResponseEntity<byte[]> generateQRCode( @ApiParam(value = "data", name = "data", required = true) @RequestParam("data") String data, @ApiParam(value = "A user-chosen password that can be used with password-based encryption (PBE) Algo PBEWITHMD5AND128BITAES-CBC-OPENSSL)", name = "passKey", required = false) @RequestParam(required = false, value = "passKey") String passKey, @ApiParam(value = "ForeColor e.g #000000 (Black - RGB(hex))", name = "foreColor", required = false) @RequestParam(required = false, value = "foreColor") String foreColor, @ApiParam(value = "BackgroundColor e.g #FFFFFF (White - RGB(hex))", name = "bgColor", required = false) @RequestParam(required = false, value = "bgColor") String bgColor, @ApiParam(value = "L|M|Q|H - Reed-Solomon error correctionCode Level(from low to high) default=Low", name = "ecc", required = false) @RequestParam(required = false, value = "ecc") String ecc, @ApiParam(value = "Image Size e.g #150x150", name = "size", required = false) @RequestParam(required = false, value = "size") String size, @ApiParam(value = "jpeg|tiff|gif|png|bmp - default=png", name = "format", required = false) @RequestParam(required = false, value = "format") String format, @ApiParam(value = "true|false default=false", name = "download", required = false) @RequestParam(required = false, value = "download") boolean download, @ApiIgnore @Value("#{request.getHeader('" + ACCEPT_HEADER + "')}") String acceptHeaderValue) throws Exception { Assert.isTrue(StringUtils.isNotEmpty(data), "Please provide valid data param."); LOGGER.debug("Accept Header::" + acceptHeaderValue); HttpHeaders responseHeaders = new HttpHeaders(); if (!(StringUtils.isBlank(passKey))) { builder.setCodeText(StringEncryptor.encrypt(data, passKey)); } else { builder.setCodeText(data); } builder.setImageQuality(ImageQualityMode.Default); builder.setSymbologyType(Symbology.QR); builder.setCodeLocation(CodeLocation.None); builder.setForeColor(getColorValue(foreColor, "#000000")); builder.setBackColor(getColorValue(bgColor, "#FFFFFF")); builder.setQRErrorLevel(getErrorCorrectCode(ecc, QRErrorLevel.LevelL)); Dimension imageDimention = geCustomImageSizeDimention(size); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageFormatDTO responseImageTypeDto = getRequestedImageFormat(responseHeaders, acceptHeaderValue, format); long startTime = System.currentTimeMillis(); LOGGER.debug("builder.save Start @ " + startTime); byte[] imageInByte; if (imageDimention != null) { // Set graphics unit builder.setGraphicsUnit(GraphicsUnit.Millimeter); // Set margins builder.getMargins().set(0); builder.setForeColor(getColorValue(foreColor, "#000000")); builder.setBackColor(getColorValue(bgColor, "#FFFFFF")); LOGGER.debug("builder.getGraphicsUnit() ::" + builder.getGraphicsUnit()); // Get BufferedImage with exact bar code only BufferedImage img = builder.getOnlyBarCodeImage(); LOGGER.debug("img.getWidth() : :" + img.getWidth()); LOGGER.debug("img.getHeight() :: " + img.getHeight()); if (imageDimention.getWidth() < img.getWidth()) { imageDimention.width = img.getWidth(); } if (imageDimention.getHeight() < img.getHeight()) { imageDimention.height = img.getHeight(); } BufferedImage img2 = builder.getCustomSizeBarCodeImage(imageDimention, true); MediaType responseType = responseImageTypeDto.getMediaType(); ImageIO.write(img2, responseType.getSubtype(), baos); baos.flush(); imageInByte = baos.toByteArray(); baos.close(); } else { builder.setxDimension(1.0f); builder.setyDimension(1.0f); builder.save(baos, responseImageTypeDto.getBarCodeImageFormat()); baos.flush(); imageInByte = baos.toByteArray(); baos.close(); } long endTime = System.currentTimeMillis(); LOGGER.debug("builder.save took " + (endTime - startTime) + " milliseconds"); if (download) { MediaType responseType = responseImageTypeDto.getMediaType(); responseHeaders.setContentType(responseType); responseHeaders.add("Content-Disposition", "attachment; filename=" + "Aspose_BarCode_QRCodeGen." + responseType.getSubtype()); } return new ResponseEntity<byte[]>(imageInByte, responseHeaders, HttpStatus.CREATED); }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Sets the location of the specified child relative to the location * of the specified parent and then makes it visible. * This method is mainly useful for windows, frames and dialogs. * // w w w. j a v a 2s.c om * @param parent The visible parent. * @param child The child to display. */ public static void setLocationRelativeTo(Component parent, Component child) { if (parent == null || child == null) return; int x = parent.getX() + parent.getWidth(); int y = parent.getY(); int childWidth = child.getWidth(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); if (x + childWidth > screenSize.getWidth()) { if (childWidth < parent.getX()) x = parent.getX() - childWidth; else x = (int) (screenSize.getWidth() - childWidth); } child.setLocation(x, y); child.setVisible(true); }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Sets the location of the specified child relative to the passed * bounds.//from ww w . j a v a 2 s . c o m * This method is mainly useful for windows, frames and dialogs. * * @param parentBounds The bounds of the parent. * @param child The child to display. */ public static void setLocationRelativeTo(Rectangle parentBounds, Component child) { if (child == null) return; if (parentBounds == null) parentBounds = new Rectangle(0, 0, 5, 5); int x = parentBounds.x + parentBounds.width; int y = parentBounds.y; int childWidth = child.getWidth(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); if (x + childWidth > screenSize.getWidth()) { if (childWidth < parentBounds.x) x = parentBounds.x - childWidth; else x = (int) (screenSize.getWidth() - childWidth); } child.setLocation(x, y); child.setVisible(true); }
From source file:shuffle.fwk.service.teams.EditTeamService.java
@SuppressWarnings("serial") private Component makeTeamPanel() { JPanel firstOptionRow = new JPanel(new GridBagLayout()); GridBagConstraints rowc = new GridBagConstraints(); rowc.fill = GridBagConstraints.HORIZONTAL; rowc.weightx = 0.0;/*from ww w . j a va2 s. c o m*/ rowc.weighty = 0.0; rowc.weightx = 1.0; rowc.gridx = 1; stageChooser = new StageChooser(this); firstOptionRow.add(stageChooser, rowc); rowc.weightx = 0.0; JPanel secondOptionRow = new JPanel(new GridBagLayout()); rowc.gridx = 1; JLabel megaLabel = new JLabel(getString(KEY_MEGA_LABEL)); megaLabel.setToolTipText(getString(KEY_MEGA_TOOLTIP)); secondOptionRow.add(megaLabel, rowc); rowc.gridx = 2; megaChooser = new JComboBox<String>(); megaChooser.setToolTipText(getString(KEY_MEGA_TOOLTIP)); secondOptionRow.add(megaChooser, rowc); rowc.gridx = 3; JPanel progressPanel = new JPanel(new BorderLayout()); megaActive = new JCheckBox(getString(KEY_ACTIVE)); megaActive.setSelected(false); megaActive.setToolTipText(getString(KEY_ACTIVE_TOOLTIP)); progressPanel.add(megaActive, BorderLayout.WEST); megaProgressChooser = new JComboBox<Integer>(); progressPanel.add(megaProgressChooser, BorderLayout.EAST); megaProgressChooser.setToolTipText(getString(KEY_MEGA_PROGRESS_TOOLTIP)); secondOptionRow.add(progressPanel, rowc); JPanel thirdOptionRow = new JPanel(new GridBagLayout()); rowc.gridx = 1; JButton clearTeamButton = new JButton(getString(KEY_CLEAR_TEAM)); clearTeamButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { clearTeam(); } }); clearTeamButton.setToolTipText(getString(KEY_CLEAR_TEAM_TOOLTIP)); thirdOptionRow.add(clearTeamButton, rowc); rowc.gridx = 2; woodCheckBox = new JCheckBox(getString(KEY_WOOD)); woodCheckBox.setToolTipText(getString(KEY_WOOD_TOOLTIP)); thirdOptionRow.add(woodCheckBox, rowc); rowc.gridx = 3; metalCheckBox = new JCheckBox(getString(KEY_METAL)); metalCheckBox.setToolTipText(getString(KEY_METAL_TOOLTIP)); thirdOptionRow.add(metalCheckBox, rowc); rowc.gridx = 4; coinCheckBox = new JCheckBox(getString(KEY_COIN)); coinCheckBox.setToolTipText(getString(KEY_COIN_TOOLTIP)); thirdOptionRow.add(coinCheckBox, rowc); rowc.gridx = 5; freezeCheckBox = new JCheckBox(getString(KEY_FREEZE)); freezeCheckBox.setToolTipText(getString(KEY_FREEZE_TOOLTIP)); thirdOptionRow.add(freezeCheckBox, rowc); JPanel topPart = new JPanel(new GridBagLayout()); GridBagConstraints topC = new GridBagConstraints(); topC.fill = GridBagConstraints.HORIZONTAL; topC.weightx = 0.0; topC.weighty = 0.0; topC.gridx = 1; topC.gridy = 1; topC.gridwidth = 1; topC.gridheight = 1; topC.anchor = GridBagConstraints.CENTER; topC.gridy = 1; topPart.add(firstOptionRow, topC); topC.gridy = 2; topPart.add(secondOptionRow, topC); topC.gridy = 3; topPart.add(thirdOptionRow, topC); addOptionListeners(); teamPanel = new JPanel(new WrapLayout()) { // Fix to make it play nice with the scroll bar. @Override public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); d.width = (int) (d.getWidth() - 20); return d; } }; final JScrollPane scrollPane = new JScrollPane(teamPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER) { @Override public Dimension getMinimumSize() { Dimension d = super.getMinimumSize(); d.width = topPart.getMinimumSize().width; d.height = rosterScrollPane.getPreferredSize().height - topPart.getPreferredSize().height; return d; } @Override public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); d.width = topPart.getMinimumSize().width; d.height = rosterScrollPane.getPreferredSize().height - topPart.getPreferredSize().height; return d; } }; scrollPane.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { scrollPane.revalidate(); } }); scrollPane.getVerticalScrollBar().setUnitIncrement(27); JPanel ret = new JPanel(new GridBagLayout()); GridBagConstraints rc = new GridBagConstraints(); rc.fill = GridBagConstraints.VERTICAL; rc.weightx = 0.0; rc.weighty = 0.0; rc.gridx = 1; rc.gridy = 1; rc.insets = new Insets(5, 5, 5, 5); ret.add(topPart, rc); rc.gridy += 1; rc.weightx = 0.0; rc.weighty = 1.0; rc.insets = new Insets(0, 0, 0, 0); ret.add(scrollPane, rc); return ret; }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Sets the location of the specified child relative to the location * of the specified parent and then makes it visible, and size to fill window. * This method is mainly useful for windows, frames and dialogs. * /*from www.j ava 2 s . co m*/ * @param parentBounds The bounds of the visible parent. * @param child The child to display. * @param max The maximum size of the window. */ public static void setLocationRelativeToAndSizeToWindow(Rectangle parentBounds, Component child, Dimension max) { if (child == null) return; if (parentBounds == null) parentBounds = new Rectangle(0, 0, 5, 5); if (max == null) max = new Dimension(5, 5); int x = (int) (parentBounds.getX() + parentBounds.getWidth()); int y = (int) parentBounds.getY(); int childWidth = child.getWidth(); int childHeight = child.getHeight(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); if (x + childWidth > screenSize.getWidth()) { if (childWidth < parentBounds.getX()) x = (int) (parentBounds.getX()) - childWidth; else x = (int) (screenSize.getWidth() - childWidth); } child.setLocation(x, y); int newHeight = (int) screenSize.getHeight() - y - 10; int newWidth = (int) screenSize.getWidth() - x - 10; if (newWidth > childWidth) childWidth = newWidth; if (newHeight > childHeight) childHeight = newHeight; if (childWidth > max.getWidth()) childWidth = (int) max.getWidth(); if (childHeight > max.getHeight()) childHeight = (int) max.getHeight(); child.setSize(childWidth, childHeight); child.setVisible(true); }
From source file:org.jajuk.ui.views.CoverView.java
@Override public void componentResized(final ComponentEvent e) { Dimension dim = getSize(); if (dim.getHeight() <= 0 || dim.getWidth() <= 0) { return;/* w w w . j a va2s . c om*/ } final long lCurrentDate = System.currentTimeMillis(); // adjusting code if (lCurrentDate - lDateLastResize < 500) { // Do consider only one event every // 500 ms to avoid race conditions and lead to unexpected states (verified) return; } lDateLastResize = lCurrentDate; Log.debug("Cover resized, view=" + getID() + " size=" + getSize()); // Run this in another thread to accelerate the component resize events processing and filter by time new Thread() { @Override public void run() { if (fileReference == null) { // regular cover view if (QueueModel.isStopped()) { update(new JajukEvent(JajukEvents.ZERO)); } // check if a track has already been launched else if (QueueModel.isPlayingRadio()) { update(new JajukEvent(JajukEvents.WEBRADIO_LAUNCHED, ObservationManager.getDetailsLastOccurence(JajukEvents.WEBRADIO_LAUNCHED))); // If the view is displayed for the first time, a ComponentResized event is launched at its first display but // we want to perform the full process : update past launches files (FILE_LAUNCHED). // But if it is no more the initial resize event, we only want to refresh the cover, not the full story. } else if (!initEvent) { displayCurrentCover(); } else { update(new JajukEvent(JajukEvents.FILE_LAUNCHED)); } } else { // cover view used as dialog update(new JajukEvent(JajukEvents.COVER_NEED_REFRESH)); } // It will never more be the first time ... CoverView.this.initEvent = false; } }.start(); }