Example usage for javax.swing JLabel setFont

List of usage examples for javax.swing JLabel setFont

Introduction

In this page you can find the example usage for javax.swing JLabel setFont.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The font for the component.")
public void setFont(Font font) 

Source Link

Document

Sets the font for this component.

Usage

From source file:Proiect.uploadFTP.java

public void actionFTP() {
    adressf.addCaretListener(new CaretListener() {
        public void caretUpdate(CaretEvent e) {
            InetAddress thisIp;//from w w  w  . jav  a  2s  . co  m
            try {
                thisIp = InetAddress.getLocalHost();
                titleFTP.setText("Connection: " + thisIp.getHostAddress() + " -> " + adressf.getText());
            } catch (UnknownHostException e1) {
                e1.printStackTrace();
            }
        }
    });

    exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            saveState();
            uploadFTP.dispose();
            tree.dispose();
        }
    });

    connect.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            FTPClient client = new FTPClient();
            FileInputStream fis = null;
            String pass = String.valueOf(passf.getPassword());
            try {
                if (filename == null) {
                    status.setText("File does not exist!");
                } else {
                    // Server address
                    client.connect(adressf.getText());
                    // Login credentials
                    client.login(userf.getText(), pass);
                    if (client.isConnected()) {
                        status.setText("Succesfull transfer!");
                        // File type
                        client.setFileType(FTP.BINARY_FILE_TYPE);
                        // File location
                        File file = new File(filepath);
                        fis = new FileInputStream(file);
                        // Change the folder on the server
                        client.changeWorkingDirectory(folderf.getText());
                        // Save the file on the server
                        client.storeFile(filename, fis);
                    } else {
                        status.setText("Transfer failed!");
                    }
                }
                client.logout();
            } catch (IOException e1) {
                Encrypter.printException(e1);
            } finally {
                try {
                    if (fis != null) {
                        fis.close();
                    }
                    client.disconnect();
                } catch (IOException e1) {
                    Encrypter.printException(e1);
                }
            }
        }
    });

    browsef.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int retval = chooserf.showOpenDialog(chooserf);
            if (retval == JFileChooser.APPROVE_OPTION) {
                status.setText("");
                filename = chooserf.getSelectedFile().getName().toString();
                filepath = chooserf.getSelectedFile().getPath();
                filenf.setText(chooserf.getSelectedFile().getName().toString());
            }
        }
    });

    adv.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

            tree.setSize(220, uploadFTP.getHeight());
            tree.setLocation(uploadFTP.getX() + 405, uploadFTP.getY());
            tree.setResizable(false);
            tree.setIconImage(Toolkit.getDefaultToolkit()
                    .getImage(getClass().getClassLoader().getResource("assets/ico.png")));
            tree.setUndecorated(true);
            tree.getRootPane().setBorder(BorderFactory.createLineBorder(Encrypter.color_black, 2));
            tree.setVisible(true);
            tree.setLayout(new BorderLayout());

            JLabel labeltree = new JLabel("Server documents");
            labeltree.setOpaque(true);
            labeltree.setBackground(Encrypter.color_light);
            labeltree.setBorder(BorderFactory.createMatteBorder(8, 10, 10, 0, Encrypter.color_light));
            labeltree.setForeground(Encrypter.color_blue);
            labeltree.setFont(Encrypter.font16);

            JButton refresh = new JButton("");
            ImageIcon refresh_icon = getImageIcon("assets/icons/refresh.png");
            refresh.setIcon(refresh_icon);
            refresh.setBackground(Encrypter.color_light);
            refresh.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
            refresh.setForeground(Encrypter.color_black);
            refresh.setFont(Encrypter.font16);
            refresh.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

            final FTPClient client = new FTPClient();
            DefaultMutableTreeNode top = new DefaultMutableTreeNode(adressf.getText());
            DefaultMutableTreeNode files = null;
            DefaultMutableTreeNode leaf = null;

            final JTree tree_view = new JTree(top);
            tree_view.setForeground(Encrypter.color_black);
            tree_view.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
            tree_view.putClientProperty("JTree.lineStyle", "None");
            tree_view.setBackground(Encrypter.color_light);
            JScrollPane scrolltree = new JScrollPane(tree_view);
            scrolltree.setBackground(Encrypter.color_light);
            scrolltree.getVerticalScrollBar().setPreferredSize(new Dimension(0, 0));

            UIManager.put("Tree.textBackground", Encrypter.color_light);
            UIManager.put("Tree.selectionBackground", Encrypter.color_blue);
            UIManager.put("Tree.selectionBorderColor", Encrypter.color_blue);

            tree_view.updateUI();

            final String pass = String.valueOf(passf.getPassword());
            try {
                client.connect(adressf.getText());
                client.login(userf.getText(), pass);
                client.enterLocalPassiveMode();
                if (client.isConnected()) {
                    try {
                        FTPFile[] ftpFiles = client.listFiles();
                        for (FTPFile ftpFile : ftpFiles) {
                            files = new DefaultMutableTreeNode(ftpFile.getName());
                            top.add(files);
                            if (ftpFile.getType() == FTPFile.DIRECTORY_TYPE) {
                                FTPFile[] ftpFiles1 = client.listFiles(ftpFile.getName());
                                for (FTPFile ftpFile1 : ftpFiles1) {
                                    leaf = new DefaultMutableTreeNode(ftpFile1.getName());
                                    files.add(leaf);
                                }
                            }
                        }
                    } catch (IOException e1) {
                        Encrypter.printException(e1);
                    }
                    client.disconnect();
                } else {
                    status.setText("Failed connection!");
                }
            } catch (IOException e1) {
                Encrypter.printException(e1);
            } finally {
                try {
                    client.disconnect();
                } catch (IOException e1) {
                    Encrypter.printException(e1);
                }
            }

            tree.add(labeltree, BorderLayout.NORTH);
            tree.add(scrolltree, BorderLayout.CENTER);
            tree.add(refresh, BorderLayout.SOUTH);

            uploadFTP.addComponentListener(new ComponentListener() {

                public void componentMoved(ComponentEvent e) {
                    tree.setLocation(uploadFTP.getX() + 405, uploadFTP.getY());
                }

                public void componentShown(ComponentEvent e) {
                }

                public void componentResized(ComponentEvent e) {
                }

                public void componentHidden(ComponentEvent e) {
                }
            });

            uploadFTP.addWindowListener(new WindowListener() {
                public void windowActivated(WindowEvent e) {
                    tree.toFront();
                }

                public void windowOpened(WindowEvent e) {
                }

                public void windowIconified(WindowEvent e) {
                }

                public void windowDeiconified(WindowEvent e) {
                }

                public void windowDeactivated(WindowEvent e) {
                }

                public void windowClosing(WindowEvent e) {
                }

                public void windowClosed(WindowEvent e) {
                }
            });

            refresh.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    tree.dispose();
                    tree.setVisible(true);
                }
            });
        }
    });

}

