[virtualcommons-svn] commit/foraging: alllee: moving ClipboardService and HtmlSelection to csidex
Status: Beta
Brought to you by:
alllee
From: Bitbucket <com...@bi...> - 2012-03-28 04:41:33
|
1 new commit in foraging: https://bitbucket.org/virtualcommons/foraging/changeset/8d4ab27b8999/ changeset: 8d4ab27b8999 user: alllee date: 2012-03-28 06:41:33 summary: moving ClipboardService and HtmlSelection to csidex affected #: 1 file diff -r b56c65df661e7cfe14c92ee81016c18236aeb658 -r 8d4ab27b89996b3419df205057452039823eaf49 src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java --- a/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java +++ b/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java @@ -2,24 +2,13 @@ import java.awt.BorderLayout; import java.awt.Dimension; -import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; -import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.io.StringReader; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; import javax.jnlp.ClipboardService; -import javax.jnlp.ServiceManager; -import javax.jnlp.UnavailableServiceException; import javax.swing.JEditorPane; import javax.swing.JLabel; import javax.swing.JMenu; @@ -41,6 +30,7 @@ import edu.asu.commons.foraging.rules.Strategy; import edu.asu.commons.foraging.rules.iu.ForagingStrategy; import edu.asu.commons.ui.HtmlEditorPane; +import edu.asu.commons.ui.HtmlSelection; import edu.asu.commons.ui.UserInterfaceUtils; /** @@ -270,11 +260,14 @@ return; } } - ClipboardService service = getClipboardService(); + ClipboardService service = UserInterfaceUtils.getClipboardService(); if (service != null) { HtmlSelection selection = new HtmlSelection(text); service.setContents(selection); } + else { + addMessage("Clipboard service is only available when run as a WebStart application."); + } } }); @@ -418,60 +411,4 @@ } } - public ClipboardService getClipboardService() { - if (clipboardService == null) { - try { - clipboardService = (ClipboardService) ServiceManager.lookup(JAVAX_JNLP_CLIPBOARD_SERVICE); - } catch (UnavailableServiceException e) { - e.printStackTrace(); - addMessage("Unable to load the ClipboardService for all your clipboard needs. Sorry!"); - } - } - return clipboardService; - } - - private static class HtmlSelection implements Transferable { - - private static DataFlavor[] htmlFlavors = new DataFlavor[3]; - private final String html; - static { - try { - htmlFlavors[0] = new DataFlavor("text/html;class=java.lang.String"); - htmlFlavors[1] = new DataFlavor("text/html;class=java.io.Reader"); - htmlFlavors[2] = new DataFlavor("text/html;charset=unicode;class=java.io.InputStream"); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - } - - public HtmlSelection(String html) { - this.html = html; - } - - @Override - public DataFlavor[] getTransferDataFlavors() { - return htmlFlavors; - } - - @Override - public boolean isDataFlavorSupported(DataFlavor flavor) { - return Arrays.asList(htmlFlavors).contains(flavor); - } - - @Override - public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { - if (String.class.equals(flavor.getRepresentationClass())) { - return html; - } - else if (Reader.class.equals(flavor.getRepresentationClass())) { - return new StringReader(html); - } - else if (InputStream.class.equals(flavor.getRepresentationClass())) { - return new ByteArrayInputStream(html.getBytes()); - } - throw new UnsupportedFlavorException(flavor); - } - - } - } Repository URL: https://bitbucket.org/virtualcommons/foraging/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |