Example usage for javax.swing UIManager getIcon

List of usage examples for javax.swing UIManager getIcon

Introduction

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

Prototype

public static Icon getIcon(Object key) 

Source Link

Document

Returns an Icon from the defaults.

Usage

From source file:com.sshtools.appframework.ui.SshToolsApplication.java

public void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
    if (laf != null) {
        log.info("Setting Look and Feel to " + laf.getClassName());
        try {//from   w w  w .  j  av a  2s . co  m
            @SuppressWarnings("unchecked")
            LookAndFeel l = createLookAndFeel((Class<LookAndFeel>) Class.forName(laf.getClassName()));
            UIManager.setLookAndFeel(l);

            Icon checkIcon = UIManager.getIcon("CheckBoxMenuItem.checkIcon");
            Icon radioIcon = UIManager.getIcon("RadioButtonMenuItem.checkIcon");
            UIManager.put("MenuItem.checkIcon", new EmptyIcon(
                    Math.max(checkIcon.getIconWidth(), radioIcon.getIconWidth()), checkIcon.getIconHeight()));
            UIManager.put("Menu.checkIcon", new EmptyIcon(
                    Math.max(checkIcon.getIconWidth(), radioIcon.getIconWidth()), checkIcon.getIconHeight()));

            for (SshToolsApplicationContainer container : containers) {
                container.updateUI();
            }
            for (OptionsTab tab : additionalOptionsTabs) {
                SwingUtilities.updateComponentTreeUI(tab.getTabComponent());
            }

        } catch (Throwable t) {
            /* DEBUG */t.printStackTrace();
        }
    }
}

From source file:com.igormaznitsa.sciareto.ui.MainFrame.java

private void menuOpenProjectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuOpenProjectActionPerformed
    final JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileView(new FileView() {
        private Icon KNOWLEDGE_FOLDER_ICO = null;

        @Override// w w w.  ja  va  2  s  .  c  o m
        public Icon getIcon(final File f) {
            if (f.isDirectory()) {
                final File knowledge = new File(f, ".projectKnowledge");
                if (knowledge.isDirectory()) {
                    if (KNOWLEDGE_FOLDER_ICO == null) {
                        final Icon icon = UIManager.getIcon("FileView.directoryIcon");
                        if (icon != null) {
                            KNOWLEDGE_FOLDER_ICO = new ImageIcon(
                                    UiUtils.makeBadgedRightBottom(UiUtils.iconToImage(fileChooser, icon),
                                            Icons.MMDBADGE.getIcon().getImage()));
                        }
                    }
                    return KNOWLEDGE_FOLDER_ICO;
                } else {
                    return super.getIcon(f);
                }
            } else if (f.isFile() && f.getName().toLowerCase(Locale.ENGLISH).endsWith(".mmd")) {
                return Icons.DOCUMENT.getIcon();
            } else {
                return super.getIcon(f);
            }
        }
    });
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setDialogTitle("Open project folder");

    if (fileChooser.showOpenDialog(Main.getApplicationFrame()) == JFileChooser.APPROVE_OPTION) {
        openProject(fileChooser.getSelectedFile(), false);
    }
}

From source file:ca.phon.ipamap.IpaMap.java

private JXButton getToggleButton(Grid grid, JXCollapsiblePane cp) {
    Action toggleAction = cp.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION);

    // use the collapse/expand icons from the JTree UI
    toggleAction.putValue(JXCollapsiblePane.COLLAPSE_ICON, UIManager.getIcon("Tree.expandedIcon"));
    toggleAction.putValue(JXCollapsiblePane.EXPAND_ICON, UIManager.getIcon("Tree.collapsedIcon"));
    toggleAction.putValue(Action.NAME, grid.getName());

    JXButton btn = new JXButton(toggleAction) {
        @Override/* w  w  w  .jav a 2 s  .  c  o  m*/
        public Insets getInsets() {
            Insets retVal = super.getInsets();

            retVal.top = 0;
            retVal.bottom = 0;

            return retVal;
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(0, 20);
        }

    };

    btn.setHorizontalAlignment(SwingConstants.LEFT);

    btn.setBackgroundPainter(new Painter<JXButton>() {

        @Override
        public void paint(Graphics2D g, JXButton object, int width, int height) {
            MattePainter mp = new MattePainter(UIManager.getColor("Button.background"));
            mp.paint(g, object, width, height);
        }
    });

    btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    btn.setBorderPainted(false);
    btn.setFocusable(false);

    btn.putClientProperty("JComponent.sizeVariant", "small");

    btn.revalidate();

    return btn;
}

