Example usage for java.awt Graphics dispose

List of usage examples for java.awt Graphics dispose

Introduction

In this page you can find the example usage for java.awt Graphics dispose.

Prototype

public abstract void dispose();

Source Link

Document

Disposes of this graphics context and releases any system resources that it is using.

Usage

From source file:JuliaSet2.java

public void print() {
    // Create some attributes objects. This is Java 1.3 stuff.
    // In Java 1.1, we'd use a java.util.Preferences object instead.
    JobAttributes jattrs = new JobAttributes();
    PageAttributes pattrs = new PageAttributes();

    // Set some example attributes: monochrome, landscape mode
    pattrs.setColor(PageAttributes.ColorType.MONOCHROME);
    pattrs.setOrientationRequested(PageAttributes.OrientationRequestedType.LANDSCAPE);
    // Print to file by default
    jattrs.setDestination(JobAttributes.DestinationType.FILE);
    jattrs.setFileName("juliaset.ps");

    // Look up the Frame that holds this component
    Component frame = this;
    while (!(frame instanceof Frame))
        frame = frame.getParent();/*from w ww .ja  v  a2 s. c o  m*/

    // Get a PrintJob object to print the Julia set with.
    // The getPrintJob() method displays a print dialog and allows the user
    // to override and modify the default JobAttributes and PageAttributes
    Toolkit toolkit = this.getToolkit();
    PrintJob job = toolkit.getPrintJob((Frame) frame, "JuliaSet1", jattrs, pattrs);

    // We get a null PrintJob if the user clicked cancel
    if (job == null)
        return;

    // Get a Graphics object from the PrintJob.
    // We print simply by drawing to this Graphics object.
    Graphics g = job.getGraphics();

    // Center the image on the page
    Dimension pagesize = job.getPageDimension(); // how big is page?
    Dimension panesize = this.getSize(); // how big is image?
    g.translate((pagesize.width - panesize.width) / 2, // center it
            (pagesize.height - panesize.height) / 2);

    // Draw a box around the Julia Set and label it
    g.drawRect(-1, -1, panesize.width + 2, panesize.height + 2);
    g.drawString("Julia Set for c={" + cx + "," + cy + "}", 0, -15);

    // Set a clipping region
    g.setClip(0, 0, panesize.width, panesize.height);

    // Now print the component by calling its paint method
    this.paint(g);

    // Finally tell the printer we're done with the page.
    // No output will be generated if we don't call dispose() here.
    g.dispose();
}

From source file:org.pentaho.reporting.libraries.base.util.WaitingImageObserver.java

/**
 * The workerthread. Simply draws the image to a BufferedImage's Graphics-Object and waits for the AWT to load the
 * image./*from   w w w .  j  ava  2s . c  o  m*/
 */
public synchronized void waitImageLoaded() {

    if (this.lock == false) {
        return;
    }

    final BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    final Graphics g = img.getGraphics();

    try {
        while (this.lock && error == false) {
            lastUpdate = System.currentTimeMillis();
            if (g.drawImage(this.image, 0, 0, img.getWidth(this), img.getHeight(this), this)) {
                return;
            }

            try {
                wait(500);
            } catch (InterruptedException e) {
                LOGGER.info("WaitingImageObserver.waitImageLoaded(): InterruptedException thrown", e);
            }

            if (lock == false) {
                return;
            }

            if (maxLoadTime > 0 && lastUpdate < (System.currentTimeMillis() - maxLoadTime)) {
                error = true;
                lock = false;
                LOGGER.info("WaitingImageObserver.waitImageLoaded(): Image loading reached timeout.");
                return;
            }
        }
    } finally {
        g.dispose();
    }
}

From source file:org.csml.tommo.sugar.modules.QualityHeatMapsPerTileAndBase.java

