Example usage for javax.swing JToolBar getComponentCount

List of usage examples for javax.swing JToolBar getComponentCount

Introduction

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

Prototype

public int getComponentCount() 

Source Link

Document

Gets the number of components in this panel.

Usage

From source file:ec.nbdemetra.ui.demo.ComponentsDemo.java

private static Component configure(Component c) {
    if (c instanceof ExceptionPanel || c instanceof ReflectComponent) {
        return c;
    }// w w  w .  jav  a  2  s.c o  m
    JToolBar toolBar = NbComponents.newInnerToolbar();
    for (DemoComponentHandler o : Lookup.getDefault().lookupAll(DemoComponentHandler.class)) {
        if (o.canHandle(c)) {
            o.configure(c);
            o.fillToolBar(toolBar, c);
        }
    }
    if (toolBar.getComponentCount() > 0) {
        JPanel result = new JPanel(new BorderLayout());
        result.add(c, BorderLayout.CENTER);
        result.add(toolBar, BorderLayout.NORTH);
        return result;
    }
    return c;
}

From source file:edu.ku.brc.specify.BackupAndRestoreApp.java

public void loggedIn(final Window window, final String databaseNameArg, final String userNameArg) {
    log.debug("loggedIn - database[" + databaseNameArg + "] username[" + userNameArg + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    boolean firstTime = this.databaseName == null;

    this.databaseName = databaseNameArg;
    this.userName = userNameArg;

    // This is used to fill who edited the object
    FormHelper.setCurrentUserEditStr(userNameArg);

    AppPreferences.setConnectedToDB(true);

    restartApp(window, databaseName, userName, false, firstTime);

    doLayout();//from  ww w  . j a  v a  2  s.c  o  m

    JToolBar toolBar = (JToolBar) UIRegistry.get(UIRegistry.TOOLBAR);
    if (toolBar != null && toolBar.getComponentCount() < 2) {
        toolBar.setVisible(false);
    }
    statusField.setSectionText(0, userName);
}

From source file:edu.ku.brc.specify.tasks.BaseTask.java

/**
 * @param cmdAction/*  w ww  .  j a  v  a  2  s .c o  m*/
 */
protected void reAddToolBarItem(final CommandAction cmdAction, final Component toolBarBtn,
        final String prefName) {
    AppPreferences remotePrefs = (AppPreferences) cmdAction.getData();
    if (remotePrefs == AppPreferences.getRemote()) {
        JToolBar toolBar = (JToolBar) UIRegistry.get(UIRegistry.TOOLBAR);
        Object value = cmdAction.getProperties().get(prefName);
        if (value != null && value instanceof Boolean) {
            //if (!remotePrefs.getBoolean(prefName, true))
            //{
            Boolean isChecked = (Boolean) value;
            if (!isChecked) {
                toolbarBtnIndex = toolBar.getComponentIndex(toolBarBtn);
                TaskMgr.removeToolbarBtn(toolBarBtn);
                toolBar.validate();
                toolBar.repaint();

            } else {
                int curInx = toolBar.getComponentIndex(toolBarBtn);
                if (curInx == -1) {
                    int lastInx = toolBar.getComponentCount() - 2;
                    int inx = toolbarBtnIndex != -1 && toolbarBtnIndex <= lastInx ? toolbarBtnIndex : lastInx;
                    TaskMgr.addToolbarBtn(toolBarBtn, inx);
                    toolBar.validate();
                    toolBar.repaint();
                }
            }
        }
    }
}

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
 *//*w w  w  .  j a va  2 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:edu.ku.brc.specify.plugins.ipadexporter.iPadDBExporterPlugin.java

/**
 * //from   w w  w. j a  v a  2  s  .  c o  m
 */
private void prefsChanged(final CommandAction cmdAction) {
    AppPreferences appPrefs = (AppPreferences) cmdAction.getData();

    if (appPrefs == AppPreferences.getRemote()) {
        // Note: The event send with the name of pref from the form
        // not the name that was saved. So we don't need to append the discipline name on the end
        Object value = cmdAction.getProperties().get(ON_TASKBAR);
        if (value != null && value instanceof Boolean) {
            /*
             * This doesn't work because it isn't added to the Toolbar correctly
             * */
            JToolBar toolBar = (JToolBar) get(TOOLBAR);

            Boolean isChecked = (Boolean) value;
            if (isChecked) {
                TaskMgr.addToolbarBtn(toolBarBtn, toolBar.getComponentCount() - 1);
            } else {
                TaskMgr.removeToolbarBtn(toolBarBtn);
            }
            toolBar.validate();
            toolBar.repaint();

        }
    }
}

From source file:edu.ku.brc.specify.Specify.java

/**
 * Creates the initial panels that will be shown at start up and sets up the Application Context
 * @param databaseNameArg the database name
 * @param userNameArg the user name// w ww  .  j a  v a 2s. c  om
 */
protected void initStartUpPanels(final String databaseNameArg, final String userNameArg) {

    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                initStartUpPanels(databaseNameArg, userNameArg);
            }
        });
        return;
    }

    TaskMgr.getInstance().readRegistry(UIRegistry.isMobile());

    TaskMgr.initializePlugins();

    Taskable bkTask = TaskMgr.getTask("BackupTask");
    if (bkTask != null) {
        bkTask.setIconName("MySQL");
    }
    validate();

    add(mainPanel, BorderLayout.CENTER);
    doLayout();

    mainPanel.setBackground(Color.WHITE);

    JToolBar toolBar = (JToolBar) UIRegistry.get(UIRegistry.TOOLBAR);
    if (toolBar != null && toolBar.getComponentCount() < 2) {
        toolBar.setVisible(false);
    }

    //        AttachmentManagerIface attchMgr = AttachmentUtils.getAttachmentManager();
    //        attchMgr.addListener(new AttachmentMgrListener()
    //        {
    //            int max = 0;
    //            @Override
    //            public void filesLoading(final int numberOfFiles)
    //            {
    //                final String statusName = "ATTACH";
    //                SwingUtilities.invokeLater(new Runnable()
    //                {
    //                    @Override
    //                    public void run()
    //                    {
    //                        //System.out.println("N: "+numberOfFiles+" MX: "+max);
    //                        statusField.setIndeterminate(statusName, numberOfFiles > 0);
    //                        
    ////                        if (max == 0) 
    ////                        {
    ////                            statusField.setProgressRange(statusName, 0, 100);
    ////                            statusField.setValue(statusName, 0);
    ////                        }
    ////                        boolean hasFiles = numberOfFiles > 0;
    ////                        if (hasFiles) 
    ////                        {
    ////                            if (numberOfFiles > max) 
    ////                            {
    ////                                max = numberOfFiles;
    ////                            } 
    ////                            int num = (int)((double)(max - numberOfFiles) / (double)max) * 100;
    ////                            System.out.println("N: "+numberOfFiles+" MX: "+max+"  num: "+num);
    ////                            if (numberOfFiles == max && max == 1)
    ////                            {
    ////                                statusField.setIndeterminate(statusName, true);
    ////                                System.out.println("setIndeterminate true");
    ////
    ////                            } else
    ////                            {
    ////                                statusField.setIndeterminate(statusName, false);
    ////                                statusField.setValue(statusName, num);
    ////                                System.out.println("setIndeterminate falsw");
    ////                                //progress.setValue(num);
    ////                                //progress.setString(Integer.toString(num)+"%");
    ////                            }
    ////                            //progress.repaint();
    ////                        } else 
    ////                        {
    ////                            max = 0;
    ////                            statusField.setProgressDone(statusName);
    ////                        }
    //                    }
    //                });
    //            }
    //        });

}

