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 String configDirectory;
+ 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;
// CONFIGURATION
//
- /** Whether to beautify the GUI. */
- private boolean beautify;
+ /** The advanced mode. */
+ private boolean advancedMode;
+
+ /** Whether to antialias the GUI. */
+ private boolean antialias;
+
+ /** The control font. */
+ private String controlFont;
+
+ /** The user font. */
+ private String userFont;
/**
* Creates a new swing interface.
- *
+ *
* @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) {
+ if (antialias) {
System.setProperty("swing.aatext", "true");
- System.setProperty("swing.plaf.metal.controlFont", "Tahoma");
- System.setProperty("swing.plaf.metal.userFont", "Tahoma");
+ }
+ if (controlFont != null) {
+ System.setProperty("swing.plaf.metal.controlFont", controlFont);
+ }
+ if (userFont != null) {
+ System.setProperty("swing.plaf.metal.userFont", userFont);
}
initActions();
initDialogs();
/**
* Returns the core that is controlled by the Swing interface.
- *
+ *
* @return The core
*/
Core getCore() {
/**
* Returns the main window of the Swing interface.
- *
+ *
* @return The main window
*/
MainWindow getMainWindow() {
/**
* Returns the “configure” action.
- *
+ *
* @return The “configure” action
*/
I18nAction getConfigureAction() {
/**
* Returns the “import config” action.
- *
+ *
* @return The “import config” action
*/
I18nAction getImportConfigAction() {
/**
* Returns the “quit” action.
- *
+ *
* @return The “quit” action
*/
I18nAction getQuitAction() {
/**
* Returns the “manage nodes” action.
- *
+ *
* @return The “manage nodes” action
*/
I18nAction getManageNodesAction() {
/**
* Returns the “connect to node” action.
- *
+ *
* @return The “connect to node” action
*/
I18nAction getNodeConnectAction() {
/**
* Returns the “disconnect from node” action.
- *
+ *
* @return The “disconnect from node” action
*/
I18nAction getNodeDisconnectAction() {
/**
* Returns all language actions.
- *
+ *
* @return All language actions
*/
List<I18nAction> getLanguageActions() {
/**
* Returns the “about” action.
- *
+ *
* @return The “about” action
*/
I18nAction getHelpAboutAction() {
/**
* Returns the “add project” action.
- *
+ *
* @return The “add project” action
*/
I18nAction getAddProjectAction() {
}
/**
- * Sets the configuration directory.
- *
- * @param configDirectory
- * The directory the configuration is stored in
+ * Returns the “clone project” action.
+ *
+ * @return The “clone project” action
*/
- public void setConfigDirectory(String configDirectory) {
- this.configDirectory = configDirectory;
+ I18nAction getCloneProjectAction() {
+ return cloneProjectAction;
+ }
+
+ /**
+ * Returns the “delete project” action.
+ *
+ * @return The “delete project” action
+ */
+ I18nAction getDeleteProjectAction() {
+ return deleteProjectAction;
}
//
*/
private void loadConfig() {
/* initialize default stuff. */
- beautify = false;
+ antialias = false;
/* now read config. */
File configFile = new File(configDirectory, "swing-interface.properties");
if (!configFile.exists() || !configFile.canRead() || !configFile.isFile()) {
} finally {
Closer.close(configInputStream);
}
- if (configProperties.containsKey("beautify")) {
- beautify = Boolean.valueOf(configProperties.getProperty("beautify"));
+ if (configProperties.containsKey("advancedMode")) {
+ advancedMode = Boolean.valueOf(configProperties.getProperty("advancedMode"));
+ }
+ if (configProperties.containsKey("antialias")) {
+ antialias = Boolean.valueOf(configProperties.getProperty("antialias"));
+ }
+ if (configProperties.containsKey("controlFont")) {
+ controlFont = configProperties.getProperty("controlFont");
+ }
+ if (configProperties.containsKey("userFont")) {
+ userFont = configProperties.getProperty("userFont");
+ }
+ if (configProperties.containsKey("language")) {
+ I18n.setLocale(new Locale(configProperties.getProperty("language")));
}
}
}
File configFile = new File(configDirectory, "swing-interface.properties");
Properties configProperties = new Properties();
- configProperties.setProperty("beautify", String.valueOf(beautify));
+ configProperties.setProperty("advancedMode", String.valueOf(advancedMode));
+ configProperties.setProperty("antialias", String.valueOf(antialias));
+ if (controlFont != null) {
+ configProperties.setProperty("controlFont", controlFont);
+ }
+ if (userFont != null) {
+ configProperties.setProperty("userFont", userFont);
+ }
+ configProperties.setProperty("language", I18n.getLocale().getLanguage());
FileOutputStream configOutputStream = null;
try {
configOutputStream = new FileOutputStream(configFile);
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();
+ }
+ };
}
/**
* Shows the configuration dialog.
*/
private void configure() {
- configurationDialog.setBeautify(beautify);
+ configurationDialog.setAdvancedMode(advancedMode);
+ configurationDialog.setAntialias(antialias);
+ configurationDialog.setControlFont(controlFont);
+ configurationDialog.setUserFont(userFont);
configurationDialog.setVisible(true);
if (!configurationDialog.wasCancelled()) {
- beautify = configurationDialog.getBeautify();
+ advancedMode = configurationDialog.isAdvancedMode();
+ if (!advancedMode && (nodeList.size() > 1)) {
+ JOptionPane.showMessageDialog(mainWindow, I18n.get("mainWindow.warning.multipleNodesNotAdvancedMode.message"), I18n.get("mainWindow.warning.multipleNodesNotAdvancedMode.title"), JOptionPane.WARNING_MESSAGE);
+ }
+ antialias = configurationDialog.isAntialias();
+ controlFont = configurationDialog.getControlFont();
+ userFont = configurationDialog.getUserFont();
saveConfig();
}
}
* Imports old jSite configuration.
*/
private void importConfig() {
+ /* TODO */
}
/**
* Pops up the “manage nodes” dialog.
*/
private void manageNodes() {
- manageNodesDialog.setNodeList(nodeList);
- manageNodesDialog.setVisible(true);
- nodeList = manageNodesDialog.getNodeList();
+ if (advancedMode) {
+ manageNodesDialog.setNodeList(nodeList);
+ manageNodesDialog.setVisible(true);
+ nodeList = manageNodesDialog.getNodeList();
+ } else {
+ if (nodeList.isEmpty()) {
+ Node newNode = new Node();
+ newNode.setName(I18n.get("general.defaultNode.name"));
+ newNode.setHostname("localhost");
+ newNode.setPort(9481);
+ nodeList.add(newNode);
+ }
+ Node firstNode = nodeList.get(0);
+ EditNodeDialog editNodeDialog = manageNodesDialog.getEditNodeDialog();
+ editNodeDialog.setNodeName(firstNode.getName());
+ editNodeDialog.setNodeHostname(firstNode.getHostname());
+ editNodeDialog.setNodePort(firstNode.getPort());
+ editNodeDialog.setVisible(true);
+ if (!editNodeDialog.wasCancelled()) {
+ firstNode.setName(editNodeDialog.getNodeName());
+ firstNode.setHostname(editNodeDialog.getNodeHostname());
+ firstNode.setPort(editNodeDialog.getNodePort());
+ /* TODO - give to core. */
+ }
+ }
}
/**
* Connects to the node.
*/
private void nodeConnect() {
+ /* TODO */
}
/**
* Disconnects from the node.
*/
private void nodeDisconnect() {
+ /* TODO */
}
/**
* Changes the language of the interface. This method also disables the
* action for the newly set language and enables all others.
- *
+ *
* @param newLocale
* The new language
* @param languageAction
* Adds a project.
*/
private void addProject() {
+ Project project = new Project();
+ project.setName("New Project");
+ project.setDescription("");
+ }
+
+ /**
+ * Clones a project.
+ */
+ private void cloneProject() {
+ /* TODO */
+ }
+
+ /**
+ * Deletes a project.
+ */
+ private void deleteProject() {
+ /* TODO */
}
//
// INTERFACE CoreListener
//
+
+ /**
+ * {@inheritDoc}
+ */
+ public void loadingProjectsDone(String directory) {
+ mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.projectLoadingDone"));
+ }
+
/**
* {@inheritDoc}
*/
- public void loadingProjectsFailed(String directory) {
+ public void loadingProjectsFailed(String directory, Throwable throwable) {
JOptionPane.showMessageDialog(mainWindow, I18n.get("mainWindow.error.projectLoadingFailed.message", directory), I18n.get("mainWindow.error.projectLoadingFailed.title"), JOptionPane.ERROR_MESSAGE);
}
/**
* {@inheritDoc}
*/
+ public void savingProjectsDone(String directory) {
+ mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.projectSavingDone"));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void savingProjectsFailed(String directory, Throwable throwabled) {
+ /* TODO */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void loadingNodesDone(String directory) {
+ mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.loadingNodesDone"));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void loadingNodesFailed(String directory, Throwable throwable) {
+ /* TODO */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void savingNodesDone(String directory) {
+ mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.savingNodesDone"));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void savingNodesFailed(String directory, Throwable throwable) {
+ /* TODO */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void coreLoaded() {
this.nodeList = core.getNodes();
manageNodesDialog.setNodeList(nodeList);
mainWindow.setVisible(true);
- mainWindow.setStatusBarText("Core loaded.");
+ mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.coreLoaded"));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void coreStopped() {
+ mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.coreStopped"));
}
/**
* {@inheritDoc}
*/
public void nodeConnected(Node node) {
+ /* TODO */
}
/**
* {@inheritDoc}
*/
public void nodeConnecting(Node node) {
+ /* TODO */
}
/**
* {@inheritDoc}
*/
public void nodeDisconnected(Node node) {
+ /* TODO */
}
}