Java Code Examples for org.openide.awt.Actions#connect()

The following examples show how to use org.openide.awt.Actions#connect() . 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: ProfilerToolbarDropdownAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Component getToolbarPresenter() {
    if (toolbarPresenter == null) {
        // gets the real action registered in the menu from layer
        Action a = Actions.forID("Profile", "org.netbeans.modules.profiler.actions.AttachMainProject"); // NOI18N
        final Action attachProjectAction = a != null ? a : /* XXX should be impossible */AttachAction.getInstance();
        
        // gets the real action registered in the menu from layer
        a = Actions.forID("Profile", "org.netbeans.modules.profiler.actions.AttachAction"); // NOI18N
        final Action attachProcessAction = a != null ? a : /* XXX should be impossible */AttachAction.getInstance();

        JPopupMenu dropdownPopup = new JPopupMenu();
        dropdownPopup.add(createDropdownItem(defaultAction));
        dropdownPopup.add(createDropdownItem(attachProjectAction));
        dropdownPopup.addSeparator();
        dropdownPopup.add(createDropdownItem(attachProcessAction));

        JButton button = DropDownButtonFactory.createDropDownButton(new ImageIcon(
                new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), dropdownPopup);
        Actions.connect(button, defaultAction);

        toolbarPresenter = button;
    }

    return toolbarPresenter;
}
 
Example 2
Source File: ScreenshotComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JButton createSaveButton() {
    SaveAction sa = SaveAction.get(SaveAction.class);
    Action saveAction = sa.createContextAwareInstance(Lookups.singleton(new ScreenshotSavable()));
    JButton jb = new JButton();
    Actions.connect(jb, saveAction);
    return jb;
}
 
Example 3
Source File: JavaRefactoringGlobalAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    if (isMethodOverridden(JavaRefactoringGlobalAction.this, "getToolbarPresenter")) { // NOI18N

        return JavaRefactoringGlobalAction.this.getToolbarPresenter();
    } else {
        final JButton button = new JButton();
        Actions.connect(button, this);
        return button;
    }
}
 
Example 4
Source File: JavaRefactoringGlobalAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    if (isMethodOverridden(JavaRefactoringGlobalAction.this, "getToolbarPresenter")) { // NOI18N

        return JavaRefactoringGlobalAction.this.getToolbarPresenter();
    } else {
        final JButton button = new JButton();
        Actions.connect(button, this);
        return button;
    }
}
 
Example 5
Source File: RefactoringGlobalAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    if (isMethodOverridden(RefactoringGlobalAction.this, "getToolbarPresenter")) { // NOI18N

        return RefactoringGlobalAction.this.getToolbarPresenter();
    } else {
        final JButton button = new JButton();
        Actions.connect(button, this);
        return button;
    }
}
 
Example 6
Source File: ShelveChangesAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JComponent[] getMenu (VCSContext context, boolean popup) {
    Set<File> actionRoots = GitUtils.getRepositoryRoots(context);
    if (actionRoots.size() == 1) {
        final File root = actionRoots.iterator().next();
        RepositoryInfo info = RepositoryInfo.getInstance(root);
        final List<GitRevisionInfo> stashes = info.getStashes();
        if (!stashes.isEmpty()) {
            JMenu menu = new JMenu(popup ? Bundle.CTL_UnstashMenu_name_popup(): Bundle.CTL_UnstashMenu_name());
            Mnemonics.setLocalizedText(menu, menu.getText());
            int i = 0;
            for (ListIterator<Stash> it = Stash.create(root, stashes).listIterator(); it.hasNext() && i < 10; ++i) {
                Stash stash = it.next();
                Action a = stash.getApplyAction();
                String name = Bundle.CTL_UnstashAction_name(stash.getIndex(), stash.getInfo().getShortMessage());
                if (name.length() > 40) {
                    name = name.substring(0, 40);
                }
                a.putValue(Action.NAME, name);
                a.putValue(Action.SHORT_DESCRIPTION, stash.getInfo().getShortMessage());
                JMenuItem item = new JMenuItem(name);
                if (popup) {
                    Actions.connect(item, a, true);
                } else {
                    Actions.connect(item, a);
                }
                menu.add(item);
            }
            return new JComponent[] { menu };
        }
    }
    return null;
}
 
Example 7
Source File: Utils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a menu item from an action.
 *
 * @param action an action
 * @return JMenuItem
 */
public static JMenuItem toMenuItem(Action action) {
    JMenuItem item;
    if (action instanceof Presenter.Menu) {
        item = ((Presenter.Menu) action).getMenuPresenter();
    } else {
        item = new JMenuItem();
        Actions.connect(item, action, false);
    }
    return item;
}
 
Example 8
Source File: ProjectMenuItem.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JMenuItem createmenuItem(Action action) {
    JMenuItem item;
    if (action instanceof Presenter.Menu) {
        item = ((Presenter.Menu) action).getMenuPresenter();
    } else if (action instanceof Presenter.Popup) {
        item = ((Presenter.Popup) action).getPopupPresenter();
    } else {
        item = new JMenuItem();
        Actions.connect(item, action, true);
    }
    return item;
}
 
