Skip to content

Commit 0f32653

Browse files
committed
wip
1 parent 01a24bb commit 0f32653

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import ca.odell.glazedlists.EventList;
88
import ca.odell.glazedlists.swing.DefaultEventListModel;
99
import ca.odell.glazedlists.swing.GlazedListsSwing;
10+
import mediathek.tool.ApplicationConfiguration;
1011
import mediathek.tool.SVGIconUtilities;
12+
import org.apache.commons.configuration2.sync.LockMode;
1113

1214
import javax.swing.*;
1315
import javax.swing.border.EmptyBorder;
@@ -20,6 +22,11 @@
2022
* @author christianfranzke
2123
*/
2224
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+
2330
public EditHistoryDialog(Window owner, JMenuItem menuItem, EventList<String> eventList) {
2431
super(owner);
2532
initComponents();
@@ -29,6 +36,7 @@ public EditHistoryDialog(Window owner, JMenuItem menuItem, EventList<String> eve
2936
@Override
3037
public void windowClosed(WindowEvent e) {
3138
menuItem.setEnabled(true);
39+
savePosition();
3240
}
3341
});
3442

@@ -38,7 +46,6 @@ public void windowClosed(WindowEvent e) {
3846
if (l.getValueIsAdjusting())
3947
return;
4048
adjustDeleteButton();
41-
4249
});
4350
adjustDeleteButton();
4451

@@ -50,6 +57,41 @@ public void windowClosed(WindowEvent e) {
5057
changeList.forEach(eventList::remove);
5158
changeList.clear();
5259
});
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+
}
5395
}
5496

5597
private void adjustDeleteButton() {

0 commit comments

Comments
 (0)