Module: SwingParadise::BaseModule
Overview
SwingParadise::BaseModule
Constant Summary
LAST_UDPATE, VERSION
Instance Method Summary
collapse
-
#bold_text(i = '') ⇒ Object
(also: #bold_label)
# === bold_text ========================================================================= #.
-
#checkbox(i = '') ⇒ Object
(also: #jcheckbox, #create_checkbox)
# === checkbox ========================================================================= #.
-
#combo_box(optional_array = nil) ⇒ Object
(also: #create_combo_box)
# === combo_box.
-
#commandline_arguments? ⇒ Boolean
# === commandline_arguments? ========================================================================= #.
-
#create_boxlayout(i, use_this_axis = BoxLayout::PAGE_AXIS) ⇒ Object
(also: #new_boxlayout)
# === create_boxlayout.
-
#create_grid(argument1 = 3, argument2 = 3) ⇒ Object
# === create_grid (grid tag) ========================================================================= #.
-
#default_close ⇒ Object
# === default_close ========================================================================= #.
-
#do_quit(use_this_as_the_exit_code = 0) ⇒ Object
# === do_quit.
-
#empty_border(a = 2, b = 2, c = 2, d = 2) ⇒ Object
# === empty_border ========================================================================= #.
-
#entry(i = '', optional_size = nil) ⇒ Object
(also: #hcentered_entry, #create_entry, #text_field)
# === entry.
-
#first_argument? ⇒ Boolean
(also: #first?)
# === first_argument? ========================================================================= #.
-
#hbox ⇒ Object
(also: #create_hbox)
# === hbox (hbox tag) ========================================================================= #.
-
#infer_the_namespace ⇒ Object
# === infer_the_namespace.
-
#is_visible ⇒ Object
# === is_visible ========================================================================= #.
-
#java_colour(use_this_symbol = :steelblue) ⇒ Object
(also: #java_color)
# === java_colour.
-
#jbutton(i = '', &block) ⇒ Object
(also: #button, #bold_button)
-
#jlabel(i = '') ⇒ Object
# === jlabel ========================================================================= #.
-
#jpanel(optional_layout_to_use = nil, &block) ⇒ Object
(also: #create_panel, #new_panel)
# === jpanel.
-
#jscroll_pane(child_widget, vertical_scrollbar_policy = :vertical_always, horizontal_scrollbar_policy = :horizontal_never) ⇒ Object
(also: #scroll_pane, #scrollpane, #scrolled_window, #scrolling)
-
#jtextarea ⇒ Object
(also: #create_textarea)
# === jtextarea ========================================================================= #.
-
#make_bold(i) ⇒ Object
# === make_bold ========================================================================= #.
-
#namespace? ⇒ Boolean
# === namespace? ========================================================================= #.
-
#password_field(i = '') ⇒ Object
# === password_field ========================================================================= #.
-
#quit_button(use_this_text = 'Quit') ⇒ Object
-
#reset_the_internal_hash ⇒ Object
# === reset_the_internal_hash ========================================================================= #.
-
#return_pwd ⇒ Object
# === return_pwd ========================================================================= #.
-
#right_aligned_label(i = '') ⇒ Object
# === right_aligned_label.
-
#set_commandline_arguments(i = '') ⇒ Object
# === set_commandline_arguments ========================================================================= #.
-
#text(i = '') ⇒ Object
(also: #label)
# === text ========================================================================= #.
-
#this_file_was_not_found(i) ⇒ Object
(also: #no_file_exists_at, #no_file_was_found_at)
# === this_file_was_not_found.
-
#use_jruby? ⇒ Boolean
# === use_jruby? ========================================================================= #.
-
#vbox ⇒ Object
(also: #create_vbox)
# === vbox.
-
#word_wrap(text, line_width = 75) ⇒ Object
# === word_wrap ========================================================================= #.
#jcombobox, #jframe, #jruby_font, #jtextview, remove_html, #show_message_dialog, #swing_dimension, text
Instance Method Details
#bold_text(i = '') ⇒ Object
Also known as:
bold_label
325
326
327
328
329
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 325
def bold_text(i = '')
_ = ::SwingParadise.text(i)
make_bold(_)
return _
end
|
#checkbox(i = '') ⇒ Object
Also known as:
jcheckbox, create_checkbox
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 447
def checkbox(i = '')
if i.is_a? Symbol
case i
when :is_checked
_ = JCheckBox.new
_.setSelected(true)
end
else
_ = JCheckBox.new(i)
end
return _
end
|
#combo_box(optional_array = nil) ⇒ Object
Also known as:
create_combo_box
#
combo_box
You can pass an Array to this method; ideally an Array of Strings.
#
543
544
545
546
547
548
549
550
551
552
553
554
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 543
def combo_box(
optional_array = nil
)
_ = JComboBox.new
if optional_array and optional_array.is_a?(Array) and !optional_array.empty?
optional_array.each {|this_item|
_.addItem(this_item)
}
_.setSelectedIndex(0) end
return _
end
|
#commandline_arguments? ⇒ Boolean
#
commandline_arguments?
#
81
82
83
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 81
def commandline_arguments?
@commandline_arguments
end
|
#create_boxlayout(i, use_this_axis = BoxLayout::PAGE_AXIS) ⇒ Object
Also known as:
new_boxlayout
#
create_boxlayout
BoxLayout in Java resides at javax.swing.BoxLayout.
The first argument to this method should be the panel that contains the child elements.
The second argument can have any of these values:
BoxLayout::X_AXIS
BoxLayout::Y_AXIS
BoxLayout::LINE_AXIS
BoxLayout::PAGE_AXIS
The recommended API for using this method is this:
panel = create_boxlayout(:new_panel)
#
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 394
def create_boxlayout(
i,
use_this_axis = BoxLayout::PAGE_AXIS
)
case i
when :new_panel
i = create_panel
end
case use_this_axis
when :north
use_this_axis = BorderLayout::NORTH
when :west
use_this_axis = BorderLayout::WEST
when :east
use_this_axis = BorderLayout::EAST
when :south
use_this_axis = BorderLayout::SOUTH
end
box_layout = BoxLayout.new(i, use_this_axis)
i.setLayout(box_layout)
return i
end
|
#create_grid(argument1 = 3, argument2 = 3) ⇒ Object
#
create_grid (grid tag)
#
524
525
526
527
528
529
530
531
532
533
534
535
536
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 524
def create_grid(
argument1 = 3,
argument2 = 3
)
if argument1.is_a?(String) and argument1.include?('x')
splitted = argument1.split('x')
argument1 = splitted[0].to_i
argument2 = splitted[1].to_i
end
grid_layout = GridLayout.new(argument1, argument2)
panel = create_panel(grid_layout)
return panel
end
|
#default_close ⇒ Object
95
96
97
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 95
def default_close
setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE)
end
|
#do_quit(use_this_as_the_exit_code = 0) ⇒ Object
#
do_quit
This method can be used as a more convenient do-exit method.
#
127
128
129
130
131
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 127
def do_quit(
use_this_as_the_exit_code = 0
)
System.exit(use_this_as_the_exit_code)
end
|
#empty_border(a = 2, b = 2, c = 2, d = 2) ⇒ Object
102
103
104
105
106
107
108
109
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 102
def empty_border(
a = 2,
b = 2,
c = 2,
d = 2
)
EmptyBorder.new(a, b, c, d)
end
|
#entry(i = '', optional_size = nil) ⇒ Object
Also known as:
hcentered_entry, create_entry, text_field
#
entry
This is simply a wrapper over JTextField.
#
236
237
238
239
240
241
242
243
244
245
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 236
def entry(
i = '',
optional_size = nil
)
if optional_size
JTextField.new(i, optional_size) else
JTextField.new(i)
end
end
|
#first_argument? ⇒ Boolean
Also known as:
first?
88
89
90
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 88
def first_argument?
@commandline_arguments.first
end
|
#hbox ⇒ Object
Also known as:
create_hbox
347
348
349
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 347
def hbox
Box.createHorizontalBox
end
|
#infer_the_namespace ⇒ Object
#
infer_the_namespace
This will assume the true namespace from the inspectable name.
#
294
295
296
297
298
299
300
301
302
303
304
305
306
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 294
def infer_the_namespace
_ = inspect.to_s.delete('<')
if _.include? ' '
_ = _.split(' ').first.delete('#')
if _.include? ':'
_ = _.split(':')[0 .. -2].reject {|entry| entry.empty? }.join('::')
end
end
if @internal_hash.nil?
reset_the_internal_hash
end
@internal_hash[:namespace] = _ end
|
#is_visible ⇒ Object
198
199
200
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 198
def is_visible
setVisible(true)
end
|
#java_colour(use_this_symbol = :steelblue) ⇒ Object
Also known as:
java_color
#
java_colour
This method only works with symbols as input, such as :steelblue or :bisque.
This method depends on the external gem called ‘colours’.
Usage examples:
use_this_colour = java_colour(:bisque)
use_this_colour = java_colour(:steelblue)
#
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 272
def java_colour(
use_this_symbol = :steelblue
)
begin
require 'colours/constants/file_constants.rb'
rescue LoadError; end
_ = ::Colours.file_html_colours
if File.exist? _
dataset = YAML.load_file(_)
if dataset.has_key? use_this_symbol.to_s
pointer = dataset[use_this_symbol.to_s]
return Color.new(pointer[0], pointer[1], pointer[2])
end
end
return nil end
|
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 205
def jbutton(
i = '',
&block
)
button = JButton.new(i)
if block_given?
yielded = yield
if yielded.is_a? Hash
if yielded.has_key? :font
button.use_this_font = yielded.delete(:font)
end
end
end
return button
end
|
#jlabel(i = '') ⇒ Object
363
364
365
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 363
def jlabel(i = '')
JLabel.new(i)
end
|
#jpanel(optional_layout_to_use = nil, &block) ⇒ Object
Also known as:
create_panel, new_panel
#
jpanel
Usage example:
panel = create_panel { :left }
#
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 491
def jpanel(
optional_layout_to_use = nil,
&block
)
if optional_layout_to_use
_ = JPanel.new(optional_layout_to_use)
else
_ = JPanel.new
end
if block_given?
yielded = yield
case yielded
when :left
_.layout = FlowLayout.new(FlowLayout::LEFT)
end
end
return _
end
|
#
A JScrollPane provides a scrollable view of another widget. The JScrollPane manages a viewport, optional vertical and horizontal scroll bars, and optional row and column heading viewports.
#
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 166
def jscroll_pane(
child_widget,
vertical_scrollbar_policy = :vertical_always,
horizontal_scrollbar_policy = :horizontal_never
)
case vertical_scrollbar_policy
when :vertical_always
vertical_scrollbar_policy = Java::JavaxSwing::ScrollPaneConstants::VERTICAL_SCROLLBAR_ALWAYS
end
case horizontal_scrollbar_policy
when :horizontal_never
horizontal_scrollbar_policy = Java::JavaxSwing::ScrollPaneConstants::HORIZONTAL_SCROLLBAR_NEVER
end
JScrollPane.new(
child_widget,
vertical_scrollbar_policy,
horizontal_scrollbar_policy
)
end
|
#jtextarea ⇒ Object
Also known as:
create_textarea
517
518
519
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 517
def jtextarea
JTextArea.new
end
|
#make_bold(i) ⇒ Object
334
335
336
337
338
339
340
341
342
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 334
def make_bold(i)
bold_font = Font.new(
i.getFont.getName,
Font::BOLD,
i.getFont.getSize
)
i.setFont(bold_font)
return i
end
|
#namespace? ⇒ Boolean
311
312
313
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 311
def namespace?
@internal_hash[:namespace]
end
|
#password_field(i = '') ⇒ Object
252
253
254
255
256
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 252
def password_field(
i = ''
)
JPasswordField.new(i)
end
|
114
115
116
117
118
119
120
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 114
def quit_button(
use_this_text = 'Quit'
)
_ = button(use_this_text)
_.on_clicked { do_quit }
return _
end
|
#reset_the_internal_hash ⇒ Object
#
reset_the_internal_hash
#
318
319
320
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 318
def reset_the_internal_hash
@internal_hash = {}
end
|
#return_pwd ⇒ Object
370
371
372
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 370
def return_pwd
(Dir.pwd+'/').squeeze('/')
end
|
#right_aligned_label(i = '') ⇒ Object
#
right_aligned_label
Note that JLabel also has setHorizontalAlignment:
label.setHorizontalAlignment(SwingConstants::RIGHT)
#
479
480
481
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 479
def right_aligned_label(i = '')
return JLabel.new(i, SwingConstants::RIGHT)
end
|
#set_commandline_arguments(i = '') ⇒ Object
#
set_commandline_arguments
#
73
74
75
76
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 73
def set_commandline_arguments(i = '')
i = [i].flatten.compact
@commandline_arguments = i
end
|
#text(i = '') ⇒ Object
Also known as:
label
467
468
469
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 467
def text(i = '')
::SwingParadise.text(i)
end
|
#this_file_was_not_found(i) ⇒ Object
Also known as:
no_file_exists_at, no_file_was_found_at
#
this_file_was_not_found
Use this to notify the user, whenever the open-gem was unable to find a file that was assumed to exist locally.
#
438
439
440
441
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 438
def this_file_was_not_found(i)
e "#{rev}No file called `#{sfile(i)}` was found. It "\
"is assumed to not exist."
end
|
#use_jruby? ⇒ Boolean
155
156
157
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 155
def use_jruby?
true
end
|
#vbox ⇒ Object
Also known as:
create_vbox
356
357
358
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 356
def vbox
Box.createVerticalBox
end
|
#word_wrap(text, line_width = 75) ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 136
def word_wrap(
text,
line_width = 75
)
if line_width.is_a? Hash
if line_width.has_key? :threshold
line_width = line_width.delete(:threshold)
end
end
result = text.scan(/\S.{0,#{line_width}}\S(?=\s|$)|\S+/).join(N)
return result
end
|