Example usage for javax.swing JToolBar getComponents

List of usage examples for javax.swing JToolBar getComponents

Introduction

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

Prototype

public Component[] getComponents() 

Source Link

Document

Gets all the components in this container.

Usage

From source file:Main.java

/**
 * Turns on display of text in all child buttons within the
 * {@link JToolBar}.//from w w w  .  j a  va2s. com
 * 
 * @param toolBar
 * @param show
 */
public static void showText(JToolBar toolBar, boolean show) {
    for (Component comp : toolBar.getComponents()) {
        if (comp instanceof AbstractButton) {
            ((AbstractButton) comp).putClientProperty("hideActionText", Boolean.valueOf(show));
        }
    }
    toolBar.revalidate();
}

From source file:Main.java

public static void disableToolBar(JToolBar panel, Class<?>... classesToIgnore) {
    for (Component component : panel.getComponents()) {
        if (!ignoreClasses(component, classesToIgnore)) {
            Method m = discover(component, "setEnabled", boolean.class);
            invoke(m, component, new Object[] { Boolean.FALSE });
        }//  ww w .  ja v  a2  s.  c  o  m
    }
}

From source file:Main.java

public static void enableToolBar(JToolBar panel, Class<?>... classesToIgnore) {
    for (Component component : panel.getComponents()) {
        if (!ignoreClasses(component, classesToIgnore)) {
            Method m = discover(component, "setEnabled", boolean.class);
            invoke(m, component, new Object[] { Boolean.TRUE });
        }/*w w w.  ja  va  2  s  . co  m*/
    }
}

From source file:net.sf.jabref.gui.PreviewPanel.java

private JToolBar createToolBar() {
    JToolBar toolBar = new OSXCompatibleToolbar(SwingConstants.VERTICAL);
    toolBar.setMargin(new Insets(0, 0, 0, 2));
    toolBar.setFloatable(false);/* ww w .j  a v a 2 s  .  c  o  m*/

    // Add actions (and thus buttons)
    toolBar.add(this.closeAction);
    toolBar.addSeparator();
    toolBar.add(this.copyPreviewAction);
    toolBar.addSeparator();
    toolBar.add(this.printAction);

    Component[] comps = toolBar.getComponents();

    for (Component comp : comps) {
        ((JComponent) comp).setOpaque(false);
    }

    return toolBar;
}

From source file:net.sf.jabref.EntryEditor.java

/**
 * Create toolbar for entry editor./*w w w  .jav  a  2  s  . c  o  m*/
 */
private void setupToolBar() {
    JToolBar tlb = new JToolBar(JToolBar.VERTICAL);
    CloseAction closeAction = new CloseAction();
    ;
    StoreFieldAction storeFieldAction = new StoreFieldAction();
    DeleteAction deleteAction = new DeleteAction();
    UndoAction undoAction = new UndoAction();
    RedoAction redoAction = new RedoAction();

    tlb.setBorder(null);
    tlb.setRollover(true);
    tlb.setMargin(new Insets(0, 0, 0, 2));
    tlb.setFloatable(false);
    tlb.addSeparator();
    tlb.add(deleteAction);
    tlb.addSeparator();
    tlb.add(prevEntryAction);
    tlb.add(nextEntryAction);
    tlb.addSeparator();
    tlb.add(helpAction);
    for (Component comp : tlb.getComponents()) {
        ((JComponent) comp).setOpaque(false);
    }

    // The toolbar carries all the key bindings that are valid for the whole window.
    ActionMap am = tlb.getActionMap();
    InputMap im = tlb.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(prefs.getKey("Close entry editor"), "close");
    am.put("close", closeAction);
    im.put(prefs.getKey("Entry editor, store field"), "store");
    am.put("store", storeFieldAction);
    im.put(prefs.getKey("Entry editor, previous entry"), "prev");
    am.put("prev", prevEntryAction);
    im.put(prefs.getKey("Entry editor, next entry"), "next");
    am.put("next", nextEntryAction);
    im.put(prefs.getKey("Undo"), "undo");
    am.put("undo", undoAction);
    im.put(prefs.getKey("Redo"), "redo");
    am.put("redo", redoAction);
    im.put(prefs.getKey("Help"), "help");
    am.put("help", helpAction);

    // Add actions (and thus buttons)
    JButton closeBut = new JButton(closeAction);
    closeBut.setText(null);
    closeBut.setBorder(null);

    // Create type-label
    TypeLabel typeLabel = new TypeLabel(entry.getType().getName());

    JPanel leftPan = new JPanel();
    leftPan.setLayout(new BorderLayout());
    leftPan.add(closeBut, BorderLayout.NORTH);
    leftPan.add(typeLabel, BorderLayout.CENTER);
    leftPan.add(tlb, BorderLayout.SOUTH);

    add(leftPan, BorderLayout.WEST);
}

