Search in sources :

Example 1 with GenericActionListener

use of pt.up.fe.specs.util.swing.GenericActionListener in project lara-framework by specs-feup.

the class EditorToolBar method addExecButton.

private JButton addExecButton() {
    execButton = new JButton();
    setIcon(execButton, "run", EditorToolBar.RUN_LARA_TEXT);
    // try {
    // Image img = ImageIO.read(IoUtils.resourceToStream("larai/resources/img/cancel.gif"));
    // execButton.setSelectedIcon(new ImageIcon(img));
    // } catch (Exception ex) {
    // }
    running = false;
    // execButton.setSelected(false);
    // execButton.setMnemonic(StrokesAndActions.F11);
    Consumer<ActionEvent> listener = e -> {
        if (!running) {
            // if (execButton.isSelected()) {
            editor.execute();
        // setIcon(newItem, "run", "Run LARA");
        } else {
            // setIcon(newItem, "cancel", "Cancel");
            editor.cancelExecution();
        }
    };
    execButton.addActionListener(new GenericActionListener(listener));
    String replace = StrokesAndActions.prettyString(StrokesAndActions.F11);
    execButton.setToolTipText(EditorToolBar.RUN_LARA_TEXT + " (" + replace + ")");
    execButton.registerKeyboardAction(new GenericActionListener(listener), StrokesAndActions.F11, JComponent.WHEN_IN_FOCUSED_WINDOW);
    // ListenerUtils.mapAction(newItem, stroke, actionName,
    // listener);
    execButton.addFocusListener(new FocusGainedListener(e -> getCurrentTab().requestFocus()));
    toolBar.add(execButton);
    return execButton;
}
Also used : SearchContext(org.fife.ui.rtextarea.SearchContext) LaraCli(org.lara.interpreter.cli.LaraCli) ItemListener(java.awt.event.ItemListener) SearchEngine(org.fife.ui.rtextarea.SearchEngine) EditorPanel(org.lara.interpreter.joptions.panels.editor.EditorPanel) DataStore(org.suikasoft.jOptions.Interfaces.DataStore) ImageIO(javax.imageio.ImageIO) ImageIcon(javax.swing.ImageIcon) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) HeapBar(pt.up.fe.specs.util.utilities.heapwindow.HeapBar) AppKeys(org.suikasoft.jOptions.gui.panels.app.AppKeys) JComponent(javax.swing.JComponent) KeyStroke(javax.swing.KeyStroke) ItemEvent(java.awt.event.ItemEvent) JToolBar(javax.swing.JToolBar) JButton(javax.swing.JButton) SpecsIo(pt.up.fe.specs.util.SpecsIo) Image(java.awt.Image) RTextArea(org.fife.ui.rtextarea.RTextArea) TabsContainerPanel(org.lara.interpreter.joptions.panels.editor.tabbed.TabsContainerPanel) FocusGainedListener(org.lara.interpreter.joptions.panels.editor.listeners.FocusGainedListener) StrokesAndActions(org.lara.interpreter.joptions.panels.editor.listeners.StrokesAndActions) KeyEvent(java.awt.event.KeyEvent) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) File(java.io.File) Consumer(java.util.function.Consumer) Dimension(java.awt.Dimension) JLabel(javax.swing.JLabel) JTextArea(javax.swing.JTextArea) SourceTextArea(org.lara.interpreter.joptions.panels.editor.tabbed.SourceTextArea) JPanel(javax.swing.JPanel) GenericActionListener(pt.up.fe.specs.util.swing.GenericActionListener) FocusGainedListener(org.lara.interpreter.joptions.panels.editor.listeners.FocusGainedListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) GenericActionListener(pt.up.fe.specs.util.swing.GenericActionListener)

Example 2 with GenericActionListener

use of pt.up.fe.specs.util.swing.GenericActionListener in project lara-framework by specs-feup.

the class EditorToolBar method addNewItem.

