List of usage examples for javax.swing JToolBar getComponentIndex
public int getComponentIndex(Component c)
From source file:edu.ku.brc.specify.tasks.StartUpTask.java
/** * @param cmdAction/* ww w . ja v a 2 s.c o m*/ */ protected void prefsChanged(final CommandAction cmdAction) { AppPreferences remotePrefs = (AppPreferences) cmdAction.getData(); if (remotePrefs == AppPreferences.getRemote()) { String ds = AppContextMgr.getInstance().getClassObject(Discipline.class).getType(); boolean hasWelcome = remotePrefs.getBoolean(WELCOME_BTN_PREF + "." + ds, true); JToolBar toolBar = (JToolBar) UIRegistry.get(UIRegistry.TOOLBAR); if (!hasWelcome) { indexOfTBB = toolBar.getComponentIndex(welcomeBtn); TaskMgr.removeToolbarBtn(welcomeBtn); toolBar.validate(); toolBar.repaint(); } else { int curInx = toolBar.getComponentIndex(welcomeBtn); if (curInx == -1) { int inx = indexOfTBB != -1 ? indexOfTBB : 0; TaskMgr.addToolbarBtn(welcomeBtn, inx); toolBar.validate(); toolBar.repaint(); } welcomeBtn.setIcon(IconManager.getIcon("InnerAppIcon", IconManager.IconSize.Std24)); } } }
From source file:edu.ku.brc.specify.tasks.BaseTask.java
/** * @param cmdAction/*w w w.jav a2 s . c om*/ */ 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.specify.tasks.InteractionsTask.java
@Override public void doConfigure() { boolean isEmpty = infoRequestNavBox.getItems().size() == 0; Vector<TaskConfigItemIFace> stdList = new Vector<TaskConfigItemIFace>(); Vector<TaskConfigItemIFace> miscList = new Vector<TaskConfigItemIFace>(); Vector<TaskConfigItemIFace> srvList = new Vector<TaskConfigItemIFace>(); boolean showIRBox = true; for (InteractionEntry entry : entries) { DBTableInfo tableInfo = DBTableIdMgr.getInstance().getInfoByTableName(entry.getTableName()); if (!AppContextMgr.isSecurityOn() || tableInfo.getPermissions().canView()) { //System.err.println(entry.getName()+"\t "+entry.isSearchService()+" "+entry.isOnLeft()+" "+entry.isVisible()); entry.setEnabled(true);//from ww w . j a v a 2 s.c o m if (entry.isVisible()) { Vector<TaskConfigItemIFace> list = entry.isOnLeft() ? stdList : miscList; // Clone for undo (Cancel) try { list.add((TaskConfigItemIFace) entry.clone()); } catch (CloneNotSupportedException ex) { /* ignore */} } else { srvList.add(entry); } } else { entry.setEnabled(false); if (tableInfo.getTableId() == infoRequestTableId) { showIRBox = false; } } } if (showIRBox) { navBoxes.add(infoRequestNavBox); } else { navBoxes.remove(infoRequestNavBox); } int origNumStd = stdList.size(); TaskConfigureDlg dlg = new TaskConfigureDlg(stdList, miscList, false, "InteractionsConfig", "IAT_TITLE", "IAT_AVAIL_ITEMS", "IAT_HIDDEN_ITEMS", "IAT_MAKE_AVAIL", "IAT_MAKE_HIDDEN"); dlg.setVisible(true); if (!dlg.isCancelled()) { entries.clear(); for (TaskConfigItemIFace ie : stdList) { ((InteractionEntry) ie).setOnLeft(true); entries.add((InteractionEntry) ie); } for (TaskConfigItemIFace ie : miscList) { ((InteractionEntry) ie).setOnLeft(false); entries.add((InteractionEntry) ie); } for (TaskConfigItemIFace ie : srvList) { entries.add((InteractionEntry) ie); } writeEntries(); actionsNavBox.clear(); Collections.sort(entries); for (InteractionEntry entry : entries) { DBTableInfo tableInfo = DBTableIdMgr.getInstance().getInfoByTableName(entry.getTableName()); if (entry.isEnabled()) { if (entry.isOnLeft()) { NavBoxButton navBtn = addCommand(actionsNavBox, tableInfo, entry); navBtn.setToolTip(entry.getI18NTooltip()); } else if (StringUtils.isNotEmpty(entry.getViewName()) && !entry.isSearchService()) { CommandAction cmdAction = createCmdActionFromEntry(entry, tableInfo); ContextMgr.registerService(10, entry.getViewName(), tableInfo.getTableId(), cmdAction, this, "Data_Entry", tableInfo.getTitle(), true); // the Name gets Hashed } } } NavBoxMgr.getInstance().validate(); NavBoxMgr.getInstance().invalidate(); NavBoxMgr.getInstance().doLayout(); if (stdList.size() == 0) { String ds = AppContextMgr.getInstance().getClassObject(Discipline.class).getType(); AppPreferences.getRemote().putBoolean(IS_USING_INTERACTIONS_PREFNAME + ds, false); JToolBar toolBar = (JToolBar) UIRegistry.get(UIRegistry.TOOLBAR); indexOfTBB = toolBar.getComponentIndex(toolBarBtn); if (indexOfTBB > -1) { TaskMgr.removeToolbarBtn(toolBarBtn); toolBar.validate(); toolBar.repaint(); } } else if (isEmpty && stdList.size() > 0) { String ds = AppContextMgr.getInstance().getClassObject(Discipline.class).getType(); AppPreferences.getRemote().putBoolean(IS_USING_INTERACTIONS_PREFNAME + ds, true); prefsChanged(new CommandAction(null, null, AppPreferences.getRemote())); if (origNumStd == 0) { JToolBar toolBar = (JToolBar) UIRegistry.get(UIRegistry.TOOLBAR); int inx = indexOfTBB != -1 ? indexOfTBB : 4; TaskMgr.addToolbarBtn(toolBarBtn, inx); toolBar.validate(); toolBar.repaint(); } } } }