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:com.awesomecoding.minetestlauncher.Main.java

private void initialize() {
    fileGetter = new FileGetter(userhome + "\\minetest\\temp\\");
    latest = fileGetter.getContents("http://socialmelder.com/minetest/latest.txt", true);
    currentVersion = latest.split("\n")[0];
    changelog = fileGetter.getContents("http://socialmelder.com/minetest/changelog.html", false);

    try {/*from w  w w. j  ava  2s . com*/
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        e.printStackTrace();
    }

    frmMinetestLauncherV = new JFrame();
    frmMinetestLauncherV.setResizable(false);
    frmMinetestLauncherV.setIconImage(Toolkit.getDefaultToolkit()
            .getImage(Main.class.getResource("/com/awesomecoding/minetestlauncher/icon.png")));
    frmMinetestLauncherV.setTitle("Minetest Launcher (Version 0.1)");
    frmMinetestLauncherV.setBounds(100, 100, 720, 480);
    frmMinetestLauncherV.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SpringLayout springLayout = new SpringLayout();
    frmMinetestLauncherV.getContentPane().setLayout(springLayout);

    final JProgressBar progressBar = new JProgressBar();
    springLayout.putConstraint(SpringLayout.WEST, progressBar, 10, SpringLayout.WEST,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, progressBar, -10, SpringLayout.SOUTH,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.EAST, progressBar, -130, SpringLayout.EAST,
            frmMinetestLauncherV.getContentPane());
    frmMinetestLauncherV.getContentPane().add(progressBar);

    final JButton btnDownloadPlay = new JButton("Play!");
    springLayout.putConstraint(SpringLayout.WEST, btnDownloadPlay, 6, SpringLayout.EAST, progressBar);
    springLayout.putConstraint(SpringLayout.SOUTH, btnDownloadPlay, 0, SpringLayout.SOUTH, progressBar);
    springLayout.putConstraint(SpringLayout.EAST, btnDownloadPlay, -10, SpringLayout.EAST,
            frmMinetestLauncherV.getContentPane());
    frmMinetestLauncherV.getContentPane().add(btnDownloadPlay);

    final JLabel label = new JLabel("Ready to play!");
    springLayout.putConstraint(SpringLayout.WEST, label, 10, SpringLayout.WEST,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.NORTH, btnDownloadPlay, 0, SpringLayout.NORTH, label);
    springLayout.putConstraint(SpringLayout.SOUTH, label, -37, SpringLayout.SOUTH,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.NORTH, progressBar, 6, SpringLayout.SOUTH, label);
    frmMinetestLauncherV.getContentPane().add(label);

    JTextPane txtpnNewFeatures = new JTextPane();
    txtpnNewFeatures.setBackground(SystemColor.window);
    springLayout.putConstraint(SpringLayout.NORTH, txtpnNewFeatures, 10, SpringLayout.NORTH,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.WEST, txtpnNewFeatures, 10, SpringLayout.WEST,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, txtpnNewFeatures, -10, SpringLayout.NORTH, btnDownloadPlay);
    springLayout.putConstraint(SpringLayout.EAST, txtpnNewFeatures, 0, SpringLayout.EAST, btnDownloadPlay);
    txtpnNewFeatures.setEditable(false);
    txtpnNewFeatures.setContentType("text/html");
    txtpnNewFeatures.setText(changelog);
    txtpnNewFeatures.setFont(new Font("Tahoma", Font.PLAIN, 12));
    frmMinetestLauncherV.getContentPane().add(txtpnNewFeatures);

    File file = new File(userhome + "\\minetest\\version.txt");

    if (!file.exists())
        newVersion = true;
    else {
        String version = fileGetter.getLocalContents(file, false);
        if (!version.equals(currentVersion))
            newVersion = true;
    }

    if (newVersion) {
        label.setText("New Version Available! (" + currentVersion + ")");
        btnDownloadPlay.setText("Download & Play");

        btnDownloadPlay.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                Thread t = new Thread() {
                    public void run() {
                        File file = new File(userhome + "\\minetest\\version.txt");
                        String version = fileGetter.getLocalContents(file, false);
                        try {
                            FileUtils.deleteDirectory(new File(userhome + "\\minetest\\minetest-" + version));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        fileGetter.download(latest.split("\n")[1], userhome + "\\minetest\\temp\\",
                                "minetest.zip", label, progressBar, btnDownloadPlay, currentVersion);
                        try {
                            label.setText("Cleaning up...");
                            btnDownloadPlay.setText("Cleaning up...");
                            FileUtils.deleteDirectory(new File(userhome + "\\minetest\\temp"));
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        System.exit(0);
                    }
                };
                t.start();
            }
        });
    } else {
        btnDownloadPlay.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                try {
                    label.setText("Launching...");
                    btnDownloadPlay.setEnabled(false);
                    btnDownloadPlay.setText("Launching...");
                    File file = new File(userhome + "\\minetest\\version.txt");
                    String version = fileGetter.getLocalContents(file, false);
                    Runtime.getRuntime()
                            .exec(userhome + "\\minetest\\minetest-" + version + "\\bin\\minetest.exe");
                    System.exit(0);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
        progressBar.setValue(100);
    }
}

