Example usage for java.awt Toolkit getDefaultToolkit

List of usage examples for java.awt Toolkit getDefaultToolkit

Introduction

In this page you can find the example usage for java.awt Toolkit getDefaultToolkit.

Prototype

public static synchronized Toolkit getDefaultToolkit() 

Source Link

Document

Gets the default toolkit.

Usage

From source file:edu.stanford.epadd.launcher.Splash.java

public Splash() {
    final SplashScreen splash = (System.getProperty("nobrowseropen") == null) ? SplashScreen.getSplashScreen()
            : null;/*from   w  ww . j  a v a 2s  .  c om*/
    if (splash == null) {
        System.out.println("SplashScreen.getSplashScreen() returned null");
        return;
    }
    Rectangle r = splash.getBounds();
    g = splash.createGraphics();
    if (g == null) {
        System.out.println("splash.createGraphics() returned null");
        return;
    }

    /* code to prevent text from appearing too pixelated - https://stackoverflow.com/questions/31536952/how-to-fix-text-quality-in-java-graphics */
    Map<?, ?> desktopHints = (Map<?, ?>) Toolkit.getDefaultToolkit()
            .getDesktopProperty("awt.font.desktophints");
    if (desktopHints != null) {
        g.setRenderingHints(desktopHints);
    }
    System.out.println("splash url = " + splash.getImageURL() + " w=" + r.getWidth() + " h=" + r.getHeight()
            + " size=" + r.getSize() + " loc=" + r.getLocation());
    //      setVisible(true);
    //      toFront();
}

From source file:net.sf.firemox.Magic.java

/**
 * @param args/*w  ww. j  a  v  a 2  s  .c o  m*/
 *          the command line arguments
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    Log.init();
    Log.debug("MP v" + IdConst.VERSION + ", jre:" + System.getProperty("java.runtime.version") + ", jvm:"
            + System.getProperty("java.vm.version") + ",os:" + System.getProperty("os.name") + ", res:"
            + Toolkit.getDefaultToolkit().getScreenSize().width + "x"
            + Toolkit.getDefaultToolkit().getScreenSize().height + ", root:" + MToolKit.getRootDir());
    System.setProperty("swing.aatext", "true");
    System.setProperty(SubstanceLookAndFeel.WATERMARK_IMAGE_PROPERTY,
            MToolKit.getIconPath(Play.ZONE_NAME + "/hardwoodfloor.png"));

    final File substancelafFile = MToolKit.getFile(FILE_SUBSTANCE_PROPERTIES);
    if (substancelafFile == null) {
        Log.warn("Unable to locate '" + FILE_SUBSTANCE_PROPERTIES
                + "' file, you are using the command line with wrong configuration. See http://www.firemox.org/dev/project.html documentation");
    } else {
        System.getProperties().load(new FileInputStream(substancelafFile));
    }
    MToolKit.defaultFont = new Font("Arial", 0, 11);
    try {
        if (args.length > 0) {
            final String[] args2 = new String[args.length - 1];
            System.arraycopy(args, 1, args2, 0, args.length - 1);
            if ("-rebuild".equals(args[0])) {
                XmlConfiguration.main(args2);
            } else if ("-oracle2xml".equals(args[0])) {
                Oracle2Xml.main(args2);
            } else if ("-batch".equals(args[0])) {
                if ("-server".equals(args[1])) {
                    batchMode = BATCH_SERVER;
                } else if ("-client".equals(args[1])) {
                    batchMode = BATCH_CLIENT;
                }
            } else {
                Log.error("Unknown options '" + Arrays.toString(args)
                        + "'\nUsage : java -jar starter.jar <options>, where options are :\n"
                        + "\t-rebuild -game <tbs name> [-x] [-d] [-v] [-h] [-f] [-n]\n"
                        + "\t-oracle2xml -f <oracle file> -d <output directory> [-v] [-h]");
            }
            System.exit(0);
            return;
        }
        if (batchMode == -1 && !"Mac OS X".equals(System.getProperty("os.name"))) {
            splash = new SplashScreen(MToolKit.getIconPath("splash.jpg"), null, 2000);
        }

        // language settings
        LanguageManager.initLanguageManager(Configuration.getString("language", "auto"));
    } catch (Throwable t) {
        Log.error("START-ERROR : \n\t" + t.getMessage());
        System.exit(1);
        return;
    }
    Log.debug("MP Language : " + LanguageManager.getLanguage().getName());
    speparateAvatar = Toolkit.getDefaultToolkit().getScreenSize().height > 768;

    // verify the java version, minimal is 1.5
    if (new JavaVersion().compareTo(new JavaVersion(IdConst.MINIMAL_JRE)) == -1) {
        Log.error(LanguageManager.getString("wrongjava") + IdConst.MINIMAL_JRE);
    }

    // load look and feel settings
    lookAndFeelName = Configuration.getString("preferred", MUIManager.LF_SUBSTANCE_CLASSNAME);
    // try {
    // FileInputStream in= new FileInputStream("MAGIC.TTF");
    // MToolKit.defaultFont= Font.createFont(Font.TRUETYPE_FONT, in);
    // in.close();
    // MToolKit.defaultFont= MToolKit.defaultFont.deriveFont(Font.BOLD, 11);
    // }
    // catch (FileNotFoundException e) {
    // System.out.println("editorfont.ttf not found, using default.");
    // }
    // catch (Exception ex) {
    // ex.printStackTrace();
    // }

    // Read available L&F
    final LinkedList<Pair<String, String>> lfList = new LinkedList<Pair<String, String>>();
    try {
        BufferedReader buffReader = new BufferedReader(
                new InputStreamReader(MToolKit.getResourceAsStream(IdConst.FILE_THEME_SETTINGS)));
        String line;
        while ((line = buffReader.readLine()) != null) {
            line = line.trim();
            if (!line.startsWith("#")) {
                final int index = line.indexOf(';');
                if (index != -1) {
                    lfList.add(new Pair<String, String>(line.substring(0, index), line.substring(index + 1)));
                }
            }
        }
        IOUtils.closeQuietly(buffReader);
    } catch (Throwable e) {
        // no place for resolve this problem
        Log.debug("Error reading L&F properties : " + e.getMessage());
    }
    for (Pair<String, String> pair : lfList) {
        UIManager.installLookAndFeel(pair.key, pair.value);
    }

    // install L&F
    if (SkinLF.isSkinLF(lookAndFeelName)) {
        // is a SkinLF Look & Feel
        /*
         * Make sure we have a nice window decoration.
         */
        SkinLF.installSkinLF(lookAndFeelName);
    } else {
        // is Metal Look & Feel
        if (!MToolKit.isAvailableLookAndFeel(lookAndFeelName)) {
            // preferred look&feel is not available
            JOptionPane.showMessageDialog(magicForm,
                    LanguageManager.getString("preferredlfpb", lookAndFeelName),
                    LanguageManager.getString("error"), JOptionPane.INFORMATION_MESSAGE);
            setDefaultUI();
        }

        // Install the preferred
        LookAndFeel newLAF = MToolKit.geLookAndFeel(lookAndFeelName);
        frameDecorated = newLAF.getSupportsWindowDecorations();

        /*
         * Make sure we have a nice window decoration.
         */
        JFrame.setDefaultLookAndFeelDecorated(frameDecorated);
        JDialog.setDefaultLookAndFeelDecorated(frameDecorated);
        UIManager.setLookAndFeel(MToolKit.geLookAndFeel(lookAndFeelName));
    }

    // Start main thread
    try {
        new Magic();
        SwingUtilities.invokeLater(SkinLF.REFRESH_RUNNER);
    } catch (Throwable e) {
        Log.fatal("In main thread, occurred exception : ", e);
        ConnectionManager.closeConnexions();
        return;
    }
}

