Search in sources :

Example 1 with MainToolBar

use of org.apache.cayenne.swing.components.MainToolBar in project cayenne by apache.

the class CayenneModelerFrame method initToolbar.

/**
 * Initializes main toolbar.
 */
protected void initToolbar() {
    final JToolBar toolBar = new MainToolBar();
    Dimension smallBtnDim = new Dimension(30, 30);
    JButton backButton = getAction(NavigateBackwardAction.class).buildButton(1);
    backButton.setMinimumSize(smallBtnDim);
    backButton.setPreferredSize(smallBtnDim);
    toolBar.add(backButton);
    JButton forwardButton = getAction(NavigateForwardAction.class).buildButton(3);
    forwardButton.setMinimumSize(smallBtnDim);
    forwardButton.setPreferredSize(smallBtnDim);
    toolBar.add(forwardButton);
    toolBar.addSeparator(new Dimension(30, 0));
    toolBar.add(getAction(NewProjectAction.class).buildButton(1));
    toolBar.add(getAction(OpenProjectAction.class).buildButton(2));
    toolBar.add(getAction(SaveAction.class).buildButton(3));
    toolBar.addSeparator();
    JButton removeButton = getAction(RemoveAction.class).buildButton();
    toolBar.add(removeButton);
    toolBar.addSeparator();
    toolBar.add(getAction(CutAction.class).buildButton(1));
    toolBar.add(getAction(CopyAction.class).buildButton(2));
    toolBar.add(getAction(PasteAction.class).buildButton(3));
    toolBar.addSeparator();
    toolBar.add(getAction(UndoAction.class).buildButton(1));
    toolBar.add(getAction(RedoAction.class).buildButton(3));
    toolBar.addSeparator();
    toolBar.add(getAction(CreateNodeAction.class).buildButton(1));
    toolBar.add(getAction(CreateDataMapAction.class).buildButton(3));
    toolBar.addSeparator();
    toolBar.add(getAction(CreateDbEntityAction.class).buildButton(1));
    toolBar.add(getAction(CreateProcedureAction.class).buildButton(3));
    toolBar.addSeparator();
    toolBar.add(getAction(CreateObjEntityAction.class).buildButton(1));
    toolBar.add(getAction(CreateEmbeddableAction.class).buildButton(2));
    toolBar.add(getAction(CreateQueryAction.class).buildButton(3));
    // is used to place search feature components the most right on a toolbar
    toolBar.add(new SearchPanel());
    getContentPane().add(toolBar, BorderLayout.NORTH);
    // Hide some buttons when frame is too small
    final int defaultBtnWidth = removeButton.getUI().getPreferredSize(backButton).width;
    addComponentListener(new ComponentAdapter() {

        private final int[] empty = {};

        private final int[] all = { 6, 7, 8, 9, 10, 11, 12, 13, 14 };

        private final int[] remove = { 6, 7 };

        private final int[] removeAndCopy = { 6, 7, 8, 9, 10, 11 };

        private final int[] undo = { 12, 13, 14 };

        private final int[] undoAndCopy = { 8, 9, 10, 11, 12, 13, 14 };

        @Override
        public void componentResized(ComponentEvent e) {
            int[] hidden, shown;
            if (getSize().width < (13 * defaultBtnWidth + 300)) {
                hidden = all;
                shown = empty;
            } else if (getSize().width < (16 * defaultBtnWidth + 300)) {
                hidden = removeAndCopy;
                shown = undo;
            } else if (getSize().width < (18 * defaultBtnWidth + 300)) {
                hidden = remove;
                shown = undoAndCopy;
            } else {
                hidden = empty;
                shown = all;
            }
            for (int i : hidden) {
                toolBar.getComponentAtIndex(i).setVisible(false);
            }
            for (int i : shown) {
                toolBar.getComponentAtIndex(i).setVisible(true);
            }
        }
    });
}
Also used : JButton(javax.swing.JButton) NavigateForwardAction(org.apache.cayenne.modeler.action.NavigateForwardAction) JToolBar(javax.swing.JToolBar) Dimension(java.awt.Dimension) NavigateBackwardAction(org.apache.cayenne.modeler.action.NavigateBackwardAction) MainToolBar(org.apache.cayenne.swing.components.MainToolBar) ComponentEvent(java.awt.event.ComponentEvent) RemoveAction(org.apache.cayenne.modeler.action.RemoveAction) ComponentAdapter(java.awt.event.ComponentAdapter)

Aggregations

Dimension (java.awt.Dimension)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1 JButton (javax.swing.JButton)1 JToolBar (javax.swing.JToolBar)1 NavigateBackwardAction (org.apache.cayenne.modeler.action.NavigateBackwardAction)1 NavigateForwardAction (org.apache.cayenne.modeler.action.NavigateForwardAction)1 RemoveAction (org.apache.cayenne.modeler.action.RemoveAction)1 MainToolBar (org.apache.cayenne.swing.components.MainToolBar)1