Search in sources :

Example 91 with Toolkit

use of java.awt.Toolkit in project open-ecard by ecsec.

the class GUIDefaults method initialize.

public static void initialize() {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        GUIProperties guiProps = new GUIProperties();
        Properties props = guiProps.properties();
        for (String property : props.stringPropertyNames()) {
            try {
                String propertyName = property.substring(0, property.indexOf('.'));
                String propertyAttribute = property.substring(propertyName.length() + 1, property.length());
                String value = (String) props.getProperty(property);
                // Parse color property
                if (colorProperties.contains(propertyAttribute)) {
                    validateHexColor(value);
                    if (value.length() == 4) {
                        StringBuilder sb = new StringBuilder("#");
                        for (int i = 1; i < value.length(); i++) {
                            sb.append(value.substring(i, i + 1));
                            sb.append(value.substring(i, i + 1));
                        }
                        value = sb.toString();
                    }
                    Color color = Color.decode(value);
                    defaults.put(property, color);
                    ownDefaults.put(property, color);
                } else // Parse font propertiy
                if (fontProperties.contains(propertyAttribute)) {
                    Font font = Font.decode(value);
                    defaults.put(property, font);
                    ownDefaults.put(property, font);
                } else // Parse icon propertiy
                if (iconProperties.contains(propertyAttribute)) {
                    URL url = FileUtils.resolveResourceAsURL(guiProps.getClass(), value);
                    if (url == null) {
                        logger.error("Cannot parse the property: " + property);
                    } else {
                        Image image = toolkit.getImage(url);
                        ImageIcon icon = new ImageIcon(image);
                        defaults.put(property, icon);
                        ownDefaults.put(property, icon);
                    }
                }
            } catch (Exception e) {
                logger.error("Cannot parse the property: " + property);
            }
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) Color(java.awt.Color) Toolkit(java.awt.Toolkit) Properties(java.util.Properties) Image(java.awt.Image) Font(java.awt.Font) URL(java.net.URL)

Example 92 with Toolkit

use of java.awt.Toolkit in project zaproxy by zaproxy.

the class GuiBootstrap method setX11AwtAppClassName.

private void setX11AwtAppClassName() {
    Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
    // See JDK-6528430 : need system property to override default WM_CLASS
    // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6528430
    // Based on NetBeans workaround linked from the issue:
    Class<?> toolkitClass = defaultToolkit.getClass();
    if ("sun.awt.X11.XToolkit".equals(toolkitClass.getName())) {
        try {
            Field awtAppClassName = toolkitClass.getDeclaredField("awtAppClassName");
            awtAppClassName.setAccessible(true);
            awtAppClassName.set(null, Constant.PROGRAM_NAME);
        } catch (Exception e) {
            logger.warn("Failed to set awt app class name: " + e.getMessage());
        }
    }
}
Also used : Field(java.lang.reflect.Field) Toolkit(java.awt.Toolkit) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Example 93 with Toolkit

use of java.awt.Toolkit in project openblocks by mikaelhg.

the class ImageManager method createImage.

public BufferedImage createImage(String file) {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    URL u = ImageManager.class.getResource(file);
    if (u == null) {
        System.out.println("Could not find resource " + file);
        return null;
    }
    Image img = toolkit.createImage(u);
    if (img == null) {
        System.out.println("Couldn't load image " + file);
        return null;
    }
    MediaTracker mt = new MediaTracker(comp);
    try {
        mt.addImage(img, 0);
        mt.waitForAll();
    } catch (Exception e) {
        System.out.println("Couldn't load image " + file);
        System.out.println(e);
        return null;
    }
    if (mt.isErrorAny()) {
        System.out.println("Couldn't load image " + file);
        return null;
    }
    // ImageObserver observer = new ImageObserver() {
    // public boolean imageUpdate(Image img,int flags,int x,int y,int w,int h) {
    // if ((flags & (ALLBITS | FRAMEBITS | ABORT)) != 0) {
    // synchronized (this) { notify(); }
    // return false;
    // }
    // return true;
    // }
    // };
    // try {
    // synchronized (observer) {
    // while (!toolkit.prepareImage(img,-1,-1,observer)) { observer.wait(); }
    // }
    // }
    // catch (InterruptedException e) {
    // System.out.println("Couldn't load image "+file);
    // return null;
    // }
    // System.out.println("image width "+ img.getWidth(comp) +
    // " height " + img.getHeight(comp));
    BufferedImage bimg = comp.getGraphicsConfiguration().createCompatibleImage(img.getWidth(comp), img.getHeight(comp), Transparency.TRANSLUCENT);
    bimg.getGraphics().drawImage(img, 0, 0, comp);
    return bimg;
}
Also used : MediaTracker(java.awt.MediaTracker) Toolkit(java.awt.Toolkit) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) URL(java.net.URL) BufferedImage(java.awt.image.BufferedImage)

