Example usage for java.awt Toolkit getScreenSize

List of usage examples for java.awt Toolkit getScreenSize

Introduction

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

Prototype

public abstract Dimension getScreenSize() throws HeadlessException;

Source Link

Document

Gets the size of the screen.

Usage

From source file:javazoom.jlgui.player.amp.Player.java

/**
 * Constructor./*from  ww  w  .  ja v  a 2 s.  c o  m*/
 */
public Player(String Skin, Frame top) {
    super(top);
    topFrame = top;

    // Config feature.
    config = Config.getInstance();
    config.load(initConfig);
    OrigineX = config.getXLocation();
    OrigineY = config.getYLocation();

    // Get screen size
    try {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension dimension = toolkit.getScreenSize();
        screenWidth = dimension.width;
        screenHeight = dimension.height;
    } catch (Exception e) {
    }

    // Minimize/Maximize/Icon features.
    topFrame.addWindowListener(this);
    topFrame.setLocation(OrigineX, OrigineY);
    topFrame.setSize(0, 0);
    // Polis : Comment out to fix a bug under XWindow
    //topFrame.setResizable(false);
    ClassLoader cl = this.getClass().getClassLoader();
    URL iconURL = cl.getResource("javazoom/jlgui/player/amp/jlguiicon.gif");
    if (iconURL != null) {
        ImageIcon jlguiIcon = new ImageIcon(iconURL);
        topFrame.setIconImage(jlguiIcon.getImage());
    }
    topFrame.show();

    // DnD feature.
    DropTarget dt = new DropTarget(this, DnDConstants.ACTION_COPY, this, true);

    // Playlist feature.
    boolean playlistfound = false;
    if ((initSong != null) && (!initSong.equals("")))
        playlistfound = loadPlaylist(initSong);
    else
        playlistfound = loadPlaylist(config.getPlaylistFilename());

    // Load skin specified in args
    if (Skin != null) {
        thePath = Skin;
        log.info("Load default skin from " + thePath);
        loadSkin(thePath);
        config.setDefaultSkin(thePath);
    }
    // Load skin specified in jlgui.ini
    else if ((config.getDefaultSkin() != null) && (!config.getDefaultSkin().trim().equals(""))) {
        log.info("Load default skin from " + config.getDefaultSkin());
        loadSkin(config.getDefaultSkin());
    }
    // Default included skin
    else {
        //ClassLoader cl = this.getClass().getClassLoader();
        InputStream sis = cl.getResourceAsStream("javazoom/jlgui/player/amp/metrix.wsz");
        log.info("Load default skin for JAR");
        loadSkin(sis);
    }

    // Go to playlist begining if needed.
    if ((playlist != null) && (playlistfound == true)) {
        if (playlist.getPlaylistSize() > 0)
            acNext.fireEvent();
    }

    // Display the whole
    hide();
    show();
    repaint();
}

From source file:javazoom.jlgui.player.amp.PlayerApplet.java

/**
 * Init player applet.//w  w w . ja  v  a2s .  co  m
 */
