Example usage for javax.swing BoxLayout BoxLayout

List of usage examples for javax.swing BoxLayout BoxLayout

Introduction

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

Prototype

@ConstructorProperties({ "target", "axis" })
public BoxLayout(Container target, int axis) 

Source Link

Document

Creates a layout manager that will lay out components along the given axis.

Usage

From source file:io.github.jeremgamer.editor.panels.Panels.java

public Panels(final JFrame frame, final PanelsPanel pp) {
    this.setBorder(BorderFactory.createTitledBorder(""));

    JButton add = null;/* www.  j a  v  a  2  s  .co m*/
    try {
        add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                JOptionPane jop = new JOptionPane();
                @SuppressWarnings("static-access")
                String name = jop.showInputDialog((JFrame) SwingUtilities.windowForComponent(panelList),
                        "Nommez le panneau :", "Crer un panneau", JOptionPane.QUESTION_MESSAGE);

                if (name != null) {
                    for (int i = 0; i < data.getSize(); i++) {
                        if (data.get(i).equals(name)) {
                            name += "1";
                        }
                    }
                    data.addElement(name);
                    new PanelSave(name);
                    PanelsPanel.updateLists();
                    mainPanel.addItem(name);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    });

    JButton remove = null;
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                if (panelList.getSelectedValue() != null) {
                    File file = new File("projects/" + Editor.getProjectName() + "/panels/"
                            + panelList.getSelectedValue() + "/" + panelList.getSelectedValue() + ".rbd");
                    JOptionPane jop = new JOptionPane();
                    @SuppressWarnings("static-access")
                    int option = jop.showConfirmDialog((JFrame) SwingUtilities.windowForComponent(panelList),
                            "tes-vous sr de vouloir supprimer ce panneau?", "Avertissement",
                            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

                    if (option == JOptionPane.OK_OPTION) {
                        if (panelList.getSelectedValue().equals(pp.getFileName())) {
                            pp.setFileName("");
                        }
                        pp.hide();
                        file.delete();
                        File parent = new File(file.getParent());
                        for (File img : FileUtils.listFiles(parent, TrueFileFilter.INSTANCE,
                                TrueFileFilter.INSTANCE)) {
                            img.delete();
                        }
                        parent.delete();
                        mainPanel.removeItem(panelList.getSelectedValue());
                        data.remove(panelList.getSelectedIndex());
                        ActionPanel.updateLists();
                        PanelsPanel.updateLists();
                    }
                }
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            }

        }

    });

    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS));
    buttons.add(add);
    buttons.add(remove);

    mainPanel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            GeneralSave gs = new GeneralSave();
            try {
                gs.load(new File("projects/" + Editor.getProjectName() + "/general.rbd"));
                gs.set("mainPanel", combo.getSelectedItem());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    });

    updateList();
    panelList.addMouseListener(new MouseAdapter() {
        @SuppressWarnings("unchecked")
        public void mouseClicked(MouseEvent evt) {
            JList<String> list = (JList<String>) evt.getSource();
            if (evt.getClickCount() == 2) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    pp.load(new File("projects/" + Editor.getProjectName() + "/panels/"
                            + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index)
                            + ".rbd"));
                    PanelsPanel.updateLists();
                    pp.show();
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            pp.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            pp.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            pp.load(new File("projects/" + Editor.getProjectName() + "/panels/"
                                    + list.getModel().getElementAt(index) + "/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                            PanelsPanel.updateLists();
                        }
                    } catch (NullPointerException npe) {
                        pp.hide();
                        list.clearSelection();
                    }
                }
            } else if (evt.getClickCount() == 3) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    pp.load(new File("projects/" + Editor.getProjectName() + "/panels/"
                            + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index)
                            + ".rbd"));
                    PanelsPanel.updateLists();
                    pp.show();
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            pp.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            pp.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            pp.load(new File("projects/" + Editor.getProjectName() + "/panels/"
                                    + list.getModel().getElementAt(index) + "/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                            PanelsPanel.updateLists();
                        }
                    } catch (NullPointerException npe) {
                        pp.hide();
                        list.clearSelection();
                    }
                }
            }
        }
    });
    JScrollPane listPane = new JScrollPane(panelList);
    listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    this.add(buttons);
    this.add(listPane);

    JPanel mainPanelInput = new JPanel();
    mainPanelInput.setPreferredSize(new Dimension(280, 35));
    mainPanelInput.setMaximumSize(new Dimension(280, 35));
    mainPanelInput.add(new JLabel("Panneau principal:"));
    mainPanel.setPreferredSize(new Dimension(150, 27));
    mainPanelInput.add(mainPanel);
    this.add(mainPanelInput);
}

From source file:com.dragoniade.deviantart.ui.PreferencesDialog.java