From source file:projectresurrection.Music.java

public void subMenu(int menu) {
    JPanel panel = (JPanel) ((JViewport) ((JScrollPane) pnlSub.getComponent(3)).getComponent(0))
            .getComponent(0);/*w ww. ja  va2s  .c om*/
    JLabel header = (JLabel) pnlSub.getComponent(1);
    JLabel label;
    panel.removeAll();
    int y = 10;
    switch (menu) {
    case 0:
        header.setText("Artists");
        panel.setPreferredSize(new Dimension(349, (55 + (artists.size() * 35))));
        label = new JLabel("All");
        label.setOpaque(true);
        label.setBackground(new Color(245, 245, 245));
        label.setFont(new Font("Tahoma", Font.PLAIN, 20));
        label.setBounds(10, y, 339, 35);
        label.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                subMenu(ALBUMS);
                panel.revalidate();
                panel.repaint();
            }
        });
        panel.add(label);
        y += 35;
        List artistList = new ArrayList(artists.keySet());
        Collections.sort(artistList);
        for (int i = 0; i < artistList.size(); i++) {
            String artist = artistList.get(i).toString();
            label = new JLabel(artist);
            label.setOpaque(true);
            if (i % 2 == 1) {
                label.setBackground(new Color(245, 245, 245));
            }
            label.setFont(new Font("Tahoma", Font.PLAIN, 20));
            label.setBounds(10, y, 339, 35);
            label.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent arg0) {
                    subMenu(ARTISTS, artist);
                    panel.revalidate();
                    panel.repaint();
                }
            });
            panel.add(label);
            y += 35;
        }
        break;
    case 1:
        header.setText("Albums");
        panel.setPreferredSize(new Dimension(349, (55 + (albums.size() * 35))));
        label = new JLabel("All");
        label.setOpaque(true);
        label.setBackground(new Color(245, 245, 245));
        label.setFont(new Font("Tahoma", Font.PLAIN, 20));
        label.setBounds(10, y, 339, 35);
        label.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                subMenu(SONGS);
                panel.revalidate();
                panel.repaint();
            }
        });
        panel.add(label);
        y += 35;
        List albumList = new ArrayList(albums.keySet());
        Collections.sort(albumList);
        for (int i = 0; i < albumList.size(); i++) {
            String album = albumList.get(i).toString();
            label = new JLabel(album);
            label.setOpaque(true);
            if (i % 2 == 1) {
                label.setBackground(new Color(245, 245, 245));
            }
            label.setFont(new Font("Tahoma", Font.PLAIN, 20));
            label.setBounds(10, y, 339, 35);
            label.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent arg0) {
                    subMenu(ALBUMS, album);
                    panel.revalidate();
                    panel.repaint();
                }
            });
            panel.add(label);
            y += 35;
        }
        break;
    case 2:
        header.setText("Songs");
        panel.setPreferredSize(new Dimension(349, (20 + (songs.size() * 35))));
        List songList = new ArrayList(songs.keySet());
        Collections.sort(songList);
        List fileList = new ArrayList();
        for (int i = 0; i < songList.size(); i++) {
            fileList.add(((List) songs.get(songList.get(i))).get(0));
        }
        for (int i = 0; i < songList.size(); i++) {
            int num = i;
            String song = songList.get(i).toString();
            label = new JLabel(song);
            label.setOpaque(true);
            if (i % 2 == 0) {
                label.setBackground(new Color(245, 245, 245));
            }
            label.setFont(new Font("Tahoma", Font.PLAIN, 20));
            label.setBounds(10, y, 339, 35);
            label.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent arg0) {
                    player.setPlaylist(fileList, num);
                    pnlSub.setVisible(false);
                    pnlPlayer.setVisible(true);
                    try {
                        Thread.sleep(200);
                    } catch (Exception e) {
                    }
                    if (player.isPlaying() == false) {
                        player.toggle();
                    }
                }
            });
            panel.add(label);
            y += 35;
        }
        break;
    }
    pnlMenu.setVisible(false);
    pnlSub.setVisible(true);
}