From source file:SciTK.Plot.java

/** 
 * Constructor (automatic window sizing) 
 *///from w ww.  java 2s.  c  o  m
public Plot() {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    def_width = (int) (screenSize.getWidth() / 4);
    def_height = (int) (screenSize.getHeight() / 4);
    // for very wide screen resolutions (i.e. dual monitor setups)
    // the above creates funny results. Introduce a max aspect ratio:
    def_width = Math.min(def_width, 2 * def_height);
}

From source file:visualize.Visualize.java

public static void makeScreenshot(final int index) {
    makeScreenshot(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()), index);
}

From source file:com.mirth.connect.client.ui.Mirth.java

/**
 * Create the alternate key bindings for the menu shortcut key mask. This is called if the menu
 * shortcut key mask is not the CTRL key (i.e. COMMAND on OSX)
 *//*from  ww  w . j  a v a2 s .  co  m*/
private static void createAlternateKeyBindings() {
    int acceleratorKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    // Add the common KeyBindings for macs
    KeyBinding[] defaultBindings = {
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_C, acceleratorKey), DefaultEditorKit.copyAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_V, acceleratorKey), DefaultEditorKit.pasteAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_X, acceleratorKey), DefaultEditorKit.cutAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_A, acceleratorKey),
                    DefaultEditorKit.selectAllAction),
            // deleteNextWordAction and deletePrevWordAction were not available in Java 1.5
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, acceleratorKey),
                    DefaultEditorKit.deleteNextWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, acceleratorKey),
                    DefaultEditorKit.deletePrevWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, acceleratorKey),
                    DefaultEditorKit.nextWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_KP_RIGHT, acceleratorKey),
                    DefaultEditorKit.nextWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, acceleratorKey),
                    DefaultEditorKit.previousWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_KP_LEFT, acceleratorKey),
                    DefaultEditorKit.previousWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, acceleratorKey | InputEvent.SHIFT_MASK),
                    DefaultEditorKit.selectionNextWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_KP_RIGHT, acceleratorKey | InputEvent.SHIFT_MASK),
                    DefaultEditorKit.selectionNextWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, acceleratorKey | InputEvent.SHIFT_MASK),
                    DefaultEditorKit.selectionPreviousWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_KP_LEFT, acceleratorKey | InputEvent.SHIFT_MASK),
                    DefaultEditorKit.selectionPreviousWordAction) };

    keyMapBindings(new javax.swing.JTextField(), defaultBindings);
    keyMapBindings(new javax.swing.JPasswordField(), defaultBindings);
    keyMapBindings(new javax.swing.JTextPane(), defaultBindings);
    keyMapBindings(new javax.swing.JTextArea(), defaultBindings);
    keyMapBindings(new com.mirth.connect.client.ui.components.MirthTextField(), defaultBindings);
    keyMapBindings(new com.mirth.connect.client.ui.components.MirthPasswordField(), defaultBindings);
    keyMapBindings(new com.mirth.connect.client.ui.components.MirthTextPane(), defaultBindings);
    keyMapBindings(new com.mirth.connect.client.ui.components.MirthTextArea(), defaultBindings);
}

