Example usage for javax.swing JToolBar add

List of usage examples for javax.swing JToolBar add

Introduction

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

Prototype

public Component add(String name, Component comp) 

Source Link

Document

Adds the specified component to this container.

Usage

From source file:edu.ku.brc.af.core.TaskMgr.java

public static void addToolbarBtn(final Component toolBarComp, final int pos) {
    JToolBar toolBar = (JToolBar) UIRegistry.get(UIRegistry.TOOLBAR);
    if (toolBar != null) {
        toolBar.add(toolBarComp, pos);
    }//  w w  w  . j av  a 2 s  .co  m
}

From source file:fi.smaa.jsmaa.gui.SMAATRIGUIFactory.java

@Override
protected JToolBar buildBottomToolBar() {
    JToolBar tb = super.buildBottomToolBar();
    tb.add(new LambdaPanel(smaaModel), BorderLayout.EAST);
    return tb;/*  w  w  w  .ja v  a  2 s .c  o  m*/
}

From source file:edu.ku.brc.af.core.TaskMgr.java

/**
 * Registers the plugin's UI components with the various parts of the UI. If the requested position
 * is 'Position.AppendNextToLast' then it is appended and the ToolBar is set to adjust the last item to
 * the right. Note: If two items request Position.AppendNextToLast then the last one to do so is 
 * is adjusted right since they are appended.
 * @param plugin the plugin that will register it's UI
 *//*from w  w  w .j a va2 s  .  co  m*/
protected static void registerWithUI(final Taskable plugin) {
    boolean isVisible = false;

    JToolBar toolBar = (JToolBar) UIRegistry.get(UIRegistry.TOOLBAR);
    if (toolBar != null) {
        List<ToolBarItemDesc> toolBarItems = plugin.getToolBarItems();
        if (toolBarItems != null && toolBarItems.size() > 0) {
            isVisible = true;
            for (ToolBarItemDesc tbItem : toolBarItems) {
                Component toolBarComp = tbItem.getComp();
                if (tbItem.getPos() == ToolBarItemDesc.Position.Insert) {
                    toolBar.add(toolBarComp, tbItem.getIndex());

                } else if (tbItem.getPos() == ToolBarItemDesc.Position.Append) {
                    toolBar.add(toolBarComp);

                } else if (tbItem.getPos() == ToolBarItemDesc.Position.AdjustRightLastComp) {
                    toolBar.add(toolBarComp);
                    LayoutManager layout = toolBar.getLayout();
                    if (layout instanceof ToolbarLayoutManager) {
                        ((ToolbarLayoutManager) layout).setAdjustRightLastComp(true);
                    }

                } else if (tbItem.getPos() == ToolBarItemDesc.Position.AppendNextToLast) {
                    int inx = toolBar.getComponentCount();
                    if (inx > 0) {
                        inx -= 1;
                    }
                    toolBar.add(toolBarComp, inx);
                }
            } // for
        }
    } else {
        throw new NullPointerException("The Toolbar component cannot be null!"); //$NON-NLS-1$
    }

    // Load all the menu Items
    JMenuBar menuBar = (JMenuBar) UIRegistry.get(UIRegistry.MENUBAR);
    if (menuBar != null) {
        List<MenuItemDesc> menuItems = plugin.getMenuItems();
        if (menuItems != null) {
            for (MenuItemDesc menuItem : menuItems) {
                instance.menuHash.put(menuItem.getMenuPath(), menuItem.getMenuItem());
                String[] menuPath = split(menuItem.getMenuPath(), "/"); //$NON-NLS-1$
                buildMenuTree(menuBar, menuItem, menuPath, 0);
            }
        }
    } else {
        throw new NullPointerException("The MenuBar component cannot be null!"); //$NON-NLS-1$
    }

    if (isVisible) {
        instance.toolbarTasks.add(plugin);
    }
}

From source file:org.geopublishing.atlasViewer.swing.AtlasChartJPanel.java

/**
 * If {@link #previewMapPane} and {@link #mapLegend} are both not <code>null</code>
 * , this method adds a {@link JButton}/*from  ww  w  . j a v  a2s  .c  o  m*/
 * 
 * @param atlasChartPanel
 */