From source file:projectresurrection.Music.java

public void subMenu(int type, String menu) {
    JPanel panel = (JPanel) ((JViewport) ((JScrollPane) pnlSub.getComponent(3)).getComponent(0))
            .getComponent(0);/*from  w  w w . j  a  v  a 2s . co m*/
    JLabel header = (JLabel) pnlSub.getComponent(1);
    JLabel label;
    header.setText(menu);
    panel.removeAll();
    int y = 10;
    switch (type) {
    case 0:
        List albumList = new ArrayList(((Map) artists.get(menu)).keySet());
        Collections.sort(albumList);
        panel.setPreferredSize(new Dimension(349, (55 + (albumList.size() * 35))));
        label = new JLabel("All");
        label.setOpaque(true);
        label.setBackground(new Color(245, 245, 245));
        label.setFont(new Font("Tahoma", Font.PLAIN, 20));
        label.setBounds(10, y, 339, 35);
        label.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                subMenuAll(ARTISTS, menu);
                panel.revalidate();
                panel.repaint();
            }
        });
        panel.add(label);
        y += 35;
        for (int i = 0; i < albumList.size(); i++) {
            String album = albumList.get(i).toString();
            label = new JLabel(album);
            label.setOpaque(true);
            if (i % 2 == 1) {
                label.setBackground(new Color(245, 245, 245));
            }
            label.setFont(new Font("Tahoma", Font.PLAIN, 20));
            label.setBounds(10, y, 339, 35);
            label.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent arg0) {
                    subMenu(ALBUMS, album);
                    panel.revalidate();
                    panel.repaint();
                }
            });
            panel.add(label);
            y += 35;
        }
        break;
    case 1:
        List songList = new ArrayList();
        List albumSongs = new ArrayList(((Map) albums.get(menu)).keySet());
        Collections.sort(albumSongs);
        Map tracks = new HashMap();
        for (int i = 0; i < albumSongs.size(); i++) {
            String track = ((List) songs.get(albumSongs.get(i))).get(1).toString();
            if (tracks.containsKey(track)) {
                track = track + "(1)";
                int j = 2;
                while (tracks.containsKey(track)) {
                    track = track + "(" + j + ")";
                }
            }
            tracks.put(track, albumSongs.get(i));
        }
        List nums = new ArrayList(tracks.keySet());
        Collections.sort(nums);
        List hasTrack = new ArrayList();
        List noTrack = new ArrayList();
        for (int i = 0; i < nums.size(); i++) {
            if (nums.get(i).equals("-1")) {
                noTrack.add(tracks.get(nums.get(i)));
            } else {
                hasTrack.add(tracks.get(nums.get(i)));
            }
        }
        Collections.sort(noTrack);
        for (int i = 0; i < hasTrack.size(); i++) {
            songList.add(hasTrack.get(i));
        }
        for (int i = 0; i < noTrack.size(); i++) {
            songList.add(noTrack.get(i));
        }
        panel.setPreferredSize(new Dimension(349, (20 + (albumSongs.size() * 35))));
        List fileList = new ArrayList();
        for (int i = 0; i < songList.size(); i++) {
            fileList.add(((List) songs.get(songList.get(i))).get(0));
        }
        for (int i = 0; i < songList.size(); i++) {
            int num = i;
            String song = songList.get(i).toString();
            label = new JLabel(song);
            label.setOpaque(true);
            if (i % 2 == 0) {
                label.setBackground(new Color(245, 245, 245));
            }
            label.setFont(new Font("Tahoma", Font.PLAIN, 20));
            label.setBounds(10, y, 339, 35);
            label.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent arg0) {
                    player.setPlaylist(fileList, num);
                    pnlSub.setVisible(false);
                    pnlPlayer.setVisible(true);
                    try {
                        Thread.sleep(200);
                    } catch (Exception e) {
                    }
                    if (player.isPlaying() == false) {
                        player.toggle();
                    }
                }
            });
            panel.add(label);
            y += 35;
        }
        break;
    }
    panel.revalidate();
    panel.repaint();
}

From source file:projectresurrection.Music.java