From source file:org.pmedv.blackboard.EditorUtils.java

/**
 * Updates the toolbar button states./*from  w  ww.j  a v a  2  s  . co  m*/
 * 
 * @param editor
 */
public static void setToolbarButtonState(BoardEditor editor) {
    final ApplicationContext ctx = AppContext.getContext();
    final ApplicationToolbarProvider provider = (ApplicationToolbarProvider) ctx.getBean("toolBarProvider");
    JToolBar toolbar = provider.getToolbar();
    for (int i = 0; i < toolbar.getComponentCount(); i++) {
        if (toolbar.getComponent(i) instanceof CmdJButton) {
            CmdJButton button = (CmdJButton) toolbar.getComponent(i);
            if (button.getAction() instanceof SetDrawModeCommand) {
                button.setBorderPainted(editor.getEditorMode().equals(EditorMode.DRAW_LINE));
            }
            if (button.getAction() instanceof SetSelectModeCommand) {
                button.setBorderPainted(editor.getEditorMode().equals(EditorMode.SELECT));
            }
            if (button.getAction() instanceof SetDrawRectangleModeCommand) {
                button.setBorderPainted(editor.getEditorMode().equals(EditorMode.DRAW_RECTANGLE));
            }
            if (button.getAction() instanceof SetDrawEllipseModeCommand) {
                button.setBorderPainted(editor.getEditorMode().equals(EditorMode.DRAW_ELLIPSE));
            }
            if (button.getAction() instanceof SetConnectionCheckModeCommand) {
                button.setBorderPainted(editor.getEditorMode().equals(EditorMode.CHECK_CONNECTIONS));
            }
            if (button.getAction() instanceof SetDrawMeasureModeCommand) {
                button.setBorderPainted(editor.getEditorMode().equals(EditorMode.DRAW_MEASURE));
            }
            if (button.getAction() instanceof SetMoveModeCommand) {
                button.setBorderPainted(editor.getEditorMode().equals(EditorMode.MOVE));
            }

        }
    }
}

