X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FProjectPanel.java;h=187e0571ca6be16b27ce94b01fdae5232265bb92;hb=954a1a33392ef83e007b1045e2aaeac173361289;hp=73d901f2bbd7ce42c22e01fd356ce107df4da7f0;hpb=03d89340924164e1158490999186383217e9d2bd;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/ProjectPanel.java b/src/net/pterodactylus/jsite/gui/ProjectPanel.java index 73d901f..187e057 100644 --- a/src/net/pterodactylus/jsite/gui/ProjectPanel.java +++ b/src/net/pterodactylus/jsite/gui/ProjectPanel.java @@ -25,26 +25,28 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; -import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +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.JLabel; 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; import net.pterodactylus.jsite.i18n.gui.I18nAction; import net.pterodactylus.jsite.i18n.gui.I18nLabel; -import net.pterodactylus.jsite.project.Entry; -import net.pterodactylus.jsite.project.Project; import net.pterodactylus.util.logging.Logging; /** @@ -89,8 +91,14 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { /** The “base path” textfield. */ private JTextField basePathTextField; - /** The “base path information” label. */ - private JLabel basePathInformationLabel; + /** The “node” label. */ + private I18nLabel nodeLabel; + + /** The “node” action. */ + private Action nodeAction; + + /** The “node” combo box. */ + private JComboBox nodeComboBox; /** * Creates a new project panel. @@ -123,6 +131,31 @@ public class ProjectPanel extends JPanel implements DocumentListener, 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 // @@ -150,6 +183,17 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { editFiles(); } }; + nodeAction = new AbstractAction() { + + /** + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + Node node = (Node) nodeComboBox.getSelectedItem(); + project.setNode(node); + } + }; } /** @@ -177,25 +221,34 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { nameTextField.getDocument().addDocumentListener(this); nameLabel = new I18nLabel("projectPanel.label.name", nameTextField); propertiesPanel.add(nameLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); - propertiesPanel.add(nameTextField, new GridBagConstraints(1, 0, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 6, 0, 0), 0, 0)); + propertiesPanel.add(nameTextField, new GridBagConstraints(1, 0, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 12, 0, 0), 0, 0)); descriptionTextField = new JTextField(project.getDescription()); descriptionTextField.getDocument().addDocumentListener(this); descriptionLabel = new I18nLabel("projectPanel.label.description", descriptionTextField); - propertiesPanel.add(descriptionLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 0, 0, 0), 0, 0)); - propertiesPanel.add(descriptionTextField, new GridBagConstraints(1, 1, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0)); + propertiesPanel.add(descriptionLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 0, 0, 0), 0, 0)); + propertiesPanel.add(descriptionTextField, new GridBagConstraints(1, 1, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); basePathTextField = new JTextField(project.getBasePath()); basePathTextField.setEditable(false); basePathLabel = new I18nLabel("projectPanel.label.basePath"); - basePathInformationLabel = new JLabel(I18n.get("projectPanel.basePathInformation.fileCount", project.getBasePathEntries().size())); JButton changeBasePathButton = new JButton(changeBasePathAction); JButton editFilesButton = new JButton(editFilesAction); - propertiesPanel.add(basePathLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 0, 0, 0), 0, 0)); - propertiesPanel.add(basePathTextField, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0)); - propertiesPanel.add(changeBasePathButton, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0)); - propertiesPanel.add(editFilesButton, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0)); - propertiesPanel.add(basePathInformationLabel, new GridBagConstraints(1, 3, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0)); + propertiesPanel.add(basePathLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 0, 0, 0), 0, 0)); + propertiesPanel.add(basePathTextField, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(12, 12, 0, 0), 0, 0)); + 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(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)); + propertiesPanel.add(nodeComboBox, new GridBagConstraints(1, 3, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); propertiesPanel.add(new JPanel(), new GridBagConstraints(0, 4, 4, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); @@ -246,22 +299,7 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { if (chooseAction == JFileChooser.APPROVE_OPTION) { String newBasePath = fileChooser.getSelectedFile().getPath(); basePathTextField.setText(newBasePath); - basePathInformationLabel.setText(I18n.get("projectPanel.basePathInformation.scanning")); project.setBasePath(newBasePath); - changeBasePathAction.setEnabled(false); - swingInterface.getThreadPool().execute(new Runnable() { - - /** - * {@inheritDoc} - */ - @SuppressWarnings("synthetic-access") - public void run() { - project.rescanBasePath(); - List projectEntries = project.getBasePathEntries(); - basePathInformationLabel.setText(I18n.get("projectPanel.basePathInformation.fileCount", projectEntries.size())); - changeBasePathAction.setEnabled(true); - } - }); } } @@ -270,7 +308,7 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { * physical and virtual files. */ private void editFiles() { - FileManager fileManager = new FileManager(swingInterface.getMainWindow(), project); + FileManager fileManager = new FileManager(swingInterface, project); fileManager.setVisible(true); }