Example usage for java.awt Component dispatchEvent

List of usage examples for java.awt Component dispatchEvent

Introduction

In this page you can find the example usage for java.awt Component dispatchEvent.

Prototype

public final void dispatchEvent(AWTEvent e) 

Source Link

Document

Dispatches an event to this component or one of its sub components.

Usage

From source file:org.nuclos.client.ui.collect.SubForm.java

/**
 * create an Tablecelleditor for the given component
 * @param clctcomp//  w  ww.j a  va  2  s . c o  m
 * @return the newly created table cell editor
 */
private CollectableComponentTableCellEditor createTableCellEditor(final CollectableComponent clctcomp) {
    if (getColumn(clctcomp.getFieldName()) != null) {
        final Map<String, Object> properties = getColumn(clctcomp.getFieldName()).getProperties();
        for (String property : properties.keySet()) {
            clctcomp.setProperty(property, properties.get(property));
        }
    }
    final CollectableComponentTableCellEditor result = new CollectableComponentTableCellEditor(clctcomp,
            clctcomp.isSearchComponent());

    result.addCollectableComponentModelListener(getCollectableTableCellEditorChangeListener());

    // @see NUCLOS-603. checkboxes and options should setvalue directly.
    if (clctcomp instanceof CollectableCheckBox) {
        ((CollectableCheckBox) clctcomp).getJCheckBox().addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                SwingUtilities.invokeLater(new Runnable() { //@see NUCLOSINT-1635
                    public void run() {
                        try {
                            if (getSubformTable().getModel() instanceof SubFormTableModel) {
                                int row = getSubformTable().getSelectedRow();
                                int column = ((SubFormTableModel) getSubformTable().getModel())
                                        .findColumnByFieldName(clctcomp.getFieldName());
                                if (row != -1 && column != -1) {
                                    if (getSubformTable().getModel() instanceof SearchConditionTableModel)
                                        getSubformTable().setValueAt(clctcomp.getSearchCondition(), row,
                                                column);
                                    else
                                        getSubformTable().setValueAt(clctcomp.getField(), row, column);
                                }
                            }
                        } catch (CollectableFieldFormatException e1) {
                            LOG.warn("could not set value for " + clctcomp.getFieldName(), e1);
                        }
                    }
                });
            }
        });
    }
    if (clctcomp instanceof CollectableOptionGroup) {
        ((CollectableOptionGroup) clctcomp).getOptionGroup().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    if (getSubformTable().getModel() instanceof SubFormTableModel) {
                        int row = getSubformTable().getSelectedRow();
                        int column = ((SubFormTableModel) getSubformTable().getModel())
                                .findColumnByFieldName(clctcomp.getFieldName());
                        if (row != -1 && column != -1)
                            getSubformTable().setValueAt(clctcomp.getField(), row, column);
                    }

                } catch (CollectableFieldFormatException e1) {
                    LOG.warn("could not set value for " + clctcomp.getFieldName(), e1);
                }
            }
        });
    }

    // textarea have to handle Tab in an subform differently.
    if (clctcomp instanceof NuclosCollectableTextArea) {
        ((NuclosCollectableTextArea) clctcomp).overrideActionMap(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                Component c = (Component) ((NuclosCollectableTextArea) clctcomp).getJTextArea().getParent();
                c.dispatchEvent(
                        new KeyEvent(c, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), 0, KeyEvent.VK_TAB));
            }
        }, new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                Component c = (Component) ((NuclosCollectableTextArea) clctcomp).getJTextArea().getParent();
                c.dispatchEvent(new KeyEvent(c, KeyEvent.KEY_PRESSED, System.currentTimeMillis(),
                        KeyEvent.SHIFT_MASK, KeyEvent.VK_TAB));
            }
        });
    }
    if (clctcomp instanceof DynamicRowHeightChangeProvider) {
        ((DynamicRowHeightChangeProvider) clctcomp).addDynamicRowHeightChangeListener(this);
    }

    return result;
}