Class: ClipboardHelper
- Inherits:
-
Object
- Object
- ClipboardHelper
- Includes:
- ClipboardOwner
- Defined in:
- lib/life_game_viewer/view/clipboard_helper.rb
Overview
Simplifies the use of the system clipboard access via Java.
Class Method Summary collapse
- .clipboard ⇒ Object
- .clipboard_text ⇒ Object
- .clipboard_text=(text) ⇒ Object
-
.copy_key_name ⇒ Object
Name of copy key for this OS.
-
.input_action_key(action_name) ⇒ Object
Gets the first Action object associated with the passed action_name.
-
.key_prefix ⇒ Object
For getting descriptive text for, e.g.
- .lostOwnership(clipboard, contents) ⇒ Object
- .mac_os? ⇒ Boolean
-
.paste_key_name ⇒ Object
Name of paste key for this OS.
Class Method Details
.clipboard ⇒ Object
12 13 14 |
# File 'lib/life_game_viewer/view/clipboard_helper.rb', line 12 def self.clipboard Toolkit.default_toolkit.system_clipboard end |
.clipboard_text ⇒ Object
16 17 18 19 |
# File 'lib/life_game_viewer/view/clipboard_helper.rb', line 16 def self.clipboard_text transferable = clipboard.getContents(self) transferable.getTransferData(DataFlavor::stringFlavor) end |
.clipboard_text=(text) ⇒ Object
21 22 23 24 |
# File 'lib/life_game_viewer/view/clipboard_helper.rb', line 21 def self.clipboard_text=(text) string_selection = StringSelection.new(text) clipboard.setContents(string_selection, self) end |
.copy_key_name ⇒ Object
Name of copy key for this OS.
42 43 44 |
# File 'lib/life_game_viewer/view/clipboard_helper.rb', line 42 def self.copy_key_name input_action_key("copy-to-clipboard").to_string end |
.input_action_key(action_name) ⇒ Object
Gets the first Action object associated with the passed action_name.
36 37 38 39 |
# File 'lib/life_game_viewer/view/clipboard_helper.rb', line 36 def self.input_action_key(action_name) map = UIManager.get("TextField.focusInputMap") map.keys.select { |key| map.get(key) == action_name }.first end |
.key_prefix ⇒ Object
For getting descriptive text for, e.g. tooltips.
31 32 33 |
# File 'lib/life_game_viewer/view/clipboard_helper.rb', line 31 def self.key_prefix mac_os? ? "Command" : "Ctrl" end |
.lostOwnership(clipboard, contents) ⇒ Object
51 52 53 54 |
# File 'lib/life_game_viewer/view/clipboard_helper.rb', line 51 def self.lostOwnership(clipboard, contents) # do nothing; this method called by Java when this object loses ownership # of the clipboard. end |
.mac_os? ⇒ Boolean
26 27 28 |
# File 'lib/life_game_viewer/view/clipboard_helper.rb', line 26 def self.mac_os? /^Mac/ === java.lang.System.properties['os.name'] end |
.paste_key_name ⇒ Object
Name of paste key for this OS.
47 48 49 |
# File 'lib/life_game_viewer/view/clipboard_helper.rb', line 47 def self.paste_key_name input_action_key("paste-from-clipboard").to_string end |