Java Code Examples for javax.swing.JToggleButton#putClientProperty()

The following examples show how to use javax.swing.JToggleButton#putClientProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenPanel.java    From settlers-remake with MIT License 6 votes vote down vote up
/**
 * Initialize the filter buttons
 */
private void initFilter() {
	JLabel filterLabel = new JLabel(Labels.getString("mapfilter.title"));
	filterLabel.putClientProperty(ELFStyle.KEY, ELFStyle.LABEL_SHORT);

	filterPanel.add(filterLabel);

	boolean first = true;
	ButtonGroup group = new ButtonGroup();
	for (final EMapFilter filter : EMapFilter.values()) {
		JToggleButton bt = new JToggleButton(filter.getName());
		bt.putClientProperty(ELFStyle.KEY, ELFStyle.TOGGLE_BUTTON_STONE);
		bt.addActionListener(e -> {
			currentFilter = filter;
			searchChanged();
		});

		if (first) {
			first = false;
			bt.setSelected(true);
		}

		group.add(bt);
		filterPanel.add(bt);
	}
}
 
Example 2
Source File: ToggleDebuggingAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    toggleButton = new JToggleButton();
    toggleButton.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
    toggleButton.setIcon((Icon) getValue(SMALL_ICON));
    toggleButton.setAction(this); // this will make hard ref to button => check GC
    return toggleButton;
}
 
Example 3
Source File: ActionFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    JToggleButton toggleButton = new JToggleButton();
    toggleButtonRef = new WeakReference<>(toggleButton);
    toggleButton.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
    toggleButton.setIcon((Icon) getValue(SMALL_ICON));
    toggleButton.setAction(this); // this will make hard ref to button => check GC
    return toggleButton;
}
 
Example 4
Source File: ToggleHighlightSearchAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    JToggleButton b = new MyGaGaButton();
    b.setModel(new HighlightButtonModel());
    b.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
    b.setAction(this);
    return b;
}
 
Example 5
Source File: PaletteUI.java    From pumpernickel with MIT License 5 votes vote down vote up
private JToggleButton createCell() {
	JToggleButton newCell = new JToggleButton();
	newCell.addMouseListener(mouseListener);
	newCell.addMouseMotionListener(mouseListener);
	newCell.setContentAreaFilled(false);
	newCell.setBorder(null);
	newCell.setRequestFocusEnabled(false);
	newCell.setBorderPainted(false);
	newCell.setOpaque(false);
	newCell.putClientProperty(PROPERTY_CELL, Boolean.TRUE);
	newCell.addActionListener(cellActionListener);
	return newCell;
}
 
Example 6
Source File: LexerFrame.java    From groovy with Apache License 2.0 5 votes vote down vote up
private void scanScript(final StringReader reader) throws Exception {
    scriptPane.read(reader, null);
    reader.reset();

    // create lexer
    final GroovyLangLexer lexer = new GroovyLangLexer(reader);

    tokenPane.setEditable(true);
    tokenPane.setText("");

    int line = 1;
    final ButtonGroup bg = new ButtonGroup();
    Token token;

    while (true) {
        token = lexer.nextToken();
        JToggleButton tokenButton = new JToggleButton(tokens.get(token.getType()));
        bg.add(tokenButton);
        tokenButton.addActionListener(this);
        tokenButton.setToolTipText(token.getText());
        tokenButton.putClientProperty("token", token);
        tokenButton.setMargin(new Insets(0, 1, 0, 1));
        tokenButton.setFocusPainted(false);
        if (token.getLine() > line) {
            tokenPane.getDocument().insertString(tokenPane.getDocument().getLength(), "\n", null);
            line = token.getLine();
        }
        insertComponent(tokenButton);
        if (eof().equals(token.getType())) {
            break;
        }
    }

    tokenPane.setEditable(false);
    tokenPane.setCaretPosition(0);
    reader.close();
}
 
Example 7
Source File: MainMenuPanel.java    From settlers-remake with MIT License 5 votes vote down vote up
private void registerMenu(String translationKey, ActionListener listener) {
	JToggleButton bt = new JToggleButton(Labels.getString(translationKey));
	bt.putClientProperty(ELFStyle.KEY, ELFStyle.BUTTON_MENU);
	buttonGroup.add(bt);
	bt.addActionListener(listener);
	buttonPanel.add(bt);
	bt.setPreferredSize(new Dimension(230, 60));
}
 
