Add check box and text field for “changed name” attribute.
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 22 Jan 2010 21:24:54 +0000 (22:24 +0100)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 22 Jan 2010 21:24:54 +0000 (22:24 +0100)
src/de/todesbaum/jsite/gui/ProjectFilesPage.java
src/de/todesbaum/jsite/i18n/jSite.properties
src/de/todesbaum/jsite/i18n/jSite_de.properties

index b2fe3d9..fd9ae2f 100644 (file)
@@ -112,6 +112,12 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
        /** The “custom key” textfield. */
        private JTextField fileOptionsCustomKeyTextField;
 
+       /** The “rename” check box. */
+       private JCheckBox fileOptionsRenameCheckBox;
+
+       /** The “new name” text field. */
+       private JTextField fileOptionsRenameTextField;
+
        /** The “mime type” combo box. */
        private JComboBox fileOptionsMIMETypeComboBox;
 
@@ -283,6 +289,46 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                fileOptionsPanel.add(customKeyLabel, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 6, 0, 0), 0, 0));
                fileOptionsPanel.add(fileOptionsCustomKeyTextField, new GridBagConstraints(2, 5, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
 
+               fileOptionsRenameCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.rename"), false);
+               fileOptionsRenameCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.rename.tooltip"));
+               fileOptionsRenameCheckBox.setName("rename");
+               fileOptionsRenameCheckBox.setMnemonic(KeyEvent.VK_N);
+               fileOptionsRenameCheckBox.addActionListener(this);
+               fileOptionsRenameCheckBox.setEnabled(false);
+
+               fileOptionsRenameTextField = new JTextField();
+               fileOptionsRenameTextField.setEnabled(false);
+               fileOptionsRenameTextField.getDocument().addDocumentListener(new DocumentListener() {
+
+                       @SuppressWarnings("synthetic-access")
+                       private void storeText(DocumentEvent documentEvent) {
+                               FileOption fileOption = getSelectedFile();
+                               Document document = documentEvent.getDocument();
+                               int documentLength = document.getLength();
+                               try {
+                                       fileOption.setChangedName(document.getText(0, documentLength).trim());
+                               } catch (BadLocationException ble1) {
+                                       /* ignore, it should never happen. */
+                               }
+                       }
+
+                       public void changedUpdate(DocumentEvent documentEvent) {
+                               storeText(documentEvent);
+                       }
+
+                       public void insertUpdate(DocumentEvent documentEvent) {
+                               storeText(documentEvent);
+                       }
+
+                       public void removeUpdate(DocumentEvent documentEvent) {
+                               storeText(documentEvent);
+                       }
+
+               });
+
+               fileOptionsPanel.add(fileOptionsRenameCheckBox, new GridBagConstraints(0, 6, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
+               fileOptionsPanel.add(fileOptionsRenameTextField, new GridBagConstraints(2, 6, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
+
                fileOptionsMIMETypeComboBox = new JComboBox(DefaultMIMETypes.getAllMIMETypes());
                fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
                fileOptionsMIMETypeComboBox.setName("project-files.mime-type");
@@ -291,8 +337,8 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                fileOptionsMIMETypeComboBox.setEnabled(false);
 
                final TLabel mimeTypeLabel = new TLabel(I18n.getMessage("jsite.project-files.mime-type") + ":", KeyEvent.VK_M, fileOptionsMIMETypeComboBox);
-               fileOptionsPanel.add(mimeTypeLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
-               fileOptionsPanel.add(fileOptionsMIMETypeComboBox, new GridBagConstraints(1, 6, 4, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
+               fileOptionsPanel.add(mimeTypeLabel, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
+               fileOptionsPanel.add(fileOptionsMIMETypeComboBox, new GridBagConstraints(1, 7, 4, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
 
                containerComboBoxModel = new DefaultComboBoxModel();
                fileOptionsContainerComboBox = new JComboBox(containerComboBoxModel);
@@ -310,11 +356,11 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                editContainerButton.setVisible(false);
                JButton deleteContainerButton = new JButton(deleteContainerAction);
                deleteContainerButton.setVisible(false);
-               fileOptionsPanel.add(containerLabel, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
-               fileOptionsPanel.add(fileOptionsContainerComboBox, new GridBagConstraints(1, 7, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
-               fileOptionsPanel.add(addContainerButton, new GridBagConstraints(2, 7, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
-               fileOptionsPanel.add(editContainerButton, new GridBagConstraints(3, 7, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
-               fileOptionsPanel.add(deleteContainerButton, new GridBagConstraints(4, 7, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
+               fileOptionsPanel.add(containerLabel, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
+               fileOptionsPanel.add(fileOptionsContainerComboBox, new GridBagConstraints(1, 8, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
+               fileOptionsPanel.add(addContainerButton, new GridBagConstraints(2, 8, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
+               fileOptionsPanel.add(editContainerButton, new GridBagConstraints(3, 8, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
+               fileOptionsPanel.add(deleteContainerButton, new GridBagConstraints(4, 8, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
 
                JPanel fileOptionsReplacementPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 6, 6));
                fileOptionsReplacementPanel.setBorder(new EmptyBorder(-6, -6, -6, -6));
@@ -338,7 +384,7 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                fileOptionsReplacementPanel.add(editionRangeLabel);
                fileOptionsReplacementPanel.add(replaceEditionRangeSpinner);
 
-               fileOptionsPanel.add(fileOptionsReplacementPanel, new GridBagConstraints(0, 8, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 18, 0, 0), 0, 0));
+               fileOptionsPanel.add(fileOptionsReplacementPanel, new GridBagConstraints(0, 9, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 18, 0, 0), 0, 0));
 
                I18nContainer.getInstance().registerRunnable(new Runnable() {
 
@@ -355,6 +401,8 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                                fileOptionsInsertRedirectCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert-redirect.tooltip"));
                                fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
                                customKeyLabel.setText(I18n.getMessage("jsite.project-files.custom-key") + ":");
+                               fileOptionsRenameCheckBox.setText("jsite.project-files.rename");
+                               fileOptionsRenameCheckBox.setToolTipText("jsite.project-files.rename.tooltip");
                                fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
                                mimeTypeLabel.setText(I18n.getMessage("jsite.project-files.mime-type") + ":");
                                fileOptionsContainerComboBox.setToolTipText(I18n.getMessage("jsite.project-files.container.tooltip"));
@@ -548,6 +596,21 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                });
        }
 
+       /**
+        * Returns the {@link FileOption file options} for the currently selected
+        * file.
+        *
+        * @return The {@link FileOption}s for the selected file, or {@code null} if
+        *         no file is selected
+        */
+       private FileOption getSelectedFile() {
+               String filename = (String) projectFileList.getSelectedValue();
+               if (filename == null) {
+                       return null;
+               }
+               return project.getFileOption(filename);
+       }
+
        //
        // INTERFACE ActionListener
        //
@@ -586,6 +649,10 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                                boolean isInsertRedirect = checkBox.isSelected();
                                fileOption.setInsertRedirect(isInsertRedirect);
                                fileOptionsCustomKeyTextField.setEnabled(isInsertRedirect);
+                       } else if ("rename".equals(checkBox.getName())) {
+                               boolean isRenamed = checkBox.isSelected();
+                               fileOptionsRenameTextField.setEnabled(isRenamed);
+                               fileOption.setChangedName(isRenamed ? fileOptionsRenameTextField.getText() : "");
                        } else if ("project-files.replace-edition".equals(checkBox.getName())) {
                                boolean replaceEdition = checkBox.isSelected();
                                fileOption.setReplaceEdition(replaceEdition);
@@ -621,6 +688,7 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                boolean insert = fileOptionsInsertCheckBox.isSelected();
                defaultFileCheckBox.setEnabled(enabled);
                fileOptionsInsertCheckBox.setEnabled(enabled);
+               fileOptionsRenameCheckBox.setEnabled(enabled);
                fileOptionsMIMETypeComboBox.setEnabled(enabled);
                fileOptionsContainerComboBox.setEnabled(enabled);
                addContainerAction.setEnabled(enabled);
@@ -635,6 +703,9 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                        fileOptionsInsertRedirectCheckBox.setSelected(fileOption.isInsertRedirect());
                        fileOptionsCustomKeyTextField.setEnabled(fileOption.isInsertRedirect());
                        fileOptionsCustomKeyTextField.setText(fileOption.getCustomKey());
+                       fileOptionsRenameCheckBox.setSelected(fileOption.hasChangedName());
+                       fileOptionsRenameTextField.setEnabled(fileOption.hasChangedName());
+                       fileOptionsRenameTextField.setText(fileOption.getChangedName());
                        fileOptionsMIMETypeComboBox.getModel().setSelectedItem(fileOption.getMimeType());
                        fileOptionsContainerComboBox.setSelectedItem(fileOption.getContainer());
                        replacementCheckBox.setSelected(fileOption.getReplaceEdition());
@@ -647,6 +718,10 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                        fileOptionsInsertRedirectCheckBox.setSelected(false);
                        fileOptionsCustomKeyTextField.setEnabled(false);
                        fileOptionsCustomKeyTextField.setText("CHK@");
+                       fileOptionsRenameCheckBox.setEnabled(false);
+                       fileOptionsRenameCheckBox.setSelected(false);
+                       fileOptionsRenameTextField.setEnabled(false);
+                       fileOptionsRenameTextField.setText("");
                        fileOptionsMIMETypeComboBox.getModel().setSelectedItem(DefaultMIMETypes.DEFAULT_MIME_TYPE);
                        fileOptionsContainerComboBox.setSelectedItem("");
                        replacementCheckBox.setSelected(false);
index db78119..291f30f 100644 (file)
@@ -152,6 +152,8 @@ jsite.project-files.insert-redirect=Redirect
 jsite.project-files.insert-redirect.tooltip=Check if you want to insert a redirect for this file
 jsite.project-files.custom-key=Custom key
 jsite.project-files.custom-key.tooltip=The externally created key for the file
+jsite.project-files.rename=Rename
+jsite.project-files.rename.tooltip=Renames the file in the uploaded site
 jsite.project-files.mime-type=MIME type
 jsite.project-files.mime-type.tooltip=Select the correct MIME type here if the detection failed
 jsite.project-files.container=Container
@@ -192,3 +194,4 @@ jsite.error.index-missing=<html>Your default file is missing</b><br><br>A defaul
 jsite.error.index-not-inserted=<html><b>Default file not inserted</b><br><br>You have chosen not to insert the default file!<br>You need to either choose to insert it or select<br>a different default file!</html>
 jsite.error.no-custom-key=<html><b>No custom key for file</b><br><br>You specified not to insert <code>{0}</code><br>but failed to enter a key to redirect to!</html>
 jsite.error.no-files-to-insert=<html><b>No files to insert</b><br><br>You do not have any files selected for insertion!<br>Please select at least one file to insert.</html>
+jsite.error.duplicate-file=<html><b>Duplicate file</b><br><br>The file <code>{0}</code> is inserted twice!<br>Please check your filenames and redirects.</html>
index 6c303ff..ee7f2be 100644 (file)
@@ -152,6 +152,8 @@ jsite.project-files.insert-redirect=Umleitung
 jsite.project-files.insert-redirect.tooltip=F\u00fcgt eine Umleitung ein
 jsite.project-files.custom-key=Extern erstellter Schl\u00fcssel
 jsite.project-files.custom-key.tooltip=Der extern erstellte Schl\u00fcssel f\u00fcr diese Datei
+jsite.project-files.rename=Umbenennen
+jsite.project-files.rename.tooltip=Benennt die Datei in der eingef\u00fcgten Seite um
 jsite.project-files.mime-type=MIME-Typ
 jsite.project-files.mime-type.tooltip=Den richtigen MIME-Typ hier ausw\u00e4hlen, wenn die automatische Erkennenung falsch ist
 jsite.project-files.container=Container
@@ -192,3 +194,4 @@ jsite.error.index-missing=<html><b>Index-Datei fehlt!</b><br><br>Sie haben eine
 jsite.error.index-not-inserted=<html><b>Index-Datei nicht eingef\u00fcgt</b><br><br>Die index-Datei ist nicht zum Einf\u00fcgen ausgew\u00e4hlt!<br>Sie m\u00fcssen entweder w\u00e4hlen, die Index-Datei einzuf\u00fcgen,<br>oder Sie m\u00fcssen eine andere Index-Datei ausw\u00e4hlen!</html>
 jsite.error.no-custom-key=<html><b>Kein externer Schl\u00fcssel</b><br><br>Sie haben angegeben, dass die Datei <code>{0}</code><br>nicht eingef\u00fcgt werden soll. Allerdings haben Sie<br>keinen extern erstellten Schl\u00fcssel angegeben.</html>
 jsite.error.no-files-to-insert=<html><b>Keine Dateien einzuf\u00fcgen</b><br><br>Es sind keine Dateien zum Einf\u00fcgen ausgew\u00e4hlt! Bitte<br>w\u00e4hlen Sie mindestens eine Datei zum Einf\u00fcgen aus!</html>
+jsite.error.duplicate-file=<html><b>Doppelte Datei</b><br><br>Die Datei <code>{0}</code> wird zweimal eingef\u00fcgt!<br>Bitte \u00fcberpr\u00fcfen Sie Ihre Umleitungen und Dateinamen!</html>