Skip to content

Commit 9a547c7

Browse files
committed
- add Edit Search History menu and dialog to search field
1 parent d8e94e7 commit 9a547c7

File tree

4 files changed

+235
-5
lines changed

4 files changed

+235
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
- **FEATURE:** Fehlerhafte Downloads werden nun automatisch aus der Gesehen Datenbank entfernt.
3434
- **FEATURE(Windows/Linux):** Darkmode Button wird ab Windows 10 und unter Linux in der Menüzeile neben den window controls angezeigt.
3535
- **FEATURE(Windows/Linux):** Tab-Labels werden nun korrekt rotiert wenn die Tab-Position nicht oben ist.
36-
- **FEATURE:** Der bevorzugte DNS-IP-Auflösungsmodus kann nun via `-dpm <XXX>` oder `--dns-preference-mode <XXX>` geändert werden. Zulässige Werte sind `system`, `ip_v6`, `ip_v4`, `ip_v6_only`, `ip_v4_only` (Standardwert). Eine Änderung kann bei IPv6-only Internetanschlüssen notwendig sein.
36+
- **FEATURE:** Der bevorzugte DNS-IP-Auflösungsmodus kann nun via `-dpm <XXX>` oder `--dns-preference-mode <XXX>` geändert werden. Zulässige Werte sind `system`, `ip_v6`, `ip_v4`, `ip_v6_only`, `ip_v4_only` (Standardwert). Eine Änderung kann bei IPv6-only Internetanschlüssen notwendig sein.
37+
- **FEATURE:** Die Suchhistorie kann nun im Kontextmenü editiert werden.
3738

3839

