Example usage for javax.swing AbstractButton getIcon

List of usage examples for javax.swing AbstractButton getIcon

Introduction

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

Prototype

public Icon getIcon() 

Source Link

Document

Returns the default icon.

Usage

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JToggleButton("Press Me");
    jb.setSelected(true);//from www. j a  v a 2 s. c  o m
    System.out.println(jb.getIcon());

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(jb);
    f.pack();
    f.setVisible(true);
}

From source file:MainClass.java

public Transferable createTransferable(JComponent comp) {
    image = null;/* w  w w  .  j  a v  a 2s.c  o m*/

    if (comp instanceof JLabel) {
        JLabel label = (JLabel) comp;
        Icon icon = label.getIcon();
        if (icon instanceof ImageIcon) {
            image = ((ImageIcon) icon).getImage();
            return this;
        }
    } else if (comp instanceof AbstractButton) {
        AbstractButton button = (AbstractButton) comp;
        Icon icon = button.getIcon();
        if (icon instanceof ImageIcon) {
            image = ((ImageIcon) icon).getImage();
            return this;
        }
    }
    return null;
}

From source file:ImageSelection.java

public Transferable createTransferable(JComponent comp) {
    // Clear//from ww w .j  a  v a2  s .co m
    image = null;

    if (comp instanceof JLabel) {
        JLabel label = (JLabel) comp;
        Icon icon = label.getIcon();
        if (icon instanceof ImageIcon) {
            image = ((ImageIcon) icon).getImage();
            return this;
        }
    } else if (comp instanceof AbstractButton) {
        AbstractButton button = (AbstractButton) comp;
        Icon icon = button.getIcon();
        if (icon instanceof ImageIcon) {
            image = ((ImageIcon) icon).getImage();
            return this;
        }
    }
    return null;
}

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

/**
 *
 * @param configuration/*from www  .  ja  v a2  s  . c o  m*/
 * @param job
 *            either this or result must be available
 * @param result
 *            either this or job must be available
 * @param jobFilename
 * @param windowContext
 * @param userPreferences
 * @param rendererFactory
 */
