Search in sources :

Example 6 with KeyCombination

use of com.haulmont.cuba.gui.components.KeyCombination in project cuba by cuba-platform.

the class MenuBuilder method assignShortcut.

private void assignShortcut(JMenuItem jMenuItem, MenuItem item) {
    if (item.getShortcut() != null) {
        KeyCombination.Key key = item.getShortcut().getKey();
        KeyCombination.Modifier[] modifiers = item.getShortcut().getModifiers();
        KeyCombination combo = new KeyCombination(key, modifiers);
        jMenuItem.setAccelerator(DesktopComponentsHelper.convertKeyCombination(combo));
    }
}
Also used : KeyCombination(com.haulmont.cuba.gui.components.KeyCombination)

Example 7 with KeyCombination

use of com.haulmont.cuba.gui.components.KeyCombination in project cuba by cuba-platform.

the class LogWindow method initUI.

protected void initUI() {
    ClientConfig clientConfig = AppBeans.<Configuration>get(Configuration.NAME).getConfig(ClientConfig.class);
    String closeShortcut = clientConfig.getCloseShortcut();
    KeyCombination closeCombination = KeyCombination.create(closeShortcut);
    com.vaadin.event.ShortcutAction closeShortcutAction = new com.vaadin.event.ShortcutAction("closeShortcutAction", closeCombination.getKey().getCode(), KeyCombination.Modifier.codes(closeCombination.getModifiers()));
    addActionHandler(new com.vaadin.event.Action.Handler() {

        @Override
        public com.vaadin.event.Action[] getActions(Object target, Object sender) {
            return new com.vaadin.event.Action[] { closeShortcutAction };
        }

        @Override
        public void handleAction(com.vaadin.event.Action action, Object sender, Object target) {
            if (Objects.equals(action, closeShortcutAction)) {
                close();
            }
        }
    });
    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);
    layout.setMargin(false);
    layout.setSizeFull();
    setContent(layout);
    Panel scrollablePanel = new Panel();
    scrollablePanel.setSizeFull();
    VerticalLayout scrollContent = new VerticalLayout();
    scrollContent.setMargin(false);
    scrollContent.setSpacing(false);
    scrollContent.setSizeUndefined();
    scrollablePanel.setContent(scrollContent);
    final Label label = new Label();
    label.setContentMode(ContentMode.HTML);
    label.setValue(writeLog());
    label.setSizeUndefined();
    label.setStyleName("c-log-content");
    ((Layout) scrollablePanel.getContent()).addComponent(label);
    HorizontalLayout topLayout = new HorizontalLayout();
    topLayout.setMargin(false);
    topLayout.setSpacing(false);
    topLayout.setWidth("100%");
    topLayout.setHeightUndefined();
    Messages messages = AppBeans.get(Messages.NAME);
    Button refreshBtn = new CubaButton(messages.getMessage(getClass(), "logWindow.refreshBtn"), event -> label.setValue(writeLog()));
    topLayout.addComponent(refreshBtn);
    layout.addComponent(topLayout);
    layout.addComponent(scrollablePanel);
    layout.setExpandRatio(scrollablePanel, 1.0f);
}
Also used : Messages(com.haulmont.cuba.core.global.Messages) KeyCombination(com.haulmont.cuba.gui.components.KeyCombination) CubaButton(com.haulmont.cuba.web.widgets.CubaButton) CubaButton(com.haulmont.cuba.web.widgets.CubaButton) ClientConfig(com.haulmont.cuba.client.ClientConfig)

Example 8 with KeyCombination

use of com.haulmont.cuba.gui.components.KeyCombination in project cuba by cuba-platform.

the class WebButton method setShortcutCombination.

@Override
public void setShortcutCombination(KeyCombination shortcut) {
    KeyCombination oldValue = this.shortcut;
    if (!Objects.equals(oldValue, shortcut)) {
        this.shortcut = shortcut;
        if (shortcut != null) {
            int[] shortcutModifiers = KeyCombination.Modifier.codes(shortcut.getModifiers());
            int shortcutCode = shortcut.getKey().getCode();
            component.setClickShortcut(shortcutCode, shortcutModifiers);
        } else {
            component.removeClickShortcut();
        }
    }
}
Also used : KeyCombination(com.haulmont.cuba.gui.components.KeyCombination)

Aggregations

KeyCombination (com.haulmont.cuba.gui.components.KeyCombination)8 ShortcutListener (com.vaadin.event.ShortcutListener)2 AbstractComponent (com.vaadin.ui.AbstractComponent)2 ClientConfig (com.haulmont.cuba.client.ClientConfig)1 Messages (com.haulmont.cuba.core.global.Messages)1 AbstractAction (com.haulmont.cuba.gui.components.AbstractAction)1 AppUI (com.haulmont.cuba.web.AppUI)1 MenuShortcutAction (com.haulmont.cuba.web.gui.MenuShortcutAction)1 CubaButton (com.haulmont.cuba.web.widgets.CubaButton)1 ShortcutAction (com.vaadin.event.ShortcutAction)1