Skip to content

Commit 2d0c59e

Browse files
committed
- code refactor
1 parent b7afefc commit 2d0c59e

File tree

2 files changed

+60
-28
lines changed

2 files changed

+60
-28
lines changed

src/main/java/mediathek/tool/swing/AutoCompletionComboBox2.java

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package mediathek.tool.swing;
2020

2121
import com.jidesoft.swing.AutoCompletion;
22-
import com.jidesoft.swing.ComboBoxSearchable;
2322

2423
import javax.swing.*;
2524

@@ -31,24 +30,22 @@
3130
*/
3231
public class AutoCompletionComboBox2 extends JComboBox<String> {
3332
protected AutoCompletion _autoCompletion;
34-
protected boolean _noActionOnKeyNavigation;
35-
private boolean _preventActionEvent;
3633

3734
public AutoCompletionComboBox2() {
3835
initComponents();
3936
}
4037

4138
protected void initComponents() {
4239
setEditable(true);
43-
setNoActionOnKeyNavigation(true);
4440

4541
_autoCompletion = createAutoCompletion();
4642
_autoCompletion.setStrict(true);
4743
_autoCompletion.setStrictCompletion(true);
44+
setNoActionOnKeyNavigation(true);
4845
}
4946

50-
public void setNoActionOnKeyNavigation(boolean _noActionOnKeyNavigation) {
51-
this._noActionOnKeyNavigation = _noActionOnKeyNavigation;
47+
public void setNoActionOnKeyNavigation(boolean value) {
48+
((NoFireOnKeyComboBoxSearchable)_autoCompletion.getSearchable()).setNoActionOnKeyNavigation(value);
5249
}
5350

5451
/**
@@ -69,31 +66,10 @@ protected void resetCaretPosition() {
6966

7067
@Override
7168
protected void fireActionEvent() {
72-
if (!_preventActionEvent) {
69+
if (!((NoFireOnKeyComboBoxSearchable)_autoCompletion.getSearchable()).isPreventActionEvent()) {
7370
resetCaretPosition();
7471
super.fireActionEvent();
7572
}
7673
}
7774

78-
private class NoFireOnKeyComboBoxSearchable extends ComboBoxSearchable {
79-
public NoFireOnKeyComboBoxSearchable(JComboBox<?> comboBox) {
80-
super(comboBox);
81-
}
82-
83-
@Override
84-
protected void setSelectedIndex(int index, boolean incremental) {
85-
Object propTableCellEditor = _component.getClientProperty("JComboBox.isTableCellEditor");
86-
Object propNoActionOnKeyNavigation = UIManager.get("ComboBox.noActionOnKeyNavigation");
87-
if ((propTableCellEditor instanceof Boolean && (Boolean) propTableCellEditor) ||
88-
(propNoActionOnKeyNavigation instanceof Boolean && (Boolean) propNoActionOnKeyNavigation) ||
89-
_noActionOnKeyNavigation) {
90-
_preventActionEvent = true;
91-
}
92-
try {
93-
super.setSelectedIndex(index, incremental);
94-
} finally {
95-
_preventActionEvent = false;
96-
}
97-
}
98-
}
9975
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2025 derreisende77.
3+
* This code was developed as part of the MediathekView project https://github.com/mediathekview/MediathekView
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 3 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
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package mediathek.tool.swing;
20+
21+
import com.jidesoft.swing.ComboBoxSearchable;
22+
23+
import javax.swing.*;
24+
25+
public class NoFireOnKeyComboBoxSearchable extends ComboBoxSearchable {
26+
protected boolean _preventActionEvent;
27+
protected boolean _noActionOnKeyNavigation;
28+
29+
public NoFireOnKeyComboBoxSearchable(JComboBox<?> comboBox) {
30+
super(comboBox);
31+
}
32+
33+
public boolean isPreventActionEvent() {
34+
return _preventActionEvent;
35+
}
36+
37+
public void setNoActionOnKeyNavigation(boolean val) {
38+
_noActionOnKeyNavigation = val;
39+
}
40+
41+
@Override
42+
protected void setSelectedIndex(int index, boolean incremental) {
43+
Object propTableCellEditor = _component.getClientProperty("JComboBox.isTableCellEditor");
44+
Object propNoActionOnKeyNavigation = UIManager.get("ComboBox.noActionOnKeyNavigation");
45+
if ((propTableCellEditor instanceof Boolean && (Boolean) propTableCellEditor) ||
46+
(propNoActionOnKeyNavigation instanceof Boolean && (Boolean) propNoActionOnKeyNavigation) ||
47+
_noActionOnKeyNavigation) {
48+
_preventActionEvent = true;
49+
}
50+
try {
51+
super.setSelectedIndex(index, incremental);
52+
} finally {
53+
_preventActionEvent = false;
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)