com.alee.managers.hotkey.Hotkey Java Examples

The following examples show how to use com.alee.managers.hotkey.Hotkey. 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: WebCustomTooltipExample.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
@NotNull
@Override
protected List<? extends JComponent> createPreviewElements ()
{
    final WebButton button = new WebButton ();
    button.setLanguage ( getPreviewLanguagePrefix () + "text", 0 );
    button.addHotkey ( Hotkey.CTRL_D );
    button.setToolTip ( getPreviewLanguagePrefix () + "tip" );
    button.addActionListener ( new ActionListener ()
    {
        private int counter = 0;

        @Override
        public void actionPerformed ( final ActionEvent e )
        {
            counter++;
            button.updateLanguage ( counter );
        }
    } );
    return CollectionUtils.asList ( button );
}
 
Example #2
Source File: WebFileListCellEditor.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void installStartEditActions ( final JList list )
{
    keyAdapter = new KeyAdapter ()
    {
        @Override
        public void keyReleased ( final KeyEvent e )
        {
            if ( Hotkey.F2.isTriggered ( e ) )
            {
                startEdit ( list, list.getSelectedIndex () );
            }
        }
    };
    list.addKeyListener ( keyAdapter );
}
 
Example #3
Source File: WebCheckBoxTree.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void keyPressed ( @NotNull final KeyEvent e )
{
    if ( isCheckingByUserEnabled () && Hotkey.SPACE.isTriggered ( e ) )
    {
        final List<N> nodes = getSelectedNodes ();

        // Removing invisible nodes from checking list
        final Iterator<N> nodesIterator = nodes.iterator ();
        while ( nodesIterator.hasNext () )
        {
            final N node = nodesIterator.next ();
            if ( !isCheckBoxVisible ( node ) || !isCheckBoxEnabled ( node ) )
            {
                nodesIterator.remove ();
            }
        }

        // Performing checking
        if ( nodes.size () > 0 )
        {
            invertCheck ( nodes );
        }
    }
}
 
Example #4
Source File: WebDefaultCellEditor.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
public boolean isCellEditable ( final EventObject anEvent )
{
    if ( anEvent == null || anEvent instanceof ActionEvent )
    {
        return true;
    }
    else if ( anEvent instanceof KeyEvent )
    {
        final KeyEvent keyEvent = ( KeyEvent ) anEvent;
        return Hotkey.F2.isTriggered ( keyEvent );
    }
    else if ( anEvent instanceof MouseEvent )
    {
        final MouseEvent mouseEvent = ( MouseEvent ) anEvent;
        return clickCountToStart >= 0 && mouseEvent.getClickCount () >= clickCountToStart;
    }
    else
    {
        return false;
    }
}
 
Example #5
Source File: WebDirectoryChooserPanel.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructs new directory chooser panel.
 *
 * @param id {@link StyleId}
 */
public WebDirectoryChooserPanel ( final StyleId id )
{
    super ( id, new TableLayout ( new double[][]{
            { TableLayout.FILL },
            { TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED }
    } ) );

    // Panel content
    add ( createToolBar (), "0,0" );
    add ( createPathField (), "0,1" );
    add ( createFileTree (), "0,2" );
    add ( createControlsPanel (), "0,3" );

    // Updating selected directory
    updateSelectedDirectory ( null, true, true );
    updateToolbarControlsState ();

    // Hotkeys preview action and hotkeys global condition
    HotkeyManager.installShowAllHotkeysAction ( this, Hotkey.F1 );
    HotkeyManager.addContainerHotkeyCondition ( this, new HotkeyCondition ()
    {
        @Override
        public boolean checkCondition ( final Component component )
        {
            return allowHotkeys ();
        }
    } );
}
 
Example #6
Source File: AbstractListCellEditor.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Installs start edit actions in the list.
 *
 * @param list list to process
 */
protected void installStartEditActions ( final JList list )
{
    mouseAdapter = new MouseAdapter ()
    {
        @Override
        public void mouseClicked ( final MouseEvent e )
        {
            if ( getClicksToEdit () > 0 && e.getClickCount () == getClicksToEdit () && SwingUtils.isLeftMouseButton ( e ) )
            {
                final Point point = e.getPoint ();
                final int index = list.getUI ().locationToIndex ( list, point );
                if ( index >= 0 && index < list.getModel ().getSize () )
                {
                    final Rectangle cell = list.getCellBounds ( index, index );
                    if ( cell.contains ( point ) )
                    {
                        startEdit ( list, index );
                    }
                }
            }
        }
    };
    list.addMouseListener ( mouseAdapter );

    keyAdapter = new KeyAdapter ()
    {
        @Override
        public void keyReleased ( final KeyEvent e )
        {
            if ( Hotkey.F2.isTriggered ( e ) )
            {
                startEdit ( list, list.getSelectedIndex () );
            }
        }
    };
    list.addKeyListener ( keyAdapter );
}
 
