/**
* Defines the main window of the application.
- *
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
public class MainWindow extends JFrame implements WindowListener, I18nable, PropertyChangeListener {
/**
* Creates a new main window that redirects all actions to the given swing
* interface.
- *
+ *
* @param swingInterface
* The swing interface to receive all actions
*/
/**
* Sets the text of the status bar.
- *
+ *
* @param text
* The text of the status bar
*/
/**
* Returns the status bar clear delay (in milliseconds).
- *
+ *
* @return The status bar clear delay
*/
public int getStatusBarClearDelay() {
/**
* Sets the status bar clear delay (in milliseconds).
- *
+ *
* @param statusBarClearDelay
* The status bar clear delay
*/
/**
* Sets whether the advanced mode is activated.
- *
+ *
* @param advancedMode
* <code>true</code> if the advanced mode is activated,
* <code>false</code> if the simple mode is activated
/**
* Returns the currently selected project.
- *
+ *
* @return The currently selected project
*/
public Project getSelectedProject() {
/**
* Sets the given node to the “online” state.
- *
+ *
* @param node
* The node to set online
*/
/**
* Sets the given node to the “offline” state in the status bar.
- *
+ *
* @param node
* The node to set offline
*/
/**
* Sets the given node to the “error” state in the status bar.
- *
+ *
* @param node
* The node to set the error state for
*/
/**
* Adds a node to the menu.
- *
+ *
* @param node
* The node to add
*/
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
/**
* Removes the pane containing the given project.
- *
+ *
* @param project
* The project whose pane to remove
*/
/**
* 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
languageMenu = new I18nMenu("mainWindow.menu.language");
menuBar.add(languageMenu);
- for (I18nAction languageAction: swingInterface.getLanguageActions()) {
+ for (I18nAction languageAction : swingInterface.getLanguageActions()) {
languageMenu.add(new FixedJMenuItem(languageAction));
}
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();
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
+import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;
+import net.pterodactylus.jsite.core.Node;
import net.pterodactylus.jsite.core.Project;
import net.pterodactylus.jsite.i18n.I18n;
import net.pterodactylus.jsite.i18n.I18nable;
}
//
+ // ACTIONS
+ //
+
+ /**
+ * Adds the given node to the node combo boxes in all {@link ProjectPanel}s.
+ *
+ * @param node
+ * The node to add
+ */
+ public void addNode(Node node) {
+ ((DefaultComboBoxModel) nodeComboBox.getModel()).addElement(node);
+ }
+
+ /**
+ * Removes the given node from the node combo boxes in all
+ * {@link ProjectPanel}s.
+ *
+ * @param node
+ * The node to remove
+ */
+ public void removeNode(Node node) {
+ ((DefaultComboBoxModel) nodeComboBox.getModel()).removeElement(node);
+ }
+
+ //
// PRIVATE METHODS
//
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
+ @SuppressWarnings("synthetic-access")
public void actionPerformed(ActionEvent actionEvent) {
- /* TODO */
+ Node node = (Node) nodeComboBox.getSelectedItem();
+ project.setNode(node);
}
};
}
propertiesPanel.add(changeBasePathButton, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0));
propertiesPanel.add(editFilesButton, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0));
- nodeComboBox = new JComboBox();
+ nodeComboBox = new JComboBox(new DefaultComboBoxModel());
+ ((DefaultComboBoxModel) nodeComboBox.getModel()).addElement(null);
+ for (Node node : swingInterface.getNodes()) {
+ ((DefaultComboBoxModel) nodeComboBox.getModel()).addElement(node);
+ }
+ nodeComboBox.setSelectedItem(project.getNode());
nodeComboBox.addActionListener(nodeAction);
nodeLabel = new I18nLabel("projectPanel.label.node", nodeComboBox);
propertiesPanel.add(nodeLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 0, 0, 0), 0, 0));