Example usage for javax.swing JLabel setIcon

List of usage examples for javax.swing JLabel setIcon

Introduction

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

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The icon this component will display.")
public void setIcon(Icon icon) 

Source Link

Document

Defines the icon this component will display.

Usage

From source file:org.datacleaner.widgets.OpenAnalysisJobFileChooserAccessory.java

private void showFileInformation() {
    JaxbJobReader reader = new JaxbJobReader(_configuration);

    try {/* w w  w.  j  a  v  a2  s .com*/
        _metadata = reader.readMetadata(_file);
    } catch (Exception e) {
        // metadata could not be produced so we cannot display the file
        // information
        logger.warn("An unexpected error occurred reading metadata from file", e);
        setVisible(false);
        return;
    }

    _centerPanel.removeAll();

    final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    final int separatorHeight = 6;

    final String jobName = _metadata.getJobName();
    if (jobName != null) {
        _centerPanel.add(new JLabel("<html><b>Job name:</b></html>"));
        _centerPanel.add(new JLabel(jobName));
        _centerPanel.add(Box.createVerticalStrut(separatorHeight));
    }
    final String jobDescription = _metadata.getJobDescription();
    if (jobDescription != null) {
        _centerPanel.add(new JLabel("<html><b>Job description:</b></html>"));
        DCLabel descriptionLabel = DCLabel.darkMultiLine(jobDescription);
        descriptionLabel.setMaximumWidth(WIDTH);
        _centerPanel.add(descriptionLabel);
        _centerPanel.add(Box.createVerticalStrut(separatorHeight));
    }
    final String jobVersion = _metadata.getJobVersion();
    if (jobVersion != null) {
        _centerPanel.add(new JLabel("<html><b>Job version:</b></html>"));
        _centerPanel.add(new JLabel(jobVersion));
        _centerPanel.add(Box.createVerticalStrut(separatorHeight));
    }
    final String author = _metadata.getAuthor();
    if (author != null) {
        _centerPanel.add(new JLabel("<html><b>Author:</b></html>"));
        _centerPanel.add(new JLabel(author));
        _centerPanel.add(Box.createVerticalStrut(separatorHeight));
    }
    final Date createdDate = _metadata.getCreatedDate();
    if (createdDate != null) {
        _centerPanel.add(new JLabel("<html><b>Created:</b></html>"));
        _centerPanel.add(new JLabel(dateFormat.format(createdDate)));
        _centerPanel.add(Box.createVerticalStrut(separatorHeight));
    }
    final Date updatedDate = _metadata.getUpdatedDate();
    if (updatedDate != null) {
        _centerPanel.add(new JLabel("<html><b>Updated:</b></html>"));
        _centerPanel.add(new JLabel(dateFormat.format(updatedDate)));
        _centerPanel.add(Box.createVerticalStrut(separatorHeight));
    }

    final String datastoreName = _metadata.getDatastoreName();

    _centerPanel.add(new JLabel("<html><b>Datastore:</b></html>"));
    final JLabel datastoreLabel = new JLabel(datastoreName);

    Datastore datastore = _configuration.getDatastoreCatalog().getDatastore(datastoreName);
    if (datastore == null) {
        _openJobButton.setEnabled(false);
        datastoreLabel.setIcon(imageManager.getImageIcon(IconUtils.STATUS_WARNING, IconUtils.ICON_SIZE_SMALL));
        datastoreLabel.setToolTipText("No such datastore: " + datastoreName);
    } else {
        _openJobButton.setEnabled(true);
        datastoreLabel.setIcon(IconUtils.getDatastoreIcon(datastore, IconUtils.ICON_SIZE_SMALL));
        datastoreLabel.setToolTipText(null);
    }

    _centerPanel.add(datastoreLabel);
    _centerPanel.add(Box.createVerticalStrut(separatorHeight));
    _centerPanel.add(new JLabel("<html><b>Source columns:</b></html>"));
    List<String> paths = _metadata.getSourceColumnPaths();
    for (String path : paths) {
        JLabel columnLabel = new JLabel(path);
        columnLabel.setIcon(imageManager.getImageIcon("images/model/column.png", IconUtils.ICON_SIZE_SMALL));
        _centerPanel.add(columnLabel);
    }

    _centerPanel.updateUI();
    setVisible(true);
}