public void initPlayer(String Skin) {
    // Config feature.
    config = Config.getInstance();
    config.load(initConfig);
    OrigineX = config.getXLocation();
    OrigineY = config.getYLocation();

    // Get screen size
    try {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension dimension = toolkit.getScreenSize();
        screenWidth = dimension.width;
        screenHeight = dimension.height;
    } catch (Exception e) {
    }

    // Minimize/Maximize/Icon features.
    //topFrame.addWindowListener(this);
    topFrame.setLocation(OrigineX, OrigineY);
    topFrame.setSize(0, 0);
    // Polis : Comment out to fix a bug under XWindow
    //topFrame.setResizable(false);
    ClassLoader cl = this.getClass().getClassLoader();
    URL iconURL = cl.getResource("javazoom/jlgui/player/amp/jlguiicon.gif");
    if (iconURL != null) {
        ImageIcon jlguiIcon = new ImageIcon(iconURL);
        //topFrame.setIconImage(jlguiIcon.getImage());
    }
    topFrame.show();

    // DnD feature.
    DropTarget dt = new DropTarget(this, DnDConstants.ACTION_COPY, this, true);

    // Playlist feature.
    boolean playlistfound = false;
    if ((initSong != null) && (!initSong.equals("")))
        playlistfound = loadPlaylist(initSong);
    else
        playlistfound = loadPlaylist(config.getPlaylistFilename());

    // Load skin specified in args
    if (Skin != null) {
        thePath = Skin;
        log.info("Load default skin from " + thePath);
        loadSkin(thePath);
        config.setDefaultSkin(thePath);
    }
    // Load skin specified in jlgui.ini
    else if ((config.getDefaultSkin() != null) && (!config.getDefaultSkin().trim().equals(""))) {
        log.info("Load default skin from " + config.getDefaultSkin());
        loadSkin(config.getDefaultSkin());
    }
    // Default included skin
    else {
        //ClassLoader cl = this.getClass().getClassLoader();
        InputStream sis = cl.getResourceAsStream("javazoom/jlgui/player/amp/metrix.wsz");
        log.info("Load default skin for JAR");
        loadSkin(sis);
    }

    // Go to playlist begining if needed.
    if ((playlist != null) && (playlistfound == true)) {
        if (playlist.getPlaylistSize() > 0)
            acNext.fireEvent();
    }

    // Display the whole
    hide();
    show();
    repaint();
}

From source file:ffx.ui.MainPanel.java

/**
 * Load preferences from the user node//www  .j  av a  2 s  .co m
 */
public void loadPrefs() {
    String c = MainPanel.class.getName();
    JFrame frame1 = (JFrame) SwingUtilities.getRoot(this);
    Toolkit toolkit = getToolkit();
    Dimension screenSize = toolkit.getScreenSize();
    int x = preferences.getInt(c + ".x", screenSize.width / 8);
    int y = preferences.getInt(c + ".y", screenSize.height / 8);
    int width = preferences.getInt(c + ".width", screenSize.width * 3 / 4);
    int height = preferences.getInt(c + ".height", screenSize.height * 3 / 4);
    if (width > screenSize.width * 0.4 && width < screenSize.width * 0.8 && height > screenSize.height * 0.4
            && height < screenSize.height * 0.8) {
        frame1.setSize(width, height);
    } else {
        frame1.setSize(screenSize.width * 4 / 5, screenSize.height * 4 / 5);
    }
    if (x > 0 && x < screenSize.width / 2 && y > 0 && y < screenSize.height / 2) {
        frame1.setLocation(x, y);
    } else {
        frame1.setLocation(screenSize.width / 8, screenSize.height / 8);
    }
    splitPaneDivider = preferences.getInt(c + ".divider", 200);
    if (splitPaneDivider < frame1.getWidth() * (1.0f / 4.0f)) {
        splitPaneDivider = (int) (frame1.getWidth() * (1.0f / 4.0f));
    }
    splitPane.setDividerLocation(splitPaneDivider);
    if (!preferences.getBoolean(c + ".system", true)) {
        mainMenu.setSystemShowing(false);
        splitPane.setDividerLocation(0);
    } else {
        mainMenu.setSystemShowing(true);
    }
    if (!preferences.getBoolean(c + ".menu", true)) {
        remove(mainMenu.getToolBar());
        mainMenu.setMenuShowing(false);
        validate();
    } else {
        mainMenu.setMenuShowing(true);
    }
    try {
        port = preferences.getInt(c + ".port", 2000);
        ip = preferences.get(c + ".ip", InetAddress.getLocalHost().getHostAddress());
        if (ip != null) {
            address = InetAddress.getByName(ip);
            socketAddress = new InetSocketAddress(address, port);
        } else {
            socketAddress = new InetSocketAddress(port);
        }
    } catch (Exception e) {
        logger.log(Level.WARNING, e.toString());
    }
    if (graphicsCanvas != null) {
        graphicsCanvas.loadPrefs();
    }
}