public void addZoomToFeatureExtends(final SelectableXMapPane myMapPane, final MapLegend mapLegend,
        final StyledFeaturesInterface<?> styledFeatures, AtlasChartJPanel atlasChartPanel) {
    if (myMapPane != null && mapLegend != null) {

        /**
         * Add a normal Button to zoom to the BBOX of the selected objects.
         */
        final SmallButton zoomToSelectionButton = new SmallButton(
                new AbstractAction("", SelectableChartPanel.ICON_ZOOM_TO_SELECTED) {

                    @Override
                    public void actionPerformed(final ActionEvent e) {

                        final StyledLayerSelectionModel<?> anySelectionModel = myMapPane != null
                                ? mapLegend.getRememberSelection(styledFeatures.getId())
                                : null;

                        if ((anySelectionModel instanceof StyledFeatureLayerSelectionModel)) {
                            final StyledFeatureLayerSelectionModel selectionModel = (StyledFeatureLayerSelectionModel) anySelectionModel;

                            final Vector<String> selectionIDs = selectionModel.getSelection();

                            try {

                                /*
                                 * Creating a set of FeatureIdImpl which can
                                 * be used for a FidFilter
                                 */
                                final HashSet<Identifier> setOfIdentifiers = new HashSet<Identifier>();
                                for (final String idString : selectionIDs) {
                                    setOfIdentifiers.add(new FeatureIdImpl(idString));
                                }

                                final FeatureCollection<SimpleFeatureType, SimpleFeature> selectedFeatures = styledFeatures
                                        .getFeatureSource()
                                        .getFeatures(FeatureUtil.FILTER_FACTORY2.id(setOfIdentifiers));
                                myMapPane.zoomTo(selectedFeatures);
                                myMapPane.refresh();

                            } catch (final IOException e1) {
                                throw new RuntimeException("While zooming to the selected features.", e1);
                            }

                        }

                    }

                });
        // zoomToSelectionButton.setBorder(BorderFactory
        // .createRaisedBevelBorder());
        zoomToSelectionButton.setToolTipText(GeotoolsGUIUtil
                .R("schmitzm.geotools.gui.SelectableFeatureTablePane.button.zoomToSelection.tt"));
        final JToolBar toolBar = atlasChartPanel.getToolBar();
        toolBar.add(zoomToSelectionButton, 6);

        {
            // Add listeners to the selection model, so we know when to
            // disable/enable the button

            // get the selectionmodel(s) of the chart
            List<FeatureDatasetSelectionModel<?, ?, ?>> datasetSelectionModelFor = FeatureChartUtil
                    .getFeatureDatasetSelectionModelFor(atlasChartPanel.getChart());
            for (final FeatureDatasetSelectionModel selModel : datasetSelectionModelFor) {

                DatasetSelectionListener listener_ZoomToSelectionButtonEnbled = new DatasetSelectionListener() {

                    @Override
                    public void selectionChanged(DatasetSelectionChangeEvent e) {
                        if (!e.getSource().getValueIsAdjusting()) {

                            // Update the clearSelectionButton
                            zoomToSelectionButton.setEnabled(selModel.getSelectedFeatures().size() > 0);
                        }
                    }
                };
                insertedListeners.add(listener_ZoomToSelectionButtonEnbled);
                selModel.addSelectionListener(listener_ZoomToSelectionButtonEnbled);

                zoomToSelectionButton.setEnabled(selModel.getSelectedFeatures().size() > 0);
            }
        }
    }
}

From source file:de.codesourcery.jasm16.ide.ui.views.SourceEditorView.java

