X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FSwingInterface.java;h=45e98ac1e75dae7784d499b864e6b0fd794cb0bd;hb=6b6f9763a64c5245ed53b4a6d4103aa2fe6cd481;hp=fb76cf02a3a448509ff8b75291a3a277969631a3;hpb=2bd90a148fe17a4f091d148586d67eb69f4122f6;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/SwingInterface.java b/src/net/pterodactylus/jsite/gui/SwingInterface.java index fb76cf0..45e98ac 100644 --- a/src/net/pterodactylus/jsite/gui/SwingInterface.java +++ b/src/net/pterodactylus/jsite/gui/SwingInterface.java @@ -40,13 +40,18 @@ import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JOptionPane; +import javax.swing.UIManager; +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; import net.pterodactylus.util.io.Closer; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.logging.LoggingListener; @@ -138,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 @@ -156,6 +164,21 @@ public class SwingInterface implements CoreListener, LoggingListener { /** The user font. */ private String userFont; + /** 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. * @@ -169,6 +192,19 @@ public class SwingInterface implements CoreListener, LoggingListener { this.configDirectory = configDirectory; I18n.setLocale(Locale.ENGLISH); loadConfig(); + if (lookAndFeel != null) { + try { + UIManager.setLookAndFeel(lookAndFeel); + } catch (ClassNotFoundException cnfe1) { + logger.log(Level.WARNING, "could not load look and feel", cnfe1); + } catch (InstantiationException ie1) { + logger.log(Level.WARNING, "could not load look and feel", ie1); + } catch (IllegalAccessException iae1) { + logger.log(Level.WARNING, "could not load look and feel", iae1); + } catch (UnsupportedLookAndFeelException ulafe1) { + logger.log(Level.WARNING, "could not load look and feel", ulafe1); + } + } if (antialias) { System.setProperty("swing.aatext", "true"); } @@ -182,8 +218,11 @@ 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(); - logWindow.setVisible(true); /* TODO - remove */ } // @@ -335,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 // @@ -381,9 +429,24 @@ public class SwingInterface implements CoreListener, LoggingListener { if (configProperties.containsKey("userFont")) { userFont = configProperties.getProperty("userFont"); } + if (configProperties.containsKey("lookAndFeel")) { + lookAndFeel = configProperties.getProperty("lookAndFeel"); + } 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")); + } } /** @@ -411,7 +474,14 @@ public class SwingInterface implements CoreListener, LoggingListener { if (userFont != null) { configProperties.setProperty("userFont", userFont); } + if (lookAndFeel != null) { + 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); @@ -427,7 +497,7 @@ public class SwingInterface implements CoreListener, LoggingListener { * 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} @@ -447,7 +517,7 @@ public class SwingInterface implements CoreListener, LoggingListener { importConfig(); } }; - quitAction = new I18nAction("mainWindow.menu.jSite.quit") { + quitAction = new I18nAction("mainWindow.menu.jSite.quit", IconLoader.loadIcon("/system-log-out.png")) { /** * {@inheritDoc} @@ -572,6 +642,7 @@ public class SwingInterface implements CoreListener, LoggingListener { configurationDialog.setAntialias(antialias); configurationDialog.setControlFont(controlFont); configurationDialog.setUserFont(userFont); + configurationDialog.setLookAndFeel(lookAndFeel); configurationDialog.setVisible(true); if (!configurationDialog.wasCancelled()) { advancedMode = configurationDialog.isAdvancedMode(); @@ -582,6 +653,7 @@ public class SwingInterface implements CoreListener, LoggingListener { antialias = configurationDialog.isAntialias(); controlFont = configurationDialog.getControlFont(); userFont = configurationDialog.getUserFont(); + lookAndFeel = configurationDialog.getLookAndFeel(); saveConfig(); } } @@ -597,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); } @@ -608,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(); @@ -615,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()) { /** @@ -640,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); } @@ -737,9 +817,19 @@ 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(); + project.setName(I18n.get("")); /* TODO - i18n */ + project.setDescription(I18n.get("")); /* TODO - i18n */ + 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); + } } /** @@ -820,8 +910,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")); } @@ -836,6 +924,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); @@ -849,6 +959,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(); } @@ -860,9 +982,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 //