X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FMainWindow.java;h=d4924d06747ff77afecf5a95ebbc53cd968feee5;hb=79e957d90cf47fdedbbd2892c312ccb406ac2f22;hp=61a61c62c864e3ca1471f6140c10c8126252b99c;hpb=86fee12cd8136a0c768189795f8a7d4916aad26b;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/MainWindow.java b/src/net/pterodactylus/jsite/gui/MainWindow.java index 61a61c6..d4924d0 100644 --- a/src/net/pterodactylus/jsite/gui/MainWindow.java +++ b/src/net/pterodactylus/jsite/gui/MainWindow.java @@ -41,6 +41,7 @@ import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JToolBar; @@ -61,9 +62,8 @@ import net.pterodactylus.util.swing.SwingUtils; /** * Defines the main window of the application. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> - * @version $Id$ */ public class MainWindow extends JFrame implements WindowListener, I18nable, PropertyChangeListener { @@ -125,7 +125,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop /** * Creates a new main window that redirects all actions to the given swing * interface. - * + * * @param swingInterface * The swing interface to receive all actions */ @@ -138,6 +138,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop SwingUtils.center(this); I18n.registerI18nable(this); addWindowListener(this); + setIconImage(IconLoader.loadImage("/jSite-frame-icon.png")); } // @@ -146,7 +147,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop /** * Sets the text of the status bar. - * + * * @param text * The text of the status bar */ @@ -171,7 +172,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop /** * Returns the status bar clear delay (in milliseconds). - * + * * @return The status bar clear delay */ public int getStatusBarClearDelay() { @@ -180,7 +181,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop /** * Sets the status bar clear delay (in milliseconds). - * + * * @param statusBarClearDelay * The status bar clear delay */ @@ -190,7 +191,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop /** * Sets whether the advanced mode is activated. - * + * * @param advancedMode * true if the advanced mode is activated, * false if the simple mode is activated @@ -209,20 +210,50 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop /** * Returns the currently selected project. - * + * * @return The currently selected project */ public Project getSelectedProject() { return null; } + /** + * Sets the given node to the “online” state. + * + * @param node + * The node to set online + */ + public void setOnline(Node node) { + nodeLabels.get(node).setOnline(); + } + + /** + * Sets the given node to the “offline” state in the status bar. + * + * @param node + * The node to set offline + */ + public void setOffline(Node node) { + nodeLabels.get(node).setOffline(); + } + + /** + * Sets the given node to the “error” state in the status bar. + * + * @param node + * The node to set the error state for + */ + public void setError(Node node) { + nodeLabels.get(node).setError(); + } + // // ACTIONS // /** * Adds a node to the menu. - * + * * @param node * The node to add */ @@ -231,6 +262,9 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop nodeMenus.put(node, newNodeMenu); newNodeMenu.add(swingInterface.getNodeConnectAction(node)); newNodeMenu.add(swingInterface.getNodeDisconnectAction(node)); + newNodeMenu.addSeparator(); + newNodeMenu.add(swingInterface.getNodeEditAction(node)); + newNodeMenu.add(swingInterface.getNodeDeleteAction(node)); nodeMenu.add(newNodeMenu); NodeLabel nodeLabel = new NodeLabel(swingInterface, node, onlineIcon, offlineIcon, errorIcon); nodeLabels.put(node, nodeLabel); @@ -240,7 +274,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop /** * Removes a node from the menu. - * + * * @param node * The node to remove */ @@ -252,7 +286,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop /** * Adds a project to the project pane. - * + * * @param project * The project to add * @param switchToProject @@ -267,10 +301,25 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop project.addPropertyChangeListener(this); if (switchToProject) { projectPane.setSelectedIndex(newTabIndex); + while (project.getBasePath().length() == 0) { + JOptionPane.showMessageDialog(this, I18n.get("mainWindow.information.changeProjectBasePath.message"), I18n.get("mainWindow.information.changeProjectBasePath.title"), JOptionPane.INFORMATION_MESSAGE); + projectPanel.changeBasePath(); + } } } /** + * Removes the pane containing the given project. + * + * @param project + * The project whose pane to remove + */ + void removeProject(Project project) { + int projectIndex = getProjectIndex(project); + projectPane.remove(projectIndex); + } + + /** * @param project */ void projectInsertStarted(Project project) { @@ -323,7 +372,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop /** * Returns the index of the project panel that contains the given project. - * + * * @param project * The wanted project * @return The index of {@link #projectPane}’s tab that contains the given @@ -364,7 +413,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop nodeMenu = new I18nMenu("mainWindow.menu.node"); menuBar.add(nodeMenu); - nodeMenu.add(new FixedJMenuItem(swingInterface.getManageNodesAction())); + nodeMenu.add(new FixedJMenuItem(swingInterface.getAddNodeAction())); nodeMenu.addSeparator(); languageMenu = new I18nMenu("mainWindow.menu.language"); @@ -384,9 +433,10 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop setJMenuBar(menuBar); JToolBar toolBar = new JToolBar(I18n.get("mainWindow.toolbar.name")); - toolBar.add(swingInterface.getManageNodesAction()); - toolBar.addSeparator(); + toolBar.add(swingInterface.getConfigureAction()); toolBar.add(swingInterface.getQuitAction()); + toolBar.addSeparator(); + toolBar.add(swingInterface.getAddNodeAction()); super.getContentPane().add(toolBar, BorderLayout.PAGE_START); super.getContentPane().add(contentPane, BorderLayout.CENTER); @@ -438,10 +488,8 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop swingInterface.getConfigureAction().updateI18n(); swingInterface.getImportConfigAction().updateI18n(); swingInterface.getQuitAction().updateI18n(); - swingInterface.getManageNodesAction().updateI18n(); + swingInterface.getAddNodeAction().updateI18n(); swingInterface.getAddProjectAction().updateI18n(); - swingInterface.getCloneProjectAction().updateI18n(); - swingInterface.getDeleteProjectAction().updateI18n(); swingInterface.getHelpAboutAction().updateI18n(); jSiteMenu.updateI18n(); nodeMenu.updateI18n(); @@ -449,6 +497,12 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop for (Node node: swingInterface.getNodes()) { swingInterface.getNodeConnectAction(node).updateI18n(); swingInterface.getNodeDisconnectAction(node).updateI18n(); + swingInterface.getNodeEditAction(node).updateI18n(); + swingInterface.getNodeDeleteAction(node).updateI18n(); + } + for (Project project: swingInterface.getProjects()) { + swingInterface.getCloneProjectAction(project).updateI18n(); + swingInterface.getDeleteProjectAction(project).updateI18n(); } for (I18nAction languageAction: swingInterface.getLanguageActions()) { languageAction.updateI18n(); @@ -462,7 +516,6 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop ((ProjectPanel) tabComponent).updateI18n(); } } - SwingUtils.repackCentered(this); } // @@ -532,17 +585,11 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop /* if a project was changed, update the tab title and tooltip. */ if (Project.PROPERTY_NAME.equals(propertyName) || Project.PROPERTY_DESCRIPTION.equals(propertyName)) { Project project = (Project) eventSource; - int tabCount = projectPane.getTabCount(); - for (int tabIndex = 0; tabIndex < tabCount; tabIndex++) { - Component tabComponent = projectPane.getComponentAt(tabIndex); - if (tabComponent instanceof ProjectPanel) { - Project tabProject = ((ProjectPanel) tabComponent).getProject(); - if (tabProject.equals(project)) { - projectPane.setTitleAt(tabIndex, project.getName()); - projectPane.setToolTipTextAt(tabIndex, project.getDescription()); - projectPane.repaint(); - } - } + int projectIndex = getProjectIndex(project); + if (projectIndex != -1) { + projectPane.setTitleAt(projectIndex, project.getName()); + projectPane.setToolTipTextAt(projectIndex, project.getDescription()); + projectPane.repaint(); } } } else if (eventSource instanceof Node) {