From source file:de.tud.kom.p2psim.impl.skynet.visualization.SkyNetVisualization.java

private SkyNetVisualization() {
    super("Metric-Visualization");
    createLookAndFeel();// w w w  . j a v  a 2 s.  c om
    displayedMetrics = new HashMap<String, MetricsPlot>();
    setLayout(new GridLayout(1, 1));
    addWindowListener(this);
    graphix = new JPanel(new GridBagLayout());
    graphix.setLayout(new BoxLayout(graphix, BoxLayout.PAGE_AXIS));
    mb = new JMenuBar();
    JScrollPane scroller = new JScrollPane(graphix, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    // calculating the size of the application-window as well as of all
    // components, that depend on the size of the window
    Toolkit kit = Toolkit.getDefaultToolkit();
    int appWidth = kit.getScreenSize().width * 3 / 4;
    int appHeight = kit.getScreenSize().height * 3 / 4;
    scroller.setPreferredSize(new Dimension(appWidth, appHeight));
    getContentPane().add(scroller);
    maxPlotsPerRow = 1;
    while ((maxPlotsPerRow + 1) * PLOT_WIDTH < appWidth) {
        maxPlotsPerRow++;
    }
    log.warn("Creating the visualization...");
    mb.add(new JMenu("File"));
    JMenu met = new JMenu("Available Metrics");
    met.setEnabled(false);
    mb.add(met);
    setJMenuBar(mb);
}

From source file:com.qspin.qtaste.ui.xmleditor.TestRequirementEditor.java

public TestRequirementEditor() {
    super(new BorderLayout());
    m_systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    genUI();
}

From source file:piilSource.BarChart.java

public BarChart(final String title, List<List<String>> list, Character meta) {

    super(title);
    geneName = title;/*from   w  w w. j  a v a  2s  . c o  m*/
    metaLabel = (meta.equals('M')) ? "beta" : "expression";
    final CategoryDataset dataset = createDataset(list, metaLabel);
    final JFreeChart chart = createChart(title, dataset, metaLabel);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(600, 300));
    setContentPane(chartPanel);

    exportButton = new JButton("Export to image");
    exportButton.setPreferredSize(new Dimension(150, 30));
    closeButton = new JButton("Close");
    closeButton.setPreferredSize(new Dimension(150, 30));
    buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new FlowLayout());
    buttonsPanel.setBackground(Color.WHITE);
    buttonsPanel.add(exportButton);
    buttonsPanel.add(closeButton);

    exportButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent bc) {
            ExportDialog export = new ExportDialog();
            export.showExportDialog(chartFrame, "Export view as ...", chartPanel,
                    "Barplot of the " + metaLabel + " values for all samples - " + title);
        }
    });
    closeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            chartFrame.dispose();
        }
    });

    chartFrame = new JFrame();
    chartFrame.setLayout(new BorderLayout());
    chartFrame.setSize(400, 100);
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension dim = tk.getScreenSize();
    int xPos = (dim.width / 2) - (chartFrame.getWidth() / 2);
    int yPos = (dim.height / 2) - (chartFrame.getHeight() / 2);
    chartFrame.setLocation(xPos, yPos);
    chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    chartFrame.add(chartPanel, BorderLayout.CENTER);
    chartFrame.add(buttonsPanel, BorderLayout.SOUTH);

    chartFrame.setSize(800, 400);
    chartFrame.setVisible(true);

}

From source file:main.Configuration.java

/**
 * Load an image icon to be displayed on a button.
 * /*  ww w  .  j a  v a2s  . co  m*/
 * @param path
 * @return image for a button
 */
public static Image getImage(String path) {
    URL url = Configuration.class.getResource(path);
    if (url == null) {
        return null;
    }
    return Toolkit.getDefaultToolkit().getImage(url);
}

From source file:ImageUtilities.java

/**
 * Returns whether the specified image is already fully loaded.
 *///from   w ww  .jav a 2 s  . c  o  m

public static boolean isLoaded(Image image) {
    return (Toolkit.getDefaultToolkit().checkImage(image, -1, -1, null) & ImageObserver.ALLBITS) != 0;
}