public void subMenuAll(int type, String menu) {
    JPanel panel = (JPanel) ((JViewport) ((JScrollPane) pnlSub.getComponent(3)).getComponent(0))
            .getComponent(0);//from w ww .j a va 2  s  . c  o m
    JLabel header = (JLabel) pnlSub.getComponent(1);
    header.setText(menu + " - All");
    panel.removeAll();
    int y = 10;
    switch (type) {
    case 0:
        List songList = new ArrayList();
        List albumList = new ArrayList(((Map) artists.get(menu)).keySet());
        Collections.sort(albumList);
        for (int i = 0; i < albumList.size(); i++) {
            List albumSongs = new ArrayList(((Map) albums.get(albumList.get(i))).keySet());
            Map tracks = new HashMap();
            for (int j = 0; j < albumSongs.size(); j++) {
                String track = ((List) songs.get(albumSongs.get(j))).get(1).toString();
                tracks.put(track, albumSongs.get(j));
            }
            List nums = new ArrayList(tracks.keySet());
            Collections.sort(nums);
            List hasTrack = new ArrayList();
            List noTrack = new ArrayList();
            for (int j = 0; j < nums.size(); j++) {
                if (nums.get(j).equals("-1")) {
                    noTrack.add(tracks.get(nums.get(j)));
                } else {
                    hasTrack.add(tracks.get(nums.get(j)));
                }
            }
            for (int j = 0; j < hasTrack.size(); j++) {
                songList.add(hasTrack.get(j));
            }
            for (int j = 0; j < noTrack.size(); j++) {
                songList.add(noTrack.get(j));
            }
        }
        panel.setPreferredSize(new Dimension(349, (20 + (songList.size() * 35))));
        List fileList = new ArrayList();
        for (int i = 0; i < songList.size(); i++) {
            fileList.add(((List) songs.get(songList.get(i))).get(0));
        }
        for (int i = 0; i < songList.size(); i++) {
            int num = i;
            String song = songList.get(i).toString();
            JLabel label = new JLabel(song);
            label.setOpaque(true);
            if (i % 2 == 0) {
                label.setBackground(new Color(245, 245, 245));
            }
            label.setFont(new Font("Tahoma", Font.PLAIN, 20));
            label.setBounds(10, y, 339, 35);
            label.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent arg0) {
                    player.setPlaylist(fileList, num);
                    pnlSub.setVisible(false);
                    pnlPlayer.setVisible(true);
                    try {
                        Thread.sleep(200);
                    } catch (Exception e) {
                    }
                    if (player.isPlaying() == false) {
                        player.toggle();
                    }
                }
            });
            panel.add(label);
            y += 35;
        }
        break;
    }
    panel.revalidate();
    panel.repaint();
}

From source file:qic.ui.ManualPanel.java

@SuppressWarnings("serial")
public ManualPanel(Main main) {
    super(new BorderLayout(5, 5));

    table.setDoubleBuffered(true);//from w  w  w  .j  av  a  2  s . c om

    JTextField searchTf = new JTextField(100);
    JButton runBtn = new JButton("Run");
    runBtn.setPreferredSize(new Dimension(200, 10));
    JLabel invalidTermsLblLbl = new JLabel();
    invalidTermsLblLbl.setFont(invalidTermsLblLbl.getFont().deriveFont(Font.BOLD));
    JLabel invalidTermsLbl = new JLabel();
    invalidTermsLbl.setForeground(Color.RED);
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.X_AXIS));
    JLabel searchLbl = new JLabel(" Search: ");
    searchLbl.setFont(searchLbl.getFont().deriveFont(Font.BOLD));
    northPanel.add(searchLbl);
    northPanel.add(searchTf);
    northPanel.add(invalidTermsLblLbl);
    northPanel.add(invalidTermsLbl);
    northPanel.add(runBtn);
    this.add(northPanel, BorderLayout.NORTH);

    List<String> searchList = Util.loadSearchList(MANUAL_TXT_FILENAME);
    searchList.stream().forEach(searchJListModel::addElement);
    searchJList.setModel(searchJListModel);

    searchJList.addListSelectionListener(e -> {
        if (e.getValueIsAdjusting()) {
            searchTf.setText(trimToEmpty(searchJList.getSelectedValue()));
        }
    });
    searchJList.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                int index = searchJList.locationToIndex(evt.getPoint());
                if (index != -1) {
                    String search = trimToEmpty(searchJListModel.getElementAt(index));
                    searchTf.setText(search);
                    runBtn.doClick();
                }
            }
        }
    });

    searchJList.getInputMap().put(KeyStroke.getKeyStroke("DELETE"), "doSomething");
    searchJList.getActionMap().put("doSomething", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int selectedIndex = searchJList.getSelectedIndex();
            if (selectedIndex != -1) {
                searchJListModel.remove(selectedIndex);
            }
        }
    });

    ActionListener runCommand = e -> {
        String tfText = searchTf.getText().trim();
        if (!tfText.isEmpty()) {
            Worker<Command> worker = new Worker<Command>(() -> {
                runBtn.setEnabled(false);
                Command result = null;
                try {
                    result = runQuery(main, tfText);
                } catch (Exception ex) {
                    runBtn.setEnabled(true);
                    SwingUtil.showError(ex);
                }
                return result;
            }, command -> {
                if (command != null) {
                    if (command.invalidSearchTerms.isEmpty()) {
                        addDataToTable(command);
                        saveSearchToList(tfText);
                        invalidTermsLbl.setText("");
                        invalidTermsLblLbl.setText("");
                        if (getBooleanProperty(MANUAL_AUTO_VERIFY, false)) {
                            long sleep = Config.getLongProperty(Config.MANUAL_AUTO_VERIFY_SLEEP, 5000);
                            table.runAutoVerify(sleep);
                        }
                    } else {
                        String invalidTermsStr = command.invalidSearchTerms.stream().collect(joining(", "));
                        invalidTermsLbl.setText(invalidTermsStr + " ");
                        invalidTermsLblLbl.setText(" Invalid: ");
                    }
                }
                runBtn.setEnabled(true);
            });
            worker.execute();
        }
    };

    searchTf.addActionListener(runCommand);
    runBtn.addActionListener(runCommand);

    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(table),
            new JScrollPane(searchJList));

    this.add(splitPane, BorderLayout.CENTER);
}

From source file:rita.ui.component.DialogSelectEnemies.java

/**
 * Initialize the contents of the frame.
 * /*  www.  j a va2s.c om*/
 * @throws NoEnemiesException
 */