From source file:net.sf.jabref.gui.entryeditor.EntryEditor.java

private void setupToolBar() {
    JPanel leftPan = new JPanel();
    leftPan.setLayout(new BorderLayout());
    JToolBar toolBar = new OSXCompatibleToolbar(SwingConstants.VERTICAL);

    toolBar.setBorder(null);//from  w  w w.ja  va2  s. c o  m
    toolBar.setRollover(true);

    toolBar.setMargin(new Insets(0, 0, 0, 2));

    // The toolbar carries all the key bindings that are valid for the whole
    // window.
    ActionMap actionMap = toolBar.getActionMap();
    InputMap inputMap = toolBar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_ENTRY_EDITOR), "close");
    actionMap.put("close", closeAction);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_STORE_FIELD), "store");
    actionMap.put("store", getStoreFieldAction());
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.AUTOGENERATE_BIBTEX_KEYS), "generateKey");
    actionMap.put("generateKey", getGenerateKeyAction());
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.AUTOMATICALLY_LINK_FILES), "autoLink");
    actionMap.put("autoLink", autoLinkAction);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_ENTRY), "prev");
    actionMap.put("prev", getPrevEntryAction());
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_ENTRY), "next");
    actionMap.put("next", getNextEntryAction());
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.UNDO), "undo");
    actionMap.put("undo", undoAction);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.REDO), "redo");
    actionMap.put("redo", redoAction);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.HELP), "help");
    actionMap.put("help", getHelpAction());

    toolBar.setFloatable(false);

    // Add actions (and thus buttons)
    JButton closeBut = new JButton(closeAction);
    closeBut.setText(null);
    closeBut.setBorder(null);
    closeBut.setMargin(new Insets(8, 0, 8, 0));
    leftPan.add(closeBut, BorderLayout.NORTH);

    // Create type-label
    TypedBibEntry typedEntry = new TypedBibEntry(entry, Optional.empty(),
            panel.getBibDatabaseContext().getMode());
    leftPan.add(new TypeLabel(typedEntry.getTypeForDisplay()), BorderLayout.CENTER);
    TypeButton typeButton = new TypeButton();

    toolBar.add(typeButton);
    toolBar.add(getGenerateKeyAction());
    toolBar.add(autoLinkAction);

    toolBar.add(writeXmp);

    toolBar.addSeparator();

    toolBar.add(deleteAction);
    toolBar.add(getPrevEntryAction());
    toolBar.add(getNextEntryAction());

    toolBar.addSeparator();

    toolBar.add(getHelpAction());

    Component[] comps = toolBar.getComponents();

    for (Component comp : comps) {
        ((JComponent) comp).setOpaque(false);
    }

    leftPan.add(toolBar, BorderLayout.SOUTH);
    add(leftPan, BorderLayout.WEST);
}

From source file:utybo.branchingstorytree.swing.editor.StoryEditor.java