Example #7
Source File: WebCheckBoxList.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyReleased ( final KeyEvent e )
{
    if ( Hotkey.SPACE.isTriggered ( e ) && getSelectedIndex () != -1 && isEnabled () )
    {
        for ( final int index : getSelectedIndices () )
        {
            invertCheckBoxSelection ( index );
        }
    }
}
 
Example #8
Source File: WebSyntaxArea.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initializes additional custom settings.
 *
 * @param presets presets to apply
 */
protected void initialize ( @NotNull final SyntaxPreset... presets )
{
    // Applying provided presets
    applyPresets ( presets );

    // Applying default theme if it wasn't provided
    if ( themePreset == null )
    {
        // todo A temporary solution for initial theme selected according to skin
        applyPresets ( StyleManager.getSkin () instanceof WebDarkSkin ? SyntaxPreset.darkTheme : SyntaxPreset.ideaTheme );

        // todo A temporary solution for switching theme according to skin
        StyleManager.addSkinListener ( new SkinListener ()
        {
            @Override
            public void skinChanged ( @Nullable final Skin previous, @NotNull final Skin current )
            {
                applyPresets ( StyleManager.getSkin () instanceof WebDarkSkin ? SyntaxPreset.darkTheme : SyntaxPreset.ideaTheme );
            }
        } );
    }

    // Clearing history to avoid initial text removal on undo
    clearHistory ();

    // Adding redo action
    onKeyPress ( Hotkey.CTRL_SHIFT_Z, new KeyEventRunnable ()
    {
        @Override
        public void run ( @NotNull final KeyEvent e )
        {
            redoLastAction ();
        }
    } );
}
 
Example #9
Source File: CheckBoxListTest.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public static void main ( final String[] args )
{
    SwingTest.run ( new Runnable ()
    {
        @Override
        public void run ()
        {
            final CheckBoxListModel model = new CheckBoxListModel ();
            model.add ( new CheckBoxCellData ( "Sample 1" ) );
            model.add ( new CheckBoxCellData ( "Sample 2" ) );
            model.add ( new CheckBoxCellData ( "Sample 3" ) );

            final WebCheckBoxList list = new WebCheckBoxList ( StyleId.checkboxlist, model );

            list.setCheckBoxSelected ( 0, true );
            list.setCheckBoxSelected ( 1, false );
            list.setCheckBoxSelected ( 2, true );

            TestFrame.show ( list );

            list.onKeyPress ( Hotkey.CTRL_A, new KeyEventRunnable ()
            {
                @Override
                public void run ( @NotNull final KeyEvent e )
                {
                    for ( int i = 0; i < list.getModel ().getSize (); i++ )
                    {
                        list.setCheckBoxSelected ( i, false );
                    }
                }
            } );
        }
    } );
}
 
Example #10
Source File: ExamplesFrame.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructs examples frame.
 */
public ExamplesFrame ()
{
    super ( StyleId.dockableframeCompact, ID, DemoIcons.examples16, "demo.examples.title" );
    setPosition ( CompassDirection.west );
    setPreferredSize ( 300, 200 );

    // Examples tree
    final ExamplesTree examplesTree = new ExamplesTree ();
    examplesTree.onKeyPress ( Hotkey.ENTER, new KeyEventRunnable ()
    {
        @Override
        public void run ( @NotNull final KeyEvent e )
        {
            open ( examplesTree.getSelectedNode () );
        }
    } );
    examplesTree.onNodeDoubleClick ( new TreeNodeEventRunnable<ExamplesTreeNode> ()
    {
        @Override
        public void run ( @NotNull final ExamplesTreeNode node )
        {
            open ( node );
        }
    } );
    examplesTree.registerSettings ( new Configuration<TreeState> ( "ExamplesTree" ) );
    final WebScrollPane examplesTreeScroll = new WebScrollPane ( StyleId.scrollpaneTransparentHoveringExtending, examplesTree );
    examplesTreeScroll.registerSettings ( new Configuration<ScrollPaneState> ( "ExamplesScroll" ) );

    // Filtering field
    final WebTreeFilterField filter = new WebTreeFilterField ( DemoStyles.filterfield, examplesTree );

    // Frame UI composition
    final WebSeparator separator = new WebSeparator ( StyleId.separatorHorizontal );
    add ( new GroupPanel ( GroupingType.fillLast, 0, false, filter, separator, examplesTreeScroll ) );
}
 