private void initialize() throws NoEnemiesException {
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    this.getContentPane().setLayout(new BorderLayout(6, 6));
    this.setTitle(Language.get("selectEnemies"));
    randomMode = new JCheckBox(Language.get("robotsBattleMode.random"));
    randomMode.setSelected(true);
    randomMode.addActionListener(new SelectUnselectPositionAction());

    icon = new ImageIcon(DialogSelectEnemies.class.getResource("/images/icons/target.jpg"));

    JPanel panelRobots = new JPanel();
    panelRobots.setBorder(new EmptyBorder(0, 12, 12, 0));
    panelRobots.setLayout(new BorderLayout(0, 0));

    JPanel panelSelectAllNone = new JPanel();
    panelSelectAllNone.setBorder(new EmptyBorder(0, 12, 0, 12));
    panelRobots.add(panelSelectAllNone, BorderLayout.EAST);
    this.getContentPane().add(panelRobots, BorderLayout.CENTER);

    GridBagLayout gbl_panelSelectAllNone = new GridBagLayout();
    gbl_panelSelectAllNone.columnWidths = new int[] { 0, 0 };
    gbl_panelSelectAllNone.rowHeights = new int[] { 0, 0, 8 };
    gbl_panelSelectAllNone.columnWeights = new double[] { 0.0, Double.MIN_VALUE };
    gbl_panelSelectAllNone.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    panelSelectAllNone.setLayout(gbl_panelSelectAllNone);

    JButton btnSelectAll = new JButton(Language.get("selectAllEnemies"));
    GridBagConstraints gbc_btnSelectAll = new GridBagConstraints();
    gbc_btnSelectAll.fill = GridBagConstraints.HORIZONTAL;
    gbc_btnSelectAll.insets = new Insets(0, 0, 5, 0);
    gbc_btnSelectAll.gridx = 0;
    gbc_btnSelectAll.gridy = 0;
    panelSelectAllNone.add(btnSelectAll, gbc_btnSelectAll);

    JButton btnSelectNone = new JButton(Language.get("selectNoEnemies"));
    GridBagConstraints gbc_btnSelectNone = new GridBagConstraints();
    gbc_btnSelectNone.fill = GridBagConstraints.HORIZONTAL;
    gbc_btnSelectNone.gridx = 0;
    gbc_btnSelectNone.gridy = 1;
    panelSelectAllNone.add(btnSelectNone, gbc_btnSelectNone);

    /*
     * btnInitialPositionsConfig = new
     * JButton(Language.get("selectRobotsInitialPositions"));
     * GridBagConstraints gbc_btnInitialPositionsConfig = new
     * GridBagConstraints(); gbc_btnSelectNone.fill =
     * GridBagConstraints.HORIZONTAL; gbc_btnSelectNone.gridx = 0;
     * gbc_btnSelectNone.gridy = 1;
     * panelSelectAllNone.add(btnInitialPositionsConfig,
     * gbc_btnInitialPositionsConfig);
     * btnInitialPositionsConfig.addActionListener(new ActionListener() {
     * public void actionPerformed(ActionEvent evt) {
     * selectRobotsInitialPositions(); } });
     */

    JLabel label = new JLabel(String.format(Language.get("youtRobotAgainst"), HelperEditor.currentRobotName));
    label.setBorder(new EmptyBorder(12, 12, 0, 12));
    label.setIcon(new ImageIcon(DialogSelectEnemies.class.getResource("/images/icons/compite2.png")));
    label.setVerticalAlignment(SwingConstants.TOP);
    label.setFont(label.getFont().deriveFont(Font.BOLD, 14));

    panelSelectRobots = new JPanel();
    panelSelectRobots.setLayout(new GridLayout(0, 2));
    panelSelectRobots.setAutoscrolls(true);

    panelRobots.add(label, BorderLayout.NORTH);
    panelRobots.add(panelSelectRobots, BorderLayout.CENTER);

    // posicion de mi robot
    JPanel panelSetMyRobotPosition = new JPanel();
    // panelRobots.add(panelSetMyRobotPosition, BorderLayout.PAGE_END);
    panelSetMyRobotPosition.setLayout(new FlowLayout());
    JLabel ownPosition = new JLabel(Language.get("myRobotPosition") + " " + HelperEditor.currentRobotName);
    ownPosition.setFont(new Font("sansserif", Font.BOLD, 12));
    panelSetMyRobotPosition.add(ownPosition);
    // Posicion de mi robot
    buttonPos = new JButton(icon);
    buttonPos.addActionListener(new PosicionRobotAction(HelperEditor.currentRobotName)); // el nombre aqui es solo a
    // modo informativo
    buttonPos.setPreferredSize(new Dimension(30, 30));
    panelSetMyRobotPosition.add(buttonPos);
    positionComponents.add(buttonPos);

    // Matas
    JPanel panelSelectRoundsNumber = new JPanel();
    // panelRobots.add(panelSelectRoundsNumber, BorderLayout.SOUTH);
    panelSelectRoundsNumber.setLayout(new FlowLayout());
    panelSelectRoundsNumber.add(new JLabel(Language.get("selectRoundsNumber")));
    //      this.roundsNumberTextField = new JTextField(
    //            Integer.toString(Batalla.NUMBER_OF_ROUNDS), 5);
    this.roundsNumberSpinner = new JSpinner(new SpinnerNumberModel(Batalla.NUMBER_OF_ROUNDS,
            Batalla.MIN_NUMBER_OF_ROUNDS, Batalla.MAX_NUMBER_OF_ROUNDS, 1));

    panelSelectRoundsNumber.add(this.roundsNumberSpinner);

    JPanel panelSouth = new JPanel();
    panelSouth.setLayout(new GridLayout(4, 1));

    panelSouth.add(panelSetMyRobotPosition);
    //this.getContentPane().add(randomMode, BorderLayout.SOUTH);
    panelSouth.add(randomMode);
    panelSouth.add(new JSeparator());
    panelSouth.add(panelSelectRoundsNumber);
    panelRobots.add(panelSouth, BorderLayout.SOUTH);

    JPanel panelOkCancel = new JPanel();
    this.getContentPane().add(panelOkCancel, BorderLayout.SOUTH);
    panelOkCancel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 12));

    btnOK = new JButton(Language.get("selectStartBattle"));
    btnOK.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            startBattle(panelSelectRobots);
        }
    });
    // comienza deshabilitado hasta que se seleccione 1 enemigo
    // btnOK.setEnabled(false);
    panelOkCancel.add(btnOK);

    JButton btnCancel = new JButton(Language.get("cancel"));
    btnCancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            closeDialog();
        }
    });
    panelOkCancel.add(btnCancel);

    btnSelectAll.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            selectChecks(panelSelectRobots, true);
            // btnOK.setEnabled(true);
        }
    });

    btnSelectNone.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            selectChecks(panelSelectRobots, false);
            // btnOK.setEnabled(false);
        }
    });

    // TODO Agregar funcionalidad de elegir las posiciones iniciales de los
    // robots.
    // TODO Averiguar como pasar las posiciones para que se elijan de manera
    // random, probar (0,0,0)

    try {
        robotNameClicked = new RobotNameClickedEvent(btnOK);
        addRobotsToPanel(panelSelectRobots);

        this.setResizable(false);
        this.pack();
        PositionCalc.centerDialog(this);
        enablePositionOptions(false);
        this.setVisible(true);
    } catch (FileNotFoundException e) {
        throw new NoEnemiesException(e.getMessage());
    }

}

