version 0.4.9.1:
[jSite.git] / src / de / todesbaum / jsite / gui / ProjectInsertPage.java
index c2b42b0..2641fb0 100644 (file)
 package de.todesbaum.jsite.gui;
 
 import java.awt.BorderLayout;
+import java.awt.Font;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.Insets;
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.ClipboardOwner;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
 import java.text.DateFormat;
 import java.text.MessageFormat;
 import java.util.Date;
 
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.JButton;
 import javax.swing.JComponent;
 import javax.swing.JLabel;
 import javax.swing.JOptionPane;
@@ -47,11 +58,12 @@ import de.todesbaum.util.swing.TWizardPage;
  * @author David Roden <droden@gmail.com>
  * @version $Id$
  */
-public class ProjectInsertPage extends TWizardPage implements InsertListener {
+public class ProjectInsertPage extends TWizardPage implements InsertListener, ClipboardOwner {
 
        protected TWizard wizard;
        protected ProjectInserter projectInserter;
 
+       protected Action copyURIAction;
        protected JTextField requestURITextField;
        protected JLabel startTimeLabel;
        protected JProgressBar progressBar;
@@ -59,12 +71,24 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener {
 
        public ProjectInsertPage() {
                super();
+               createActions();
                pageInit();
                setHeading(I18n.getMessage("jsite.insert.heading"));
                setDescription(I18n.getMessage("jsite.insert.description"));
                projectInserter = new ProjectInserter();
                projectInserter.addInsertListener(this);
        }
+       
+       private void createActions() {
+               copyURIAction = new AbstractAction(I18n.getMessage("jsite.project.action.copy-uri")) {
+                       public void actionPerformed(ActionEvent actionEvent) {
+                               actionCopyURI();
+                       }
+               };
+               copyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
+               copyURIAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U);
+               copyURIAction.setEnabled(false);
+       }
 
        private void pageInit() {
                setLayout(new BorderLayout(12, 12));
@@ -90,6 +114,7 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener {
                projectInsertPanel.add(startTimeLabel, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
                projectInsertPanel.add(new JLabel(I18n.getMessage("jsite.insert.progress") + ":"), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 18, 0, 0), 0, 0));
                projectInsertPanel.add(progressBar, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
+               projectInsertPanel.add(new JButton(copyURIAction), new GridBagConstraints(0, 4, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_END, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
 
                return projectInsertPanel;
        }
@@ -103,7 +128,9 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener {
                wizard.setPreviousEnabled(false);
                wizard.setNextEnabled(false);
                wizard.setQuitEnabled(false);
+               copyURIAction.setEnabled(false);
                progressBar.setValue(0);
+               progressBar.setFont(progressBar.getFont().deriveFont(Font.PLAIN));
                projectInserter.start();
        }
 
@@ -124,7 +151,7 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener {
                SwingUtilities.invokeLater(new Runnable() {
 
                        public void run() {
-                               requestURITextField.setText(project.getFinalRequestURI(0));
+                               requestURITextField.setText(project.getFinalRequestURI(1));
                        }
                });
        }
@@ -156,6 +183,7 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener {
        public void projectURIGenerated(Project project, final String uri) {
                SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
+                               copyURIAction.setEnabled(true);
                                requestURITextField.setText(uri);
                        }
                });
@@ -170,6 +198,15 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener {
                        public void run() {
                                progressBar.setMaximum(total);
                                progressBar.setValue(succeeded + failed + fatal);
+                               int progress = (succeeded + failed + fatal) * 100 / total;
+                               StringBuilder progressString = new StringBuilder();
+                               progressString.append(progress).append("% (");
+                               progressString.append(succeeded + failed + fatal).append("/").append(total);
+                               progressString.append(")");
+                               progressBar.setString(progressString.toString());
+                               if (finalized) {
+                                       progressBar.setFont(progressBar.getFont().deriveFont(Font.BOLD));
+                               }
                        }
                });
        }
@@ -190,10 +227,31 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener {
                SwingUtilities.invokeLater(new Runnable() {
 
                        public void run() {
+                               progressBar.setValue(progressBar.getMaximum());
+                               progressBar.setString("Done");
                                wizard.setNextEnabled(true);
                                wizard.setQuitEnabled(true);
                        }
                });
        }
+       
+       //
+       // ACTIONS
+       //
+       
+       protected void actionCopyURI() {
+               Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+               clipboard.setContents(new StringSelection(requestURITextField.getText()), this);
+       }
+
+       //
+       // INTERFACE ClipboardOwner
+       //
+       
+       /**
+        * {@inheritDoc}
+        */
+       public void lostOwnership(Clipboard clipboard, Transferable contents) {
+       }
 
 }