Example #11
Source File: WebHotkeyLabelExample.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
@NotNull
@Override
protected List<? extends JComponent> createPreviewElements ()
{
    final WebHotkeyLabel p1 = new WebHotkeyLabel ( getStyleId (), Hotkey.ALT );
    final WebHotkeyLabel p2 = new WebHotkeyLabel ( getStyleId (), Hotkey.F4 );
    final WebHotkeyLabel p3 = new WebHotkeyLabel ( getStyleId (), Hotkey.ALT_F4 );
    return CollectionUtils.asList ( p1, p2, p3 );
}
 
Example #12
Source File: ChatView.java    From desktopclient-java with GNU General Public License v3.0 5 votes vote down vote up
void setHotkeys(final boolean enterSends) {
    mTextComposingArea.setHotkeys(enterSends);

    mSendButton.removeHotkeys();
    HotkeyData sendHotkey = enterSends ? Hotkey.ENTER : Hotkey.CTRL_ENTER;
    mSendButton.addHotkey(sendHotkey, TooltipWay.up);
}
 
Example #13
Source File: WebTreeFilterField.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Initializes listeners.
 */
protected void initListeners ()
{
    // Updating filtering on text change
    onChange ( new DocumentEventRunnable<WebTextField> ()
    {
        @Override
        public void run ( @NotNull final WebTextField component, @Nullable final DocumentEvent event )
        {
            filter.setSearchText ( component.getText () );
            updateFiltering ();
        }
    } );

    // Clearing filter field on ESCAPE press
    onKeyPress ( Hotkey.ESCAPE, new KeyEventRunnable ()
    {
        @Override
        public void run ( @NotNull final KeyEvent e )
        {
            clear ();
        }
    } );

    // Model listener for carrying custom filter over to new model
    treeModelChangeListener = new PropertyChangeListener ()
    {
        @Override
        public void propertyChange ( @NotNull final PropertyChangeEvent evt )
        {
            // Checking model support
            final TreeModel newModel = ( TreeModel ) evt.getNewValue ();
            checkTreeModel ( newModel );

            // Removing filter from the old model
            removeFieldFilter ();

            // Clearing tree state as it might not be applicable to the new model data
            clearState ();

            // Saving reference to the new model
            model = newModel;

            // Saving tree state before applying the filter
            saveState ();

            // Applying filter to the new model
            applyFieldFilter ();
        }
    };
}
 
Example #14
Source File: TooltipManager.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Installs "show all hotkeys" action on window or component
 */

public static void installShowAllTooltipsAction ( final JComponent topComponent )
{
    installShowAllTooltipsAction ( topComponent, Hotkey.F2 );
}
 
Example #15
Source File: JMenuBarExample.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns new menu bar.
 *
 * @return new menu bar
 */
protected JMenuBar createMenuBar ()
{
    // Creating new menu bar
    final JMenuBar menuBar = new JMenuBar ();
    menuBar.putClientProperty ( StyleId.STYLE_PROPERTY, getStyleId () );

    // Filling menu bar with items
    final JMenuBarGenerator generator = new JMenuBarGenerator ( menuBar );
    generator.setLanguagePrefix ( "demo.example.menus.menu" );
    generator.setIconSettings ( MenusGroup.class, "icons/menu/", "png" );

    final ActionListener action = new ActionListener ()
    {
        @Override
        public void actionPerformed ( final ActionEvent e )
        {
            final JMenuItem menuItem = ( JMenuItem ) e.getSource ();
            notifyAboutEvent ( menuItem.getText () );
        }
    };

    final MenuGenerator fileMenu = generator.addSubMenu ( "file", "file" );
    final MenuGenerator subMenu = fileMenu.addSubMenu ( "new", "new" );
    subMenu.addItem ( "image", "image", Hotkey.CTRL_N, action );
    subMenu.addItem ( "video", "video", action );
    subMenu.addItem ( "music", "music", action );
    fileMenu.addItem ( "open", "open", Hotkey.CTRL_O, action );
    fileMenu.addSeparator ();
    fileMenu.addItem ( "save", "save", Hotkey.CTRL_S, action );
    fileMenu.addItem ( "print", "print", Hotkey.CTRL_P, action );
    fileMenu.addSeparator ();
    fileMenu.addItem ( "exit", "exit", Hotkey.ALT_X, action );
    menuBar.add ( fileMenu.getMenu () );

    final MenuGenerator editMenu = generator.addSubMenu ( "edit", "edit" );
    editMenu.addItem ( "undo", "undo", Hotkey.CTRL_Z, action );
    editMenu.addItem ( "redo", "redo", Hotkey.CTRL_Y, action );
    editMenu.addSeparator ();
    editMenu.addItem ( "cut", "cut", Hotkey.CTRL_X, action );
    editMenu.addItem ( "copy", "copy", Hotkey.CTRL_C, action );
    editMenu.addItem ( "paste", "paste", Hotkey.CTRL_P, action );
    menuBar.add ( editMenu.getMenu () );

    final MenuGenerator settingsMenu = generator.addSubMenu ( "settings", "settings" );
    settingsMenu.openGroup ();
    settingsMenu.addRadioItem ( "image", "choice1", Hotkey.F1, true, action );
    settingsMenu.addRadioItem ( "video", "choice2", Hotkey.F2, false, action );
    settingsMenu.addRadioItem ( "choice3", Hotkey.F3, false, action );
    settingsMenu.closeGroup ();
    settingsMenu.addSeparator ();
    settingsMenu.addCheckItem ( "save", "option1", Hotkey.F4, true, action );
    settingsMenu.addCheckItem ( "print", "option2", Hotkey.F5, false, action );
    settingsMenu.addCheckItem ( "option3", Hotkey.F6, false, action );
    menuBar.add ( settingsMenu.getMenu () );

    return menuBar;
}
 
