Module: SwingParadise

Included in:
BaseModule, QuitButtonExample, TextAreaExample
Defined in:
lib/swing_paradise/misc/misc.rb,
lib/swing_paradise/awt/color.rb,
lib/swing_paradise/version/version.rb,
lib/swing_paradise/toplevel_methods/misc.rb,
lib/swing_paradise/base_module/base_module.rb,
lib/swing_paradise/examples/002_text_area_example.rb,
lib/swing_paradise/examples/003_combo_box_example.rb,
lib/swing_paradise/examples/001_quit_button_example.rb

Overview

#

require ‘swing_paradise/toplevel_methods/misc.rb’ include SwingParadise

#

Defined Under Namespace

Modules: AWT, BaseModule Classes: ComboBoxExample, QuitButtonExample, TextAreaExample

Constant Summary collapse

VERSION =
#

VERSION

#
'0.0.64'
LAST_UDPATE =
#

LAST_UPDATE

#
'02.11.2023'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.remove_html(i) ⇒ Object

#

SwingParadise.remove_html

Usage example:

SwingParadise.remove_html('<one>two</three>')
#


18
19
20
21
22
23
# File 'lib/swing_paradise/toplevel_methods/misc.rb', line 18

def self.remove_html(i)
  i.gsub(
    %r{<[^>]+>},
    ''
  )
end

.text(i = '') ⇒ Object

#

SwingParadise.text

This method will return a JLabel instance.

#


30
31
32
33
# File 'lib/swing_paradise/toplevel_methods/misc.rb', line 30

def self.text(i = '')
  _ = JLabel.new(i)
  return _
end

Instance Method Details

#jcombobox(i = nil) ⇒ Object

#

jcombobox

#


66
67
68
69
70
71
72
73
74
# File 'lib/swing_paradise/toplevel_methods/misc.rb', line 66

def jcombobox(i = nil)
  combo_box = JComboBox.new
  if i and i.respond_to?(:each)
    i.each {|this_exam_topic|
      combo_box.addItem(this_exam_topic)
    }
  end
  return combo_box
end

#jframe(i = '') ⇒ Object Also known as: frame

#

jframe

#


22
23
24
# File 'lib/swing_paradise/misc/misc.rb', line 22

def jframe(i = '')
  JFrame.new(i)
end

#jruby_font(i = 'Sans serif 28') ⇒ Object Also known as: font

#

jruby_font

This method should be equivalent to:

Font.new('Sans serif', Font::PLAIN, 28)

Usage example:

LARGE_FONT = jruby_font('Sans serif 28')
#


47
48
49
50
51
52
# File 'lib/swing_paradise/toplevel_methods/misc.rb', line 47

def jruby_font(i = 'Sans serif 28')
  splitted = i.split(' ') # i = 'Monospace 25'; splitted = i.split(' ')
  type = Font::PLAIN
  font_size = splitted.last.to_i
  return Font.new(splitted[0 .. -2].join(' '), type, font_size)
end

#jtextview(i = '') ⇒ Object Also known as: text_view, textview

#

jtextview

JTextArea is the one for multi-line input.

#


14
15
16
# File 'lib/swing_paradise/misc/misc.rb', line 14

def jtextview(i = '')
  JTextArea.new(i)
end

#quit_buttonObject

#

quit_button

This method can be used to quickly create a quit-button.

#


95
96
97
98
99
100
101
# File 'lib/swing_paradise/toplevel_methods/misc.rb', line 95

def quit_button
  _ = jbutton('Quit')
  _.on_event {|event|
    System.exit(0)
  }
  return _
end

#show_message_dialog(text = '') ⇒ Object

#

show_message_dialog

#


86
87
88
# File 'lib/swing_paradise/toplevel_methods/misc.rb', line 86

def show_message_dialog(text = '')
  javax.swing.JOptionPane.showMessageDialog(nil, text)
end

#swing_dimension(new_width, new_height) ⇒ Object

#

swing_dimension

This is a slight wrapper over java.awt.Dimension.

#


59
60
61
# File 'lib/swing_paradise/toplevel_methods/misc.rb', line 59

def swing_dimension(new_width, new_height)
  java.awt.Dimension.new(new_width, new_height)
end

#text(i = '') ⇒ Object Also known as: jtext

#

text

#


79
80
81
# File 'lib/swing_paradise/toplevel_methods/misc.rb', line 79

def text(i = '')
  return JLabel.new(i)
end