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.harvard.mcz.imagecapture.ChangePasswordDialog.java

private void setForDisplay() {
    this.pack();//from   w ww.jav  a 2 s  .c o  m
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    this.setLocation((screenSize.width - this.getWidth()) / 2, (screenSize.height - this.getHeight()) / 2);
}

From source file:com.mgmtp.jfunk.core.util.ScreenCapturer.java

/**
 * Captures the whole screen and saves it as png to the specified file. The file must have the
 * extension {@code png}. Any necessary but non-existent parent directories of the specified
 * file are created.// w  w w .  java2 s  .  c  om
 * 
 * @param file
 *            the file to save the screenshot to
 */
public static void captureScreen(final File file) {
    Rectangle rectangle = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    captureScreenRect(file, rectangle);
}

From source file:ImageTransferTest.java

/**
 * Copies the current image to the system clipboard.
 *///from  w w w .j a  v a  2s. c om
private void copy() {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    ImageTransferable selection = new ImageTransferable(image);
    clipboard.setContents(selection, null);
}

From source file:com.smart.aqimonitor.client.AqiMonitor.java

/**
 * Create the frame./*from  www .  j a  v a2s.  c o  m*/
 */
public AqiMonitor() {
    refSelf = this;
    setPreferredSize(new Dimension(640, 480));
    setTitle("\u7A7A\u6C14\u8D28\u91CF\u76D1\u6D4B");
    setIconImage(Toolkit.getDefaultToolkit()
            .getImage(AqiMonitor.class.getResource("/lombok/installer/eclipse/STS.png")));
    setMinimumSize(new Dimension(640, 480));
    setMaximumSize(new Dimension(1024, 768));
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 636, 412);
    contentPane = new JPanel();
    contentPane.setPreferredSize(new Dimension(640, 480));
    contentPane.setMinimumSize(new Dimension(640, 480));
    contentPane.setMaximumSize(new Dimension(1024, 768));
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);

    JPanel mainPanel = new JPanel();
    contentPane.add(mainPanel, BorderLayout.CENTER);
    mainPanel.setLayout(new BorderLayout(0, 0));

    JPanel contentPanel = new JPanel();
    mainPanel.add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new BorderLayout(0, 0));

    JScrollPane scrollPane = new JScrollPane();
    scrollPane
            .setViewportBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    contentPanel.add(scrollPane, BorderLayout.CENTER);

    textPane = new AqiTextPane();
    textPane.addInputMethodListener(new InputMethodListener() {

        public void caretPositionChanged(InputMethodEvent event) {

        }

        public void inputMethodTextChanged(InputMethodEvent event) {
            textPane.setCaretPosition(document.getLength() + 1);
        }
    });
    textPane.setEditable(false);
    textPane.setOpaque(false);
    textPane.setForeground(Color.BLACK);
    scrollPane.setViewportView(textPane);
    document = textPane.getStyledDocument();

    document.addDocumentListener(new DocumentListener() {

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

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

        @Override
        public void changedUpdate(DocumentEvent e) {
            if (e.getDocument() == document) {
                textPane.setCaretPosition(document.getLength());
            }
        }
    });

    JPanel buttonPanel = new JPanel();
    contentPane.add(buttonPanel, BorderLayout.SOUTH);
    buttonPanel.setLayout(new BorderLayout(0, 0));

    JLabel lblTipsLabel = new JLabel(
            "Tips\uFF1A\u6587\u4EF6\u4FDD\u5B58\u683C\u5F0Fcsv\u53EF\u7528Excel\u6253\u5F00");
    lblTipsLabel.setForeground(Color.BLUE);
    buttonPanel.add(lblTipsLabel, BorderLayout.WEST);

    JPanel panel = new JPanel();
    buttonPanel.add(panel, BorderLayout.CENTER);
    panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

    JButton btnRetrieve = new JButton("\u624B\u52A8\u83B7\u53D6\u6570\u636E");
    panel.add(btnRetrieve);
    btnRetrieve.setVerticalAlignment(SwingConstants.BOTTOM);

    JButton btnNewButton = new JButton("\u5173\u4E8E");
    btnNewButton.setToolTipText("\u5173\u4E8E");
    btnNewButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JTextArea textArea = new JTextArea(
                    "\n        csv\n\n        smartstudio@foxmail.com");
            textArea.setColumns(35);
            textArea.setRows(6);
            textArea.setLineWrap(true);// 
            textArea.setEditable(false);// 
            textArea.setOpaque(false);
            JOptionPane.showMessageDialog(contentPane, textArea, "", JOptionPane.PLAIN_MESSAGE);
        }
    });

    JButton btnSetting = new JButton("\u8BBE\u7F6E");
    btnSetting.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

            Point parentPos = refSelf.getLocation();

            AqiSettingDialog settingDialog = new AqiSettingDialog(refSelf, pm25InDetailJob.getAqiParser());
            settingDialog.setModal(true);
            settingDialog.setLocation(parentPos.x + 100, parentPos.y + 150);
            settingDialog.init();
            settingDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            settingDialog.setVisible(true);
        }
    });

    JButton btnExportDir = new JButton("\u67E5\u770B\u6570\u636E");
    btnExportDir.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {

                String[] cmd = new String[5];

                String filePath = pm25InDetailJob.getAqiParser().getFilePath();
                File file = new File(filePath);
                if (!file.exists()) {
                    FileUtil.makeDir(file);
                }
                if (!file.isDirectory()) {
                    JOptionPane.showMessageDialog(contentPane, "", "",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }

                cmd[0] = "cmd";
                cmd[1] = "/c";
                cmd[2] = "start";
                cmd[3] = " ";
                cmd[4] = pm25InDetailJob.getAqiParser().getFilePath();

                Runtime.getRuntime().exec(cmd);

            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });
    panel.add(btnExportDir);
    panel.add(btnSetting);
    panel.add(btnNewButton);
    btnRetrieve.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (!isRetrieving) {
                isRetrieving = true;
                Thread firstRun = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        pm25InDetailJob.refresh();
                        isRetrieving = false;
                    }
                });

                firstRun.start();
            }
        }
    });

    init();
}