From source file:com.sshtools.sshterm.SshTerminalPanel.java

public void open(File f) {
    if (log.isDebugEnabled()) {
        log.debug("Opening connection file " + f);
    }//  w  w w  .jav  a  2 s. com

    // Make sure a connection is not already open
    if (isConnected()) {
        Option optNew = new Option("New", "New create a new terminal", 'n');
        Option optClose = new Option("Close", "Close current connection", 'l');
        Option optCancel = new Option("Cancel", "Cancel the opening of this connection", 'c');
        OptionsDialog dialog = OptionsDialog.createOptionDialog(this,
                new Option[] { optNew, optClose, optCancel },
                "You already have a connection open. Select\n" + "Close to close the current connection, New\n"
                        + "to create a new terminal or Cancel to abort.",
                "Existing connection", optNew, null, UIManager.getIcon("OptionPane.warningIcon"));
        UIUtil.positionComponent(SwingConstants.CENTER, dialog);
        dialog.setVisible(true);

        Option opt = dialog.getSelectedOption();

        if ((opt == null) || (opt == optCancel)) {
            return;
        } else if (opt == optNew) {
            try {
                SshToolsApplicationContainer c = (SshToolsApplicationContainer) application.newContainer();
                SshTerminalPanel term = (SshTerminalPanel) c.getApplicationPanel();
                term.open(f);

                return;
            } catch (SshToolsApplicationException stae) {
                log.error(stae);
            }
        } else {
            closeConnection(true);
        }
    }

    // Save to MRU
    if (getApplication() instanceof SshTerm && (((SshTerm) getApplication()).getMRUModel() != null)) {
        ((SshTerm) getApplication()).getMRUModel().add(f);
    }

    // Make sure its not invalid
    if (f != null) {
        // Create a new connection properties object
        SshToolsConnectionProfile profile = new SshToolsConnectionProfile();

        try {
            // Open the file
            profile.open(f.getAbsolutePath());
            setNeedSave(false);
            setCurrentConnectionFile(f);
            //setContainerTitle(f);

            // Connect with the new details.
            connect(profile, false);
        } catch (InvalidProfileFileException fnfe) {
            showExceptionMessage("Open Connection", fnfe.getMessage());
        } catch (SshException e) {
            e.printStackTrace();
            showExceptionMessage("Open Connection", "An unexpected error occured!");
        }
    } else {
        showExceptionMessage("Open Connection", "Invalid file specified");
    }
}

From source file:hermes.browser.HermesBrowser.java

public void showErrorDialog(final String message, final Throwable t) {
    Runnable r = new Runnable() {
        public void run() {
            String detail = null;

            if (t instanceof PyException) {
                StringBuffer s = new StringBuffer();
                PyException pyT = (PyException) t;
                pyT.traceback.dumpStack(s);

                detail = s.toString();/*from w  w w.j a v  a2 s. c  o m*/
            } else {
                StringWriter s = new StringWriter();
                PrintWriter p = new PrintWriter(s);
                t.printStackTrace(p);
                detail = s.toString();
            }

            JideOptionPane optionPane = new JideOptionPane(message, JOptionPane.ERROR_MESSAGE,
                    JideOptionPane.CLOSE_OPTION, UIManager.getIcon("OptionPane.errorIcon"));
            optionPane.setTitle(message);

            if (detail != null) {
                optionPane.setDetails(detail);
            }
            JDialog dialog = optionPane.createDialog(HermesBrowser.this, "Error");
            dialog.setResizable(true);
            dialog.pack();
            dialog.setVisible(true);
        }
    };

    if (SwingUtilities.isEventDispatchThread()) {
        r.run();
    } else {
        SwingUtilities.invokeLater(r);
    }
}

From source file:ca.phon.ipamap.IpaMap.java

/**
 * Create the context menu based on source component
 *///from w ww.  ja va 2 s.com
