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:ColorApp.java

public void loadImage() {
    displayImage = Toolkit.getDefaultToolkit().getImage("largeJava2sLogo.jpg");
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(displayImage, 1);/*  ww w.  ja  v  a 2 s.  c om*/
    try {
        mt.waitForAll();
    } catch (Exception e) {
        System.out.println("Exception while loading.");
    }

    if (displayImage.getWidth(this) == -1) {
        System.out.println("No jpg file");
        System.exit(0);
    }
}

From source file:com.artistech.tuio.mouse.MouseDriver.java

/**
 * Update Cursor Event.//w  w  w .ja  va2s. com
 *
 * @param tcur
 */
@Override
public void updateTuioCursor(TuioCursor tcur) {
    logger.trace(MessageFormat.format("update tuio cursor id: {0}", tcur.getCursorID()));

    int width = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
    int height = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();

    if (!curs.isEmpty() && curs.get(0).getLeft() == tcur.getSessionID()) {
        logger.debug(MessageFormat.format("update mouse move: ({0}, {1})",
                new Object[] { tcur.getScreenX(width), tcur.getScreenY(height) }));
        robot.mouseMove(tcur.getScreenX(width), tcur.getScreenY(height));
    }
    for (MutableTriple<Long, Integer, Integer> trip : curs) {
        if (trip.getLeft() == tcur.getSessionID()) {
            trip.setMiddle(tcur.getScreenX(width));
            trip.setRight(tcur.getScreenY(height));
            break;
        }
    }
}

From source file:com.photon.phresco.framework.actions.FrameworkBaseAction.java

public void copyToClipboard() {
    S_LOGGER.debug("Entered FrameworkBaseAction.copyToClipboard");
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(//  www. ja va  2  s  .  c o m
            new StringSelection(copyToClipboard.replaceAll(" ", "").replaceAll("(?m)^[ \t]*\r?\n", "")), null);

}

From source file:edu.harvard.mcz.imagecapture.ImageZoomPanel.java

/**
 * This method initializes this/*from www . j  a v  a2s . co  m*/
 * 
 */
private void initialize() {
    this.setSize(new Dimension(553, 323));
    this.setLayout(new BorderLayout());
    this.add(getJPanel(), BorderLayout.NORTH);
    this.add(getJScrollPane(), BorderLayout.CENTER);
    URL cursorFile = this.getClass()
            .getResource("/edu/harvard/mcz/imagecapture/resources/magnifying_glass.gif");
    try {
        log.debug(cursorFile.toString());
        Image zoomCursorImage = ImageIO.read(cursorFile);
        Point hotPoint = new Point(5, 5);
        zoomCursor = Toolkit.getDefaultToolkit().createCustomCursor(zoomCursorImage, hotPoint, "ZoomCursor");
    } catch (IOException e) {
        log.error("Unable to load ZoomCursor");
        zoomCursor = null;
    }
    jLabel.addMouseListener(this);

}

From source file:es.emergya.ui.base.BasicWindow.java

/**
 * Initialize the window with default values.
 *///from  w w  w  .j av  a  2  s .c  o  m
private void inicializar() {
    frame = new JFrame(i18n.getString("title")); //$NON-NLS-1$
    getFrame().setBackground(Color.WHITE);
    getFrame().setIconImage(ICON_IMAGE); //$NON-NLS-1$
    getFrame().addWindowListener(new RemoveClientesConectadosListener());

    getFrame().setMinimumSize(new Dimension(900, 600));
    getFrame().addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            resize();
        }

    });

    busyCursor = new Cursor(Cursor.WAIT_CURSOR);
    defaultCursor = new Cursor(Cursor.DEFAULT_CURSOR);
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image image = getImageIcon("/images/hand.gif");
    if (image != null)
        handCursor = toolkit.createCustomCursor(image, new Point(0, 0), "hand"); //$NON-NLS-1$
}

From source file:edu.harvard.mcz.imagecapture.RunnableJobReportDialog.java

/**
 * This method initializes this/*w  ww  .j  av a 2  s.co  m*/
 * 
 * @return void
 */
private void initialize() {
    this.setPreferredSize(new Dimension(1000, 400));
    this.setTitle(title);
    this.setContentPane(getJContentPane());
    this.pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    this.setLocation((screenSize.width - this.getWidth()) / 2, (screenSize.height - this.getHeight()) / 2);
}

From source file:net.pandoragames.far.ui.swing.component.UndoHistoryPopupMenu.java

