import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import net.pterodactylus.jsite.core.Core;
import net.pterodactylus.jsite.core.CoreListener;
+import net.pterodactylus.jsite.core.JSiteException;
import net.pterodactylus.jsite.core.Node;
-import net.pterodactylus.jsite.core.Project;
+import net.pterodactylus.jsite.core.Request;
import net.pterodactylus.jsite.i18n.I18n;
import net.pterodactylus.jsite.i18n.gui.I18nAction;
+import net.pterodactylus.jsite.project.Project;
+import net.pterodactylus.util.image.IconLoader;
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.logging.LoggingListener;
private ConfigurationDialog configurationDialog;
/** The list of all defined nodes. */
- private List<Node> nodeList;
+ private List<Node> nodeList = Collections.synchronizedList(new ArrayList<Node>());
+
+ /** The request table model. */
+ private RequestTableModel requestTableModel = new RequestTableModel();
//
// CONFIGURATION
/** The class name of the look and feel. */
private String lookAndFeel;
+ /** X coordinate of the main window. */
+ private int mainWindowX = -1;
+
+ /** Y coordinate of the main window. */
+ private int mainWindowY = -1;
+
+ /** Width of the main window. */
+ private int mainWindowWidth = -1;
+
+ /** Height of the main window. */
+ private int mainWindowHeight = -1;
+
/**
* Creates a new swing interface.
*
initDialogs();
mainWindow = new MainWindow(this);
mainWindow.setAdvancedMode(advancedMode);
+ if ((mainWindowX != -1) && (mainWindowY != -1) && (mainWindowWidth != -1) && (mainWindowHeight != -1)) {
+ mainWindow.setLocation(mainWindowX, mainWindowY);
+ mainWindow.setSize(mainWindowWidth, mainWindowHeight);
+ }
logWindow = new LogWindow();
}
return deleteProjectAction;
}
+ /**
+ * Returns the request table model.
+ *
+ * @return The request table model
+ */
+ RequestTableModel getRequestTableModel() {
+ return requestTableModel;
+ }
+
//
// ACTIONS
//
if (configProperties.containsKey("language")) {
I18n.setLocale(new Locale(configProperties.getProperty("language")));
}
+ if (configProperties.containsKey("mainWindowX")) {
+ mainWindowX = Integer.valueOf(configProperties.getProperty("mainWindowX"));
+ }
+ if (configProperties.containsKey("mainWindowY")) {
+ mainWindowY = Integer.valueOf(configProperties.getProperty("mainWindowY"));
+ }
+ if (configProperties.containsKey("mainWindowWidth")) {
+ mainWindowWidth = Integer.valueOf(configProperties.getProperty("mainWindowWidth"));
+ }
+ if (configProperties.containsKey("mainWindowHeight")) {
+ mainWindowHeight = Integer.valueOf(configProperties.getProperty("mainWindowHeight"));
+ }
}
/**
configProperties.setProperty("lookAndFeel", lookAndFeel);
}
configProperties.setProperty("language", I18n.getLocale().getLanguage());
+ configProperties.setProperty("mainWindowX", String.valueOf(mainWindowX));
+ configProperties.setProperty("mainWindowY", String.valueOf(mainWindowY));
+ configProperties.setProperty("mainWindowWidth", String.valueOf(mainWindowWidth));
+ configProperties.setProperty("mainWindowHeight", String.valueOf(mainWindowHeight));
FileOutputStream configOutputStream = null;
try {
configOutputStream = new FileOutputStream(configFile);
* Initializes all actions.
*/
private void initActions() {
- configureAction = new I18nAction("mainWindow.menu.jSite.configure") {
+ configureAction = new I18nAction("mainWindow.menu.jSite.configure", IconLoader.loadIcon("/preferences-system.png")) {
/**
* {@inheritDoc}
importConfig();
}
};
- quitAction = new I18nAction("mainWindow.menu.jSite.quit") {
+ quitAction = new I18nAction("mainWindow.menu.jSite.quit", IconLoader.loadIcon("/system-log-out.png")) {
/**
* {@inheritDoc}
* Quits jSite.
*/
private void quit() {
+ /* TODO - ask */
+ core.stop();
+ mainWindowX = mainWindow.getX();
+ mainWindowY = mainWindow.getY();
+ mainWindowWidth = mainWindow.getWidth();
+ mainWindowHeight = mainWindow.getHeight();
saveConfig();
System.exit(0);
}
* The list of nodes
*/
private void rebuildNodeActions(List<Node> nodes) {
+ logger.fine("rebuilding node actions…");
nodeConnectActions.clear();
nodeNodeConnectActions.clear();
nodeConnectActionNodes.clear();
nodeNodeDisconnectActions.clear();
nodeDisconnectActionNodes.clear();
for (Node node: nodes) {
+ logger.finer("adding node “" + node + "” to menus");
Action nodeConnectAction = new AbstractAction(node.getName()) {
/**
nodeDisconnect(node);
}
};
-// nodeDisconnectActions.add(nodeDisconnectAction);
+ // nodeDisconnectActions.add(nodeDisconnectAction);
nodeDisconnectActionNodes.put(nodeDisconnectAction, node);
nodeNodeDisconnectActions.put(node, nodeDisconnectAction);
}
* Adds a project.
*/
private void addProject() {
- Project project = new Project();
- project.setName("New Project");
- project.setDescription("");
+ try {
+ Project project = core.createProject();
+ mainWindow.addProject(project);
+ project.setName(I18n.get("general.newProject.name"));
+ project.setDescription(I18n.get("general.newProject.description", new Date()));
+ } catch (JSiteException nne1) {
+ /* TODO - add i18n */
+ JOptionPane.showMessageDialog(mainWindow, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE);
+ } catch (IOException e) {
+ /* TODO - add i18n */
+ JOptionPane.showMessageDialog(mainWindow, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE);
+ }
}
/**
*/
public void loadingProjectsDone(String directory) {
mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.projectLoadingDone"));
+ for (Project project: core.getProjects()) {
+ mainWindow.addProject(project);
+ }
}
/**
* {@inheritDoc}
*/
public void coreLoaded() {
- this.nodeList = core.getNodes();
- manageNodesDialog.setNodeList(nodeList);
mainWindow.setVisible(true);
mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.coreLoaded"));
}
/**
* {@inheritDoc}
*/
+ public void nodeAdded(Node node) {
+ logger.log(Level.INFO, "node added: " + node);
+ nodeList.add(node);
+ logger.log(Level.FINE, "nodeList.size(): " + nodeList.size());
+ manageNodesDialog.setNodeList(nodeList);
+ rebuildNodeActions(nodeList);
+ mainWindow.refreshNodeMenuItems();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void nodeRemoved(Node node) {
+ logger.log(Level.INFO, "node removed: " + node);
+ nodeList.remove(node);
+ rebuildNodeActions(nodeList);
+ mainWindow.refreshNodeMenuItems();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void nodeConnecting(Node node) {
Action nodeConnectAction = nodeNodeConnectActions.get(node);
nodeConnectActions.remove(nodeConnectAction);
public void nodeConnected(Node node) {
Action nodeDisconnectAction = nodeNodeDisconnectActions.get(node);
nodeDisconnectActions.add(nodeDisconnectAction);
+ mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.connectedToNode", node.getName(), node.getHostname(), node.getPort()));
+ mainWindow.refreshNodeMenuItems();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void nodeConnectionFailed(Node node, Throwable cause) {
+ Action nodeConnectAction = nodeNodeConnectActions.get(node);
+ nodeConnectActions.add(nodeConnectAction);
+ mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.connectionToNodeFailed", node.getName(), node.getHostname(), node.getPort(), (cause != null) ? cause.getMessage() : "no reason given"));
+ JOptionPane.showMessageDialog(mainWindow, I18n.get("mainWindow.error.nodeConnectionFailed.message", node.getName(), node.getHostname(), node.getPort(), (cause != null) ? cause.getMessage() : "no reason given"), I18n.get("mainWindow.error.nodeConnectionFailed.title"), JOptionPane.ERROR_MESSAGE);
mainWindow.refreshNodeMenuItems();
}
nodeConnectActions.add(nodeConnectAction);
Action nodeDisconnectAction = nodeNodeDisconnectActions.get(node);
nodeDisconnectActions.remove(nodeDisconnectAction);
+ mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.disconnectedFromNode", node.getName(), node.getHostname(), node.getPort()));
mainWindow.refreshNodeMenuItems();
}
+ /**
+ * {@inheritDoc}
+ */
+ public void requestAdded(Request request) {
+ logger.log(Level.INFO, "request added to node: " + request + ", " + request.getNode());
+ /* TODO - implement */
+ requestTableModel.addRequest(request);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void requestProgressed(Request request) {
+ /* TODO - update table model */
+ }
+
+ /**
+ * @see net.pterodactylus.jsite.core.CoreListener#requestRemoved(net.pterodactylus.jsite.core.Request)
+ */
+ public void requestRemoved(Request request) {
+ requestTableModel.removeRequest(request);
+ }
+
//
// INTERFACE LoggingListener
//