• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.clients
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Changeset
  • Next Changeset →

Changeset 5535

Show
Ignore:
Timestamp:
07/09/08 17:44:33 (5 months ago)
Author:
will
Message:

Paste button to allow clip-board text to be pasted into the EditorPane?. This is to overcome problems with pasting from word documents into the Editor pane.

Files:
1 modified

  • branches/ProtocolEditor/src/ui/components/AttributeMemoFormatEditor.java (modified) (5 diffs)

Legend:

Unmodified
Added
Removed
  • branches/ProtocolEditor/src/ui/components/AttributeMemoFormatEditor.java

    r5260 r5535  
    55 
    66import java.awt.BorderLayout; 
     7import java.awt.Toolkit; 
     8import java.awt.datatransfer.DataFlavor; 
     9import java.awt.datatransfer.Transferable; 
     10import java.awt.datatransfer.UnsupportedFlavorException; 
    711import java.awt.event.ActionEvent; 
    812import java.awt.event.ActionListener; 
    … …  
    1115import java.awt.event.KeyEvent; 
    1216import java.awt.event.KeyListener; 
     17import java.io.IOException; 
    1318 
    1419import javax.swing.Box; 
    … …  
    2126import javax.swing.border.Border; 
    2227import javax.swing.border.EmptyBorder; 
     28import javax.swing.text.BadLocationException; 
    2329 
    2430import tree.IAttributeSaver; 
    … …  
    6268                toolBarButtonBorder = new EmptyBorder(spacing,spacing,spacing,spacing); 
    6369                toolBarBox = Box.createHorizontalBox(); 
     70                 
     71                /* 
     72                 * Paste button to paste clip-board text into the EditorPane.  
     73                 * The system Paste (Control-V) doesn't work when pasting text from 
     74                 * a word document, perhaps because it contains unknown characters. 
     75                 * NB. formatting is lost in this process.  
     76                 */ 
     77                Icon pasteIcon = ImageFactory.getInstance().getIcon(ImageFactory.PASTE_ICON); 
     78                JButton pasteButton = new JButton(pasteIcon); 
     79                pasteButton.setToolTipText("Paste Text"); 
     80                pasteButton.addActionListener(new ActionListener() { 
     81                        public void actionPerformed(ActionEvent e) { 
     82                                 
     83                        Transferable t = Toolkit.getDefaultToolkit(). 
     84                                getSystemClipboard().getContents(null); 
     85                     
     86                        try { 
     87                            if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { 
     88                                String text = (String)t.getTransferData(DataFlavor.stringFlavor); 
     89                                int offset = editorPane.getCaretPosition(); 
     90                                editorPane.getDocument().insertString(offset, text, null); 
     91                            } 
     92                        } catch (UnsupportedFlavorException ex) { 
     93                        } catch (IOException ex) { 
     94                        } catch (BadLocationException ex) { 
     95                                        // TODO Auto-generated catch block 
     96                                        ex.printStackTrace(); 
     97                                }     
     98                        } 
     99                } 
     100                ); 
     101                pasteButton.setBorder(toolBarButtonBorder); 
     102                toolBarBox.add(pasteButton); 
     103                 
    64104                 
    65105                Icon bulletPointsIcon = ImageFactory.getInstance().getIcon(ImageFactory.BULLET_POINTS_ICON);  
    … …  
    85125                underlineButton.setBorder(toolBarButtonBorder); 
    86126                toolBarBox.add(underlineButton); 
     127                 
     128 
    87129                 
    88130                JPanel topPanel = new JPanel(new BorderLayout()); 

Download in other formats:

  • Unified Diff
  • Zip Archive

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/