Example 94 with Toolkit

use of java.awt.Toolkit in project mzmine2 by mzmine.

the class MainWindow method initModule.

public void initModule() {
    assert SwingUtilities.isEventDispatchThread();
    try {
        final InputStream mzmineIconStream = DesktopSetup.class.getClassLoader().getResourceAsStream("MZmineIcon.png");
        this.mzmineIcon = ImageIO.read(mzmineIconStream);
        mzmineIconStream.close();
        setIconImage(mzmineIcon);
    } catch (Throwable e) {
        e.printStackTrace();
        logger.log(Level.WARNING, "Could not set application icon", e);
    }
    DesktopSetup desktopSetup = new DesktopSetup();
    desktopSetup.init();
    setLayout(new BorderLayout());
    mainPanel = new MainPanel();
    add(mainPanel, BorderLayout.CENTER);
    statusBar = new StatusBar();
    add(statusBar, BorderLayout.SOUTH);
    // Construct menu
    menuBar = new MainMenu();
    setJMenuBar(menuBar);
    // Initialize window listener for responding to user events
    addWindowListener(this);
    pack();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension screenSize = toolkit.getScreenSize();
    // Set initial window size to 1000x700 pixels, but check the screen size
    // first
    int width = Math.min(screenSize.width, 1000);
    int height = Math.min(screenSize.height, 700);
    setBounds(0, 0, width, height);
    setLocationRelativeTo(null);
    // Application wants to control closing by itself
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    updateTitle();
    // get the window settings parameter
    ParameterSet paramSet = MZmineCore.getConfiguration().getPreferences();
    WindowSettingsParameter settings = paramSet.getParameter(MZminePreferences.windowSetttings);
    // listen for changes
    this.addComponentListener(settings);
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) WindowSettingsParameter(net.sf.mzmine.parameters.parametertypes.WindowSettingsParameter) BorderLayout(java.awt.BorderLayout) InputStream(java.io.InputStream) Toolkit(java.awt.Toolkit) Dimension(java.awt.Dimension)

Example 95 with Toolkit

use of java.awt.Toolkit in project freeplane by freeplane.

the class UITools method getDesktopBounds.

public static Rectangle getDesktopBounds(Component frame) {
    final Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
    final Insets screenInsets = defaultToolkit.getScreenInsets(frame.getGraphicsConfiguration());
    final Dimension screenSize = defaultToolkit.getScreenSize();
    final int screenWidth = screenSize.width - screenInsets.left - screenInsets.right;
    final int screenHeight = screenSize.height - screenInsets.top - screenInsets.bottom;
    return new Rectangle(screenInsets.left, screenInsets.top, screenWidth, screenHeight);
}
Also used : Insets(java.awt.Insets) Rectangle(java.awt.Rectangle) Toolkit(java.awt.Toolkit) Dimension(java.awt.Dimension) Point(java.awt.Point)

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