package net.pterodactylus.jsite.gui;
import java.awt.BorderLayout;
+import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.DefaultListCellRenderer;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
+import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
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;
/**
* A panel that contains all information about a project and lets the user edit
* the properties of the project.
- *
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
public class ProjectPanel extends JPanel implements DocumentListener, I18nable {
/** Logger. */
- @SuppressWarnings("unused")
private static final Logger logger = Logging.getLogger(ProjectPanel.class.getName());
/** The Swing interface. */
/**
* Creates a new project panel.
- *
+ *
* @param swingInterface
* The Swing interface
* @param project
/**
* Returns the project that is displayed in this panel.
- *
+ *
* @return The project of this panel
*/
public Project getProject() {
}
//
+ // 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
//
/**
* {@inheritDoc}
*/
- @SuppressWarnings("synthetic-access")
public void actionPerformed(ActionEvent actionEvent) {
changeBasePath();
}
/**
* @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);
}
};
}
/**
* Creates the properties panel.
- *
+ *
* @return The properties panel
*/
private JPanel createPropertiesPanel() {
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());
+ nodeComboBox.setRenderer(new NodeComboBoxCellRenderer());
+ ((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));
/**
* Creates the button panel.
- *
+ *
* @return The button panel
*/
private JPanel createButtonPanel() {
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 12, 12));
buttonPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12));
- buttonPanel.add(new JButton(swingInterface.getDeleteProjectAction(project)));
+ buttonPanel.add(new JButton(swingInterface.getInsertProjectAction(project)));
buttonPanel.add(new JButton(swingInterface.getCloneProjectAction(project)));
+ buttonPanel.add(new JButton(swingInterface.getDeleteProjectAction(project)));
return buttonPanel;
}
/**
* Updates the project from changes in the text fields.
- *
+ *
* @param document
* The document that was changed
*/
textFieldsUpdated(documentEvent.getDocument());
}
+ /**
+ * Cell cenderer for the node combo box.
+ *
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ */
+ private static class NodeComboBoxCellRenderer extends DefaultListCellRenderer {
+
+ /**
+ * Empty constructor.
+ */
+ public NodeComboBoxCellRenderer() {
+ super();
+ }
+
+ /**
+ * @see javax.swing.DefaultListCellRenderer#getListCellRendererComponent(javax.swing.JList,
+ * java.lang.Object, int, boolean, boolean)
+ */
+ @Override
+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ if (value == null) {
+ return super.getListCellRendererComponent(list, "\u00a0", index, isSelected, cellHasFocus);
+ }
+ return super.getListCellRendererComponent(list, ((Node) value).getName(), index, isSelected, cellHasFocus);
+ }
+
+ }
+
}