public StoryEditor(BranchingStory baseStory) throws BSTException {
    setLayout(new MigLayout("hidemode 3", "[grow]", "[][grow]"));

    JToolBar toolBar = new JToolBar();
    toolBar.setBorder(null);/*from w  w  w .j av a 2s.c o m*/
    toolBar.setFloatable(false);
    add(toolBar, "cell 0 0,growx");

    JButton btnSaveAs = new JButton(Lang.get("saveas"), new ImageIcon(Icons.getImage("Save As", 16)));
    btnSaveAs.addActionListener(e -> {
        saveAs();
    });
    toolBar.add(btnSaveAs);

    JButton btnSave = new JButton(Lang.get("save"), new ImageIcon(Icons.getImage("Save", 16)));
    btnSave.addActionListener(e -> {
        save();
    });
    toolBar.add(btnSave);

    JButton btnPlay = new JButton(Lang.get("play"), new ImageIcon(Icons.getImage("Circled Play", 16)));
    btnPlay.addActionListener(ev -> {
        try {
            String s = exportToString();
            File f = Files.createTempDirectory("openbst").toFile();
            File bstFile = new File(f, "expoted.bst");
            try (FileOutputStream fos = new FileOutputStream(bstFile);) {
                IOUtils.write(s, fos, StandardCharsets.UTF_8);
            }
            OpenBSTGUI.getInstance().openStory(bstFile);
        } catch (Exception e) {
            OpenBST.LOG.error("Export failed", e);
            Messagers.showException(OpenBSTGUI.getInstance(), Lang.get("editor.exportfail"), e);
        }
    });
    toolBar.add(btnPlay);

    JButton btnFilePreview = new JButton(Lang.get("editor.exportpreview"),
            new ImageIcon(Icons.getImage("PreviewText", 16)));
    btnFilePreview.addActionListener(e -> {
        try {
            String s = exportToString();
            JDialog dialog = new JDialog(OpenBSTGUI.getInstance(), Lang.get("editor.exportpreview"));
            JTextArea jta = new JTextArea(s);
            jta.setLineWrap(true);
            jta.setWrapStyleWord(true);
            dialog.add(new JScrollPane(jta));

            dialog.setModalityType(ModalityType.APPLICATION_MODAL);
            dialog.setSize((int) (Icons.getScale() * 350), (int) (Icons.getScale() * 300));
            dialog.setLocationRelativeTo(OpenBSTGUI.getInstance());
            dialog.setVisible(true);
        } catch (Exception x) {
            OpenBST.LOG.error("Failed to preview", x);
            Messagers.showException(OpenBSTGUI.getInstance(), Lang.get("editor.previewerror"), x);
        }
    });
    toolBar.add(btnFilePreview);

    Component horizontalGlue = Box.createHorizontalGlue();
    toolBar.add(horizontalGlue);

    JButton btnClose = new JButton(Lang.get("close"), new ImageIcon(Icons.getImage("Cancel", 16)));
    btnClose.addActionListener(e -> {
        askClose();
    });
    toolBar.add(btnClose);

    for (final Component component : toolBar.getComponents()) {
        if (component instanceof JButton) {
            ((JButton) component).setHideActionText(false);
            ((JButton) component).setToolTipText(((JButton) component).getText());
            ((JButton) component).setText("");
        }
    }

    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.setTabPlacement(JTabbedPane.LEFT);
    add(tabbedPane, "cell 0 1,grow");

    tabbedPane.addTab("Beta Warning", new StoryEditorWelcomeScreen());

    details = new StoryDetailsEditor(this);
    tabbedPane.addTab(Lang.get("editor.details"), details);

    nodesEditor = new StoryNodesEditor();
    tabbedPane.addTab(Lang.get("editor.nodes"), nodesEditor);

    this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("control S"),
            "doSave");
    this.getActionMap().put("doSave", new AbstractAction() {

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

    importFrom(baseStory);
}