Example 8
Source File: CssStylesPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void updateToolbar(FileObject file, Collection<CssStylesPanelProvider> activeProviders) {

        toolBar.removeAll();
        if (activeProviders.size() <= 1) {
            //remove the whole toolbar, if there's one or zero providers
            removeToolbar();
        } else {
            addToolbar();
        }

        // Button group for document and source buttons
        ButtonGroup buttonGroup = new ButtonGroup();

        boolean first = true;

        CssStylesPanelProvider selected = (file == null) ? null : selectedTabs.get(file.getMIMEType());

        //do the active providers contain the pre-selected provider for this mimetype?
        boolean containsPreselected = selected == null ? false : activeProviders.contains(selected);

        for (CssStylesPanelProvider provider : activeProviders) {
            JToggleButton button = new JToggleButton();
            button.setText(provider.getPanelDisplayName());
            button.setActionCommand(provider.getPanelID());
            button.addActionListener(toolbarListener);

            button.setFocusable(true);
            button.setFocusPainted(false);
            button.setRolloverEnabled(true);

            //copied from org.netbeans.core.multiview.TabsComponent.createButton to make the look 
            //similar to the editor tabs
            Border b = (getButtonBorder());
            if (b != null) {
                button.setBorder(b);
            }
            if (AQUA) {
                button.putClientProperty("JButton.buttonType", "square"); //NOI18N
                button.putClientProperty("JComponent.sizeVariant", "small"); //NOI18N
            }

            buttonGroup.add(button);
            toolBar.add(button);

            if (containsPreselected) {
                //one of the active providers is already pre-selected by user
                if (provider == selected) {
                    //the selected one - activate it
                    button.setSelected(true);
                    setActiveProvider(provider);
                } else {
                    button.setSelected(false);
                }
            } else {
                //no provider has been explicitly selected by the user yet
                button.setSelected(first);
                if (first) {
                    setActiveProvider(provider);
                    first = false;
                }
            }
        }

        revalidate();
        repaint();
    }
 
Example 9
Source File: CollapsiblePanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public FilesPanel(VCSCommitPanel master, Map<String, VCSCommitFilter> filters, int preferedHeight)  {
    super(master, master.getModifier().getMessage(VCSCommitPanelModifier.BundleMessage.FILE_PANEL_TITLE), DEFAULT_DISPLAY_FILES);
    this.filters = filters;
    
    master.getCommitTable().labelFor(filesLabel);
    
    JComponent table = master.getCommitTable().getComponent();
    
    Mnemonics.setLocalizedText(filesLabel, getMessage("CTL_CommitForm_FilesToCommit"));         // NOI18N
    filesLabel.setMaximumSize(new Dimension(Integer.MAX_VALUE, filesLabel.getMaximumSize().height));
    
    table.setPreferredSize(new Dimension(0, preferedHeight));
    
    ButtonGroup bg = new ButtonGroup();
    toolbar = new JToolBar();
    toolbar.setFloatable(false);
    
    for (VCSCommitFilter filter : filters.values()) {
        
        JToggleButton tgb = new JToggleButton();
        tgb.setIcon(filter.getIcon()); 
        tgb.setToolTipText(filter.getTooltip()); 
        tgb.setFocusable(false);
        tgb.setSelected(filter.isSelected());
        tgb.addActionListener(this);                
        tgb.putClientProperty(TOOLBAR_FILTER, filter);
        bg.add(tgb);
        toolbar.add(tgb);
        
    }
    toolbar.setAlignmentX(LEFT_ALIGNMENT);        
    
    sectionPanel.add(toolbar);
    sectionPanel.add(table);
    sectionPanel.add(VCSCommitPanel.makeVerticalStrut(filesLabel, table, RELATED, sectionPanel));
    sectionPanel.add(filesLabel);
    
    sectionPanel.setAlignmentX(LEFT_ALIGNMENT);
    filesLabel.setAlignmentX(LEFT_ALIGNMENT);
    table.setAlignmentX(LEFT_ALIGNMENT);
}