Skip to content

Commit 6342194

Browse files
authored
Merge pull request #59 from yarl/dev
version 18.02
2 parents 9836af7 + f9ebd66 commit 6342194

18 files changed

Lines changed: 305 additions & 128 deletions

‎.github/ISSUE_TEMPLATE.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
If you are reporting a bug please:
2+
3+
- Check the bug has already been reported (https://github.com/yarl/pattypan/issues).
4+
- Explain the current issue.
5+
- Describe the expected behavior.
6+
- Add the problematic spreadsheet and a example media file (drag & drop here).
7+
- Add the PattyPan log file (drag & drop here). You find a link to the PattyPan log at the application start screen.

‎src/pattypan/LogManager.java‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package pattypan;
2+
3+
import java.io.IOException;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
7+
import java.util.logging.ConsoleHandler;
8+
import java.util.logging.FileHandler;
9+
import java.util.logging.Logger;
10+
import java.util.logging.SimpleFormatter;
11+
import pattypan.Settings;
12+
13+
public class LogManager {
14+
public static final Logger logger = Logger.getLogger(Main.class.getName());
15+
16+
public LogManager() {
17+
try {
18+
Path logFileLocation = Paths.get(Util.getApplicationDirectory() + "/logs");
19+
if (!Files.exists(logFileLocation)) {
20+
Files.createDirectories(logFileLocation);
21+
}
22+
23+
if (!Settings.getSetting("version").equals(Settings.VERSION)) {
24+
Files.deleteIfExists(Paths.get(logFileLocation.toString() + "/pattypan.log"));
25+
}
26+
27+
FileHandler fh = new FileHandler(logFileLocation.toString() + "/pattypan.log", true);
28+
fh.setFormatter(new SimpleFormatter());
29+
logger.addHandler(fh);
30+
logger.addHandler(new ConsoleHandler());
31+
logger.setUseParentHandlers(false); // remove console prefix for privacy
32+
} catch (SecurityException e) {
33+
e.printStackTrace();
34+
} catch (IOException e) {
35+
e.printStackTrace();
36+
}
37+
}
38+
}

‎src/pattypan/Main.java‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
package pattypan;
2525

2626
import java.util.logging.Level;
27-
import java.util.logging.Logger;
2827
import javafx.application.Application;
2928
import javafx.scene.Scene;
3029
import javafx.scene.image.Image;
@@ -34,12 +33,8 @@
3433
import pattypan.panes.StartPane;
3534

3635
public class Main extends Application {
37-
38-
private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
39-
4036
@Override
4137
public void start(Stage stage) {
42-
Settings.readProperties();
4338
Image logo = new Image(getClass().getResourceAsStream("/pattypan/resources/logo.png"));
4439

4540
Scene scene = new Scene(new StartPane(stage), Settings.getSettingInt("windowWidth"), Settings.getSettingInt("windowHeight"));
@@ -52,6 +47,7 @@ public void start(Stage stage) {
5247
stage.setOnCloseRequest((WindowEvent we) -> {
5348
Settings.setSetting("windowWidth", (int) scene.getWidth() + "");
5449
Settings.setSetting("windowHeight", (int) scene.getHeight() + "");
50+
Settings.setSetting("version", Settings.VERSION);
5551
Settings.saveProperties();
5652
});
5753
}
@@ -63,7 +59,6 @@ public static void main(String[] args) {
6359
String wiki = "commons.wikimedia.org";
6460
String protocol = "https://";
6561
String scriptPath = "/w";
66-
6762
for (String arg : args) {
6863
String[] pair = arg.split("=");
6964
if (pair[0].contains("wiki")) {
@@ -75,11 +70,20 @@ public static void main(String[] args) {
7570
}
7671
}
7772

78-
LOGGER.log(Level.INFO,
73+
Settings.readProperties();
74+
75+
Session.LOGGER.log(Level.INFO,
7976
"Wiki set as: {0}\nProtocol set as: {1}\nScript path set as: {2}",
8077
new String[]{wiki, protocol, scriptPath}
8178
);
82-
79+
80+
String os = System.getProperty("os.name");
81+
82+
Session.LOGGER.log(Level.INFO,
83+
"Operating System: {0}\nPattypan Version: {1}",
84+
new String[]{os, Settings.VERSION}
85+
);
86+
8387
Session.WIKI = new Wiki(wiki, scriptPath, protocol);
8488
launch(args);
8589
}

‎src/pattypan/Session.java‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,30 @@
3030
import java.util.Map;
3131
import javafx.scene.Scene;
3232
import org.wikipedia.Wiki;
33+
import pattypan.LogManager;
34+
import java.util.logging.Logger;
3335

3436
public final class Session {
35-
37+
3638
private Session() {};
37-
39+
3840
public static Map<String, Scene> SCENES = new HashMap<>();
39-
41+
4042
public static File DIRECTORY;
4143
public static File FILE;
42-
44+
4345
public static ArrayList<File> FILES = new ArrayList<>();
44-
46+
47+
public static Logger LOGGER = new LogManager().logger;
48+
4549
public static String METHOD = "template";
4650
public static String TEMPLATE = "Artwork";
4751
public static String WIKICODE = "";
4852
public static ArrayList<String> VARIABLES = new ArrayList<>(Arrays.asList("path", "name"));
49-
53+
5054
public static Wiki WIKI = new Wiki("commons.wikimedia.org");
5155
public static ArrayList<UploadElement> FILES_TO_UPLOAD = new ArrayList<>();
52-
56+
5357
static {
5458
WIKI.setUserAgent(Settings.USERAGENT);
5559
}

‎src/pattypan/Settings.java‎

Lines changed: 90 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@
3434
import java.util.Map;
3535
import java.util.Properties;
3636
import java.util.logging.Level;
37-
import java.util.logging.Logger;
37+
38+
import pattypan.Util;
3839

3940
public final class Settings {
4041

4142
private Settings() {};
4243

4344
public static final String NAME = "pattypan";
44-
public static final String VERSION = "17.12";
45+
public static final String VERSION = "18.02";
4546
public static final String USERAGENT = NAME + "/" + VERSION + " (https://github.com/yarl/pattypan)";
4647

4748
public static final Map<String, String> SETTINGS = new HashMap<>();
@@ -95,7 +96,7 @@ public final class Settings {
9596
new TemplateField("medium", "Medium"),
9697
new TemplateField("dimensions", "Dimensions"),
9798
new TemplateField("institution", "Institution"),
98-
new TemplateField("departament", "Departament"),
99+
new TemplateField("department", "Department"),
99100
new TemplateField("place_of_discovery", "Place of discovery"),
100101
new TemplateField("object_history", "Object history"),
101102
new TemplateField("exhibition_history", "Exhibition history"),
@@ -121,7 +122,7 @@ public final class Settings {
121122
+ " |medium = ${medium}\n"
122123
+ " |dimensions = ${dimensions}\n"
123124
+ " |institution = ${institution}\n"
124-
+ " |department = ${departament}\n"
125+
+ " |department = ${department}\n"
125126
+ " |place of discovery = ${place_of_discovery}\n"
126127
+ " |object history = ${object_history}\n"
127128
+ " |exhibition history = ${exhibition_history}\n"
@@ -225,6 +226,83 @@ public final class Settings {
225226
+ "</#if>"
226227
)
227228
);
229+
TEMPLATES.put("Map",
230+
new Template("Map",
231+
new TemplateField[]{
232+
new TemplateField("title", "Title"),
233+
new TemplateField("description", "Description"),
234+
new TemplateField("legend", "Legend"),
235+
new TemplateField("author", "Author"),
236+
new TemplateField("date", "Date"),
237+
new TemplateField("source", "Source"),
238+
new TemplateField("permission", "Permission"),
239+
new TemplateField("map_date", "Map date"),
240+
new TemplateField("location", "Location"),
241+
new TemplateField("projection", "Projection"),
242+
new TemplateField("scale", "Scale"),
243+
new TemplateField("heading", "Heading"),
244+
new TemplateField("latitude", "Latitude"),
245+
new TemplateField("longitude", "Longitude"),
246+
new TemplateField("warp_status", "Warp status"),
247+
new TemplateField("set", "Set"),
248+
new TemplateField("sheet", "Sheet"),
249+
new TemplateField("type", "Type"),
250+
new TemplateField("language", "Language"),
251+
new TemplateField("publisher", "Publisher"),
252+
new TemplateField("printer", "Printer"),
253+
new TemplateField("print_date", "Print date"),
254+
new TemplateField("institution", "Institution"),
255+
new TemplateField("accession_number", "Accession number"),
256+
new TemplateField("dimensions", "Dimensions"),
257+
new TemplateField("medium", "Medium"),
258+
new TemplateField("inscriptions", "Inscriptions"),
259+
new TemplateField("notes", "Notes"),
260+
new TemplateField("other_versions", "Other versions"),
261+
new TemplateField("license", "License"),
262+
new TemplateField("partnership", "Partnership")
263+
}, "=={{int:filedesc}}==\n"
264+
+ "{{Map\n"
265+
+ " |title = ${title}\n"
266+
+ " |description = ${description}\n"
267+
+ " |legend = ${legend}\n"
268+
+ " |author = ${author}\n"
269+
+ " |date = ${date}\n"
270+
+ " |source = ${source}\n"
271+
+ " |permission = ${permission}\n"
272+
+ " |map date = ${map_date}\n"
273+
+ " |location = ${location}\n"
274+
+ " |projection = ${projection}\n"
275+
+ " |scale = ${scale}\n"
276+
+ " |heading = ${heading}\n"
277+
+ " |latitude = ${latitude}\n"
278+
+ " |longitude = ${longitude}\n"
279+
+ " |warp status = ${warp_status}\n"
280+
+ " |set = ${set}\n"
281+
+ " |sheet = ${sheet}\n"
282+
+ " |type = ${type}\n"
283+
+ " |language = ${language}\n"
284+
+ " |publisher = ${publisher}\n"
285+
+ " |printer = ${printer}\n"
286+
+ " |print date = ${print_date}\n"
287+
+ " |institution = ${institution}\n"
288+
+ " |accession number = ${accession_number}\n"
289+
+ " |dimensions = ${dimensions}\n"
290+
+ " |medium = ${medium}\n"
291+
+ " |inscriptions = ${inscriptions}\n"
292+
+ " |notes = ${notes}\n"
293+
+ " |other versions = ${other_versions}\n"
294+
+ "}}\n\n"
295+
+ "=={{int:license-header}}==\n"
296+
+ "${license}${partnership}"
297+
+ "\n\n"
298+
+ "<#if categories ? has_content>\n"
299+
+ "<#list categories ? split(\";\") as category>\n"
300+
+ "[[Category:${category?trim}]]\n"
301+
+ "</#list>\n"
302+
+ "<#else>{{subst:unc}}\n"
303+
+ "</#if>"
304+
)
305+
);
228306
TEMPLATES.put("Musical work",
229307
new Template("Musical work",
230308
new TemplateField[]{
@@ -344,27 +422,6 @@ public final class Settings {
344422
*/
345423
}
346424

347-
/**
348-
* Gets directory for local user settings
349-
*
350-
* @source http://stackoverflow.com/a/16660314/1418878
351-
* @return path to local Pattypan directory
352-
*/
353-
private static String getPropertiesDirectiry() {
354-
String dir;
355-
String OS = (System.getProperty("os.name")).toUpperCase();
356-
357-
if (OS.contains("WIN")) {
358-
dir = System.getenv("AppData") + "/Pattypan";
359-
} else if (OS.contains("NUX")) {
360-
dir = System.getProperty("user.home") + "/.pattypan";
361-
} else {
362-
dir = System.getProperty("user.home");
363-
dir += "/Library/Application Support/Pattypan";
364-
}
365-
return dir;
366-
}
367-
368425
public static String getSetting(String key) {
369426
return SETTINGS.get(key) != null ? SETTINGS.get(key) : "";
370427
}
@@ -381,7 +438,7 @@ public static void readProperties() {
381438
InputStream input = null;
382439

383440
try {
384-
File f = new File(getPropertiesDirectiry() + "/config.properties");
441+
File f = new File(Util.getApplicationDirectory() + "/config.properties");
385442
input = new FileInputStream(f);
386443
prop.load(input);
387444

@@ -392,15 +449,15 @@ public static void readProperties() {
392449
});
393450

394451
} catch (FileNotFoundException ex) {
395-
Logger.getLogger(Settings.class.getName()).log(Level.INFO, "Settings file not found, use default");
452+
Session.LOGGER.log(Level.INFO, "Settings file not found, use default");
396453
} catch (IOException ex) {
397-
Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
454+
Session.LOGGER.log(Level.SEVERE, null, ex);
398455
} finally {
399456
if (input != null) {
400457
try {
401458
input.close();
402459
} catch (IOException ex) {
403-
Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
460+
Session.LOGGER.log(Level.SEVERE, null, ex);
404461
}
405462
}
406463
}
@@ -414,21 +471,21 @@ public static void saveProperties() {
414471
OutputStream output = null;
415472

416473
try {
417-
new File(getPropertiesDirectiry()).mkdirs();
418-
File f = new File(getPropertiesDirectiry() + "/config.properties");
474+
new File(Util.getApplicationDirectory()).mkdirs();
475+
File f = new File(Util.getApplicationDirectory() + "/config.properties");
419476
output = new FileOutputStream(f);
420477
SETTINGS.forEach((key, value) -> {
421478
prop.setProperty(key, value);
422479
});
423480
prop.store(output, null);
424481
} catch (IOException ex) {
425-
Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
482+
Session.LOGGER.log(Level.SEVERE, null, ex);
426483
} finally {
427484
if (output != null) {
428485
try {
429486
output.close();
430487
} catch (IOException ex) {
431-
Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
488+
Session.LOGGER.log(Level.SEVERE, null, ex);
432489
}
433490
}
434491
}

0 commit comments

Comments
 (0)