From source file:net.sourceforge.metware.binche.execs.BiNCheExec.java

private void runGui() {

    final JFrame window = new JFrame("binche Settings");
    final SettingsPanel settingsPanel = new SettingsPanel();
    window.getContentPane().add(settingsPanel);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setGlassPane(settingsPanel.getProgressPanel());
    window.pack();//from w w  w  .ja v  a  2  s . c  om

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    window.setLocation(screenSize.width / 2 - (window.getWidth() / 2),
            screenSize.height / 2 - (window.getHeight() / 2));
    window.setVisible(true);
    window.setResizable(true);
}

From source file:AttributesApp.java

public void loadImage() {
    image = Toolkit.getDefaultToolkit().getImage("largeJava2sLogo.gif");
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 1);/*from  www  . j  a  v a2s .  co  m*/
    try {
        mt.waitForAll();
    } catch (Exception e) {
        System.out.println("Exception while loading.");
    }

    if (image.getWidth(this) == -1) {
        System.out.println("no images");
        System.exit(0);
    }
}

From source file:net.sf.keystore_explorer.gui.actions.SignCsrAction.java

/**
 * Construct action.//ww  w  .jav a  2  s .  co m
 *
 * @param kseFrame
 *            KeyStore Explorer frame
 */
public SignCsrAction(KseFrame kseFrame) {
    super(kseFrame);

    putValue(LONG_DESCRIPTION, res.getString("SignCsrAction.statusbar"));
    putValue(NAME, res.getString("SignCsrAction.text"));
    putValue(SHORT_DESCRIPTION, res.getString("SignCsrAction.tooltip"));
    putValue(SMALL_ICON, new ImageIcon(Toolkit.getDefaultToolkit()
            .createImage(getClass().getResource(res.getString("SignCsrAction.image")))));
}