public PreferencesDialog(final DownloaderGUI owner, Properties config) {
    super(owner, "Preferences", true);

    HttpClientParams params = new HttpClientParams();
    params.setVersion(HttpVersion.HTTP_1_1);
    params.setSoTimeout(30000);//from ww  w .ja v  a 2  s . com
    client = new HttpClient(params);
    setProxy(ProxyCfg.parseConfig(config));

    sample = new Deviation();
    sample.setId(15972367L);
    sample.setTitle("Fella Promo");
    sample.setArtist("devart");
    sample.setImageDownloadUrl(DOWNLOAD_URL);
    sample.setImageFilename(Deviation.extractFilename(DOWNLOAD_URL));
    sample.setCollection(new Collection(1L, "MyCollect"));
    setLayout(new BorderLayout());
    panes = new JTabbedPane(JTabbedPane.TOP);

    JPanel genPanel = new JPanel();
    BoxLayout genLayout = new BoxLayout(genPanel, BoxLayout.Y_AXIS);
    genPanel.setLayout(genLayout);
    panes.add("General", genPanel);

    JLabel userLabel = new JLabel("Username");

    userLabel.setToolTipText("The username the account you want to download the favorites from.");

    userField = new JTextField(config.getProperty(Constants.USERNAME));

    userLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    userLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    userField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    userField.setMaximumSize(new Dimension(Integer.MAX_VALUE, userField.getFont().getSize() * 2));

    genPanel.add(userLabel);
    genPanel.add(userField);

    JPanel radioPanel = new JPanel();
    BoxLayout radioLayout = new BoxLayout(radioPanel, BoxLayout.X_AXIS);
    radioPanel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    radioPanel.setBorder(new EmptyBorder(0, 5, 0, 5));

    radioPanel.setLayout(radioLayout);

    JLabel searchLabel = new JLabel("Search for");
    searchLabel
            .setToolTipText("Select what you want to download from that user: it favorites or it galleries.");
    searchLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    searchLabel.setBorder(new EmptyBorder(0, 5, 0, 5));

    selectedSearch = SEARCH.lookup(config.getProperty(Constants.SEARCH, SEARCH.getDefault().getId()));
    buttonGroup = new ButtonGroup();

    for (final SEARCH search : SEARCH.values()) {
        JRadioButton radio = new JRadioButton(search.getLabel());
        radio.setAlignmentX(JLabel.LEFT_ALIGNMENT);
        radio.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                selectedSearch = search;
            }
        });

        buttonGroup.add(radio);
        radioPanel.add(radio);
        if (search.equals(selectedSearch)) {
            radio.setSelected(true);
        }
    }

    genPanel.add(radioPanel);

    final JTextField sampleField = new JTextField("");
    sampleField.setEditable(false);

    JLabel locationLabel = new JLabel("Download location");
    locationLabel.setToolTipText("The folder pattern where you want the file to be downloaded in.");

    JLabel legendsLabel = new JLabel(
            "<html><body>Field names: %user%, %artist%, %title%, %id%, %filename%, %collection%, %ext%<br></br>Example:</body></html>");
    legendsLabel.setToolTipText("An example of where a file will be downloaded to.");

    locationString = new StringBuilder();
    locationField = new JTextField(config.getProperty(Constants.LOCATION));
    locationField.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub

        }

        public void keyReleased(KeyEvent e) {
            File dest = LocationHelper.getFile(locationField.getText(), userField.getText(), sample,
                    sample.getImageFilename());
            locationString.setLength(0);
            locationString.append(dest.getAbsolutePath());
            sampleField.setText(locationString.toString());
            if (useSameForMatureBox.isSelected()) {
                locationMatureString.setLength(0);
                locationMatureString.append(sampleField.getText());
                locationMatureField.setText(locationField.getText());
            }
        }

        public void keyTyped(KeyEvent e) {
        }

    });
    locationField.addMouseListener(new MouseListener() {
        public void mouseReleased(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
            sampleField.setText(locationString.toString());
        }

        public void mouseEntered(MouseEvent e) {
            sampleField.setText(locationString.toString());
        }

        public void mouseClicked(MouseEvent e) {
        }
    });
    JLabel locationMatureLabel = new JLabel("Mature download location");
    locationMatureLabel.setToolTipText(
            "The folder pattern where you want the file marked as 'Mature' to be downloaded in.");

    locationMatureString = new StringBuilder();
    locationMatureField = new JTextField(config.getProperty(Constants.MATURE));
    locationMatureField.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub

        }

        public void keyReleased(KeyEvent e) {
            File dest = LocationHelper.getFile(locationMatureField.getText(), userField.getText(), sample,
                    sample.getImageFilename());
            locationMatureString.setLength(0);
            locationMatureString.append(dest.getAbsolutePath());
            sampleField.setText(locationMatureString.toString());
        }

        public void keyTyped(KeyEvent e) {
        }

    });

    locationMatureField.addMouseListener(new MouseListener() {
        public void mouseReleased(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
            sampleField.setText(locationString.toString());
        }

        public void mouseEntered(MouseEvent e) {
            sampleField.setText(locationMatureString.toString());
        }

        public void mouseClicked(MouseEvent e) {
        }
    });

    useSameForMatureBox = new JCheckBox("Use same location for mature deviation?");
    useSameForMatureBox.setSelected(locationLabel.getText().equals(locationMatureField.getText()));
    useSameForMatureBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (useSameForMatureBox.isSelected()) {
                locationMatureField.setEditable(false);
                locationMatureField.setText(locationField.getText());
                locationMatureString.setLength(0);
                locationMatureString.append(locationString);
            } else {
                locationMatureField.setEditable(true);
            }

        }
    });

    File dest = LocationHelper.getFile(locationField.getText(), userField.getText(), sample,
            sample.getImageFilename());
    sampleField.setText(dest.getAbsolutePath());
    locationString.append(sampleField.getText());

    dest = LocationHelper.getFile(locationMatureField.getText(), userField.getText(), sample,
            sample.getImageFilename());
    locationMatureString.append(dest.getAbsolutePath());

    locationLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    locationField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationField.setMaximumSize(new Dimension(Integer.MAX_VALUE, locationField.getFont().getSize() * 2));
    locationMatureLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationMatureLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    locationMatureField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationMatureField
            .setMaximumSize(new Dimension(Integer.MAX_VALUE, locationMatureField.getFont().getSize() * 2));
    useSameForMatureBox.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    legendsLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    legendsLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    legendsLabel.setMaximumSize(new Dimension(Integer.MAX_VALUE, legendsLabel.getFont().getSize() * 2));
    sampleField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    sampleField.setMaximumSize(new Dimension(Integer.MAX_VALUE, sampleField.getFont().getSize() * 2));

    genPanel.add(locationLabel);
    genPanel.add(locationField);

    genPanel.add(locationMatureLabel);
    genPanel.add(locationMatureField);
    genPanel.add(useSameForMatureBox);

    genPanel.add(legendsLabel);
    genPanel.add(sampleField);
    genPanel.add(Box.createVerticalBox());

    final KeyListener prxChangeListener = new KeyListener() {

        public void keyTyped(KeyEvent e) {
            proxyChangeState = true;
        }

        public void keyPressed(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
        }
    };

    JPanel prxPanel = new JPanel();
    BoxLayout prxLayout = new BoxLayout(prxPanel, BoxLayout.Y_AXIS);
    prxPanel.setLayout(prxLayout);
    panes.add("Proxy", prxPanel);

    JLabel prxHostLabel = new JLabel("Proxy Host");
    prxHostLabel.setToolTipText("The hostname of the proxy server");
    prxHostField = new JTextField(config.getProperty(Constants.PROXY_HOST));
    prxHostLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxHostLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxHostField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxHostField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxHostField.getFont().getSize() * 2));

    JLabel prxPortLabel = new JLabel("Proxy Port");
    prxPortLabel.setToolTipText("The port of the proxy server (Default 80).");

    prxPortSpinner = new JSpinner();
    prxPortSpinner.setModel(new SpinnerNumberModel(
            Integer.parseInt(config.getProperty(Constants.PROXY_PORT, "80")), 1, 65535, 1));

    prxPortLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPortLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxPortSpinner.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPortSpinner.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxPortSpinner.getFont().getSize() * 2));

    JLabel prxUserLabel = new JLabel("Proxy username");
    prxUserLabel.setToolTipText("The username used for authentication, if applicable.");
    prxUserField = new JTextField(config.getProperty(Constants.PROXY_USERNAME));
    prxUserLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxUserLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxUserField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxUserField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxUserField.getFont().getSize() * 2));

    JLabel prxPassLabel = new JLabel("Proxy username");
    prxPassLabel.setToolTipText("The username used for authentication, if applicable.");
    prxPassField = new JPasswordField(config.getProperty(Constants.PROXY_PASSWORD));
    prxPassLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPassLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxPassField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPassField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxPassField.getFont().getSize() * 2));

    prxUseBox = new JCheckBox("Use a proxy?");
    prxUseBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            prxChangeListener.keyTyped(null);

            if (prxUseBox.isSelected()) {
                prxHostField.setEditable(true);
                prxPortSpinner.setEnabled(true);
                prxUserField.setEditable(true);
                prxPassField.setEditable(true);

            } else {
                prxHostField.setEditable(false);
                prxPortSpinner.setEnabled(false);
                prxUserField.setEditable(false);
                prxPassField.setEditable(false);
            }
        }
    });

    prxUseBox.setSelected(!Boolean.parseBoolean(config.getProperty(Constants.PROXY_USE)));
    prxUseBox.doClick();
    proxyChangeState = false;

    prxHostField.addKeyListener(prxChangeListener);
    prxUserField.addKeyListener(prxChangeListener);
    prxPassField.addKeyListener(prxChangeListener);
    prxPortSpinner.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            proxyChangeState = true;
        }
    });
    prxPanel.add(prxUseBox);

    prxPanel.add(prxHostLabel);
    prxPanel.add(prxHostField);

    prxPanel.add(prxPortLabel);
    prxPanel.add(prxPortSpinner);

    prxPanel.add(prxUserLabel);
    prxPanel.add(prxUserField);

    prxPanel.add(prxPassLabel);
    prxPanel.add(prxPassField);
    prxPanel.add(Box.createVerticalBox());

    final JPanel advPanel = new JPanel();
    BoxLayout advLayout = new BoxLayout(advPanel, BoxLayout.Y_AXIS);
    advPanel.setLayout(advLayout);
    panes.add("Advanced", advPanel);
    panes.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            JTabbedPane pane = (JTabbedPane) e.getSource();

            if (proxyChangeState && pane.getSelectedComponent() == advPanel) {
                Properties properties = new Properties();
                properties.setProperty(Constants.PROXY_USERNAME, prxUserField.getText().trim());
                properties.setProperty(Constants.PROXY_PASSWORD, new String(prxPassField.getPassword()).trim());
                properties.setProperty(Constants.PROXY_HOST, prxHostField.getText().trim());
                properties.setProperty(Constants.PROXY_PORT, prxPortSpinner.getValue().toString());
                properties.setProperty(Constants.PROXY_USE, Boolean.toString(prxUseBox.isSelected()));
                ProxyCfg prx = ProxyCfg.parseConfig(properties);
                setProxy(prx);
                revalidateSearcher(null);
            }
        }
    });
    JLabel domainLabel = new JLabel("Deviant Art domain name");
    domainLabel.setToolTipText("The deviantART main domain, should it ever change.");

    domainField = new JTextField(config.getProperty(Constants.DOMAIN));
    domainLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    domainLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    domainField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    domainField.setMaximumSize(new Dimension(Integer.MAX_VALUE, domainField.getFont().getSize() * 2));

    advPanel.add(domainLabel);
    advPanel.add(domainField);

    JLabel throttleLabel = new JLabel("Throttle search delay");
    throttleLabel.setToolTipText(
            "Slow down search query by inserting a pause between them. This help prevent abuse when doing a massive download.");

    throttleSpinner = new JSpinner();
    throttleSpinner.setModel(
            new SpinnerNumberModel(Integer.parseInt(config.getProperty(Constants.THROTTLE, "0")), 5, 60, 1));

    throttleLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    throttleLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    throttleSpinner.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    throttleSpinner.setMaximumSize(new Dimension(Integer.MAX_VALUE, throttleSpinner.getFont().getSize() * 2));

    advPanel.add(throttleLabel);
    advPanel.add(throttleSpinner);

    JLabel searcherLabel = new JLabel("Searcher");
    searcherLabel.setToolTipText("Select a searcher that will look for your favorites.");

    searcherBox = new JComboBox();
    searcherBox.setRenderer(new TogglingRenderer());

    final AtomicInteger index = new AtomicInteger(0);
    searcherBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox combo = (JComboBox) e.getSource();
            Object selectedItem = combo.getSelectedItem();
            if (selectedItem instanceof SearchItem) {
                SearchItem item = (SearchItem) selectedItem;
                if (item.isValid) {
                    index.set(combo.getSelectedIndex());
                } else {
                    combo.setSelectedIndex(index.get());
                }
            }
        }
    });

    try {
        for (Class<Search> clazz : SearcherClassCache.getInstance().getClasses()) {

            Search searcher = clazz.newInstance();
            String name = searcher.getName();

            SearchItem item = new SearchItem(name, clazz.getName(), true);
            searcherBox.addItem(item);
        }
        String selectedClazz = config.getProperty(Constants.SEARCHER,
                com.dragoniade.deviantart.deviation.SearchRss.class.getName());
        revalidateSearcher(selectedClazz);
    } catch (Exception e1) {
        throw new RuntimeException(e1);
    }

    searcherLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    searcherLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    searcherBox.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    searcherBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, searcherBox.getFont().getSize() * 2));

    advPanel.add(searcherLabel);
    advPanel.add(searcherBox);

    advPanel.add(Box.createVerticalBox());

    add(panes, BorderLayout.CENTER);

    JButton saveBut = new JButton("Save");

    userField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            if (field.getText().trim().length() == 0) {
                JOptionPane.showMessageDialog(input, "The user musn't be empty.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }
            return true;
        }
    });

    locationField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            String content = field.getText().trim();
            if (content.length() == 0) {
                JOptionPane.showMessageDialog(input, "The location musn't be empty.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }

            if (!content.contains("%filename%") && !content.contains("%id%")) {
                JOptionPane.showMessageDialog(input,
                        "The location must contains at least a %filename% or an %id% field.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }
            return true;
        }
    });

    locationMatureField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            String content = field.getText().trim();
            if (content.length() == 0) {
                JOptionPane.showMessageDialog(input, "The Mature location musn't be empty.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }

            if (!content.contains("%filename%") && !content.contains("%id%")) {
                JOptionPane.showMessageDialog(input,
                        "The Mature location must contains at least a %username% or an %id% field.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }
            return true;
        }
    });

    domainField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            String domain = field.getText().trim();
            if (domain.length() == 0) {
                JOptionPane.showMessageDialog(input, "You must specify the deviantART main domain.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }

            if (domain.toLowerCase().startsWith("http://")) {
                JOptionPane.showMessageDialog(input,
                        "You must specify the deviantART main domain, not the full URL (aka www.deviantart.com).",
                        "Warning", JOptionPane.WARNING_MESSAGE);
                return false;
            }

            return true;
        }
    });
    locationField.setVerifyInputWhenFocusTarget(true);

    final JDialog parent = this;
    saveBut.addActionListener(new ActionListener() {

        String errorMsg = "The location is invalid or cannot be written to.";

        public void actionPerformed(ActionEvent e) {

            String username = userField.getText().trim();
            String location = locationField.getText().trim();
            String locationMature = locationMatureField.getText().trim();
            String domain = domainField.getText().trim();
            String throttle = throttleSpinner.getValue().toString();
            String searcher = searcherBox.getSelectedItem().toString();

            String prxUse = Boolean.toString(prxUseBox.isSelected());
            String prxHost = prxHostField.getText().trim();
            String prxPort = prxPortSpinner.getValue().toString();
            String prxUsername = prxUserField.getText().trim();
            String prxPassword = new String(prxPassField.getPassword()).trim();

            if (!testPath(location, username)) {
                JOptionPane.showMessageDialog(parent, errorMsg, "Error", JOptionPane.ERROR_MESSAGE);
            }
            if (!testPath(locationMature, username)) {
                JOptionPane.showMessageDialog(parent, errorMsg, "Error", JOptionPane.ERROR_MESSAGE);
            }

            Properties p = new Properties();
            p.setProperty(Constants.USERNAME, username);
            p.setProperty(Constants.LOCATION, location);
            p.setProperty(Constants.MATURE, locationMature);
            p.setProperty(Constants.DOMAIN, domain);
            p.setProperty(Constants.THROTTLE, throttle);
            p.setProperty(Constants.SEARCHER, searcher);
            p.setProperty(Constants.SEARCH, selectedSearch.getId());

            p.setProperty(Constants.PROXY_USE, prxUse);
            p.setProperty(Constants.PROXY_HOST, prxHost);
            p.setProperty(Constants.PROXY_PORT, prxPort);
            p.setProperty(Constants.PROXY_USERNAME, prxUsername);
            p.setProperty(Constants.PROXY_PASSWORD, prxPassword);

            owner.savePreferences(p);
            parent.dispose();
        }
    });

    JButton cancelBut = new JButton("Cancel");
    cancelBut.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            parent.dispose();
        }
    });

    JPanel buttonPanel = new JPanel();
    BoxLayout butLayout = new BoxLayout(buttonPanel, BoxLayout.X_AXIS);
    buttonPanel.setLayout(butLayout);

    buttonPanel.add(saveBut);
    buttonPanel.add(cancelBut);
    add(buttonPanel, BorderLayout.SOUTH);

    pack();
    setResizable(false);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    this.setLocation((d.width - getWidth()) / 2, (d.height - getHeight()) / 2);
    setVisible(true);
}