From source file:cz.alej.michalik.totp.client.AddDialog.java

public AddDialog(final Properties prop) {
    System.out.println("Pridat novy zaznam");
    this.setTitle("Pidat");
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    this.setMinimumSize(new Dimension(600, 150));
    this.setLocationByPlatform(true);
    // Panel pro vytvoen okraj
    JPanel panel = new JPanel();
    panel.setBorder(new EmptyBorder(10, 10, 10, 10));
    panel.setLayout(new GridBagLayout());
    // Vlastnosti pro popisky
    GridBagConstraints label = new GridBagConstraints();
    label.insets = new Insets(2, 2, 2, 2);
    label.fill = GridBagConstraints.NONE;
    label.weightx = 1;/*from   w ww.j a v  a 2 s.co m*/
    // Vlastnosti pro pole
    GridBagConstraints field = new GridBagConstraints();
    field.insets = new Insets(2, 2, 2, 2);
    field.fill = GridBagConstraints.HORIZONTAL;
    field.weightx = 10;

    this.add(panel);

    // Nastavm ikonu okna
    try {
        String path = "/material-design-icons/content/drawable-xhdpi/ic_create_black_48dp.png";
        this.setIconImage(Toolkit.getDefaultToolkit().getImage(App.class.getResource(path)));
    } catch (NullPointerException ex) {
        System.out.println("Icon not found");
    }

    // Pole pro pojmenovn zznamu
    // Ikona
    ImageIcon icon = null;
    try {
        String path = "/material-design-icons/editor/drawable-xhdpi/ic_format_color_text_black_18dp.png";
        icon = new ImageIcon(App.class.getResource(path));
    } catch (NullPointerException ex) {
        System.out.println("Icon not found");
    }
    // Pidn labelu s ikonou a nastavm velikost psma
    label.gridy = 0;
    field.gridy = 0;
    JLabel nameLabel = new JLabel("Nzev: ", icon, JLabel.CENTER);
    nameLabel.setFont(nameLabel.getFont().deriveFont(App.FONT_SIZE * 2 / 3));
    panel.add(nameLabel, label);
    // Pole pro jmno
    final JTextField name = new JTextField();
    name.setMaximumSize(new Dimension(Integer.MAX_VALUE, 50));
    name.setFont(name.getFont().deriveFont(App.FONT_SIZE * 2 / 3));
    panel.add(name, field);

    // Pole pro zadn sdlenho hesla
    // Ikona
    icon = null;
    try {
        String path = "/material-design-icons/hardware/drawable-xhdpi/ic_security_black_18dp.png";
        icon = new ImageIcon(App.class.getResource(path));
    } catch (NullPointerException ex) {
        System.out.println("Icon not found");
    }
    // Pidn labelu s ikonou
    label.gridy = 1;
    field.gridy = 1;
    JLabel secretLabel = new JLabel("Heslo: ", icon, JLabel.CENTER);
    secretLabel.setFont(secretLabel.getFont().deriveFont(App.FONT_SIZE * 2 / 3));
    panel.add(secretLabel, label);
    // Pole pro heslo
    final JTextField secret = new JTextField();
    secret.setMaximumSize(new Dimension(Integer.MAX_VALUE, 50));
    secret.setFont(secret.getFont().deriveFont(App.FONT_SIZE * 2 / 3));
    panel.add(secret, field);

    this.setVisible(true);

    // Akce pro odesln formule
    ActionListener submit = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            submit(prop, name, secret, false);
        }
    };

    // Pi stisku klvesy Enter odele formul
    name.addActionListener(submit);
    secret.addActionListener(submit);
    // Pi zmn pole pro heslo se vstup okamit zformtuje
    final Runnable sanitizer = new Runnable() {
        @Override
        public void run() {
            sanitize(secret);

        }
    };
    secret.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            SwingUtilities.invokeLater(sanitizer);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }
    });

    // Pi zaven okna odele formul
    this.addWindowListener(new WindowListener() {

        @Override
        public void windowOpened(WindowEvent e) {
            // Ignorovat

        }

        @Override
        public void windowIconified(WindowEvent e) {
            // Ignorovat

        }

        @Override
        public void windowDeiconified(WindowEvent e) {
            // Ignorovat

        }

        @Override
        public void windowDeactivated(WindowEvent e) {
            // Ignorovat

        }

        @Override
        public void windowClosing(WindowEvent e) {
            // Odeslat
            submit(prop, name, secret, true);

        }

        @Override
        public void windowClosed(WindowEvent e) {
            // Ignorovat

        }

        @Override
        public void windowActivated(WindowEvent e) {
            // Ignorovat

        }
    });
}

