Skip to content

Commit 5eebe34

Browse files
committed
- implement context menu for thema combo box
- code refactor
1 parent 351f80b commit 5eebe34

File tree

2 files changed

+26
-42
lines changed

2 files changed

+26
-42
lines changed

src/main/java/mediathek/gui/tabs/tab_film/filter/SwingFilterDialog.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,15 @@ private void updateThemaComboBox() {
226226
jcbThema.setSelectedItem(aktuellesThema);
227227
}
228228

229+
private JPopupMenu createPopupMenu() {
230+
var popupMenu = new JPopupMenu();
231+
popupMenu.add(new ResetThemaButtonAction());
232+
return popupMenu;
233+
}
234+
229235
private void setupThemaComboBox() {
230-
jcbThema.setNoActionOnKeyNavigation(true);
231-
jcbThema.setStrict(true);
232-
jcbThema.setStrictCompletion(true);
236+
jcbThema.setComponentPopupMenu(createPopupMenu());
237+
233238
var model = GlazedListsSwing.eventComboBoxModel(new EventListWithEmptyFirstEntry(sourceThemaList));
234239
jcbThema.setModel(model);
235240
//otherwise stored filter will not be accepted as entry may not be in list
@@ -480,21 +485,22 @@ public void restoreFilterConfig() {
480485

481486
private class AddNewFilterAction extends AbstractAction {
482487
private static final String STR_ACTION_NAME = "Neuen Filter anlegen";
488+
483489
public AddNewFilterAction() {
484490
putValue(Action.SMALL_ICON, SVGIconUtilities.createSVGIcon("icons/fontawesome/plus.svg"));
485491
putValue(Action.SHORT_DESCRIPTION, STR_ACTION_NAME);
486492
}
487493

488494
@Override
489495
public void actionPerformed(ActionEvent e) {
490-
String newFilterName = (String)JOptionPane.showInputDialog(MediathekGui.ui(), "Filtername:",
496+
String newFilterName = (String) JOptionPane.showInputDialog(MediathekGui.ui(), "Filtername:",
491497
STR_ACTION_NAME, JOptionPane.PLAIN_MESSAGE, null, null,
492498
String.format("Filter %d", filterConfig.getAvailableFilters().size() + 1));
493499
if (newFilterName != null) {
494500
filterConfig.findFilterForName(newFilterName).ifPresentOrElse(f ->
495501
JOptionPane.showMessageDialog(MediathekGui.ui(),
496-
"Ein Filter mit dem gewählten Namen existiert bereits!",
497-
STR_ACTION_NAME, JOptionPane.ERROR_MESSAGE), () -> {
502+
"Ein Filter mit dem gewählten Namen existiert bereits!",
503+
STR_ACTION_NAME, JOptionPane.ERROR_MESSAGE), () -> {
498504
FilterDTO newFilter = new FilterDTO(UUID.randomUUID(), newFilterName);
499505
filterConfig.addNewFilter(newFilter);
500506
checkDeleteCurrentFilterButtonState();
@@ -525,9 +531,11 @@ public void actionPerformed(ActionEvent e) {
525531
}
526532

527533
private class ResetThemaAction extends AbstractAction {
534+
protected static final String STR_RESET_THEMA = "Thema zurücksetzen";
535+
528536
public ResetThemaAction() {
529537
putValue(Action.SMALL_ICON, SVGIconUtilities.createSVGIcon("icons/fontawesome/trash-can.svg"));
530-
putValue(Action.SHORT_DESCRIPTION, "Thema zurücksetzen");
538+
putValue(Action.SHORT_DESCRIPTION, STR_RESET_THEMA);
531539
}
532540

533541
@Override
@@ -537,6 +545,12 @@ public void actionPerformed(ActionEvent e) {
537545
}
538546
}
539547

548+
private class ResetThemaButtonAction extends ResetThemaAction {
549+
public ResetThemaButtonAction() {
550+
putValue(Action.NAME, STR_RESET_THEMA);
551+
}
552+
}
553+
540554
private class RenameFilterAction extends AbstractAction {
541555
public RenameFilterAction() {
542556
putValue(Action.SMALL_ICON, SVGIconUtilities.createSVGIcon("icons/fontawesome/pen-to-square.svg"));

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

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@
2626
/**
2727
* An auto completion combobox.
2828
* <p/>
29-
* Since auto-complete has to listen to the key user types, it has to be editable. If you want to limit user to the list
30-
* available in the combobox model, you can call {@link #setStrict(boolean)} and set it to true.
3129
* This class is a rewrite of {@link com.jidesoft.swing.AutoCompletionComboBox} and does not send action events when keys
3230
* are pressed if {@link #setNoActionOnKeyNavigation(boolean)} is set to true.
3331
*/
3432
public class AutoCompletionComboBox2 extends JComboBox<String> {
3533
protected AutoCompletion _autoCompletion;
36-
boolean _noActionOnKeyNavigation;
34+
protected boolean _noActionOnKeyNavigation;
3735
private boolean _preventActionEvent;
3836

3937
public AutoCompletionComboBox2() {
@@ -42,7 +40,11 @@ public AutoCompletionComboBox2() {
4240

4341
protected void initComponents() {
4442
setEditable(true);
43+
setNoActionOnKeyNavigation(true);
44+
4545
_autoCompletion = createAutoCompletion();
46+
_autoCompletion.setStrict(true);
47+
_autoCompletion.setStrictCompletion(true);
4648
}
4749

4850
public void setNoActionOnKeyNavigation(boolean _noActionOnKeyNavigation) {
@@ -58,38 +60,6 @@ protected AutoCompletion createAutoCompletion() {
5860
return new AutoCompletion(this, new NoFireOnKeyComboBoxSearchable());
5961
}
6062

61-
/**
62-
* Sets the strict property. If true, it will not allow user to type in anything that is not in the known item list.
63-
* If false, user can type in whatever he/she wants. If the text can match with a item in the known item list, it
64-
* will still auto-complete.
65-
*
66-
* @param strict true or false.
67-
*/
68-
public void setStrict(boolean strict) {
69-
getAutoCompletion().setStrict(strict);
70-
}
71-
72-
/**
73-
* Sets the strict completion property. If true, in case insensitive searching, it will always use the exact item in
74-
* the Searchable to replace whatever user types. For example, when Searchable has an item "Arial" and user types in
75-
* "AR", if this flag is true, it will auto-completed as "Arial". If false, it will be auto-completed as "ARial". Of
76-
* course, this flag will only make a difference if Searchable is case insensitive.
77-
*
78-
* @param strictCompletion true or false.
79-
*/
80-
public void setStrictCompletion(boolean strictCompletion) {
81-
getAutoCompletion().setStrictCompletion(strictCompletion);
82-
}
83-
84-
/**
85-
* Gets the underlying AutoCompletion class.
86-
*
87-
* @return the underlying AutoCompletion.
88-
*/
89-
public AutoCompletion getAutoCompletion() {
90-
return _autoCompletion;
91-
}
92-
9363
protected void resetCaretPosition() {
9464
final var tf = (JTextField)getEditor().getEditorComponent();
9565
final var textLength = tf.getText().length();

0 commit comments

Comments
 (0)