Search in sources :

Example 46 with KeyListener

use of java.awt.event.KeyListener in project artisynth_core by artisynth.

the class ViewerManager method removeViewer.

public boolean removeViewer(GLViewer viewer) {
    int idx = myViewers.indexOf(viewer);
    if (idx != -1) {
        for (MouseInputListener l : myMouseListeners) {
            viewer.removeMouseInputListener(l);
        }
        for (KeyListener l : myKeyListeners) {
            viewer.removeKeyListener(l);
        }
        myViewers.remove(idx);
        myPopupManagers.remove(idx);
        return true;
    } else {
        return false;
    }
}
Also used : MouseInputListener(javax.swing.event.MouseInputListener) KeyListener(java.awt.event.KeyListener)

Example 47 with KeyListener

use of java.awt.event.KeyListener in project blue by kunstmusik.

the class Knob method createKnob.

private void createKnob(int preferredWidth) {
    DRAG_SPEED = 0.01F;
    CLICK_SPEED = 0.01F;
    SHADOWX = 1;
    SHADOWY = 1;
    focusColor = DEFAULT_FOCUS_COLOR;
    Dimension prefSize = new Dimension(preferredWidth, preferredWidth);
    setPreferredSize(prefSize);
    // Degrees ??? Radians???
    hitArc.setAngleStart(235);
    addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent me) {
            dragpos = me.getX() + me.getY();
            startVal = val;
            // Fix last angle
            int xpos = middle - me.getX();
            int ypos = middle - me.getY();
            lastAng = Math.atan2(xpos, ypos);
            requestFocus();
        }

        @Override
        public void mouseClicked(MouseEvent me) {
            hitArc.setAngleExtent(-(LENGTH + 20));
            if (hitArc.contains(me.getX(), me.getY())) {
                hitArc.setAngleExtent(MULTIP * (ang - START_ANG) - 10);
                if (hitArc.contains(me.getX(), me.getY())) {
                    decValue();
                } else {
                    incValue();
                }
            }
        }
    });
    // Let the user control the knob with the mouse
    addMouseMotionListener(new MouseMotionAdapter() {

        @Override
        public void mouseDragged(MouseEvent me) {
            if (dragType == SIMPLE) {
                float f = DRAG_SPEED * ((me.getX() + me.getY()) - dragpos);
                setValue(startVal + f);
            } else if (dragType == ROUND) {
                // Measure relative the middle of the button!
                int xpos = middle - me.getX();
                int ypos = middle - me.getY();
                double ang = Math.atan2(xpos, ypos);
                double diff = lastAng - ang;
                setValue((float) (getValue() + (diff / LENGTH_ANG)));
                lastAng = ang;
            }
        }

        @Override
        public void mouseMoved(MouseEvent me) {
        }
    });
    // Let the user control the knob with the keyboard
    addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
            int k = e.getKeyCode();
            if (k == KeyEvent.VK_RIGHT) {
                incValue();
            } else if (k == KeyEvent.VK_LEFT) {
                decValue();
            }
        }
    });
    // Handle focus so that the knob gets the correct focus highlighting.
    addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            repaint();
        }

        @Override
        public void focusLost(FocusEvent e) {
            repaint();
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) KeyListener(java.awt.event.KeyListener) Dimension(java.awt.Dimension) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 48 with KeyListener

use of java.awt.event.KeyListener in project UniversalMediaServer by UniversalMediaServer.

the class TracesTab method build.

