X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FMainWindow.java;h=2e2e0825cbefff722330760e8714e0e6db79bcd7;hb=f0bc03c6988cc9abcb2fcba8f149b1d41031ec5e;hp=654f548cf40c1e07d32b4ccc052d61bf69ce236f;hpb=7403a08d06153ecc3869efc0204064c37e67dc37;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/MainWindow.java b/src/net/pterodactylus/jsite/gui/MainWindow.java index 654f548..2e2e082 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,12 +38,12 @@ 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; import javax.swing.JMenu; import javax.swing.JMenuBar; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JToolBar; @@ -48,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; @@ -113,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(); @@ -137,6 +140,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")); } // @@ -267,6 +271,13 @@ 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); } @@ -279,6 +290,13 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop 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); } @@ -299,10 +317,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) { @@ -402,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)); } @@ -416,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); @@ -448,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)); } // @@ -472,19 +503,21 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop swingInterface.getQuitAction().updateI18n(); swingInterface.getAddNodeAction().updateI18n(); swingInterface.getAddProjectAction().updateI18n(); - swingInterface.getCloneProjectAction().updateI18n(); - swingInterface.getDeleteProjectAction().updateI18n(); swingInterface.getHelpAboutAction().updateI18n(); 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 (I18nAction languageAction: swingInterface.getLanguageActions()) { + for (Project project : swingInterface.getProjects()) { + swingInterface.getCloneProjectAction(project).updateI18n(); + swingInterface.getDeleteProjectAction(project).updateI18n(); + } + for (I18nAction languageAction : swingInterface.getLanguageActions()) { languageAction.updateI18n(); } helpMenu.updateI18n(); @@ -496,7 +529,6 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop ((ProjectPanel) tabComponent).updateI18n(); } } - SwingUtils.repackCentered(this); } // @@ -566,17 +598,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) {