protected JPanel createPanel() {
    // button panel
    final JToolBar toolbar = new JToolBar();
    toolbar.setLayout(new GridBagLayout());
    setColors(toolbar);/* w w  w . j av  a 2 s.co m*/

    final JButton showASTButton = new JButton("Show AST");
    setColors(showASTButton);

    showASTButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final boolean currentlyVisible = isASTInspectorVisible();
            if (currentlyVisible) {
                showASTButton.setText("Show AST");
            } else {
                showASTButton.setText("Hide AST");
            }
            if (currentlyVisible) {
                astInspector.setVisible(false);
            } else {
                showASTInspector();
            }

        }
    });

    GridBagConstraints cnstrs = constraints(0, 0, false, true, GridBagConstraints.NONE);
    toolbar.add(showASTButton, cnstrs);

    // navigation history back button
    cnstrs = constraints(1, 0, false, true, GridBagConstraints.NONE);
    toolbar.add(navigationHistoryBack, cnstrs);
    navigationHistoryBack.addActionListener(new ActionListener() {

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

    navigationHistoryBack.setEnabled(false);

    // navigation history forward button
    cnstrs = constraints(2, 0, true, true, GridBagConstraints.NONE);
    toolbar.add(navigationHistoryForward, cnstrs);
    navigationHistoryForward.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            navigationHistoryForward();
        }
    });
    navigationHistoryForward.setEnabled(false);

    // create status area
    statusArea.setPreferredSize(new Dimension(400, 100));
    statusArea.setModel(statusModel);
    setColors(statusArea);

    /**
     * TOOLBAR
     * SOURCE
     * cursor position
     * status area 
     */
    final JPanel topPanel = new JPanel();
    topPanel.setLayout(new GridBagLayout());

    cnstrs = constraints(0, 0, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.weighty = 0;
    topPanel.add(toolbar, cnstrs);

    cnstrs = constraints(0, 1, GridBagConstraints.BOTH);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.weighty = 1.0;
    topPanel.add(super.getPanel(), cnstrs);

    final JPanel bottomPanel = new JPanel();
    bottomPanel.setLayout(new GridBagLayout());

    statusArea.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);

    statusArea.addMouseListener(new MouseAdapter() {

        public void mouseClicked(java.awt.event.MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
                final int viewRow = statusArea.rowAtPoint(e.getPoint());
                if (viewRow != -1) {
                    final int modelRow = statusArea.convertRowIndexToModel(viewRow);
                    StatusMessage message = statusModel.getMessage(modelRow);
                    if (message.getLocation() != null) {
                        moveCursorTo(message.getLocation(), true);
                    }
                }
            }
        };
    });

    EditorContainer.addEditorCloseKeyListener(statusArea, this);

    statusArea.setFillsViewportHeight(true);
    statusArea.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    final JScrollPane statusPane = new JScrollPane(statusArea);
    setColors(statusPane);

    statusPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    statusPane.setPreferredSize(new Dimension(400, 100));
    statusPane.setMinimumSize(new Dimension(100, 20));

    cnstrs = constraints(0, 0, GridBagConstraints.BOTH);
    cnstrs.weightx = 1;
    cnstrs.weighty = 1;
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = GridBagConstraints.REMAINDER;

    bottomPanel.add(statusPane, cnstrs);

    // setup result panel
    final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, bottomPanel);
    setColors(splitPane);

    final JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    setColors(panel);
    cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH);
    panel.add(splitPane, cnstrs);

    final AncestorListener l = new AncestorListener() {

        @Override
        public void ancestorRemoved(AncestorEvent event) {
        }

        @Override
        public void ancestorMoved(AncestorEvent event) {
        }

        @Override
        public void ancestorAdded(AncestorEvent event) {
            splitPane.setDividerLocation(0.8d);
        }
    };
    panel.addAncestorListener(l);
    return panel;
}

From source file:ome.formats.importer.gui.FileQueueChooser.java

/**
 * File chooser on the file picker tab of the importer
 * /*from w w  w  . j av  a2  s. c o m*/
 * @param config ImportConfig
 * @param scanReader OmeroWrapper
 */
