Search in sources :

Example 81 with Toolkit

use of java.awt.Toolkit in project yyl_example by Relucent.

the class ThumbnailatorExample method display.

private static void display(Image original, Image processed) {
    @SuppressWarnings("serial")
    class ImageCanvas extends Canvas {

        private final Image image;

        public ImageCanvas(Image image) {
            this.image = image;
        }

        @Override
        public void paint(Graphics g) {
            super.paint(g);
            g.drawImage(image, 0, 0, this);
        }
    }
    Frame frame = new Frame();
    frame.setLayout(new GridLayout(1, 2));
    frame.add(new ImageCanvas(original));
    frame.add(new ImageCanvas(processed));
    frame.setTitle("Thumbnailator");
    frame.setResizable(false);
    frame.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    int width = 520;
    int height = 300;
    Toolkit kit = Toolkit.getDefaultToolkit();
    Dimension screen = kit.getScreenSize();
    frame.setBounds((screen.width - width) / 2, (screen.height - height) / 2, 520, 300);
    frame.setVisible(true);
}
Also used : Graphics(java.awt.Graphics) Frame(java.awt.Frame) GridLayout(java.awt.GridLayout) Canvas(java.awt.Canvas) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) Toolkit(java.awt.Toolkit) Dimension(java.awt.Dimension) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage)

Example 82 with Toolkit

use of java.awt.Toolkit in project sulky by huxi.

the class TaskManagerTest method setUp.

@Before
public void setUp() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    if (logger.isDebugEnabled())
        logger.debug("Toolkit: {}", tk);
    instance = new TaskManager<>();
    taskName = "TaskName";
}
Also used : Toolkit(java.awt.Toolkit) Before(org.junit.Before)

Example 83 with Toolkit

use of java.awt.Toolkit in project ginkgo-jdbc by georgeworld.

the class JdbcMain method setWindowCenter.

/*
     * 使窗口居中显示
     */
public static void setWindowCenter(Window window) {
    Toolkit kit = Toolkit.getDefaultToolkit();
    Dimension screenSize = kit.getScreenSize();
    int width = (int) screenSize.getWidth();
    int height = (int) screenSize.getHeight();
    int w = window.getWidth();
    int h = window.getHeight();
    window.setLocation((width - w) / 2, (height - h) / 2);
}
Also used : Toolkit(java.awt.Toolkit) Dimension(java.awt.Dimension)

Example 84 with Toolkit

use of java.awt.Toolkit in project beast-mcmc by beast-dev.

the class BeagleSequenceSimulatorApp method CreateImage.

// END: main
private Image CreateImage(String path) {
    URL imgURL = this.getClass().getResource(path);
    Toolkit kit = Toolkit.getDefaultToolkit();
    Image img = kit.createImage(imgURL);
    if (img != null) {
        return img;
    } else {
        System.out.println("Couldn't find file: " + path + "\n");
        return null;
    }
}
Also used : Toolkit(java.awt.Toolkit) Image(java.awt.Image) URL(java.net.URL)

Example 85 with Toolkit

use of java.awt.Toolkit in project triplea by triplea-game.

the class HeadedUiContext method internalSetMapDir.

@Override
protected void internalSetMapDir(final String dir, final GameData data) {
    final Stopwatch stopWatch = new Stopwatch(logger, Level.FINE, "Loading UI Context");
    resourceLoader = ResourceLoader.getMapResourceLoader(dir);
    if (mapData != null) {
        mapData.close();
    }
    mapData = new MapData(resourceLoader);
    // DiceImageFactory needs loader and game data
    diceImageFactory = new DiceImageFactory(resourceLoader, data.getDiceSides());
    final double unitScale = getPreferencesMapOrSkin(dir).getDouble(UNIT_SCALE_PREF, mapData.getDefaultUnitScale());
    scale = getPreferencesMapOrSkin(dir).getDouble(MAP_SCALE_PREF, 1);
    if (scale < 1) {
        setDrawTerritoryBordersAgainToMedium();
    }
    unitImageFactory.setResourceLoader(resourceLoader, unitScale, mapData.getDefaultUnitWidth(), mapData.getDefaultUnitHeight(), mapData.getDefaultUnitCounterOffsetWidth(), mapData.getDefaultUnitCounterOffsetHeight());
    // TODO: separate scale for resources
    resourceImageFactory.setResourceLoader(resourceLoader);
    territoryEffectImageFactory.setResourceLoader(resourceLoader);
    flagIconImageFactory.setResourceLoader(resourceLoader);
    puImageFactory.setResourceLoader(resourceLoader);
    tileImageFactory.setMapDir(resourceLoader);
    tileImageFactory.setScale(scale);
    // load map data
    mapImage.loadMaps(resourceLoader);
    mapDir = dir;
    drawTerritoryEffects = mapData.useTerritoryEffectMarkers();
    // load the sounds in a background thread,
    // avoids the pause where sounds dont load right away
    // change the resource loader (this allows us to play sounds the map folder, rather than just default sounds)
    new Thread(() -> ClipPlayer.getInstance(resourceLoader), "Triplea sound loader").start();
    // load a new cursor
    cursor = Cursor.getDefaultCursor();
    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    // URL's use "/" not "\"
    final URL cursorUrl = resourceLoader.getResource("misc" + "/" + "cursor.gif");
    if (cursorUrl != null) {
        try {
            final Image image = ImageIO.read(cursorUrl);
            if (image != null) {
                final Point hotSpot = new Point(mapData.getMapCursorHotspotX(), mapData.getMapCursorHotspotY());
                cursor = toolkit.createCustomCursor(image, hotSpot, data.getGameName() + " Cursor");
            }
        } catch (final Exception e) {
            ClientLogger.logQuietly("Failed to create cursor from: " + cursorUrl, e);
        }
    }
    stopWatch.done();
}
Also used : DiceImageFactory(games.strategy.triplea.image.DiceImageFactory) MapData(games.strategy.triplea.ui.mapdata.MapData) Stopwatch(games.strategy.triplea.util.Stopwatch) Toolkit(java.awt.Toolkit) Point(java.awt.Point) Image(java.awt.Image) MapImage(games.strategy.triplea.image.MapImage) URL(java.net.URL) BackingStoreException(java.util.prefs.BackingStoreException)

Aggregations

Toolkit (java.awt.Toolkit)95 Dimension (java.awt.Dimension)29 Point (java.awt.Point)21 Image (java.awt.Image)19 BufferedImage (java.awt.image.BufferedImage)14 URL (java.net.URL)14 GraphicsDevice (java.awt.GraphicsDevice)8 Insets (java.awt.Insets)8 GraphicsEnvironment (java.awt.GraphicsEnvironment)7 Rectangle (java.awt.Rectangle)7 IOException (java.io.IOException)6 Field (java.lang.reflect.Field)6 MediaTracker (java.awt.MediaTracker)5 ImageIcon (javax.swing.ImageIcon)5 Frame (java.awt.Frame)4 Clipboard (java.awt.datatransfer.Clipboard)4 BorderLayout (java.awt.BorderLayout)3 Font (java.awt.Font)3 Graphics (java.awt.Graphics)3 GraphicsConfiguration (java.awt.GraphicsConfiguration)3