From source file:ch.fork.AdHocRailway.ui.utils.ImageTools.java

public static Image TransformColorToTransparency(BufferedImage image, Color c1, Color c2) {
    // Primitive test, just an example
    final int r1 = c1.getRed();
    final int g1 = c1.getGreen();
    final int b1 = c1.getBlue();
    final int r2 = c2.getRed();
    final int g2 = c2.getGreen();
    final int b2 = c2.getBlue();
    ImageFilter filter = new RGBImageFilter() {
        public final int filterRGB(int x, int y, int rgb) {
            int r = (rgb & 0xFF0000) >> 16;
            int g = (rgb & 0xFF00) >> 8;
            int b = rgb & 0xFF;
            if (r >= r1 && r <= r2 && g >= g1 && g <= g2 && b >= b1 && b <= b2) {
                // Set fully transparent but keep color
                return rgb & 0xFFFFFF;
            }/*from www  .  j  a  va2s.  c  o m*/
            return rgb;
        }
    };

    ImageProducer ip = new FilteredImageSource(image.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
}

From source file:de.tor.tribes.util.ClipboardWatch.java

@Override
public void run() {
    logger.info("Starting ClipboardMonitor");
    String lastHash = null;/*from  ww w .ja  v a  2s .  co m*/
    while (true) {
        if (DSWorkbenchMainFrame.getSingleton().isWatchClipboard()) {
            try {
                Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
                String data = (String) t.getTransferData(DataFlavor.stringFlavor);
                String currentHash = SecurityAdapter.hashStringMD5(data);
                boolean validData = false;
                if ((data.length() > 10) && (lastHash == null || !currentHash.equals(lastHash))) {
                    if (PluginManager.getSingleton().executeReportParser(data)) {
                        //report parsed, clean clipboard
                        logger.info("Report successfully parsed.");
                        playNotification();
                        validData = true;
                    } else if (PluginManager.getSingleton().executeTroopsParser(data)) {
                        logger.info("Troops successfully parsed.");
                        SystrayHelper.showInfoMessage("Truppen erfolgreich eingelesen");
                        playNotification();
                        //at least one village was found, so clean the clipboard
                        validData = true;
                    } else if (PluginManager.getSingleton().executeGroupParser(data)) {
                        logger.info("Groups successfully parsed.");
                        SystrayHelper.showInfoMessage("Gruppen erfolgreich eingelesen");
                        playNotification();
                        validData = true;
                    } else if (PluginManager.getSingleton().executeSupportParser(data)) {
                        logger.info("Support successfully parsed.");
                        SystrayHelper.showInfoMessage("Untersttzungen erfolgreich eingelesen");
                        playNotification();
                        validData = true;
                    } else if (PluginManager.getSingleton().executeNonPAPlaceParser(data)) {
                        logger.info("Place info successfully parsed.");
                        SystrayHelper.showInfoMessage("Truppen aus Versammlungsplatz erfolgreich eingelesen");
                        playNotification();
                        validData = true;
                    }
                }
                if (validData) {
                    lastHash = currentHash;
                }
            } catch (Exception e) {
                //no usable data
                //  e.printStackTrace();
            }
        } else {
            //clipboard watch is disabled, sleep 9 + 1 seconds
            try {
                Thread.sleep(9000);
            } catch (Exception e) {
            }
        }
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
        }
    }
}

From source file:com.jwmsolutions.timeCheck.gui.TodoForm.java

private void myInitComponents() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screenSize = tk.getScreenSize();
    int screenHeight = screenSize.height;
    int screenWidth = screenSize.width;
    setLocation(screenWidth - getSize().width - 20, screenHeight - getSize().height - 60);
}