@Deprecated
private void writeTable2HTML(HTMLReportArchive report, LaneCoordinates laneCoordinates,
        TileNumeration tileNumeration) throws IOException {
    final ResultsTableModel model = new ResultsTableModel(this, laneCoordinates, tileNumeration);

    String flowCell = laneCoordinates.getFlowCell();
    Integer lane = laneCoordinates.getLane();

    ZipOutputStream zip = report.zipFile();
    StringBuffer b = report.htmlDocument();
    StringBuffer d = report.dataDocument();

    b.append("<table>\n");
    // Do the headers
    b.append("<tr>\n");
    d.append("#Tiles: ");

    // "row header" for base position number
    b.append("<th></th>\n");
    d.append("\t");
    for (int c = 0; c < model.getColumnCount(); c++) {
        b.append("<th>");
        b.append(model.getColumnName(c));
        d.append(model.getColumnName(c));
        b.append("</th>\n");
        d.append("\t");

        if (c == model.getTopBottomSeparatorColumn()) {
            b.append("<th>");
            b.append("Top-Bottom");
            d.append("Top-Bottom");
            b.append("</th>\n");
            d.append("\t");
        }/*from  w  w  w .j av  a 2 s  .  c  o  m*/
    }
    b.append("</tr>\n");
    d.append("\n");

    long before = System.currentTimeMillis();

    // Do the rows
    d.append("#Base Positions: 1-" + maxSequenceLength);
    d.append("\n");
    for (int r = 0; r < model.getRowCount(); r++) {
        b.append("<tr>\n");

        // "header" for base position number
        b.append("<th>");
        int bp = model.getBasePosition(r);
        b.append(model.getCycleID(r) == 0 ? bp : "");
        b.append("</th>\n");

        for (int c = 0; c < model.getColumnCount(); c++) {
            TileBPCoordinates tileBPCoordinate = model.getCoordinateAt(r, c);
            TileCoordinates tileCoordinates = tileBPCoordinate.getTileCoordinate();
            b.append("<td>");
            MeanQualityMatrix matrix = getMeanQualityMatrix(tileBPCoordinate);

            if (matrix != null) {
                String imgFileName = "matrix_" + flowCell + "_" + lane + "_" + tileCoordinates.getTile() + "_"
                        + tileBPCoordinate.getBasePosition() + ".png";
                zip.putNextEntry(new ZipEntry(report.folderName() + "/Images/" + imgFileName));
                BufferedImage image = (BufferedImage) matrix.createBufferedImage(LinearPaintScale.PAINT_SCALE);
                int imgSize = Options.getHeatmapImageSize();
                BufferedImage scaledImage = new BufferedImage(imgSize, imgSize, BufferedImage.TYPE_INT_RGB);
                Graphics g = scaledImage.getGraphics();
                g.drawImage(image, 0, 0, imgSize, imgSize, null);
                g.dispose();
                ImageIO.write(scaledImage, "png", zip);

                b.append("<img src=\"Images/" + imgFileName + "\" alt=\"M[" + tileBPCoordinate.toString()
                        + "]\">\n");
            } else {
                b.append("");
                d.append("Missing matrix for: " + tileBPCoordinate + "\n");
            }
            b.append("</td>\n");

            if (c == model.getTopBottomSeparatorColumn()) {
                b.append("<td></td>\n");
            }
        }
        b.append("</tr>\n");
    }
    long after = System.currentTimeMillis();
    d.append("Creating report time: " + (after - before));

    b.append("</table>\n");
}

From source file:org.jtrfp.trcl.core.ResourceManager.java

private BufferedImage[] getSpecialRAWImage(String name, Color[] palette, int upscalePowerOfTwo)
        throws IllegalAccessException, FileLoadException, IOException {
    RAWFile dat = getRAW(name);//w  w w.  j a v  a  2s  . c  o m
    dat.setPalette(palette);
    BufferedImage[] segs = dat.asSegments(upscalePowerOfTwo);
    for (BufferedImage seg : segs) {
        Graphics g = seg.getGraphics();
        BufferedImage scaled = new BufferedImage(seg.getColorModel(), seg.copyData(null),
                seg.isAlphaPremultiplied(), null);
        g.drawImage(
                scaled.getScaledInstance(seg.getWidth() - 2, seg.getHeight() - 2, Image.SCALE_AREA_AVERAGING),
                1, 1, seg.getWidth() - 2, seg.getHeight() - 2, null);
        g.dispose();
    }
    return segs;
}

From source file:de.tor.tribes.ui.views.DSWorkbenchAttackFrame.java

