Java Code Examples for javax.swing.JPanel#getInputMap()

The following examples show how to use javax.swing.JPanel#getInputMap() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
protected JDialog createDialog(Component parent) {
	Frame frame = parent instanceof Frame ? (Frame) parent
			: (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);
	JDialog dialog = new JDialog(frame, ("Select Font"), true);

	Action okAction = new DialogOKAction(dialog);
	Action cancelAction = new DialogCancelAction(dialog);

	JButton okButton = new JButton(okAction);
	okButton.setFont(DEFAULT_FONT);
	JButton cancelButton = new JButton(cancelAction);
	cancelButton.setFont(DEFAULT_FONT);

	JPanel buttonsPanel = new JPanel();
	buttonsPanel.setLayout(new GridLayout(2, 1));
	buttonsPanel.add(okButton);
	buttonsPanel.add(cancelButton);
	buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10));

	ActionMap actionMap = buttonsPanel.getActionMap();
	actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction);
	actionMap.put(okAction.getValue(Action.DEFAULT), okAction);
	InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
	inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT));
	inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT));

	JPanel dialogEastPanel = new JPanel();
	dialogEastPanel.setLayout(new BorderLayout());
	dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH);

	dialog.getContentPane().add(this, BorderLayout.CENTER);
	dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST);
	dialog.pack();
	dialog.setLocationRelativeTo(frame);
	return dialog;
}
 
Example 2
Source Project: PacketProxy   File: JFontChooser.java    License: Apache License 2.0 5 votes vote down vote up
protected JDialog createDialog(Component parent) {
    Frame frame = parent instanceof Frame ? (Frame) parent
        : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);
    JDialog dialog = new JDialog(frame, I18nString.get("Font Setting"), true);

    Action okAction = new DialogOKAction(dialog);
    Action cancelAction = new DialogCancelAction(dialog);

    JButton okButton = new JButton(okAction);
    okButton.setFont(DEFAULT_FONT);
    JButton cancelButton = new JButton(cancelAction);
    cancelButton.setFont(DEFAULT_FONT);

    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new GridLayout(2, 1));
    buttonsPanel.add(okButton);
    buttonsPanel.add(cancelButton);
    buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10));

    ActionMap actionMap = buttonsPanel.getActionMap();
    actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction);
    actionMap.put(okAction.getValue(Action.DEFAULT), okAction);
    InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT));
    inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT));

    JPanel dialogEastPanel = new JPanel();
    dialogEastPanel.setLayout(new BorderLayout());
    dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH);

    dialog.getContentPane().add(this, BorderLayout.CENTER);
    dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST);
    dialog.pack();
    dialog.setLocationRelativeTo(frame);
    return dialog;
}
 
Example 3
Source Project: PacketProxy   File: GUIMain.java    License: Apache License 2.0 5 votes vote down vote up
private void addShortcutForWindows() {
	if (PacketProxyUtility.getInstance().isMac()) {
		return;
	}
	JPanel p = (JPanel) getContentPane();
	InputMap im = p.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
	ActionMap am = p.getActionMap();
	int hotkey = (KeyEvent.CTRL_MASK);
	registerTabShortcut(KeyEvent.VK_H, hotkey, im, am, Panes.HISTORY.ordinal());
	registerTabShortcut(KeyEvent.VK_I, hotkey, im, am, Panes.INTERCEPT.ordinal());
	registerTabShortcut(KeyEvent.VK_R, hotkey, im, am, Panes.REPEATER.ordinal());
	registerTabShortcut(KeyEvent.VK_B, hotkey, im, am, Panes.BULKSENDER.ordinal());
	registerTabShortcut(KeyEvent.VK_O, hotkey, im, am, Panes.OPTIONS.ordinal());
	registerTabShortcut(KeyEvent.VK_L, hotkey, im, am, Panes.LOG.ordinal());
}
 