From source file:io.github.jeremgamer.editor.panels.GeneralSettings.java

public GeneralSettings() {
    this.setBorder(BorderFactory.createTitledBorder(""));

    JPanel namePanel = new JPanel();
    JLabel nameLabel = new JLabel("Nom :");
    namePanel.add(nameLabel);//  w  w  w .  ja va  2  s.  c o m
    name.setPreferredSize(new Dimension(220, 30));
    namePanel.add(name);
    CaretListener caretUpdateName = new CaretListener() {
        public void caretUpdate(javax.swing.event.CaretEvent e) {
            JTextField text = (JTextField) e.getSource();
            gs.set("name", text.getText());
        }
    };
    name.addCaretListener(caretUpdateName);
    this.add(namePanel);

    adress.setEditable(false);
    CaretListener caretUpdateAdress = new CaretListener() {
        public void caretUpdate(javax.swing.event.CaretEvent e) {
            JTextField text = (JTextField) e.getSource();
            gs.set("adress", text.getText());
        }
    };
    adress.addCaretListener(caretUpdateAdress);
    JPanel subTypePanel = new JPanel();
    JLabel typeLabel = new JLabel("Type :");
    subTypePanel.add(typeLabel);
    type.setPreferredSize(new Dimension(220, 30));
    type.addItem("Minecraft classique");
    type.addItem("Minecraft personnalis");
    if (new File("projects/" + Editor.getProjectName() + "/data.zip").exists()) {
        type.setSelectedIndex(1);
        browse.setEnabled(true);
        browse.setText("Supprimer l'import");
    } else {
        browse.setEnabled(false);
    }
    type.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            if (combo.getSelectedIndex() == 1) {
                browse.setEnabled(true);
                adress.setEnabled(true);
                adress.setEditable(true);
            } else {
                browse.setEnabled(false);
                adress.setEnabled(false);
                adress.setEditable(false);
            }
            gs.set("type", combo.getSelectedIndex());
        }

    });
    subTypePanel.add(type);
    JPanel typePanel = new JPanel();
    typePanel.setLayout(new BoxLayout(typePanel, BoxLayout.PAGE_AXIS));

    typePanel.add(subTypePanel);
    JPanel browsePanel = new JPanel();
    browsePanel.add(browse);
    JPanel adressPanel = new JPanel();
    adressPanel.setLayout(new BoxLayout(adressPanel, BoxLayout.PAGE_AXIS));
    JLabel adressLabel = new JLabel("Adresse de tlchargement :");
    adressPanel.setPreferredSize(new Dimension(0, 47));
    adress.setPreferredSize(new Dimension(0, 30));
    adressPanel.add(adressLabel);
    adressPanel.add(adress);
    typePanel.add(adressPanel);

    this.add(typePanel);
    closeOnStart.setSelected(true);
    closeOnStart.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (closeOnStart.isSelected()) {
                gs.set("close", true);
            } else {
                gs.set("close", false);
            }
        }

    });
    this.add(closeOnStart);

    JPanel look = new JPanel();
    look.setBorder(BorderFactory.createTitledBorder("Apparence"));
    look.setPreferredSize(new Dimension(290, 340));
    JPanel colors = new JPanel();
    cDark.setSelected(true);
    bg.add(cLight);
    bg.add(cDark);
    colors.add(cLight);
    colors.add(cDark);
    cLight.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            gs.set("color", 0);
        }

    });
    cDark.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            gs.set("color", 1);
        }

    });
    look.add(colors);
    JPanel checks = new JPanel();
    checks.setLayout(new BoxLayout(checks, BoxLayout.PAGE_AXIS));
    borders.setSelected(true);
    borders.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (borders.isSelected()) {
                gs.set("borders", true);
            } else {
                gs.set("borders", false);
            }
        }

    });
    resize.setSelected(true);
    resize.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (resize.isSelected()) {
                gs.set("resizable", true);
            } else {
                gs.set("resizable", false);
            }
        }

    });
    alwaysOnTop.setSelected(false);
    alwaysOnTop.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (alwaysOnTop.isSelected()) {
                gs.set("top", true);
            } else {
                gs.set("top", false);
            }
        }

    });
    checks.add(borders);
    checks.add(resize);
    checks.add(alwaysOnTop);
    checks.setPreferredSize(new Dimension(270, 60));

    JPanel size = new JPanel();
    width.setPreferredSize(new Dimension(57, 30));
    widthMin.setPreferredSize(new Dimension(57, 30));
    widthMax.setPreferredSize(new Dimension(57, 30));
    height.setPreferredSize(new Dimension(57, 30));
    heightMin.setPreferredSize(new Dimension(57, 30));
    heightMax.setPreferredSize(new Dimension(57, 30));
    JPanel widthPanel = new JPanel();
    widthPanel.setPreferredSize(new Dimension(130, 150));
    widthPanel.setBorder(BorderFactory.createTitledBorder("Largeur"));
    widthPanel.setLayout(new BoxLayout(widthPanel, BoxLayout.PAGE_AXIS));
    JPanel widthPanelBase = new JPanel();
    widthPanelBase.add(new JLabel("Base :"));
    widthPanelBase.add(width);
    JPanel widthPanelMin = new JPanel();
    widthPanelMin.add(new JLabel("Min :"));
    widthPanelMin.add(Box.createRigidArea(new Dimension(5, 1)));
    widthPanelMin.add(widthMin);
    JPanel widthPanelMax = new JPanel();
    widthPanelMax.add(new JLabel("Max :"));
    widthPanelMax.add(Box.createRigidArea(new Dimension(3, 1)));
    widthPanelMax.add(widthMax);
    widthPanel.add(widthPanelBase);
    widthPanel.add(widthPanelMin);
    widthPanel.add(widthPanelMax);

    JPanel heightPanel = new JPanel();
    heightPanel.setPreferredSize(new Dimension(130, 150));
    heightPanel.setBorder(BorderFactory.createTitledBorder("Hauteur"));
    heightPanel.setLayout(new BoxLayout(heightPanel, BoxLayout.PAGE_AXIS));
    JPanel heightPanelBase = new JPanel();
    heightPanelBase.add(new JLabel("Base :"));
    heightPanelBase.add(height);
    JPanel heightPanelMin = new JPanel();
    heightPanelMin.add(new JLabel("Min :"));
    heightPanelMin.add(Box.createRigidArea(new Dimension(5, 1)));
    heightPanelMin.add(heightMin);
    JPanel heightPanelMax = new JPanel();
    heightPanelMax.add(new JLabel("Max :"));
    heightPanelMax.add(Box.createRigidArea(new Dimension(3, 1)));
    heightPanelMax.add(heightMax);
    heightPanel.add(heightPanelBase);
    heightPanel.add(heightPanelMin);
    heightPanel.add(heightPanelMax);
    size.add(widthPanel);
    size.add(heightPanel);

    width.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            gs.set("width", spinner.getValue());
        }
    });
    widthMin.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            gs.set("widthMin", spinner.getValue());
        }
    });
    widthMax.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            ;
            gs.set("widthMax", spinner.getValue());
        }
    });
    height.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            gs.set("height", spinner.getValue());
        }
    });
    heightMin.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            gs.set("heightMin", spinner.getValue());
        }
    });
    heightMax.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            ;
            gs.set("heightMax", spinner.getValue());
        }
    });

    look.add(checks);
    look.add(size);

    JPanel bottom = new JPanel();
    bottom.setLayout(new BoxLayout(bottom, BoxLayout.LINE_AXIS));
    JButton music = new JButton("Ajouter de la musique");
    music.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            new MusicFrame((JFrame) SwingUtilities.windowForComponent(adress), gs);
        }

    });
    bottom.add(music);
    JButton icons = new JButton("Icnes");
    icons.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            new IconFrame((JFrame) SwingUtilities.windowForComponent(adress));
        }

    });
    bottom.add(icons);

    look.add(bottom);

    this.add(look);

    load();
}

