Gridarta Editor
StringKeyManager.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.gui.dialog.gameobjectattributes;
21 
22 import javax.swing.ComboBoxModel;
23 import javax.swing.JComboBox;
24 import javax.swing.JComboBox.KeySelectionManager;
25 
35 public class StringKeyManager implements KeySelectionManager {
36 
40  private final JComboBox<?> box;
41 
46  public StringKeyManager(final JComboBox<?> box) {
47  this.box = box;
48  }
49 
50  @Override
51  public int selectionForKey(final char aKey, final ComboBoxModel aModel) {
52  for (int i = 0; i < aModel.getSize(); i++) {
53  if (((String) aModel.getElementAt(i)).toLowerCase().charAt(1) == aKey) {
54  //typeListener.ignoreEvent = true;
55  box.setSelectedIndex(i); // should happen automatically, but doesn't
56  //typeListener.ignoreEvent = false;
57  //typeListener.listenAction = true;
58  return i;
59  }
60  }
61  return -1; // no match found
62  }
63 
64 }
net.sf.gridarta.gui.dialog.gameobjectattributes.StringKeyManager
KeySelectionManager to manage the select-per-keystroke in a JComboBox (The default KeySelectionManage...
Definition: StringKeyManager.java:35
net.sf.gridarta.gui.dialog.gameobjectattributes.StringKeyManager.selectionForKey
int selectionForKey(final char aKey, final ComboBoxModel aModel)
Definition: StringKeyManager.java:51
net.sf.gridarta.gui.dialog.gameobjectattributes.StringKeyManager.box
final JComboBox<?> box
JComboBox reference.
Definition: StringKeyManager.java:40
net.sf.gridarta.gui.dialog.gameobjectattributes.StringKeyManager.StringKeyManager
StringKeyManager(final JComboBox<?> box)
Creates a new instance.
Definition: StringKeyManager.java:46