3940
# **14.0.0**
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
* Created by JFormDesigner on Sat Apr 27 12:49:11 CEST 2024
3+
*/
4+
5+
package mediathek.gui.tabs.tab_film;
6+
7+
import ca.odell.glazedlists.EventList;
8+
import ca.odell.glazedlists.swing.DefaultEventListModel;
9+
import ca.odell.glazedlists.swing.GlazedListsSwing;
10+
import mediathek.tool.ApplicationConfiguration;
11+
import mediathek.tool.SVGIconUtilities;
12+
import org.apache.commons.configuration2.sync.LockMode;
13+
14+
import javax.swing.*;
15+
import javax.swing.border.EmptyBorder;
16+
import java.awt.*;
17+
import java.awt.event.WindowAdapter;
18+
import java.awt.event.WindowEvent;
19+
import java.util.ArrayList;
20+
21+
/**
22+
* @author christianfranzke
23+
*/
24+
public class EditHistoryDialog extends JDialog {
25+
private static final String CONFIG_X = "edit_history.x";
26+
private static final String CONFIG_Y = "edit_history.y";
27+
private static final String CONFIG_HEIGHT = "edit_history.height";
28+
private static final String CONFIG_WIDTH = "edit_history.width";
29+
30+
public EditHistoryDialog(Window owner, JMenuItem menuItem, EventList<String> eventList) {
31+
super(owner);
32+
initComponents();
33+
34+
menuItem.setEnabled(false);
35+
addWindowListener(new WindowAdapter() {
36+
@Override
37+
public void windowClosed(WindowEvent e) {
38+
menuItem.setEnabled(true);
39+
savePosition();
40+
}
41+
});
42+
43+
DefaultEventListModel<String> model = GlazedListsSwing.eventListModelWithThreadProxyList(eventList);
44+
list.setModel(model);
45+
list.getSelectionModel().addListSelectionListener(l -> {
46+
if (l.getValueIsAdjusting())
47+
return;
48+
adjustDeleteButton();
49+
});
50+
adjustDeleteButton();
51+
52+
btnDeleteEntries.addActionListener(l -> {
53+
var changeList = new ArrayList<String>();
54+
for (var idx : list.getSelectedIndices()) {
55+
changeList.add(list.getModel().getElementAt(idx));
56+
}
57+
changeList.forEach(eventList::remove);
58+
changeList.clear();
59+
});
60+
61+
restorePosition();
62+
}
63+
64+
private void restorePosition() {
65+
var config = ApplicationConfiguration.getConfiguration();
66+
try {
67+
config.lock(LockMode.READ);
68+
int x = config.getInt(CONFIG_X);
69+
int y = config.getInt(CONFIG_Y);
70+
int width = config.getInt(CONFIG_WIDTH);
71+
int height = config.getInt(CONFIG_HEIGHT);
72+
73+
setSize(width, height);
74+
setLocation(x, y);
75+
} catch (Exception ignored) {
76+
System.out.println("COULD NOT FIND CONFIGURATION");
77+
} finally {
78+
config.unlock(LockMode.READ);
79+
}
80+
}
81+
82+
private void savePosition() {
83+
var config = ApplicationConfiguration.getConfiguration();
84+
try {
85+
config.lock(LockMode.WRITE);
86+
var size = getSize();
87+
var location = getLocation();
88+
config.setProperty(CONFIG_WIDTH, size.width);
89+
config.setProperty(CONFIG_HEIGHT, size.height);
90+
config.setProperty(CONFIG_X, location.x);
91+
config.setProperty(CONFIG_Y, location.y);
92+
} finally {
93+
config.unlock(LockMode.WRITE);
94+
}
95+
}
96+
97+
private void adjustDeleteButton() {
98+
btnDeleteEntries.setEnabled(list.getSelectionModel().getSelectedItemsCount() > 0);
99+
}
100+
101+
private void initComponents() {
102+
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents @formatter:off
103+
// Generated using JFormDesigner non-commercial license
104+
var dialogPane = new JPanel();
105+
var contentPanel = new JPanel();
106+
var scrollPane1 = new JScrollPane();
107+
list = new JList<>();
108+
var toolBar1 = new JToolBar();
109+
btnDeleteEntries = new JButton();
110+
btnDeleteEntries.setIcon(SVGIconUtilities.createSVGIcon("icons/fontawesome/trash-can.svg")); //NON-NLS
111+
112+
//======== this ========
113+
setTitle("Suchhistorie bearbeiten"); //NON-NLS
114+
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
115+
setType(Window.Type.UTILITY);
116+
var contentPane = getContentPane();
117+
contentPane.setLayout(new BorderLayout());
118+
119+
//======== dialogPane ========
120+
{
121+
dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
122+
dialogPane.setLayout(new BorderLayout());
123+
124+
//======== contentPanel ========
125+
{
126+
contentPanel.setLayout(new BorderLayout());
127+
128+
//======== scrollPane1 ========
129+
{
130+
scrollPane1.setViewportView(list);
131+
}
132+
contentPanel.add(scrollPane1, BorderLayout.CENTER);
133+
134+
//======== toolBar1 ========
135+
{
136+
toolBar1.setFloatable(false);
137+
138+
//---- btnDeleteEntries ----
139+
btnDeleteEntries.setToolTipText("Ausgew\u00e4hlte Eintr\u00e4ge l\u00f6schen"); //NON-NLS
140+
toolBar1.add(btnDeleteEntries);
141+
}
142+
contentPanel.add(toolBar1, BorderLayout.NORTH);
143+
}
144+
dialogPane.add(contentPanel, BorderLayout.CENTER);
145+
}
146+
contentPane.add(dialogPane, BorderLayout.CENTER);
147+
pack();
148+
setLocationRelativeTo(getOwner());
149+
// JFormDesigner - End of component initialization //GEN-END:initComponents @formatter:on
150+
}
151+
152+
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables @formatter:off
153+
// Generated using JFormDesigner non-commercial license
154+
private JList<String> list;
155+
private JButton btnDeleteEntries;
156+
// JFormDesigner - End of variables declaration //GEN-END:variables @formatter:on
157+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
JFDML JFormDesigner: "8.2.3.0.386" Java: "17.0.10" encoding: "UTF-8"
2+
3+
new FormModel {
4+
contentType: "form/swing"
5+
root: new FormRoot {
6+
add( new FormWindow( "javax.swing.JDialog", new FormLayoutManager( class java.awt.BorderLayout ) ) {
7+
name: "this"
8+
"title": "Suchhistorie bearbeiten"
9+
"defaultCloseOperation": 2
10+
"type": enum java.awt.Window$Type UTILITY
11+
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.BorderLayout ) ) {
12+
name: "dialogPane"
13+
"border": new javax.swing.border.EmptyBorder( 12, 12, 12, 12 )
14+
auxiliary() {
15+
"JavaCodeGenerator.variableLocal": true
16+
}
17+
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.BorderLayout ) ) {
18+
name: "contentPanel"
19+
auxiliary() {
20+
"JavaCodeGenerator.variableLocal": true
21+
}
22+
add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) {
23+
name: "scrollPane1"
24+
auxiliary() {
25+
"JavaCodeGenerator.variableLocal": true
26+
}
27+
add( new FormComponent( "javax.swing.JList" ) {
28+
name: "list"
29+
auxiliary() {
30+
"JavaCodeGenerator.typeParameters": "String"
31+
}
32+
} )
33+
}, new FormLayoutConstraints( class java.lang.String ) {
34+
"value": "Center"
35+
} )
36+
add( new FormContainer( "javax.swing.JToolBar", new FormLayoutManager( class javax.swing.JToolBar ) ) {
37+
name: "toolBar1"
38+
"floatable": false
39+
auxiliary() {
40+
"JavaCodeGenerator.variableLocal": true
41+
}
42+
add( new FormComponent( "javax.swing.JButton" ) {
43+
name: "btnDeleteEntries"
44+
"toolTipText": "Ausgewählte Einträge löschen"
45+
auxiliary() {
46+
"JavaCodeGenerator.postCreateCode": "btnDeleteEntries.setIcon(SVGIconUtilities.createSVGIcon(\"icons/fontawesome/trash-can.svg\"));"
47+
}
48+
} )
49+
}, new FormLayoutConstraints( class java.lang.String ) {
50+
"value": "North"
51+
} )
52+
}, new FormLayoutConstraints( class java.lang.String ) {
53+
"value": "Center"
54+
} )
55+
}, new FormLayoutConstraints( class java.lang.String ) {
56+
"value": "Center"
57+
} )
58+
}, new FormLayoutConstraints( null ) {
59+
"location": new java.awt.Point( 0, 0 )
60+
"size": new java.awt.Dimension( 515, 350 )
61+
} )
62+
}
63+
}