From source file:com.idealista.solrmeter.view.statistic.CacheHistoryPanel.java

/**
 * Creates the cumulative data panel/*w  ww .j  a v a 2 s. c o m*/
 * @return
 */
private JPanel createCumulativeDataPanel() {
    JPanel panel = new RoundedBorderJPanel("Cumulative Data");
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    cumulativeLookupsInfoPanel = new InfoPanel(I18n.get(PREFIX + "Lookups"));
    cumulativeHitsInfoPanel = new InfoPanel(I18n.get(PREFIX + "Hits"));
    cumulativeHitRatioInfoPanel = new InfoPanel(I18n.get(PREFIX + "HitRatio"));
    cumulativeInsertsInfoPanel = new InfoPanel(I18n.get(PREFIX + "Inserts"));
    cumulativeEvictionsInfoPanel = new InfoPanel(I18n.get(PREFIX + "Evictions"));
    panel.add(cumulativeLookupsInfoPanel);
    panel.add(cumulativeHitsInfoPanel);
    panel.add(cumulativeHitRatioInfoPanel);
    panel.add(cumulativeInsertsInfoPanel);
    panel.add(cumulativeEvictionsInfoPanel);
    return panel;
}

From source file:instance.gui.InstanceGUI.java

private void createSystemInfoPanel() {
    systemInfoPanel = new JPanel();
    systemInfoPanel.setBorder(BorderFactory.createTitledBorder("System Info"));
    systemInfoPanel.setLayout(new BoxLayout(systemInfoPanel, BoxLayout.Y_AXIS));

    cpuInfoLbl = new JLabel("CPU: ");
    cpuInfoLbl.setBorder(BorderFactory.createEtchedBorder());
    memoryLbl = new JLabel("Memory: ");
    memoryLbl.setBorder(BorderFactory.createEtchedBorder());
    bandwidthInfoLbl = new JLabel("Bandwidth: ");
    bandwidthInfoLbl.setBorder(BorderFactory.createEtchedBorder());
    costLabel = new JLabel("Cost: $ 0.0");
    costLabel.setBorder(BorderFactory.createEtchedBorder());
    simultaneousLabel = new JLabel("Simultaneous Downloads: ");
    simultaneousLabel.setBorder(BorderFactory.createEtchedBorder());

    systemInfoPanel.add(cpuInfoLbl);/*from www. ja  v a 2s .  c om*/
    systemInfoPanel.add(memoryLbl);
    systemInfoPanel.add(bandwidthInfoLbl);
    systemInfoPanel.add(costLabel);
    systemInfoPanel.add(simultaneousLabel);

    infoTab.add(systemInfoPanel);

}

