javax.swing.text.JTextComponent.getKeymap()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(159)

本文整理了Java中javax.swing.text.JTextComponent.getKeymap()方法的一些代码示例,展示了JTextComponent.getKeymap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextComponent.getKeymap()方法的具体详情如下:
包路径:javax.swing.text.JTextComponent
类名称:JTextComponent
方法名:getKeymap

JTextComponent.getKeymap介绍

暂无

代码示例

代码示例来源:origin: bobbylight/RSyntaxTextArea

/**
 * Creates the keymap for this text area.  This takes the super class's
 * keymap, but sets the default keystroke to be RTextAreaEditorKit's
 * DefaultKeyTypedAction.  This must be done to override the default
 * keymap's default key-typed action.
 *
 * @return The keymap.
 */
@Override
protected Keymap createKeymap() {
  // Load the keymap we'll be using (it's saved by
  // JTextComponent.addKeymap).
  Keymap map = JTextComponent.getKeymap(RTEXTAREA_KEYMAP_NAME);
  if (map==null) {
    Keymap parent = JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);
    map = JTextComponent.addKeymap(RTEXTAREA_KEYMAP_NAME, parent);
    map.setDefaultAction(new RTextAreaEditorKit.DefaultKeyTypedAction());
  }
  return map;
}

代码示例来源:origin: nodebox/nodebox

Keymap defaultKeymap = JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);
Keymap keymap = JTextComponent.addKeymap(null, defaultKeymap);
keymap.addActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), new EnterAction());

代码示例来源:origin: net.sf.squirrel-sql.plugins/syntax

private void unregisterKeyStrokes()
{
 KeyStroke keyStroke;
 keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Event.CTRL_MASK);
 _textPane.getKeymap().removeKeyStrokeBinding(keyStroke);
 keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Event.CTRL_MASK | Event.SHIFT_MASK);
 _textPane.getKeymap().removeKeyStrokeBinding(keyStroke);
 keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, Event.CTRL_MASK);
 _textPane.getKeymap().removeKeyStrokeBinding(keyStroke);
 keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, Event.CTRL_MASK | Event.SHIFT_MASK);
 _textPane.getKeymap().removeKeyStrokeBinding(keyStroke);
  keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, Event.CTRL_MASK);
  _textPane.getKeymap().removeKeyStrokeBinding(keyStroke);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-gsf

private void addAcceleretors(Action a, JMenuItem item, JTextComponent target) {
  // Try to get the accelerator
  Keymap km = target.getKeymap();
  if (km != null) {
    KeyStroke[] keys = km.getKeyStrokesForAction(a);
    if ((keys != null) && (keys.length > 0)) {
      item.setAccelerator(keys[0]);
    } else if (a != null) {
      KeyStroke ks = (KeyStroke)a.getValue(Action.ACCELERATOR_KEY);
      if (ks != null) {
        item.setAccelerator(ks);
      }
    }
  }
}

代码示例来源:origin: dcaoyuan/nbscala

/** Creates a new instance of FilteredKeymap */
public FilteredKeymap(final JTextComponent component) {
  
  class KeymapUpdater implements Runnable {
    public void run() {
      component.setKeymap(new FilteredKeymap(component));
    }
  }
  
  this.keyMap = component.getKeymap();
  component.addPropertyChangeListener("keymap", new PropertyChangeListener() {
    public void propertyChange(PropertyChangeEvent evt) {
      if (!(evt.getNewValue() instanceof FilteredKeymap)) {
        // We have to do that lazily, because the property change
        // is fired *before* the keymap is actually changed!
        component.removePropertyChangeListener("keymap", this);
        if (EventQueue.isDispatchThread()) {
          EventQueue.invokeLater(new KeymapUpdater());
        } else {
          RequestProcessor.getDefault().post(new KeymapUpdater(), 100);
        }
      }
    }
  });
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib

private void recordAction( JTextComponent target, ActionEvent evt ) {
  if( this == target.getKeymap().getDefaultAction() ) { // defaultKeyTyped
    textBuffer.append( getFilteredActionCommand(evt.getActionCommand()) );
  } else { // regular action
    if( textBuffer.length() > 0 ) {
      if( macroBuffer.length() > 0 ) macroBuffer.append( ' ' ); 
      macroBuffer.append( encodeText( textBuffer.toString() ) );
      textBuffer.setLength( 0 );
    }
    if( macroBuffer.length() > 0 ) macroBuffer.append( ' ' ); 
    String name = (String)getValue( Action.NAME );
    macroBuffer.append( encodeActionName( name ) );
  }
}

代码示例来源:origin: com.fifesoft/rsyntaxtextarea

/**
 * Creates the keymap for this text area.  This takes the super class's
 * keymap, but sets the default keystroke to be RTextAreaEditorKit's
 * DefaultKeyTypedAction.  This must be done to override the default
 * keymap's default key-typed action.
 *
 * @return The keymap.
 */
@Override
protected Keymap createKeymap() {
  // Load the keymap we'll be using (it's saved by
  // JTextComponent.addKeymap).
  Keymap map = JTextComponent.getKeymap(RTEXTAREA_KEYMAP_NAME);
  if (map==null) {
    Keymap parent = JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);
    map = JTextComponent.addKeymap(RTEXTAREA_KEYMAP_NAME, parent);
    map.setDefaultAction(new RTextAreaEditorKit.DefaultKeyTypedAction());
  }
  return map;
}