From source file:savant.ucscexplorer.UCSCExplorerPlugin.java

private void buildUI() {
    topLevelPanel.removeAll();/*from w ww .  j  av  a  2  s. c o  m*/
    topLevelPanel.setLayout(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.insets = new Insets(5, 5, 5, 5);

    try {
        UCSCDataSourcePlugin ucsc = getUCSCPlugin();
        ucsc.getConnection();
        JLabel cladeLabel = new JLabel("Clade:");
        gbc.anchor = GridBagConstraints.EAST;
        topLevelPanel.add(cladeLabel, gbc);

        cladeCombo = new JComboBox();
        cladeCombo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                UCSCDataSourcePlugin ucsc = getUCSCPlugin();
                String clade = (String) cladeCombo.getSelectedItem();
                genomeCombo.setModel(new DefaultComboBoxModel(ucsc.getCladeGenomes(clade)));
                genomeCombo.setSelectedItem(ucsc.getCurrentGenome(clade));
            }
        });

        gbc.anchor = GridBagConstraints.WEST;
        topLevelPanel.add(cladeCombo, gbc);

        JLabel genomeLabel = new JLabel("Genome:");
        gbc.anchor = GridBagConstraints.EAST;
        topLevelPanel.add(genomeLabel, gbc);

        genomeCombo = new JComboBox();
        genomeCombo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                buildProgressUI();
                new GroupsFetcher(getUCSCPlugin(), (GenomeDef) genomeCombo.getSelectedItem()) {
                    @Override
                    public void done(List<GroupDef> groups) {
                        if (groups != null) {
                            GridBagConstraints gbc = new GridBagConstraints();
                            gbc.gridwidth = GridBagConstraints.REMAINDER;
                            gbc.fill = GridBagConstraints.BOTH;
                            gbc.weightx = 1.0;
                            for (GroupDef g : groups) {
                                groupsPanel.add(new GroupPanel(g), gbc);
                            }

                            // Add a filler panel to force everything to the top.
                            gbc.weighty = 1.0;
                            groupsPanel.add(new JPanel(), gbc);
                            loadButton.setEnabled(true);
                            topLevelPanel.validate();
                        }
                    }

                    @Override
                    public void showProgress(double value) {
                        updateProgress(progressMessage, value);
                    }
                }.execute();
            }
        });
        gbc.anchor = GridBagConstraints.WEST;
        topLevelPanel.add(genomeCombo, gbc);

        loadButton = new JButton("Load Selected Tracks");
        loadButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    loadSelectedTracks();
                } catch (Throwable x) {
                    DialogUtils.displayException(getTitle(), "Unable to load selected tracks.", x);
                }
            }
        });
        gbc.anchor = GridBagConstraints.EAST;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        topLevelPanel.add(loadButton, gbc);

        groupsPanel = new GroupsPanel();
        groupsPanel.setLayout(new GridBagLayout());

        JScrollPane groupsScroller = new JScrollPane(groupsPanel,
                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        topLevelPanel.add(groupsScroller, gbc);

        buildProgressUI();

        GenomeUtils.addGenomeChangedListener(new Listener<GenomeChangedEvent>() {
            @Override
            public void handleEvent(GenomeChangedEvent event) {
                UCSCDataSourcePlugin ucsc = getUCSCPlugin();
                ucsc.selectGenomeDB(null);
                GenomeAdapter newGenome = event.getNewGenome();
                GenomeDef g = new GenomeDef(newGenome.getName(), null);
                String newClade = ucsc.findCladeForGenome(g);

                // newClade could be null if the user has opened a genome which has no UCSC equivalent.
                if (newClade != null) {
                    cladeCombo.setSelectedItem(newClade);
                }
            }
        });

        ucsc.selectGenomeDB(null);
        new CladesFetcher(getUCSCPlugin()) {
            @Override
            public void done(String selectedClade) {
                cladeCombo.setModel(new DefaultComboBoxModel(UCSCDataSourcePlugin.STANDARD_CLADES));
                if (selectedClade != null) {
                    cladeCombo.setSelectedItem(selectedClade);
                } else {
                    cladeCombo.setSelectedIndex(0);
                }
            }

            @Override
            public void showProgress(double value) {
                updateProgress(progressMessage, value);
            }
        }.execute();
    } catch (Exception x) {
        LOG.error("Unable to connect to UCSC database.", x);
        topLevelPanel.removeAll();
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.fill = GridBagConstraints.NONE;
        gbc.weightx = 0.0;
        gbc.weighty = 0.0;
        topLevelPanel.add(new JLabel("Unable to connect to UCSC database."), gbc);
        JLabel error = new JLabel(MiscUtils.getMessage(x));
        Font f = topLevelPanel.getFont();
        f = f.deriveFont(Font.ITALIC, f.getSize() - 2.0f);
        error.setFont(f);
        topLevelPanel.add(error, gbc);
    }
}