Example 4
protected JDialog createDialog(Component parent)
{
    Frame frame = parent instanceof Frame ? (Frame) parent
        : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);
    JDialog dialog = new JDialog(frame, Editor.fromConfiguracao.getValor("Inspector.obj.font.selfonte"), true);

    Action okAction = new DialogOKAction(dialog);
    Action cancelAction = new DialogCancelAction(dialog);

    JButton okButton = new JButton(okAction);
    okButton.setFont(DEFAULT_FONT);
    JButton cancelButton = new JButton(cancelAction);
    cancelButton.setFont(DEFAULT_FONT);

    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new GridLayout(2, 1));
    buttonsPanel.add(okButton);
    buttonsPanel.add(cancelButton);
    buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10));

    ActionMap actionMap = buttonsPanel.getActionMap();
    actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction);
    actionMap.put(okAction.getValue(Action.DEFAULT), okAction);
    InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT));
    inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT));

    JPanel dialogEastPanel = new JPanel();
    dialogEastPanel.setLayout(new BorderLayout());
    dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH);

    dialog.getContentPane().add(this, BorderLayout.CENTER);
    dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST);
    dialog.pack();
    dialog.setLocationRelativeTo(frame);
    return dialog;
}
 
Example 5
Source Project: Luyten   File: JFontChooser.java    License: Apache License 2.0 5 votes vote down vote up
protected JDialog createDialog(Component parent) {
	Frame frame = parent instanceof Frame ? (Frame) parent
			: (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);
	JDialog dialog = new JDialog(frame, ("Select Font"), true);

	Action okAction = new DialogOKAction(dialog);
	Action cancelAction = new DialogCancelAction(dialog);

	JButton okButton = new JButton(okAction);
	okButton.setFont(DEFAULT_FONT);
	JButton cancelButton = new JButton(cancelAction);
	cancelButton.setFont(DEFAULT_FONT);

	JPanel buttonsPanel = new JPanel();
	buttonsPanel.setLayout(new GridLayout(2, 1));
	buttonsPanel.add(okButton);
	buttonsPanel.add(cancelButton);
	buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10));

	ActionMap actionMap = buttonsPanel.getActionMap();
	actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction);
	actionMap.put(okAction.getValue(Action.DEFAULT), okAction);
	InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
	inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT));
	inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT));

	JPanel dialogEastPanel = new JPanel();
	dialogEastPanel.setLayout(new BorderLayout());
	dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH);

	dialog.getContentPane().add(this, BorderLayout.CENTER);
	dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST);
	dialog.pack();
	dialog.setLocationRelativeTo(frame);
	return dialog;
}
 
Example 6
private void initialize( final MasterReport report ) {
  if ( report == null ) {
    throw new NullPointerException();
  }

  masterReport = report;
  messages =
      new ResourceBundleSupport( Locale.getDefault(), SwingPreviewModule.BUNDLE_NAME, ObjectUtilities
          .getClassLoader( PreviewParametersDialog.class ) );
  confirmAction = new OkAction();

  setTitle( messages.getString( "PreviewParametersDialog.Title" ) );
  setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE );

  final JPanel contentPane = new JPanel();
  contentPane.setLayout( new BorderLayout() );
  contentPane.add( createParametersPanel(), BorderLayout.CENTER );
  contentPane.add( createButtonsPanel(), BorderLayout.SOUTH );
  setContentPane( contentPane );

  final InputMap inputMap = contentPane.getInputMap();
  final ActionMap actionMap = contentPane.getActionMap();

  inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, 0 ), "confirm" ); // NON-NLS
  inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), "cancel" ); // NON-NLS
  actionMap.put( "confirm", new OkAction() ); // NON-NLS
  actionMap.put( "cancel", new CancelAction() ); // NON-NLS

  setModal( true );
  pack();
  LibSwingUtil.centerDialogInParent( this );
}
 
Example 7
Source Project: PacketProxy   File: GUIMain.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * JTextPane上でCommand+Cとかでコピペをできるようにする
 */