Example #16
Source File: ComponentInspectBehavior.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Installs {@link ComponentInspectBehavior} in the specified root {@link Component}.
 * In case {@link Component} is {@code null} behavior will be able to inspect any element on any window.
 *
 * @param root     root {@link Component}
 * @param listener {@link InspectionListener}
 */
public void install ( @Nullable final Component root, @NotNull final InspectionListener listener )
{
    if ( !isInstalled () )
    {
        // Saving root component
        this.root = root;

        // Saving inspection listener
        this.listener = listener;

        // Creating hover highlighter
        this.hoverHighlighter = new ComponentHighlighter ();

        // Adding listeners
        // todo Replace with HoverManager usage?
        awtEventListener = new AWTEventListener ()
        {
            @Override
            public void eventDispatched ( @NotNull final AWTEvent event )
            {
                final int eventId = event.getID ();
                if ( event instanceof MouseEvent )
                {
                    // Limiting affected area of UI elements by the root
                    final MouseEvent mouseEvent = ( MouseEvent ) event;
                    final Component source = ( Component ) event.getSource ();
                    final Component component = CoreSwingUtils.getTopComponentAt ( source, mouseEvent.getPoint () );
                    if ( component != null && component.isShowing () && ( ComponentInspectBehavior.this.root == null ||
                            CoreSwingUtils.isAncestorOf ( ComponentInspectBehavior.this.root, component ) ) )
                    {
                        // Performing on-event actions
                        if ( Objects.equals ( eventId, MouseEvent.MOUSE_PRESSED ) )
                        {
                            // Firing events
                            ComponentInspectBehavior.this.listener.inspected ( component );

                            // Uninstalling behavior
                            uninstall ();
                        }
                        else if ( Objects.equals ( eventId, MouseEvent.MOUSE_ENTERED, MouseEvent.MOUSE_MOVED ) )
                        {
                            // Checking that hovered component has actually changed
                            if ( hoverHighlighter != null && hoverHighlighter.getComponent () != component )
                            {
                                // Displaying inspector for newly hovered component
                                showInspector ( component );
                            }
                        }
                        else if ( Objects.equals ( eventId, MouseEvent.MOUSE_EXITED ) )
                        {
                            // Hiding inspector
                            hideInspector ();
                        }

                        // Consuming event to avoid it being processed by someone else
                        mouseEvent.consume ();
                    }
                }
                else if ( event instanceof KeyEvent )
                {
                    // Uninstalling behavior on ESCAPE press
                    final KeyEvent keyEvent = ( KeyEvent ) event;
                    if ( Objects.equals ( eventId, KeyEvent.KEY_PRESSED ) && Hotkey.ESCAPE.isTriggered ( keyEvent ) )
                    {
                        // Firing events
                        ComponentInspectBehavior.this.listener.cancelled ();

                        // Uninstalling behavior
                        uninstall ();
                    }

                    // Consuming event to avoid it being processed by someone else
                    keyEvent.consume ();
                }
            }
        };
        Toolkit.getDefaultToolkit ().addAWTEventListener ( awtEventListener, AWTEvent.MOUSE_EVENT_MASK );
        Toolkit.getDefaultToolkit ().addAWTEventListener ( awtEventListener, AWTEvent.MOUSE_MOTION_EVENT_MASK );
        Toolkit.getDefaultToolkit ().addAWTEventListener ( awtEventListener, AWTEvent.KEY_EVENT_MASK );
    }
    else
    {
        throw new BehaviorException ( "ComponentInspectBehavior is already installed" );
    }
}
 
Example #17
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 ();
}