Revize 98da6ab0
Přidáno uživatelem Michal Horký před téměř 5 roky(ů)
project/Deserializer/app.config | ||
---|---|---|
1 |
#Sun Apr 26 09:18:07 CEST 2020 |
project/Deserializer/src/Converter.java | ||
---|---|---|
136 | 136 |
} |
137 | 137 |
//test file output |
138 | 138 |
|
139 |
ui.completed(html.toString(), json.toString(), new String(array)); |
|
139 |
ui.completed(html.toString(), json.toString(), array == null ? null : new String(array));
|
|
140 | 140 |
} |
141 | 141 |
} |
142 | 142 |
|
project/Deserializer/src/Deserializer.java | ||
---|---|---|
1 | 1 |
import java.io.File; |
2 |
import java.util.Properties; |
|
2 | 3 |
|
3 | 4 |
import io.Database.DB_Messenger; |
4 | 5 |
import io.FileWorker; |
5 | 6 |
import javafx.application.Application; |
6 | 7 |
import javafx.application.Platform; |
7 | 8 |
import javafx.collections.FXCollections; |
9 |
import javafx.collections.ObservableList; |
|
8 | 10 |
import javafx.geometry.Insets; |
9 | 11 |
import javafx.geometry.Pos; |
10 | 12 |
import javafx.scene.Node; |
... | ... | |
47 | 49 |
private VBox outputLayout; |
48 | 50 |
|
49 | 51 |
private Converter converter; |
52 |
private Properties properties; |
|
50 | 53 |
|
51 | 54 |
@Override |
52 | 55 |
public void init() throws Exception { |
53 | 56 |
super.init(); |
54 | 57 |
converter = new Converter(this); |
55 | 58 |
converter.start(); |
59 |
properties = FileWorker.getConfig(); |
|
56 | 60 |
} |
57 | 61 |
|
58 | 62 |
@Override |
... | ... | |
60 | 64 |
super.stop(); |
61 | 65 |
converter.end(); |
62 | 66 |
converter.join(); |
67 |
FileWorker.saveConfig(properties); |
|
63 | 68 |
Platform.exit(); |
64 | 69 |
} |
65 | 70 |
|
66 | 71 |
@Override |
67 | 72 |
public void start(Stage stage) throws Exception { |
68 | 73 |
this.stage = stage; |
69 |
stage.getIcons().add(new Image(getResource("logo.png")));
|
|
74 |
stage.getIcons().add(new Image(FileWorker.getResource("/logo.png")));
|
|
70 | 75 |
stage.setTitle("Java Object Universal Deserializer"); |
71 | 76 |
stage.setScene(createScene()); |
72 | 77 |
stage.show(); |
... | ... | |
82 | 87 |
private Scene createScene() { |
83 | 88 |
createMenu(); |
84 | 89 |
Scene scene = new Scene(createLayout()); |
85 |
scene.getStylesheets().add(getResource("main.css"));
|
|
90 |
scene.getStylesheets().add(FileWorker.getResource("/main.css"));
|
|
86 | 91 |
return scene; |
87 | 92 |
} |
88 | 93 |
|
... | ... | |
104 | 109 |
|
105 | 110 |
editor = new Editor(); |
106 | 111 |
|
112 |
String propMode = properties.getProperty(FileWorker.ACE_MODE); |
|
113 |
String propTheme = properties.getProperty(FileWorker.ACE_THEME); |
|
114 |
|
|
115 |
ObservableList<String> aceModes = FXCollections.observableArrayList(); |
|
116 |
ObservableList<String> aceThemes = FXCollections.observableArrayList(); |
|
117 |
FileWorker.getAceModesAndThemes(aceModes, aceThemes); |
|
118 |
|
|
107 | 119 |
ComboBox<String> modeBox = new ComboBox<String>(); |
108 |
modeBox.setItems(FileWorker.getAceModes());
|
|
109 |
modeBox.getSelectionModel().select(Editor.DEFAULT_MODE);
|
|
120 |
modeBox.setItems(aceModes);
|
|
121 |
modeBox.getSelectionModel().select(propMode == null ? Editor.DEFAULT_MODE : propMode);
|
|
110 | 122 |
modeBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { |
111 |
if (newValue != null && oldValue != newValue) { |
|
123 |
if (modeBox.getValue() != null) { |
|
124 |
properties.setProperty(FileWorker.ACE_MODE, modeBox.getValue()); |
|
112 | 125 |
editor.setMode(modeBox.getValue()); |
113 | 126 |
} |
114 | 127 |
}); |
115 | 128 |
|
116 | 129 |
ComboBox<String> themeBox = new ComboBox<String>(); |
117 |
themeBox.setItems(FileWorker.getAceThemes());
|
|
118 |
themeBox.getSelectionModel().select(Editor.DEFAULT_THEME);
|
|
130 |
themeBox.setItems(aceThemes);
|
|
131 |
themeBox.getSelectionModel().select(propTheme == null ? Editor.DEFAULT_THEME : propTheme);
|
|
119 | 132 |
themeBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { |
120 |
if (newValue != null && oldValue != newValue) { |
|
133 |
if (themeBox.getValue() != null) { |
|
134 |
properties.setProperty(FileWorker.ACE_THEME, themeBox.getValue()); |
|
121 | 135 |
editor.setTheme(themeBox.getValue()); |
122 | 136 |
} |
123 | 137 |
}); |
... | ... | |
184 | 198 |
} |
185 | 199 |
|
186 | 200 |
private Tab createQueryTab() { |
201 |
String propType = properties.getProperty(FileWorker.DB_TYPE); |
|
202 |
String propUrl = properties.getProperty(FileWorker.DB_URL); |
|
203 |
String propUser = properties.getProperty(FileWorker.DB_USER); |
|
204 |
|
|
205 |
|
|
187 | 206 |
String promptTexts[] = new String[] { "jdbc:mysql://server/nazevDB", "jdbc:oracle:thin:@server:port:nazevDB" }; |
188 | 207 |
|
189 | 208 |
Label rdbmsLabel = new Label("Typ DB"); |
190 | 209 |
Label urlLabel = new Label("URL"); |
191 | 210 |
ComboBox<String> rdbms = new ComboBox<String>(FXCollections.observableArrayList(new String[] { "MySQL", "ORACLE" })); |
192 |
TextField url = new TextField(); |
|
193 |
|
|
211 |
TextField url = new TextField(propUrl == null ? "" : propUrl); |
|
212 |
|
|
213 |
if (propType == null) { |
|
214 |
rdbms.getSelectionModel().selectFirst(); |
|
215 |
url.setPromptText(promptTexts[0]); |
|
216 |
} else { |
|
217 |
rdbms.getSelectionModel().select(propType); |
|
218 |
url.setPromptText(promptTexts[rdbms.getItems().indexOf(propType)]); |
|
219 |
} |
|
194 | 220 |
rdbms.setOnAction(event -> { |
195 | 221 |
url.setPromptText(promptTexts[rdbms.getSelectionModel().getSelectedIndex()]); |
196 | 222 |
}); |
197 | 223 |
|
198 |
rdbms.getSelectionModel().selectFirst(); |
|
199 |
url.setPromptText(promptTexts[0]); |
|
224 |
|
|
200 | 225 |
|
201 | 226 |
|
202 | 227 |
Label userLabel = new Label("Uživatel"); |
203 | 228 |
Label passwordLabel = new Label("Heslo"); |
204 |
TextField user = new TextField(); |
|
229 |
TextField user = new TextField(propUser == null ? "" : propUser);
|
|
205 | 230 |
PasswordField password = new PasswordField(); |
206 | 231 |
|
207 | 232 |
VBox rdbmsLayout = new VBox(); |
... | ... | |
256 | 281 |
|
257 | 282 |
Button setQuery = new Button("Spustit"); |
258 | 283 |
setQuery.setOnAction(event -> { |
284 |
String urlStr = url.getText().trim(); |
|
285 |
String userStr = user.getText().trim(); |
|
286 |
properties.setProperty(FileWorker.DB_TYPE, rdbms.getValue()); |
|
287 |
properties.setProperty(FileWorker.DB_URL, urlStr); |
|
288 |
properties.setProperty(FileWorker.DB_USER, userStr); |
|
289 |
|
|
259 | 290 |
String driver = rdbms.getValue().equals("MySQL") ? "com.mysql.cj.jdbc.Driver" : "oracle.jdbc.driver.OracleDriver"; |
260 |
converter.setInput(null, new DB_Messenger(driver, url.getText().trim(), user.getText().trim(), password.getText().trim(),
|
|
291 |
converter.setInput(null, new DB_Messenger(driver, urlStr, userStr, password.getText().trim(),
|
|
261 | 292 |
table.getText().trim(), cond.getText().trim(), column.getText().trim())); |
262 | 293 |
}); |
263 | 294 |
|
... | ... | |
320 | 351 |
this.fullScreen = (Label) fullScreen.getGraphic(); |
321 | 352 |
changeFullScreenMenuItem(); |
322 | 353 |
|
323 |
MenuItem close = createMenuItem("Ukončit", getResource("close.png"), new KeyCodeCombination(KeyCode.E, KeyCombination.CONTROL_DOWN));
|
|
354 |
MenuItem close = createMenuItem("Ukončit", FileWorker.getResource("/close.png"), new KeyCodeCombination(KeyCode.E, KeyCombination.CONTROL_DOWN));
|
|
324 | 355 |
close.setOnAction(event -> { |
325 | 356 |
Platform.exit(); |
326 | 357 |
}); |
... | ... | |
334 | 365 |
|
335 | 366 |
private void changeFullScreenMenuItem() { |
336 | 367 |
fullScreen.setText(stage.isFullScreen() ? "Normální zobrazení" : "Plné zobrazení"); |
337 |
fullScreen.setGraphic(new ImageView(stage.isFullScreen() ? getResource("normal.png") : getResource("full.png")));
|
|
368 |
fullScreen.setGraphic(new ImageView(stage.isFullScreen() ? FileWorker.getResource("/normal.png") : FileWorker.getResource("/full.png")));
|
|
338 | 369 |
} |
339 | 370 |
|
340 | 371 |
private MenuItem createMenuItem(String name, String icon, KeyCodeCombination keyCodeComb) { |
... | ... | |
356 | 387 |
outputLayout.setDisable(disable); |
357 | 388 |
} |
358 | 389 |
|
359 |
private String getResource(String path) { |
|
360 |
return Deserializer.class.getResource(path).toString(); |
|
361 |
} |
|
362 |
|
|
363 | 390 |
@Override |
364 | 391 |
public void loadingInputFileError() { |
365 | 392 |
Platform.runLater(()->{ |
... | ... | |
374 | 401 |
|
375 | 402 |
boolean showData = html != null && html.length() > 0 && json != null && json.length() > 0; |
376 | 403 |
|
377 |
if (!showData && Report.confirm("Výsledek deserializace", null, "Při deserializaci došlo k chybě. Je ale možné, že nejde o serializovaná data. Chcete zobrazit, co bylo načteno?")) { |
|
404 |
if (!showData && loaded != null && loaded.length() > 0 && |
|
405 |
Report.confirm("Výsledek deserializace", null, "Při deserializaci došlo k chybě. " |
|
406 |
+ "Je ale možné, že nejde o serializovaná data. Chcete zobrazit, co bylo načteno?")) { |
|
378 | 407 |
_html = loaded.trim(); |
379 | 408 |
_json = loaded.trim(); |
380 | 409 |
showData = true; |
project/Deserializer/src/Editor.java | ||
---|---|---|
1 | 1 |
|
2 |
import io.FileWorker; |
|
2 | 3 |
import javafx.concurrent.Worker; |
3 | 4 |
import javafx.scene.effect.BlendMode; |
4 | 5 |
import javafx.scene.input.Clipboard; |
... | ... | |
72 | 73 |
} |
73 | 74 |
|
74 | 75 |
public void setContent(String html, String json) { |
76 |
this.json = json; |
|
75 | 77 |
editor.call("setValue", ""); |
76 | 78 |
editor.call("insert", json); |
77 | 79 |
} |
... | ... | |
93 | 95 |
"</head>" + |
94 | 96 |
"<body>" + |
95 | 97 |
"<div id=\"editor\"></div>" + |
96 |
"<script src=\"" + getClass().getResource("ace/ace.js").toExternalForm() + "\"></script>" +
|
|
98 |
"<script src=\"" + FileWorker.getResource("/ace/ace.js") + "\"></script>" +
|
|
97 | 99 |
"</body>" + |
98 | 100 |
"</html>"; |
99 | 101 |
} |
project/Deserializer/src/io/FileWorker.java | ||
---|---|---|
6 | 6 |
import java.io.File; |
7 | 7 |
import java.io.FileInputStream; |
8 | 8 |
import java.io.FileNotFoundException; |
9 |
import java.io.FileOutputStream; |
|
9 | 10 |
import java.io.FileWriter; |
10 | 11 |
import java.io.IOException; |
11 | 12 |
import java.io.PrintStream; |
13 |
import java.net.URISyntaxException; |
|
14 |
import java.net.URL; |
|
12 | 15 |
import java.util.ArrayList; |
16 |
import java.util.Enumeration; |
|
13 | 17 |
import java.util.List; |
14 | 18 |
import java.util.NoSuchElementException; |
19 |
import java.util.Properties; |
|
20 |
import java.util.jar.JarEntry; |
|
21 |
import java.util.jar.JarFile; |
|
15 | 22 |
|
16 |
import javafx.collections.FXCollections; |
|
17 | 23 |
import javafx.collections.ObservableList; |
18 | 24 |
|
19 | 25 |
public class FileWorker { |
20 | 26 |
|
21 |
public static ObservableList<String> getAceModes() { |
|
22 |
File dir = new File(FileWorker.class.getResource("/ace/").toExternalForm().substring(6)); // TODO v JAR |
|
23 |
String names[] = dir.list(); |
|
24 |
ObservableList<String> modes = FXCollections.observableArrayList(); |
|
25 |
for (int i = 0; i < names.length; i++) { |
|
26 |
if (names[i].startsWith("mode-")) { |
|
27 |
modes.add(names[i].substring(5, names[i].lastIndexOf('.'))); |
|
28 |
} |
|
27 |
private static final String CONFIG = "app.config"; |
|
28 |
public static final String ACE_MODE = "ace_mode"; |
|
29 |
public static final String ACE_THEME = "ace_theme"; |
|
30 |
public static final String DB_TYPE = "db_type"; |
|
31 |
public static final String DB_URL = "db_url"; |
|
32 |
public static final String DB_USER = "db_user"; |
|
33 |
|
|
34 |
public static String getResource(String path) { |
|
35 |
return FileWorker.class.getResource(path).toString(); |
|
36 |
} |
|
37 |
|
|
38 |
public static Properties getConfig() { |
|
39 |
Properties properties = new Properties(); |
|
40 |
|
|
41 |
try { |
|
42 |
File config = new File(CONFIG); |
|
43 |
config.createNewFile(); |
|
44 |
properties.load(new FileInputStream(config)); |
|
45 |
} catch (IOException e) { } |
|
46 |
|
|
47 |
return properties; |
|
48 |
} |
|
49 |
|
|
50 |
public static void saveConfig(Properties properties) { |
|
51 |
try { |
|
52 |
properties.store(new FileOutputStream(CONFIG), null); |
|
53 |
} catch (IOException e) { |
|
54 |
e.printStackTrace(); |
|
29 | 55 |
} |
30 |
return modes; |
|
31 | 56 |
} |
32 | 57 |
|
33 |
public static ObservableList<String> getAceThemes() { |
|
34 |
File dir = new File(FileWorker.class.getResource("/ace/").toExternalForm().substring(6)); // TODO v JAR |
|
35 |
String names[] = dir.list(); |
|
36 |
ObservableList<String> themes = FXCollections.observableArrayList(); |
|
37 |
for (int i = 0; i < names.length; i++) { |
|
38 |
if (names[i].startsWith("theme-")) { |
|
39 |
themes.add(names[i].substring(6, names[i].lastIndexOf('.'))); |
|
58 |
public static void getAceModesAndThemes(ObservableList<String> modes, ObservableList<String> themes) { |
|
59 |
final String aceFolder = "ace"; |
|
60 |
List<String> names = new ArrayList<String>(); |
|
61 |
|
|
62 |
|
|
63 |
String path = FileWorker.class.getResource(FileWorker.class.getSimpleName() + ".class").getFile(); |
|
64 |
if (!path.startsWith("/")) { |
|
65 |
path = ClassLoader.getSystemClassLoader().getResource(path).getFile(); |
|
66 |
File jarFile = new File(path.substring(6, path.lastIndexOf('!'))); |
|
67 |
|
|
68 |
try { |
|
69 |
JarFile jar = new JarFile(jarFile); |
|
70 |
Enumeration<JarEntry> entries = jar.entries(); |
|
71 |
while (entries.hasMoreElements()) { |
|
72 |
String name = entries.nextElement().getName(); |
|
73 |
if (name.startsWith(aceFolder + "/")) { |
|
74 |
name = name.substring(name.lastIndexOf("/") + 1); |
|
75 |
if (name.length() > 0) { |
|
76 |
names.add(name); |
|
77 |
} |
|
78 |
} |
|
79 |
} |
|
80 |
jar.close(); |
|
81 |
} catch (IOException e) { |
|
82 |
e.printStackTrace(); |
|
83 |
} |
|
84 |
} else { |
|
85 |
URL url = FileWorker.class.getResource("/" + aceFolder); |
|
86 |
if (url != null) { |
|
87 |
try { |
|
88 |
File dir = new File(url.toURI()); |
|
89 |
for (File file : dir.listFiles()) { |
|
90 |
names.add(file.getName()); |
|
91 |
} |
|
92 |
} catch (URISyntaxException e) { |
|
93 |
e.printStackTrace(); |
|
94 |
} |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
|
|
99 |
for (int i = 0; i < names.size(); i++) { |
|
100 |
if (names.get(i).startsWith("mode-")) { |
|
101 |
modes.add(names.get(i).substring(5, names.get(i).lastIndexOf('.'))); |
|
102 |
} else if (names.get(i).startsWith("theme-")) { |
|
103 |
themes.add(names.get(i).substring(6, names.get(i).lastIndexOf('.'))); |
|
40 | 104 |
} |
41 | 105 |
} |
42 |
return themes; |
|
43 | 106 |
} |
44 | 107 |
|
45 | 108 |
public static PrintStream createRedirectStream() throws FileNotFoundException { |
project/app.config | ||
---|---|---|
1 |
#Sun Apr 26 09:05:48 CEST 2020 |
Také k dispozici: Unified diff
re #7895
Ukládání určitých dat do configu. Konkrétně nastavení editoru a základní konfigurace DB spojení. Vyřešeny problémy při exportu do .jar.