From source file:MinAppletviewer.java

public Image getImage(URL url) {
    return Toolkit.getDefaultToolkit().getImage(url);
}

From source file:me.mayo.telnetkek.MainPanel.java

public void setup() {
    this.txtServer.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
        @Override//from w  ww  .j  av a 2 s .c  o m
        public void keyTyped(KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                MainPanel.this.triggerConnect();
            }
        }
    });

    this.loadServerList();

    final URL icon = this.getClass().getResource("/icon.png");
    if (icon != null) {
        setIconImage(Toolkit.getDefaultToolkit().createImage(icon));
    }

    setupTablePopup();

    this.getConnectionManager().updateTitle(false);

    this.tblPlayers.setModel(playerListTableModel);

    this.tblPlayers.getRowSorter().toggleSortOrder(0);

    this.setLocationRelativeTo(null);
    this.setVisible(true);
}

From source file:ImageUtilities.java

/**
 * Starts loading the given images, returns only when all the images are done
 * loading. If you just need to preload one Image, use the preload(Image) method
 * instead.//from  ww  w .  ja  v  a  2s.c o  m
 *
 * @return An array specifying the loading result of each image. Possible values
 * are {@link #COMPLETE}, {@link #ERRORED} and {@link #ABORTED}.
 *
 * @see #preload(Image)
 */

public static int[] preload(Image[] images, int[] results) {
    Object[] locks = new Object[images.length];
    ImageLoadObserver[] loadObservers = new ImageLoadObserver[images.length];
    if ((results == null) || (results.length < images.length))
        results = new int[images.length];
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    for (int i = 0; i < images.length; i++) {
        locks[i] = new Object();
        loadObservers[i] = new ImageLoadObserver(locks[i]);
        toolkit.prepareImage(images[i], -1, -1, loadObservers[i]);
    }

    for (int i = 0; i < images.length; i++) {
        synchronized (locks[i]) {
            int result = toolkit.checkImage(images[i], -1, -1, null);

            if ((result & ImageObserver.ALLBITS) != 0) {
                results[i] = COMPLETE;
                continue;
            }
            if ((result & ImageObserver.ERROR) != 0) {
                results[i] = ERRORED;
                continue;
            }
            if ((result & ImageObserver.ABORT) != 0) {
                results[i] = ABORTED;
                continue;
            }

            try {
                locks[i].wait();
                results[i] = loadObservers[i].getResult();
            } catch (InterruptedException e) {
                results[i] = INTERRUPTED;
            }
        }
    }

    return results;
}

From source file:OAT.ui.BarChartFrame.java

@Override
protected void init() {
    //        setJMenuBar(new MainMenuBar(this));
    //        setContentPane(chartPanel);
    //        setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    //set getItemCount and location
    //Rectangle mainBound = Main.frame.getBounds();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    screenSize.height = screenSize.height - MENU_BAR_HEIGHT;
    //Dimension chartFrameSize = getChartPanelSize();
    //chartFrameSize.height += MENU_BAR_HEIGHT;

    int gridRows = Main.chartFramesGrid.length;
    int gridColumns = Main.chartFramesGrid[0].length;

    boolean isOccupied = false;
    for (int c = 0; c < gridColumns; c++) {
        for (int r = 0; r < gridRows; r++) {
            Rectangle bound = Main.chartFramesGrid[r][c];

            for (BarChartFrame existingFrame : Main.chartFrames) {
                if (bound.contains(existingFrame.getLocation())
                        || existingFrame.getBounds().contains(bound.intersection(new Rectangle(screenSize)))) {
                    isOccupied = true;/*w  w  w  .j a v  a 2 s .co  m*/
                    break;
                }
            }

            if (!isOccupied) {
                setBounds(bound);
                break;
            }
        }

        if (!isOccupied) {
            break;
        }
    }

    if (isOccupied) {
        setBounds(Main.chartFramesGrid[Main.lastChartFrameGridId
                % gridRows][(Main.lastChartFrameGridId / gridRows) % gridColumns]);
    }

    Main.lastChartFrameGridId++;

    Main.chartFrames.add(this);

    addComponentListener(new java.awt.event.ComponentAdapter() {

        @Override
        public void componentHidden(java.awt.event.ComponentEvent evt) {
            formComponentHidden(evt);
        }
    });

    //pack and display
    pack();
}