From source file:org.datacleaner.windows.OpenAnalysisJobAsTemplateDialog.java

@Override
protected JComponent getDialogContent() {
    final DCPanel panel = new DCPanel();

    int row = 0;/*from w w  w  . j av  a2 s  .c  o m*/
    WidgetUtils.addToGridBag(DCLabel.bright("<html><b>Original value:</b></html>"), panel, 1, row);
    WidgetUtils.addToGridBag(DCLabel.bright("<html><b>New/mapped value:</b></html>"), panel, 2, row);

    row++;
    WidgetUtils.addToGridBag(new JLabel(imageManager.getImageIcon(IconUtils.GENERIC_DATASTORE_IMAGEPATH)),
            panel, 0, row);
    WidgetUtils.addToGridBag(DCLabel.bright(_metadata.getDatastoreName()), panel, 1, row,
            GridBagConstraints.WEST);

    DCPanel datastoreButtonPanel = new DCPanel();
    datastoreButtonPanel.setLayout(new HorizontalLayout(0));
    datastoreButtonPanel.add(_datastoreCombobox);
    datastoreButtonPanel.add(Box.createHorizontalStrut(4));
    datastoreButtonPanel.add(_autoMapButton);

    WidgetUtils.addToGridBag(datastoreButtonPanel, panel, 2, row, GridBagConstraints.WEST);

    Set<String> tableNames = _sourceColumnComboBoxes.keySet();
    for (final String tableName : tableNames) {
        row++;
        final JLabel tableLabel = DCLabel.bright("<html><b>" + tableName + "</b></html>");
        tableLabel.setIcon(imageManager.getImageIcon(IconUtils.MODEL_TABLE, IconUtils.ICON_SIZE_SMALL));
        WidgetUtils.addToGridBag(tableLabel, panel, 0, row, 2, 1, GridBagConstraints.WEST);

        final JButton clearButton = WidgetFactory.createDefaultButton("Clear");
        clearButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                List<SourceColumnComboBox> comboBoxes = _sourceColumnComboBoxes.get(tableName);
                for (SourceColumnComboBox comboBox : comboBoxes) {
                    comboBox.setModel(_datastore, false);
                }
            }
        });
        final DCPanel clearButtonPanel = new DCPanel();
        clearButtonPanel.add(clearButton);
        WidgetUtils.addToGridBag(clearButtonPanel, panel, 2, row, GridBagConstraints.CENTER);

        final List<SourceColumnComboBox> comboBoxes = _sourceColumnComboBoxes.get(tableName);
        for (SourceColumnComboBox comboBox : comboBoxes) {
            row++;
            WidgetUtils.addToGridBag(
                    new JLabel(imageManager.getImageIcon(IconUtils.MODEL_COLUMN, IconUtils.ICON_SIZE_SMALL)),
                    panel, 0, row);
            WidgetUtils.addToGridBag(DCLabel.bright(comboBox.getName()), panel, 1, row,
                    GridBagConstraints.WEST);
            WidgetUtils.addToGridBag(comboBox, panel, 2, row, GridBagConstraints.WEST);
        }
    }
    row++;

    if (!_variableTextFields.isEmpty()) {
        final JLabel tableLabel = DCLabel.bright("<html><b>Job-level variables</b></html>");
        tableLabel.setIcon(imageManager.getImageIcon(IconUtils.MODEL_JOB, IconUtils.ICON_SIZE_SMALL));
        WidgetUtils.addToGridBag(tableLabel, panel, 0, row, 2, 1, GridBagConstraints.WEST);

        for (Entry<String, JXTextField> entry : _variableTextFields.entrySet()) {
            row++;
            String variableId = entry.getKey();
            JXTextField textField = entry.getValue();

            WidgetUtils.addToGridBag(
                    new JLabel(
                            imageManager.getImageIcon("images/model/variable.png", IconUtils.ICON_SIZE_SMALL)),
                    panel, 0, row);
            WidgetUtils.addToGridBag(DCLabel.bright(variableId), panel, 1, row, GridBagConstraints.WEST);
            WidgetUtils.addToGridBag(textField, panel, 2, row, GridBagConstraints.WEST);
        }
        row++;
    }

    final DCPanel openButtonPanel = new DCPanel();
    openButtonPanel.add(_openButton);
    WidgetUtils.addToGridBag(openButtonPanel, panel, 2, row, GridBagConstraints.EAST);

    return WidgetUtils.scrolleable(panel);
}

