Search in sources :

Example 71 with FocusEvent

use of java.awt.event.FocusEvent in project ceylon-compiler by ceylon.

the class SelectToolTask method createPane.

JOptionPane createPane(final Properties props) {
    JPanel body = new JPanel(new GridBagLayout());
    GridBagConstraints lc = new GridBagConstraints();
    lc.insets.right = 10;
    lc.insets.bottom = 3;
    GridBagConstraints fc = new GridBagConstraints();
    fc.anchor = GridBagConstraints.WEST;
    fc.gridx = 1;
    fc.gridwidth = GridBagConstraints.REMAINDER;
    fc.insets.bottom = 3;
    JLabel toolLabel = new JLabel("Tool:");
    body.add(toolLabel, lc);
    String[] toolChoices = { "apt", "javac", "javadoc", "javah", "javap" };
    if (true || toolProperty == null) {
        // include empty value in setup mode
        List<String> l = new ArrayList<String>(Arrays.asList(toolChoices));
        l.add(0, "");
        toolChoices = l.toArray(new String[l.size()]);
    }
    toolChoice = new JComboBox(toolChoices);
    if (toolName != null)
        toolChoice.setSelectedItem(toolName);
    toolChoice.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            String tn = (String) e.getItem();
            argsField.setText(getDefaultArgsForTool(props, tn));
            if (toolProperty != null)
                okButton.setEnabled(!tn.equals(""));
        }
    });
    body.add(toolChoice, fc);
    argsField = new JTextField(getDefaultArgsForTool(props, toolName), 40);
    if (toolProperty == null || argsProperty != null) {
        JLabel argsLabel = new JLabel("Args:");
        body.add(argsLabel, lc);
        body.add(argsField, fc);
        argsField.addFocusListener(new FocusListener() {

            public void focusGained(FocusEvent e) {
            }

            public void focusLost(FocusEvent e) {
                String toolName = (String) toolChoice.getSelectedItem();
                if (toolName.length() > 0)
                    props.put(toolName + ".args", argsField.getText());
            }
        });
    }
    defaultCheck = new JCheckBox("Set as default");
    if (toolProperty == null)
        defaultCheck.setSelected(true);
    else
        body.add(defaultCheck, fc);
    final JOptionPane p = new JOptionPane(body);
    okButton = new JButton("OK");
    okButton.setEnabled(toolProperty == null || (toolName != null && !toolName.equals("")));
    okButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JDialog d = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, p);
            d.setVisible(false);
        }
    });
    p.setOptions(new Object[] { okButton });
    return p;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) ItemEvent(java.awt.event.ItemEvent) GridBagLayout(java.awt.GridBagLayout) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent) JOptionPane(javax.swing.JOptionPane) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener) FocusListener(java.awt.event.FocusListener) JDialog(javax.swing.JDialog)

Example 72 with FocusEvent

use of java.awt.event.FocusEvent in project SAGU by brianmcmichael.

the class LogTypesTest method isEventSourceShouldWork.

@Test
public void isEventSourceShouldWork() throws Exception {
    final LogTypes logTypes = new LogTypes(menu, 0);
    final FocusEvent event = mock(FocusEvent.class);
    assertThat(logTypes.isEventSource(event), is(false));
    when(event.getSource()).thenReturn(logTypes.getLogRadio());
    assertThat(logTypes.isEventSource(event), is(true));
    when(event.getSource()).thenReturn(logTypes.getTxtRadio());
    assertThat(logTypes.isEventSource(event), is(true));
    when(event.getSource()).thenReturn(logTypes.getCsvRadio());
    assertThat(logTypes.isEventSource(event), is(true));
    when(event.getSource()).thenReturn(logTypes.getYamlRadio());
    assertThat(logTypes.isEventSource(event), is(true));
}
Also used : FocusEvent(java.awt.event.FocusEvent) Test(org.testng.annotations.Test)

Example 73 with FocusEvent

use of java.awt.event.FocusEvent in project processdash by dtuma.

the class AbstractCustomProcessEditor method buildHeader.

private Component buildHeader() {
    Box header = Box.createHorizontalBox();
    header.add(Box.createHorizontalStrut(2));
    header.add(new JLabel("Framework Name: "));
    header.add(processName = new JTextField(20));
    header.add(Box.createHorizontalStrut(10));
    header.add(new JLabel("Framework Version: "));
    header.add(processVersion = new JTextField(5));
    header.add(Box.createHorizontalStrut(2));
    // Notify the process of changes to the name and version
    FocusListener l = new FocusAdapter() {

        public void focusLost(FocusEvent e) {
            process.setName(processName.getText());
            processName.setText(process.getName());
            process.setVersion(processVersion.getText());
            processVersion.setText(process.getVersion());
        }
    };
    processName.addFocusListener(l);
    processVersion.addFocusListener(l);
    Box result = Box.createVerticalBox();
    result.add(Box.createVerticalStrut(2));
    result.add(header);
    result.add(Box.createVerticalStrut(2));
    return result;
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) JLabel(javax.swing.JLabel) Box(javax.swing.Box) JTextField(javax.swing.JTextField) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 74 with FocusEvent

use of java.awt.event.FocusEvent in project processdash by dtuma.

the class BoundTextField method addUpdateFromTextListeners.