private JButton addNewItem(String toolTip, String icon, int keyEvent, KeyStroke stroke, Consumer<ActionEvent> listener) {
    JButton newItem = new JButton();
    try {
        Image img = ImageIO.read(SpecsIo.resourceToStream("larai/resources/img/" + icon + ".gif"));
        newItem.setIcon(new ImageIcon(img));
    } catch (Exception ex) {
        newItem.setText(toolTip);
    }
    // newItem.setMnemonic(keyEvent);
    newItem.addActionListener(new GenericActionListener(listener));
    newItem.setToolTipText(toolTip);
    if (stroke != null) {
        String replace = StrokesAndActions.prettyString(stroke);
        newItem.setToolTipText(toolTip + " (" + replace + ")");
        newItem.registerKeyboardAction(new GenericActionListener(listener), stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
    // ListenerUtils.mapAction(newItem, stroke, actionName,
    // listener);
    }
    newItem.addFocusListener(new FocusGainedListener(e -> getCurrentTab().requestFocus()));
    toolBar.add(newItem);
    return newItem;
}
Also used : SearchContext(org.fife.ui.rtextarea.SearchContext) LaraCli(org.lara.interpreter.cli.LaraCli) ItemListener(java.awt.event.ItemListener) SearchEngine(org.fife.ui.rtextarea.SearchEngine) EditorPanel(org.lara.interpreter.joptions.panels.editor.EditorPanel) DataStore(org.suikasoft.jOptions.Interfaces.DataStore) ImageIO(javax.imageio.ImageIO) ImageIcon(javax.swing.ImageIcon) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) HeapBar(pt.up.fe.specs.util.utilities.heapwindow.HeapBar) AppKeys(org.suikasoft.jOptions.gui.panels.app.AppKeys) JComponent(javax.swing.JComponent) KeyStroke(javax.swing.KeyStroke) ItemEvent(java.awt.event.ItemEvent) JToolBar(javax.swing.JToolBar) JButton(javax.swing.JButton) SpecsIo(pt.up.fe.specs.util.SpecsIo) Image(java.awt.Image) RTextArea(org.fife.ui.rtextarea.RTextArea) TabsContainerPanel(org.lara.interpreter.joptions.panels.editor.tabbed.TabsContainerPanel) FocusGainedListener(org.lara.interpreter.joptions.panels.editor.listeners.FocusGainedListener) StrokesAndActions(org.lara.interpreter.joptions.panels.editor.listeners.StrokesAndActions) KeyEvent(java.awt.event.KeyEvent) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) File(java.io.File) Consumer(java.util.function.Consumer) Dimension(java.awt.Dimension) JLabel(javax.swing.JLabel) JTextArea(javax.swing.JTextArea) SourceTextArea(org.lara.interpreter.joptions.panels.editor.tabbed.SourceTextArea) JPanel(javax.swing.JPanel) GenericActionListener(pt.up.fe.specs.util.swing.GenericActionListener) ImageIcon(javax.swing.ImageIcon) FocusGainedListener(org.lara.interpreter.joptions.panels.editor.listeners.FocusGainedListener) JButton(javax.swing.JButton) GenericActionListener(pt.up.fe.specs.util.swing.GenericActionListener) Image(java.awt.Image)

Example 3 with GenericActionListener

use of pt.up.fe.specs.util.swing.GenericActionListener in project lara-framework by specs-feup.

the class ExplorerPopup method newItem.

private JMenuItem newItem(String name, Consumer<ActionEvent> listener) {
    JMenuItem newItem = new JMenuItem(name);
    // newItem.setMnemonic(keyEvent);
    newItem.addActionListener(new GenericActionListener(listener));
    return add(newItem);
}
Also used : GenericActionListener(pt.up.fe.specs.util.swing.GenericActionListener) JMenuItem(javax.swing.JMenuItem)

Example 4 with GenericActionListener

use of pt.up.fe.specs.util.swing.GenericActionListener in project lara-framework by specs-feup.

the class LanguageSpecificationSideBar method initJoinPoints.

private void initJoinPoints() {
    joinPoints.addItem(langSpec.getGlobal());
    for (JoinPointClass joinPoint : langSpec.getJoinPoints().values()) {
        joinPoints.addItem(joinPoint);
    }
    joinPoints.addActionListener(new GenericActionListener(e -> updateJPInfo((JoinPointClass) joinPoints.getSelectedItem())));
}
Also used : Color(java.awt.Color) Attribute(org.lara.language.specification.dsl.Attribute) SpecsEnums(pt.up.fe.specs.util.SpecsEnums) LanguageSpecificationV2(org.lara.language.specification.dsl.LanguageSpecificationV2) Function(java.util.function.Function) SwingConstants(javax.swing.SwingConstants) ArrayList(java.util.ArrayList) Action(org.lara.language.specification.dsl.Action) Parameter(org.lara.language.specification.dsl.Parameter) EditorPanel(org.lara.interpreter.joptions.panels.editor.EditorPanel) Select(org.lara.language.specification.dsl.Select) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) JoinPointClass(org.lara.language.specification.dsl.JoinPointClass) GenericType(org.lara.language.specification.dsl.types.GenericType) FlowLayout(java.awt.FlowLayout) Declaration(org.lara.language.specification.dsl.Declaration) JButton(javax.swing.JButton) Font(java.awt.Font) JList(javax.swing.JList) BorderFactory(javax.swing.BorderFactory) GridBagConstraints(java.awt.GridBagConstraints) NotImplementedException(pt.up.fe.specs.util.exceptions.NotImplementedException) Component(java.awt.Component) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) LangSpecSorting(org.lara.interpreter.joptions.panels.editor.components.langspecsidebar.LangSpecSorting) Preferences(java.util.prefs.Preferences) JScrollPane(javax.swing.JScrollPane) ListCellRenderer(javax.swing.ListCellRenderer) Dimension(java.awt.Dimension) List(java.util.List) DefaultListModel(javax.swing.DefaultListModel) SpecsStrings(pt.up.fe.specs.util.SpecsStrings) JLabel(javax.swing.JLabel) EmptyBorder(javax.swing.border.EmptyBorder) GridBagLayout(java.awt.GridBagLayout) Collections(java.util.Collections) JPanel(javax.swing.JPanel) GenericActionListener(pt.up.fe.specs.util.swing.GenericActionListener) ListModel(javax.swing.ListModel) JoinPointClass(org.lara.language.specification.dsl.JoinPointClass) GenericActionListener(pt.up.fe.specs.util.swing.GenericActionListener)