From source file:org.drugis.addis.gui.WelcomeDialog.java

private JLabel createImageLabel(String imageHeader) {
    JLabel label = new JLabel();
    label.setIcon(Main.IMAGELOADER.getIcon(imageHeader));
    return label;
}

From source file:org.eclipse.om2m.ipe.sample.gui.GUI.java

/**
 * Sets the LampIcon to ON or OFF depending on the newState
 * @param appId - The LAMP AppId//from   ww w .  j a  va2  s  .c om
 * @param newState - The new LAMP State
 */
public static void setLabel(String appId, boolean newState) {
    JLabel label = new JLabel("");
    if ("LABEL_LAMP_0".endsWith(appId)) {
        label = LABEL_LAMP_0;
    }
    if ("LABEL_LAMP_1".endsWith(appId)) {
        label = LABEL_LAMP_1;
    }
    if (newState) {
        label.setIcon(iconLampON);
    } else {
        label.setIcon(iconLampOFF);
    }
}

From source file:org.eobjects.datacleaner.windows.OpenAnalysisJobAsTemplateDialog.java

@Override
protected JComponent getDialogContent() {
    final DCPanel panel = new DCPanel();

    int row = 0;/*from   www .  j av  a2s  .c  om*/
    WidgetUtils.addToGridBag(DCLabel.bright("<html><b>Original value:</b></html>"), panel, 1, row);
    WidgetUtils.addToGridBag(DCLabel.bright("<html><b>New/mapped value:</b></html>"), panel, 2, row);

    row++;
    WidgetUtils.addToGridBag(new JLabel(imageManager.getImageIcon("images/model/datastore.png")), panel, 0,
            row);
    WidgetUtils.addToGridBag(DCLabel.bright(_metadata.getDatastoreName()), panel, 1, row,
            GridBagConstraints.WEST);

    DCPanel datastoreButtonPanel = new DCPanel();
    datastoreButtonPanel.setLayout(new HorizontalLayout(0));
    datastoreButtonPanel.add(_datastoreCombobox);
    datastoreButtonPanel.add(Box.createHorizontalStrut(4));
    datastoreButtonPanel.add(_autoMapButton);

    WidgetUtils.addToGridBag(datastoreButtonPanel, panel, 2, row, GridBagConstraints.WEST);

    Set<String> tableNames = _sourceColumnComboBoxes.keySet();
    for (final String tableName : tableNames) {
        row++;
        final JLabel tableLabel = DCLabel.bright("<html><b>" + tableName + "</b></html>");
        tableLabel.setIcon(imageManager.getImageIcon("images/model/table.png", IconUtils.ICON_SIZE_SMALL));
        WidgetUtils.addToGridBag(tableLabel, panel, 0, row, 2, 1, GridBagConstraints.WEST);

        final JButton clearButton = new JButton("Clear");
        clearButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                List<SourceColumnComboBox> comboBoxes = _sourceColumnComboBoxes.get(tableName);
                for (SourceColumnComboBox comboBox : comboBoxes) {
                    comboBox.setModel(_datastore, false);
                }
            }
        });
        final DCPanel clearButtonPanel = new DCPanel();
        clearButtonPanel.add(clearButton);
        WidgetUtils.addToGridBag(clearButtonPanel, panel, 2, row, GridBagConstraints.CENTER);

        final List<SourceColumnComboBox> comboBoxes = _sourceColumnComboBoxes.get(tableName);
        for (SourceColumnComboBox comboBox : comboBoxes) {
            row++;
            WidgetUtils.addToGridBag(
                    new JLabel(imageManager.getImageIcon("images/model/column.png", IconUtils.ICON_SIZE_SMALL)),
                    panel, 0, row);
            WidgetUtils.addToGridBag(DCLabel.bright(comboBox.getName()), panel, 1, row,
                    GridBagConstraints.WEST);
            WidgetUtils.addToGridBag(comboBox, panel, 2, row, GridBagConstraints.WEST);
        }
    }
    row++;

    if (!_variableTextFields.isEmpty()) {
        final JLabel tableLabel = DCLabel.bright("<html><b>Job-level variables</b></html>");
        tableLabel.setIcon(
                imageManager.getImageIcon("images/filetypes/analysis_job.png", IconUtils.ICON_SIZE_SMALL));
        WidgetUtils.addToGridBag(tableLabel, panel, 0, row, 2, 1, GridBagConstraints.WEST);

        for (Entry<String, JXTextField> entry : _variableTextFields.entrySet()) {
            row++;
            String variableId = entry.getKey();
            JXTextField textField = entry.getValue();

            WidgetUtils.addToGridBag(
                    new JLabel(
                            imageManager.getImageIcon("images/model/variable.png", IconUtils.ICON_SIZE_SMALL)),
                    panel, 0, row);
            WidgetUtils.addToGridBag(DCLabel.bright(variableId), panel, 1, row, GridBagConstraints.WEST);
            WidgetUtils.addToGridBag(textField, panel, 2, row, GridBagConstraints.WEST);
        }
        row++;
    }

    final DCPanel openButtonPanel = new DCPanel();
    openButtonPanel.add(_openButton);
    WidgetUtils.addToGridBag(openButtonPanel, panel, 2, row, GridBagConstraints.EAST);

    return WidgetUtils.scrolleable(panel);
}

