Example usage for javax.swing JToolBar JToolBar

List of usage examples for javax.swing JToolBar JToolBar

Introduction

In this page you can find the example usage for javax.swing JToolBar JToolBar.

Prototype

public JToolBar() 

Source Link

Document

Creates a new tool bar; orientation defaults to HORIZONTAL.

Usage

From source file:org.jab.docsearch.DocSearch.java

private JToolBar createToolBar() {

    // tool bar/*from w  ww .ja va 2 s .c  o  m*/
    JToolBar toolBar = new JToolBar();

    // file open
    JButton buttonOpen = new JButton(new ImageIcon(getClass().getResource("/icons/fileopen.png")));
    buttonOpen.setToolTipText(I18n.getString("tooltip.open"));
    buttonOpen.setActionCommand("ac_open");
    buttonOpen.addActionListener(this);
    buttonOpen.setMnemonic(KeyEvent.VK_O);
    buttonOpen.setEnabled(!env.isWebStart()); // disable in WebStart
    toolBar.add(buttonOpen);

    // file save
    JButton buttonSave = new JButton(new ImageIcon(getClass().getResource("/icons/filesave.png")));
    buttonSave.setToolTipText(I18n.getString("tooltip.save"));
    buttonSave.setActionCommand("ac_save");
    buttonSave.addActionListener(this);
    buttonSave.setMnemonic(KeyEvent.VK_S);
    buttonSave.setEnabled(!env.isWebStart()); // disable in WebStart
    toolBar.add(buttonSave);
    toolBar.addSeparator();

    // open browser
    JButton buttonBrowser = new JButton(new ImageIcon(getClass().getResource("/icons/html.png")));
    buttonBrowser.setToolTipText(I18n.getString("tooltip.open_in_browser"));
    buttonBrowser.setActionCommand("ac_openinbrowser");
    buttonBrowser.addActionListener(this);
    buttonBrowser.setMnemonic(KeyEvent.VK_E);
    buttonBrowser.setEnabled(!env.isWebStart()); // disable in WebStart
    toolBar.add(buttonBrowser);
    toolBar.addSeparator();

    // home
    JButton buttonHome = new JButton(new ImageIcon(getClass().getResource("/icons/home.png")));
    buttonHome.setToolTipText(I18n.getString("tooltip.home"));
    buttonHome.setActionCommand("ac_home");
    buttonHome.addActionListener(this);
    buttonHome.setMnemonic(KeyEvent.VK_H);
    toolBar.add(buttonHome);

    // refresh
    JButton buttonRefresh = new JButton(new ImageIcon(getClass().getResource("/icons/refresh.png")));
    buttonRefresh.setToolTipText(I18n.getString("tooltip.refresh"));
    buttonRefresh.setActionCommand("ac_refresh");
    buttonRefresh.addActionListener(this);
    buttonRefresh.setMnemonic(KeyEvent.VK_L);
    toolBar.add(buttonRefresh);
    toolBar.addSeparator();

    // result
    JButton buttonResult = new JButton(new ImageIcon(getClass().getResource("/icons/search_results.png")));
    buttonResult.setToolTipText(I18n.getString("tooltip.results"));
    buttonResult.setActionCommand("ac_result");
    buttonResult.addActionListener(this);
    buttonResult.setMnemonic(KeyEvent.VK_R);
    toolBar.add(buttonResult);
    toolBar.addSeparator();

    // bookmark
    JButton buttonBookMark = new JButton(new ImageIcon(getClass().getResource("/icons/bookmark.png")));
    buttonBookMark.setToolTipText(I18n.getString("tooltip.add_bookmark"));
    buttonBookMark.setActionCommand("ac_addbookmark");
    buttonBookMark.addActionListener(this);
    buttonBookMark.setMnemonic(KeyEvent.VK_M);
    toolBar.add(buttonBookMark);
    toolBar.addSeparator();

    // print
    JButton buttonPrint = new JButton(new ImageIcon(getClass().getResource("/icons/fileprint.png")));
    buttonPrint.setToolTipText(I18n.getString("tooltip.print"));
    buttonPrint.setActionCommand("ac_print");
    buttonPrint.addActionListener(this);
    buttonPrint.setMnemonic(KeyEvent.VK_P);
    toolBar.add(buttonPrint);
    toolBar.addSeparator();

    // setting
    JButton buttonSetting = new JButton(new ImageIcon(getClass().getResource("/icons/configure.png")));
    buttonSetting.setToolTipText(I18n.getString("tooltip.settings"));
    buttonSetting.setActionCommand("ac_settings");
    buttonSetting.addActionListener(this);
    buttonSetting.setMnemonic(KeyEvent.VK_HOME);
    toolBar.add(buttonSetting);
    toolBar.addSeparator();

    // stop
    buttonStop = new JButton(new ImageIcon(getClass().getResource("/icons/stop.png")));
    buttonStop.setToolTipText(I18n.getString("tooltip.stop"));
    buttonStop.setActionCommand("ac_stop");
    buttonStop.addActionListener(this);
    buttonStop.setMnemonic(KeyEvent.VK_X);
    toolBar.add(buttonStop);
    toolBar.addSeparator();

    //
    toolBar.setFloatable(false);

    // finished
    return toolBar;
}