private void init(SwingConfig config, ComponentRepository componentRepository) {
    // COPY/*from  w w  w . j av a  2 s  .  co m*/
    JMenuItem copy = new JMenuItem(config.getLocalizer().localize("label.copy"));
    copy.setAccelerator(KeyStroke.getKeyStroke("control C"));
    copy.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String selection = textComponent.getSelectedText();
            if (selection != null) {
                StringSelection textTransfer = new StringSelection(selection);
                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(textTransfer, null);
            }
        }
    });
    this.add(copy);
    // PASTE
    JMenuItem paste = new JMenuItem(config.getLocalizer().localize("label.paste"));
    paste.setAccelerator(KeyStroke.getKeyStroke("control V"));
    paste.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            Transferable transfer = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);

            try {
                if (transfer != null && transfer.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                    String text = (String) transfer.getTransferData(DataFlavor.stringFlavor);
                    String selected = textComponent.getSelectedText();
                    if (selected == null) {
                        int insertAt = textComponent.getCaretPosition();
                        textComponent.getDocument().insertString(insertAt, text, null);
                    } else {
                        int start = textComponent.getSelectionStart();
                        int end = textComponent.getSelectionEnd();
                        textComponent.getDocument().remove(start, end - start);
                        textComponent.getDocument().insertString(start, text, null);
                    }
                }
            } catch (UnsupportedFlavorException e) {
                LogFactory.getLog(this.getClass()).error("UnsupportedFlavorException reading from clipboard",
                        e);
            } catch (IOException iox) {
                LogFactory.getLog(this.getClass()).error("IOException reading from clipboard", iox);
            } catch (BadLocationException blx) {
                LogFactory.getLog(this.getClass()).error("BadLocationException reading from clipboard", blx);
            }
        }
    });
    this.add(paste);
    // UNDO
    Action undoAction = textComponent.getActionMap().get(UndoHistory.ACTION_KEY_UNDO);
    if (undoAction != null) {
        undoAction.putValue(Action.NAME, config.getLocalizer().localize("label.undo"));
        this.add(undoAction);
    }
    // REDO
    Action redoAction = textComponent.getActionMap().get(UndoHistory.ACTION_KEY_REDO);
    if (redoAction != null) {
        redoAction.putValue(Action.NAME, config.getLocalizer().localize("label.redo"));
        this.add(redoAction);
    }
    // PREVIOUS
    Action prevAction = textComponent.getActionMap().get(UndoHistory.ACTION_KEY_PREVIOUS);
    if (prevAction != null) {
        prevAction.putValue(Action.NAME, config.getLocalizer().localize("label.previous"));
        this.add(prevAction);
    }
    // NEXT
    Action nextAction = textComponent.getActionMap().get(UndoHistory.ACTION_KEY_NEXT);
    if (nextAction != null) {
        nextAction.putValue(Action.NAME, config.getLocalizer().localize("label.next"));
        this.add(nextAction);
    }
}

From source file:sanger.team16.gui.genevar.eqtl.query.SNPGeneAssocPlot.java

private Dimension getAutoPreferredSize() {
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

    if (dim.width > 1024)
        //return new Dimension(680/7*3, 420/7*3); // 3/7 Dimension(680, 420) for 1024 widescreen
        return new Dimension(680 / 5 * 2, 420 / 5 * 2); // 1024 wide

    //return new Dimension(250, 166);   // Original Dimension(680, 420)
    return new Dimension(250, 420 * 250 / 680);
}

From source file:AffineTransformApp.java

public void loadImage() {
    displayImage = Toolkit.getDefaultToolkit().getImage("largeJava2sLogo.jpg");
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(displayImage, 1);//from  ww  w  .ja v a2 s. co  m
    try {
        mt.waitForAll();
    } catch (Exception e) {
        System.out.println("Exception while loading.");
    }

    if (displayImage.getWidth(this) == -1) {
        System.out.println(" Missing .jpg file");
        System.exit(0);
    }
}

From source file:net.sf.keystore_explorer.gui.dnd.DragKeyPairEntry.java

/**
 * Construct DragKeyPairEntry.//w  w  w. j a  v a 2 s . c  o m
 *
 * @param name
 *            Entry name
 * @param privateKey
 *            Private key
 * @param password
 *            Private key password
 * @param certificateChain
 *            Certificate chain
 * @throws CryptoException
 *             If there was a problem creating the content
 */
public DragKeyPairEntry(String name, PrivateKey privateKey, Password password, Certificate[] certificateChain)
        throws CryptoException {
    super(name);

    try {
        // Binary content is PKCS #12 protected by password
        KeyStore p12 = KeyStoreUtil.create(KeyStoreType.PKCS12);
        p12.setKeyEntry(name, privateKey, new char[] {}, certificateChain);

        ByteArrayOutputStream baos = null;
        try {
            baos = new ByteArrayOutputStream();
            p12.store(baos, password.toCharArray());
            contentBytes = baos.toByteArray();
        } finally {
            IOUtils.closeQuietly(baos);
        }

        /*
         * String content is PKCS #8 PEM (private key) protected by PBE
         * (SHA-1 and 128 bit RC4) concatenated with PCKS #7 PEM
         * (certificate chain)
         */
        StringBuffer sbContent = new StringBuffer();
        String pkcs8 = Pkcs8Util.getEncryptedPem(privateKey, Pkcs8PbeType.SHA1_128BIT_RC4, password);
        String pkcs7 = X509CertUtil.getCertsEncodedPkcs7Pem(X509CertUtil.convertCertificates(certificateChain));

        // Output notes delimiting the different parts
        sbContent.append(res.getString("DragKeyPairEntry.StringFlavor.PrivateKeyPart.text"));
        sbContent.append("\n\n");
        sbContent.append(pkcs8);
        sbContent.append('\n');
        sbContent.append(res.getString("DragKeyPairEntry.StringFlavor.CertificateChainPart.text"));
        sbContent.append("\n\n");
        sbContent.append(pkcs7);

        contentStr = sbContent.toString();

        // Get drag image
        image = new ImageIcon(Toolkit.getDefaultToolkit()
                .createImage(getClass().getResource(res.getString("DragKeyPairEntry.Drag.image"))));
    } catch (IOException ex) {
        throw new CryptoException(res.getString("NoGetKeyPairEntryContent.exception.message"), ex);
    } catch (GeneralSecurityException ex) {
        throw new CryptoException(res.getString("NoGetKeyPairEntryContent.exception.message"), ex);
    }
}