From source file:org.formic.wizard.step.gui.RequirementsValidationStep.java

/**
 * {@inheritDoc}/*from  w  ww. j  av  a 2  s.  co m*/
 * @see org.formic.wizard.WizardStep#displayed()
 */
public void displayed() {
    form.showInfoMessage(null);
    requirementInfo.setText(null);
    retryButton.setEnabled(false);

    setBusy(true);
    try {
        Integer result = (Integer) Worker.post(new Task() {
            public Object run() throws Exception {
                Integer result = OK;
                TableModel model = table.getModel();
                for (int ii = 0; ii < model.getRowCount(); ii++) {
                    final JLabel label = (JLabel) model.getValueAt(ii, 1);
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            label.setIcon(busyIcon);
                            busyIcon.setImageObserver(table);
                            table.revalidate();
                            table.repaint();
                        }
                    });
                    Requirement requirement = (Requirement) model.getValueAt(ii, 0);
                    final RequirementProvider.Status status = provider.validate(requirement);
                    requirement.setStatus(status);
                    if (status.getCode() == RequirementProvider.FAIL) {
                        result = FAIL;
                    } else if (OK.equals(result) && status.getCode() == RequirementProvider.WARN) {
                        result = WARN;
                    }

                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            switch (status.getCode()) {
                            case RequirementProvider.OK:
                                label.setIcon(okIcon);
                                break;
                            case RequirementProvider.WARN:
                                label.setIcon(warnIcon);
                                break;
                            default:
                                label.setIcon(failedIcon);
                            }
                            table.revalidate();
                            table.repaint();
                        }
                    });
                }
                return result;
            }
        });
        if (FAIL.equals(result)) {
            form.showErrorMessage(Installer.getString("requirements.message.failed"));
        } else if (WARN.equals(result)) {
            form.showWarningMessage(Installer.getString("requirements.message.warning"));
        } else {
            form.showInfoMessage(Installer.getString("requirements.message.ok"));
        }
        boolean valid = !result.equals(FAIL);
        setValid(valid);
        retryButton.setVisible(retryButton.isVisible() || !valid);
        retryButton.setEnabled(!valid);
    } catch (Exception e) {
        GuiDialogs.showError(e);
        setValid(false);
    } finally {
        setBusy(false);
    }
}

From source file:org.isatools.gui.datamanager.exportisa.ExportISAGUI.java

