Skip to content

Commit

Permalink
Merge pull request #59 from yarl/dev
Browse files Browse the repository at this point in the history
version 18.02
  • Loading branch information
yarl authored Feb 23, 2018
2 parents 9836af7 + f9ebd66 commit 6342194
Show file tree
Hide file tree
Showing 18 changed files with 305 additions and 128 deletions.
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
If you are reporting a bug please:

- Check the bug has already been reported (https://github.com/yarl/pattypan/issues).
- Explain the current issue.
- Describe the expected behavior.
- Add the problematic spreadsheet and a example media file (drag & drop here).
- Add the PattyPan log file (drag & drop here). You find a link to the PattyPan log at the application start screen.
38 changes: 38 additions & 0 deletions src/pattypan/LogManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package pattypan;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import pattypan.Settings;

public class LogManager {
public static final Logger logger = Logger.getLogger(Main.class.getName());

public LogManager() {
try {
Path logFileLocation = Paths.get(Util.getApplicationDirectory() + "/logs");
if (!Files.exists(logFileLocation)) {
Files.createDirectories(logFileLocation);
}

if (!Settings.getSetting("version").equals(Settings.VERSION)) {
Files.deleteIfExists(Paths.get(logFileLocation.toString() + "/pattypan.log"));
}

FileHandler fh = new FileHandler(logFileLocation.toString() + "/pattypan.log", true);
fh.setFormatter(new SimpleFormatter());
logger.addHandler(fh);
logger.addHandler(new ConsoleHandler());
logger.setUseParentHandlers(false); // remove console prefix for privacy
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
20 changes: 12 additions & 8 deletions src/pattypan/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package pattypan;

import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
Expand All @@ -34,12 +33,8 @@
import pattypan.panes.StartPane;

public class Main extends Application {

private static final Logger LOGGER = Logger.getLogger(Main.class.getName());

@Override
public void start(Stage stage) {
Settings.readProperties();
Image logo = new Image(getClass().getResourceAsStream("/pattypan/resources/logo.png"));

Scene scene = new Scene(new StartPane(stage), Settings.getSettingInt("windowWidth"), Settings.getSettingInt("windowHeight"));
Expand All @@ -52,6 +47,7 @@ public void start(Stage stage) {
stage.setOnCloseRequest((WindowEvent we) -> {
Settings.setSetting("windowWidth", (int) scene.getWidth() + "");
Settings.setSetting("windowHeight", (int) scene.getHeight() + "");
Settings.setSetting("version", Settings.VERSION);
Settings.saveProperties();
});
}
Expand All @@ -63,7 +59,6 @@ public static void main(String[] args) {
String wiki = "commons.wikimedia.org";
String protocol = "https://";
String scriptPath = "/w";

for (String arg : args) {
String[] pair = arg.split("=");
if (pair[0].contains("wiki")) {
Expand All @@ -75,11 +70,20 @@ public static void main(String[] args) {
}
}

LOGGER.log(Level.INFO,
Settings.readProperties();

Session.LOGGER.log(Level.INFO,
"Wiki set as: {0}\nProtocol set as: {1}\nScript path set as: {2}",
new String[]{wiki, protocol, scriptPath}
);


String os = System.getProperty("os.name");

Session.LOGGER.log(Level.INFO,
"Operating System: {0}\nPattypan Version: {1}",
new String[]{os, Settings.VERSION}
);

Session.WIKI = new Wiki(wiki, scriptPath, protocol);
launch(args);
}
Expand Down
18 changes: 11 additions & 7 deletions src/pattypan/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,30 @@
import java.util.Map;
import javafx.scene.Scene;
import org.wikipedia.Wiki;
import pattypan.LogManager;
import java.util.logging.Logger;

public final class Session {

private Session() {};

public static Map<String, Scene> SCENES = new HashMap<>();

public static File DIRECTORY;
public static File FILE;

public static ArrayList<File> FILES = new ArrayList<>();


public static Logger LOGGER = new LogManager().logger;

public static String METHOD = "template";
public static String TEMPLATE = "Artwork";
public static String WIKICODE = "";
public static ArrayList<String> VARIABLES = new ArrayList<>(Arrays.asList("path", "name"));

public static Wiki WIKI = new Wiki("commons.wikimedia.org");
public static ArrayList<UploadElement> FILES_TO_UPLOAD = new ArrayList<>();

static {
WIKI.setUserAgent(Settings.USERAGENT);
}
Expand Down
123 changes: 90 additions & 33 deletions src/pattypan/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import pattypan.Util;

public final class Settings {

private Settings() {};

public static final String NAME = "pattypan";
public static final String VERSION = "17.12";
public static final String VERSION = "18.02";
public static final String USERAGENT = NAME + "/" + VERSION + " (https://github.com/yarl/pattypan)";

public static final Map<String, String> SETTINGS = new HashMap<>();
Expand Down Expand Up @@ -95,7 +96,7 @@ public final class Settings {
new TemplateField("medium", "Medium"),
new TemplateField("dimensions", "Dimensions"),
new TemplateField("institution", "Institution"),
new TemplateField("departament", "Departament"),
new TemplateField("department", "Department"),
new TemplateField("place_of_discovery", "Place of discovery"),
new TemplateField("object_history", "Object history"),
new TemplateField("exhibition_history", "Exhibition history"),
Expand All @@ -121,7 +122,7 @@ public final class Settings {
+ " |medium = ${medium}\n"
+ " |dimensions = ${dimensions}\n"
+ " |institution = ${institution}\n"
+ " |department = ${departament}\n"
+ " |department = ${department}\n"
+ " |place of discovery = ${place_of_discovery}\n"
+ " |object history = ${object_history}\n"
+ " |exhibition history = ${exhibition_history}\n"
Expand Down Expand Up @@ -225,6 +226,83 @@ public final class Settings {
+ "</#if>"
)
);
TEMPLATES.put("Map",
new Template("Map",
new TemplateField[]{
new TemplateField("title", "Title"),
new TemplateField("description", "Description"),
new TemplateField("legend", "Legend"),
new TemplateField("author", "Author"),
new TemplateField("date", "Date"),
new TemplateField("source", "Source"),
new TemplateField("permission", "Permission"),
new TemplateField("map_date", "Map date"),
new TemplateField("location", "Location"),
new TemplateField("projection", "Projection"),
new TemplateField("scale", "Scale"),
new TemplateField("heading", "Heading"),
new TemplateField("latitude", "Latitude"),
new TemplateField("longitude", "Longitude"),
new TemplateField("warp_status", "Warp status"),
new TemplateField("set", "Set"),
new TemplateField("sheet", "Sheet"),
new TemplateField("type", "Type"),
new TemplateField("language", "Language"),
new TemplateField("publisher", "Publisher"),
new TemplateField("printer", "Printer"),
new TemplateField("print_date", "Print date"),
new TemplateField("institution", "Institution"),
new TemplateField("accession_number", "Accession number"),
new TemplateField("dimensions", "Dimensions"),
new TemplateField("medium", "Medium"),
new TemplateField("inscriptions", "Inscriptions"),
new TemplateField("notes", "Notes"),
new TemplateField("other_versions", "Other versions"),
new TemplateField("license", "License"),
new TemplateField("partnership", "Partnership")
}, "=={{int:filedesc}}==\n"
+ "{{Map\n"
+ " |title = ${title}\n"
+ " |description = ${description}\n"
+ " |legend = ${legend}\n"
+ " |author = ${author}\n"
+ " |date = ${date}\n"
+ " |source = ${source}\n"
+ " |permission = ${permission}\n"
+ " |map date = ${map_date}\n"
+ " |location = ${location}\n"
+ " |projection = ${projection}\n"
+ " |scale = ${scale}\n"
+ " |heading = ${heading}\n"
+ " |latitude = ${latitude}\n"
+ " |longitude = ${longitude}\n"
+ " |warp status = ${warp_status}\n"
+ " |set = ${set}\n"
+ " |sheet = ${sheet}\n"
+ " |type = ${type}\n"
+ " |language = ${language}\n"
+ " |publisher = ${publisher}\n"
+ " |printer = ${printer}\n"
+ " |print date = ${print_date}\n"
+ " |institution = ${institution}\n"
+ " |accession number = ${accession_number}\n"
+ " |dimensions = ${dimensions}\n"
+ " |medium = ${medium}\n"
+ " |inscriptions = ${inscriptions}\n"
+ " |notes = ${notes}\n"
+ " |other versions = ${other_versions}\n"
+ "}}\n\n"
+ "=={{int:license-header}}==\n"
+ "${license}${partnership}"
+ "\n\n"
+ "<#if categories ? has_content>\n"
+ "<#list categories ? split(\";\") as category>\n"
+ "[[Category:${category?trim}]]\n"
+ "</#list>\n"
+ "<#else>{{subst:unc}}\n"
+ "</#if>"
)
);
TEMPLATES.put("Musical work",
new Template("Musical work",
new TemplateField[]{
Expand Down Expand Up @@ -344,27 +422,6 @@ public final class Settings {
*/
}

/**
* Gets directory for local user settings
*
* @source http://stackoverflow.com/a/16660314/1418878
* @return path to local Pattypan directory
*/
private static String getPropertiesDirectiry() {
String dir;
String OS = (System.getProperty("os.name")).toUpperCase();

if (OS.contains("WIN")) {
dir = System.getenv("AppData") + "/Pattypan";
} else if (OS.contains("NUX")) {
dir = System.getProperty("user.home") + "/.pattypan";
} else {
dir = System.getProperty("user.home");
dir += "/Library/Application Support/Pattypan";
}
return dir;
}

public static String getSetting(String key) {
return SETTINGS.get(key) != null ? SETTINGS.get(key) : "";
}
Expand All @@ -381,7 +438,7 @@ public static void readProperties() {
InputStream input = null;

try {
File f = new File(getPropertiesDirectiry() + "/config.properties");
File f = new File(Util.getApplicationDirectory() + "/config.properties");
input = new FileInputStream(f);
prop.load(input);

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

} catch (FileNotFoundException ex) {
Logger.getLogger(Settings.class.getName()).log(Level.INFO, "Settings file not found, use default");
Session.LOGGER.log(Level.INFO, "Settings file not found, use default");
} catch (IOException ex) {
Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
Session.LOGGER.log(Level.SEVERE, null, ex);
} finally {
if (input != null) {
try {
input.close();
} catch (IOException ex) {
Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
Session.LOGGER.log(Level.SEVERE, null, ex);
}
}
}
Expand All @@ -414,21 +471,21 @@ public static void saveProperties() {
OutputStream output = null;

try {
new File(getPropertiesDirectiry()).mkdirs();
File f = new File(getPropertiesDirectiry() + "/config.properties");
new File(Util.getApplicationDirectory()).mkdirs();
File f = new File(Util.getApplicationDirectory() + "/config.properties");
output = new FileOutputStream(f);
SETTINGS.forEach((key, value) -> {
prop.setProperty(key, value);
});
prop.store(output, null);
} catch (IOException ex) {
Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
Session.LOGGER.log(Level.SEVERE, null, ex);
} finally {
if (output != null) {
try {
output.close();
} catch (IOException ex) {
Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
Session.LOGGER.log(Level.SEVERE, null, ex);
}
}
}
Expand Down
Loading

0 comments on commit 6342194

Please sign in to comment.