@SuppressWarnings("serial")
public JComponent build() {
    // Apply the orientation for the locale
    ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());
    String colSpec = FormLayoutUtil.getColSpec("pref, pref:grow, pref, 3dlu, pref, pref, pref", orientation);
    int cols = colSpec.split(",").length;
    FormLayout layout = new FormLayout(colSpec, "p, fill:10:grow, p, p");
    PanelBuilder builder = new PanelBuilder(layout);
    builder.opaque(true);
    CellConstraints cc = new CellConstraints();
    // Create the search box
    JPanel jSearchPanel = new JPanel();
    jSearchPanel.setLayout(new BoxLayout(jSearchPanel, BoxLayout.LINE_AXIS));
    jSearchPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    JLabel jFilterLabel = new JLabel(Messages.getString("TracesTab.24") + ":");
    jFilterLabel.setDisplayedMnemonic(KeyEvent.VK_F);
    jFilterLabel.setToolTipText(Messages.getString("TracesTab.33"));
    jTracesFilter = new CustomJComboBox<>(levelStrings);
    jTracesFilter.setSelectedIndex(findLevelsIdx(configuration.getLoggingFilterLogsTab()));
    jFilterLabel.setLabelFor(jTracesFilter);
    jTracesFilter.setToolTipText(Messages.getString("TracesTab.33"));
    jTracesFilter.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setLoggingFilterLogsTab(logLevels[jTracesFilter.getSelectedIndex()]);
            LoggingConfig.setTracesFilter();
        }
    });
    jSearchPanel.add(jFilterLabel);
    jSearchPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    jSearchPanel.add(jTracesFilter);
    jSearchPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    jSearchBox = new CustomJTextField();
    jSearchBox.setBackground(new Color(248, 248, 248));
    jSearchBox.setToolTipText(Messages.getString("TracesTab.34"));
    jSearchPanel.add(jSearchBox);
    jSearchPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    JButton jSearchButton = new JButton(Messages.getString("PMS.144"));
    jSearchButton.setMnemonic(KeyEvent.VK_S);
    jSearchButton.setToolTipText(Messages.getString("TracesTab.34"));
    jSearchPanel.add(jSearchButton);
    jSearchPanel.add(jCSSpace = Box.createRigidArea(new Dimension(5, 0)));
    jCSSearch = new CustomJCheckBox(Messages.getString("TracesTab.19"), configuration.getGUILogSearchCaseSensitive());
    jCSSearch.setMnemonic(KeyEvent.VK_C);
    jCSSearch.setToolTipText(Messages.getString("TracesTab.35"));
    jSearchPanel.add(jCSSearch);
    jSearchPanel.add(jRESpace = Box.createRigidArea(new Dimension(5, 0)));
    jRESearch = new CustomJCheckBox("RegEx", configuration.getGUILogSearchRegEx());
    jRESearch.setMnemonic(KeyEvent.VK_R);
    jRESearch.setToolTipText(Messages.getString("TracesTab.36"));
    jSearchPanel.add(jRESearch);
    jSearchPanel.add(jMLSpace = Box.createRigidArea(new Dimension(5, 0)));
    jMLSearch = new CustomJCheckBox(Messages.getString("TracesTab.20"), configuration.getGUILogSearchMultiLine());
    jMLSearch.setMnemonic(KeyEvent.VK_M);
    jMLSearch.setToolTipText(Messages.getString("TracesTab.37"));
    jSearchPanel.add(jMLSearch);
    jSearchPanel.add(jBufferSpace1 = Box.createRigidArea(new Dimension(4, 0)));
    jSearchPanel.add(jBufferSeparator = new JSeparator(SwingConstants.VERTICAL));
    jSearchPanel.add(jBufferSpace2 = Box.createRigidArea(new Dimension(4, 0)));
    jBufferLabel = new JLabel(Messages.getString("TracesTab.17"));
    jBufferLabel.setDisplayedMnemonic(KeyEvent.VK_B);
    jBufferLabel.setToolTipText(Messages.getString("TracesTab.38"));
    jLineBuffer = new CustomJSpinner(new SpinnerIntModel(configuration.getLoggingLogsTabLinebuffer(), PmsConfiguration.LOGGING_LOGS_TAB_LINEBUFFER_MIN, PmsConfiguration.LOGGING_LOGS_TAB_LINEBUFFER_MAX, PmsConfiguration.LOGGING_LOGS_TAB_LINEBUFFER_STEP), true);
    jLineBuffer.setToolTipText(Messages.getString("TracesTab.38"));
    jBufferLabel.setLabelFor(jLineBuffer);
    jSearchPanel.add(jBufferLabel);
    jSearchPanel.add(jBufferSpace3 = Box.createRigidArea(new Dimension(5, 0)));
    jSearchPanel.add(jLineBuffer);
    jLineBuffer.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            jList.setMaxLines((Integer) jLineBuffer.getValue());
            configuration.setLoggingLogsTabLinebuffer(jList.getMaxLines());
        }
    });
    jSearchBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            searchTraces();
        }
    });
    jSearchButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            searchTraces();
        }
    });
    jCSSearch.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setGUILogSearchCaseSensitive(jCSSearch.isSelected());
        }
    });
    jRESearch.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setGUILogSearchRegEx(jRESearch.isSelected());
        }
    });
    jMLSearch.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setGUILogSearchMultiLine(jMLSearch.isSelected());
        }
    });
    builder.add(jSearchPanel, cc.xyw(1, 1, cols));
    // Create traces text box
    jList = new TextAreaFIFO(configuration.getLoggingLogsTabLinebuffer());
    jList.setEditable(false);
    jList.setBackground(Color.WHITE);
    jList.setFont(new Font(Font.MONOSPACED, Font.PLAIN, jList.getFont().getSize()));
    final JPopupMenu popup = new JPopupMenu();
    Action copy = jList.getActionMap().get("copy-to-clipboard");
    JMenuItem copyItem = new JMenuItem(copy);
    copyItem.setText(Messages.getString("General.1"));
    popup.add(copyItem);
    popup.addSeparator();
    JMenuItem clearItem = new JMenuItem(Messages.getString("TracesTab.3"));
    clearItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            jList.setText("");
        }
    });
    popup.add(clearItem);
    jList.addMouseListener(new PopupTriggerMouseListener(popup, jList));
    jList.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                searchTraces();
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }
    });
    jListPane = new JScrollPane(jList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    jListPane.setBorder(BorderFactory.createEmptyBorder());
    new SmartScroller(jListPane);
    builder.add(jListPane, cc.xyw(1, 2, cols));
    // Create the logging options panel
    jOptionsPanel = new JPanel();
    jOptionsPanel.setLayout(new BoxLayout(jOptionsPanel, BoxLayout.LINE_AXIS));
    jOptionsPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5), BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), Messages.getString("TracesTab.26")), BorderFactory.createEmptyBorder(10, 5, 10, 5))));
    jBuffered = new CustomJCheckBox(Messages.getString("TracesTab.25"), configuration.getLoggingBuffered());
    jBuffered.setMnemonic(KeyEvent.VK_U);
    jBuffered.setToolTipText(Messages.getString("TracesTab.43"));
    jBuffered.setHorizontalTextPosition(SwingConstants.LEADING);
    jBuffered.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (PMS.getTraceMode() == 2 && jBuffered.isSelected()) {
                jBuffered.setSelected(false);
                return;
            }
            configuration.setLoggingBuffered(jBuffered.isSelected());
            LoggingConfig.setBuffered(jBuffered.isSelected());
        }
    });
    jOptionsPanel.add(jBuffered);
    jOptionsPanel.add(Box.createRigidArea(new Dimension(4, 0)));
    boolean useSyslog = configuration.getLoggingUseSyslog();
    jUseSyslog = new CustomJCheckBox(Messages.getString("TracesTab.27"), useSyslog);
    jUseSyslog.setMnemonic(KeyEvent.VK_Y);
    jUseSyslog.setToolTipText(Messages.getString("TracesTab.44"));
    jUseSyslog.setHorizontalTextPosition(SwingConstants.LEADING);
    jUseSyslog.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (PMS.getTraceMode() == 2 && jUseSyslog.isSelected()) {
                jUseSyslog.setSelected(false);
                return;
            } else if (jSyslogHost.getText().trim().isEmpty()) {
                jSearchOutput.setText(Messages.getString("TracesTab.31"));
                jUseSyslog.setSelected(false);
                return;
            }
            jSearchOutput.setText("");
            boolean useSyslog = jUseSyslog.isSelected();
            configuration.setLoggingUseSyslog(useSyslog);
            LoggingConfig.setSyslog();
            jSyslogHost.setEnabled(!useSyslog);
            jSyslogPort.setEnabled(!useSyslog);
            jSyslogFacility.setEnabled(!useSyslog);
        }
    });
    jOptionsPanel.add(jUseSyslog);
    jOptionsPanel.add(Box.createRigidArea(new Dimension(4, 0)));
    JLabel jSyslogHostLabel = new JLabel(Messages.getString("TracesTab.28"));
    jSyslogHostLabel.setDisplayedMnemonic(KeyEvent.VK_N);
    jSyslogHostLabel.setToolTipText(Messages.getString("TracesTab.45"));
    jOptionsPanel.add(jSyslogHostLabel);
    jOptionsPanel.add(Box.createRigidArea(new Dimension(4, 0)));
    jSyslogHost = new CustomJTextField(configuration.getLoggingSyslogHost(), 10);
    jSyslogHostLabel.setLabelFor(jSyslogHost);
    jSyslogHost.setToolTipText(Messages.getString("TracesTab.45"));
    jSyslogHost.setEnabled(!useSyslog);
    jSyslogHost.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                jSyslogHost.setText(configuration.getLoggingSyslogHost());
            } else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                FocusManager.getCurrentManager().focusNextComponent();
            }
        }
    });
    jSyslogHost.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            String s = ((CustomJTextField) input).getText().trim();
            if (!s.isEmpty() && !(// Hostname or IPv4
            s.matches("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") || // Simplified IPv6
            s.matches("(^([0-9a-fA-F]{0,4}:)+[0-9a-fA-F]{1,4}([0-9a-fA-F]{0,4}:)*$)|(^([0-9a-fA-F]{0,4}:)*[0-9a-fA-F]{1,4}([0-9a-fA-F]{0,4}:)+$)|(^::$)"))) {
                jSearchOutput.setText(String.format(Messages.getString("TracesTab.32"), s));
                return false;
            }
            jSearchOutput.setText("");
            configuration.setLoggingSyslogHost(jSyslogHost.getText().trim());
            return true;
        }
    });
    jOptionsPanel.add(jSyslogHost);
    jOptionsPanel.add(Box.createRigidArea(new Dimension(4, 0)));
    JLabel jSyslogPortLabel = new JLabel(Messages.getString("TracesTab.29"));
    jSyslogPortLabel.setToolTipText(Messages.getString("TracesTab.46"));
    jOptionsPanel.add(jSyslogPortLabel);
    jOptionsPanel.add(Box.createRigidArea(new Dimension(4, 0)));
    jSyslogPort = new CustomJSpinner(new SpinnerIntModel(configuration.getLoggingSyslogPort(), 1, 65535), true);
    jSyslogPort.setToolTipText(Messages.getString("TracesTab.46"));
    jSyslogPort.setEnabled(!useSyslog);
    jSyslogPortLabel.setLabelFor(jSyslogPort);
    jSyslogPort.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            configuration.setLoggingSyslogPort((Integer) jSyslogPort.getValue());
        }
    });
    jOptionsPanel.add(jSyslogPort);
    jOptionsPanel.add(Box.createRigidArea(new Dimension(4, 0)));
    JLabel jSyslogFacilityLabel = new JLabel(Messages.getString("TracesTab.30"));
    jSyslogFacilityLabel.setDisplayedMnemonic(KeyEvent.VK_A);
    jSyslogFacilityLabel.setToolTipText(Messages.getString("TracesTab.47"));
    jOptionsPanel.add(jSyslogFacilityLabel);
    jOptionsPanel.add(Box.createRigidArea(new Dimension(4, 0)));
    jSyslogFacility = new CustomJComboBox<>(syslogFacilities);
    jSyslogFacility.setToolTipText(Messages.getString("TracesTab.47"));
    jSyslogFacility.setEnabled(!useSyslog);
    jSyslogFacility.setSelectedIndex(findSyslogFacilityIdx(configuration.getLoggingSyslogFacility()));
    jSyslogFacilityLabel.setLabelFor(jSyslogFacility);
    jSyslogFacility.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setLoggingSyslogFacility(syslogFacilities[jSyslogFacility.getSelectedIndex()]);
        }
    });
    jOptionsPanel.add(jSyslogFacility);
    jOptionsPanel.setFocusTraversalPolicyProvider(true);
    builder.add(jOptionsPanel, cc.xyw(1, 3, cols));
    jShowOptions = new CustomJCheckBox(Messages.getString("TracesTab.18"), PMS.getTraceMode() != 2 && configuration.getLoggingUseSyslog());
    jShowOptions.setHorizontalTextPosition(SwingConstants.LEADING);
    jShowOptions.setToolTipText(Messages.getString("TracesTab.41"));
    jShowOptions.setMnemonic(KeyEvent.VK_G);
    jShowOptions.setEnabled(PMS.getTraceMode() != 2);
    jShowOptions.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            jOptionsPanel.setVisible(jShowOptions.isSelected());
            if (jShowOptions.isSelected()) {
                jBuffered.requestFocusInWindow();
            }
        }
    });
    builder.add(jShowOptions, cc.xy(3, 4));
    // Add buttons to open logfiles (there may be more than one)
    JPanel pLogFileButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    HashMap<String, String> logFiles = LoggingConfig.getLogFilePaths();
    for (Map.Entry<String, String> logger : logFiles.entrySet()) {
        String loggerNameDisplay = logger.getKey();
        if (logger.getKey().toLowerCase().startsWith("default.log")) {
            loggerNameDisplay = Messages.getString("TracesTab.5");
        }
        CustomJButton b = new CustomJButton(loggerNameDisplay);
        if (!logger.getKey().equals(loggerNameDisplay)) {
            b.setMnemonic(KeyEvent.VK_O);
        }
        b.setToolTipText(logger.getValue());
        b.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                File logFile = new File(((CustomJButton) e.getSource()).getToolTipText());
                try {
                    java.awt.Desktop.getDesktop().open(logFile);
                } catch (IOException | UnsupportedOperationException ioe) {
                    LOGGER.error("Failed to open file \"{}\" in default editor: {}", logFile, ioe);
                }
            }
        });
        pLogFileButtons.add(b);
    }
    builder.add(pLogFileButtons, cc.xy(cols, 4));
    final ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    JLabel rootLevelLabel = new JLabel(Messages.getString("TracesTab.11") + ": ");
    rootLevelLabel.setDisplayedMnemonic(KeyEvent.VK_L);
    rootLevelLabel.setToolTipText(Messages.getString("TracesTab.42"));
    CustomJComboBox<String> rootLevel = new CustomJComboBox<>(levelStrings);
    rootLevelLabel.setLabelFor(rootLevel);
    rootLevel.setSelectedIndex(findLevelsIdx(rootLogger.getLevel()));
    rootLevel.setToolTipText(Messages.getString("TracesTab.42"));
    rootLevel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            CustomJComboBox<?> cb = (CustomJComboBox<?>) e.getSource();
            rootLogger.setLevel(logLevels[cb.getSelectedIndex()]);
            Level newLevel = rootLogger.getLevel();
            if (newLevel.toInt() > Level.INFO_INT) {
                rootLogger.setLevel(Level.INFO);
            }
            LOGGER.info("Changed debug level to " + newLevel);
            if (newLevel != rootLogger.getLevel()) {
                rootLogger.setLevel(newLevel);
            }
            configuration.setRootLogLevel(newLevel);
        }
    });
    builder.add(rootLevelLabel, cc.xy(5, 4));
    builder.add(rootLevel, cc.xy(6, 4));
    if (PMS.getTraceMode() == 2) {
        // Forced trace mode
        rootLevel.setEnabled(false);
    }
    // Add buttons to pack logs (there may be more than one)
    JPanel pLogPackButtons = new JPanel(new FlowLayout(FlowLayout.LEFT));
    if (PMS.getTraceMode() == 0) {
        // PMS was not started in trace mode
        CustomJButton rebootTrace = new CustomJButton(Messages.getString("TracesTab.12"));
        rebootTrace.setToolTipText(Messages.getString("TracesTab.39"));
        rebootTrace.setMnemonic(KeyEvent.VK_T);
        rebootTrace.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int opt = JOptionPane.showConfirmDialog(null, Messages.getString("TracesTab.13"), Messages.getString("TracesTab.14"), JOptionPane.YES_NO_OPTION);
                if (opt == JOptionPane.YES_OPTION) {
                    ProcessUtil.reboot("trace");
                }
            }
        });
        pLogPackButtons.add(rebootTrace);
    }
    CustomJButton packDbg = new CustomJButton(Messages.getString("TracesTab.4"));
    packDbg.setMnemonic(KeyEvent.VK_P);
    packDbg.setToolTipText(Messages.getString("TracesTab.40"));
    packDbg.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JComponent comp = PMS.get().dbgPack().config();
            String[] cancelStr = { Messages.getString("Dialog.Close") };
            JOptionPane.showOptionDialog(looksFrame, comp, Messages.getString("Dialog.Options"), JOptionPane.CLOSED_OPTION, JOptionPane.PLAIN_MESSAGE, null, cancelStr, null);
        }
    });
    pLogPackButtons.add(packDbg);
    builder.add(pLogPackButtons, cc.xy(1, 4));
    builder.add(jSearchOutput, cc.xy(2, 4));
    JPanel builtPanel = builder.getPanel();
    // Add a Ctrl + F shortcut to search field
    builtPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_DOWN_MASK), "Ctrl_F");
    builtPanel.getActionMap().put("Ctrl_F", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            jSearchBox.requestFocusInWindow();
        }
    });
    builtPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), "F3");
    builtPanel.getActionMap().put("F3", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            searchTraces();
        }
    });
    applyViewLevel();
    return builtPanel;
}
Also used : ActionEvent(java.awt.event.ActionEvent) CellConstraints(com.jgoodies.forms.layout.CellConstraints) PanelBuilder(com.jgoodies.forms.builder.PanelBuilder) Color(java.awt.Color) ComponentOrientation(java.awt.ComponentOrientation) ActionListener(java.awt.event.ActionListener) Level(ch.qos.logback.classic.Level) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) FlowLayout(java.awt.FlowLayout) Logger(org.slf4j.Logger) Font(java.awt.Font) KeyEvent(java.awt.event.KeyEvent) ChangeListener(javax.swing.event.ChangeListener) FormLayout(com.jgoodies.forms.layout.FormLayout) Dimension(java.awt.Dimension) ChangeEvent(javax.swing.event.ChangeEvent) KeyListener(java.awt.event.KeyListener)