代码示例来源:origin: org.nuiton.thirdparty/rsyntaxtextarea

/**
 * Creates the keymap for this text area.  This takes the super class's
 * keymap, but sets the default keystroke to be RTextAreaEditorKit's
 * DefaultKeyTypedAction.  This must be done to override the default
 * keymap's default key-typed action.
 *
 * @return The keymap.
 */
protected Keymap createKeymap() {
  // Load the keymap we'll be using (it's saved by
  // JTextComponent.addKeymap).
  Keymap map = JTextComponent.getKeymap(RTEXTAREA_KEYMAP_NAME);
  if (map==null) {
    Keymap parent = JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);
    map = JTextComponent.addKeymap(RTEXTAREA_KEYMAP_NAME, parent);
    map.setDefaultAction(new RTextAreaEditorKit.DefaultKeyTypedAction());
  }
  return map;
}

代码示例来源:origin: org.codehaus.jtstand/jtstand-editor

/**
 * Creates the keymap for this text area.  This takes the super class's
 * keymap, but sets the default keystroke to be RTextAreaEditorKit's
 * DefaultKeyTypedAction.  This must be done to override the default
 * keymap's default key-typed action.
 *
 * @return The keymap.
 */
protected Keymap createKeymap() {
  // Load the keymap we'll be using (it's saved by
  // JTextComponent.addKeymap).
  Keymap map = JTextComponent.getKeymap(RTEXTAREA_KEYMAP_NAME);
  if (map==null) {
    Keymap parent = JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);
    map = JTextComponent.addKeymap(RTEXTAREA_KEYMAP_NAME, parent);
    map.setDefaultAction(new RTextAreaEditorKit.DefaultKeyTypedAction());
  }
  return map;
}

代码示例来源:origin: net.java.abeille/abeille

private void recordAction(JTextComponent target, ActionEvent evt) {
  if (this == target.getKeymap().getDefaultAction()) { // defaultKeyTyped
    textBuffer.append(getFilteredActionCommand(evt.getActionCommand()));
  }
  else { // regular action
    if (textBuffer.length() > 0) {
      if (macroBuffer.length() > 0)
        macroBuffer.append(' ');
      macroBuffer.append(encodeText(textBuffer.toString()));
      textBuffer.setLength(0);
    }
    if (macroBuffer.length() > 0)
      macroBuffer.append(' ');
    String name = (String) getValue(Action.NAME);
    macroBuffer.append(encodeActionName(name));
  }
}

代码示例来源:origin: net.sf.squirrel-sql.plugins/syntax

_textPane.getKeymap().addActionForKeyStroke(keyStroke,act);
_textPane.getKeymap().addActionForKeyStroke(keyStroke,act);
_textPane.getKeymap().addActionForKeyStroke(keyStroke,act);
_textPane.getKeymap().addActionForKeyStroke(keyStroke,act);
 _textPane.getKeymap().addActionForKeyStroke(keyStroke,act);

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib

private void addAcceleretors(Action a, JMenuItem item, BaseKit kit){
  // Try to get the accelerator
  javax.swing.text.JTextComponent target = Utilities.getFocusedComponent();
  if (target == null) return;
  javax.swing.text.Keymap km = target.getKeymap();
  if (km != null) {
    javax.swing.KeyStroke[] keys = km.getKeyStrokesForAction(a);
    if (keys != null && keys.length > 0) {
      item.setAccelerator(keys[0]);
    }else{
      // retrieve via actionName
      String actionName = (String)a.getValue(Action.NAME);
      if (actionName == null) return;
      BaseAction action = (BaseAction)kit.getActionByName(actionName);
      if (action == null) return;
      keys = km.getKeyStrokesForAction(action);
      if (keys != null && keys.length > 0) {
        item.setAccelerator(keys[0]);
      }                        
    }
  }
}

代码示例来源:origin: stackoverflow.com

import java.awt.event.*;
import javax.swing.*;

public class BackspaceCapture extends JDialog {

  public BackspaceCapture() {
    JTextField textField = new JTextField("A text field");
    textField.getKeymap().addActionForKeyStroke(
      KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
          backSpace();
        }
      });

    add(textField);
    pack();
  }

  public void backSpace() {
    System.out.println("Backspace is pressed");
  }

  public static void main(String args[]) {
    JDialog dialog = new BackspaceCapture();
    dialog.setVisible(true);
  }
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-vmd-midp

Keymap keymap = editor.getKeymap();
Action undoAction = new ActionFactory.UndoAction();
for (KeyStroke k : undoKeys) {

代码示例来源:origin: stackoverflow.com

JTextComponent component = new JTextArea();
pane.add(component, BorderLayout.SOUTH);
Keymap keymap = component.getKeymap();

代码示例来源:origin: net.java.abeille/abeille

item.addActionListener(a);
Keymap km = target.getKeymap();
if (km != null) {
  KeyStroke[] keys = km.getKeyStrokesForAction(a);

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib

item.addActionListener(a);
Keymap km = target.getKeymap();
if (km != null) {
  KeyStroke[] keys = km.getKeyStrokesForAction(a);

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-beans

/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey, JTextComponent component) {
  // This method is implemented due to the issue
  // #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
  KeyStroke[] ret = new KeyStroke[] { defaultKey };
  if (component != null) {
    TextUI componentUI = component.getUI();
    Keymap km = component.getKeymap();
    if (componentUI != null && km != null) {
      EditorKit kit = componentUI.getEditorKit(component);
      if (kit instanceof BaseKit) {
        Action a = ((BaseKit)kit).getActionByName(editorActionName);
        if (a != null) {
          KeyStroke[] keys = km.getKeyStrokesForAction(a);
          if (keys != null && keys.length > 0) {
            ret = keys;
          }
        }
      }
    }
  }
  return ret;
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib

/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey) {
  // This method is implemented due to the issue
  // #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
  KeyStroke[] ret = new KeyStroke[] { defaultKey };
  if (editorActionName != null && extEditorUI != null) {
    JTextComponent component = extEditorUI.getComponent();
    if (component != null) {
      TextUI ui = component.getUI();
      Keymap km = component.getKeymap();
      if (ui != null && km != null) {
        EditorKit kit = ui.getEditorKit(component);
        if (kit instanceof BaseKit) {
          Action a = ((BaseKit)kit).getActionByName(editorActionName);
          if (a != null) {
            KeyStroke[] keys = km.getKeyStrokesForAction(a);
            if (keys != null && keys.length > 0) {
              ret = keys;
            }
          }
        }
      }
    }
  }
  return ret;
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-editor-deprecated-pre61completion

/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey) {
  // This method is implemented due to the issue
  // #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
  KeyStroke[] ret = new KeyStroke[] { defaultKey };
  if (editorActionName != null && extEditorUI != null) {
    JTextComponent component = extEditorUI.getComponent();
    if (component != null) {
      TextUI ui = component.getUI();
      Keymap km = component.getKeymap();
      if (ui != null && km != null) {
        EditorKit kit = ui.getEditorKit(component);
        if (kit instanceof BaseKit) {
          Action a = ((BaseKit)kit).getActionByName(editorActionName);
          if (a != null) {
            KeyStroke[] keys = km.getKeyStrokesForAction(a);
            if (keys != null && keys.length > 0) {
              ret = keys;
            }
          }
        }
      }
    }
  }
  return ret;
}

相关文章

JTextComponent类方法