From source file:com.adito.upgrade.GUIUpgrader.java

public GUIUpgrader() {
    super(new BorderLayout());
    JPanel info = new JPanel(new BorderLayout(2, 2));

    //        info.setBackground(Color.white);
    //        info.setForeground(Color.black);
    //        info.setOpaque(true);
    info.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    JLabel l = new JLabel("<html><p>This utility upgrades configuration from "
            + "one version 0.1.16 installation to another "
            + "0.2.5+ installation. You may choose which resources you "
            + "wish to be copied. If resources with the same name already " + "exist they will be left as is.");
    l.setIcon(new ImageIcon(GUIUpgrader.class.getResource("upgrader-48x48.png")));
    info.add(l, BorderLayout.CENTER);
    info.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.SOUTH);
    mainPanel = new JPanel(new BorderLayout());
    add(info, BorderLayout.NORTH);
    add(mainPanel, BorderLayout.CENTER);

    // Installations panel
    JPanel installations = new JPanel(new GridBagLayout());
    installations.setBorder(BorderFactory.createTitledBorder("Installations"));
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.WEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(2, 2, 2, 2);
    gbc.weightx = 2.0;/*  ww w.  java2  s .c o m*/
    UIUtil.jGridBagAdd(installations, new JLabel("Source"), gbc, GridBagConstraints.REMAINDER);
    gbc.weightx = 1.0;
    source = new JTextField();
    source.getDocument().addDocumentListener(this);
    UIUtil.jGridBagAdd(installations, source, gbc, GridBagConstraints.RELATIVE);
    browseSource = new JButton("Browse");
    browseSource.setMnemonic('b');
    browseSource.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser(source.getText());
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setDialogTitle("Select source installation directory (0.16.1)");
            if (chooser.showOpenDialog(GUIUpgrader.this) == JFileChooser.APPROVE_OPTION) {
                source.setText(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });
    gbc.weightx = 0.0;
    UIUtil.jGridBagAdd(installations, browseSource, gbc, GridBagConstraints.REMAINDER);
    gbc.weightx = 2.0;
    UIUtil.jGridBagAdd(installations, new JLabel("Target"), gbc, GridBagConstraints.REMAINDER);
    gbc.weightx = 1.0;
    target = new JTextField(System.getProperty("user.dir"));
    target.getDocument().addDocumentListener(this);
    UIUtil.jGridBagAdd(installations, target, gbc, GridBagConstraints.RELATIVE);
    browseTarget = new JButton("Browse");
    browseTarget.setMnemonic('r');
    browseTarget.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser(target.getText());
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setDialogTitle("Select target installation directory (0.2.5+)");
            if (chooser.showOpenDialog(GUIUpgrader.this) == JFileChooser.APPROVE_OPTION) {
                target.setText(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });
    gbc.weightx = 0.0;
    UIUtil.jGridBagAdd(installations, browseTarget, gbc, GridBagConstraints.REMAINDER);
    mainPanel.add(installations, BorderLayout.NORTH);

    // Upgrade selection
    upgradeSelectionPanel = new JPanel();
    upgradeSelectionPanel.setBorder(BorderFactory.createTitledBorder("Upgrades"));
    upgradeSelectionPanel.setLayout(new BoxLayout(upgradeSelectionPanel, BoxLayout.Y_AXIS));
    mainPanel.add(upgradeSelectionPanel, BorderLayout.CENTER);

}