@Inject
protected ResultWindow(DataCleanerConfiguration configuration, @Nullable AnalysisJob job,
        @Nullable AnalysisResult result, @Nullable @JobFile FileObject jobFilename, WindowContext windowContext,
        UserPreferences userPreferences, RendererFactory rendererFactory) {
    super(windowContext);
    final boolean running = (result == null);

    _resultPanels = new IdentityHashMap<>();
    _configuration = configuration;
    _job = job;
    _jobFilename = jobFilename;
    _userPreferences = userPreferences;
    _rendererFactory = rendererFactory;

    final Ref<AnalysisResult> resultRef = new Ref<AnalysisResult>() {
        @Override
        public AnalysisResult get() {
            return getResult();
        }
    };

    Border buttonBorder = new CompoundBorder(WidgetUtils.BORDER_LIST_ITEM_SUBTLE,
            new EmptyBorder(10, 4, 10, 4));
    _cancelButton = WidgetFactory.createDefaultButton("Cancel job", IconUtils.ACTION_STOP);
    _cancelButton.setHorizontalAlignment(SwingConstants.LEFT);
    _cancelButton.setBorder(buttonBorder);

    _saveResultsPopupButton = WidgetFactory.createDefaultPopupButton("Save results",
            IconUtils.ACTION_SAVE_DARK);
    _saveResultsPopupButton.setHorizontalAlignment(SwingConstants.LEFT);
    _saveResultsPopupButton.setBorder(buttonBorder);
    _saveResultsPopupButton.setMenuPosition(MenuPosition.TOP);
    _saveResultsPopupButton.getMenu().setBorder(new MatteBorder(1, 0, 0, 1, WidgetUtils.BG_COLOR_MEDIUM));

    JMenuItem saveAsFileItem = WidgetFactory.createMenuItem("Save as result file", IconUtils.ACTION_SAVE_DARK);
    saveAsFileItem.addActionListener(new SaveAnalysisResultActionListener(resultRef, _userPreferences));
    saveAsFileItem.setBorder(buttonBorder);
    _saveResultsPopupButton.getMenu().add(saveAsFileItem);

    JMenuItem exportToHtmlItem = WidgetFactory.createMenuItem("Export to HTML", IconUtils.WEBSITE);
    exportToHtmlItem.addActionListener(
            new ExportResultToHtmlActionListener(resultRef, _configuration, _userPreferences));
    exportToHtmlItem.setBorder(buttonBorder);
    _saveResultsPopupButton.getMenu().add(exportToHtmlItem);

    JMenuItem publishToServerItem = WidgetFactory.createMenuItem("Publish to server",
            IconUtils.MENU_DQ_MONITOR);
    publishToServerItem.addActionListener(new PublishResultToMonitorActionListener(getWindowContext(),
            _userPreferences, resultRef, _jobFilename));
    publishToServerItem.setBorder(buttonBorder);
    _saveResultsPopupButton.getMenu().add(publishToServerItem);

    _tabbedPane = new VerticalTabbedPane() {
        private static final long serialVersionUID = 1L;

        @Override
        protected JComponent wrapInCollapsiblePane(final JComponent originalPanel) {
            DCPanel buttonPanel = new DCPanel();
            buttonPanel.setLayout(new VerticalLayout());
            buttonPanel.setBorder(new MatteBorder(1, 0, 0, 0, WidgetUtils.BG_COLOR_MEDIUM));

            buttonPanel.add(_saveResultsPopupButton);
            buttonPanel.add(_cancelButton);

            DCPanel wrappedPanel = new DCPanel();
            wrappedPanel.setLayout(new BorderLayout());
            wrappedPanel.add(originalPanel, BorderLayout.CENTER);
            wrappedPanel.add(buttonPanel, BorderLayout.SOUTH);
            return super.wrapInCollapsiblePane(wrappedPanel);
        }
    };

    final Dimension size = getDefaultWindowSize();
    _windowSizePreference = new WindowSizePreferences(_userPreferences, getClass(), size.width, size.height);
    _progressInformationPanel = new ProgressInformationPanel(running);
    _tabbedPane.addTab("Progress information",
            imageManager.getImageIcon("images/model/progress_information.png", IconUtils.ICON_SIZE_TAB),
            _progressInformationPanel);

    for (Func<ResultWindow, JComponent> pluggableComponent : PLUGGABLE_BANNER_COMPONENTS) {
        JComponent component = pluggableComponent.eval(this);
        if (component != null) {
            if (component instanceof AbstractButton) {
                AbstractButton button = (AbstractButton) component;
                JMenuItem menuItem = WidgetFactory.createMenuItem(button.getText(), button.getIcon());
                for (ActionListener listener : button.getActionListeners()) {
                    menuItem.addActionListener(listener);
                }
                menuItem.setBorder(buttonBorder);
                _saveResultsPopupButton.getMenu().add(menuItem);
            } else if (component instanceof JMenuItem) { // TODO: Not possible. JMenuItem is a subclass of AbstractButton. Reorder or remove?
                JMenuItem menuItem = (JMenuItem) component;
                menuItem.setBorder(buttonBorder);
                _saveResultsPopupButton.getMenu().add(menuItem);
            }
        }
    }

    if (running) {
        // run the job in a swing worker
        _result = null;
        _worker = new AnalysisRunnerSwingWorker(_configuration, _job, this);

        _cancelButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                _worker.cancelIfRunning();
            }
        });
    } else {
        // don't add the progress information, simply render the job asap
        _result = result;
        _worker = null;

        final Map<ComponentJob, AnalyzerResult> map = result.getResultMap();
        for (Entry<ComponentJob, AnalyzerResult> entry : map.entrySet()) {
            final ComponentJob componentJob = entry.getKey();
            final AnalyzerResult analyzerResult = entry.getValue();

            addResult(componentJob, analyzerResult);
        }
        _progressInformationPanel.onSuccess();

        WidgetUtils.invokeSwingAction(new Runnable() {
            @Override
            public void run() {
                if (_tabbedPane.getTabCount() > 1) {
                    // switch to the first available result panel
                    _tabbedPane.setSelectedIndex(1);
                }
            }
        });
    }

    updateButtonVisibility(running);
}

From source file:org.pentaho.ui.xul.swing.tags.SwingButton.java

@Override
public void layout() {
    // check type to see if it's a toggleButton
    if (type == Type.CHECKBOX || type == Type.RADIO) {
        final AbstractButton oldButton = getButton();

        final AbstractButton button = new JToggleButton();
        button.setText(oldButton.getText());
        button.setIcon(oldButton.getIcon());
        button.setEnabled(oldButton.isEnabled());
        button.setSelected(this.selected);
        setButton(button);/*from   w  ww .  j  ava 2  s  .  com*/

        if (this.getOnclick() != null) {
            this.setOnclick(this.getOnclick());
        }
    }
    final AbstractButton button = getButton();
    // adjust orientation of label and icon
    if (this.orientation == Orient.VERTICAL) {
        button.setHorizontalTextPosition(JButton.CENTER);
        if (this.dir == Direction.FORWARD) {
            button.setVerticalTextPosition(JButton.BOTTOM);
        } else {
            button.setVerticalTextPosition(JButton.TOP);
        }
    } else {
        button.setVerticalTextPosition(JButton.CENTER);
        if (this.dir == Direction.FORWARD) {
            button.setHorizontalTextPosition(JButton.RIGHT);
        } else {
            button.setHorizontalTextPosition(JButton.LEFT);
        }
    }

    // Square button patch. if no label and icon is square, set min/max to square up button
    final Icon icon = button.getIcon();
    if ("".equals(button.getText()) && icon != null && icon.getIconHeight() == icon.getIconWidth()) {
        Dimension dim = button.getPreferredSize();
        button.setMinimumSize(new Dimension(dim.height, dim.height));
        button.setPreferredSize(new Dimension(dim.height, dim.height));
    }

    button.setToolTipText(this.getTooltiptext());

    super.layout();
}