Java Code Examples for com.alee.laf.button.WebToggleButton#addActionListener()

The following examples show how to use com.alee.laf.button.WebToggleButton#addActionListener() . 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: HeatMapTool.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructs new {@link HeatMapTool}.
 *
 * @param application {@link DemoApplication}
 */
public HeatMapTool ( final DemoApplication application )
{
    super ( StyleId.panelTransparent, new BorderLayout ( 0, 0 ) );

    // Heat map
    heatMap = new HeatMap ();

    // Magnifier glass switcher button
    final WebToggleButton heatMapButton = new WebToggleButton ( DemoStyles.toolButton, DemoIcons.fire16 );
    heatMapButton.setLanguage ( "demo.tool.heatmap" );
    heatMapButton.setSelected ( heatMap.isDisplayed () );
    heatMapButton.addActionListener ( new ActionListener ()
    {
        @Override
        public void actionPerformed ( final ActionEvent e )
        {
            heatMap.displayOrDispose ( application );
        }
    } );
    add ( heatMapButton );
}
 
Example 2
Source File: MethodEditorPanel.java    From Cafebabe with GNU General Public License v3.0 5 votes vote down vote up
private WebButtonGroup accessToggleGroup() {
	// do not change tooltips
	WebToggleButton private_ = new WebToggleButton(MethodListCellRenderer.pri);
	private_.setToolTipText("private");
	WebToggleButton public_ = new WebToggleButton(MethodListCellRenderer.pub);
	public_.setToolTipText("public");
	WebToggleButton protected_ = new WebToggleButton(MethodListCellRenderer.pro);
	protected_.setToolTipText("protected");
	WebToggleButton static_ = new WebToggleButton(MethodListCellRenderer.stat);
	static_.setToolTipText("static");
	WebToggleButton final_ = new WebToggleButton(MethodListCellRenderer.fin);
	final_.setToolTipText("final");
	WebToggleButton abstract_ = new WebToggleButton(MethodListCellRenderer.abs);
	abstract_.setToolTipText("abstract");
	WebToggleButton native_ = new WebToggleButton(MethodListCellRenderer.nat);
	native_.setToolTipText("native");
	WebToggleButton synchronized_ = new WebToggleButton(MethodListCellRenderer.syn);
	synchronized_.setToolTipText("synchronized");
	WebToggleButton synthetic_ = new WebToggleButton(MethodListCellRenderer.synth);
	synthetic_.setToolTipText("synthetic");

	private_.addActionListener(l -> {
		public_.setSelected(false);
		protected_.setSelected(false);
	});
	public_.addActionListener(l -> {
		protected_.setSelected(false);
		private_.setSelected(false);
	});
	protected_.addActionListener(l -> {
		public_.setSelected(false);
		private_.setSelected(false);
	});
	WebButtonGroup accessGroup = new WebButtonGroup(false, private_, public_, protected_, static_, final_, abstract_,
			native_, synchronized_, synthetic_);
	accessGroup.setButtonsDrawFocus(false);

	return accessGroup;
}
 
Example 3
Source File: ClassEditorPanel.java    From Cafebabe with GNU General Public License v3.0 5 votes vote down vote up
private WebButtonGroup accessToggleGroup() {
	// do not change tooltips
	WebToggleButton private_ = new WebToggleButton(MethodListCellRenderer.pri);
	private_.setToolTipText("private");
	WebToggleButton public_ = new WebToggleButton(MethodListCellRenderer.pub);
	public_.setToolTipText("public");
	WebToggleButton protected_ = new WebToggleButton(MethodListCellRenderer.pro);
	protected_.setToolTipText("protected");
	WebToggleButton abstract_ = new WebToggleButton(MethodListCellRenderer.abs);
	abstract_.setToolTipText("abstract");
	WebToggleButton final_ = new WebToggleButton(MethodListCellRenderer.fin);
	final_.setToolTipText("final");
	WebToggleButton synthetic_ = new WebToggleButton(MethodListCellRenderer.synth);
	synthetic_.setToolTipText("synthetic");

	private_.addActionListener(l -> {
		public_.setSelected(false);
		protected_.setSelected(false);
	});
	public_.addActionListener(l -> {
		protected_.setSelected(false);
		private_.setSelected(false);
	});
	protected_.addActionListener(l -> {
		public_.setSelected(false);
		private_.setSelected(false);
	});
	WebButtonGroup accessGroup = new WebButtonGroup(false, private_, public_, protected_, abstract_, final_,
			synthetic_);
	accessGroup.setButtonsDrawFocus(false);

	return accessGroup;
}
 
Example 4
Source File: JMenuBarExample.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns new dialog preview button.
 *
 * @param text          button text
 * @param dialogStyleId dialog {@link StyleId}
 * @return new dialog preview button
 */
