List of usage examples for javax.swing ComponentInputMap put
public void put(KeyStroke keyStroke, Object actionMapKey)
keyStroke
to actionMapKey
. From source file:ca.phon.app.session.editor.view.session_information.SessionInfoEditorView.java
private void init() { setLayout(new BorderLayout()); contentPanel = new TierDataLayoutPanel(); dateField = createDateField();/*from w ww .j a v a2 s .c o m*/ dateField.getTextField().setColumns(10); dateField.setBackground(Color.white); mediaLocationField = new MediaSelectionField(getEditor().getProject()); mediaLocationField.setEditor(getEditor()); mediaLocationField.getTextField().setColumns(10); mediaLocationField.addPropertyChangeListener(FileSelectionField.FILE_PROP, mediaLocationListener); participantTable = new JXTable(); participantTable.setVisibleRowCount(3); ComponentInputMap participantTableInputMap = new ComponentInputMap(participantTable); ActionMap participantTableActionMap = new ActionMap(); ImageIcon deleteIcon = IconManager.getInstance().getIcon("actions/delete_user", IconSize.SMALL); final PhonUIAction deleteAction = new PhonUIAction(this, "deleteParticipant"); deleteAction.putValue(PhonUIAction.SHORT_DESCRIPTION, "Delete selected participant"); deleteAction.putValue(PhonUIAction.SMALL_ICON, deleteIcon); participantTableActionMap.put("DELETE_PARTICIPANT", deleteAction); participantTableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "DELETE_PARTICIPANT"); participantTableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "DELETE_PARTICIPANT"); removeParticipantButton = new JButton(deleteAction); participantTable.setInputMap(WHEN_FOCUSED, participantTableInputMap); participantTable.setActionMap(participantTableActionMap); addParticipantButton = new JButton(new NewParticipantAction(getEditor(), this)); addParticipantButton.setFocusable(false); ImageIcon editIcon = IconManager.getInstance().getIcon("actions/edit_user", IconSize.SMALL); final PhonUIAction editParticipantAct = new PhonUIAction(this, "editParticipant"); editParticipantAct.putValue(PhonUIAction.NAME, "Edit participant..."); editParticipantAct.putValue(PhonUIAction.SHORT_DESCRIPTION, "Edit selected participant..."); editParticipantAct.putValue(PhonUIAction.SMALL_ICON, editIcon); editParticipantButton = new JButton(editParticipantAct); editParticipantButton.setFocusable(false); final CellConstraints cc = new CellConstraints(); FormLayout participantLayout = new FormLayout("fill:pref:grow, pref, pref, pref", "pref, pref, pref:grow"); JPanel participantPanel = new JPanel(participantLayout); participantPanel.setBackground(Color.white); participantPanel.add(new JScrollPane(participantTable), cc.xywh(1, 2, 3, 2)); participantPanel.add(addParticipantButton, cc.xy(2, 1)); participantPanel.add(editParticipantButton, cc.xy(3, 1)); participantPanel.add(removeParticipantButton, cc.xy(4, 2)); participantTable.addMouseListener(new MouseInputAdapter() { @Override public void mouseClicked(MouseEvent arg0) { if (arg0.getClickCount() == 2 && arg0.getButton() == MouseEvent.BUTTON1) { editParticipantAct.actionPerformed(new ActionEvent(arg0.getSource(), arg0.getID(), "edit")); } } }); languageField = new LanguageField(); languageField.getDocument().addDocumentListener(languageFieldListener); int rowIdx = 0; final JLabel dateLbl = new JLabel("Session Date"); dateLbl.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(dateLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx)); contentPanel.add(dateField, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++)); final JLabel mediaLbl = new JLabel("Media"); mediaLbl.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(mediaLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx)); contentPanel.add(mediaLocationField, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++)); final JLabel partLbl = new JLabel("Participants"); partLbl.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(partLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx)); contentPanel.add(participantPanel, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++)); final JLabel langLbl = new JLabel("Language"); langLbl.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(langLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx)); contentPanel.add(languageField, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++)); add(new JScrollPane(contentPanel), BorderLayout.CENTER); update(); }