Example 49 with KeyListener

use of java.awt.event.KeyListener in project fql by CategoricalData.

the class AqlDisplay method display.

private void display(String s, @SuppressWarnings("unused") List<String> order, JComponent report) {
    frame = new JFrame();
    Vector<String> ooo = new Vector<>();
    for (Pair<String, JComponent> p : frames) {
        x.add(p.second, p.first);
        ooo.add(p.first);
    }
    x.add(report, "Summary");
    cl.show(x, "Summary");
    current = "Summary";
    yyy.setListData(ooo);
    yyy.setSelectedIndex(0);
    JPanel temp1 = new JPanel(new GridLayout(1, 1));
    temp1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Select:"));
    JScrollPane yyy1 = new JScrollPane(yyy);
    temp1.add(yyy1);
    yyy.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    yyy.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            JComponent c = lookup(current);
            if (!(c instanceof JTabbedPane) || c == null) {
                return;
            }
            JTabbedPane p = (JTabbedPane) c;
            int i = p.getSelectedIndex();
            int j = -1;
            if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                j = i - 1;
                if (j < 0) {
                    j = p.getTabCount() - 1;
                }
                p.setSelectedIndex(j);
                p.revalidate();
            } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                j = i + 1;
                if (j >= p.getTabCount()) {
                    j = 0;
                }
                p.setSelectedIndex(j);
                p.revalidate();
            }
        }
    });
    yyy.addListSelectionListener(e -> {
        int i = yyy.getSelectedIndex();
        if (i == -1) {
            cl.show(x, "Summary");
            current = "Summary";
        } else {
            cl.show(x, ooo.get(i));
            current = ooo.get(i);
        }
    });
    JPanel north = new JPanel(new GridLayout(1, 1));
    JSplitPane px = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    px.setDividerLocation(200);
    px.setDividerSize(4);
    frame = new JFrame(/* "Viewer for " + */
    s);
    // TODO AQL what is other split pane?
    JSplitPane temp2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    temp2.setResizeWeight(1);
    temp2.setDividerSize(0);
    temp2.setBorder(BorderFactory.createEmptyBorder());
    temp2.add(temp1);
    temp2.add(north);
    px.add(temp2);
    px.add(x);
    frame.setContentPane(px);
    frame.setSize(900, 600);
    ActionListener escListener = e -> frame.dispose();
    frame.getRootPane().registerKeyboardAction(escListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
    KeyStroke ctrlW = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK);
    KeyStroke commandW = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.META_MASK);
    frame.getRootPane().registerKeyboardAction(escListener, ctrlW, JComponent.WHEN_IN_FOCUSED_WINDOW);
    frame.getRootPane().registerKeyboardAction(escListener, commandW, JComponent.WHEN_IN_FOCUSED_WINDOW);
    frame.setLocationRelativeTo(null);
    if (exn != null) {
        frame.setLocation(frame.getLocation().x + 400, frame.getLocation().y);
    }
    frame.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) InputEvent(java.awt.event.InputEvent) ListSelectionModel(javax.swing.ListSelectionModel) KeyListener(java.awt.event.KeyListener) CardLayout(java.awt.CardLayout) ActionListener(java.awt.event.ActionListener) JSplitPane(javax.swing.JSplitPane) Point(java.awt.Point) HashMap(java.util.HashMap) AqlTyping(catdata.aql.exp.AqlTyping) AqlOption(catdata.aql.AqlOptions.AqlOption) LineException(catdata.LineException) Instance(catdata.aql.Instance) GridLayout(java.awt.GridLayout) Vector(java.util.Vector) Map(java.util.Map) JTabbedPane(javax.swing.JTabbedPane) MouseAdapter(java.awt.event.MouseAdapter) Exp(catdata.aql.exp.Exp) LinkedList(java.util.LinkedList) JFrame(javax.swing.JFrame) Pair(catdata.Pair) RoundingMode(java.math.RoundingMode) Semantics(catdata.aql.Semantics) JComponent(javax.swing.JComponent) KeyStroke(javax.swing.KeyStroke) PragmaExpConsistent(catdata.aql.exp.PragmaExp.PragmaExpConsistent) CodeTextPanel(catdata.ide.CodeTextPanel) Disp(catdata.ide.Disp) Kind(catdata.aql.Kind) DecimalFormat(java.text.DecimalFormat) JList(javax.swing.JList) Util(catdata.Util) BorderFactory(javax.swing.BorderFactory) KeyEvent(java.awt.event.KeyEvent) AqlEnv(catdata.aql.exp.AqlEnv) MouseEvent(java.awt.event.MouseEvent) JScrollPane(javax.swing.JScrollPane) List(java.util.List) Program(catdata.Program) PragmaExpCheck(catdata.aql.exp.PragmaExp.PragmaExpCheck) GuiUtil(catdata.ide.GuiUtil) JPanel(javax.swing.JPanel) Toolkit(java.awt.Toolkit) JPanel(javax.swing.JPanel) JTabbedPane(javax.swing.JTabbedPane) JComponent(javax.swing.JComponent) Point(java.awt.Point) KeyEvent(java.awt.event.KeyEvent) GridLayout(java.awt.GridLayout) ActionListener(java.awt.event.ActionListener) JFrame(javax.swing.JFrame) KeyStroke(javax.swing.KeyStroke) KeyListener(java.awt.event.KeyListener) JSplitPane(javax.swing.JSplitPane) Vector(java.util.Vector)