src/main/java/mediathek/gui/tabs/tab_film/GuiFilme.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package mediathek.gui.tabs.tab_film;
22

3+
import ca.odell.glazedlists.BasicEventList;
4+
import ca.odell.glazedlists.EventList;
35
import com.fasterxml.jackson.core.JsonProcessingException;
46
import com.fasterxml.jackson.core.type.TypeReference;
57
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -863,8 +865,9 @@ public void keyPressed(KeyEvent e) {
863865

864866
public class SearchHistoryButton extends JButton {
865867
private static final Logger logger = LogManager.getLogger();
866-
private final List<String> historyList = new ArrayList<>();
867-
private final JMenuItem miClearHistory = new JMenuItem("Historie löschen");
868+
private final EventList<String> historyList = new BasicEventList<>();
869+
private final JMenuItem miClearHistory = new JMenuItem("Alles löschen");
870+
private final JMenuItem miEditHistory = new JMenuItem("Einträge bearbeiten");
868871
private String SEARCH_HISTORY_CONFIG = "search.history.items";
869872

870873
public SearchHistoryButton(@Nullable SearchControlFieldMode mode) {
@@ -881,9 +884,16 @@ public SearchHistoryButton(@Nullable SearchControlFieldMode mode) {
881884
historyList.clear();
882885
saveHistory();
883886
});
887+
888+
miEditHistory.addActionListener(l -> {
889+
EditHistoryDialog dlg = new EditHistoryDialog(mediathekGui , miEditHistory, historyList);
890+
dlg.setVisible(true);
891+
});
892+
884893
addActionListener(l -> {
885894
JPopupMenu popupMenu = new JPopupMenu();
886895
popupMenu.add(miClearHistory);
896+
popupMenu.add(miEditHistory);
887897
if (!historyList.isEmpty()) {
888898
popupMenu.addSeparator();
889899
for (var item : historyList) {
@@ -899,14 +909,13 @@ public SearchHistoryButton(@Nullable SearchControlFieldMode mode) {
899909
});
900910

901911
loadHistory();
912+
historyList.addListEventListener(l -> saveHistory());
902913
}
903914

904915
public void addHistoryEntry(String text) {
905916
if (!historyList.contains(text)) {
906917
historyList.addFirst(text);
907-
saveHistory();
908918
}
909-
910919
}
911920

912921
private void loadHistory() {

0 commit comments

Comments
 (0)