From source file:BoxAlignmentDemo.java

protected JPanel createYAlignmentExample(boolean doItRight) {
    JPanel pane = new JPanel();
    String title;// w  ww .j  a v  a 2 s. c  o m

    JComponent component1 = new JPanel();
    Dimension size = new Dimension(100, 50);
    component1.setMaximumSize(size);
    component1.setPreferredSize(size);
    component1.setMinimumSize(size);
    TitledBorder border = new TitledBorder(new LineBorder(Color.black), "A JPanel", TitledBorder.CENTER,
            TitledBorder.BELOW_TOP);
    border.setTitleColor(Color.black);
    component1.setBorder(border);

    JComponent component2 = new JPanel();
    size = new Dimension(100, 50);
    component2.setMaximumSize(size);
    component2.setPreferredSize(size);
    component2.setMinimumSize(size);
    border = new TitledBorder(new LineBorder(Color.black), "A JPanel", TitledBorder.CENTER,
            TitledBorder.BELOW_TOP);
    border.setTitleColor(Color.black);
    component2.setBorder(border);

    if (doItRight) {
        title = "Matched";
    } else {
        component1.setAlignmentY(TOP_ALIGNMENT);
        title = "Mismatched";
    }

    pane.setBorder(BorderFactory.createTitledBorder(title));
    pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
    pane.add(component1);
    pane.add(component2);
    return pane;
}