@Override
public void actionPerformed(ActionEvent e) {
    AttackTableTab activeTab = getActiveTab();
    int idx = jAttackTabPane.getSelectedIndex();
    if (e.getActionCommand() != null && activeTab != null) {
        if (e.getActionCommand().equals("TimeChange")) {
            activeTab.fireChangeTimeEvent();
        } else if (e.getActionCommand().equals("UnitChange")) {
            activeTab.fireChangeUnitEvent();
        } else if (e.getActionCommand().equals("Recolor")) {
            activeTab.updateSortHighlighter();
        } else if (e.getActionCommand().equals("ExportScript")) {
            activeTab.fireExportScriptEvent();
        } else if (e.getActionCommand().equals("Copy")) {
            activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.COPY_TO_INTERNAL_CLIPBOARD);
        } else if (e.getActionCommand().equals("BBCopy")) {
            activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.CLIPBOARD_BB);
        } else if (e.getActionCommand().equals("Cut")) {
            activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.CUT_TO_INTERNAL_CLIPBOARD);
            jAttackTabPane.setSelectedIndex(idx);
        } else if (e.getActionCommand().equals("Paste")) {
            activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.FROM_INTERNAL_CLIPBOARD);
            jAttackTabPane.setSelectedIndex(idx);
        } else if (e.getActionCommand().equals("Delete")) {
            activeTab.deleteSelection(true);
        } else if (e.getActionCommand().equals("Find")) {
            BufferedImage back = ImageUtils.createCompatibleBufferedImage(3, 3, BufferedImage.TRANSLUCENT);
            Graphics g = back.getGraphics();
            g.setColor(new Color(120, 120, 120, 120));
            g.fillRect(0, 0, back.getWidth(), back.getHeight());
            g.setColor(new Color(120, 120, 120));
            g.drawLine(0, 0, 3, 3);/*from  w  w  w  .  j av  a 2s .c o  m*/
            g.dispose();
            TexturePaint paint = new TexturePaint(back,
                    new Rectangle2D.Double(0, 0, back.getWidth(), back.getHeight()));

            jxSearchPane.setBackgroundPainter(new MattePainter(paint));
            DefaultListModel model = new DefaultListModel();

            for (int i = 0; i < activeTab.getAttackTable().getColumnCount(); i++) {
                TableColumnExt col = activeTab.getAttackTable().getColumnExt(i);
                if (col.isVisible()) {
                    if (!col.getTitle().equals("Einheit") && !col.getTitle().equals("Typ")
                            && !col.getTitle().equals("Sonstiges") && !col.getTitle().equals("Abschickzeit")
                            && !col.getTitle().equals("Ankunftzeit") && !col.getTitle().equals("Verbleibend")) {
                        model.addElement(col.getTitle());
                    }
                }
            }
            jXColumnList.setModel(model);
            jXColumnList.setSelectedIndex(0);
            jxSearchPane.setVisible(true);
        }
    }
}

From source file:org.esa.nest.dat.views.polarview.PolarCanvas.java

private void draw(Graphics g, Dimension size) {
    final int annotationHeight = 100;
    final int x = Math.max((int) (size.height * 0.05), 10);
    final int y = Math.max((int) (size.width * 0.05), 10);
    final int bottom = Math.max((int) (size.height * 0.1) + annotationHeight, 20);
    final int right = Math.max((int) (size.width * 0.1), 20);
    final Rectangle r = positionPlot(size, x, y, bottom, right);
    plotRadius = Math.min(r.width / 2, r.height / 2);
    final Dimension quadrantSize = new Dimension(plotRadius, plotRadius);
    g.translate(0, origin.y + r.height);
    if (data != null) {
        loadColorBar(data.getColorScale());
        drawColorBar(g, colourAxis);/* w w w .j  a v  a  2s. c o m*/
    }
    g.translate(0, -origin.y - r.height);

    origin.y += r.height / 2;
    origin.x += r.width / 2;
    final Graphics graphics = g.create();
    graphics.translate(origin.x, origin.y);
    radialAxis.setSize(quadrantSize);
    if (data != null)
        data.draw(graphics);
    if (rings != null) {
        int ri = 0;
        for (double ring : rings) {
            final int rad = radialAxis.getScreenPoint(ring);
            final int rad2 = rad + rad;
            graphics.setColor(Color.lightGray);
            graphics.drawOval(-rad, -rad, rad2, rad2);
            if (ringText != null && ringText[ri] != null) {
                graphics.setColor(Color.black);
                graphics.drawString(ringText[ri], 0, -rad);
            }
            ++ri;
        }
    } else {
        radialAxis.draw(graphics);
    }

    // draw wind direction & speed
    if (showWindDirection)
        drawWindDirection(graphics, plotRadius, windDirection - 90);

    graphics.translate(-origin.x, -origin.y);

    drawAxisLabels(graphics);

    graphics.dispose();
}

From source file:de.tor.tribes.ui.views.DSWorkbenchReportFrame.java