From source file:org.jcurl.demo.tactics.JCurlShotPlanner.java

private JComponent createToolBar() {
    final String[] toolbarActionNames = { "cut", "copy", "paste" };
    final JToolBar toolBar = new JToolBar();
    toolBar.setFloatable(false);/*from w w  w .  j  a v a  2  s  . com*/
    for (final String actionName : toolbarActionNames) {
        final JButton button = new JButton();
        button.setAction(gui.findAction(actionName));
        button.setFocusable(false);
        toolBar.add(button);
    }
    return toolBar;
}

From source file:org.kepler.gui.KeplerGraphFrame.java

/**
 * Override BasicGraphFrame._initBasicGraphFrame()
 *///from  w w w  .  ja  v  a  2  s . c  o  m
@Override
protected void _initBasicGraphFrame() {

    /**
     * @todo - FIXME - Need to move this further up the hierarchy, so other
     *       types of frames use it too. Don't put it in a launcher class
     *       like KeplerApplication, because it then gets overridden later,
     *       elsewhere in PTII
     */
    StaticGUIResources.setLookAndFeel();

    _initBasicGraphFrameInitialization();

    _dropTarget = BasicGraphFrameExtension.getDropTarget(_jgraph);

    // add a CanvasDropTargetListener so that other classes can get
    CanvasDropTargetListener listener = CanvasDropTargetListener.getInstance();
    _dropTarget.registerAdditionalListener(listener);

    ActionListener deletionListener = new DeletionListener();

    _rightComponent.registerKeyboardAction(deletionListener, "Delete",
            KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    _rightComponent.registerKeyboardAction(deletionListener, "BackSpace",
            KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    _initBasicGraphFrameRightComponent();

    _jgraph.setRequestFocusEnabled(true);

    // Background color is parameterizable by preferences.
    Configuration configuration = getConfiguration();

    if (configuration != null) {
        try {
            // Set the PtolemyPreference to the desired background.
            // See
            // http://bugzilla.ecoinformatics.org/show_bug.cgi?id=2321#c14
            PtolemyPreferences preferences = PtolemyPreferences
                    .getPtolemyPreferencesWithinConfiguration(configuration);
            if (_isDebugging) {
                _log.debug("bg: " + BACKGROUND_COLOR);
            }
            if (preferences != null) {
                float[] components = new float[4];
                // Make sure we get only 4 elements in case the color space
                // is bigger than 4
                components = BACKGROUND_COLOR.getComponents(components);
                preferences.backgroundColor.setExpression("{" + components[0] + "," + components[1] + ","
                        + components[2] + "," + components[3] + "}");
                _rightComponent.setBackground(preferences.backgroundColor.asColor());
                if (_isDebugging) {
                    _log.debug("desired background: " + BACKGROUND_COLOR + " actual background:  "
                            + preferences.backgroundColor.asColor());
                }
            }
        } catch (IllegalActionException e1) {
            // Ignore the exception and use the default color.
        }
    }

    _initBasicGraphFrameRightComponentMouseListeners();

    try {
        // The SizeAttribute property is used to specify the size
        // of the JGraph component. Unfortunately, with Swing's
        // mysterious and undocumented handling of component sizes,
        // there appears to be no way to control the size of the
        // JGraph from the size of the Frame, which is specified
        // by the WindowPropertiesAttribute.
        SizeAttribute size = (SizeAttribute) getModel().getAttribute("_vergilSize", SizeAttribute.class);
        if (size != null) {
            size.setSize(_jgraph);
        } else {
            // Set the default size.
            // Note that the location is of the frame, while the size
            // is of the scrollpane.
            _jgraph.setPreferredSize(new Dimension(600, 400));
        }

        _initBasicGraphFrameSetZoomAndPan();
    } catch (Exception ex) {
        // Ignore problems here. Errors simply result in a default
        // size and location.
    }

    // Create the panner.
    _graphPanner = new JCanvasPanner(_jgraph);

    _horizontalScrollBar = new JScrollBar(Adjustable.HORIZONTAL);
    _verticalScrollBar = new JScrollBar(Adjustable.VERTICAL);

    // see if we want scrollbars on the canvas or not
    // the answer defaults to 'no'
    CanvasNavigationModifierFactory CNMfactory = (CanvasNavigationModifierFactory) getConfiguration()
            .getAttribute("canvasNavigationModifier");
    if (CNMfactory != null) { // get the scrollbar flag from the factory if
        // it exists in the config
        ScrollBarModifier modifier = CNMfactory.createScrollBarModifier();
        _scrollBarFlag = modifier.getScrollBarModifier();
    }

    _canvasPanel = new JPanel();

    _canvasPanel.setBorder(null);
    _canvasPanel.setLayout(new BorderLayout());

    if (_scrollBarFlag) {
        _canvasPanel.add(_horizontalScrollBar, BorderLayout.SOUTH);
        _canvasPanel.add(_verticalScrollBar, BorderLayout.EAST);
        _horizontalScrollBar.setModel(_jgraph.getGraphPane().getCanvas().getHorizontalRangeModel());
        _verticalScrollBar.setModel(_jgraph.getGraphPane().getCanvas().getVerticalRangeModel());
        _horizontalScrollBarListener = new ScrollBarListener(_horizontalScrollBar);
        _verticalScrollBarListener = new ScrollBarListener(_verticalScrollBar);
        _horizontalScrollBar.addAdjustmentListener(_horizontalScrollBarListener);
        _verticalScrollBar.addAdjustmentListener(_verticalScrollBarListener);
    }

    // NOTE: add _rightComponent instead of _jgraph since _rightComponent
    // may be sub-divided into tabbed panes.
    // see http://bugzilla.ecoinformatics.org/show_bug.cgi?id=3708
    _canvasPanel.add(_rightComponent, BorderLayout.CENTER);

    TabManager tabman = TabManager.getInstance();
    tabman.initializeTabs(this);

    ViewManager viewman = ViewManager.getInstance();
    viewman.initializeViews(this);
    try {
        viewman.addCanvasToLocation(_canvasPanel, this);
    } catch (Exception e) {
        throw new RuntimeException("Could not add canvas panel: " + e.getMessage());
    }

    // _jgraph.setMinimumSize(new Dimension(0, 0));

    getContentPane().add(viewman.getViewArea(this), BorderLayout.CENTER);

    // The toolbar panel is the container that contains the main toolbar and
    // any additional toolbars
    JPanel toolbarPanel = new JPanel();
    toolbarPanel.setLayout(new BoxLayout(toolbarPanel, BoxLayout.Y_AXIS)); // They
    // stack
    _toolbar = new JToolBar(); // The main Kepler toolbar
    toolbarPanel.add(_toolbar);
    getContentPane().add(toolbarPanel, BorderLayout.NORTH); // Place the
    // toolbar panel
    _initBasicGraphFrameToolBarZoomButtons();

    _initBasicGraphFrameActions();

    // Add a weak reference to this to keep track of all
    // the graph frames that have been created.
    _openGraphFrames.add(this);

    System.gc();
}

From source file:org.kuali.test.creator.TestCreator.java

private JPanel createToolBar() {
    JPanel retval = new JPanel(new BorderLayout(2, 2));

    JToolBar toolbar = new JToolBar();
    toolbar.setFloatable(false);/*from www.  ja  v  a2  s  . c o m*/
    toolbar.setMargin(new Insets(1, 5, 2, 0));
    ToolbarButton b;
    toolbar.add(b = new ToolbarButton(Constants.PLATFORM_TOOLBAR_ICON, "add platform"));
    b.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            handleAddPlatform(e);
        }

    });
    toolbar.add(b = new ToolbarButton(Constants.DATABASE_TOOLBAR_ICON, "add database connection"));
    b.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            handleAddDatabaseConnection(e);
        }

    });
    toolbar.add(b = new ToolbarButton(Constants.JMX_CONNECTION_TOOLBAR_ICON, "add JMX connection"));
    b.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            handleAddJmxConnection(e);
        }

    });

    toolbar.add(b = new ToolbarButton(Constants.WEB_SERVICE_TOOLBAR_ICON, "add web service"));
    b.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            handleAddWebService(e);
        }

    });

    toolbar.add(b = new ToolbarButton(Constants.SCHEDULE_TEST_TOOLBAR_ICON, "schedule test"));
    b.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            handleScheduleTests(e);
        }

    });

    toolbar.addSeparator();

    toolbar.add(saveConfigurationButton = new ToolbarButton(Constants.SAVE_CONFIGURATION_ICON,
            "save repository configuration") {
        @Override
        public void setEnabled(boolean enabled) {
            if (enabled) {
                getConfiguration().setModified(true);
            }

            super.setEnabled(enabled);
        }
    });
    saveConfigurationButton.setEnabled(false);
    saveConfigurationButton.setMargin(new Insets(1, 1, 1, 1));
    saveConfigurationButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            handleSaveConfiguration();
        }
    });

    toolbar.add(createTestButton = new ToolbarButton(Constants.TEST_ICON, "create new test"));
    createTestButton.setMargin(new Insets(1, 1, 1, 1));

    createTestButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            handleCreateTest(null);
        }
    });

    toolbar.addSeparator();

    toolbar.add(
            exitApplication = new ToolbarButton(Constants.EXIT_APPLICATION_TOOLBAR_ICON, "exit application"));

    exitApplication.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showConfirmDialog(TestCreator.this, "Exit Test Application?", "Exit",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                startSpinner("Shutting down application...");
                handleExit(0);
            }
        }
    });

    toolbar.addSeparator();

    toolbar.add(spinner = new Spinner());
    toolbar.add(spinner2 = new Spinner(true));

    retval.add(new JSeparator(), BorderLayout.NORTH);
    retval.add(toolbar, BorderLayout.CENTER);

    this.enableCreateTestActions(havePlatforms());

    return retval;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.AnnotationDataUI.java

