Search in sources :

Example 61 with JToolBar

use of javax.swing.JToolBar 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)

Example 62 with JToolBar

use of javax.swing.JToolBar in project cayenne by apache.

the class EmbeddableTab method initView.

private void initView() {
    this.setLayout(new BorderLayout());
    JToolBar toolBar = new JToolBar();
    toolBar.setBorder(BorderFactory.createEmptyBorder());
    toolBar.setFloatable(false);
    ActionManager actionManager = Application.getInstance().getActionManager();
    toolBar.add(actionManager.getAction(CreateAttributeAction.class).buildButton());
    add(toolBar, BorderLayout.NORTH);
    className = new TextAdapter(new JTextField()) {

        @Override
        protected void updateModel(String text) {
            setClassName(text);
        }
    };
    comment = new TextAdapter(new JTextField()) {

        @Override
        protected void updateModel(String text) {
            setComment(text);
        }
    };
    FormLayout layout = new FormLayout("right:50dlu, 3dlu, fill:150dlu, 3dlu, fill:100", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.setDefaultDialogBorder();
    builder.append("Class Name:", className.getComponent(), 3);
    builder.append("Comment:", comment.getComponent(), 3);
    add(builder.getPanel(), BorderLayout.CENTER);
}
Also used : ActionManager(org.apache.cayenne.modeler.action.ActionManager) FormLayout(com.jgoodies.forms.layout.FormLayout) BorderLayout(java.awt.BorderLayout) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder) TextAdapter(org.apache.cayenne.modeler.util.TextAdapter) JToolBar(javax.swing.JToolBar) JTextField(javax.swing.JTextField)

Example 63 with JToolBar

use of javax.swing.JToolBar in project cayenne by apache.

the class SelectQueryPrefetchTab method createToolbar.

protected JComponent createToolbar() {
    JButton add = new CayenneAction.CayenneToolbarButton(null, 1);
    add.setText("Add Prefetch");
    Icon addIcon = ModelerUtil.buildIcon("icon-plus.png");
    add.setIcon(addIcon);
    add.setDisabledIcon(FilteredIconFactory.createDisabledIcon(addIcon));
    add.addActionListener(e -> {
        String prefetch = getSelectedPath();
        if (prefetch == null) {
            return;
        }
        addPrefetch(prefetch);
        Application.getInstance().getUndoManager().addEdit(new AddPrefetchUndoableEdit(prefetch, SelectQueryPrefetchTab.this));
    });
    JButton remove = new CayenneAction.CayenneToolbarButton(null, 3);
    remove.setText("Remove Prefetch");
    Icon removeIcon = ModelerUtil.buildIcon("icon-trash.png");
    remove.setIcon(removeIcon);
    remove.setDisabledIcon(FilteredIconFactory.createDisabledIcon(removeIcon));
    remove.addActionListener(e -> {
        int selection = table.getSelectedRow();
        if (selection < 0) {
            return;
        }
        String prefetch = (String) table.getModel().getValueAt(selection, 0);
        removePrefetch(prefetch);
    });
    JToolBar toolBar = new JToolBar();
    toolBar.setBorder(BorderFactory.createEmptyBorder());
    toolBar.setFloatable(false);
    toolBar.add(add);
    toolBar.add(remove);
    return toolBar;
}
Also used : JButton(javax.swing.JButton) AddPrefetchUndoableEdit(org.apache.cayenne.modeler.undo.AddPrefetchUndoableEdit) Icon(javax.swing.Icon) JToolBar(javax.swing.JToolBar)

Example 64 with JToolBar

use of javax.swing.JToolBar in project cayenne by apache.

the class SelectQueryOrderingTab method createToolbar.

protected JComponent createToolbar() {
    JButton add = new CayenneAction.CayenneToolbarButton(null, 1);
    add.setText("Add Ordering");
    Icon addIcon = ModelerUtil.buildIcon("icon-plus.png");
    add.setIcon(addIcon);
    add.setDisabledIcon(FilteredIconFactory.createDisabledIcon(addIcon));
    add.addActionListener(e -> addOrdering());
    JButton remove = new CayenneAction.CayenneToolbarButton(null, 3);
    remove.setText("Remove Ordering");
    Icon removeIcon = ModelerUtil.buildIcon("icon-trash.png");
    remove.setIcon(removeIcon);
    remove.setDisabledIcon(FilteredIconFactory.createDisabledIcon(removeIcon));
    remove.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            removeOrdering();
        }
    });
    JToolBar toolBar = new JToolBar();
    toolBar.setBorder(BorderFactory.createEmptyBorder());
    toolBar.setFloatable(false);
    toolBar.add(add);
    toolBar.add(remove);
    return toolBar;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) Icon(javax.swing.Icon) JToolBar(javax.swing.JToolBar)

Example 65 with JToolBar

use of javax.swing.JToolBar in project cayenne by apache.

