Class: RPV::Swing::SwingSet::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/rpv/swing/swingset.rb

Overview

Proxies missing methods to java.awt.Color

Color.white #=> java.awt.Color.white

And constructs colors from hex values

Color.00ff00 #=> Color[0, 255, 0]
Color.11f #=> Color[16, 16, 240]

Class Method Summary collapse

Class Method Details

.[](red, green, blue) ⇒ Object

Constructs a new java.awt.Color object from the given RGB values



79
80
81
# File 'lib/rpv/swing/swingset.rb', line 79

def self.[](red, green, blue)
  Java::java.awt.Color.new red.to_i, green.to_i, blue.to_i
end

.method_missing(name) ⇒ Object

:no_doc:



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rpv/swing/swingset.rb', line 83

def self.method_missing(name) #:no_doc:
  if Java::java.awt.Color.respond_to? name
    Java::java.awt.Color.send(name)
  else
    name = name.to_s
    if name.size == 6
      r, g, b = name[0..1].hex, name[2..3].hex, name[4..5].hex
    elsif name.size == 3
      r, g, b = name[0..0].hex * 16, name[1..1].hex * 16, name[2..2].hex * 16
    else
      raise NoMethodError, "no method #{name} on Color"
    end
    Color[r, g, b]
  end
end