public void setupContextMenu(JPopupMenu menu, JComponent comp) {
    final CommonModuleFrame parentFrame = (CommonModuleFrame) SwingUtilities
            .getAncestorOfClass(CommonModuleFrame.class, comp);
    if (parentFrame != null) {
        final PhonUIAction toggleAlwaysOnTopAct = new PhonUIAction(parentFrame, "setAlwaysOnTop",
                !parentFrame.isAlwaysOnTop());
        toggleAlwaysOnTopAct.putValue(PhonUIAction.NAME, "Always on top");
        toggleAlwaysOnTopAct.putValue(PhonUIAction.SELECTED_KEY, parentFrame.isAlwaysOnTop());
        final JCheckBoxMenuItem toggleAlwaysOnTopItem = new JCheckBoxMenuItem(toggleAlwaysOnTopAct);
        menu.add(toggleAlwaysOnTopItem);
    }

    // button options first
    if (comp instanceof CellButton) {
        CellButton btn = (CellButton) comp;
        Cell cell = btn.cell;

        // copy to clipboard options
        String cellData = cell.getText().replaceAll("" + (char) 0x25cc, "");
        PhonUIAction copyToClipboardAct = new PhonUIAction(this, "onCopyToClipboard", cellData);
        copyToClipboardAct.putValue(PhonUIAction.NAME, "Copy character (" + cell.getText() + ")");
        JMenuItem copyToClipboardItem = new JMenuItem(copyToClipboardAct);
        menu.add(copyToClipboardItem);

        String htmlVal = new String();
        for (Character c : cellData.toCharArray()) {
            htmlVal += "&#" + (int) c + ";";
        }
        PhonUIAction copyHTMLToClipboardAct = new PhonUIAction(this, "onCopyToClipboard", htmlVal);
        copyHTMLToClipboardAct.putValue(PhonUIAction.NAME, "Copy as HTML (" + htmlVal + ")");
        JMenuItem copyHTMLToClipboardItem = new JMenuItem(copyHTMLToClipboardAct);
        menu.add(copyHTMLToClipboardItem);

        String hexVal = new String();
        for (Character c : cellData.toCharArray()) {
            hexVal += (hexVal.length() > 0 ? " " : "") + Integer.toHexString((int) c);
        }
        hexVal = hexVal.toUpperCase();
        PhonUIAction copyHEXToClipboardAct = new PhonUIAction(this, "onCopyToClipboard", hexVal);
        copyHEXToClipboardAct.putValue(PhonUIAction.NAME, "Copy as Unicode HEX (" + hexVal + ")");
        JMenuItem copyHEXToClipboardItem = new JMenuItem(copyHEXToClipboardAct);
        menu.add(copyHEXToClipboardItem);

        menu.addSeparator();
        if (isInFavorites(cell)) {
            PhonUIAction removeFromFavAct = new PhonUIAction(this, "onRemoveCellFromFavorites", cell);
            removeFromFavAct.putValue(Action.NAME, "Remove from favorites");
            removeFromFavAct.putValue(Action.SHORT_DESCRIPTION, "Remove button from list of favorites");
            JMenuItem removeFromFavItem = new JMenuItem(removeFromFavAct);
            menu.add(removeFromFavItem);
        } else {
            PhonUIAction addToFavAct = new PhonUIAction(this, "onAddCellToFavorites", cell);
            addToFavAct.putValue(Action.NAME, "Add to favorites");
            addToFavAct.putValue(Action.SHORT_DESCRIPTION, "Add button to list of favorites");
            JMenuItem addToFavItem = new JMenuItem(addToFavAct);
            menu.add(addToFavItem);
        }
        menu.addSeparator();
    }

    // section scroll-tos
    JMenuItem gotoTitleItem = new JMenuItem("Scroll to:");
    gotoTitleItem.setEnabled(false);
    menu.add(gotoTitleItem);

    for (JXButton toggleBtn : toggleButtons) {
        PhonUIAction gotoAct = new PhonUIAction(this, "onGoto", toggleBtn);
        gotoAct.putValue(Action.NAME, toggleBtn.getText());
        gotoAct.putValue(Action.SHORT_DESCRIPTION, "Scroll to " + toggleBtn.getText());
        JMenuItem gotoItem = new JMenuItem(gotoAct);
        menu.add(gotoItem);
    }

    menu.addSeparator();

    // setup font scaler
    final JLabel smallLbl = new JLabel("A");
    smallLbl.setFont(getFont().deriveFont(12.0f));
    smallLbl.setHorizontalAlignment(SwingConstants.CENTER);
    JLabel largeLbl = new JLabel("A");
    largeLbl.setFont(getFont().deriveFont(24.0f));
    largeLbl.setHorizontalAlignment(SwingConstants.CENTER);

    final JSlider scaleSlider = new JSlider(1, 101);
    scaleSlider.setValue((int) (scale * 100));
    scaleSlider.setMajorTickSpacing(20);
    scaleSlider.setMinorTickSpacing(10);
    scaleSlider.setSnapToTicks(true);
    scaleSlider.setPaintTicks(true);
    scaleSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent arg0) {
            int sliderVal = scaleSlider.getValue();

            float scale = (float) sliderVal / (float) 100;

            _cFont = null;

            setSavedScale(scale);
            setScale(scale);

        }
    });

    FormLayout scaleLayout = new FormLayout("3dlu, center:pref, fill:pref:grow, center:pref, 3dlu", "pref");
    CellConstraints cc = new CellConstraints();
    JPanel scalePanel = new JPanel(scaleLayout) {
        @Override
        public Insets getInsets() {
            Insets retVal = super.getInsets();

            retVal.left += UIManager.getIcon("Tree.collapsedIcon").getIconWidth();

            return retVal;
        }
    };
    scalePanel.add(smallLbl, cc.xy(2, 1));
    scalePanel.add(scaleSlider, cc.xy(3, 1));
    scalePanel.add(largeLbl, cc.xy(4, 1));

    JMenuItem scaleItem = new JMenuItem("Font size");
    scaleItem.setEnabled(false);
    menu.add(scaleItem);
    menu.add(scalePanel);

    menu.addSeparator();

    // highlighting
    PhonUIAction onToggleHighlightAct = new PhonUIAction(this, "onToggleHighlightRecent");
    onToggleHighlightAct.putValue(PhonUIAction.NAME, "Highlight recently used");
    onToggleHighlightAct.putValue(PhonUIAction.SELECTED_KEY, isHighlightRecent());
    JCheckBoxMenuItem onToggleHighlightItm = new JCheckBoxMenuItem(onToggleHighlightAct);
    menu.add(onToggleHighlightItm);
}

