List of usage examples for java.awt Graphics2D dispose
public abstract void dispose();
From source file:edu.emory.library.tast.images.ThumbnailServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // location of images String baseUrl = AppConfig.getConfiguration().getString(AppConfig.IMAGES_URL); baseUrl = StringUtils.trimEnd(baseUrl, '/'); // image name and size String imageFileName = request.getParameter("i"); int thumbnailWidth = Integer.parseInt(request.getParameter("w")); int thumbnailHeight = Integer.parseInt(request.getParameter("h")); // image dir/*from w w w .j a v a 2s. c o m*/ String imagesDir = AppConfig.getConfiguration().getString(AppConfig.IMAGES_DIRECTORY); // create the thumbnail name String thumbnailFileName = FilenameUtils.getBaseName(imageFileName) + "-" + thumbnailWidth + "x" + thumbnailHeight + ".png"; // does it exist? File thumbnailFile = new File(imagesDir, thumbnailFileName); if (thumbnailFile.exists()) { response.sendRedirect(baseUrl + "/" + thumbnailFileName); return; } // read the image File imageFile = new File(imagesDir, imageFileName); BufferedImage image = ImageIO.read(imageFile); int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); BufferedImage imageCopy = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); imageCopy.getGraphics().drawImage(image, 0, 0, imageWidth, imageHeight, 0, 0, imageWidth, imageHeight, null); // height is calculated automatically if (thumbnailHeight == 0) thumbnailHeight = (int) ((double) thumbnailWidth / (double) imageWidth * (double) imageHeight); // width is calculated automatically if (thumbnailWidth == 0) thumbnailWidth = (int) ((double) thumbnailHeight / (double) imageHeight * (double) imageWidth); // create an empty thumbnail BufferedImage thumbnail = new BufferedImage(thumbnailWidth, thumbnailHeight, BufferedImage.TYPE_INT_RGB); Graphics2D gr = thumbnail.createGraphics(); gr.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); gr.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // determine the piece of the image which we want to clip int clipX1, clipX2, clipY1, clipY2; if (imageWidth * thumbnailHeight > thumbnailWidth * imageHeight) { int clipWidth = (int) Math .round(((double) thumbnailWidth / (double) thumbnailHeight) * (double) imageHeight); int imgCenterX = imageWidth / 2; clipX1 = imgCenterX - clipWidth / 2; clipX2 = imgCenterX + clipWidth / 2; clipY1 = 0; clipY2 = imageHeight; } else { int clipHeight = (int) Math .round(((double) thumbnailHeight / (double) thumbnailWidth) * (double) imageWidth); int imgCenterY = imageHeight / 2; clipX1 = 0; clipX2 = imageWidth; clipY1 = imgCenterY - clipHeight / 2; clipY2 = imgCenterY + clipHeight / 2; } // we filter the image first to get better results when shrinking if (2 * thumbnailWidth < clipX2 - clipX1 || 2 * thumbnailHeight < clipY2 - clipY1) { int kernelDimX = (clipX2 - clipX1) / (thumbnailWidth); int kernelDimY = (clipY2 - clipY1) / (thumbnailHeight); if (kernelDimX % 2 == 0) kernelDimX++; if (kernelDimY % 2 == 0) kernelDimY++; if (kernelDimX < kernelDimY) kernelDimX = kernelDimY; if (kernelDimY < kernelDimX) kernelDimY = kernelDimX; float[] blurKernel = new float[kernelDimX * kernelDimY]; for (int i = 0; i < kernelDimX; i++) for (int j = 0; j < kernelDimY; j++) blurKernel[i * kernelDimX + j] = 1.0f / (float) (kernelDimX * kernelDimY); BufferedImageOp op = new ConvolveOp(new Kernel(kernelDimX, kernelDimY, blurKernel)); imageCopy = op.filter(imageCopy, null); } // draw the thumbnail gr.drawImage(imageCopy, 0, 0, thumbnailWidth, thumbnailHeight, clipX1, clipY1, clipX2, clipY2, null); // and we are done gr.dispose(); ImageIO.write(thumbnail, "png", thumbnailFile); // redirect to it response.sendRedirect(baseUrl + "/" + thumbnailFileName); }
From source file:krasa.cpu.CpuUsagePanel.java
@Override public void paintComponent(final Graphics g) { final boolean pressed = getModel().isPressed(); final boolean stateChanged = myWasPressed != pressed; myWasPressed = pressed;//from w w w .ja v a2s.c o m Image bufferedImage = myBufferedImage; if (bufferedImage == null || stateChanged) { final Dimension size = getSize(); final Insets insets = getInsets(); bufferedImage = UIUtil.createImage(g, size.width, size.height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = (Graphics2D) bufferedImage.getGraphics().create(); final int max = 100; int system = CpuUsageManager.system; int process = CpuUsageManager.process; final int otherProcesses = system - process; final int totalBarLength = size.width - insets.left - insets.right - 3; final int processUsageBarLength = totalBarLength * process / max; final int otherProcessesUsageBarLength = totalBarLength * otherProcesses / max; final int barHeight = Math.max(size.height, getFont().getSize() + 2); final int yOffset = (size.height - barHeight) / 2; final int xOffset = insets.left; // background g2.setColor(UIUtil.getPanelBackground()); g2.fillRect(0, 0, size.width, size.height); // gauge (ide) g2.setColor(ideColor); g2.fillRect(xOffset + 1, yOffset, processUsageBarLength + 1, barHeight); // gauge (system) g2.setColor(systemColor); g2.fillRect(xOffset + processUsageBarLength + 1, yOffset, otherProcessesUsageBarLength + 1, barHeight); // label g2.setFont(getFont()); // final String info = CpuUsageBundle.message("cpu.usage.panel.message.text", CpuUsageManager.process, // CpuUsageManager.system); final String info = fixedLengthString(String.valueOf(process), 3) + "% / " + fixedLengthString(String.valueOf(system), 3) + "%"; final FontMetrics fontMetrics = g.getFontMetrics(); final int infoWidth = fontMetrics.charsWidth(info.toCharArray(), 0, info.length()); final int infoHeight = fontMetrics.getAscent(); UISettings.setupAntialiasing(g2); final Color fg = pressed ? UIUtil.getLabelDisabledForeground() : JBColor.foreground(); g2.setColor(fg); g2.drawString(info, xOffset + (totalBarLength - infoWidth) / 2, yOffset + infoHeight + (barHeight - infoHeight) / 2 - 1); // border g2.setStroke(new BasicStroke(1)); g2.setColor(JBColor.GRAY); g2.drawRect(0, 0, size.width - 2, size.height - 1); g2.dispose(); myBufferedImage = bufferedImage; } draw(g, bufferedImage); }
From source file:org.rdv.viz.chart.ChartPanel.java
/** * Handles a 'mouse released' event. On Windows, we need to check if this * is a popup trigger, but only if we haven't already been tracking a zoom * rectangle.//from w w w .ja v a2 s . c o m * * @param e information about the event. */ public void mouseReleased(MouseEvent e) { if (this.zoomRectangle != null) { boolean hZoom = false; boolean vZoom = false; if (this.orientation == PlotOrientation.HORIZONTAL) { hZoom = this.rangeZoomable; vZoom = this.domainZoomable; } else { hZoom = this.domainZoomable; vZoom = this.rangeZoomable; } boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.zoomPoint.getX()) >= this.zoomTriggerDistance; boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.zoomPoint.getY()) >= this.zoomTriggerDistance; if (zoomTrigger1 || zoomTrigger2) { if ((hZoom && (e.getX() < this.zoomPoint.getX())) || (vZoom && (e.getY() < this.zoomPoint.getY()))) { // restore the the range for the domain and range axis from // the history Plot p = this.chart.getPlot(); if (p instanceof XYPlot && !rangeHistory.empty()) { XYPlot xyPlot = (XYPlot) p; ValueAxis rangeAxis = xyPlot.getRangeAxis(); ValueAxis domainAxis = xyPlot.getDomainAxis(); if (rangeAxis.getRange().equals(rangeHistory.pop()) && domainAxis.getRange().equals(rangeHistory.pop())) { xyPlot.getRangeAxis().setRange(rangeHistory.pop()); xyPlot.getDomainAxis().setRange(rangeHistory.pop()); if (!rangeHistory.empty()) { rangeHistory.push(domainAxis.getRange()); rangeHistory.push(rangeAxis.getRange()); } } else { rangeHistory.clear(); restoreAutoBounds(); } } else { restoreAutoBounds(); } } else { double x, y, w, h; Rectangle2D screenDataArea = getScreenDataArea((int) this.zoomPoint.getX(), (int) this.zoomPoint.getY()); double maxX = screenDataArea.getMaxX(); double maxY = screenDataArea.getMaxY(); // for mouseReleased event, (horizontalZoom || verticalZoom) // will be true, so we can just test for either being false; // otherwise both are true if (!vZoom) { x = this.zoomPoint.getX(); y = screenDataArea.getMinY(); w = Math.min(this.zoomRectangle.getWidth(), maxX - this.zoomPoint.getX()); h = screenDataArea.getHeight(); } else if (!hZoom) { x = screenDataArea.getMinX(); y = this.zoomPoint.getY(); w = screenDataArea.getWidth(); h = Math.min(this.zoomRectangle.getHeight(), maxY - this.zoomPoint.getY()); } else { x = this.zoomPoint.getX(); y = this.zoomPoint.getY(); w = Math.min(this.zoomRectangle.getWidth(), maxX - this.zoomPoint.getX()); h = Math.min(this.zoomRectangle.getHeight(), maxY - this.zoomPoint.getY()); } Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h); zoom(zoomArea); } this.zoomPoint = null; this.zoomRectangle = null; } else { // Erase the zoom rectangle Graphics2D g2 = (Graphics2D) getGraphics(); drawZoomRectangle(g2); g2.dispose(); this.zoomPoint = null; this.zoomRectangle = null; } } else if (e.isPopupTrigger()) { if (this.popup != null) { displayPopupMenu(e.getX(), e.getY()); } } }
From source file:edu.ku.brc.ui.UIRegistry.java
/** * Writes a string message into the BufferedImage on GlassPane and sets the main component's visibility to false and * shows the GlassPane./* w ww. ja v a 2s. c om*/ * @param msg the message * @param pointSize the Font point size for the message to be writen in */ public static GhostGlassPane writeGlassPaneMsg(final String msg, final int pointSize) { GhostGlassPane glassPane = getGlassPane(); if (glassPane != null) { glassPane.finishDnD(); } glassPane.setMaskingEvents(true); Component mainComp = get(MAINPANE); if (mainComp != null && glassPane != null) { JFrame frame = (JFrame) get(FRAME); frameRect = frame.getBounds(); int y = 0; JMenuBar menuBar = null; Dimension size = mainComp.getSize(); if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { menuBar = frame.getJMenuBar(); size.height += menuBar.getSize().height; y += menuBar.getSize().height; } BufferedImage buffer = getGlassPaneBufferedImage(size.width, size.height); Graphics2D g2 = buffer.createGraphics(); if (menuBar != null) { menuBar.paint(g2); } g2.translate(0, y); mainComp.paint(g2); g2.translate(0, -y); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(new Color(255, 255, 255, 128)); g2.fillRect(0, 0, size.width, size.height); g2.setFont(new Font((new JLabel()).getFont().getName(), Font.BOLD, pointSize)); FontMetrics fm = g2.getFontMetrics(); int tw = fm.stringWidth(msg); int th = fm.getHeight(); int tx = (size.width - tw) / 2; int ty = (size.height - th) / 2; int expand = 20; int arc = expand * 2; g2.setColor(Color.WHITE); g2.fillRoundRect(tx - (expand / 2), ty - fm.getAscent() - (expand / 2), tw + expand, th + expand, arc, arc); g2.setColor(Color.DARK_GRAY); g2.drawRoundRect(tx - (expand / 2), ty - fm.getAscent() - (expand / 2), tw + expand, th + expand, arc, arc); g2.setColor(Color.BLACK); g2.drawString(msg, tx, ty); g2.dispose(); glassPane.setImage(buffer); glassPane.setPoint(new Point(0, 0), GhostGlassPane.ImagePaintMode.ABSOLUTE); glassPane.setOffset(new Point(0, 0)); glassPane.setVisible(true); mainComp.setVisible(false); //Using paintImmediately fixes problems with glass pane not showing, such as for workbench saves initialed //during workbench or app shutdown. Don't know if there is a better way to fix it. //glassPane.repaint(); glassPane.paintImmediately(glassPane.getBounds()); showingGlassPane = true; } return glassPane; }
From source file:com.dlya.facturews.DlyaPdfExporter2.java
/** * *//*from w w w. java2 s . c o m*/ public void exportImage(JRPrintImage printImage) throws DocumentException, IOException, JRException { if (printImage.getModeValue() == ModeEnum.OPAQUE) { pdfContentByte.setRGBColorFill(printImage.getBackcolor().getRed(), printImage.getBackcolor().getGreen(), printImage.getBackcolor().getBlue()); pdfContentByte.rectangle(printImage.getX() + getOffsetX(), jasperPrint.getPageHeight() - printImage.getY() - getOffsetY(), printImage.getWidth(), -printImage.getHeight()); pdfContentByte.fill(); } int topPadding = printImage.getLineBox().getTopPadding().intValue(); int leftPadding = printImage.getLineBox().getLeftPadding().intValue(); int bottomPadding = printImage.getLineBox().getBottomPadding().intValue(); int rightPadding = printImage.getLineBox().getRightPadding().intValue(); int availableImageWidth = printImage.getWidth() - leftPadding - rightPadding; availableImageWidth = (availableImageWidth < 0) ? 0 : availableImageWidth; int availableImageHeight = printImage.getHeight() - topPadding - bottomPadding; availableImageHeight = (availableImageHeight < 0) ? 0 : availableImageHeight; Renderable renderer = printImage.getRenderable(); if (renderer != null && availableImageWidth > 0 && availableImageHeight > 0) { if (renderer.getTypeValue() == RenderableTypeEnum.IMAGE) { // Image renderers are all asked for their image data at some point. // Better to test and replace the renderer now, in case of lazy load error. renderer = RenderableUtil.getInstance(jasperReportsContext).getOnErrorRendererForImageData(renderer, printImage.getOnErrorTypeValue()); } } else { renderer = null; } if (renderer != null) { int xoffset = 0; int yoffset = 0; Chunk chunk = null; float scaledWidth = availableImageWidth; float scaledHeight = availableImageHeight; if (renderer.getTypeValue() == RenderableTypeEnum.IMAGE) { com.lowagie.text.Image image = null; float xalignFactor = getXAlignFactor(printImage); float yalignFactor = getYAlignFactor(printImage); switch (printImage.getScaleImageValue()) { case CLIP: { // Image load might fail, from given image data. // Better to test and replace the renderer now, in case of lazy load error. renderer = RenderableUtil.getInstance(jasperReportsContext) .getOnErrorRendererForDimension(renderer, printImage.getOnErrorTypeValue()); if (renderer == null) { break; } int normalWidth = availableImageWidth; int normalHeight = availableImageHeight; Dimension2D dimension = renderer.getDimension(jasperReportsContext); if (dimension != null) { normalWidth = (int) dimension.getWidth(); normalHeight = (int) dimension.getHeight(); } xoffset = (int) (xalignFactor * (availableImageWidth - normalWidth)); yoffset = (int) (yalignFactor * (availableImageHeight - normalHeight)); int minWidth = Math.min(normalWidth, availableImageWidth); int minHeight = Math.min(normalHeight, availableImageHeight); BufferedImage bi = new BufferedImage(minWidth, minHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g = bi.createGraphics(); if (printImage.getModeValue() == ModeEnum.OPAQUE) { g.setColor(printImage.getBackcolor()); g.fillRect(0, 0, minWidth, minHeight); } renderer.render(jasperReportsContext, g, new java.awt.Rectangle((xoffset > 0 ? 0 : xoffset), (yoffset > 0 ? 0 : yoffset), normalWidth, normalHeight)); g.dispose(); xoffset = (xoffset < 0 ? 0 : xoffset); yoffset = (yoffset < 0 ? 0 : yoffset); //awtImage = bi.getSubimage(0, 0, minWidth, minHeight); //image = com.lowagie.text.Image.getInstance(awtImage, printImage.getBackcolor()); image = com.lowagie.text.Image.getInstance(bi, null); break; } case FILL_FRAME: { if (printImage.isUsingCache() && loadedImagesMap.containsKey(renderer)) { image = loadedImagesMap.get(renderer); } else { try { image = com.lowagie.text.Image.getInstance(renderer.getImageData(jasperReportsContext)); imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0); } catch (Exception e) { JRImageRenderer tmpRenderer = JRImageRenderer.getOnErrorRendererForImage( jasperReportsContext, JRImageRenderer.getInstance(renderer.getImageData(jasperReportsContext)), printImage.getOnErrorTypeValue()); if (tmpRenderer == null) { break; } java.awt.Image awtImage = tmpRenderer.getImage(jasperReportsContext); image = com.lowagie.text.Image.getInstance(awtImage, null); } if (printImage.isUsingCache()) { loadedImagesMap.put(renderer, image); } } image.scaleAbsolute(availableImageWidth, availableImageHeight); break; } case RETAIN_SHAPE: default: { if (printImage.isUsingCache() && loadedImagesMap.containsKey(renderer)) { image = loadedImagesMap.get(renderer); } else { try { image = com.lowagie.text.Image.getInstance(renderer.getImageData(jasperReportsContext)); imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0); } catch (Exception e) { JRImageRenderer tmpRenderer = JRImageRenderer.getOnErrorRendererForImage( jasperReportsContext, JRImageRenderer.getInstance(renderer.getImageData(jasperReportsContext)), printImage.getOnErrorTypeValue()); if (tmpRenderer == null) { break; } java.awt.Image awtImage = tmpRenderer.getImage(jasperReportsContext); image = com.lowagie.text.Image.getInstance(awtImage, null); } if (printImage.isUsingCache()) { loadedImagesMap.put(renderer, image); } } image.scaleToFit(availableImageWidth, availableImageHeight); xoffset = (int) (xalignFactor * (availableImageWidth - image.plainWidth())); yoffset = (int) (yalignFactor * (availableImageHeight - image.plainHeight())); xoffset = (xoffset < 0 ? 0 : xoffset); yoffset = (yoffset < 0 ? 0 : yoffset); break; } } if (image != null) { chunk = new Chunk(image, 0, 0); scaledWidth = image.scaledWidth(); scaledHeight = image.scaledHeight(); } } else { double normalWidth = availableImageWidth; double normalHeight = availableImageHeight; double displayWidth = availableImageWidth; double displayHeight = availableImageHeight; double ratioX = 1f; double ratioY = 1f; Rectangle2D clip = null; Dimension2D dimension = renderer.getDimension(jasperReportsContext); if (dimension != null) { normalWidth = dimension.getWidth(); normalHeight = dimension.getHeight(); displayWidth = normalWidth; displayHeight = normalHeight; float xalignFactor = getXAlignFactor(printImage); float yalignFactor = getYAlignFactor(printImage); switch (printImage.getScaleImageValue()) { case CLIP: { xoffset = (int) (xalignFactor * (availableImageWidth - normalWidth)); yoffset = (int) (yalignFactor * (availableImageHeight - normalHeight)); clip = new Rectangle2D.Double(-xoffset, -yoffset, availableImageWidth, availableImageHeight); break; } case FILL_FRAME: { ratioX = availableImageWidth / normalWidth; ratioY = availableImageHeight / normalHeight; normalWidth *= ratioX; normalHeight *= ratioY; xoffset = 0; yoffset = 0; break; } case RETAIN_SHAPE: default: { ratioX = availableImageWidth / normalWidth; ratioY = availableImageHeight / normalHeight; ratioX = ratioX < ratioY ? ratioX : ratioY; ratioY = ratioX; normalWidth *= ratioX; normalHeight *= ratioY; xoffset = (int) (xalignFactor * (availableImageWidth - normalWidth)); yoffset = (int) (yalignFactor * (availableImageHeight - normalHeight)); break; } } } PdfTemplate template = pdfContentByte.createTemplate((float) displayWidth, (float) displayHeight); Graphics2D g = forceSvgShapes ? template.createGraphicsShapes((float) displayWidth, (float) displayHeight) : template.createGraphics(availableImageWidth, availableImageHeight, new LocalFontMapper()); if (clip != null) { g.setClip(clip); } if (printImage.getModeValue() == ModeEnum.OPAQUE) { g.setColor(printImage.getBackcolor()); g.fillRect(0, 0, (int) displayWidth, (int) displayHeight); } Rectangle2D rectangle = new Rectangle2D.Double(0, 0, displayWidth, displayHeight); renderer.render(jasperReportsContext, g, rectangle); g.dispose(); pdfContentByte.saveState(); pdfContentByte.addTemplate(template, (float) ratioX, 0f, 0f, (float) ratioY, printImage.getX() + getOffsetX() + xoffset, jasperPrint.getPageHeight() - printImage.getY() - getOffsetY() - (int) normalHeight - yoffset); pdfContentByte.restoreState(); Image image = getPxImage(); image.scaleAbsolute(availableImageWidth, availableImageHeight); chunk = new Chunk(image, 0, 0); } /* image.setAbsolutePosition( printImage.getX() + offsetX + borderOffset, jasperPrint.getPageHeight() - printImage.getY() - offsetY - image.scaledHeight() - borderOffset ); pdfContentByte.addImage(image); */ if (chunk != null) { setAnchor(chunk, printImage, printImage); setHyperlinkInfo(chunk, printImage); //tagHelper.startImage(printImage); ColumnText colText = new ColumnText(pdfContentByte); int upperY = jasperPrint.getPageHeight() - printImage.getY() - topPadding - getOffsetY() - yoffset; int lowerX = printImage.getX() + leftPadding + getOffsetX() + xoffset; colText.setSimpleColumn(new Phrase(chunk), lowerX, upperY - scaledHeight, lowerX + scaledWidth, upperY, scaledHeight, Element.ALIGN_LEFT); colText.go(); //tagHelper.endImage(); } } if (printImage.getLineBox().getTopPen().getLineWidth().floatValue() <= 0f && printImage.getLineBox().getLeftPen().getLineWidth().floatValue() <= 0f && printImage.getLineBox().getBottomPen().getLineWidth().floatValue() <= 0f && printImage.getLineBox().getRightPen().getLineWidth().floatValue() <= 0f) { if (printImage.getLinePen().getLineWidth().floatValue() > 0f) { exportPen(printImage.getLinePen(), printImage); } } else { /* */ exportBox(printImage.getLineBox(), printImage); } }
From source file:org.fhcrc.cpl.viewer.gui.MRMDialog.java
public void menuItemSaveImage_actionPerformed(ActionEvent event) { int returnVal = _imageOutputFileChooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File imfi = _imageOutputFileChooser.getSelectedFile(); if (imfi != null && !imfi.toString().toUpperCase().endsWith(".PNG")) { imfi = new File(imfi.toString() + ".png"); }//from w w w . j a va 2 s. com if (imfi == null) { ApplicationContext.infoMessage("Cannot save chromatogram image."); } else { int width = daughterContainerPanel.getWidth(); int height = daughterContainerPanel.getHeight(); BufferedImage dataForFile = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = dataForFile.createGraphics(); daughterContainerPanel.paint(g2d); g2d.dispose(); try { ImageIO.write(dataForFile, "png", imfi); } catch (Exception e) { ApplicationContext.infoMessage("Cannot save chromatogram image: " + e); buttonPostPressTasks(); } } } else { ApplicationContext.infoMessage("Cannot save chromatogram image to '" + _imageOutputFileChooser.getName() + "', returnVal=" + returnVal); } buttonPostPressTasks(); }
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * Handles a 'mouse dragged' event./* ww w . ja va 2 s .c o m*/ * * @param e the mouse event. */ public void mouseDragged(MouseEvent e) { // if the popup menu has already been triggered, then ignore dragging... if (this.popup != null && this.popup.isShowing()) { return; } // if no initial zoom point was set, ignore dragging... if (this.zoomPoint == null) { return; } Graphics2D g2 = (Graphics2D) getGraphics(); // Erase the previous zoom rectangle (if any)... drawRectangle(g2); boolean hZoom = false; boolean vZoom = false; if (this.orientation == PlotOrientation.HORIZONTAL) { hZoom = this.rangeZoomable; vZoom = this.domainZoomable; } else { hZoom = this.domainZoomable; vZoom = this.rangeZoomable; } Rectangle2D scaledDataArea = getScreenDataArea((int) this.zoomPoint.getX(), (int) this.zoomPoint.getY()); if (hZoom && vZoom) { // selected rectangle shouldn't extend outside the data area... double xmax = Math.min(e.getX(), scaledDataArea.getMaxX()); double ymax = Math.min(e.getY(), scaledDataArea.getMaxY()); this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), this.zoomPoint.getY(), xmax - this.zoomPoint.getX(), ymax - this.zoomPoint.getY()); } else if (hZoom) { double xmax = Math.min(e.getX(), scaledDataArea.getMaxX()); this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), scaledDataArea.getMinY(), xmax - this.zoomPoint.getX(), scaledDataArea.getHeight()); } else if (vZoom) { double ymax = Math.min(e.getY(), scaledDataArea.getMaxY()); this.zoomRectangle = new Rectangle2D.Double(scaledDataArea.getMinX(), this.zoomPoint.getY(), scaledDataArea.getWidth(), ymax - this.zoomPoint.getY()); } // Draw the new zoom rectangle... drawRectangle(g2); g2.dispose(); }
From source file:edu.ku.brc.specify.ui.containers.ContainerTreeRenderer.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Dimension d = getSize();/* w ww . j ava 2s.c o m*/ //System.out.println("d: "+d+" "+g.getClipBounds()); Graphics2D g2d = (Graphics2D) g.create(); g2d.setRenderingHints(renderingHints); FontMetrics fm = g2d.getFontMetrics(); int imgY = img1 != null ? (d.height - 24) / 2 : 0; int imgY2 = img1 != null ? (d.height - 16) / 2 : 0; int txtY = ((d.height - fm.getHeight()) / 2) + fm.getAscent(); int x = 0; Color color = g2d.getColor(); if (img1 != null) { g2d.drawImage(img1.getImage(), x, imgY, null); x += img1.getIconWidth(); } int iconInx = 0; if (txt1 != null) { x += getIconTextGap(); g2d.setColor(getForeground()); g.drawString(txt1, x, txtY); x += fm.stringWidth(txt1); g2d.setColor(color); } if (isContainer) { //if (isSelected && isEditable) //{ // x += drawIcon(g2d, x, imgY2, delImgIcon, iconInx++); // Delete the container //} if (hasColObj) { if (img2 != null) { x += 1; x += iconSep; g2d.drawImage(img2.getImage(), x, imgY2, null); x += img2.getIconWidth(); } if (txt2 != null) { x += getIconTextGap(); g2d.setColor(getForeground()); g.drawString(txt2, x, txtY); x += fm.stringWidth(txt2); g2d.setColor(color); } if (isSelected) { x += iconSep; x += drawIcon(g2d, x, imgY2, viewImgIcon, iconInx++); if (isEditable) { x += drawIcon(g2d, x, imgY2, delImgIcon, iconInx++); } } } else if (isSelected) // No Col Obj { x += iconSep; x += drawIcon(g2d, x, imgY2, schImgIcon, iconInx++); x += drawIcon(g2d, x, imgY2, addImgIcon, iconInx++); } } else if (isSelected) { x += iconSep; x += drawIcon(g2d, x, imgY2, viewImgIcon, iconInx++); // View for Collection Object //if (!isViewMode) //{ // x += iconSep; // x += drawIcon(g2d, x, imgY2, delImgIcon, iconInx++); // Delete for Collection Object //} } g2d.dispose(); }
From source file:com.moviejukebox.plugin.DefaultImagePlugin.java
/** * Draw the TV and HD logos onto the image * * @param movie The source movie/* www. ja v a 2s . co m*/ * @param bi The image to draw on * @param imageType * @param beforeMainOverlay * @return The new image with the added logos */ @SuppressWarnings("deprecation") protected BufferedImage drawLogos(Movie movie, BufferedImage bi, String imageType, boolean beforeMainOverlay) { BufferedImage newBi = bi; // Issue 1937: Overlay configuration XML if (xmlOverlay) { for (LogoOverlay layer : overlayLayers) { if (layer.isBefore() != beforeMainOverlay) { continue; } boolean flag = false; List<StateOverlay> states = new ArrayList<>(); for (String name : layer.getNames()) { String value = Movie.UNKNOWN; if (checkLogoEnabled(name)) { if ("set".equalsIgnoreCase(name)) { value = ((THUMBNAIL.equalsIgnoreCase(imageType) || BANNER.equalsIgnoreCase(imageType) || FOOTER.equalsIgnoreCase(imageType)) && movie.isSetMaster()) ? countSetLogo ? Integer.toString(movie.getSetSize()) : TRUE : countSetLogo ? "0" : FALSE; } else if ("TV".equalsIgnoreCase(name)) { value = movie.isTVShow() ? TRUE : FALSE; } else if ("HD".equalsIgnoreCase(name)) { value = movie.isHD() ? highdefDiff ? movie.isHD1080() ? "hd1080" : "hd720" : "hd" : FALSE; } else if (SUBTITLE.equalsIgnoreCase(name) || "ST".equalsIgnoreCase(name)) { value = (StringTools.isNotValidString(movie.getSubtitles()) || "NO".equalsIgnoreCase(movie.getSubtitles())) ? FALSE : (blockSubTitle ? movie.getSubtitles() : TRUE); } else if (LANGUAGE.equalsIgnoreCase(name)) { value = movie.getLanguage(); } else if (RATING.equalsIgnoreCase(name)) { value = ((!movie.isTVShow() && !movie.isSetMaster()) || (movie.isTVShow() && movie.isSetMaster())) ? Integer.toString(realRating ? movie.getRating() : (int) (Math.floor(movie.getRating() / 10) * 10)) : Movie.UNKNOWN; } else if (VIDEOSOURCE.equalsIgnoreCase(name) || SOURCE.equalsIgnoreCase(name) || "VS".equalsIgnoreCase(name)) { value = movie.getVideoSource(); } else if ("videoout".equalsIgnoreCase(name) || "out".equalsIgnoreCase(name) || "VO".equalsIgnoreCase(name)) { value = movie.getVideoOutput(); } else if (VIDEOCODEC.equalsIgnoreCase(name) || VCODEC.equalsIgnoreCase(name) || "VC".equalsIgnoreCase(name)) { value = movie.getVideoCodec(); } else if (AUDIOCODEC.equalsIgnoreCase(name) || ACODEC.equalsIgnoreCase(name) || "AC".equalsIgnoreCase(name)) { value = movie.getAudioCodec(); if (!blockAudioCodec) { int pos = value.indexOf(Movie.SPACE_SLASH_SPACE); if (pos > -1) { value = value.substring(0, pos); } pos = value.indexOf(" ("); if (pos > -1) { value = value.substring(0, pos); } } else { while (value.contains(" (") && value.indexOf(" (") < value.indexOf(')')) { value = value.substring(0, value.indexOf(" (")) + value.substring(value.indexOf(')') + 1); } } } else if (AUDIOLANG.equalsIgnoreCase(name) || ALANG.equalsIgnoreCase(name) || "AL".equalsIgnoreCase(name)) { value = ""; for (String tmp : movie.getAudioCodec().split(Movie.SPACE_SLASH_SPACE)) { if (tmp.contains(" (") && tmp.indexOf(" (") < tmp.indexOf(')')) { tmp = tmp.substring(tmp.indexOf(" (") + 2, tmp.indexOf(')')); } else { tmp = Movie.UNKNOWN; } if (!blockAudioLang) { value = tmp; break; } if (StringUtils.isNotBlank(value)) { value += Movie.SPACE_SLASH_SPACE; } value += tmp; } if (StringTools.isNotValidString(value)) { value = Movie.UNKNOWN; } } else if (name.equalsIgnoreCase(AUDIOCHANNELS) || name.equalsIgnoreCase(CHANNELS)) { value = movie.getAudioChannels(); if (!blockAudioChannels) { int pos = value.indexOf(Movie.SPACE_SLASH_SPACE); if (pos > -1) { value = value.substring(0, pos); } } } else if (CONTAINER.equalsIgnoreCase(name)) { value = movie.getContainer(); } else if (ASPECT.equalsIgnoreCase(name)) { value = movie.getAspectRatio(); } else if ("fps".equalsIgnoreCase(name)) { value = Float.toString(movie.getFps()); } else if (CERTIFICATION.equalsIgnoreCase(name)) { value = movie.getCertification(); } else if (WATCHED.equalsIgnoreCase(name)) { if (imageType.equalsIgnoreCase(VIDEOIMAGE)) { value = movie.getFiles().toArray(new MovieFile[movie.getFiles().size()])[viIndex] .isWatched() ? TRUE : FALSE; } else if (movie.isTVShow() && blockWatched) { StringBuilder sbWatched = new StringBuilder(); boolean first = true; for (MovieFile mf : movie.getFiles()) { if (first) { first = false; } else { sbWatched.append(Movie.SPACE_SLASH_SPACE); } sbWatched.append(mf.isWatched() ? TRUE : FALSE); } value = sbWatched.toString(); } else { value = movie.isWatched() ? TRUE : FALSE; } } else if (EPISODE.equalsIgnoreCase(name)) { if (movie.isTVShow()) { if (blockEpisode) { StringBuilder sbEpisode = new StringBuilder(); boolean first = true; int firstPart, lastPart; for (MovieFile mf : movie.getFiles()) { firstPart = mf.getFirstPart(); lastPart = mf.getLastPart(); for (int part = firstPart; part <= lastPart; part++) { if (first) { first = false; } else { sbEpisode.append(Movie.SPACE_SLASH_SPACE); } sbEpisode.append(part); } } value = sbEpisode.toString(); } else { value = Integer.toString(movie.getFiles().size()); } } } else if ("top250".equalsIgnoreCase(name)) { value = movie.getTop250() > 0 ? TRUE : FALSE; } else if (KEYWORDS.equalsIgnoreCase(name)) { value = movie.getBaseFilename().toLowerCase(); } else if (COUNTRY.equalsIgnoreCase(name)) { value = movie.getCountriesAsString(); if (!blockCountry) { int pos = value.indexOf(Movie.SPACE_SLASH_SPACE); if (pos > -1) { value = value.substring(0, pos); } } } else if (COMPANY.equalsIgnoreCase(name)) { value = movie.getCompany(); if (!blockCompany) { int pos = value.indexOf(Movie.SPACE_SLASH_SPACE); if (pos > -1) { value = value.substring(0, pos); } } } else if (AWARD.equalsIgnoreCase(name)) { value = ""; int awardCount = 0; Map<String, Integer> awards = new HashMap<>(); if (!movie.isSetMaster()) { for (AwardEvent awardEvent : movie.getAwards()) { for (Award award : awardEvent.getAwards()) { if (award.getWon() > 0) { if (blockAward) { awards.put((awardEventName ? (awardEvent.getName() + " - ") : "") + award.getName(), award.getWon()); } else if (countAward) { awardCount++; } else { value = TRUE; break; } } } if (!blockAward && !countAward && StringTools.isValidString(value)) { break; } } } if (blockAward) { ValueComparator bvc = new ValueComparator(awards); Map<String, Integer> sortedAwards = new TreeMap<>(bvc); sortedAwards.putAll(awards); StringBuilder sbAwards = new StringBuilder(); boolean first = value.isEmpty(); // Append the separator only if the "value" is not empty for (String award : sortedAwards.keySet()) { if (first) { first = false; } else { sbAwards.append(Movie.SPACE_SLASH_SPACE); } sbAwards.append(award); } value += sbAwards.toString(); } value = (StringTools.isNotValidString(value) && !countAward) ? blockAward ? Movie.UNKNOWN : FALSE : countAward ? Integer.toString(awardCount) : value; } else { value = PropertiesUtil.getProperty(name, Movie.UNKNOWN); } } StateOverlay state = new StateOverlay(layer.getLeft(), layer.getTop(), layer.getAlign(), layer.getValign(), layer.getWidth(), layer.getHeight(), value); states.add(state); } for (int inx = 0; inx < layer.getNames().size(); inx++) { String name = layer.getNames().get(inx); String value = states.get(inx).getValue(); String filename = Movie.UNKNOWN; if (checkLogoEnabled(name)) { if (!blockLanguage && LANGUAGE.equalsIgnoreCase(name) && StringTools.isValidString(value)) { filename = "languages/English.png"; } String[] values = value.split(Movie.SPACE_SLASH_SPACE); for (String splitValue : values) { value = splitValue; for (ImageOverlay img : layer.getImages()) { if (img.getName().equalsIgnoreCase(name)) { boolean accept = false; if (img.getValues().size() == 1 && cmpOverlayValue(name, img.getValue(), value)) { accept = true; } else if (img.getValues().size() > 1) { accept = true; for (int i = 0; i < layer.getNames().size(); i++) { accept = accept && cmpOverlayValue(layer.getNames().get(i), img.getValues().get(i), states.get(i).getValue()); if (!accept) { break; } } } if (!accept) { continue; } File imageFile = new File(overlayResources + img.getFilename()); if (imageFile.exists()) { if (StringTools.isNotValidString(filename)) { filename = img.getFilename(); } else { filename += Movie.SPACE_SLASH_SPACE + img.getFilename(); } } break; } } } flag = flag || StringTools.isValidString(filename); } states.get(inx).setFilename(filename); } if (!flag) { continue; } if (!layer.getPositions().isEmpty()) { for (ConditionOverlay cond : layer.getPositions()) { flag = true; for (int i = 0; i < layer.getNames().size(); i++) { String name = layer.getNames().get(i); String condition = cond.getValues().get(i); String value = states.get(i).getValue(); flag = flag && cmpOverlayValue(name, condition, value); if (!flag) { break; } } if (flag) { for (int i = 0; i < layer.getNames().size(); i++) { PositionOverlay pos = cond.getPositions().get(i); states.get(i).setLeft(pos.getLeft()); states.get(i).setTop(pos.getTop()); states.get(i).setAlign(pos.getAlign()); states.get(i).setValign(pos.getValign()); } break; } } } for (int i = 0; i < layer.getNames().size(); i++) { StateOverlay state = states.get(i); String name = layer.getNames().get(i); if (!blockLanguage && LANGUAGE.equalsIgnoreCase(name)) { newBi = drawLanguage(movie, newBi, getOverlayX(newBi.getWidth(), 62, state.getLeft(), state.getAlign()), getOverlayY(newBi.getHeight(), 40, state.getTop(), state.getValign())); continue; } String filename = state.getFilename(); if (StringTools.isNotValidString(filename)) { continue; } if (((blockAudioCodec && ((AUDIOCODEC.equalsIgnoreCase(name) || ACODEC.equalsIgnoreCase(name) || "AC".equalsIgnoreCase(name)))) || (blockAudioChannels && (AUDIOCHANNELS.equalsIgnoreCase(name) || CHANNELS.equalsIgnoreCase(name))) || (blockAudioLang && (AUDIOLANG.equalsIgnoreCase(name) || ALANG.equalsIgnoreCase(name) || "AL".equalsIgnoreCase(name))) || (blockCountry && COUNTRY.equalsIgnoreCase(name)) || (blockCompany && COMPANY.equalsIgnoreCase(name)) || (blockAward && AWARD.equalsIgnoreCase(name)) || (blockWatched && WATCHED.equalsIgnoreCase(name)) || (blockEpisode && EPISODE.equalsIgnoreCase(name)) || (blockSubTitle && SUBTITLE.equalsIgnoreCase(name)) || (blockLanguage && LANGUAGE.equalsIgnoreCase(name))) && (overlayBlocks.get(name) != null)) { newBi = drawBlock(movie, newBi, name, filename, state.getLeft(), state.getAlign(), state.getWidth(), state.getTop(), state.getValign(), state.getHeight()); continue; } try { BufferedImage biSet = GraphicTools.loadJPEGImage(overlayResources + filename); Graphics2D g2d = newBi.createGraphics(); g2d.drawImage(biSet, getOverlayX(newBi.getWidth(), biSet.getWidth(), state.getLeft(), state.getAlign()), getOverlayY(newBi.getHeight(), biSet.getHeight(), state.getTop(), state.getValign()), state.getWidth().matches(D_PLUS) ? Integer.parseInt(state.getWidth()) : biSet.getWidth(), state.getHeight().matches(D_PLUS) ? Integer.parseInt(state.getHeight()) : biSet.getHeight(), null); g2d.dispose(); } catch (FileNotFoundException ex) { LOG.warn("Failed to load {} {}, please ensure it is valid", overlayResources, filename); } catch (IOException ex) { LOG.warn( "Failed drawing overlay to image file: Please check that {} is in the resources directory.", filename); } if ("set".equalsIgnoreCase(name)) { newBi = drawSetSize(movie, newBi); } } } } else if (beforeMainOverlay) { if (addHDLogo) { newBi = drawLogoHD(movie, newBi, addTVLogo); } if (addTVLogo) { newBi = drawLogoTV(movie, newBi, addHDLogo); } if (addLanguage) { newBi = drawLanguage(movie, newBi, 1, 1); } if (addSubTitle) { newBi = drawSubTitle(movie, newBi); } // Should only really happen on set's thumbnails. if (imageType.equalsIgnoreCase(THUMBNAIL) && movie.isSetMaster()) { // Draw the set logo if requested. if (addSetLogo) { newBi = drawSet(movie, newBi); LOG.debug("Drew set logo on {}", movie.getTitle()); } newBi = drawSetSize(movie, newBi); } } return newBi; }