From source file:savant.util.swing.TrackChooser.java

private void initLayout() {

    this.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();

    //FILLER// ww  w . ja va 2 s  .c o m
    //LEFT LABEL
    JLabel leftLabel = new JLabel("All Tracks");
    leftLabel.setFont(new Font(null, Font.BOLD, 12));
    c.gridx = 0;
    c.gridy = 0;
    c.insets = new Insets(5, 5, 5, 5);
    add(leftLabel, c);

    // RIGHT LABEL
    JLabel rightLabel = new JLabel("Selected Tracks");
    rightLabel.setFont(new Font(null, Font.BOLD, 12));
    c.gridx = 2;
    c.gridwidth = GridBagConstraints.REMAINDER;
    add(rightLabel, c);

    //LEFT LIST
    leftList = new JList();
    JScrollPane leftScroll = new JScrollPane();
    leftScroll.setViewportView(leftList);
    leftScroll.setMinimumSize(new Dimension(450, 300));
    leftScroll.setPreferredSize(new Dimension(450, 300));
    c.weightx = 1.0;
    c.weighty = 1.0;
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 1;
    c.gridheight = 4;
    add(leftScroll, c);

    //RIGHT LIST
    rightList = new JList();
    JScrollPane rightScroll = new JScrollPane();
    rightScroll.setViewportView(rightList);
    rightScroll.setMinimumSize(new Dimension(450, 300));
    rightScroll.setPreferredSize(new Dimension(450, 300));
    c.gridx = 2;
    c.gridwidth = GridBagConstraints.REMAINDER;
    this.add(rightScroll, c);

    // MOVE RIGHT
    c.weightx = 0.0;
    c.weighty = 0.5;
    c.gridx = 1;
    c.gridy = 1;
    c.gridwidth = 1;
    c.gridheight = 1;
    add(createMoveRight(), c);

    // MOVE LEFT
    c.gridy = 2;
    add(createMoveLeft(), c);

    // ALL RIGHT
    c.gridy = 3;
    add(createAllRight(), c);

    //ALL LEFT
    c.gridy = 4;
    this.add(createAllLeft(), c);

    //FILTER
    c.gridx = 0;
    c.gridy = 5;
    add(createFilterPanel(), c);

    //AUTO SELECT ALL
    c.gridx = 2;
    add(createSelectAllCheck(), c);

    //SEPARATOR
    JSeparator separator1 = new JSeparator(SwingConstants.HORIZONTAL);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 0;
    c.gridy = GridBagConstraints.RELATIVE;
    c.weightx = 1.0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    add(separator1, c);

    if (selectBase) {

        //SELECT BASE PANEL
        JPanel selectBasePanel = new JPanel(new BorderLayout());
        c.gridwidth = 2;
        add(selectBasePanel, c);

        //SELECT BASE LABEL
        JLabel selectBaseLabel = new JLabel("(Optional) Select Base: ");
        selectBasePanel.add(selectBaseLabel, BorderLayout.WEST);

        //SELECT BASE FIELD
        selectBaseField = new JTextField();
        selectBasePanel.add(selectBaseField, BorderLayout.CENTER);

        //SELECT BASE EXAMPLE
        JLabel selectBaseExample = new JLabel("  ex. 123,456,789");
        selectBasePanel.add(selectBaseExample, BorderLayout.EAST);

        //SEPARATOR
        JSeparator separator2 = new JSeparator(SwingConstants.HORIZONTAL);
        c.gridwidth = GridBagConstraints.REMAINDER;
        add(separator2, c);
    }

    JPanel okCancelPanel = new JPanel(new BorderLayout());
    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;
    c.fill = GridBagConstraints.NONE;
    add(okCancelPanel, c);

    //OK
    okCancelPanel.add(createOKButton(), BorderLayout.CENTER);

    //CANCEL
    okCancelPanel.add(createCancelButton(), BorderLayout.EAST);

    pack();
}

