Java Code Examples for javax.swing.JToolBar#putClientProperty()

The following examples show how to use javax.swing.JToolBar#putClientProperty() . 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: ImageDetailProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
ImageTopComponent(Image image, String className, int instanceNumber) {
    setName(BrowserUtils.getSimpleType(className) + "#" + instanceNumber);
    setToolTipText("Preview of " + className + "#" + instanceNumber);
    setLayout(new BorderLayout());

    int width = image.getWidth(null);
    int height = image.getHeight(null);
    BufferedImage displayedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics g = displayedImage.createGraphics();
    drawChecker(g, 0, 0, width, height);
    g.drawImage(image, 0, 0, null);

    JComponent c = new JScrollPane(new JLabel(new ImageIcon(displayedImage)));
    add(c, BorderLayout.CENTER);


    JToolBar toolBar = new JToolBar();
    toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); //NOI18N
    toolBar.setFloatable(false);
    toolBar.setName(Bundle.ImageDetailProvider_Toolbar());

    //JButton button = new JButton();
    //button.setText("");
    toolBar.add(new ImageExportAction(image));
    add(toolBar, BorderLayout.NORTH);
}
 
Example 2
Source File: ToolBarLayout.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the ToolBarHandler attached to the specified toolbar as a client
 * property. If no handler is present, creates a new one and attaches it to
 * the toolbar.
 */
private Handler getHandler(final JToolBar toolbar) {
    if (toolbar == null)
        return null;

    Handler handler = extractHandler(toolbar);

    if (handler == null) // Ensure that the toolbar has a handler
    {
        final String key = Handler.TOOL_BAR_HANDLER_KEY;
        handler = new Handler(toolbar, this);
        toolbar.putClientProperty(key, handler);
    }

    return handler;
}
 
Example 3
Source File: ImageDetailProvider.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
ImageTopComponent(Image image, String className, int instanceNumber) {
    setName(BrowserUtils.getSimpleType(className) + "#" + instanceNumber);
    setToolTipText("Preview of " + className + "#" + instanceNumber);
    setLayout(new BorderLayout());

    int width = image.getWidth(null);
    int height = image.getHeight(null);
    BufferedImage displayedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics g = displayedImage.createGraphics();
    drawChecker(g, 0, 0, width, height);
    g.drawImage(image, 0, 0, null);

    JComponent c = new JScrollPane(new JLabel(new ImageIcon(displayedImage)));
    add(c, BorderLayout.CENTER);


    JToolBar toolBar = new JToolBar();
    toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); //NOI18N
    toolBar.setFloatable(false);
    toolBar.setName(Bundle.ImageDetailProvider_Toolbar());

    //JButton button = new JButton();
    //button.setText("");
    toolBar.add(new ImageExportAction(image));
    add(toolBar, BorderLayout.NORTH);
}
 
Example 4
Source File: ToolBarManager.java    From openAGV with Apache License 2.0 5 votes vote down vote up
/**
   *
   * @param toolBar
   * @param editor
   */
  private JToggleButton addDragToolButton(JToolBar toolBar, DrawingEditor editor) {
    final JToggleButton button = new JToggleButton();
    dragTool = new DragTool();
    editor.setTool(dragTool);

    if (!(toolBar.getClientProperty("toolHandler") instanceof ToolListener)) {
      ToolListener toolHandler = new ToolAdapter() {
        @Override
        public void toolDone(ToolEvent event) {
          button.setSelected(true);
        }
      };
      toolBar.putClientProperty("toolHandler", toolHandler);
    }

    URL url = getClass().getResource(ImageDirectory.DIR + "/toolbar/cursor-opened-hand.png");
    button.setIcon(new ImageIcon(url));
    button.setText(null);
    button.setToolTipText(ResourceBundleUtil.getBundle(I18nPlantOverview.TOOLBAR_PATH)
        .getString("toolBarManager.button_dragTool.tooltipText"));

    button.setSelected(false);
    button.addItemListener(new ToolButtonListener(dragTool, editor));
//    button.setFocusable(false);

    ButtonGroup group = (ButtonGroup) toolBar.getClientProperty("toolButtonGroup");
    group.add(button);
    toolBar.add(button);
    return button;
  }
 
Example 5
Source File: AbstractToolbarFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public JToolBar createToolbar(String containerCtx) {
    JToolBar result = new JToolBar();
    result.setName(containerCtx);
    result.putClientProperty (KEY_CONTAINERCTX, containerCtx);
    result.putClientProperty (KEY_CREATOR, this);
    attachToToolbar(containerCtx, result);
    populateToolbar(containerCtx, result); //XXX listener should do this
    return result;
}
 