FileQueueChooser(ImportConfig config, OMEROWrapper scanReader) {

    try {
        JPanel fp = null;
        JToolBar tb = null;

        String refreshIcon = "gfx/recycled12.png";
        refreshBtn = GuiCommonElements.addBasicButton("Refresh ", refreshIcon, null);
        refreshBtn.setActionCommand(REFRESHED);
        refreshBtn.addActionListener(this);
        JPanel panel = new JPanel();

        // Set up the main panel for tPane, quit, and send buttons
        double mainTable[][] = { { 10, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL, 10 }, // columns
                { TableLayout.PREFERRED } }; // rows

        TableLayout tl = new TableLayout(mainTable);
        panel.setLayout(tl);

        // Here's a nice little pieces of test code to find all components
        if (DEBUG) {
            try {
                Component[] components = this.getComponents();
                Component component = null;
                System.err.println("Components: " + components.length);
                for (int i = 0; i < components.length; i++) {
                    component = components[i];
                    System.err.println("Component " + i + " = " + component.getClass());
                }
            } catch (Exception e) {
                log.info("component exception ignore");
            }
        }

        if (laf.contains("AquaLookAndFeel")) {
            //Do Aqua implimentation
            fp = (JPanel) this.getComponent(1);
            fp.setLayout(new BoxLayout(fp, BoxLayout.X_AXIS));
            fp.add(refreshBtn);
        } else if (laf.contains("QuaquaLookAndFeel")) {
            //do Quaqua implimentation
            fp = (JPanel) this.getComponent(1);
            panel.add(refreshBtn, "1,0,C,C");
            panel.add(fp.getComponent(0), "2,0,C,C");
            fp.add(panel, BorderLayout.NORTH);
        } else if (laf.contains("Windows")) {
            try {
                //Do windows implimentation
                tb = (JToolBar) this.getComponent(1);
                refreshBtn.setToolTipText("Refresh");
                refreshBtn.setText(null);
                tb.add(refreshBtn, 8);
            } catch (Exception e) {
                log.info("Exception ignored.");
            }
        }
        /* Disabled temporarily */
        else if (laf.contains("MetalLookAndFeel")) {
            //Do Metal implimentation
            JPanel prefp = (JPanel) this.getComponent(0);
            fp = (JPanel) prefp.getComponent(0);
            refreshBtn.setToolTipText("Refresh");
            refreshBtn.setText(null);
            Dimension size = new Dimension(24, 24);
            refreshBtn.setMaximumSize(size);
            refreshBtn.setPreferredSize(size);
            refreshBtn.setMinimumSize(size);
            refreshBtn.setSize(size);
            fp.add(Box.createRigidArea(new Dimension(5, 0)));
            fp.add(refreshBtn);
        }

        else if (laf.contains("GTKLookAndFeel")) {
            //do GTK implimentation
            fp = (JPanel) this.getComponent(0);
            refreshBtn.setIcon(null);
            fp.add(refreshBtn);
        } else if (laf.contains("MotifLookAndFeel")) {
            //do Motif implimentation
            fp = (JPanel) this.getComponent(0);
            fp.add(refreshBtn);
        }

        if (fp != null && DEBUG == true) {
            fp.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                    fp.getBorder()));
            System.err.println(fp.getLayout());
        }

        if (tb != null && DEBUG == true) {
            tb.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                    tb.getBorder()));
            System.err.println(tb.getLayout());
        }
    } catch (ArrayIndexOutOfBoundsException e) {
    }

    File dir = null;
    if (config != null)
        dir = config.savedDirectory.get();

    if (dir != null) {
        this.setCurrentDirectory(dir);
    } else {
        this.setCurrentDirectory(this.getFileSystemView().getHomeDirectory());
    }

    this.setControlButtonsAreShown(false);
    this.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    this.setMultiSelectionEnabled(true);
    this.setDragEnabled(true);

    setAcceptAllFileFilterUsed(false);

    FileFilter[] originalFF = null;
    int readerFFSize = 0;
    if (scanReader != null) {
        originalFF = loci.formats.gui.GUITools.buildFileFilters(scanReader.getImageReader());
        FileFilter filter;
        List<FileFilter> extensionFilters = new ArrayList<FileFilter>();
        for (int i = 0; i < originalFF.length; i++) {
            filter = originalFF[i];
            if (filter instanceof ComboFileFilter) {
                ComboFileFilter cff = (ComboFileFilter) filter;
                extensionFilters.add(cff);
                extensionFilters.addAll(Arrays.asList(cff.getFilters()));
                break;
            }
        }
        if (extensionFilters != null) {
            originalFF = extensionFilters.toArray(new FileFilter[extensionFilters.size()]);
        }
        readerFFSize = originalFF.length;
    }

    FileFilter[] ff = new FileFilter[readerFFSize + 7];
    ff[0] = new DashFileFilter();
    ff[readerFFSize + 1] = new DashFileFilter();
    ff[readerFFSize + 2] = new R3DNewFileFilter();
    ff[readerFFSize + 3] = new R3DOldFileFilter();
    ff[readerFFSize + 4] = new D3DNewFileFilter();
    ff[readerFFSize + 5] = new D3DOldFileFilter();
    ff[readerFFSize + 6] = new D3DNPrjFileFilter();

    if (originalFF != null)
        System.arraycopy(originalFF, 0, ff, 1, originalFF.length);

    //this.addChoosableFileFilter(new DashFileFilter());

    //FileFilter combo = null;
    for (int i = 0; i < ff.length; i++)
        this.addChoosableFileFilter(ff[i]);
    this.setFileFilter(ff[1]);

    //Retrieve all JLists and JTables from the fileChooser
    fileListObjects = getFileListObjects(this);

    //For now, assume the first list/table found is the correct one
    //(this will need to be adjusted if LAF bugs crop up)
    //Shouldn't break anything since dblclick will just stop working if
    //this changes for some reason
    if (fileListObjects.length > 0 && !laf.contains("Windows")) {
        fileList = fileListObjects[0];
        MouseCommand mc = new MouseCommand();
        fileList.addMouseListener(mc);
    }
}