Example 5 with GenericActionListener

use of pt.up.fe.specs.util.swing.GenericActionListener in project lara-framework by specs-feup.

the class LanguageSpecificationSideBar method initExtends.

private void initExtends() {
    JLabel jLabel = new JLabel("Extends: ");
    extendsButton = new JButton("N/A");
    extendsButton.setContentAreaFilled(false);
    extendsButton.setBorder(BorderFactory.createEtchedBorder());
    extendsButton.addActionListener(new GenericActionListener(e -> {
        if (currentExtend != null) {
            joinPoints.setSelectedItem(currentExtend);
        }
    }));
    extendsPanel.add(jLabel);
    extendsPanel.add(extendsButton);
    joinPointPanel.add(extendsPanel, BorderLayout.EAST);
// rootPanel.setPreferredSize(new Dimension(50, 50));
}
Also used : Color(java.awt.Color) Attribute(org.lara.language.specification.dsl.Attribute) SpecsEnums(pt.up.fe.specs.util.SpecsEnums) LanguageSpecificationV2(org.lara.language.specification.dsl.LanguageSpecificationV2) Function(java.util.function.Function) SwingConstants(javax.swing.SwingConstants) ArrayList(java.util.ArrayList) Action(org.lara.language.specification.dsl.Action) Parameter(org.lara.language.specification.dsl.Parameter) EditorPanel(org.lara.interpreter.joptions.panels.editor.EditorPanel) Select(org.lara.language.specification.dsl.Select) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) JoinPointClass(org.lara.language.specification.dsl.JoinPointClass) GenericType(org.lara.language.specification.dsl.types.GenericType) FlowLayout(java.awt.FlowLayout) Declaration(org.lara.language.specification.dsl.Declaration) JButton(javax.swing.JButton) Font(java.awt.Font) JList(javax.swing.JList) BorderFactory(javax.swing.BorderFactory) GridBagConstraints(java.awt.GridBagConstraints) NotImplementedException(pt.up.fe.specs.util.exceptions.NotImplementedException) Component(java.awt.Component) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) LangSpecSorting(org.lara.interpreter.joptions.panels.editor.components.langspecsidebar.LangSpecSorting) Preferences(java.util.prefs.Preferences) JScrollPane(javax.swing.JScrollPane) ListCellRenderer(javax.swing.ListCellRenderer) Dimension(java.awt.Dimension) List(java.util.List) DefaultListModel(javax.swing.DefaultListModel) SpecsStrings(pt.up.fe.specs.util.SpecsStrings) JLabel(javax.swing.JLabel) EmptyBorder(javax.swing.border.EmptyBorder) GridBagLayout(java.awt.GridBagLayout) Collections(java.util.Collections) JPanel(javax.swing.JPanel) GenericActionListener(pt.up.fe.specs.util.swing.GenericActionListener) ListModel(javax.swing.ListModel) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) GenericActionListener(pt.up.fe.specs.util.swing.GenericActionListener)

Aggregations

GenericActionListener (pt.up.fe.specs.util.swing.GenericActionListener)11 BorderLayout (java.awt.BorderLayout)8 Dimension (java.awt.Dimension)8 ActionEvent (java.awt.event.ActionEvent)8 JButton (javax.swing.JButton)8 JComboBox (javax.swing.JComboBox)8 JLabel (javax.swing.JLabel)8 JPanel (javax.swing.JPanel)8 EditorPanel (org.lara.interpreter.joptions.panels.editor.EditorPanel)8 Color (java.awt.Color)5 File (java.io.File)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Component (java.awt.Component)4 FlowLayout (java.awt.FlowLayout)4 Font (java.awt.Font)4 GridBagConstraints (java.awt.GridBagConstraints)4 GridBagLayout (java.awt.GridBagLayout)4 Image (java.awt.Image)4 ItemEvent (java.awt.event.ItemEvent)4