protected void addUpdateFromTextListeners() {
    addActionListener((ActionListener) EventHandler.create(ActionListener.class, this, "updateFromText"));
    addFocusListener(new FocusAdapter() {

        public void focusLost(FocusEvent e) {
            updateFromText();
        }
    });
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) FocusEvent(java.awt.event.FocusEvent)

Example 75 with FocusEvent

use of java.awt.event.FocusEvent in project vcell by virtualcell.

the class ScrollTable method initialize.

private void initialize() {
    autoResizeMode = AUTO_RESIZE_OFF;
    // make it bigger on Mac
    setRowHeight(getRowHeight() + 4);
    putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);
    scrollTableActionManager = new DefaultScrollTableActionManager(this);
    enclosingScrollPane = new JScrollPane(this);
    enclosingScrollPane.getViewport().setBackground(Color.WHITE);
    contentPanel = new JPanel(new BorderLayout());
    contentPanel.add(enclosingScrollPane, BorderLayout.CENTER);
    setPreferredScrollableViewportSize(new Dimension(200, 100));
    setIntercellSpacing(new Dimension(2, 2));
    defaultTableCellRenderer = new DefaultScrollTableCellRenderer();
    setDefaultRenderer(Object.class, defaultTableCellRenderer);
    setDefaultRenderer(Number.class, defaultTableCellRenderer);
    setDefaultRenderer(Double.class, defaultTableCellRenderer);
    setDefaultRenderer(Boolean.class, new ScrollTableBooleanCellRenderer());
    setDefaultEditor(Boolean.class, new ScrollTableBooleanEditor());
    final TableCellRenderer defaultTableCellHeaderRenderer = getTableHeader().getDefaultRenderer();
    TableCellRenderer defaultTableHeaderRenderer = new TableCellRenderer() {

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            Component component = defaultTableCellHeaderRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (component instanceof JLabel) {
                JLabel label = (JLabel) component;
                label.setHorizontalAlignment(SwingConstants.CENTER);
                label.setBackground(tableHeaderColor);
                label.setBorder(BorderFactory.createCompoundBorder(tableCellHeaderBorder, new EmptyBorder(1, 0, 1, 0)));
            }
            return component;
        }
    };
    getTableHeader().setDefaultRenderer(defaultTableHeaderRenderer);
    MouseAdapter mouseListener = new MouseAdapter() {

        @Override
        public void mouseClicked(final MouseEvent e) {
            if (!javaVersion.startsWith("1.5")) {
                if (!hasFocus()) {
                    if (e.getButton() == MouseEvent.BUTTON1) {
                        addFocusListener(new FocusListener() {

                            public void focusLost(FocusEvent e) {
                            }

                            public void focusGained(FocusEvent e) {
                                removeFocusListener(this);
                                Robot robot;
                                try {
                                    robot = new Robot();
                                    robot.mousePress(InputEvent.BUTTON1_MASK);
                                    robot.mouseRelease(InputEvent.BUTTON1_MASK);
                                } catch (AWTException ex) {
                                    ex.printStackTrace();
                                }
                            }
                        });
                    }
                    requestFocusInWindow();
                }
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            scrollTableActionManager.triggerPopup(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            scrollTableActionManager.triggerPopup(e);
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            hoverRow = rowAtPoint(e.getPoint());
            hoverColumn = columnAtPoint(e.getPoint());
            repaint();
        }

        @Override
        public void mouseExited(MouseEvent e) {
            hoverRow = -1;
            hoverColumn = -1;
            repaint();
        }
    };
    MouseMotionAdapter mouseMotionListener = new MouseMotionAdapter() {

        @Override
        public void mouseMoved(MouseEvent e) {
            hoverRow = rowAtPoint(e.getPoint());
            hoverColumn = columnAtPoint(e.getPoint());
            repaint();
        }
    };
    addMouseListener(mouseListener);
    addMouseMotionListener(mouseMotionListener);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) TableCellRenderer(javax.swing.table.TableCellRenderer) ScopedExpressionTableCellRenderer(cbit.vcell.model.gui.ScopedExpressionTableCellRenderer) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) FocusEvent(java.awt.event.FocusEvent) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) BorderLayout(java.awt.BorderLayout) JTable(javax.swing.JTable) EventObject(java.util.EventObject) Component(java.awt.Component) JComponent(javax.swing.JComponent) EmptyBorder(javax.swing.border.EmptyBorder) FocusListener(java.awt.event.FocusListener) Robot(java.awt.Robot) AWTException(java.awt.AWTException)

Aggregations

FocusEvent (java.awt.event.FocusEvent)81 FocusListener (java.awt.event.FocusListener)38 FocusAdapter (java.awt.event.FocusAdapter)33 JLabel (javax.swing.JLabel)21 ActionEvent (java.awt.event.ActionEvent)18 ActionListener (java.awt.event.ActionListener)17 JPanel (javax.swing.JPanel)15 JTextField (javax.swing.JTextField)15 Dimension (java.awt.Dimension)14 JButton (javax.swing.JButton)10 KeyEvent (java.awt.event.KeyEvent)9 JCheckBox (javax.swing.JCheckBox)9 BoxLayout (javax.swing.BoxLayout)8 JComboBox (javax.swing.JComboBox)8 Border (javax.swing.border.Border)8 Component (java.awt.Component)7 GridBagConstraints (java.awt.GridBagConstraints)6 GridBagLayout (java.awt.GridBagLayout)6 Insets (java.awt.Insets)6 MouseEvent (java.awt.event.MouseEvent)6