use of javax.swing.InputMap in project adempiere by adempiere.
the class CompiereLabelUI method installKeyboardActions.
// createUI
/**
* Install Keyboard Actions
* @param l label
*/
protected void installKeyboardActions(JLabel l) {
// super.installKeyboardActions(l);
int dka = l.getDisplayedMnemonic();
if (dka != 0) {
Component lf = l.getLabelFor();
if (lf != null) {
ActionMap actionMap = l.getActionMap();
actionMap.put(PRESS, ACTION_PRESS);
InputMap inputMap = SwingUtilities.getUIInputMap(l, JComponent.WHEN_IN_FOCUSED_WINDOW);
if (inputMap == null) {
inputMap = new ComponentInputMapUIResource(l);
SwingUtilities.replaceUIInputMap(l, JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap);
}
inputMap.clear();
inputMap.put(KeyStroke.getKeyStroke(dka, ActionEvent.SHIFT_MASK + ActionEvent.CTRL_MASK, false), PRESS);
}
}
}
use of javax.swing.InputMap in project adempiere by adempiere.
the class CCheckBox method setMnemonic.
// createMnemonic
/**
* Overrides the JCheckBox.setMnemonic() method, setting modifier keys to
* CTRL+SHIFT.
*
* @param mnemonic
* The mnemonic character code.
*/
public void setMnemonic(int mnemonic) {
super.setMnemonic(mnemonic);
InputMap map = SwingUtilities.getUIInputMap(this, JComponent.WHEN_IN_FOCUSED_WINDOW);
if (map == null) {
map = new ComponentInputMapUIResource(this);
SwingUtilities.replaceUIInputMap(this, JComponent.WHEN_IN_FOCUSED_WINDOW, map);
}
map.clear();
String className = this.getClass().getName();
// Default Buttons
int mask = InputEvent.ALT_MASK;
if (// In Tab
this instanceof JCheckBox || className.indexOf("VButton") != -1)
mask = InputEvent.SHIFT_MASK + InputEvent.CTRL_MASK;
map.put(KeyStroke.getKeyStroke(mnemonic, mask, false), "pressed");
map.put(KeyStroke.getKeyStroke(mnemonic, mask, true), "released");
map.put(KeyStroke.getKeyStroke(mnemonic, 0, true), "released");
setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, map);
}
use of javax.swing.InputMap in project adempiere by adempiere.
the class CButton method setMnemonic.
// setActionCommand
/**
* Overrides the JButton.setMnemonic() method, setting modifier keys to
* CTRL+ALT.
*
* @param mnemonic
* The mnemonic character code.
*/
public void setMnemonic(int mnemonic) {
super.setMnemonic(mnemonic);
// Angelo Dabala' (genied) avoid to register Ctrl+Alt modifier mask without mnemonic
if (mnemonic == KeyEvent.VK_UNDEFINED) {
return;
}
InputMap map = SwingUtilities.getUIInputMap(this, JComponent.WHEN_IN_FOCUSED_WINDOW);
if (map == null) {
map = new ComponentInputMapUIResource(this);
SwingUtilities.replaceUIInputMap(this, JComponent.WHEN_IN_FOCUSED_WINDOW, map);
}
map.clear();
// Default
int mask = InputEvent.ALT_MASK + InputEvent.CTRL_MASK;
// Buttons
map.put(KeyStroke.getKeyStroke(mnemonic, mask, false), "pressed");
map.put(KeyStroke.getKeyStroke(mnemonic, mask, true), "released");
map.put(KeyStroke.getKeyStroke(mnemonic, 0, true), "released");
setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, map);
}
use of javax.swing.InputMap in project adempiere by adempiere.
the class ADempiereAutoCompleteDecorator method decorate.
/**
* Decorates a given text component for automatic completion using the
* given AutoCompleteDocument and AbstractAutoCompleteAdaptor.
*
*
* @param textComponent a text component that should be decorated
* @param document the AutoCompleteDocument to be installed on the text component
* @param adaptor the AbstractAutoCompleteAdaptor to be used
*/
public static void decorate(JTextComponent textComponent, AutoCompleteDocument document, final AbstractAutoCompleteAdaptor adaptor) {
// install the document on the text component
textComponent.setDocument(document);
// mark entire text when the text component gains focus
// otherwise the last mark would have been retained which is quiet confusing
textComponent.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
JTextComponent textComponent = (JTextComponent) e.getSource();
adaptor.markEntireText();
}
});
// Tweak some key bindings
InputMap editorInputMap = textComponent.getInputMap();
if (document.isStrictMatching()) {
// move the selection to the left on VK_BACK_SPACE
editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_BACK_SPACE, 0), DefaultEditorKit.selectionBackwardAction);
// ignore VK_DELETE and CTRL+VK_X and beep instead when strict matching
editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DELETE, 0), errorFeedbackAction);
editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_DOWN_MASK), errorFeedbackAction);
} else {
ActionMap editorActionMap = textComponent.getActionMap();
// leave VK_DELETE and CTRL+VK_X as is
// VK_BACKSPACE will move the selection to the left if the selected item is in the list
// it will delete the previous character otherwise
editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_BACK_SPACE, 0), "nonstrict-backspace");
editorActionMap.put("nonstrict-backspace", new NonStrictBackspaceAction(editorActionMap.get(DefaultEditorKit.deletePrevCharAction), editorActionMap.get(DefaultEditorKit.selectionBackwardAction), adaptor));
editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_TAB, java.awt.event.KeyEvent.CTRL_DOWN_MASK), "NextMatchAction");
editorActionMap.put("NextMatchAction", new NextMatchAction(textComponent, document, adaptor));
}
}
use of javax.swing.InputMap in project adempiere by adempiere.
the class Find method initFindAdvanced.
// addSelectionColumn
/**
* Init Find GridController
*/
private void initFindAdvanced() {
log.config("");
advancedTable.setModel(new DefaultTableModel(0, 7));
advancedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
advancedTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
advancedTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
TableCellRenderer renderer = new ProxyRenderer(advancedTable.getDefaultRenderer(Object.class));
advancedTable.setDefaultRenderer(Object.class, renderer);
InputMap im = advancedTable.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
final Action tabAction = advancedTable.getActionMap().get(im.get(tab));
Action tabActionWrapper = new AbstractAction() {
private static final long serialVersionUID = -6868476640719619801L;
public void actionPerformed(ActionEvent e) {
tabAction.actionPerformed(e);
JTable table = (JTable) e.getSource();
table.requestFocusInWindow();
}
};
advancedTable.getActionMap().put(im.get(tab), tabActionWrapper);
KeyStroke shiftTab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK);
final Action shiftTabAction = advancedTable.getActionMap().get(im.get(shiftTab));
Action shiftTabActionWrapper = new AbstractAction() {
private static final long serialVersionUID = 5493691483070046620L;
public void actionPerformed(ActionEvent e) {
shiftTabAction.actionPerformed(e);
JTable table = (JTable) e.getSource();
table.requestFocusInWindow();
}
};
advancedTable.getActionMap().put(im.get(shiftTab), shiftTabActionWrapper);
// 0 = Columns
ArrayList<ValueNamePair> items = new ArrayList<ValueNamePair>();
for (int c = 0; c < m_findFields.length; c++) {
GridField field = m_findFields[c];
String columnName = field.getColumnName();
String header = field.getHeader();
if (header == null || header.length() == 0) {
header = Msg.translate(Env.getCtx(), columnName);
if (header == null || header.length() == 0)
continue;
}
if (field.isKey())
header += (" (ID)");
ValueNamePair pp = new ValueNamePair(columnName, header);
// System.out.println(pp + " = " + field);
items.add(pp);
}
columnValueNamePairs = new ValueNamePair[items.size()];
items.toArray(columnValueNamePairs);
// sort alpha
Arrays.sort(columnValueNamePairs);
columns = new CComboBox(columnValueNamePairs);
columns.addActionListener(this);
TableColumn tc = advancedTable.getColumnModel().getColumn(INDEX_COLUMNNAME);
tc.setPreferredWidth(120);
FindCellEditor dce = new FindCellEditor(columns);
dce.addCellEditorListener(new CellEditorListener() {
public void editingCanceled(ChangeEvent ce) {
}
public void editingStopped(ChangeEvent ce) {
int col = advancedTable.getSelectedColumn();
int row = advancedTable.getSelectedRow();
if (col == INDEX_COLUMNNAME && row >= 0) {
advancedTable.setValueAt(null, row, INDEX_VALUE);
advancedTable.setValueAt(null, row, INDEX_VALUE2);
}
}
});
tc.setCellEditor(dce);
tc.setHeaderValue(Msg.translate(Env.getCtx(), "AD_Column_ID"));
// 0 = And/Or
andOr = new CComboBox(new String[] { "", Msg.getMsg(Env.getCtx(), "AND"), Msg.getMsg(Env.getCtx(), "OR") });
tc = advancedTable.getColumnModel().getColumn(INDEX_ANDOR);
tc.setPreferredWidth(45);
dce = new FindCellEditor(andOr);
tc.setCellEditor(dce);
tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "And/Or"));
// 1 = Left Bracket
leftBrackets = new CComboBox(new String[] { "", "(", "((", "(((" });
tc = advancedTable.getColumnModel().getColumn(INDEX_LEFTBRACKET);
tc.setPreferredWidth(25);
dce = new FindCellEditor(leftBrackets);
tc.setCellEditor(dce);
tc.setHeaderValue("(");
// 3 = Operators
operators = new CComboBox(MQuery.OPERATORS);
tc = advancedTable.getColumnModel().getColumn(INDEX_OPERATOR);
tc.setPreferredWidth(55);
dce = new FindCellEditor(operators);
tc.setCellEditor(dce);
tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "Operator"));
// 4 = QueryValue
tc = advancedTable.getColumnModel().getColumn(INDEX_VALUE);
FindValueEditor fve = new FindValueEditor(this, false);
tc.setCellEditor(fve);
tc.setPreferredWidth(120);
tc.setCellRenderer(new ProxyRenderer(new FindValueRenderer(this, false)));
tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "QueryValue"));
// 5 = QueryValue2
tc = advancedTable.getColumnModel().getColumn(INDEX_VALUE2);
tc.setPreferredWidth(120);
fve = new FindValueEditor(this, true);
tc.setCellEditor(fve);
tc.setCellRenderer(new ProxyRenderer(new FindValueRenderer(this, false)));
tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "QueryValue2"));
// 6 = Right Bracket
rightBrackets = new CComboBox(new String[] { "", ")", "))", ")))" });
tc = advancedTable.getColumnModel().getColumn(INDEX_RIGHTBRACKET);
tc.setPreferredWidth(25);
dce = new FindCellEditor(rightBrackets);
tc.setCellEditor(dce);
tc.setHeaderValue(")");
// phib: disabled auto-completion as it causes date fields to have to be entered twice
//AutoCompletion.enable(columns);
//AutoCompletion.enable(operators);
//user query
refreshUserQueries();
}
Aggregations