From source file:org.pmedv.blackboard.EditorUtils.java

/**
 * Initializes the toolbar/*from   ww  w.ja v a 2  s. c o  m*/
 */
public static void initToolbar() {
    ApplicationToolbarProvider provider = ctx.getBean(ApplicationToolbarProvider.class);
    JToolBar toolbar = provider.getToolbar();
    for (int i = 0; i < toolbar.getComponentCount(); i++) {
        if (toolbar.getComponent(i) instanceof CmdJButton) {
            CmdJButton button = (CmdJButton) toolbar.getComponent(i);
            if (button.getAction() instanceof SetDrawModeCommand
                    || button.getAction() instanceof SetSelectModeCommand
                    || button.getAction() instanceof SetDrawRectangleModeCommand
                    || button.getAction() instanceof SetDrawEllipseModeCommand
                    || button.getAction() instanceof SetConnectionCheckModeCommand
                    || button.getAction() instanceof SetDrawMeasureModeCommand
                    || button.getAction() instanceof ToggleMagneticCommand
                    || button.getAction() instanceof ToggleGridCommand
                    || button.getAction() instanceof ToggleMirrorCommand
                    || button.getAction() instanceof ToggleSnapToGridCommand
                    || button.getAction() instanceof SetMoveModeCommand)
                button.setShowFeedback(false);
            if (button.getAction() instanceof SetDrawModeCommand)
                button.setBorderPainted(true);
        }
    }
}

From source file:org.pmedv.core.commands.OpenPerspectiveCommand.java

@Override
public void execute(ActionEvent e) {

    final ApplicationContext ctx = AppContext.getContext();
    final ApplicationWindow win = ctx.getBean(ApplicationWindow.class);
    final ApplicationWindowAdvisor advisor = ctx.getBean(ApplicationWindowAdvisor.class);

    final AbstractPerspective perspective = (AbstractPerspective) ctx.getBean(id);

    JMenuBar appMenuBar = win.getAppMenuBar();

    for (int i = 0; i < appMenuBar.getMenuCount(); i++) {

        JMenuWithId menu = (JMenuWithId) appMenuBar.getMenu(i);

        if (menu.getId() != null && (menu.getId().equals("common") || menu.getId().equals(perspective.ID)
                || menu.getId().equals("languages")))
            menu.setVisible(true);//from   ww w  .  j a  v a  2  s  .c  o  m
        else
            menu.setVisible(false);
    }

    JToolBar appToolbar = win.getToolBar();

    for (int i = 0; i < appToolbar.getComponentCount(); i++) {

        if (appToolbar.getComponent(i) instanceof CmdJButton) {

            CmdJButton button = (CmdJButton) appToolbar.getComponent(i);

            if (button.getId().equals("common") || button.getId().equals(perspective.ID))
                button.setVisible(true);
            else
                button.setVisible(false);

        }

    }

    log.info("Setting current editor area to " + perspective.getEditorArea());

    advisor.setCurrentEditorArea(perspective.getEditorArea());
    advisor.setCurrentPerspective(perspective);

    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {

            InputStream is = getClass().getClassLoader().getResourceAsStream("application.properties");
            Properties properties = new Properties();
            try {
                properties.load(is);
            } catch (IOException e1) {
                properties.setProperty("version", "not set");
            }

            // String title = resources.getResourceByKey(perspective.ID+".title");            
            // win.setTitle(configProvider.getConfig().getTitle()+" - "+title+" Version "+Constants.VERSION);      
            win.setTitle(AppContext.getName() + " " + properties.getProperty("version"));
            win.getLayoutPane().removeAll();
            win.getLayoutPane().add(perspective, BorderLayout.CENTER);
            win.getLayoutPane().revalidate();
            win.getLayoutPane().repaint();
        }

    });

}