Search in sources :

Example 11 with MemoryImageSource

use of java.awt.image.MemoryImageSource in project java-swing-tips by aterai.

the class MissingIcon method makeRoundedMemoryImageSource.

private static Optional<MemoryImageSource> makeRoundedMemoryImageSource(Image img, int w, int h) {
    int[] pix = new int[h * w];
    PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pix, 0, w);
    try {
        pg.grabPixels();
    } catch (InterruptedException ex) {
        System.err.println("interrupted waiting for pixels!");
        ex.printStackTrace();
        Thread.currentThread().interrupt();
        return Optional.empty();
    }
    if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
        System.err.println("image fetch aborted or error");
        return Optional.empty();
    }
    Area area = makeNorthWestCorner();
    Rectangle r = area.getBounds();
    // NW
    Shape s = area;
    for (int y = 0; y < r.height; y++) {
        for (int x = 0; x < r.width; x++) {
            if (s.contains(x, y)) {
                pix[x + y * w] = 0x0;
            }
        }
    }
    AffineTransform at = AffineTransform.getScaleInstance(-1d, 1d);
    at.translate(-w, 0);
    // NE
    s = at.createTransformedShape(area);
    for (int y = 0; y < r.height; y++) {
        for (int x = w - r.width; x < w; x++) {
            if (s.contains(x, y)) {
                pix[x + y * w] = 0x0;
            }
        }
    }
    return Optional.of(new MemoryImageSource(w, h, pix, 0, w));
}
Also used : Area(java.awt.geom.Area) PixelGrabber(java.awt.image.PixelGrabber) AffineTransform(java.awt.geom.AffineTransform) MemoryImageSource(java.awt.image.MemoryImageSource)

Example 12 with MemoryImageSource

use of java.awt.image.MemoryImageSource in project voltdb by VoltDB.

the class DatabaseManager method main.

public void main() {
    fMain = new Frame("HSQL Database Manager");
    imgEmpty = createImage(new MemoryImageSource(2, 2, new int[4 * 4], 2, 2));
    fMain.setIconImage(imgEmpty);
    fMain.addWindowListener(this);
    MenuBar bar = new MenuBar();
    // used shortcuts: CERGTSIUDOLM
    String[] fitems = { "-Connect...", "--", "-Open Script...", "-Save Script...", "-Save Result...", "-Save Result csv...", "--", "-Exit" };
    addMenu(bar, "File", fitems);
    String[] vitems = { "RRefresh Tree", "--", "GResults in Grid", "TResults in Text", "--", "1Shrink Tree", "2Enlarge Tree", "3Shrink Command", "4Enlarge Command" };
    addMenu(bar, "View", vitems);
    String[] sitems = { "SSELECT", "IINSERT", "UUPDATE", "DDELETE", "--", "-CREATE TABLE", "-DROP TABLE", "-CREATE INDEX", "-DROP INDEX", "--", "-CHECKPOINT", "-SCRIPT", "-SET", "-SHUTDOWN", "--", "-Test Script" };
    addMenu(bar, "Command", sitems);
    Menu recent = new Menu("Recent");
    mRecent = new Menu("Recent");
    bar.add(mRecent);
    String[] soptions = { "-AutoCommit on", "-AutoCommit off", "OCommit", "LRollback", "--", "-Disable MaxRows", "-Set MaxRows to 100", "--", "-Logging on", "-Logging off", "--", "-Insert test data" };
    addMenu(bar, "Options", soptions);
    String[] stools = { "-Dump", "-Restore", "-Transfer" };
    addMenu(bar, "Tools", stools);
    Menu hMenu = new Menu("Help");
    MenuItem aItem = new MenuItem("About");
    aItem.setShortcut(new MenuShortcut('A'));
    aItem.addActionListener(this);
    hMenu.add(aItem);
    MenuItem hItem = new MenuItem("Help");
    hItem.setShortcut(new MenuShortcut('H'));
    hItem.addActionListener(this);
    hMenu.add(hItem);
    //bar.add(hMenu);
    // Command above disabled only until a help display bug is fixed.
    fMain.setMenuBar(bar);
    fMain.setSize(640, 480);
    fMain.add("Center", this);
    initGUI();
    sRecent = new String[iMaxRecent];
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = fMain.getSize();
    // (ulrivo): full size on screen with less than 640 width
    if (d.width >= 640) {
        fMain.setLocation((d.width - size.width) / 2, (d.height - size.height) / 2);
    } else {
        fMain.setLocation(0, 0);
        fMain.setSize(d);
    }
    fMain.show();
    // (ulrivo): load query from command line
    if (defScript != null) {
        if (defDirectory != null) {
            defScript = defDirectory + File.separator + defScript;
        }
        txtCommand.setText(DatabaseManagerCommon.readFile(defScript));
    }
    txtCommand.requestFocus();
}
Also used : Frame(java.awt.Frame) MenuBar(java.awt.MenuBar) MenuItem(java.awt.MenuItem) Menu(java.awt.Menu) MenuShortcut(java.awt.MenuShortcut) Dimension(java.awt.Dimension) MemoryImageSource(java.awt.image.MemoryImageSource)

Example 13 with MemoryImageSource

use of java.awt.image.MemoryImageSource in project voltdb by VoltDB.

the class ZaurusDatabaseManager method main.

/**
     * Method declaration
     *
     */
