X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FMainWindow.java;h=da516c3052ce8913057ea8a508eab9065a07fbbe;hb=c63257e8cc0ba1a5aca9364b22171abe7279d479;hp=1d536c85313b73ff99b3313d755cfcd3e906f5de;hpb=3d68925f513f8e31eb34dcb1fc11e70faee847e7;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/MainWindow.java b/src/net/pterodactylus/jsite/gui/MainWindow.java index 1d536c8..da516c3 100644 --- a/src/net/pterodactylus/jsite/gui/MainWindow.java +++ b/src/net/pterodactylus/jsite/gui/MainWindow.java @@ -23,6 +23,9 @@ import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; @@ -35,7 +38,6 @@ import java.util.TimerTask; import java.util.logging.Logger; import javax.swing.Box; -import javax.swing.BoxLayout; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JFrame; @@ -49,12 +51,12 @@ import javax.swing.SwingConstants; import javax.swing.border.EmptyBorder; import net.pterodactylus.jsite.core.Node; +import net.pterodactylus.jsite.core.Project; import net.pterodactylus.jsite.i18n.I18n; import net.pterodactylus.jsite.i18n.I18nable; import net.pterodactylus.jsite.i18n.gui.I18nAction; import net.pterodactylus.jsite.i18n.gui.I18nMenu; import net.pterodactylus.jsite.main.Version; -import net.pterodactylus.jsite.project.Project; import net.pterodactylus.util.image.IconLoader; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.swing.StatusBar; @@ -62,7 +64,7 @@ import net.pterodactylus.util.swing.SwingUtils; /** * Defines the main window of the application. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ public class MainWindow extends JFrame implements WindowListener, I18nable, PropertyChangeListener { @@ -114,7 +116,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop private JTabbedPane projectPane; /** The project overview panel. */ - private Box projectOverviewPanel; + private JPanel projectOverviewPanel; /** Maps from node to menus. */ private final Map nodeMenus = new HashMap(); @@ -125,7 +127,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 */ @@ -147,7 +149,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 */ @@ -172,7 +174,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() { @@ -181,7 +183,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 */ @@ -191,7 +193,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 @@ -210,7 +212,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop /** * Returns the currently selected project. - * + * * @return The currently selected project */ public Project getSelectedProject() { @@ -219,7 +221,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop /** * Sets the given node to the “online” state. - * + * * @param node * The node to set online */ @@ -229,7 +231,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop /** * Sets the given node to the “offline” state in the status bar. - * + * * @param node * The node to set offline */ @@ -239,7 +241,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop /** * Sets the given node to the “error” state in the status bar. - * + * * @param node * The node to set the error state for */ @@ -253,7 +255,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop /** * Adds a node to the menu. - * + * * @param node * The node to add */ @@ -269,24 +271,38 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop NodeLabel nodeLabel = new NodeLabel(swingInterface, node, onlineIcon, offlineIcon, errorIcon); nodeLabels.put(node, nodeLabel); statusBar.addSideComponent(nodeLabel); + for (int tabIndex = 0, tabCount = projectPane.getTabCount(); tabIndex < tabCount; tabIndex++) { + Component tabComponent = projectPane.getComponentAt(tabIndex); + if (!(tabComponent instanceof ProjectPanel)) { + continue; + } + ((ProjectPanel) tabComponent).addNode(node); + } node.addPropertyChangeListener(this); } /** * Removes a node from the menu. - * + * * @param node * The node to remove */ void removeNode(Node node) { nodeMenu.remove(nodeMenus.remove(node)); statusBar.removeSideComponent(nodeLabels.remove(node)); + for (int tabIndex = 0, tabCount = projectPane.getTabCount(); tabIndex < tabCount; tabIndex++) { + Component tabComponent = projectPane.getComponentAt(tabIndex); + if (!(tabComponent instanceof ProjectPanel)) { + continue; + } + ((ProjectPanel) tabComponent).addNode(node); + } node.removePropertyChangeListener(this); } /** * Adds a project to the project pane. - * + * * @param project * The project to add * @param switchToProject @@ -310,7 +326,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop /** * Removes the pane containing the given project. - * + * * @param project * The project whose pane to remove */ @@ -372,7 +388,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 @@ -419,7 +435,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop languageMenu = new I18nMenu("mainWindow.menu.language"); menuBar.add(languageMenu); - for (I18nAction languageAction: swingInterface.getLanguageActions()) { + for (I18nAction languageAction : swingInterface.getLanguageActions()) { languageMenu.add(new FixedJMenuItem(languageAction)); } @@ -433,9 +449,10 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop setJMenuBar(menuBar); JToolBar toolBar = new JToolBar(I18n.get("mainWindow.toolbar.name")); - toolBar.add(swingInterface.getAddNodeAction()); - 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); @@ -465,15 +482,12 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop projectPane = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT); contentPane.add(projectPane, BorderLayout.CENTER); - projectOverviewPanel = new Box(BoxLayout.PAGE_AXIS); + projectOverviewPanel = new JPanel(new GridBagLayout()); projectOverviewPanel.setName(I18n.get("mainWindow.pane.overview.title")); projectPane.add(projectOverviewPanel); projectOverviewPanel.setBorder(new EmptyBorder(12, 12, 12, 12)); - projectOverviewPanel.add(Box.createVerticalGlue()); JButton addProjectButton = new JButton(swingInterface.getAddProjectAction()); - addProjectButton.setAlignmentX(0.5f); - projectOverviewPanel.add(addProjectButton); - projectOverviewPanel.add(Box.createVerticalGlue()); + projectOverviewPanel.add(addProjectButton, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); } // @@ -493,17 +507,17 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop jSiteMenu.updateI18n(); nodeMenu.updateI18n(); languageMenu.updateI18n(); - for (Node node: swingInterface.getNodes()) { + 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()) { + for (Project project : swingInterface.getProjects()) { swingInterface.getCloneProjectAction(project).updateI18n(); swingInterface.getDeleteProjectAction(project).updateI18n(); } - for (I18nAction languageAction: swingInterface.getLanguageActions()) { + for (I18nAction languageAction : swingInterface.getLanguageActions()) { languageAction.updateI18n(); } helpMenu.updateI18n();