private void addShortcutForMac() {
	if (!PacketProxyUtility.getInstance().isMac()) {
		return;
	}
	JPanel p = (JPanel) getContentPane();
	InputMap im = p.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
	ActionMap am = p.getActionMap();
	int hotkey = (KeyEvent.CTRL_MASK | KeyEvent.META_MASK);
	registerTabShortcut(KeyEvent.VK_H, hotkey, im, am, Panes.HISTORY.ordinal());
	registerTabShortcut(KeyEvent.VK_I, hotkey, im, am, Panes.INTERCEPT.ordinal());
	registerTabShortcut(KeyEvent.VK_R, hotkey, im, am, Panes.REPEATER.ordinal());
	registerTabShortcut(KeyEvent.VK_B, hotkey, im, am, Panes.BULKSENDER.ordinal());
	registerTabShortcut(KeyEvent.VK_O, hotkey, im, am, Panes.OPTIONS.ordinal());
	registerTabShortcut(KeyEvent.VK_L, hotkey, im, am, Panes.LOG.ordinal());

	JTextComponent.KeyBinding[] bindings1 = {
		new JTextComponent.KeyBinding(
				KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
				DefaultEditorKit.copyAction),
		new JTextComponent.KeyBinding(
				KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
				DefaultEditorKit.pasteAction),
		new JTextComponent.KeyBinding(
				KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
				DefaultEditorKit.cutAction),
		new JTextComponent.KeyBinding(
				KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
				DefaultEditorKit.selectAllAction),
	};

	JTextPane component_tp = new JTextPane();
	Keymap keymap_tp = component_tp.getKeymap();
	JTextComponent.loadKeymap(keymap_tp, bindings1, component_tp.getActions());

	JTextField component_tf = new JTextField();
	Keymap keymap_tf = component_tf.getKeymap();
	JTextComponent.loadKeymap(keymap_tf, bindings1, component_tf.getActions());

	JTextArea component_ta = new JTextArea();
	Keymap keymap_ta = component_ta.getKeymap();
	JTextComponent.loadKeymap(keymap_ta, bindings1, component_ta.getActions());
}
 
Example 8
Source Project: PolyGlot   File: JFontChooser.java    License: MIT License 4 votes vote down vote up
protected JDialog createDialog(Component parent)
{
    double menuFontSize = core.getOptionsManager().getMenuFontSize();
    boolean nightMode = core.getOptionsManager().isNightMode();
    Frame frame = parent instanceof Frame ? (Frame) parent
        : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);
    JDialog dialog = new JDialog(frame, ("Select Font"), true);

    frame.setBackground(Color.white);
    Action okAction = new DialogOKAction(dialog);
    Action cancelAction = new DialogCancelAction(dialog);

    PButton okButton = new PButton(nightMode, menuFontSize);
    okButton.setAction(okAction);
    okButton.setFont(DEFAULT_FONT);
    PButton cancelButton = new PButton(nightMode, menuFontSize);
    cancelButton.setAction(cancelAction);
    cancelButton.setFont(DEFAULT_FONT);

    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setBackground(Color.white);
    buttonsPanel.setLayout(new GridLayout(2, 1));
    buttonsPanel.add(okButton);
    buttonsPanel.add(cancelButton);
    buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10));

    ActionMap actionMap = buttonsPanel.getActionMap();
    actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction);
    actionMap.put(okAction.getValue(Action.DEFAULT), okAction);
    InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT));
    inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT));

    JPanel dialogEastPanel = new JPanel();
    dialogEastPanel.setBackground(Color.white);
    dialogEastPanel.setLayout(new BorderLayout());
    dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH);

    dialog.getContentPane().add(this, BorderLayout.CENTER);
    dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST);
    dialog.pack();
    dialog.setLocationRelativeTo(frame);
    dialog.getRootPane().setBackground(Color.white);
    return dialog;
}