Java Code Examples for org.openide.awt.DropDownButtonFactory#createDropDownButton()

The following examples show how to use org.openide.awt.DropDownButtonFactory#createDropDownButton() . 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: InfoPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private JButton createArrowButton() {
    arrowMenu = new JPopupMenu();
    JButton button = DropDownButtonFactory.createDropDownButton(
        ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/debuggingView/unvisited_bpkt_arrow_small_16.png", false), arrowMenu);
    button.setPreferredSize(new Dimension(40, button.getPreferredSize().height)); // [TODO]
    button.setMaximumSize(new Dimension(40, button.getPreferredSize().height)); // [TODO]
    button.setFocusable(false);
    button.setOpaque(false);
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (arrowMenu.getComponentCount() > 0) {
                Object item = arrowMenu.getComponent(0);
                for (Map.Entry<DVThread, JMenuItem> entry : threadToMenuItem.entrySet()) {
                    if (entry.getValue() == item) {
                        debuggingView.makeThreadCurrent(entry.getKey());
                    } // if
                } // for
            } // if
        } // actionPerformed
    });
    return button;
}
 
Example 3
Source File: RunScriptAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    if (popup != null) {
        JButton button = DropDownButtonFactory.createDropDownButton(
            (ImageIcon) getValue(SMALL_ICON), 
            popup
        );
        button.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
        button.setAction(this);
        return button;
    } else {
        return new JButton(this);
    }
}
 
Example 4
Source File: MainProjectActionWithHistory.java    From netbeans with Apache License 2.0 5 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(org.openide.awt.Actions.cutAmpersand((String) getValue("menuText")));
        item.setEnabled(isEnabled());

        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(org.openide.awt.Actions.cutAmpersand((String) evt.getNewValue()));
                }
            }
        });

        menu.add(item);
        item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                MainProjectActionWithHistory.this.actionPerformed(e);
            }
        });
       
        org.openide.awt.Actions.connect(button, this);
        menu.addPopupMenuListener(this);
        return button;
    
}
 
Example 5
Source File: NavigationHistoryBackAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    if (popupMenu != null) {
        JButton button = DropDownButtonFactory.createDropDownButton(
            (ImageIcon) getValue(SMALL_ICON), 
            popupMenu
        );
        button.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
        button.setAction(this);
        return button;
    } else {
        return new JButton(this);
    }
}
 
Example 6
Source File: NavigationHistoryForwardAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    if (popupMenu != null) {
        JButton button = DropDownButtonFactory.createDropDownButton(
            (ImageIcon) getValue(SMALL_ICON), 
            popupMenu
        );
        button.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
        button.setAction(this);
        return button;
    } else {
        return new JButton(this);
    }
}
 
Example 7
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;
}
 
Example 8
Source File: ToolbarSimulationAction.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
public Component getToolbarPresenter() {
   tb = new JPanel();
   tb.setLayout(new FlowLayout());
   tb.setPreferredSize(new Dimension(230, 50));
   tb.setMaximumSize(new Dimension(230, 50));
   //tb.setFloatable(true);
   //tb.setBorder(BorderFactory.createTitledBorder(null, "Simulate", TitledBorder.CENTER, TitledBorder.TOP));
   tb.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
   JPopupMenu popup = new JPopupMenu();
   JMenuItem endTimeMenuitem = new JMenuItem("End time...");
   popup.add(endTimeMenuitem);
   //tb.addSeparator(new Dimension(10,40));
     try {
         JLabel jLabel1 = new JLabel("Simulate");
         jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
         tb.add(jLabel1);
         ImageIcon icon = new ImageIcon(getClass().getResource("/org/opensim/tracking/tools/run.png"));
         JButton dropdownButton = DropDownButtonFactory.createDropDownButton(icon, popup);
         dropdownButton.setPreferredSize(new Dimension(60,32));
         tb.add(Box.createHorizontalStrut(2));
         final ToolbarRunForwardAction runFD = (ToolbarRunForwardAction) ToolbarRunForwardAction.findObject((Class)Class.forName("org.opensim.tracking.tools.ToolbarRunForwardAction"), true);
         //JButton fdButton = new JButton(runFD);
         endTimeMenuitem.addActionListener(new ActionListener(){

         public void actionPerformed(ActionEvent ae) {
             SpecifyFinalTimeJPanel endTimePanel = new SpecifyFinalTimeJPanel(runFD.getFinalTime());
             DialogDescriptor dlg = new DialogDescriptor(endTimePanel,"Specify end time");
             dlg.setModal(true);
             DialogDisplayer.getDefault().createDialog(dlg).setVisible(true);
             Object userInput = dlg.getValue();
             if (((Integer)userInput).compareTo((Integer)DialogDescriptor.OK_OPTION)==0){
                 runFD.setFinalTime( endTimePanel.getEndtime());
             }
         }
     });

   tb.add(dropdownButton);
         dropdownButton.setAction(runFD);
         dropdownButton.setText("Run");
         tb.add(Box.createHorizontalStrut(5));
         ToolbarStopForwardAction stopFD = (ToolbarStopForwardAction) ToolbarStopForwardAction.findObject((Class)Class.forName("org.opensim.tracking.tools.ToolbarStopForwardAction"), true);
         JButton stopBtn = new JButton(stopFD);
         stopBtn.setPreferredSize(new Dimension(60,32));
         tb.add(stopBtn);
         tb.add(Box.createHorizontalStrut(3));
         //tb.add(new JLabel("simulate "+SimulationDB.getSimulationTime()+" sec."));
     } catch (ClassNotFoundException ex) {
         Exceptions.printStackTrace(ex);
     }
   //tb.addSeparator(new Dimension(10,40));
   return tb;
}