From source file:verdandi.ui.ProjectViewerPanel.java

private JToolBar getToolbar() {
    // JPanel toolbar = new JPanel();
    // toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.LINE_AXIS));
    JToolBar toolbar = new JToolBar(SwingConstants.HORIZONTAL);

    toolbar.setLayout(new GridBagLayout());

    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;//from ww  w  . ja  v a 2  s  .c om
    c.gridy = 0;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.WEST;
    c.weightx = 0.0;
    c.weighty = 0.0;

    URL imageURL = null;
    imageURL = Thread.currentThread().getContextClassLoader()
            .getResource(THEME_RC.getString("icon.project.add"));
    ImageIcon addProjectIcon = new ImageIcon(imageURL, "add");

    JButton addProject = new JButton(addProjectIcon);
    addProject.setActionCommand(CMD_ADD_PROJECT);
    addProject.setToolTipText(RB.getString("projectviewer.add.tooltip"));
    addProject.addActionListener(this);
    toolbar.add(addProject, c);
    c.gridx++;

    imageURL = getClass().getClassLoader().getResource(THEME_RC.getString("icon.project.edit"));
    ImageIcon editProjectIcon = new ImageIcon(imageURL, "edit");

    JButton editProject = new JButton(editProjectIcon);
    editProject.setActionCommand(CMD_EDIT_PROJECT);
    editProject.setToolTipText(RB.getString("projectviewer.edit.tooltip"));
    editProject.addActionListener(this);
    toolbar.add(editProject, c);
    c.gridx++;

    imageURL = getClass().getClassLoader().getResource(THEME_RC.getString("icon.projects.import"));
    ImageIcon importProjectIcon = new ImageIcon(imageURL, "import");
    JButton importProject = new JButton(importProjectIcon);
    importProject.setActionCommand(CMD_IMPORT_PROJECT);
    importProject.setToolTipText(RB.getString("projectviewer.import.tooltip"));
    importProject.addActionListener(this);
    toolbar.add(importProject, c);
    c.gridx++;

    // THEME_RC.getString("")
    imageURL = getClass().getClassLoader().getResource(THEME_RC.getString("icon.projects.export"));
    ImageIcon exportProjectIcon = new ImageIcon(imageURL, "export");
    JButton exportProject = new JButton(exportProjectIcon);
    exportProject.setActionCommand(CMD_EXPORT_PROJECT);
    exportProject.setToolTipText(RB.getString("projectviewer.export.tooltip"));
    exportProject.addActionListener(this);
    toolbar.add(exportProject, c);
    c.gridx++;

    toolbar.add(new JToolBar.Separator(), c);
    c.gridx++;

    imageURL = getClass().getClassLoader().getResource(THEME_RC.getString("icon.project.hide.active"));
    hideActiveIcon = new ImageIcon(imageURL, "hide active");
    imageURL = getClass().getClassLoader().getResource(THEME_RC.getString("icon.project.show.active"));
    showActiveIcon = new ImageIcon(imageURL, "show active");
    toggleShowActive = new JToggleButton(hideActiveIcon);
    toggleShowActive.setActionCommand(CMD_TOGGLE_SHOW_ACTIVE);
    toggleShowActive.setToolTipText(RB.getString("projectviewer.toggleshowactive.tooltip"));
    toggleShowActive.addActionListener(this);
    toolbar.add(toggleShowActive, c);
    c.gridx++;

    c.weightx = 0.5;
    toolbar.add(Box.createHorizontalGlue(), c);
    c.weightx = 0.0;
    c.gridx++;

    c.insets = new Insets(0, 5, 0, 5);
    toolbar.add(new JLabel("Filter"), c);
    c.gridx++;
    c.insets = new Insets(0, 0, 0, 0);
    searchField = new JTextField(10);
    searchField.getDocument().addDocumentListener(this);
    searchField.setToolTipText(RB.getString("projectviewer.searchfield.tooltip"));
    toolbar.add(searchField, c);

    toolbar.setFloatable(false);
    return toolbar;
}