public void main() {
    fMain = new Frame("HSQLDB Database Manager for Zaurus");
    imgEmpty = createImage(new MemoryImageSource(2, 2, new int[4 * 4], 2, 2));
    fMain.setIconImage(imgEmpty);
    fMain.addWindowListener(this);
    MenuBar bar = new MenuBar();
    // no shortcuts used
    String[] fitems = { "-Connect...", "--", "-Open Script...", "-Save Script...", "-Save Result...", "--", "-Exit" };
    addMenu(bar, "File", fitems);
    String[] vitems = { "-Refresh Tree", "--", "-View Tree", "-View Command", "-View Result", "-View Editor", "--", "-Results in Grid", "-Results in Text" };
    addMenu(bar, "View", vitems);
    String[] sitems = { "-SELECT", "-INSERT", "-UPDATE", "-DELETE", "--", "-CREATE TABLE", "-DROP TABLE", "-CREATE INDEX", "-DROP INDEX", "--", "-SCRIPT", "-SHUTDOWN", "--", "-Test Script" };
    addMenu(bar, "SQL", sitems);
    Menu recent = new Menu("Recent");
    mRecent = new Menu("Recent");
    bar.add(mRecent);
    String[] soptions = { "-AutoCommit on", "-AutoCommit off", "-Commit", "-Rollback", "--", "-Disable MaxRows", "-Set MaxRows to 100", "--", "-Logging on", "-Logging off", "--", // , "-Transfer"
    "-Insert test data" };
    addMenu(bar, "Options", soptions);
    String[] shelp = { "-Show HTML-Help in browser" };
    addMenu(bar, "?", shelp);
    fMain.setMenuBar(bar);
    fMain.setSize(defWidth, defHeight);
    fMain.add("Center", this);
    initGUI();
    sRecent = new String[iMaxRecent];
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = fMain.getSize();
    // full size on screen with less than 640 width
    if (d.width > 640) {
        fMain.setLocation((d.width - size.width) / 2, (d.height - size.height) / 2);
    } else if (defWidth > 0 && defHeight > 0) {
        fMain.setLocation(defLocX, defLocY);
        fMain.setSize(defWidth, defHeight);
    } else {
        fMain.setLocation(0, 0);
        fMain.setSize(d);
    }
    fMain.show();
    // (ulrivo): load query from command line
    if (defQuery != null) {
        txtCommand.setText(DatabaseManagerCommon.readFile(defQuery));
    }
    txtCommand.requestFocus();
}
Also used : Frame(java.awt.Frame) MenuBar(java.awt.MenuBar) Menu(java.awt.Menu) Dimension(java.awt.Dimension) MemoryImageSource(java.awt.image.MemoryImageSource)

Example 14 with MemoryImageSource

use of java.awt.image.MemoryImageSource in project jdk8u_jdk by JetBrains.

the class CardinalTextField method calculateImage.

/**
     * Calculates and returns the image.  Halts the calculation and returns
     * null if the Applet is stopped during the calculation.
     */
private Image calculateImage() {
    Thread me = Thread.currentThread();
    int width = canvas.getSize().width;
    int height = canvas.getSize().height;
    int[] xvals = new int[2];
    int[] yvals = new int[2];
    int xmethod = XControls.getParams(xvals);
    int ymethod = YControls.getParams(yvals);
    int[] pixels = new int[width * height];
    //temporarily holds R,G,B,A information
    int[] c = new int[4];
    int index = 0;
    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; i++) {
            c[0] = c[1] = c[2] = 0;
            c[3] = 255;
            if (xmethod < ymethod) {
                applyMethod(c, xmethod, i, width, xvals);
                applyMethod(c, ymethod, j, height, yvals);
            } else {
                applyMethod(c, ymethod, j, height, yvals);
                applyMethod(c, xmethod, i, width, xvals);
            }
            pixels[index++] = ((c[3] << 24) | (c[0] << 16) | (c[1] << 8) | c[2]);
        }
        // Poll once per row to see if we've been told to stop.
        if (runner != me) {
            return null;
        }
    }
    return createImage(new MemoryImageSource(width, height, ColorModel.getRGBdefault(), pixels, 0, width));
}
Also used : MemoryImageSource(java.awt.image.MemoryImageSource)

Example 15 with MemoryImageSource

use of java.awt.image.MemoryImageSource in project jdk8u_jdk by JetBrains.

the class ImageSelection method createImage.

private static Image createImage() {
    int w = 100;
    int h = 100;
    int[] pix = new int[w * h];
    int index = 0;
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int red = 127;
            int green = 127;
            int blue = y > h / 2 ? 127 : 0;
            int alpha = 255;
            if (x < w / 4 && y < h / 4) {
                alpha = 0;
                red = 0;
            }
            pix[index++] = (alpha << 24) | (red << 16) | (green << 8) | blue;
        }
    }
    return Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, pix, 0, w));
}
Also used : MemoryImageSource(java.awt.image.MemoryImageSource)

Aggregations

MemoryImageSource (java.awt.image.MemoryImageSource)24 BufferedImage (java.awt.image.BufferedImage)6 Image (java.awt.Image)4 PixelGrabber (java.awt.image.PixelGrabber)4 Dimension (java.awt.Dimension)3 Frame (java.awt.Frame)3 Menu (java.awt.Menu)3 MenuBar (java.awt.MenuBar)3 DirectColorModel (java.awt.image.DirectColorModel)3 ImageProcessor (ij.process.ImageProcessor)2 IndexColorModel (java.awt.image.IndexColorModel)2 VCImage (cbit.image.VCImage)1 ByteProcessor (ij.process.ByteProcessor)1 FloatProcessor (ij.process.FloatProcessor)1 ShortProcessor (ij.process.ShortProcessor)1 FileDialog (java.awt.FileDialog)1 MediaTracker (java.awt.MediaTracker)1 MenuItem (java.awt.MenuItem)1 MenuShortcut (java.awt.MenuShortcut)1 Point (java.awt.Point)1