From source file:com.mirth.connect.client.ui.components.rsta.FindReplaceDialog.java

private void search(boolean find, boolean replaceAll) {
    warningLabel.setText("");
    if (StringUtils.isEmpty((String) findComboBox.getSelectedItem())) {
        return;//from w ww  . j a va2 s .  c o  m
    }

    SearchContext context = getContext();
    SearchResult result = getResult(context, find, replaceAll);
    boolean wrapped = false;

    if (result.getCount() == 0 && wrapSearchCheckBox.isSelected()) {
        int position = textArea.getCaretPosition();
        textArea.setCaretPosition(directionForwardRadio.isSelected() ? 0 : textArea.getDocument().getLength());
        result = getResult(context, find, replaceAll);
        if (result.getCount() == 0) {
            textArea.setCaretPosition(position);
        } else {
            wrapped = true;
            Toolkit.getDefaultToolkit().beep();
        }
    }

    if ((find || !replaceAll) && result.getMarkedCount() == 0 || replaceAll && result.getCount() == 0) {
        warningLabel.setText("No results found.");
    } else if (find) {
        warningLabel.setText(result.getMarkedCount() + " results found" + (wrapped ? "; wrapped." : "."));
    } else {
        warningLabel.setText(result.getCount() + " out of "
                + (replaceAll ? result.getCount() : result.getMarkedCount()) + " results replaced.");
    }

    updateProperties();
}

From source file:view.Dashboard.java

/**
 * Creates new form Dashboard/*from  w  ww . j a  va  2  s . c o  m*/
 */
public Dashboard() {
    cc = new ConnectionController();
    voltageSeries = new XYSeries("voltage");
    setPointSeries = new XYSeries("setpoint");
    voltageSeries.add(currentTime, 0);
    currentTime++;
    voltageDataset = new XYSeriesCollection();
    voltageDataset.addSeries(voltageSeries);
    voltageDataset.addSeries(setPointSeries);
    voltageLineChart = generateVoltageLineChart();
    initComponents();
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    this.setLocation(dim.width / 2 - this.getSize().width / 2, dim.height / 2 - this.getSize().height / 2);
    this.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
    baudRate.setSelectedItem(baudRate.getItemAt(3));
}

From source file:com.sshtools.common.ui.ResourceIcon.java

/**
 *
 *
 * @param imageName/* ww  w  .  j a  va 2 s  .co  m*/
 */
protected void loadImage(String imageName) {
    Image image = null;
    URL url = cls.getResource(imageName);

    if (url != null) {
        log.debug(url.toString());
        image = Toolkit.getDefaultToolkit().getImage(url);
    } else {
        try {
            if (System.getSecurityManager() != null) {
                AccessController.checkPermission(new FilePermission(imageName, "read"));
            }

            image = Toolkit.getDefaultToolkit().getImage(imageName);
        } catch (AccessControlException ace) {
            log.error("Icon " + imageName + " could not be located as a "
                    + "resource, and the current security manager will not "
                    + "allow checking for a local file.");
        }
    }

    if (image != null) {
        this.setImage(image);
    }
}

From source file:Main.java

/**
 * Computes the center point of the current screen device. If this method is called on JDK 1.4, Xinerama-aware
 * results are returned. (See Sun-Bug-ID 4463949 for details).
 *
 * @return the center point of the current screen.
 *///from  w  w w  .  j a  v a 2  s.c  o m
public static Point getCenterPoint() {
    final GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        final Method method = GraphicsEnvironment.class.getMethod("getCenterPoint", (Class[]) null);
        return (Point) method.invoke(localGraphicsEnvironment, (Object[]) null);
    } catch (Exception e) {
        // ignore ... will fail if this is not a JDK 1.4 ..
    }

    final Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
    return new Point(s.width / 2, s.height / 2);
}