From source file:org.obiba.onyx.jade.instrument.summitdoppler.VantageABIInstrumentRunner.java

/**
 * Puts together the GUI main panel component.
 * /*w w w.  j  a  v a  2s  . c  o m*/
 * @return
 */
protected JPanel buildMainPanel() {

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    panel.add(buildMeasureCountSubPanel());
    panel.add(buildFileSelectionSubPanel());
    panel.add(buildActionButtonSubPanel());

    return panel;
}

From source file:io.github.jeremgamer.editor.panels.IconFrame.java

public IconFrame(JFrame parent) {
    this.setModal(true);
    this.setResizable(false);
    ArrayList<BufferedImage> icons = new ArrayList<BufferedImage>();
    try {/*ww w.j  av a 2 s .c om*/
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon16.png")));
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon32.png")));
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon64.png")));
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon128.png")));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    this.setIconImages((List<? extends Image>) icons);
    this.setTitle("Icnes");

    this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    JPanel content = new JPanel();
    content.setLayout(new BoxLayout(content, BoxLayout.LINE_AXIS));
    content.setBorder(BorderFactory.createTitledBorder(""));

    try {
        remove128.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
        remove64.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
        remove32.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
        remove16.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    browse128.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "128.png");
                try {
                    x128.repaint();
                    x128.getGraphics().drawImage(ImageIO.read(new File(path)), 0 + 10, 0 + 20, 128, 128, null);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    remove128.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File("projects/" + Editor.getProjectName() + "/128.png");
            file.delete();
            x128.repaint();
        }
    });
    browse64.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "64.png");
                try {
                    x64.repaint();
                    x64.getGraphics().drawImage(ImageIO.read(new File(path)), 32 + 10, 32 + 20, 64, 64, null);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    remove64.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File("projects/" + Editor.getProjectName() + "/64.png");
            file.delete();
            x64.repaint();
        }
    });
    browse32.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "32.png");
                try {
                    x32.repaint();
                    x32.getGraphics().drawImage(ImageIO.read(new File(path)), 48 + 10, 48 + 20, 32, 32, null);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    remove32.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File("projects/" + Editor.getProjectName() + "/32.png");
            file.delete();
            x32.repaint();
        }
    });
    browse16.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "16.png");
                try {
                    x16.repaint();
                    x16.getGraphics().drawImage(ImageIO.read(new File(path)), 56 + 10, 56 + 20, 16, 16, null);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    remove16.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File("projects/" + Editor.getProjectName() + "/16.png");
            file.delete();
            x16.repaint();
        }
    });

    content.add(x128);
    content.add(x64);
    content.add(x32);
    content.add(x16);
    this.setContentPane(content);
    this.pack();
    this.setLocationRelativeTo(parent);
    this.setVisible(true);
}

