From: David ‘Bombe’ Roden Date: Sat, 24 May 2008 21:05:32 +0000 (+0200) Subject: implement base path changing X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=dc08ba62be9bfe0fe0c55831f8cbba785c37881c;p=jSite2.git implement base path changing --- diff --git a/src/net/pterodactylus/jsite/gui/ProjectPanel.java b/src/net/pterodactylus/jsite/gui/ProjectPanel.java index d0fb1af..03f91cc 100644 --- a/src/net/pterodactylus/jsite/gui/ProjectPanel.java +++ b/src/net/pterodactylus/jsite/gui/ProjectPanel.java @@ -25,19 +25,24 @@ 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.Logger; import javax.swing.BorderFactory; import javax.swing.JButton; +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.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; @@ -81,6 +86,9 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { /** The “base path” textfield. */ private JTextField basePathTextField; + /** The “base path information” label. */ + private JLabel basePathInformationLabel; + /** * Creates a new project panel. * @@ -166,12 +174,14 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { basePathTextField = new JTextField(project.getBasePath()); basePathTextField.setEditable(false); basePathLabel = new I18nLabel("projectPanel.label.basePath"); + basePathInformationLabel = new JLabel(""); JButton changeBasePathButton = new JButton(changeBasePathAction); 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(basePathInformationLabel, new GridBagConstraints(1, 3, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 6, 0, 0), 0, 0)); - propertiesPanel.add(new JPanel(), new GridBagConstraints(0, 3, 3, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + propertiesPanel.add(new JPanel(), new GridBagConstraints(0, 4, 3, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); return propertiesPanel; } @@ -213,7 +223,28 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { * Lets the user select a new base path and repopulates the file list. */ private void changeBasePath() { - /* TODO - edit base path */ + JFileChooser fileChooser = new JFileChooser(project.getBasePath()); + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + fileChooser.setApproveButtonText(I18n.get("projectPanel.button.approve.name")); + int chooseAction = fileChooser.showOpenDialog(this); + if (chooseAction == JFileChooser.APPROVE_OPTION) { + String newBasePath = fileChooser.getSelectedFile().getPath(); + basePathTextField.setText(newBasePath); + basePathInformationLabel.setText(I18n.get("projectPanel.basePathInformation.scanning")); + project.setBasePath(newBasePath); + 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())); + } + }); + } } // diff --git a/src/net/pterodactylus/jsite/i18n/jSite.properties b/src/net/pterodactylus/jsite/i18n/jSite.properties index d4e22b0..1c9c652 100644 --- a/src/net/pterodactylus/jsite/i18n/jSite.properties +++ b/src/net/pterodactylus/jsite/i18n/jSite.properties @@ -186,6 +186,9 @@ projectPanel.label.description.mnemonic: VK_D projectPanel.label.basePath.name: Base Path projectPanel.label.basePath.mnemonic: VK_B +projectPanel.basePathInformation.scanning: Scanning the base path\u2026 +projectPanel.basePathInformation.fileCount: Found {0} file{0,choice,0#s|1#|2#s}. + projectPanel.button.changeBasePath.name: Change projectPanel.button.changeBasePath.mnemonic: VK_C projectPanel.button.changeBasePath.accelerator: Ctrl-VK_C diff --git a/src/net/pterodactylus/jsite/i18n/jSite_de.properties b/src/net/pterodactylus/jsite/i18n/jSite_de.properties index fc12868..734b704 100644 --- a/src/net/pterodactylus/jsite/i18n/jSite_de.properties +++ b/src/net/pterodactylus/jsite/i18n/jSite_de.properties @@ -186,6 +186,9 @@ projectPanel.label.description.mnemonic: VK_B projectPanel.label.basePath.name: Basispfad projectPanel.label.basePath.mnemonic: VK_B +projectPanel.basePathInformation.scanning: Durchsuche den Basispfad\u2026 +projectPanel.basePathInformation.fileCount: {0} Datei{0,choice,0#en|1#|2#en} gefunden. + projectPanel.button.changeBasePath.name: \u00c4ndern projectPanel.button.changeBasePath.mnemonic: VK_N projectPanel.button.changeBasePath.accelerator: Ctrl-VK_N