From source file:jeplus.JEPlusFrameMain.java

/** 
 * Creates new form EPlusFrame /*  w w  w  . j  ava2  s.co  m*/
 */
public JEPlusFrameMain() {

    initComponents();

    this.setTitle(getVersionInfo());

    // tabTexts.setTabComponentAt(0, new ButtonTabComponent (tabTexts));
    jplParameterTree = new JPanel_ParameterTree(Project);
    jplTree.add(this.jplParameterTree, BorderLayout.CENTER);
    initProjectSection();
    initBatchOptions();

    EPlusExecAgents.add(new EPlusAgentLocal(Project.getExecSettings()));
    TrnsysExecAgents.add(new TrnsysAgentLocal(Project.getExecSettings()));
    InselExecAgents.add(new InselAgentLocal(Project.getExecSettings()));
    String[] options = { ExecAgents.get(0).getAgentID() };
    this.cboExecutionType.setModel(new DefaultComboBoxModel(options));
    this.cboExecutionTypeActionPerformed(null);

    this.cboSampleOpt.setModel(new DefaultComboBoxModel(EPlusBatch.SampleType.values()));

    OutputPanel = new EPlusTextPanelOld("Output", EPlusTextPanel.VIEWER_MODE);
    // Start a new thread for output panel
    new Thread(OutputPanel).start();
    OutputPanel.appendContent("Welcome to jEPlus!\n");
    TpnEditors.add(OutputPanel);
    TpnEditors.setSelectedComponent(OutputPanel);

    jplProgConfPanel = new JPanelProgConfiguration(null, JEPlusConfig.getDefaultInstance());
    jplIDFConvPanel = new JPanel_IDFVersionUpdater(this, JEPlusConfig.getDefaultInstance(), this.getProject());
    jplPythonPanel = new JPanelRunPython(this, JEPlusConfig.getDefaultInstance(),
            getProject() == null ? "./" : getProject().resolveWorkDir());
    jplReadVarsPanel = new JPanel_RunReadVars(this);
    //        TpnUtilities.add("Configure Programs", jplProgConfPanel);
    TpnUtilities.add("Run Python", jplPythonPanel);
    TpnUtilities.add("IDF Converter", jplIDFConvPanel);
    TpnUtilities.add("Run ReadVars", jplReadVarsPanel);

    // put the frame in the centre of screen
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screenSize = tk.getScreenSize();
    int frameWidth = 1000;
    int frameHeight = 740;
    int screenHeight = screenSize.height;
    int screenWidth = screenSize.width;
    setSize(frameWidth, frameHeight);
    setLocation((screenWidth - frameWidth) / 2, (screenHeight - frameHeight) / 2);
}

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