Example 6
Source File: ProfilerToolbar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component add(ProfilerToolbar toolbar, int index) {
    JToolBar implToolbar = ((Impl)toolbar).toolbar;
    implToolbar.setBorder(BorderFactory.createEmptyBorder());
    implToolbar.setOpaque(false);
    implToolbar.putClientProperty("Toolbar.noGTKBorder", Boolean.TRUE); // NOI18N
    return add(implToolbar, index);
}
 
Example 7
Source File: ProfilerToolbar.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Component add(ProfilerToolbar toolbar, int index) {
    JToolBar implToolbar = ((Impl)toolbar).toolbar;
    implToolbar.setBorder(BorderFactory.createEmptyBorder());
    implToolbar.setOpaque(false);
    implToolbar.putClientProperty("Toolbar.noGTKBorder", Boolean.TRUE); // NOI18N
    return add(implToolbar, index);
}
 
Example 8
Source File: ImageViewer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Creates toolbar. */
    private JToolBar createToolBar() {
        // Definition of toolbar.
        JToolBar toolBar = new JToolBar();
        toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); //NOI18N
        toolBar.setFloatable (false);
        toolBar.setName (NbBundle.getBundle(ImageViewer.class).getString("ACSN_Toolbar"));
        toolBar.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACSD_Toolbar"));
            JButton outButton = new JButton(SystemAction.get(ZoomOutAction.class));
            outButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_ZoomOut"));
            outButton.setMnemonic(NbBundle.getBundle(ImageViewer.class).getString("ACS_Out_BTN_Mnem").charAt(0));
            outButton.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACSD_Out_BTN"));
            outButton.setText("");
        toolBar.add(outButton);       
        toolbarButtons.add(outButton);
            JButton inButton = new JButton(SystemAction.get(ZoomInAction.class));
            inButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_ZoomIn"));
            inButton.setMnemonic(NbBundle.getBundle(ImageViewer.class).getString("ACS_In_BTN_Mnem").charAt(0));
            inButton.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACSD_In_BTN"));
            inButton.setText("");
        toolBar.add(inButton);
        toolbarButtons.add(inButton);
        toolBar.addSeparator(new Dimension(11, 0));
        
        JButton button;
        
        toolBar.add(button = getZoomButton(1,1));
        toolbarButtons.add(button);
        toolBar.addSeparator(new Dimension(11, 0));
        toolBar.add(button = getZoomButton(1,3));
        toolbarButtons.add(button);
        toolBar.add(button = getZoomButton(1,5));
        toolbarButtons.add(button);
        toolBar.add(button = getZoomButton(1,7));
        toolbarButtons.add(button);
        toolBar.addSeparator(new Dimension(11, 0));
        toolBar.add(button = getZoomButton(3,1));
        toolbarButtons.add(button);
        toolBar.add(button = getZoomButton(5,1));
        toolbarButtons.add(button);
        toolBar.add(button = getZoomButton(7,1));
        toolbarButtons.add(button);
        toolBar.addSeparator(new Dimension(11, 0));
//        SystemAction sa = SystemAction.get(CustomZoomAction.class);
//        sa.putValue (Action.SHORT_DESCRIPTION, NbBundle.getBundle(ImageViewer.class).getString("LBL_CustomZoom"));
        toolBar.add (button = getZoomButton ());
        toolbarButtons.add(button);
        toolBar.addSeparator(new Dimension(11, 0));
        toolBar.add(button = getGridButton());
        toolbarButtons.add(button);
        
        // Image Dimension
        toolBar.addSeparator(new Dimension(11, 0));
        toolBar.add(new JLabel(NbBundle.getMessage(ImageViewer.class, "LBL_ImageDimensions", imageWidth, imageHeight)));

        // Image File Size in KB, MB
        if (imageSize != -1) {
            toolBar.addSeparator(new Dimension(11, 0));

            double kb = 1024.0;
            double mb = kb * kb;

            final double size;
            final String label;

            if (imageSize >= mb) {
                size = imageSize / mb;
                label = "LBL_ImageSizeMb"; // NOI18N
            } else if (imageSize >= kb) {
                size = imageSize / kb;
                label = "LBL_ImageSizeKb"; // NOI18N
            } else {
                size = imageSize;
                label = "LBL_ImageSizeBytes"; //NOI18N
            }

            toolBar.add(new JLabel(NbBundle.getMessage(ImageViewer.class, label, formatter.format(size))));
        }

        for (JButton jb : toolbarButtons) {
            jb.setFocusable(false);
        }

        return toolBar;
    }