Module: SwingParadise::BaseModule
Overview
SwingParadise::BaseModule
Constant Summary
LAST_UDPATE, VERSION
Instance Method Summary
collapse
-
#bold_text(i = '') ⇒ Object
(also: #bold_label)
# === bold_text ========================================================================= #.
-
#combo_box(optional_array = nil) ⇒ Object
# === combo_box.
-
#commandline_arguments? ⇒ Boolean
# === commandline_arguments? ========================================================================= #.
-
#create_boxlayout(i, use_this_axis = BoxLayout::PAGE_AXIS) ⇒ Object
(also: #new_boxlayout)
# === create_boxlayout.
-
#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(&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
# === 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 ========================================================================= #.
-
#set_commandline_arguments(i = '') ⇒ Object
# === set_commandline_arguments ========================================================================= #.
-
#text(i = '') ⇒ Object
(also: #label)
# === text ========================================================================= #.
-
#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
368
369
370
371
372
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 368
def bold_text(i = '')
_ = ::SwingParadise.text(i)
make_bold(_)
return _
end
|
#combo_box(optional_array = nil) ⇒ Object
#
combo_box
You can pass an Array to this method; ideally an Array of Strings.
#
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 113
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?
#
78
79
80
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 78
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)
#
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 444
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
|
#default_close ⇒ Object
92
93
94
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 92
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.
#
142
143
144
145
146
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 142
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
99
100
101
102
103
104
105
106
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 99
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.
#
275
276
277
278
279
280
281
282
283
284
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 275
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?
85
86
87
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 85
def first_argument?
@commandline_arguments.first
end
|
#hbox ⇒ Object
Also known as:
create_hbox
390
391
392
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 390
def hbox
Box.createHorizontalBox
end
|
#infer_the_namespace ⇒ Object
#
infer_the_namespace
This will assume the true namespace from the inspectable name.
#
333
334
335
336
337
338
339
340
341
342
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 333
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
@internal_hash[:namespace] = _ end
|
#is_visible ⇒ Object
213
214
215
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 213
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)
#
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 311
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
|
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 220
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
406
407
408
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 406
def jlabel(i = '')
JLabel.new(i)
end
|
#jpanel(&block) ⇒ Object
Also known as:
create_panel, new_panel
#
jpanel
Usage example:
panel = create_panel { :left }
#
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 254
def jpanel(&block)
_ = JPanel.new
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.
#
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 181
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
413
414
415
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 413
def jtextarea
JTextArea.new
end
|
#make_bold(i) ⇒ Object
377
378
379
380
381
382
383
384
385
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 377
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
347
348
349
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 347
def namespace?
@internal_hash[:namespace]
end
|
#password_field(i = '') ⇒ Object
291
292
293
294
295
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 291
def password_field(
i = ''
)
JPasswordField.new(i)
end
|
129
130
131
132
133
134
135
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 129
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
#
354
355
356
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 354
def reset_the_internal_hash
@internal_hash = {}
end
|
#return_pwd ⇒ Object
420
421
422
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 420
def return_pwd
(Dir.pwd+'/').squeeze('/')
end
|
#set_commandline_arguments(i = '') ⇒ Object
#
set_commandline_arguments
#
70
71
72
73
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 70
def set_commandline_arguments(i = '')
i = [i].flatten.compact
@commandline_arguments = i
end
|
#text(i = '') ⇒ Object
Also known as:
label
361
362
363
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 361
def text(i = '')
::SwingParadise.text(i)
end
|
#use_jruby? ⇒ Boolean
170
171
172
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 170
def use_jruby?
true
end
|
#vbox ⇒ Object
Also known as:
create_vbox
399
400
401
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 399
def vbox
Box.createVerticalBox
end
|
#word_wrap(text, line_width = 75) ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/swing_paradise/base_module/base_module.rb', line 151
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
|