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:client.gui.ConnectionDialog.java

public ConnectionDialog() {

    connect = new JButton("Connect");
    connectDev = new JButton("Connect (Developer)");
    connectSame = new JButton("Connect (a as nick)");

    nick = new JTextField();
    host = new JTextField();
    port = new JTextField();

    setLayout(new GridBagLayout());

    final GridBagConstraints c = new GridBagConstraints();

    setSize(new Dimension(400, 200));

    host.setPreferredSize(new Dimension(200, 24));

    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0.0;//from  www. j  a v a  2s .  c o m
    c.gridx = 0;
    c.gridy = 0;
    add(new JLabel("Nick:"), c);
    c.gridy = 1;
    add(new JLabel("Host:"), c);
    c.gridy = 2;
    add(new JLabel("Port:"), c);

    c.gridx = 1;

    c.gridy = 0;
    add(nick, c);

    c.gridy = 1;
    add(host, c);

    c.gridy = 2;
    add(port, c);

    c.gridx = 0;
    c.gridy = 3;
    c.gridwidth = 2;
    add(connect, c);

    // c.gridy = 4;
    // add(connectDev, c);

    //  c.gridy = 5;
    //  add(connectSame, c);

    connect.addActionListener(this);
    connectDev.addActionListener(this);
    connectSame.addActionListener(this);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(final WindowEvent event) {
            dispose();
        }
    });

    final Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    this.setLocation(dim.width / 2 - this.getSize().width / 2, dim.height / 2 - this.getSize().height / 2);

}

From source file:edu.kit.dama.ui.components.TextImage.java

/**
 * Get the bytes of the final image.//  w ww . j  a v a2 s . com
 *
 * @return The byte array containing the bytes of the resulting image.
 *
 * @throws IOException if creating the image fails.
 */
public byte[] getBytes() throws IOException {
    Image transparentImage = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(
            new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB).getSource(), new RGBImageFilter() {
                @Override
                public final int filterRGB(int x, int y, int rgb) {
                    return (rgb << 8) & 0xFF000000;
                }
            }));

    //create the actual image and overlay it by the transparent background
    BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = outputImage.createGraphics();
    g2d.drawImage(transparentImage, 0, 0, null);
    //draw the remaining stuff
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2d.setColor(color);
    g2d.fillRoundRect(0, 0, size, size, 20, 20);
    g2d.setColor(new Color(Math.round((float) color.getRed() * .9f), Math.round((float) color.getGreen() * .9f),
            Math.round((float) color.getBlue() * .9f)));
    g2d.drawRoundRect(0, 0, size - 1, size - 1, 20, 20);

    Font font = new Font("Dialog", Font.BOLD, size - 4);
    g2d.setFont(font);
    g2d.setColor(Color.WHITE);

    String s = text.toUpperCase().substring(0, 1);
    FontMetrics fm = g2d.getFontMetrics();
    float x = ((float) size - (float) fm.stringWidth(s)) / 2f;
    float y = ((float) fm.getAscent()
            + (float) ((float) size - ((float) fm.getAscent() + (float) fm.getDescent())) / 2f) - 1f;
    g2d.drawString(s, x, y);
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ImageIO.write(outputImage, "png", bout);
    g2d.dispose();
    return bout.toByteArray();
}

From source file:gui.MainGUI.java

/** Creates new form MainGUI */
public MainGUI() {
    RUNMODE = runMode.stopped;/*from   w w w .  j  a va2  s .co m*/
    initComponents();
    this.addWindowListener(windowListener);
    // center on screen
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (dim.width - getSize().width) / 2;
    int y = (dim.height - getSize().height) / 2;
    setLocation(x, y);

    robotTeamConfig = new RobotTeamConfig();
    simConfig = new SimulatorConfig();
    updateFromRobotTeamConfig();
    updateFromEnvConfig();
    simulation = new SimulationFramework(true, this, robotTeamConfig, simConfig, explorationImage);

    showConnex = true;

    initGraphFrame();

    //to start immediately
    simulation = new SimulationFramework(true, this, robotTeamConfig, simConfig, explorationImage);
    simulation.start();

}

From source file:com.github.benchdoos.weblocopener.weblocOpener.gui.EditDialog.java

private void initGui(String pathToEditingFile) {
    setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/icon96.png")));

    this.path = pathToEditingFile;
    setContentPane(contentPane);//from  w  w  w. j ava2s  .c o  m

    getRootPane().setDefaultButton(buttonOK);

    buttonOK.addActionListener(e -> onOK());

    buttonCancel.addActionListener(e -> onCancel());

    // call onCancel() when cross is clicked
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowActivated(WindowEvent e) {
            if (textField.getText().isEmpty()) {
                fillTextFieldWithClipboard();
            }
            super.windowActivated(e);
        }

        @Override
        public void windowClosing(WindowEvent e) {
            onCancel();
        }
    });

    // call onCancel() on ESCAPE
    contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    createWeblocFileTextPane.setBackground(new Color(232, 232, 232));

    initTextField(pathToEditingFile);

    pack();

    /*setMinimumSize(getSize());
    setPreferredSize(getSize());*/

    setSize(DEFAULT_APPLICATION_WIDTH, 200);
    setResizable(false); //TODO fix setMaximumSize

    setLocation(FrameUtils.getFrameOnCenterLocationPoint(this));
}

From source file:FrameDemo2.java

public FrameDemo2() {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    maxX = screenSize.width - 50;
    maxY = screenSize.height - 50;
}

From source file:com.navient.portalupdater.Settings.java