Example 9
Source File: Utils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a menu item from an action.
 * 
 * @param action an action
 * @return JMenuItem
 */
public static JMenuItem toMenuItem(Action action) {
    JMenuItem item;
    if (action instanceof Presenter.Menu) {
        item = ((Presenter.Menu) action).getMenuPresenter();
    } else if (action instanceof Presenter.Popup) {
        item = ((Presenter.Popup) action).getPopupPresenter();
    } else {
        item = new JMenuItem();
        Actions.connect(item, action, false);
    }
    return item;
}
 
Example 10
Source File: WatchesActionsProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public JMenuItem getPopupPresenter() {
    if (popupItem == null) {
        popupItem = new JCheckBoxMenuItem();
        popupItem.setSelected(isSelected());
        Actions.connect(popupItem, this, true);
    }
    return popupItem;
}
 
Example 11
Source File: HtmlRefactoringGlobalAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Component getToolbarPresenter() {
    if (isMethodOverridden(HtmlRefactoringGlobalAction.this, "getToolbarPresenter")) { // NOI18N

        return HtmlRefactoringGlobalAction.this.getToolbarPresenter();
    } else {
        final JButton button = new JButton();
        Actions.connect(button, this);
        return button;
    }
}
 
Example 12
Source File: DebuggingJSFramesInJavaModelFilter.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public DisplayJSStacksAction() {
    cbb = new JCheckBoxMenuItem(Bundle.LBL_DisplayAllJavaFrames(), !displayJSStacks);
    Actions.connect(cbb, this);
}
 
Example 13
Source File: PauseAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    final AbstractButton suspendIOButton = new JToggleButton();
    Actions.connect(suspendIOButton, this);
    updateButton(suspendIOButton);
    final class Controller implements Runnable, ActionListener {
        private RequestProcessor.Task updateTask;
        
        Controller() {
            updateTask = RP.create(this);
            scheduleUpdate(0);
        }
        
        @Override
        public void run() {
            if (!EventQueue.isDispatchThread()) {
                EventQueue.invokeLater(this);
                return;
            }
            if (!suspendIOButton.isShowing()) {
                return;
            }
            updateButton(suspendIOButton);
            scheduleUpdate(0);
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            updateButton(suspendIOButton);
            run();
            scheduleUpdate(100);
        }

        private void scheduleUpdate(int time) {
            if (time == 0) {
                time = 1500;
            }
            updateTask.schedule(time);
        }
    }
    Controller c = new Controller();
    suspendIOButton.addActionListener(c);
    
    return suspendIOButton;
}
 
Example 14
Source File: RunLastBuildAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public @Override Component getToolbarPresenter() {
    JButton button = new JButton();
    Actions.connect(button, this);
    return button;
}
 
Example 15
Source File: SQLExecutionBaseAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Component getToolbarPresenter() {
    JButton button = new JButton();
    Actions.connect(button, this);
    return button;
}
 
Example 16
Source File: DebugMainProjectAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override public Component getToolbarPresenter() {
    JPopupMenu menu = new JPopupMenu();
    JButton button = DropDownButtonFactory.createDropDownButton(
            new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), menu);
    final JMenuItem item = new JMenuItem(Actions.cutAmpersand((String) delegate.getValue("menuText")));
    item.setEnabled(delegate.isEnabled());

    delegate.addPropertyChangeListener(new PropertyChangeListener() {
        @Override public void propertyChange(PropertyChangeEvent evt) {
            String propName = evt.getPropertyName();
            if ("enabled".equals(propName)) {
                item.setEnabled((Boolean)evt.getNewValue());
            } else if ("menuText".equals(propName)) {
                item.setText(Actions.cutAmpersand((String) evt.getNewValue()));
            } else if ("selectedProjects".equals(propName)) {
                Project[] projects = (Project[]) evt.getNewValue();
                if (projects.length == 1) {
                    debugHistorySupport.setSelectedProject(projects[0].getProjectDirectory());
                } else {
                    debugHistorySupport.setSelectedProject(null);
                }
            }
        }
    });

    menu.add(item);
    item.addActionListener(new ActionListener() {
        @Override public void actionPerformed(ActionEvent e) {
            DebugMainProjectAction.this.actionPerformed(e);
        }
    });
    try {
        Action ca = Actions.forID("Debug", "org.netbeans.modules.debugger.ui.actions.ConnectAction");
        JMenuItem item2 = new JMenuItem(Actions.cutAmpersand((String) ca.getValue(NAME)));
        Actions.connect(item2, ca);
        menu.add(item2);
    } catch (Exception nsee) {
        Exceptions.printStackTrace(nsee);
    }

    menu.addPopupMenuListener(this);

    Actions.connect(button, this);
    return button;
}