X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FSwingInterface.java;h=3652388494d6076bd8855086269b8bcced504d57;hb=7a6a3c1c08be242d176b141f261e25b16fee84aa;hp=b79cdc9958492f00efea5c8e74273e1890819d21;hpb=c8cc97074d6be182035ba1d1c373099e247afc2a;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/SwingInterface.java b/src/net/pterodactylus/jsite/gui/SwingInterface.java index b79cdc9..3652388 100644 --- a/src/net/pterodactylus/jsite/gui/SwingInterface.java +++ b/src/net/pterodactylus/jsite/gui/SwingInterface.java @@ -45,8 +45,10 @@ import javax.swing.UnsupportedLookAndFeelException; import net.pterodactylus.jsite.core.Core; import net.pterodactylus.jsite.core.CoreListener; +import net.pterodactylus.jsite.core.NoNodeException; 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.util.image.IconLoader; @@ -141,7 +143,10 @@ public class SwingInterface implements CoreListener, LoggingListener { private ConfigurationDialog configurationDialog; /** The list of all defined nodes. */ - private List nodeList; + private List nodeList = Collections.synchronizedList(new ArrayList()); + + /** The request table model. */ + private RequestTableModel requestTableModel = new RequestTableModel(); // // CONFIGURATION @@ -162,6 +167,18 @@ public class SwingInterface implements CoreListener, LoggingListener { /** 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. * @@ -201,6 +218,10 @@ public class SwingInterface implements CoreListener, LoggingListener { 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(); } @@ -353,6 +374,15 @@ public class SwingInterface implements CoreListener, LoggingListener { return deleteProjectAction; } + /** + * Returns the request table model. + * + * @return The request table model + */ + RequestTableModel getRequestTableModel() { + return requestTableModel; + } + // // ACTIONS // @@ -405,6 +435,18 @@ public class SwingInterface implements CoreListener, LoggingListener { 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")); + } } /** @@ -436,6 +478,10 @@ public class SwingInterface implements CoreListener, LoggingListener { 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); @@ -623,6 +669,12 @@ public class SwingInterface implements CoreListener, LoggingListener { * 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); } @@ -634,6 +686,7 @@ public class SwingInterface implements CoreListener, LoggingListener { * The list of nodes */ private void rebuildNodeActions(List nodes) { + logger.fine("rebuilding node actions…"); nodeConnectActions.clear(); nodeNodeConnectActions.clear(); nodeConnectActionNodes.clear(); @@ -641,6 +694,7 @@ public class SwingInterface implements CoreListener, LoggingListener { nodeNodeDisconnectActions.clear(); nodeDisconnectActionNodes.clear(); for (Node node: nodes) { + logger.finer("adding node “" + node + "” to menus"); Action nodeConnectAction = new AbstractAction(node.getName()) { /** @@ -666,7 +720,7 @@ public class SwingInterface implements CoreListener, LoggingListener { nodeDisconnect(node); } }; -// nodeDisconnectActions.add(nodeDisconnectAction); + // nodeDisconnectActions.add(nodeDisconnectAction); nodeDisconnectActionNodes.put(nodeDisconnectAction, node); nodeNodeDisconnectActions.put(node, nodeDisconnectAction); } @@ -763,9 +817,17 @@ public class SwingInterface implements CoreListener, LoggingListener { * Adds a project. */ private void addProject() { - Project project = new Project(); - project.setName("New Project"); - project.setDescription(""); + try { + Project project = core.createProject("New Project"); + System.out.println("private: " + project.getPrivateKey() + ", public: " + project.getPublicKey()); + mainWindow.addProject(project); + } catch (NoNodeException 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); + } } /** @@ -846,8 +908,6 @@ public class SwingInterface implements CoreListener, LoggingListener { * {@inheritDoc} */ public void coreLoaded() { - this.nodeList = core.getNodes(); - manageNodesDialog.setNodeList(nodeList); mainWindow.setVisible(true); mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.coreLoaded")); } @@ -862,6 +922,28 @@ public class SwingInterface implements CoreListener, LoggingListener { /** * {@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); @@ -875,6 +957,18 @@ public class SwingInterface implements CoreListener, LoggingListener { 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(); } @@ -886,9 +980,33 @@ public class SwingInterface implements CoreListener, LoggingListener { 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 //