public Settings() {
    //user_prop_file = "/tmp/user.properties";
    user_prop_file = portal_location + "/files/user.properties";

    try {/*  w ww.  ja v a 2  s.co  m*/
        String host = java.net.InetAddress.getLocalHost().getHostName();
        if (host.contains(".")) {
            hostname = host.substring(0, host.indexOf("."));
        } else {
            hostname = host;
        }
    } catch (java.net.UnknownHostException ex) {
        Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
    }

    userprop = new Properties();
    InputStream input = null;
    try {
        // Load the user properties file
        input = new FileInputStream(user_prop_file);
        userprop.load(input);

        username = userprop.getProperty("username");
        if ("t".equals(username.substring(username.length() - 1))) {
            id = username.substring(0, 6);
        } else {
            id = username;
        }

        ad_password = getADPass();
        tldap_password = getTLDAPPass();
        opsware_server = userprop.getProperty("opsware_server");

    } catch (IOException e) {
        MessageDialogs dialogs = new MessageDialogsImpl();
        dialogs.showError("Can't load user.properties file.\n\nNo such file or directory.");
        System.out.println("Error: " + e.getMessage());
        System.exit(1);
    } finally {
        try {
            input.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    InputStream in;
    try {
        in = ClassLoader.getSystemResourceAsStream("updating.gif");
        updating_splash = Toolkit.getDefaultToolkit().createImage(IOUtils.toByteArray(in));
        in = ClassLoader.getSystemResourceAsStream("downloading.gif");
        downloading_splash = Toolkit.getDefaultToolkit().createImage(IOUtils.toByteArray(in));
    } catch (IOException ex) {
        Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:at.gv.egiz.bku.local.stal.LocalIdentityLinkSTALFactory.java

@Override
public STAL createSTAL() {
    final LocalBKUWorker stal;
    //http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html
    // use undecorated JFrame instead of JWindow,
    // which creates an invisible owning frame and therefore cannot getFocusInWindow()
    JFrame dialog = new JFrame("Brgerkarte");
    log.debug("AlwaysOnTop supported: {}.", dialog.isAlwaysOnTopSupported());
    // [#439] make mocca dialog alwaysOnTop
    dialog.setAlwaysOnTop(true);//from   w ww  .j  a  va2  s.c o m
    dialog.setIconImages(BKUIcons.icons);
    //       dialog.setUndecorated(true);
    //       dialog.getRootPane().setWindowDecorationStyle(JRootPane.NONE);

    if (locale != null) {
        dialog.setLocale(locale);
    }
    LocalHelpListener helpListener = null;
    if (helpURL != null) {
        helpListener = new LocalHelpListener(helpURL, locale);
    } else {
        log.warn("No HELP URL configured, help system disabled.");
    }
    IdentityLinkGUIFacade gui = new IdentityLinkGUI(dialog.getContentPane(), dialog.getLocale(), null,
            new ResourceFontLoader(), helpListener);
    BKUGUIFacade proxy = (BKUGUIFacade) GUIProxy.newInstance(gui, dialog,
            new Class[] { IdentityLinkGUIFacade.class });
    stal = new LocalBKUWorker(proxy, dialog);
    dialog.setPreferredSize(PREFERRED_SIZE);
    dialog.pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = dialog.getSize();
    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }
    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }
    dialog.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    return stal;
}

From source file:adapters.HistogramChartAdapter.java

/**
 * Modified method//from   w w  w.  j av a2  s.co  m
 *
 * Displays chart on the screen using Swing.
 *    This method creates an application containing a chart panel displaying
 *    the chart. The created frame is positioned on-screen, and displayed before
 *    it is returned. The <TT>width</TT> and the <TT>height</TT>
 *    of the chart are measured in pixels.
 *
 * @param width frame width in pixels.
 *
 *    @param height frame height in pixels.
 *
 *    @return frame containing the chart.
 *
 */
public JFrame view(int width, int height) {
    JFrame myFrame;
    if (chart.getTitle() != null)
        myFrame = new JFrame("Histogram Chart: " + chart.getTitle().getText());
    else
        myFrame = new JFrame("Histogram Chart");
    TextTitle tt = chart.getTitle();
    tt.setFont(new FontUIResource("DensityChartSmallFont", Font.ITALIC, 12));
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(width, height));
    myFrame.setContentPane(chartPanel);
    myFrame.pack();
    myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    return myFrame;
}

From source file:MonitorSaurausRex.MainMenu.java

public void close() {

    WindowEvent winClosingEvent = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
    Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
}

From source file:AWTUtilities.java

/**
 * Returns a list of available font names. Under JDK1.1 it uses
 * <code>Toolkit.getFontList()</code> while under JDK1.2 (via reflection),
 * <code>GraphicsEnvironment.getAvailableFontFamilyNames()</code>
 *///  w ww  .j a va  2 s  .c  o  m

public static String[] getAvailableFontNames() {
    if (PlatformUtils.isJavaBetterThan("1.2")) {
        try {
            // The equivalent of "return GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();"
            Class geClass = Class.forName("java.awt.GraphicsEnvironment");
            Method getLocalGraphicsEnvironmentMethod = geClass.getMethod("getLocalGraphicsEnvironment",
                    new Class[0]);
            Object localGE = getLocalGraphicsEnvironmentMethod.invoke(null, new Object[0]);
            Method getAvailableFontFamilyNamesMethod = geClass.getMethod("getAvailableFontFamilyNames",
                    new Class[0]);
            String[] fontNames = (String[]) getAvailableFontFamilyNamesMethod.invoke(localGE, new Object[0]);
            return fontNames;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return null;
    } else
        return Toolkit.getDefaultToolkit().getFontList();
}