List of usage examples for javax.swing JToolBar getLayout
public LayoutManager getLayout()
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 ww w. j av a 2s . 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:ome.formats.importer.gui.FileQueueChooser.java
/** * File chooser on the file picker tab of the importer * /*from ww w . ja va 2s . co 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); } }