From source file:net.pms.newgui.NavigationShareTab.java

@Nullable
private static Icon getIcon(@Nullable String baseName, @Nullable String suffix) {
    if (isBlank(baseName)) {
        return null;
    }//from w  ww .j  av a  2 s  .  c  o  m
    ImageIcon icon = isBlank(suffix) ? LooksFrame.readImageIcon(baseName)
            : LooksFrame.readImageIcon(FileUtil.appendToFileName(baseName, suffix));

    return icon == null ? UIManager.getIcon("OptionPane.warningIcon") : icon;
}

From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java

protected Icon convertMessageType(MessageMode messageType) {
    switch (messageType) {
    case CONFIRMATION:
    case CONFIRMATION_HTML:
        return UIManager.getIcon("OptionPane.informationIcon");
    case WARNING:
    case WARNING_HTML:
        return UIManager.getIcon("OptionPane.warningIcon");
    default://ww  w  .  j  a  va 2 s  .c o  m
        return null;
    }
}

From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java

protected Icon convertNotificationType(NotificationType type) {
    switch (type) {
    case ERROR:/* ww  w . j a  v a 2  s  .c o m*/
    case ERROR_HTML:
        return UIManager.getIcon("OptionPane.errorIcon");
    case HUMANIZED:
    case HUMANIZED_HTML:
        return UIManager.getIcon("OptionPane.informationIcon");
    case WARNING:
    case WARNING_HTML:
        return UIManager.getIcon("OptionPane.warningIcon");
    default:
        return null;
    }
}

From source file:org.netbeans.jpa.modeler.jcre.wizard.RevEngWizardDescriptor.java