Example 50 with KeyListener

use of java.awt.event.KeyListener in project Universal-G-Code-Sender by winder.

the class MacroPanel method createMacroField.

private JTextField createMacroField(int index, MACRO_FIELD f, String text) {
    JTextField textField = new JTextField(text);
    textField.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
            update(index, f, textField.getText());
        }

        @Override
        public void keyPressed(KeyEvent e) {
            update(index, f, textField.getText());
        }

        @Override
        public void keyReleased(KeyEvent e) {
            update(index, f, textField.getText());
        }
    });
    return textField;
}
Also used : KeyEvent(java.awt.event.KeyEvent) KeyListener(java.awt.event.KeyListener)

Aggregations

KeyListener (java.awt.event.KeyListener)64 KeyEvent (java.awt.event.KeyEvent)53 JPanel (javax.swing.JPanel)20 ActionEvent (java.awt.event.ActionEvent)18 ActionListener (java.awt.event.ActionListener)17 GridBagConstraints (java.awt.GridBagConstraints)15 JLabel (javax.swing.JLabel)14 JTextField (javax.swing.JTextField)13 GridBagLayout (java.awt.GridBagLayout)12 Insets (java.awt.Insets)11 BorderLayout (java.awt.BorderLayout)8 Dimension (java.awt.Dimension)8 FocusEvent (java.awt.event.FocusEvent)8 FocusListener (java.awt.event.FocusListener)8 JButton (javax.swing.JButton)8 Point (java.awt.Point)7 MouseAdapter (java.awt.event.MouseAdapter)6 MouseEvent (java.awt.event.MouseEvent)6 JComponent (javax.swing.JComponent)5 Color (java.awt.Color)4