protected WebToggleButton createDialogButton ( final String text, final StyleId dialogStyleId )
{
    final String showText = getExampleLanguagePrefix () + text;
    final WebToggleButton showButton = new WebToggleButton ( showText, Icons.external );
    showButton.addActionListener ( new ActionListener ()
    {
        /**
         * Dialog containing menu bar.
         */
        private WebDialog dialog;

        @Override
        public void actionPerformed ( final ActionEvent e )
        {
            if ( dialog == null || !dialog.isVisible () )
            {
                if ( dialog == null )
                {
                    dialog = new WebDialog ( dialogStyleId, DemoApplication.getInstance (), getTitle () );
                    dialog.setJMenuBar ( createMenuBar () );

                    final String contentText = getExampleLanguagePrefix () + "content";
                    final WebLabel contentLabel = new WebLabel ( contentText, SwingConstants.CENTER );
                    dialog.add ( contentLabel.setPreferredSize ( 300, 250 ) );

                    dialog.setDefaultCloseOperation ( WindowConstants.DISPOSE_ON_CLOSE );
                    dialog.setModal ( false );

                    dialog.onClose ( new ComponentEventRunnable ()
                    {
                        @Override
                        public void run ( @NotNull final ComponentEvent event )
                        {
                            if ( showButton.isSelected () )
                            {
                                showButton.setSelected ( false );
                            }
                        }
                    } );
                }
                dialog.pack ();
                dialog.setLocationRelativeTo ( DemoApplication.getInstance () );
                dialog.setVisible ( true );
            }
            else
            {
                dialog.dispose ();
            }
        }
    } );
    return showButton;
}
 
Example 5
Source File: InterfaceInspector.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructs new {@link InterfaceInspector} for the specified {@link Component} and its childrens tree.
 *
 * @param id        {@link StyleId}
 * @param inspected {@link Component} to inspect
 */
public InterfaceInspector ( @NotNull final StyleId id, @Nullable final Component inspected )
{
    super ( id );

    // Tree scroll
    final WebScrollPane scrollPane = new WebScrollPane ( StyleId.inspectorScroll.at ( InterfaceInspector.this ) );
    scrollPane.setPreferredWidth ( 300 );

    // Interface tree
    tree = new InterfaceTree ( StyleId.inspectorTree.at ( scrollPane ), inspected );
    scrollPane.getViewport ().setView ( tree );

    // Filtering field
    final WebTreeFilterField filter = new WebTreeFilterField ( StyleId.inspectorFilter.at ( InterfaceInspector.this ), tree );

    // Component inspect behavior
    final WebToggleButton inspectToggle = new WebToggleButton ( StyleId.inspectorInspect.at ( filter ), Icons.target );
    inspectToggle.setRolloverIcon ( Icons.targetHover );
    inspectToggle.setSelectedIcon ( Icons.targetSelected );
    inspectToggle.setCursor ( Cursor.getDefaultCursor () );
    inspectToggle.addHotkey ( Hotkey.CTRL_I );
    inspectToggle.addActionListener ( new ActionListener ()
    {
        @Override
        public void actionPerformed ( @NotNull final ActionEvent e )
        {
            if ( inspectToggle.isSelected () )
            {
                if ( inspectBehavior == null )
                {
                    inspectBehavior = new ComponentInspectBehavior ();
                }
                if ( !inspectBehavior.isInstalled () )
                {
                    inspectBehavior.install ( inspected, new InspectionListener ()
                    {
                        @Override
                        public void inspected ( @NotNull final Component component )
                        {
                            tree.navigate ( component );
                            inspectToggle.setSelected ( false );
                            tree.requestFocusInWindow ();
                        }

                        @Override
                        public void cancelled ()
                        {
                            inspectToggle.setSelected ( false );
                        }
                    } );
                }
            }
            else
            {
                if ( inspectBehavior != null && inspectBehavior.isInstalled () )
                {
                    inspectBehavior.uninstall ();
                }
            }
        }
    } );
    filter.setTrailingComponent ( inspectToggle );

    // UI composition
    final WebSeparator separator = new WebSeparator ( StyleId.inspectorSeparator.at ( InterfaceInspector.this ) );
    add ( new GroupPanel ( GroupingType.fillLast, 0, false, filter, separator, scrollPane ) );

    // Expanding tree root by default
    tree.expandRoot ();

    // Visibility behavior
    new VisibilityBehavior<InterfaceInspector> ( this, true )
    {
        @Override
        protected void hidden ( @NotNull final InterfaceInspector inspector )
        {
            if ( inspectBehavior != null && inspectBehavior.isInstalled () )
            {
                inspectBehavior.uninstall ();
            }
        }
    }.install ();
}