X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fde%2Ftodesbaum%2Fjsite%2Fgui%2FProjectInsertPage.java;h=1c7089ddb2d8f912f461590a73b0bd2c82998809;hb=refs%2Ftags%2F0.4.8;hp=ef06fc5f1d503d87de9eedb48aa91e8a83d0331a;hpb=6f1a8216cfba28add0ef365b46a08d16d4eb87fe;p=jSite.git diff --git a/src/de/todesbaum/jsite/gui/ProjectInsertPage.java b/src/de/todesbaum/jsite/gui/ProjectInsertPage.java index ef06fc5..1c7089d 100644 --- a/src/de/todesbaum/jsite/gui/ProjectInsertPage.java +++ b/src/de/todesbaum/jsite/gui/ProjectInsertPage.java @@ -23,10 +23,20 @@ import java.awt.BorderLayout; 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; @@ -35,7 +45,6 @@ import javax.swing.JProgressBar; import javax.swing.JTextField; import javax.swing.SwingUtilities; -import de.todesbaum.jsite.application.EditionProject; import de.todesbaum.jsite.application.Freenet7Interface; import de.todesbaum.jsite.application.InsertListener; import de.todesbaum.jsite.application.Project; @@ -46,13 +55,14 @@ import de.todesbaum.util.swing.TWizardPage; /** * @author David Roden <droden@gmail.com> - * @version $Id: ProjectInsertPage.java 408 2006-03-29 09:31:10Z bombe $ + * @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; @@ -60,12 +70,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)); @@ -77,8 +99,6 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener { requestURITextField = new JTextField(); requestURITextField.setEditable(false); - requestURITextField.setBackground(getBackground()); - requestURITextField.setBorder(null); startTimeLabel = new JLabel(); @@ -93,6 +113,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; } @@ -106,6 +127,7 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener { wizard.setPreviousEnabled(false); wizard.setNextEnabled(false); wizard.setQuitEnabled(false); + copyURIAction.setEnabled(false); progressBar.setValue(0); projectInserter.start(); } @@ -127,18 +149,11 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener { SwingUtilities.invokeLater(new Runnable() { public void run() { - StringBuffer uriBuffer = new StringBuffer(); - uriBuffer.append(project.getRequestURI()); - uriBuffer.append(project.getPath()); - if (project instanceof EditionProject) { - uriBuffer.append('-').append(((EditionProject) project).getEdition()); - } - uriBuffer.append('/'); - requestURITextField.setText(uriBuffer.toString()); + requestURITextField.setText(project.getFinalRequestURI(0)); } }); } - + public void setFreenetInterface(Freenet7Interface freenetInterface) { projectInserter.setFreenetInterface(freenetInterface); } @@ -159,6 +174,18 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener { } }); } + + /** + * {@inheritDoc} + */ + public void projectURIGenerated(Project project, final String uri) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + copyURIAction.setEnabled(true); + requestURITextField.setText(uri); + } + }); + } /** * {@inheritDoc} @@ -189,10 +216,30 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener { SwingUtilities.invokeLater(new Runnable() { public void run() { + progressBar.setValue(progressBar.getMaximum()); 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) { + } }