-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDBBrowserConfig.java
More file actions
150 lines (141 loc) · 5.23 KB
/
DBBrowserConfig.java
File metadata and controls
150 lines (141 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
* DBBrowserConfig.java
* Copyright (C) 2009-2013 TMate Software Ltd
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For information on how to redistribute this software under
* the terms of a license other than GNU General Public License
* contact TMate Software at support@sqljet.com
*/
package org.tmatesoft.sqljet.browser;
import java.awt.Window;
import java.io.File;
import java.util.LinkedList;
import java.util.List;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
/**
* @author TMate Software Ltd.
* @author Sergey Scherbina (sergey.scherbina@gmail.com)
*
*/
public class DBBrowserConfig {
public static File getLastDirectory() {
try {
Preferences preferences = Preferences.userNodeForPackage(DBBrowserConfig.class);
if (preferences != null) {
try {
preferences.sync();
} catch (BackingStoreException e) {
}
String path = preferences.get("directory", null);
if (path != null) {
return new File(path);
}
}
} catch (SecurityException e) {
//
}
return null;
}
public static void setLastDirectory(File directory) {
try {
Preferences preferences = Preferences.userNodeForPackage(DBBrowserConfig.class);
if (preferences != null && directory != null) {
preferences.put("directory", directory.getAbsolutePath());
try {
preferences.flush();
} catch (BackingStoreException e) {
}
}
} catch (SecurityException e) {
//
}
}
public static void saveWindowSize(String windowName, Window w) {
try {
Preferences preferences = Preferences.userNodeForPackage(DBBrowserConfig.class);
if (preferences != null && w != null) {
preferences.put("window." + windowName + ".x", w.getLocation().x + "");
preferences.put("window." + windowName + ".y", w.getLocation().y + "");
preferences.put("window." + windowName + ".width", w.getSize().width + "");
preferences.put("window." + windowName + ".height", w.getSize().height + "");
try {
preferences.flush();
} catch (BackingStoreException e) {
}
}
} catch (SecurityException e) {
//
}
}
public static void loadWindowSize(String windowName, Window window) {
try {
Preferences preferences = Preferences.userNodeForPackage(DBBrowserConfig.class);
if (preferences != null && window != null) {
try {
preferences.sync();
} catch (BackingStoreException e) {
}
int x = preferences.getInt("window." + windowName + ".x", -1);
int y = preferences.getInt("window." + windowName + ".y", -1);
int w = preferences.getInt("window." + windowName + ".width", -1);
int h = preferences.getInt("window." + windowName + ".height", -1);
if (x >= 0 && w > 0) {
window.setSize(w, h);
window.setLocation(x, y);
} else {
window.pack();
}
}
} catch (SecurityException e) {
window.pack();
}
}
public static void setRecentDBs(List<File> paths) {
try {
Preferences preferences = Preferences.userNodeForPackage(DBBrowserConfig.class);
if (preferences != null && paths != null) {
int i = 0;
for (File path : paths) {
preferences.put("recent." + i, path.getAbsolutePath());
i++;
}
try {
preferences.flush();
} catch (BackingStoreException e) {
}
}
} catch (SecurityException e) {
}
}
public static List<File> getRecentDBs() {
LinkedList<File> list = new LinkedList<File>();
try {
Preferences preferences = Preferences.userNodeForPackage(DBBrowserConfig.class);
if (preferences != null) {
try {
preferences.sync();
} catch (BackingStoreException e) {
}
for (int i = 0; i < 5; i++) {
String path = preferences.get("recent." + i, null);
if (path == null) {
break;
}
list.add(new File(path));
}
}
} catch (SecurityException e) {
}
return list;
}
}