package net.pterodactylus.jsite.gui;
import java.awt.event.ActionEvent;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
+import java.util.Properties;
import javax.swing.JOptionPane;
import net.pterodactylus.jsite.core.Core;
import net.pterodactylus.jsite.core.CoreListener;
import net.pterodactylus.jsite.core.Node;
+import net.pterodactylus.jsite.core.Project;
import net.pterodactylus.jsite.i18n.I18n;
import net.pterodactylus.jsite.i18n.gui.I18nAction;
+import net.pterodactylus.util.io.Closer;
/**
- * TODO
+ * The Swing user interface.
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
/** The application core. */
private final Core core;
+ /** The configuration directory. */
+ private final String configDirectory;
+
/** The main window. */
private MainWindow mainWindow;
/** The “add project” action. */
private I18nAction addProjectAction;
+ /** The “clone project” action. */
+ private I18nAction cloneProjectAction;
+
+ /** The “delete project” action. */
+ private I18nAction deleteProjectAction;
+
/** The “about” dialog. */
private AboutDialog aboutDialog;
*
* @param core
* The core to operate on
+ * @param configDirectory
+ * The directory the configuration is stored in
*/
- public SwingInterface(Core core) {
+ public SwingInterface(Core core, String configDirectory) {
this.core = core;
- I18n.setLocale(Locale.ENGLISH); /* TODO - load config */
+ this.configDirectory = configDirectory;
+ I18n.setLocale(Locale.ENGLISH);
loadConfig();
if (beautify) {
System.setProperty("swing.aatext", "true");
return addProjectAction;
}
+ /**
+ * Returns the “clone project” action.
+ *
+ * @return The “clone project” action
+ */
+ I18nAction getCloneProjectAction() {
+ return cloneProjectAction;
+ }
+
+ /**
+ * Returns the “delete project” action.
+ *
+ * @return The “delete project” action
+ */
+ I18nAction getDeleteProjectAction() {
+ return deleteProjectAction;
+ }
+
//
// ACTIONS
//
* Loads the configuration of the interface.
*/
private void loadConfig() {
- beautify = true;
+ /* initialize default stuff. */
+ beautify = false;
+ /* now read config. */
+ File configFile = new File(configDirectory, "swing-interface.properties");
+ if (!configFile.exists() || !configFile.canRead() || !configFile.isFile()) {
+ System.err.println("could not find “" + configFile.getAbsolutePath() + "”!");
+ return;
+ }
+ Properties configProperties = new Properties();
+ FileInputStream configInputStream = null;
+ try {
+ configInputStream = new FileInputStream(configFile);
+ configProperties.load(configInputStream);
+ } catch (IOException ioe1) {
+ System.err.println("could not load config, " + ioe1.getMessage());
+ } finally {
+ Closer.close(configInputStream);
+ }
+ if (configProperties.containsKey("beautify")) {
+ beautify = Boolean.valueOf(configProperties.getProperty("beautify"));
+ }
+ }
+
+ /**
+ * Saves the configuration.
+ */
+ private void saveConfig() {
+ File configDirectory = new File(this.configDirectory);
+ if (!configDirectory.exists()) {
+ if (!configDirectory.mkdirs()) {
+ System.err.println("could not create “" + this.configDirectory + "”!");
+ return;
+ }
+ }
+ if (!configDirectory.exists() || !configDirectory.isDirectory() || !configDirectory.canWrite()) {
+ System.err.println("can not access “" + this.configDirectory + "”!");
+ return;
+ }
+ File configFile = new File(configDirectory, "swing-interface.properties");
+ Properties configProperties = new Properties();
+ configProperties.setProperty("beautify", String.valueOf(beautify));
+ FileOutputStream configOutputStream = null;
+ try {
+ configOutputStream = new FileOutputStream(configFile);
+ configProperties.store(configOutputStream, "configuration of swing interface");
+ } catch (IOException ioe1) {
+ System.err.println("could not save config, " + ioe1.getMessage());
+ } finally {
+ Closer.close(configOutputStream);
+ }
}
/**
addProject();
}
};
+ cloneProjectAction = new I18nAction("mainWindow.button.cloneProject") {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent actionEvent) {
+ cloneProject();
+ }
+ };
+ deleteProjectAction = new I18nAction("mainWindow.button.deleteProject") {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent actionEvent) {
+ deleteProject();
+ }
+ };
}
/**
configurationDialog.setVisible(true);
if (!configurationDialog.wasCancelled()) {
beautify = configurationDialog.getBeautify();
+ saveConfig();
}
}
* Quits jSite.
*/
private void quit() {
+ saveConfig();
System.exit(0);
}
* Adds a project.
*/
private void addProject() {
+ Project project = new Project();
+ project.setName("New Project");
+ project.setDescription("");
+ }
+
+ /**
+ * Clones a project.
+ */
+ private void cloneProject() {
+ }
+
+ /**
+ * Deletes a project.
+ */
+ private void deleteProject() {
}
//