From source file:gui.MainGUI.java

public void updateFromRobotTeamConfig() {
    try {/*ww w  . j a  v a 2  s. com*/
        RobotConfig currRobot;
        RobotPanel currRobotPanel;

        panelRobotInfo.removeAll();
        panelRobotInfo.setLayout(new BoxLayout(panelRobotInfo, BoxLayout.Y_AXIS));
        for (int i = 0; i < robotTeamConfig.getNumRobots(); i++) {
            currRobot = (RobotConfig) (robotTeamConfig.getRobotTeam().get(i + 1));
            currRobotPanel = new RobotPanel(this, currRobot);
            currRobotPanel.getLabelRole().setText(currRobot.getRole().toString());
            panelRobotInfo.add(currRobotPanel);
        }
        panelRobotInfo.add(Box.createVerticalGlue());

        panelRobotInfo.repaint();
        panelRobotInfo.revalidate();
        explorationImage = new ExplorationImage(simConfig.getEnv());
        explorationImage.redrawEnvAndAgents(this, robotTeamConfig, simConfig);
        labelImageHolder.setIcon(new ImageIcon(explorationImage.getImage()));
        validate();
        updateShowSettings();
        updateShowSettingsAgents();
    } catch (NullPointerException e) {
        System.out.println("Updating from robotTeamConfig: null pointer exception.");
    }
}