/**
     * Creates new form FAdmin/* w ww  .  j  a va2  s.c o  m*/
     */
    public FAdmin() {
        addWindowListener(new WindowListener() {

            @Override
            public void windowOpened(WindowEvent e) {
            }

            @Override
            public void windowClosing(WindowEvent e) {
                timer.stop();
            }

            @Override
            public void windowClosed(WindowEvent e) {
            }

            @Override
            public void windowIconified(WindowEvent e) {
            }

            @Override
            public void windowDeiconified(WindowEvent e) {
            }

            @Override
            public void windowActivated(WindowEvent e) {
                Uses.closeSplash();
            }

            @Override
            public void windowDeactivated(WindowEvent e) {
            }
        });
        initComponents();

        setTitle(getTitle() + " " + Uses.getLocaleMessage("project.name" + FAbout.getCMRC_SUFF()));

        try {
            setIconImage(
                    ImageIO.read(FAdmin.class.getResource("/ru/apertum/qsystem/client/forms/resources/admin.png")));
        } catch (IOException ex) {
            System.err.println(ex);
        }

        // 
        final Toolkit kit = Toolkit.getDefaultToolkit();
        setLocation((Math.round(kit.getScreenSize().width - getWidth()) / 2),
                (Math.round(kit.getScreenSize().height - getHeight()) / 2));
        // ? ?
        final JFrame fr = this;
        tray = QTray.getInstance(fr, "/ru/apertum/qsystem/client/forms/resources/admin.png",
                getLocaleMessage("tray.caption"));
        tray.addItem(getLocaleMessage("tray.caption"), (ActionEvent e) -> {
            setVisible(true);
            setState(JFrame.NORMAL);
        });
        tray.addItem("-", (ActionEvent e) -> {
        });
        tray.addItem(getLocaleMessage("tray.exit"), (ActionEvent e) -> {
            dispose();
            System.exit(0);
        });

        int ii = 1;
        final ButtonGroup bg = new ButtonGroup();
        final String currLng = Locales.getInstance().getLangCurrName();
        for (String lng : Locales.getInstance().getAvailableLocales()) {
            final JRadioButtonMenuItem item = new JRadioButtonMenuItem(
                    org.jdesktop.application.Application.getInstance(ru.apertum.qsystem.QSystem.class).getContext()
                            .getActionMap(FAdmin.class, fr).get("setCurrentLang"));
            bg.add(item);
            item.setSelected(lng.equals(currLng));
            item.setText(lng); // NOI18N
            item.setName("QRadioButtonMenuItem" + (ii++)); // NOI18N
            menuLangs.add(item);
        }

        //  ??    ??.
        listUsers.addListSelectionListener((ListSelectionEvent e) -> {
            userListChange();
        });
        //  ??    ??.
        listResponse.addListSelectionListener((ListSelectionEvent e) -> {
            responseListChange();
        });
        listSchedule.addListSelectionListener((ListSelectionEvent e) -> {
            scheduleListChange();
        });
        listCalendar.addListSelectionListener(new ListSelectionListener() {

            private int oldSelectedValue = 0;
            private int tmp = 0;

            public int getOldSelectedValue() {
                return oldSelectedValue;
            }

            public void setOldSelectedValue(int oldSelectedValue) {
                this.oldSelectedValue = tmp;
                this.tmp = oldSelectedValue;
            }

            private boolean canceled = false;

            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (canceled) {
                    canceled = false;
                } else {
                    if (tableCalendar.getModel() instanceof CalendarTableModel) {
                        final CalendarTableModel model = (CalendarTableModel) tableCalendar.getModel();
                        if (!model.isSaved()) {
                            final int res = JOptionPane.showConfirmDialog(null,
                                    getLocaleMessage("calendar.change.title"),
                                    getLocaleMessage("calendar.change.caption"), JOptionPane.YES_NO_CANCEL_OPTION,
                                    JOptionPane.QUESTION_MESSAGE);
                            switch (res) {
                            case 0: // ?  ??
                                model.save();
                                calendarListChange();
                                setOldSelectedValue(listCalendar.getSelectedIndex());
                                break;
                            case 1: // ??  ??

                                calendarListChange();
                                setOldSelectedValue(listCalendar.getSelectedIndex());

                                break;
                            case 2: //  ??  ???   
                                canceled = true;
                                listCalendar.setSelectedIndex(getOldSelectedValue());
                                break;
                            }
                        } else {
                            calendarListChange();
                            setOldSelectedValue(listCalendar.getSelectedIndex());
                        }
                    } else {
                        calendarListChange();
                        setOldSelectedValue(listCalendar.getSelectedIndex());
                    }
                }
            }
        });
        //  ??  ?  ??.
        treeServices.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        treeInfo.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        /*
         treeServices.setCellRenderer(new DefaultTreeCellRenderer() {
            
         @Override
         public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
         super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
         setText(((Element) value).attributeValue(Uses.TAG_NAME));
         return this;
         }
         });*/
        treeServices.addTreeSelectionListener((TreeSelectionEvent e) -> {
            serviceListChange();
        });
        treeInfo.addTreeSelectionListener((TreeSelectionEvent e) -> {
            infoListChange();
        });

        textFieldStartTime.setInputVerifier(DateVerifier);
        textFieldFinishTime.setInputVerifier(DateVerifier);

        // ?
        loadSettings();
        //   ? ?.
        startTimer();
        //  
        loadConfig();

        spinnerPropServerPort.getModel().addChangeListener(new ChangeNet());
        spinnerPropClientPort.getModel().addChangeListener(new ChangeNet());
        spinnerWebServerPort.getModel().addChangeListener(new ChangeNet());

        spinnerServerPort.getModel().addChangeListener(new ChangeSettings());
        spinnerClientPort.getModel().addChangeListener(new ChangeSettings());
        spinnerUserRS.getModel().addChangeListener(new ChangeUser());

        //?   .
        final Helper helper = Helper.getHelp("ru/apertum/qsystem/client/help/admin.hs");
        helper.setHelpListener(menuItemHelp);
        helper.enableHelpKey(jPanel1, "introduction");
        helper.enableHelpKey(jPanel3, "monitoring");
        helper.enableHelpKey(jPanel4, "configuring");
        helper.enableHelpKey(jPanel8, "net");

        helper.enableHelpKey(jPanel17, "schedulers");
        helper.enableHelpKey(jPanel19, "calendars");
        helper.enableHelpKey(jPanel2, "infoSystem");
        helper.enableHelpKey(jPanel13, "responses");
        helper.enableHelpKey(jPanel18, "results");

        treeServices.setTransferHandler(new TransferHandler() {

            @Override
            public boolean canImport(TransferHandler.TransferSupport info) {
                final JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();
                if (dl.getChildIndex() == -1) {
                    return false;
                }
                // Get the string that is being dropped.
                final Transferable t = info.getTransferable();
                final QService data;
                try {
                    data = (QService) t.getTransferData(DataFlavor.stringFlavor);
                    return (data.getParent().getId()
                            .equals(((QService) dl.getPath().getLastPathComponent()).getId()));
                } catch (UnsupportedFlavorException | IOException e) {
                    return false;
                }
            }

            @Override
            public boolean importData(TransferHandler.TransferSupport info) {
                if (!info.isDrop()) {
                    return false;
                }
                final QService data;
                try {
                    data = (QService) info.getTransferable().getTransferData(DataFlavor.stringFlavor);
                } catch (UnsupportedFlavorException | IOException e) {
                    System.err.println(e);
                    return false;
                }
                final JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();
                final TreePath tp = dl.getPath();
                final QService parent = (QService) tp.getLastPathComponent();
                ((QServiceTree) treeServices.getModel()).moveNode(data, parent, dl.getChildIndex());
                return true;
            }

            @Override
            public int getSourceActions(JComponent c) {
                return MOVE;
            }

            @Override
            protected Transferable createTransferable(JComponent c) {
                return (QService) ((JTree) c).getLastSelectedPathComponent();
            }
        });
        treeServices.setDropMode(DropMode.INSERT);

        //   ?
        final AnnotationSessionFactoryBean as = (AnnotationSessionFactoryBean) Spring.getInstance().getFactory()
                .getBean("conf");
        if (as.getServers().size() > 1) {
            final JMenu menu = new JMenu(getLocaleMessage("admin.servers"));
            as.getServers().stream().map((ser) -> {
                final JMenuItem mi1 = new JMenuItem(as);
                mi1.setText(ser.isCurrent() ? "<html><u><i>" + ser.getName() + "</i></u>" : ser.getName());
                return mi1;
            }).forEach((mi1) -> {
                menu.add(mi1);
            });
            jMenuBar1.add(menu, 4);
            jMenuBar1.add(new JLabel(
                    "<html><span style='font-size:13.0pt;color:red'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  ["
                            + as.getName() + "]"));
        }
        comboBoxVoices.setVisible(false);
    }