private JPanel createSouthPanel() {
    JPanel southPanel = new JPanel(new BorderLayout());
    southPanel.setOpaque(false);// w ww  .j a  va  2s.c  o  m

    errorDisplay = new JLabel(warningIcon);
    UIHelper.renderComponent(errorDisplay, UIHelper.VER_11_BOLD, UIHelper.LIGHT_GREY_COLOR, false);
    errorDisplay.setVisible(false);

    southPanel.add(UIHelper.wrapComponentInPanel(errorDisplay), BorderLayout.NORTH);

    southPanel.add(createBackToMainMenuButton(), BorderLayout.WEST);

    final JLabel exportISAButton = new JLabel(exportISAIcon);
    exportISAButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent mouseEvent) {
            exportISAButton.setIcon(exportISAIcon);

            if (!selectedOutputFolderExists() && !exportToRepository()) {
                localDirectoryLocation.setBackgroundToError();
            } else {
                if (studyAvailabilityTree.getCheckedStudies(studyAvailabilityTree.getRoot()).size() == 0) {
                    errorDisplay.setText("<html>please select <i>at least one study</i> to export!</html>");
                    errorDisplay.setVisible(true);
                } else {
                    errorDisplay.setVisible(false);
                    firePropertyChange("doISATabExport", "", "doExport");
                }
            }
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            exportISAButton.setIcon(exportISAIcon);
        }

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            exportISAButton.setIcon(exportISAIconOver);
        }
    });

    southPanel.add(exportISAButton, BorderLayout.EAST);

    return southPanel;
}

From source file:org.isatools.gui.datamanager.studyaccess.StudyAccessionGUI.java