From source file:SeedGenerator.MainForm.java

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
    JFrame frame = new JFrame("JFileChooser Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    final JLabel directoryLabel = new JLabel(" ");
    directoryLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 36));
    contentPane.add(directoryLabel, BorderLayout.NORTH);

    final JLabel filenameLabel = new JLabel(" ");
    filenameLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 36));
    contentPane.add(filenameLabel, BorderLayout.SOUTH);

    JFileChooser fileChooser = new JFileChooser(".");
    fileChooser.setControlButtonsAreShown(true);
    contentPane.add(fileChooser, BorderLayout.CENTER);

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            JFileChooser theFileChooser = (JFileChooser) actionEvent.getSource();
            String command = actionEvent.getActionCommand();
            if (command.equals(JFileChooser.APPROVE_SELECTION)) {
                File selectedFile = theFileChooser.getSelectedFile();
                directoryLabel.setText(selectedFile.getParent());
                filenameLabel.setText(selectedFile.getName());
            } else if (command.equals(JFileChooser.CANCEL_SELECTION)) {
                directoryLabel.setText(" ");
                filenameLabel.setText(" ");
            }//from   www.j  a  va 2 s. co  m
            frame.setVisible(false);
        }
    };
    fileChooser.addActionListener(actionListener);

    frame.pack();
    frame.setVisible(true); // TODO add your handling code here:
}

From source file:semgen.extraction.RadialGraph.Clusterer.java

public String clusterAndRecolor(AggregateLayout<String, Number> layout, int numEdgesToRemove, Color[] colors,
        boolean groupClusters) {

    setCursor(new Cursor(Cursor.WAIT_CURSOR));
    String moduletable = "";
    Graph<String, Number> g = layout.getGraph();
    layout.removeAll();//from   ww w. ja v  a  2s. c  o m

    EdgeBetweennessClusterer<String, Number> clusterer = new EdgeBetweennessClusterer<String, Number>(
            numEdgesToRemove);
    Set<Set<String>> clusterSet = clusterer.transform(g);
    List<Number> edges = clusterer.getEdgesRemoved();
    sempanel.removeAll();
    int i = 0;
    // Set the colors of each node so that each cluster's vertices have the same color
    extractor.clusterpanel.checkboxpanel.removeAll();
    for (Iterator<Set<String>> cIt = clusterSet.iterator(); cIt.hasNext();) {
        moduletable = moduletable + "\nCLUSTER " + (i + 1);
        Set<String> vertices = cIt.next();
        Color c = colors[i % colors.length];
        Set<DataStructure> datastrs = new HashSet<DataStructure>();
        for (String vertex : vertices) {
            datastrs.add(extractor.semsimmodel.getDataStructure(vertex));
        }

        JLabel modulelabel = new JLabel("Cluster " + (i + 1));
        modulelabel.setOpaque(true);
        modulelabel.setFont(SemGenFont.defaultBold());
        modulelabel.setBackground(c);
        modulelabel.setAlignmentX(LEFT_ALIGNMENT);
        sempanel.add(modulelabel);

        // Update the semantics panel
        Set<String> addedterms = new HashSet<String>();
        for (String ver : vertices) {
            if (extractor.semsimmodel.getDataStructure(ver).hasPhysicalProperty()) {
                if (extractor.semsimmodel.getDataStructure(ver).getPhysicalProperty()
                        .getPhysicalPropertyOf() != null) {
                    PhysicalModelComponent pmc = extractor.semsimmodel.getDataStructure(ver)
                            .getPhysicalProperty().getPhysicalPropertyOf();
                    String name = null;
                    if (pmc.hasRefersToAnnotation()) {
                        name = pmc.getFirstRefersToReferenceOntologyAnnotation().getValueDescription();
                    } else {
                        name = pmc.getName();
                    }
                    if (!addedterms.contains(name)) {
                        addedterms.add(name);
                        JTextArea enttext = new JTextArea(name);
                        enttext.setOpaque(true);
                        enttext.setBackground(c);
                        enttext.setFont(SemGenFont.defaultPlain(-2));
                        if (pmc instanceof PhysicalProcess) {
                            enttext.setFont(SemGenFont.defaultItalic(-2));
                            name = "Process: " + name;
                        } else
                            name = "Entity: " + name;
                        enttext.setWrapStyleWord(true);
                        enttext.setLineWrap(true);
                        enttext.setBorder(BorderFactory.createEmptyBorder(7, 7, 0, 0));
                        enttext.setAlignmentX(LEFT_ALIGNMENT);
                        sempanel.add(enttext);
                        moduletable = moduletable + "\n   " + name;
                    }
                }
            }
        }
        sempanel.validate();
        sempanel.repaint();
        semscroller.repaint();
        semscroller.validate();
        this.repaint();
        this.validate();

        colorCluster(vertices, c);
        ExtractorJCheckBox box = new ExtractorJCheckBox("Cluster " + (i + 1), datastrs);
        box.setBackground(c);
        box.setOpaque(true);
        box.addItemListener(extractor);
        extractor.clusterpanel.checkboxpanel.add(box);
        if (groupClusters == true)
            groupCluster(layout, vertices);
        i++;
    }
    refreshModulePanel();

    for (Number e : g.getEdges()) {
        if (edges.contains(e))
            edgePaints.put(e, Color.lightGray);
        else
            edgePaints.put(e, Color.black);
    }
    nummodules = i;
    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    return moduletable;
}