Sha256: f6b596e5c78639828d4463350e113094e36c566409e750a60412d6f4ff83449d

Contents?: true

Size: 863 Bytes

Versions: 5

Compression:

Stored size: 863 Bytes

Contents

require 'java'

class RubyClip
  import java.awt.datatransfer.StringSelection;
  import java.awt.Toolkit;

  include java.awt.datatransfer.ClipboardOwner
  
  def self.set_clipboard to_this
    stringSelection = StringSelection.new( to_this.to_s )
    clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
    clipboard.setContents( stringSelection, self );
  end
  
  def self.lostOwnership(aClipboard, aContents) 
     # ignore...
  end
  
  def self.get_clipboard_contents
     clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
     data = clipboard.get_contents self
     data.getTransferData java.awt.datatransfer.DataFlavor::stringFlavor
  end
  
end

if $0 == __FILE__
  RubyClip.set_clipboard "from jruby1"
  puts 'set clipboard contents...'
  RubyClip.set_clipboard "from jruby2"
  RubyClip.set_clipboard "from jruby3"
  STDIN.getc
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
simple_gui_creator-0.2.0 lib/simple_gui_creator/ruby_clip.rb
simple_gui_creator-0.1.4 lib/simple_gui_creator/ruby_clip.rb
simple_gui_creator-0.1.3 lib/simple_gui_creator/ruby_clip.rb
simple_gui_creator-0.1.2 lib/simple_gui_creator/ruby_clip.rb
simple_gui_creator-0.1.0 lib/simple_gui_creator/ruby_clip.rb