private JPanel createStudySelectionPanel() {

    JPanel container = new JPanel();
    container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS));
    container.setOpaque(false);/* w w w .j a  v a  2 s  . c o  m*/

    JPanel studyAccessionSelector = new JPanel();
    studyAccessionSelector.setLayout(new BorderLayout());
    studyAccessionSelector.setOpaque(false);

    JLabel information = new JLabel(unloadStudyHeader);
    information.setHorizontalAlignment(SwingConstants.RIGHT);
    information.setVerticalAlignment(SwingConstants.TOP);

    studyAccessionSelector.add(information, BorderLayout.NORTH);

    retrieveAndProcessStudyInformation();

    JScrollPane treeScroller = new JScrollPane(studyAvailabilityTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    treeScroller.getViewport().setOpaque(false);
    treeScroller.setOpaque(false);
    treeScroller.setBorder(new EmptyBorder(1, 1, 1, 1));

    treeScroller.setPreferredSize(new Dimension(380, 210));

    studyAccessionSelector.add(treeScroller);

    container.add(studyAccessionSelector);

    // and need a convert button!
    JPanel buttonCont = new JPanel(new BorderLayout());
    buttonCont.setOpaque(false);

    final JLabel unload = new JLabel(this.unloadButton, JLabel.RIGHT);

    unload.addMouseListener(new MouseAdapter() {

        public void mouseEntered(MouseEvent mouseEvent) {
            unload.setIcon(unloadButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            unload.setIcon(StudyAccessionGUI.this.unloadButton);
        }

        public void mousePressed(MouseEvent mouseEvent) {
            Set<String> studiesToUnload = studyAvailabilityTree
                    .getCheckedStudies(studyAvailabilityTree.getRoot());
            log.info("going to unload: ");
            for (String acc : studiesToUnload) {
                log.info("study with acc " + acc);
            }
            doUnloading(studiesToUnload);
        }

    });
    buttonCont.add(unload, BorderLayout.EAST);

    buttonCont.add(createBackToMainMenuButton(), BorderLayout.WEST);

    container.add(buttonCont);

    return container;
}

From source file:org.isatools.isacreator.filechooser.FileChooserUI.java

/**
 * Creates the FileSelection panel containing the list of selected files, and the toolbar to modify the list
 *
 * @return JPanel containing a selection pane
 *//* w  w  w.  j  av a 2 s. c om*/
private JPanel createFilesSelectedPanel() {
    JPanel selectionContainer = new JPanel(new BorderLayout());
    selectionContainer.setBackground(UIHelper.BG_COLOR);
    selectionContainer.setBorder(
            new TitledBorder(UIHelper.GREEN_ROUNDED_BORDER, "selection(s)", TitledBorder.DEFAULT_JUSTIFICATION,
                    TitledBorder.DEFAULT_POSITION, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR));

    selectedFiles = new DirectoryFileList();
    listModel = (DefaultListModel) selectedFiles.getModel();

    selectedFiles.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    selectedFiles.setDragEnabled(false);

    JScrollPane selectedFileScroller = new JScrollPane(selectedFiles, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    selectedFileScroller.setPreferredSize(new Dimension(200, 175));
    selectedFileScroller.setBorder(new EmptyBorder(0, 0, 0, 0));

    IAppWidgetFactory.makeIAppScrollPane(selectedFileScroller);

    selectionContainer.add(selectedFileScroller, BorderLayout.CENTER);

    // add list modification toolbar to sort, move, and delete files from the list.
    JPanel optionsPanel = new JPanel();
    optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.LINE_AXIS));
    optionsPanel.setBackground(UIHelper.BG_COLOR);

    final JLabel moveDown = new JLabel(downIcon);
    moveDown.setOpaque(false);
    moveDown.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent event) {
            moveDown.setIcon(downIcon);

            if (!selectedFiles.isSelectionEmpty()) {
                int toMoveDown = selectedFiles.getSelectedIndex();

                if (toMoveDown != (listModel.getSize() - 1)) {
                    swapElements(toMoveDown, toMoveDown + 1);
                }
            }
        }

        public void mouseEntered(MouseEvent event) {
            moveDown.setIcon(downIconOver);
        }

        public void mouseExited(MouseEvent event) {
            moveDown.setIcon(downIcon);
        }
    });

    optionsPanel.add(moveDown);
    optionsPanel.add(Box.createHorizontalStrut(5));

    final JLabel moveUp = new JLabel(upIcon);
    moveUp.setOpaque(false);
    moveUp.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent event) {
            moveUp.setIcon(upIcon);

            if (!selectedFiles.isSelectionEmpty()) {
                int toMoveUp = selectedFiles.getSelectedIndex();

                if (toMoveUp != 0) {
                    swapElements(toMoveUp, toMoveUp - 1);
                }
            }
        }

        public void mouseEntered(MouseEvent event) {
            moveUp.setIcon(upIconOver);
        }

        public void mouseExited(MouseEvent event) {
            moveUp.setIcon(upIcon);
        }
    });

    optionsPanel.add(moveUp);
    optionsPanel.add(Box.createHorizontalStrut(5));

    final JLabel deleteItem = new JLabel(deleteIcon);
    deleteItem.setOpaque(false);
    deleteItem.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent event) {
            deleteItem.setIcon(deleteIcon);

            if (selectedFiles.getSelectedValues() != null) {
                for (Object o : selectedFiles.getSelectedValues()) {
                    listModel.removeElement(o);
                }
            }
        }

        public void mouseEntered(MouseEvent event) {
            deleteItem.setIcon(deleteIconOver);
        }

        public void mouseExited(MouseEvent event) {
            deleteItem.setIcon(deleteIcon);
        }
    });

    optionsPanel.add(deleteItem);
    optionsPanel.add(Box.createHorizontalStrut(5));

    final JLabel sortAsc = new JLabel(sortAscIcon);
    sortAsc.setOpaque(false);
    sortAsc.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent event) {
            sortAsc.setIcon(sortAscIcon);
            if (listModel.getSize() > 0) {
                sort(true);
            }
        }

        public void mouseEntered(MouseEvent event) {
            sortAsc.setIcon(sortAscIconOver);
        }

        public void mouseExited(MouseEvent event) {
            sortAsc.setIcon(sortAscIcon);
        }
    });

    optionsPanel.add(sortAsc);
    optionsPanel.add(Box.createHorizontalStrut(5));

    final JLabel sortDesc = new JLabel(sortDescIcon);
    sortDesc.setOpaque(false);
    sortDesc.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent event) {
            sortDesc.setIcon(sortDescIcon);
            if (listModel.getSize() > 0) {
                sort(false);
            }
        }

        public void mouseEntered(MouseEvent event) {
            sortDesc.setIcon(sortDescIconOver);
        }

        public void mouseExited(MouseEvent event) {
            sortDesc.setIcon(sortDescIcon);
        }
    });

    optionsPanel.add(sortDesc);
    optionsPanel.add(Box.createHorizontalStrut(5));

    selectionContainer.add(optionsPanel, BorderLayout.SOUTH);

    return selectionContainer;
}