the class DbEntityTab method initView.

private void initView() {
    toolBar = new JToolBar();
    toolBar.setBorder(BorderFactory.createEmptyBorder());
    toolBar.setFloatable(false);
    ActionManager actionManager = Application.getInstance().getActionManager();
    toolBar.add(actionManager.getAction(CreateAttributeAction.class).buildButton(1));
    toolBar.add(actionManager.getAction(CreateRelationshipAction.class).buildButton(3));
    toolBar.addSeparator();
    toolBar.add(actionManager.getAction(CreateObjEntityFromDbAction.class).buildButton(1));
    toolBar.add(actionManager.getAction(DbEntitySyncAction.class).buildButton(2));
    toolBar.add(actionManager.getAction(DbEntityCounterpartAction.class).buildButton(3));
    toolBar.addSeparator();
    toolBar.add(actionManager.getAction(ShowGraphEntityAction.class).buildButton());
    // create widgets
    name = new TextAdapter(new JTextField()) {

        protected void updateModel(String text) {
            setEntityName(text);
        }
    };
    catalogLabel = new JLabel("Catalog:");
    catalog = new TextAdapter(new JTextField()) {

        protected void updateModel(String text) throws ValidationException {
            setCatalog(text);
        }
    };
    schemaLabel = new JLabel("Schema:");
    schema = new TextAdapter(new JTextField()) {

        protected void updateModel(String text) throws ValidationException {
            setSchema(text);
        }
    };
    qualifier = new TextAdapter(new JTextField()) {

        protected void updateModel(String qualifier) {
            setQualifier(qualifier);
        }
    };
    comment = new TextAdapter(new JTextField()) {

        @Override
        protected void updateModel(String text) throws ValidationException {
            setComment(text);
        }
    };
    pkGeneratorType = new JComboBox<>();
    pkGeneratorType.setEditable(false);
    pkGeneratorType.setModel(new DefaultComboBoxModel<>(PK_GENERATOR_TYPES));
    pkGeneratorDetailLayout = new CardLayout();
    pkGeneratorDetail = new JPanel(pkGeneratorDetailLayout);
    pkGeneratorDetail.add(new PKDefaultGeneratorPanel(mediator), PK_DEFAULT_GENERATOR);
    pkGeneratorDetail.add(new PKDBGeneratorPanel(mediator), PK_DB_GENERATOR);
    pkGeneratorDetail.add(new PKCustomSequenceGeneratorPanel(mediator), PK_CUSTOM_SEQUENCE_GENERATOR);
    // assemble
    FormLayout layout = new FormLayout("right:pref, 3dlu, fill:200dlu", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.setDefaultDialogBorder();
    builder.appendSeparator("DbEntity Configuration");
    builder.append("DbEntity Name:", name.getComponent());
    builder.append(catalogLabel, catalog.getComponent());
    builder.append(schemaLabel, schema.getComponent());
    builder.append("Qualifier:", qualifier.getComponent());
    builder.append("Comment:", comment.getComponent());
    builder.appendSeparator("Primary Key");
    builder.append("PK Generation Strategy:", pkGeneratorType);
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(builder.getPanel(), BorderLayout.NORTH);
    mainPanel.add(pkGeneratorDetail, BorderLayout.CENTER);
    setLayout(new BorderLayout());
    add(toolBar, BorderLayout.NORTH);
    add(mainPanel, BorderLayout.CENTER);
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) CardLayout(java.awt.CardLayout) JPanel(javax.swing.JPanel) ValidationException(org.apache.cayenne.validation.ValidationException) TextAdapter(org.apache.cayenne.modeler.util.TextAdapter) JLabel(javax.swing.JLabel) JToolBar(javax.swing.JToolBar) JTextField(javax.swing.JTextField) ActionManager(org.apache.cayenne.modeler.action.ActionManager) BorderLayout(java.awt.BorderLayout) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder)

Aggregations

JToolBar (javax.swing.JToolBar)124 JButton (javax.swing.JButton)51 BorderLayout (java.awt.BorderLayout)45 JPanel (javax.swing.JPanel)37 JScrollPane (javax.swing.JScrollPane)30 Dimension (java.awt.Dimension)25 Insets (java.awt.Insets)25 ActionEvent (java.awt.event.ActionEvent)24 JLabel (javax.swing.JLabel)23 ActionListener (java.awt.event.ActionListener)19 ImageIcon (javax.swing.ImageIcon)17 Component (java.awt.Component)14 JSplitPane (javax.swing.JSplitPane)14 JTable (javax.swing.JTable)14 JTextField (javax.swing.JTextField)14 JPopupMenu (javax.swing.JPopupMenu)13 JToggleButton (javax.swing.JToggleButton)12 GridBagConstraints (java.awt.GridBagConstraints)10 GridBagLayout (java.awt.GridBagLayout)10 JComponent (javax.swing.JComponent)10