@Override
public void actionPerformed(ActionEvent e) {
    ReportTableTab activeTab = getActiveTab();
    if (e.getActionCommand() != null && activeTab != null) {
        if (e.getActionCommand().equals("Copy")) {
            activeTab.transferSelection(ReportTableTab.TRANSFER_TYPE.COPY_TO_INTERNAL_CLIPBOARD);
        } else if (e.getActionCommand().equals("BBCopy")) {
            activeTab.transferSelection(ReportTableTab.TRANSFER_TYPE.CLIPBOARD_BB);
        } else if (e.getActionCommand().equals("Cut")) {
            activeTab.transferSelection(ReportTableTab.TRANSFER_TYPE.CUT_TO_INTERNAL_CLIPBOARD);
        } else if (e.getActionCommand().equals("Paste")) {
            activeTab.transferSelection(ReportTableTab.TRANSFER_TYPE.FROM_INTERNAL_CLIPBOARD);
        } else if (e.getActionCommand().equals("Delete")) {
            activeTab.deleteSelection(true);
        } else if (e.getActionCommand().equals("Find")) {
            BufferedImage back = ImageUtils.createCompatibleBufferedImage(3, 3, BufferedImage.TRANSLUCENT);
            Graphics g = back.getGraphics();
            g.setColor(new Color(120, 120, 120, 120));
            g.fillRect(0, 0, back.getWidth(), back.getHeight());
            g.setColor(new Color(120, 120, 120));
            g.drawLine(0, 0, 3, 3);//from w  ww. j av  a2s .  c  o m
            g.dispose();
            TexturePaint paint = new TexturePaint(back,
                    new Rectangle2D.Double(0, 0, back.getWidth(), back.getHeight()));
            jxSearchPane.setBackgroundPainter(new MattePainter(paint));
            DefaultListModel model = new DefaultListModel();

            for (int i = 0; i < activeTab.getReportTable().getColumnCount(); i++) {
                TableColumnExt col = activeTab.getReportTable().getColumnExt(i);
                if (col.isVisible()) {
                    if (!col.getTitle().equals("Status") && !col.getTitle().equals("Typ")
                            && !col.getTitle().equals("Sonstiges")) {
                        model.addElement(col.getTitle());
                    }
                }
            }
            jXColumnList.setModel(model);
            jXColumnList.setSelectedIndex(0);
            jxSearchPane.setVisible(true);
        }
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

/**
 * @see Graphics#drawImage(Image, int, int, int, int, int, int, int, int, Color, ImageObserver)
 *///from  w  w  w .j a v  a  2  s.c  o m
@Override
public boolean drawImage(final Image img, final int dx1, final int dy1, final int dx2, final int dy2,
        final int sx1, final int sy1, final int sx2, final int sy2, final Color bgcolor,
        final ImageObserver observer) {
    waitForImage(img);
    final double dwidth = (double) dx2 - dx1;
    final double dheight = (double) dy2 - dy1;
    final double swidth = (double) sx2 - sx1;
    final double sheight = (double) sy2 - sy1;

    // if either width or height is 0, then there is nothing to draw
    if (dwidth == 0 || dheight == 0 || swidth == 0 || sheight == 0) {
        return true;
    }

    final double scalex = dwidth / swidth;
    final double scaley = dheight / sheight;

    final double transx = sx1 * scalex;
    final double transy = sy1 * scaley;
    final AffineTransform tx = AffineTransform.getTranslateInstance(dx1 - transx, dy1 - transy);
    tx.scale(scalex, scaley);

    final BufferedImage mask = new BufferedImage(img.getWidth(observer), img.getHeight(observer),
            BufferedImage.TYPE_BYTE_BINARY);
    final Graphics g = mask.getGraphics();
    g.fillRect(sx1, sy1, (int) swidth, (int) sheight);
    drawImage(img, mask, tx, null, observer);
    g.dispose();
    return true;
}

From source file:org.yccheok.jstock.gui.Utils.java

public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }/*from   w  w  w.  j  a  va2  s  .c om*/

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();

    // Determine if the image has transparent pixels; for this method's
    // implementation, see e661 Determining If an Image Has Transparent Pixels
    boolean hasAlpha = hasAlpha(image);

    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        // Determine the type of transparency of the new buffered image
        int transparency = Transparency.OPAQUE;
        if (hasAlpha) {
            transparency = Transparency.BITMASK;
        }

        // Create the buffered image
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gs.getDefaultConfiguration();
        bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
    } catch (HeadlessException e) {
        // The system does not have a screen
    }

    if (bimage == null) {
        // Create a buffered image using the default color model
        int type = BufferedImage.TYPE_INT_RGB;
        if (hasAlpha) {
            type = BufferedImage.TYPE_INT_ARGB;
        }
        bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
    }

    // Copy image to buffered image
    Graphics g = bimage.createGraphics();

    // Paint the image onto the buffered image
    g.drawImage(image, 0, 0, null);
    g.dispose();

    return bimage;
}