From source file:org.isatools.isacreator.filechooser.FileChooserUI.java

/**
 * Create the Navigation Tree panel/*from   w  ww  .j a v  a2  s.  c o m*/
 *
 * @return @see JPanel containing the navigation tree to browse a file system.
 */
private JPanel createNavTree() {
    JPanel treeContainer = new JPanel(new BorderLayout());
    treeContainer.setBackground(UIHelper.BG_COLOR);
    treeContainer
            .setBorder(new TitledBorder(UIHelper.GREEN_ROUNDED_BORDER, "", TitledBorder.DEFAULT_JUSTIFICATION,
                    TitledBorder.DEFAULT_POSITION, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR));

    JPanel navigationControls = new JPanel();
    navigationControls.setLayout(new BoxLayout(navigationControls, BoxLayout.LINE_AXIS));
    navigationControls.setOpaque(false);

    final JLabel navToParentDir = new JLabel(upIcon);
    navToParentDir.setOpaque(false);
    navToParentDir.addMouseListener(new CommonMouseAdapter() {

        public void mousePressed(MouseEvent event) {
            super.mousePressed(event);
            navToParentDir.setIcon(upIcon);
            try {
                updateTree(fileBrowser.getParentDirectory());
            } catch (IOException e) {
                errorAction("problem occurred!");
            }
        }

        public void mouseEntered(MouseEvent event) {
            super.mouseEntered(event);
            navToParentDir.setIcon(upIconOver);
        }

        public void mouseExited(MouseEvent event) {
            super.mouseExited(event);
            navToParentDir.setIcon(upIcon);
        }
    });

    navigationControls.add(navToParentDir);
    navigationControls.add(Box.createHorizontalStrut(5));

    final JLabel navToHomeDir = new JLabel(homeIcon);
    navToHomeDir.setOpaque(false);
    navToHomeDir.addMouseListener(new CommonMouseAdapter() {

        public void mousePressed(MouseEvent event) {
            super.mousePressed(event);
            navToHomeDir.setIcon(homeIcon);
            try {
                updateTree(fileBrowser.getHomeDirectory());

            } catch (IOException e) {
                if (e instanceof ConnectionException) {
                    status.setText("<html>status: not connected!</html>");
                }
                FileBrowserTreeNode defaultFTPNode = new FileBrowserTreeNode("problem occurred!", false,
                        FileBrowserTreeNode.DIRECTORY);
                updateTree(defaultFTPNode);
            }
        }

        public void mouseEntered(MouseEvent event) {
            super.mouseEntered(event);
            navToHomeDir.setIcon(homeIconOver);
        }

        public void mouseExited(MouseEvent event) {
            super.mouseExited(event);
            navToHomeDir.setIcon(homeIcon);
        }
    });

    navigationControls.add(navToHomeDir);
    navigationControls.add(Box.createGlue());

    treeContainer.add(navigationControls, BorderLayout.NORTH);

    try {
        treeModel = new DefaultTreeModel(fileBrowser.getHomeDirectory());
        directoryTree = new JTree(treeModel);
        directoryTree.setFont(UIHelper.VER_11_PLAIN);
        directoryTree.setCellRenderer(new FileSystemTreeCellRenderer());
    } catch (IOException e) {
        FileBrowserTreeNode defaultFTPNode = new FileBrowserTreeNode("problem occurred!", false,
                FileBrowserTreeNode.DIRECTORY);
        updateTree(defaultFTPNode);
    }

    directoryTree.addMouseListener(new CommonMouseAdapter() {

        public void mousePressed(MouseEvent event) {
            super.mousePressed(event);
            int selRow = directoryTree.getRowForLocation(event.getX(), event.getY());

            TreePath selPath = directoryTree.getPathForLocation(event.getX(), event.getY());

            if (selRow != -1) {
                final FileBrowserTreeNode node = (FileBrowserTreeNode) selPath.getLastPathComponent();

                if (SwingUtilities.isLeftMouseButton(event)) {

                    if (event.getClickCount() == 2) {
                        if ((node.getType() == FileBrowserTreeNode.DIRECTORY) && (node.getLevel() != 0)) {

                            String newPath;
                            if (fileBrowser instanceof LocalBrowser) {
                                newPath = ((File) fileBrowser.getDirFiles().get(node.toString())).getPath();
                            } else {
                                newPath = node.toString();
                            }
                            updateTree(fileBrowser.changeDirectory(newPath));
                        }

                        // else, if a leaf node, then add file to to list
                        if (node.isLeaf() && (node.getType() != FileBrowserTreeNode.DIRECTORY)) {
                            String extension = node.toString().substring(node.toString().lastIndexOf(".") + 1)
                                    .trim().toUpperCase();

                            FileChooserFile toAdd = null;

                            for (Object o : fileBrowser.getFileMap().get(extension)) {
                                String fileName;
                                String filePath;
                                if (fileBrowser instanceof LocalBrowser) {
                                    File file = (File) o;
                                    fileName = file.getName();
                                    filePath = file.getPath();

                                    if (fileName.equals(node.toString())) {
                                        toAdd = new CustomFile(filePath);
                                        break;
                                    }
                                } else {
                                    FTPFile ftpFile = (FTPFile) o;
                                    fileName = ftpFile.getName();
                                    filePath = fileBrowser.getAbsoluteWorkingDirectory() + File.separator
                                            + ftpFile.getName();

                                    if (fileName.equals(node.toString())) {
                                        toAdd = new CustomFTPFile(ftpFile, filePath);
                                        break;
                                    }
                                }

                            }

                            if (toAdd != null && !checkIfInList(toAdd)) {
                                selectedFiles.addFileItem(toAdd);
                            }
                        }
                    }
                } else {
                    if ((node.getType() == FileBrowserTreeNode.DIRECTORY) && (node.getLevel() != 0)) {

                        // show popup to add the directory to the selected files
                        JPopupMenu popup = new JPopupMenu();

                        JMenuItem addDirectory = new JMenuItem("add directory");
                        addDirectory.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent ae) {

                                Object fileToAdd = fileBrowser.getDirFiles().get(node.toString());
                                FileChooserFile toAdd;

                                if (fileToAdd instanceof File) {
                                    toAdd = new CustomFile(((File) fileToAdd).getPath());
                                } else {
                                    FTPFile ftpFile = (FTPFile) fileToAdd;
                                    String filePath = fileBrowser.getAbsoluteWorkingDirectory() + File.separator
                                            + ftpFile.getName();

                                    toAdd = new CustomFTPFile(ftpFile, filePath);
                                }

                                if (!checkIfInList(toAdd)) {
                                    selectedFiles.addDirectoryItem(toAdd);
                                }
                            }
                        });

                        popup.add(addDirectory);
                        popup.show(directoryTree, event.getX(), event.getY());
                    }
                }
            }
        }

    });

    BasicTreeUI ui = new BasicTreeUI() {
        public Icon getCollapsedIcon() {
            return null;
        }

        public Icon getExpandedIcon() {
            return null;
        }
    };

    directoryTree.setUI(ui);
    directoryTree.setFont(UIHelper.VER_12_PLAIN);

    JScrollPane treeScroll = new JScrollPane(directoryTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    treeScroll.setPreferredSize(new Dimension(300, 200));
    treeScroll.setBorder(new EmptyBorder(0, 0, 0, 0));
    treeContainer.add(treeScroll, BorderLayout.CENTER);

    IAppWidgetFactory.makeIAppScrollPane(treeScroll);

    return treeContainer;
}