/**
 * Creates a tool bar and adds the passed buttons to it.
 * /*from  w ww  .j  ava 2  s  . c  om*/
 * @param addButton The button to add.
 * @param removeButton The button to add.
 * @return See above.
 */
private JToolBar createBar(JButton addButton, JButton removeButton) {
    JToolBar bar = new JToolBar();
    bar.setFloatable(false);
    bar.setBorder(null);
    bar.setBackground(UIUtilities.BACKGROUND_COLOR);
    if (addButton != null)
        bar.add(addButton);
    if (removeButton != null)
        bar.add(removeButton);
    return bar;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.DocComponent.java

/** Builds and lays out the UI. */
private void buildGUI() {
    setBackground(UIUtilities.BACKGROUND_COLOR);
    setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
    add(label);/*from   w  ww .j  a  v a2  s .c o m*/
    JToolBar bar = new JToolBar();
    bar.setBackground(UIUtilities.BACKGROUND_COLOR);
    bar.setFloatable(false);
    bar.setRollover(true);
    bar.setBorder(null);
    bar.setOpaque(true);
    boolean b = setControlsEnabled(data != null);
    int count = 0;
    if (editButton != null)
        count++;
    if (unlinkButton != null)
        count++;
    if (downloadButton != null)
        count++;
    if (infoButton != null)
        count++;
    if (openButton != null)
        count++;
    if (count > 0 && data != null) {
        menuButton.setEnabled(true);
        if (model.isAcrossGroups())
            menuButton.setEnabled(false);
        bar.add(menuButton);
        if (!b)
            bar.add(Box.createHorizontalStrut(8));
        add(bar);
    }
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.OriginalMetadataComponent.java

/** 
 * Builds the tool bar.//from   ww w.ja v a2 s  .  co  m
 * 
 * @return See above.
 */
private JComponent buildToolBar() {
    JToolBar bar = new JToolBar();
    bar.setFloatable(false);
    bar.setRollover(true);
    bar.setBorder(null);
    bar.add(downloadButton);
    return bar;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java

/**
 * Lays out the components using a <code>FlowLayout</code>.
 * //from www . j ava  2  s.c o  m
 * @param button    The component to lay out.
 * @param component   The component to lay out.
 * @param sizeRow   The size of the row.
 * @return See above.
 */
private JPanel layoutEditablefield(Component button, JComponent component, int sizeRow) {
    JPanel p = new JPanel();
    p.setBackground(UIUtilities.BACKGROUND_COLOR);
    p.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(0, 2, 2, 0);
    c.gridy = 0;
    c.gridx = 0;
    if (button != null) {
        JToolBar bar = new JToolBar();
        bar.setBorder(null);
        bar.setFloatable(false);
        bar.setBackground(UIUtilities.BACKGROUND_COLOR);
        bar.add(button);
        p.add(bar, c);
        c.gridx++;
    }
    if (sizeRow > 0) {
        c.ipady = sizeRow;
        c.gridheight = 2;
    }
    p.add(component, c);
    JPanel content = UIUtilities.buildComponentPanel(p, 0, 0);
    content.setBackground(UIUtilities.BACKGROUND_COLOR);
    return content;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.ToolBar.java

/** 
 * Builds the general bar./*from  w  w w. j  a  v a2s  .c o m*/
 * 
 * @return See above.
 */
private JComponent buildGeneralBar() {
    JToolBar bar = new JToolBar();
    bar.setBackground(UIUtilities.BACKGROUND_COLOR);
    bar.setFloatable(false);
    bar.setRollover(true);
    bar.setBorder(null);
    bar.add(saveButton);
    bar.add(Box.createHorizontalStrut(5));
    bar.add(refreshButton);
    bar.add(Box.createHorizontalStrut(5));
    bar.add(viewButton);
    bar.add(Box.createHorizontalStrut(5));
    bar.add(linkButton);
    bar.add(Box.createHorizontalStrut(5));
    bar.add(saveAsButton);
    bar.add(Box.createHorizontalStrut(5));
    bar.add(publishingButton);
    /*
    if (MetadataViewerAgent.isAdministrator()) {
       bar.add(Box.createHorizontalStrut(5));
        bar.add(uploadScriptButton);
    }
    bar.add(Box.createHorizontalStrut(5));
    bar.add(scriptsButton);
    */
    //bar.add(scriptsButton);
    return bar;
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/** Helper method to create the menu bar. */
private void createMenuBars() {
    rightMenuBar = new JToolBar();
    rightMenuBar.setBorder(null);/*  w  ww  . ja  v a  2s .c o  m*/
    rightMenuBar.setRollover(true);
    rightMenuBar.setFloatable(false);

    JButton button;
    leftMenuBar = new JToolBar();
    leftMenuBar.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 0));
    leftMenuBar.setRollover(true);
    leftMenuBar.setFloatable(false);
    BrowserManageAction a;
    int type = model.getBrowserType();
    switch (type) {
    case Browser.PROJECTS_EXPLORER:
    case Browser.SCREENS_EXPLORER:
        a = (BrowserManageAction) controller.getAction(BrowserControl.NEW_CONTAINER);
        button = new JButton(a);
        button.setName("new container button");
        button.setBorderPainted(false);
        button.addMouseListener(a);
        rightMenuBar.add(button);
        break;
    case Browser.ADMIN_EXPLORER:
        a = (BrowserManageAction) controller.getAction(BrowserControl.NEW_ADMIN);
        button = new JButton(a);
        button.setName("new group or user button");
        button.setBorderPainted(false);
        button.addMouseListener(a);
        rightMenuBar.add(button);
        break;
    case Browser.TAGS_EXPLORER:
        a = (BrowserManageAction) controller.getAction(BrowserControl.NEW_TAG);
        button = new JButton(a);
        button.setName("new tag button");
        button.setBorderPainted(false);
        button.addMouseListener(a);
        rightMenuBar.add(button);
    }
    button = new JButton(controller.getAction(BrowserControl.CUT));
    button.setName("cut button");
    button.setBorderPainted(false);
    rightMenuBar.add(button);
    button = new JButton(controller.getAction(BrowserControl.COPY));
    button.setName("copy button");
    button.setBorderPainted(false);
    rightMenuBar.add(button);
    button = new JButton(controller.getAction(BrowserControl.PASTE));
    button.setName("paste button");
    button.setBorderPainted(false);
    rightMenuBar.add(button);
    button = new JButton(controller.getAction(BrowserControl.DELETE));
    button.setName("delete button");
    button.setBorderPainted(false);
    rightMenuBar.add(button);
    button = new JButton(controller.getAction(BrowserControl.REFRESH));
    button.setName("refresh button");
    button.setBorderPainted(false);
    rightMenuBar.add(button);

    if (type == Browser.ADMIN_EXPLORER) {
        button = new JButton(controller.getAction(BrowserControl.RESET_PASSWORD));
        button.setBorderPainted(false);
        rightMenuBar.add(button);
    } else {
        button = new JButton(controller.getAction(BrowserControl.IMPORT));
        button.setBorderPainted(false);
        //rightMenuBar.add(button);
    }
    rightMenuBar.add(Box.createHorizontalStrut(6));
    rightMenuBar.add(new JSeparator());
    rightMenuBar.add(Box.createHorizontalStrut(6));
    ButtonGroup group = new ButtonGroup();
    JToggleButton b = new JToggleButton();
    group.add(b);
    b.setBorderPainted(true);
    b.setSelected(true);
    b.setAction(controller.getAction(BrowserControl.SORT));

    rightMenuBar.add(b);
    b = new JToggleButton(controller.getAction(BrowserControl.SORT_DATE));
    b.setBorderPainted(true);
    group.add(b);
    rightMenuBar.add(b);

    partialButton = new JToggleButton(controller.getAction(BrowserControl.PARTIAL_NAME));
    partialButton.setBorderPainted(true);
    rightMenuBar.add(partialButton);
    rightMenuBar.add(new JSeparator(JSeparator.VERTICAL));
    button = new JButton(controller.getAction(BrowserControl.COLLAPSE));
    button.setBorderPainted(false);
    rightMenuBar.add(button);
}