public static EntityMappings generateJPAModel(ProgressReporter reporter, Set<String> entities, Project project,
        FileObject packageFileObject, String fileName, boolean includeReference, boolean softWrite,
        boolean autoOpen) throws IOException, ProcessInterruptedException {
    int progressIndex = 0;
    String progressMsg = NbBundle.getMessage(RevEngWizardDescriptor.class, "MSG_Progress_JPA_Model_Pre"); //NOI18N;
    reporter.progress(progressMsg, progressIndex++);

    String version = getModelerFileVersion();

    final EntityMappings entityMappingsSpec = EntityMappings.getNewInstance(version);
    entityMappingsSpec.setGenerated();//from   w ww  .  ja v a 2  s. c o m

    if (!entities.isEmpty()) {
        String entity = entities.iterator().next();
        entityMappingsSpec.setPackage(JavaIdentifiers.getPackageName(entity));
    }

    List<String> missingEntities = new ArrayList<>();
    for (String entityClass : entities) {
        progressMsg = NbBundle.getMessage(RevEngWizardDescriptor.class, "MSG_Progress_JPA_Class_Parsing",
                entityClass + ".java");//NOI18N
        reporter.progress(progressMsg, progressIndex++);
        JPAModelGenerator.generateJPAModel(entityMappingsSpec, project, entityClass, packageFileObject,
                missingEntities);
    }

    if (includeReference) {
        List<ManagedClass> classes = new ArrayList<>(entityMappingsSpec.getEntity());
        // manageSiblingAttribute for MappedSuperClass and Embeddable is not required for (DBRE) DB REV ENG CASE
        classes.addAll(entityMappingsSpec.getMappedSuperclass());
        classes.addAll(entityMappingsSpec.getEmbeddable());

        for (ManagedClass<IPersistenceAttributes> managedClass : classes) {
            for (RelationAttribute attribute : new ArrayList<>(
                    managedClass.getAttributes().getRelationAttributes())) {
                String entityClass = StringUtils.isBlank(entityMappingsSpec.getPackage())
                        ? attribute.getTargetEntity()
                        : entityMappingsSpec.getPackage() + '.' + attribute.getTargetEntity();
                if (!entities.contains(entityClass)) {
                    progressMsg = NbBundle.getMessage(RevEngWizardDescriptor.class,
                            "MSG_Progress_JPA_Class_Parsing", entityClass + ".java");//NOI18N
                    reporter.progress(progressMsg, progressIndex++);
                    JPAModelGenerator.generateJPAModel(entityMappingsSpec, project, entityClass,
                            packageFileObject, missingEntities);
                    entities.add(entityClass);
                }
            }
        }
    }

    if (!missingEntities.isEmpty()) {
        final String title, _package;
        StringBuilder message = new StringBuilder();
        if (missingEntities.size() == 1) {
            title = "Conflict detected - Entity not found";
            message.append(JavaSourceParserUtil.simpleClassName(missingEntities.get(0))).append(" Entity is ");
        } else {
            title = "Conflict detected - Entities not found";
            message.append("Entities ").append(missingEntities.stream()
                    .map(e -> JavaSourceParserUtil.simpleClassName(e)).collect(toList())).append(" are ");
        }
        if (StringUtils.isEmpty(entityMappingsSpec.getPackage())) {
            _package = "<default_root_package>";
        } else {
            _package = entityMappingsSpec.getPackage();
        }
        message.append("missing in Project classpath[").append(_package)
                .append("]. \n Would like to cancel the process ?");
        SwingUtilities.invokeLater(() -> {
            JButton cancel = new JButton("Cancel import process (Recommended)");
            JButton procced = new JButton("Procced");
            cancel.addActionListener((ActionEvent e) -> {
                Window w = SwingUtilities.getWindowAncestor(cancel);
                if (w != null) {
                    w.setVisible(false);
                }
                StringBuilder sb = new StringBuilder();
                sb.append('\n').append("You have following option to resolve conflict :").append('\n')
                        .append('\n');
                sb.append(
                        "1- New File > Persistence > JPA Diagram from Reverse Engineering (Manually select entities)")
                        .append('\n');
                sb.append(
                        "2- Recover missing entities manually > Reopen diagram file >  Import entities again");
                NotifyDescriptor nd = new NotifyDescriptor.Message(sb.toString(),
                        NotifyDescriptor.INFORMATION_MESSAGE);
                DialogDisplayer.getDefault().notify(nd);
            });
            procced.addActionListener((ActionEvent e) -> {
                Window w = SwingUtilities.getWindowAncestor(cancel);
                if (w != null) {
                    w.setVisible(false);
                }
                manageEntityMappingspec(entityMappingsSpec);
                JPAModelerUtil.createNewModelerFile(entityMappingsSpec, packageFileObject, fileName, softWrite,
                        autoOpen);
            });

            JOptionPane.showOptionDialog(WindowManager.getDefault().getMainWindow(), message.toString(), title,
                    OK_CANCEL_OPTION, ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon"),
                    new Object[] { cancel, procced }, cancel);
        });

    } else {
        manageEntityMappingspec(entityMappingsSpec);
        JPAModelerUtil.createNewModelerFile(entityMappingsSpec, packageFileObject, fileName, softWrite,
                autoOpen);
        return entityMappingsSpec;
    }

    throw new ProcessInterruptedException();
}