swing_paradise 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of swing_paradise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/README.md +1557 -0
- data/doc/README.gen +1510 -0
- data/lib/swing_paradise/autoinclude.rb +3 -0
- data/lib/swing_paradise/awt/README.md +1 -0
- data/lib/swing_paradise/awt/color.rb +45 -0
- data/lib/swing_paradise/base_module/base_module.rb +993 -0
- data/lib/swing_paradise/classes +1 -0
- data/lib/swing_paradise/examples/001_quit_button_example.rb +55 -0
- data/lib/swing_paradise/examples/002_text_area_example.rb +55 -0
- data/lib/swing_paradise/examples/003_combo_box_example.rb +57 -0
- data/lib/swing_paradise/examples/004_jpanel_left_bound_example.rb +41 -0
- data/lib/swing_paradise/examples/005_box_layout_example.rb +39 -0
- data/lib/swing_paradise/examples/006_frame_example.rb +33 -0
- data/lib/swing_paradise/examples/007_textarea_responding_to_enter_key_example.rb +28 -0
- data/lib/swing_paradise/examples/008_scrolled_window_example.rb +41 -0
- data/lib/swing_paradise/examples/009_font_size_example.rb +39 -0
- data/lib/swing_paradise/examples/010_counter_example.rb +183 -0
- data/lib/swing_paradise/examples/011_button_with_image_example.rb +58 -0
- data/lib/swing_paradise/examples/012_quit_on_escape_key_being_pressed.rb +37 -0
- data/lib/swing_paradise/examples/013_simple_box_example.rb +38 -0
- data/lib/swing_paradise/examples/014_mouse_events_example.rb +41 -0
- data/lib/swing_paradise/examples/015_menu_example.rb +77 -0
- data/lib/swing_paradise/examples/016_file_chooser_example.rb +96 -0
- data/lib/swing_paradise/examples/017_buttons_example.rb +56 -0
- data/lib/swing_paradise/examples/018_colour_chooser_example.rb +51 -0
- data/lib/swing_paradise/examples/019_jeditorpane_example.rb +61 -0
- data/lib/swing_paradise/examples/020_table_example.rb +77 -0
- data/lib/swing_paradise/examples/021_jsplitpane_example.rb +66 -0
- data/lib/swing_paradise/examples/022_drawing_oval_example.rb +51 -0
- data/lib/swing_paradise/examples/023_show_message_dialog_example.rb +57 -0
- data/lib/swing_paradise/java_classes/border_factory/border_factory.rb +19 -0
- data/lib/swing_paradise/java_classes/box/box.rb +72 -0
- data/lib/swing_paradise/java_classes/button +1 -0
- data/lib/swing_paradise/java_classes/checkbox +1 -0
- data/lib/swing_paradise/java_classes/combobox +1 -0
- data/lib/swing_paradise/java_classes/default_table_model/default_table_model.rb +18 -0
- data/lib/swing_paradise/java_classes/frame +1 -0
- data/lib/swing_paradise/java_classes/jbutton/jbutton.rb +199 -0
- data/lib/swing_paradise/java_classes/jcheckbox/jcheckbox.rb +28 -0
- data/lib/swing_paradise/java_classes/jcombobox/jcombobox.rb +31 -0
- data/lib/swing_paradise/java_classes/jcomponent/jcomponent.rb +253 -0
- data/lib/swing_paradise/java_classes/jeditorpane/jeditorpane.rb +23 -0
- data/lib/swing_paradise/java_classes/jfilechooser/jfilechooser.rb +22 -0
- data/lib/swing_paradise/java_classes/jframe/jframe.rb +319 -0
- data/lib/swing_paradise/java_classes/jlabel/jlabel.rb +171 -0
- data/lib/swing_paradise/java_classes/jmenu/jmenu.rb +13 -0
- data/lib/swing_paradise/java_classes/jmenubar/jmenubar.rb +13 -0
- data/lib/swing_paradise/java_classes/jpanel/jpanel.rb +115 -0
- data/lib/swing_paradise/java_classes/jscrollpane/jscrollpane.rb +84 -0
- data/lib/swing_paradise/java_classes/jspinner/jspinner.rb +17 -0
- data/lib/swing_paradise/java_classes/jtextarea/jtextarea.rb +120 -0
- data/lib/swing_paradise/java_classes/jtextfield/jtextfield.rb +314 -0
- data/lib/swing_paradise/java_classes/label +1 -0
- data/lib/swing_paradise/java_classes/panel +1 -0
- data/lib/swing_paradise/java_classes/spinner +1 -0
- data/lib/swing_paradise/java_classes/textarea +1 -0
- data/lib/swing_paradise/misc/misc.rb +57 -0
- data/lib/swing_paradise/prototype/prototype.rb +79 -0
- data/lib/swing_paradise/requires/require_the_project.rb +15 -0
- data/lib/swing_paradise/toplevel_methods/misc.rb +293 -0
- data/lib/swing_paradise/version/version.rb +17 -0
- data/lib/swing_paradise/widget_collection/README.md +2 -0
- data/lib/swing_paradise/widget_collection/text_viewer.rb +160 -0
- data/lib/swing_paradise.rb +1 -0
- data/swing_paradise.gemspec +42 -0
- metadata +120 -0
@@ -0,0 +1,993 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'swing_paradise/base_module/base_module.rb'
|
6
|
+
# include SwingParadise::BaseModule
|
7
|
+
# =========================================================================== #
|
8
|
+
# (import tag, imports tag)
|
9
|
+
# =========================================================================== #
|
10
|
+
java_import java.awt.BorderLayout
|
11
|
+
java_import java.awt.Color
|
12
|
+
java_import java.awt.Component
|
13
|
+
java_import java.awt.Dimension
|
14
|
+
java_import java.awt.Font
|
15
|
+
java_import java.awt.FlowLayout
|
16
|
+
java_import java.awt.Frame
|
17
|
+
java_import java.awt.GradientPaint
|
18
|
+
java_import java.awt.Graphics
|
19
|
+
java_import java.awt.GraphicsEnvironment
|
20
|
+
java_import java.awt.Graphics2D
|
21
|
+
java_import java.awt.GridBagLayout
|
22
|
+
java_import java.awt.GridLayout
|
23
|
+
java_import java.awt.Insets
|
24
|
+
java_import java.awt.Point
|
25
|
+
java_import java.awt.Rectangle
|
26
|
+
java_import java.awt.Toolkit
|
27
|
+
|
28
|
+
# =========================================================================== #
|
29
|
+
# === Events come next - this includes being able to respond to key
|
30
|
+
# events
|
31
|
+
# =========================================================================== #
|
32
|
+
java_import java.awt.event.ActionEvent
|
33
|
+
java_import java.awt.event.ActionListener
|
34
|
+
java_import java.awt.event.KeyListener
|
35
|
+
java_import java.awt.event.KeyAdapter
|
36
|
+
java_import java.awt.event.KeyEvent
|
37
|
+
java_import java.awt.event.MouseAdapter
|
38
|
+
java_import java.awt.event.MouseEvent
|
39
|
+
java_import java.awt.event.WindowAdapter
|
40
|
+
java_import java.awt.event.WindowEvent
|
41
|
+
|
42
|
+
java_import java.lang.System
|
43
|
+
|
44
|
+
# =========================================================================== #
|
45
|
+
# Next javax. components:
|
46
|
+
# =========================================================================== #
|
47
|
+
java_import javax.imageio.ImageIO
|
48
|
+
java_import javax.swing.BorderFactory
|
49
|
+
java_import javax.swing.Box
|
50
|
+
java_import javax.swing.BoxLayout
|
51
|
+
java_import javax.swing.ButtonGroup
|
52
|
+
# java_import javax.swing.event
|
53
|
+
java_import javax.swing.ImageIcon
|
54
|
+
java_import javax.swing.JCheckBox
|
55
|
+
java_import javax.swing.JColorChooser
|
56
|
+
java_import javax.swing.JComboBox
|
57
|
+
java_import javax.swing.JComponent
|
58
|
+
java_import javax.swing.JDialog
|
59
|
+
java_import javax.swing.JEditorPane
|
60
|
+
java_import javax.swing.JFileChooser
|
61
|
+
java_import javax.swing.JFrame
|
62
|
+
java_import javax.swing.JLabel
|
63
|
+
java_import javax.swing.JMenu
|
64
|
+
java_import javax.swing.JMenuBar
|
65
|
+
java_import javax.swing.JMenuItem
|
66
|
+
java_import javax.swing.JTable
|
67
|
+
java_import javax.swing.JTextArea
|
68
|
+
java_import javax.swing.JTextField
|
69
|
+
java_import javax.swing.JPanel
|
70
|
+
java_import javax.swing.JPasswordField
|
71
|
+
java_import javax.swing.JRadioButton
|
72
|
+
java_import javax.swing.JScrollBar
|
73
|
+
java_import javax.swing.JScrollPane
|
74
|
+
java_import javax.swing.JSplitPane
|
75
|
+
java_import javax.swing.SwingConstants
|
76
|
+
java_import javax.swing.SwingUtilities
|
77
|
+
java_import javax.swing.UIManager
|
78
|
+
java_import javax.swing.border.EmptyBorder
|
79
|
+
java_import javax.swing.border.EtchedBorder
|
80
|
+
|
81
|
+
module SwingParadise
|
82
|
+
|
83
|
+
module BaseModule # === SwingParadise::BaseModule
|
84
|
+
|
85
|
+
alias e puts
|
86
|
+
|
87
|
+
require 'swing_paradise/java_classes/border_factory/border_factory.rb'
|
88
|
+
require 'swing_paradise/java_classes/box/box.rb'
|
89
|
+
require 'swing_paradise/java_classes/jbutton/jbutton.rb'
|
90
|
+
require 'swing_paradise/java_classes/jcheckbox/jcheckbox.rb'
|
91
|
+
require 'swing_paradise/java_classes/jcomponent/jcomponent.rb'
|
92
|
+
require 'swing_paradise/java_classes/jcombobox/jcombobox.rb'
|
93
|
+
require 'swing_paradise/java_classes/jeditorpane/jeditorpane.rb'
|
94
|
+
require 'swing_paradise/java_classes/jfilechooser/jfilechooser.rb'
|
95
|
+
require 'swing_paradise/java_classes/jframe/jframe.rb'
|
96
|
+
require 'swing_paradise/java_classes/jlabel/jlabel.rb'
|
97
|
+
require 'swing_paradise/java_classes/jmenu/jmenu.rb'
|
98
|
+
require 'swing_paradise/java_classes/jmenubar/jmenubar.rb'
|
99
|
+
require 'swing_paradise/java_classes/jpanel/jpanel.rb'
|
100
|
+
require 'swing_paradise/java_classes/jscrollpane/jscrollpane.rb'
|
101
|
+
require 'swing_paradise/java_classes/jtextarea/jtextarea.rb'
|
102
|
+
require 'swing_paradise/java_classes/jtextfield/jtextfield.rb'
|
103
|
+
require 'swing_paradise/java_classes/default_table_model/default_table_model.rb'
|
104
|
+
|
105
|
+
require 'swing_paradise/toplevel_methods/misc.rb'
|
106
|
+
require 'swing_paradise/misc/misc.rb'
|
107
|
+
|
108
|
+
include SwingParadise
|
109
|
+
|
110
|
+
require 'fileutils'
|
111
|
+
|
112
|
+
begin
|
113
|
+
require 'colours'
|
114
|
+
include ::Colours
|
115
|
+
rescue LoadError; end
|
116
|
+
|
117
|
+
# ========================================================================= #
|
118
|
+
# === button_with_image
|
119
|
+
#
|
120
|
+
# This is a button with an image (also called an icon).
|
121
|
+
# ========================================================================= #
|
122
|
+
def button_with_image(
|
123
|
+
icon_location = '',
|
124
|
+
optional_text = '',
|
125
|
+
optional_widget_to_have_the_click_action_defined = nil,
|
126
|
+
&block
|
127
|
+
)
|
128
|
+
if icon_location and icon_location.is_a?(String)
|
129
|
+
icon_location = ImageIcon.new(icon_location)
|
130
|
+
end
|
131
|
+
if optional_text and !optional_text.empty?
|
132
|
+
button = JButton.new(optional_text, icon_location)
|
133
|
+
else
|
134
|
+
button = JButton.new(icon_location)
|
135
|
+
end
|
136
|
+
# ======================================================================= #
|
137
|
+
# === Handle blocks given to this method next
|
138
|
+
# ======================================================================= #
|
139
|
+
if block_given?
|
140
|
+
yielded = yield
|
141
|
+
# ===================================================================== #
|
142
|
+
# === Handle Hashes next
|
143
|
+
# ===================================================================== #
|
144
|
+
if yielded.is_a? Hash
|
145
|
+
# =================================================================== #
|
146
|
+
# === :font
|
147
|
+
# =================================================================== #
|
148
|
+
if yielded.has_key? :font
|
149
|
+
button.use_this_font = yielded.delete(:font)
|
150
|
+
end
|
151
|
+
else
|
152
|
+
button.on_clicked {
|
153
|
+
if optional_widget_to_have_the_click_action_defined
|
154
|
+
optional_widget_to_have_the_click_action_defined.send(yielded.to_sym)
|
155
|
+
else
|
156
|
+
send(yielded.to_sym)
|
157
|
+
end
|
158
|
+
}
|
159
|
+
end
|
160
|
+
end
|
161
|
+
return button
|
162
|
+
end
|
163
|
+
|
164
|
+
# ========================================================================= #
|
165
|
+
# === jbutton (button tag)
|
166
|
+
#
|
167
|
+
# This method can be used to create a new button, aka a jbutton in
|
168
|
+
# java-swing parlance.
|
169
|
+
# ========================================================================= #
|
170
|
+
def jbutton(
|
171
|
+
i = '',
|
172
|
+
optional_widget_to_have_the_click_action_defined = nil,
|
173
|
+
&block
|
174
|
+
)
|
175
|
+
button = JButton.new(i)
|
176
|
+
# ======================================================================= #
|
177
|
+
# === Handle blocks given to this method next
|
178
|
+
# ======================================================================= #
|
179
|
+
if block_given?
|
180
|
+
yielded = yield
|
181
|
+
# ===================================================================== #
|
182
|
+
# === Handle Hashes next
|
183
|
+
# ===================================================================== #
|
184
|
+
if yielded.is_a? Hash
|
185
|
+
# =================================================================== #
|
186
|
+
# === :font
|
187
|
+
# =================================================================== #
|
188
|
+
if yielded.has_key? :font
|
189
|
+
button.use_this_font = yielded.delete(:font)
|
190
|
+
end
|
191
|
+
else
|
192
|
+
button.on_clicked {
|
193
|
+
if optional_widget_to_have_the_click_action_defined
|
194
|
+
optional_widget_to_have_the_click_action_defined.send(yielded.to_sym)
|
195
|
+
else
|
196
|
+
send(yielded.to_sym)
|
197
|
+
end
|
198
|
+
}
|
199
|
+
end
|
200
|
+
end
|
201
|
+
return button
|
202
|
+
end; alias button jbutton # === button
|
203
|
+
alias create_button jbutton # === create_button
|
204
|
+
|
205
|
+
# ========================================================================= #
|
206
|
+
# === radio_button
|
207
|
+
# ========================================================================= #
|
208
|
+
def radio_button(
|
209
|
+
text = '',
|
210
|
+
selected_or_not_selected = false
|
211
|
+
)
|
212
|
+
case selected_or_not_selected
|
213
|
+
# ======================================================================= #
|
214
|
+
# === :is_selected
|
215
|
+
# ======================================================================= #
|
216
|
+
when :is_selected
|
217
|
+
selected_or_not_selected = true
|
218
|
+
end
|
219
|
+
JRadioButton.new(text, selected_or_not_selected)
|
220
|
+
end; alias radiobutton radio_button # === radiobutton
|
221
|
+
alias jradio_button radio_button # === jradio_button
|
222
|
+
|
223
|
+
# ========================================================================= #
|
224
|
+
# === bold_button
|
225
|
+
# ========================================================================= #
|
226
|
+
def bold_button(
|
227
|
+
i = '',
|
228
|
+
optional_widget_to_have_the_click_action_defined = nil,
|
229
|
+
&block
|
230
|
+
)
|
231
|
+
_ = create_button(i, optional_widget_to_have_the_click_action_defined, &block)
|
232
|
+
_.setFont(_.getFont.deriveFont(Font::BOLD))
|
233
|
+
return _
|
234
|
+
end
|
235
|
+
|
236
|
+
# ========================================================================= #
|
237
|
+
# === quit_button
|
238
|
+
# ========================================================================= #
|
239
|
+
def quit_button(
|
240
|
+
use_this_text = 'Quit'
|
241
|
+
)
|
242
|
+
_ = button(use_this_text)
|
243
|
+
_.on_clicked { do_quit }
|
244
|
+
return _
|
245
|
+
end
|
246
|
+
|
247
|
+
# ========================================================================= #
|
248
|
+
# === esystem
|
249
|
+
# ========================================================================= #
|
250
|
+
def esystem(i = '')
|
251
|
+
e i; system i
|
252
|
+
end
|
253
|
+
|
254
|
+
# ========================================================================= #
|
255
|
+
# === cpr
|
256
|
+
#
|
257
|
+
# This is recursive copy.
|
258
|
+
# ========================================================================= #
|
259
|
+
def cpr(
|
260
|
+
from = return_pwd,
|
261
|
+
to = '.'
|
262
|
+
)
|
263
|
+
FileUtils.cp_r(from, to, verbose: true)
|
264
|
+
end
|
265
|
+
|
266
|
+
# ========================================================================= #
|
267
|
+
# === defaul_table_model
|
268
|
+
# ========================================================================= #
|
269
|
+
def defaul_table_model(
|
270
|
+
first_argument = nil,
|
271
|
+
optional_columns = nil
|
272
|
+
)
|
273
|
+
if optional_columns
|
274
|
+
javax.swing.table.DefaultTableModel.new(first_argument, optional_columns)
|
275
|
+
else
|
276
|
+
javax.swing.table.DefaultTableModel.new
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
# ========================================================================= #
|
281
|
+
# === jscroll_pane
|
282
|
+
#
|
283
|
+
# A JScrollPane provides a scrollable view of another widget. The
|
284
|
+
# JScrollPane manages a viewport, optional vertical and horizontal
|
285
|
+
# scroll bars, and optional row and column heading viewports.
|
286
|
+
# ========================================================================= #
|
287
|
+
def jscroll_pane(
|
288
|
+
child_widget,
|
289
|
+
vertical_scrollbar_policy = :vertical_always,
|
290
|
+
horizontal_scrollbar_policy = :default
|
291
|
+
)
|
292
|
+
case vertical_scrollbar_policy
|
293
|
+
# ======================================================================= #
|
294
|
+
# === :vertical_always
|
295
|
+
# ======================================================================= #
|
296
|
+
when :vertical_always
|
297
|
+
vertical_scrollbar_policy = Java::JavaxSwing::ScrollPaneConstants::VERTICAL_SCROLLBAR_ALWAYS
|
298
|
+
end
|
299
|
+
case horizontal_scrollbar_policy
|
300
|
+
# ======================================================================= #
|
301
|
+
# === :default
|
302
|
+
# ======================================================================= #
|
303
|
+
when :default
|
304
|
+
horizontal_scrollbar_policy = Java::JavaxSwing::ScrollPaneConstants::HORIZONTAL_SCROLLBAR_ALWAYS
|
305
|
+
# ======================================================================= #
|
306
|
+
# === :horizontal_never
|
307
|
+
# ======================================================================= #
|
308
|
+
when :horizontal_never
|
309
|
+
horizontal_scrollbar_policy = Java::JavaxSwing::ScrollPaneConstants::HORIZONTAL_SCROLLBAR_NEVER
|
310
|
+
end
|
311
|
+
JScrollPane.new(
|
312
|
+
child_widget,
|
313
|
+
vertical_scrollbar_policy,
|
314
|
+
horizontal_scrollbar_policy
|
315
|
+
)
|
316
|
+
end; alias scroll_pane jscroll_pane # === scroll_pane
|
317
|
+
alias scrollpane jscroll_pane # === scrollpane
|
318
|
+
alias scrolled_window jscroll_pane # === scrolled_window
|
319
|
+
alias scrolling jscroll_pane # === scrolling
|
320
|
+
alias created_scrolled_window jscroll_pane # === created_scrolled_window
|
321
|
+
alias create_scrolled_window jscroll_pane # === create_scrolled_window
|
322
|
+
alias default_scroll_pane jscroll_pane # === default_scroll_pane
|
323
|
+
|
324
|
+
# ========================================================================= #
|
325
|
+
# === create_file_chooser
|
326
|
+
# ========================================================================= #
|
327
|
+
def create_file_chooser
|
328
|
+
JFileChooser.new
|
329
|
+
end
|
330
|
+
|
331
|
+
# ========================================================================= #
|
332
|
+
# === vbox
|
333
|
+
#
|
334
|
+
# A vertical box.
|
335
|
+
# ========================================================================= #
|
336
|
+
def vbox
|
337
|
+
javax.swing.Box.createVerticalBox
|
338
|
+
end; alias create_vbox vbox # === create_vbox
|
339
|
+
|
340
|
+
# ========================================================================= #
|
341
|
+
# === has_the_enter_key_been_pressed?
|
342
|
+
#
|
343
|
+
# This method assumes that a java-swing event was passed as argument.
|
344
|
+
# ========================================================================= #
|
345
|
+
def has_the_enter_key_been_pressed?(event)
|
346
|
+
event.getKeyCode == KeyEvent::VK_ESCAPE
|
347
|
+
end
|
348
|
+
|
349
|
+
# ========================================================================= #
|
350
|
+
# === entry
|
351
|
+
#
|
352
|
+
# This is simply a wrapper over JTextField.
|
353
|
+
# ========================================================================= #
|
354
|
+
def entry(
|
355
|
+
i = '',
|
356
|
+
optional_size = nil
|
357
|
+
)
|
358
|
+
if optional_size
|
359
|
+
JTextField.new(i, optional_size) # This is similar to e. g. JTextField.new("", 20).
|
360
|
+
else
|
361
|
+
JTextField.new(i)
|
362
|
+
end
|
363
|
+
end; alias hcentered_entry entry # === hcentered_entry
|
364
|
+
alias create_entry entry # === create_entry
|
365
|
+
alias text_field entry # === text_field
|
366
|
+
alias jtextfield entry # === jtextfield
|
367
|
+
alias create_textfield entry # === create_textfield
|
368
|
+
|
369
|
+
# ========================================================================= #
|
370
|
+
# === default_close
|
371
|
+
# ========================================================================= #
|
372
|
+
def default_close
|
373
|
+
setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE)
|
374
|
+
end
|
375
|
+
|
376
|
+
# ========================================================================= #
|
377
|
+
# === create_window_or_runner
|
378
|
+
# ========================================================================= #
|
379
|
+
def create_window_or_runner(
|
380
|
+
optional_widget = nil
|
381
|
+
)
|
382
|
+
frame = SwingParadise.create_frame(internal_width?, internal_height?)
|
383
|
+
if optional_widget
|
384
|
+
frame.add(optional_widget)
|
385
|
+
end
|
386
|
+
return frame
|
387
|
+
end; alias create_window create_window_or_runner # === create_window
|
388
|
+
|
389
|
+
# ========================================================================= #
|
390
|
+
# === empty_border
|
391
|
+
# ========================================================================= #
|
392
|
+
def empty_border(
|
393
|
+
a = 2, # This is the primary value - the most important value.
|
394
|
+
b = :default,
|
395
|
+
c = :default,
|
396
|
+
d = :default
|
397
|
+
)
|
398
|
+
if b == :default
|
399
|
+
b = a
|
400
|
+
end
|
401
|
+
if c == :default
|
402
|
+
c = a
|
403
|
+
end
|
404
|
+
if d == :default
|
405
|
+
d = a
|
406
|
+
end
|
407
|
+
EmptyBorder.new(a, b, c, d)
|
408
|
+
end
|
409
|
+
|
410
|
+
# ========================================================================= #
|
411
|
+
# === do_quit
|
412
|
+
#
|
413
|
+
# This method can be used as a more convenient do-exit method.
|
414
|
+
# ========================================================================= #
|
415
|
+
def do_quit(
|
416
|
+
use_this_as_the_exit_code = 0
|
417
|
+
)
|
418
|
+
System.exit(use_this_as_the_exit_code)
|
419
|
+
end
|
420
|
+
|
421
|
+
# ========================================================================= #
|
422
|
+
# === word_wrap
|
423
|
+
# ========================================================================= #
|
424
|
+
def word_wrap(
|
425
|
+
text,
|
426
|
+
line_width = 75
|
427
|
+
)
|
428
|
+
if line_width.is_a? Hash
|
429
|
+
# ===================================================================== #
|
430
|
+
# === :threshold
|
431
|
+
# ===================================================================== #
|
432
|
+
if line_width.has_key? :threshold
|
433
|
+
line_width = line_width.delete(:threshold)
|
434
|
+
end
|
435
|
+
end
|
436
|
+
result = text.scan(/\S.{0,#{line_width}}\S(?=\s|$)|\S+/).join(N)
|
437
|
+
return result
|
438
|
+
end
|
439
|
+
|
440
|
+
# ========================================================================= #
|
441
|
+
# === set_global_font
|
442
|
+
#
|
443
|
+
# This method can be used to set a global font for a jruby-SWING
|
444
|
+
# application.
|
445
|
+
# ========================================================================= #
|
446
|
+
def set_global_font(
|
447
|
+
use_this_font = Font.new('Hack', Font::PLAIN, 40)
|
448
|
+
)
|
449
|
+
SwingParadise.set_global_font(use_this_font)
|
450
|
+
end
|
451
|
+
|
452
|
+
# ========================================================================= #
|
453
|
+
# === use_jruby?
|
454
|
+
# ========================================================================= #
|
455
|
+
def use_jruby?
|
456
|
+
true
|
457
|
+
end
|
458
|
+
|
459
|
+
# ========================================================================= #
|
460
|
+
# === is_visible
|
461
|
+
# ========================================================================= #
|
462
|
+
def is_visible
|
463
|
+
setVisible(true)
|
464
|
+
end
|
465
|
+
|
466
|
+
# ========================================================================= #
|
467
|
+
# === password_field
|
468
|
+
# ========================================================================= #
|
469
|
+
def password_field(
|
470
|
+
i = ''
|
471
|
+
)
|
472
|
+
JPasswordField.new(i)
|
473
|
+
end
|
474
|
+
|
475
|
+
# ========================================================================= #
|
476
|
+
# === java_colour
|
477
|
+
#
|
478
|
+
# This method only works with symbols as input, such as :steelblue or
|
479
|
+
# :bisque.
|
480
|
+
#
|
481
|
+
# This method depends on the external gem called 'colours'.
|
482
|
+
#
|
483
|
+
# Usage examples:
|
484
|
+
#
|
485
|
+
# use_this_colour = java_colour(:bisque)
|
486
|
+
# use_this_colour = java_colour(:steelblue)
|
487
|
+
#
|
488
|
+
# ========================================================================= #
|
489
|
+
def java_colour(
|
490
|
+
use_this_symbol = :steelblue
|
491
|
+
)
|
492
|
+
begin
|
493
|
+
require 'colours/constants/file_constants.rb'
|
494
|
+
rescue LoadError; end
|
495
|
+
_ = ::Colours.file_html_colours
|
496
|
+
if File.exist? _
|
497
|
+
dataset = YAML.load_file(_)
|
498
|
+
if dataset.has_key? use_this_symbol.to_s
|
499
|
+
pointer = dataset[use_this_symbol.to_s]
|
500
|
+
return Color.new(pointer[0], pointer[1], pointer[2])
|
501
|
+
end
|
502
|
+
end
|
503
|
+
return nil # else we return nil.
|
504
|
+
end; alias java_color java_colour # === java_color
|
505
|
+
|
506
|
+
# ========================================================================= #
|
507
|
+
# === insets
|
508
|
+
# ========================================================================= #
|
509
|
+
def insets(n = 6)
|
510
|
+
Insets.new(n, n, n, n)
|
511
|
+
end
|
512
|
+
|
513
|
+
# ========================================================================= #
|
514
|
+
# === menu_item
|
515
|
+
# ========================================================================= #
|
516
|
+
def menu_item(i = '')
|
517
|
+
JMenuItem.new(i)
|
518
|
+
end
|
519
|
+
|
520
|
+
# ========================================================================= #
|
521
|
+
# === infer_the_namespace
|
522
|
+
#
|
523
|
+
# This will assume the true namespace from the inspectable name.
|
524
|
+
# ========================================================================= #
|
525
|
+
def infer_the_namespace
|
526
|
+
_ = inspect.to_s.delete('<')
|
527
|
+
if _.include? ' '
|
528
|
+
_ = _.split(' ').first.delete('#')
|
529
|
+
if _.include? ':'
|
530
|
+
_ = _.split(':')[0 .. -2].reject {|entry| entry.empty? }.join('::')
|
531
|
+
end
|
532
|
+
end
|
533
|
+
if @internal_hash.nil?
|
534
|
+
reset_the_internal_hash
|
535
|
+
end
|
536
|
+
@internal_hash[:namespace] = _ # And assign it here.
|
537
|
+
end
|
538
|
+
|
539
|
+
# ========================================================================= #
|
540
|
+
# === namespace?
|
541
|
+
# ========================================================================= #
|
542
|
+
def namespace?
|
543
|
+
@internal_hash[:namespace]
|
544
|
+
end
|
545
|
+
|
546
|
+
# ========================================================================= #
|
547
|
+
# === reset_the_internal_hash
|
548
|
+
# ========================================================================= #
|
549
|
+
def reset_the_internal_hash
|
550
|
+
@internal_hash = {}
|
551
|
+
end
|
552
|
+
|
553
|
+
# ========================================================================= #
|
554
|
+
# === bold_text
|
555
|
+
# ========================================================================= #
|
556
|
+
def bold_text(i = '')
|
557
|
+
_ = ::SwingParadise.text(i)
|
558
|
+
make_bold(_)
|
559
|
+
return _
|
560
|
+
end; alias bold_label bold_text # === bold_label
|
561
|
+
alias create_text bold_text # === create_text
|
562
|
+
|
563
|
+
# ========================================================================= #
|
564
|
+
# === make_bold
|
565
|
+
# ========================================================================= #
|
566
|
+
def make_bold(i)
|
567
|
+
bold_font = Font.new(
|
568
|
+
i.getFont.getName,
|
569
|
+
Font::BOLD,
|
570
|
+
i.getFont.getSize
|
571
|
+
)
|
572
|
+
i.setFont(bold_font)
|
573
|
+
return i
|
574
|
+
end
|
575
|
+
|
576
|
+
# ========================================================================= #
|
577
|
+
# === hbox (hbox tag)
|
578
|
+
# ========================================================================= #
|
579
|
+
def hbox
|
580
|
+
Box.createHorizontalBox
|
581
|
+
end; alias create_hbox hbox # === create_hbox
|
582
|
+
|
583
|
+
# ========================================================================= #
|
584
|
+
# === jlabel
|
585
|
+
# ========================================================================= #
|
586
|
+
def jlabel(i = '')
|
587
|
+
JLabel.new(i)
|
588
|
+
end
|
589
|
+
|
590
|
+
# ========================================================================= #
|
591
|
+
# === return_pwd
|
592
|
+
# ========================================================================= #
|
593
|
+
def return_pwd
|
594
|
+
(Dir.pwd+'/').squeeze('/')
|
595
|
+
end
|
596
|
+
|
597
|
+
# ========================================================================= #
|
598
|
+
# === create_boxlayout
|
599
|
+
#
|
600
|
+
# BoxLayout in Java resides at javax.swing.BoxLayout.
|
601
|
+
#
|
602
|
+
# The first argument to this method should be the panel that contains
|
603
|
+
# the child elements.
|
604
|
+
#
|
605
|
+
# The second argument can have any of these values:
|
606
|
+
#
|
607
|
+
# BoxLayout::X_AXIS
|
608
|
+
# BoxLayout::Y_AXIS
|
609
|
+
# BoxLayout::LINE_AXIS
|
610
|
+
# BoxLayout::PAGE_AXIS
|
611
|
+
#
|
612
|
+
# The recommended API for using this method is this:
|
613
|
+
#
|
614
|
+
# panel = create_boxlayout(:new_panel)
|
615
|
+
#
|
616
|
+
# ========================================================================= #
|
617
|
+
def create_boxlayout(
|
618
|
+
i,
|
619
|
+
use_this_axis = BoxLayout::PAGE_AXIS
|
620
|
+
)
|
621
|
+
case i
|
622
|
+
# ======================================================================= #
|
623
|
+
# === :new_panel
|
624
|
+
# ======================================================================= #
|
625
|
+
when :new_panel
|
626
|
+
i = create_panel
|
627
|
+
end
|
628
|
+
case use_this_axis
|
629
|
+
# ======================================================================= #
|
630
|
+
# === :north
|
631
|
+
# ======================================================================= #
|
632
|
+
when :north
|
633
|
+
use_this_axis = BorderLayout::NORTH
|
634
|
+
# ======================================================================= #
|
635
|
+
# === :west
|
636
|
+
# ======================================================================= #
|
637
|
+
when :west
|
638
|
+
use_this_axis = BorderLayout::WEST
|
639
|
+
# ======================================================================= #
|
640
|
+
# === :east
|
641
|
+
# ======================================================================= #
|
642
|
+
when :east
|
643
|
+
use_this_axis = BorderLayout::EAST
|
644
|
+
# ======================================================================= #
|
645
|
+
# === :south
|
646
|
+
# ======================================================================= #
|
647
|
+
when :south
|
648
|
+
use_this_axis = BorderLayout::SOUTH
|
649
|
+
end
|
650
|
+
box_layout = BoxLayout.new(i, use_this_axis)
|
651
|
+
i.setLayout(box_layout)
|
652
|
+
return i
|
653
|
+
end; alias new_boxlayout create_boxlayout # === new_boxlayout
|
654
|
+
|
655
|
+
# ========================================================================= #
|
656
|
+
# === this_file_was_not_found
|
657
|
+
#
|
658
|
+
# Use this to notify the user, whenever the open-gem was unable to
|
659
|
+
# find a file that was assumed to exist locally.
|
660
|
+
# ========================================================================= #
|
661
|
+
def this_file_was_not_found(i)
|
662
|
+
e "#{rev}No file called `#{sfile(i)}` was found. It "\
|
663
|
+
"is assumed to not exist."
|
664
|
+
end; alias no_file_exists_at this_file_was_not_found # === no_file_exists_at
|
665
|
+
alias no_file_was_found_at this_file_was_not_found # === no_file_was_found_at
|
666
|
+
|
667
|
+
# ========================================================================= #
|
668
|
+
# === checkbox
|
669
|
+
#
|
670
|
+
# This method can be used to create a checkbox, in jruby-SWING.
|
671
|
+
# ========================================================================= #
|
672
|
+
def checkbox(
|
673
|
+
i = ''
|
674
|
+
)
|
675
|
+
return ::SwingParadise.create_checkbox(i)
|
676
|
+
end; alias jcheckbox checkbox # === jcheckbox
|
677
|
+
alias create_checkbox checkbox # === create_checkbox
|
678
|
+
|
679
|
+
# ========================================================================= #
|
680
|
+
# === text
|
681
|
+
# ========================================================================= #
|
682
|
+
def text(i = '')
|
683
|
+
::SwingParadise.text(i)
|
684
|
+
end; alias label text # === label
|
685
|
+
|
686
|
+
# ========================================================================= #
|
687
|
+
# === right_aligned_label
|
688
|
+
#
|
689
|
+
# Note that JLabel also has setHorizontalAlignment:
|
690
|
+
#
|
691
|
+
# label.setHorizontalAlignment(SwingConstants::RIGHT)
|
692
|
+
#
|
693
|
+
# ========================================================================= #
|
694
|
+
def right_aligned_label(i = '')
|
695
|
+
return JLabel.new(i, SwingConstants::RIGHT)
|
696
|
+
end
|
697
|
+
|
698
|
+
# ========================================================================= #
|
699
|
+
# === jpanel
|
700
|
+
#
|
701
|
+
# Usage example:
|
702
|
+
#
|
703
|
+
# panel = create_panel { :left }
|
704
|
+
#
|
705
|
+
# ========================================================================= #
|
706
|
+
def jpanel(
|
707
|
+
optional_layout_to_use = nil,
|
708
|
+
&block
|
709
|
+
)
|
710
|
+
if optional_layout_to_use
|
711
|
+
_ = JPanel.new(optional_layout_to_use)
|
712
|
+
else
|
713
|
+
_ = JPanel.new
|
714
|
+
end
|
715
|
+
if block_given?
|
716
|
+
yielded = yield
|
717
|
+
case yielded
|
718
|
+
# ===================================================================== #
|
719
|
+
# === :left
|
720
|
+
# ===================================================================== #
|
721
|
+
when :left
|
722
|
+
_.layout = FlowLayout.new(FlowLayout::LEFT)
|
723
|
+
end
|
724
|
+
end
|
725
|
+
return _
|
726
|
+
end; alias create_panel jpanel # === create_panel
|
727
|
+
alias new_panel jpanel # === new_panel
|
728
|
+
|
729
|
+
# ========================================================================= #
|
730
|
+
# === combo_box
|
731
|
+
#
|
732
|
+
# You can pass an Array to this method; ideally an Array of Strings.
|
733
|
+
# ========================================================================= #
|
734
|
+
def combo_box(
|
735
|
+
optional_array = nil
|
736
|
+
)
|
737
|
+
_ = JComboBox.new
|
738
|
+
if optional_array and optional_array.is_a?(Array) and !optional_array.empty?
|
739
|
+
optional_array.each {|this_item|
|
740
|
+
_.addItem(this_item)
|
741
|
+
}
|
742
|
+
_.setSelectedIndex(0) # Always have the first entry selected.
|
743
|
+
end
|
744
|
+
return _
|
745
|
+
end; alias create_combo_box combo_box # === create_combo_box
|
746
|
+
|
747
|
+
# ========================================================================= #
|
748
|
+
# === create_grid
|
749
|
+
# ========================================================================= #
|
750
|
+
def create_grid(
|
751
|
+
argument1 = 3,
|
752
|
+
argument2 = 3
|
753
|
+
)
|
754
|
+
::SwingParadise.create_grid(argument1, argument2)
|
755
|
+
end; alias grid create_grid # === grid
|
756
|
+
|
757
|
+
# ========================================================================= #
|
758
|
+
# === infer_the_size_based_on_constants
|
759
|
+
# ========================================================================= #
|
760
|
+
def infer_the_size_based_on_constants(
|
761
|
+
width = WIDTH,
|
762
|
+
height = HEIGHT
|
763
|
+
)
|
764
|
+
set_size(
|
765
|
+
width,
|
766
|
+
height
|
767
|
+
)
|
768
|
+
end
|
769
|
+
|
770
|
+
# ========================================================================= #
|
771
|
+
# === jtextarea
|
772
|
+
# ========================================================================= #
|
773
|
+
def jtextarea(
|
774
|
+
optional_argument1 = nil,
|
775
|
+
optional_argument2 = nil
|
776
|
+
)
|
777
|
+
if optional_argument1.nil?
|
778
|
+
JTextArea.new
|
779
|
+
elsif optional_argument1 and optional_argument2
|
780
|
+
JTextArea.new(optional_argument1, optional_argument2)
|
781
|
+
end
|
782
|
+
end; alias create_textarea jtextarea # === create_textarea
|
783
|
+
alias create_text_view jtextarea # === create_text_view
|
784
|
+
|
785
|
+
# ========================================================================= #
|
786
|
+
# === title_width_height_font
|
787
|
+
# ========================================================================= #
|
788
|
+
def title_width_height_font(
|
789
|
+
title,
|
790
|
+
width,
|
791
|
+
height,
|
792
|
+
font
|
793
|
+
)
|
794
|
+
set_internal_title(title)
|
795
|
+
set_internal_width(width)
|
796
|
+
set_internal_height(height)
|
797
|
+
set_internal_font(font)
|
798
|
+
end
|
799
|
+
|
800
|
+
# ========================================================================= #
|
801
|
+
# === set_internal_title
|
802
|
+
# ========================================================================= #
|
803
|
+
def set_internal_title(i)
|
804
|
+
@internal_title = i
|
805
|
+
end
|
806
|
+
|
807
|
+
# ========================================================================= #
|
808
|
+
# === set_internal_width
|
809
|
+
# ========================================================================= #
|
810
|
+
def set_internal_width(i)
|
811
|
+
@internal_width = i
|
812
|
+
end
|
813
|
+
|
814
|
+
# ========================================================================= #
|
815
|
+
# === set_internal_height
|
816
|
+
# ========================================================================= #
|
817
|
+
def set_internal_height(i)
|
818
|
+
@internal_height = i
|
819
|
+
end
|
820
|
+
|
821
|
+
# ========================================================================= #
|
822
|
+
# === height?
|
823
|
+
# ========================================================================= #
|
824
|
+
def height?
|
825
|
+
@internal_height
|
826
|
+
end; alias internal_height? height? # === internal_height?
|
827
|
+
|
828
|
+
# ========================================================================= #
|
829
|
+
# === width?
|
830
|
+
# ========================================================================= #
|
831
|
+
def width?
|
832
|
+
@internal_width
|
833
|
+
end; alias internal_width? width? # === internal_width?
|
834
|
+
|
835
|
+
# ========================================================================= #
|
836
|
+
# === internal_title?
|
837
|
+
# ========================================================================= #
|
838
|
+
def internal_title?
|
839
|
+
@internal_title
|
840
|
+
end; alias title? internal_title? # === title?
|
841
|
+
|
842
|
+
# ========================================================================= #
|
843
|
+
# === run_main
|
844
|
+
# ========================================================================= #
|
845
|
+
def run_main(
|
846
|
+
i = main_window?
|
847
|
+
)
|
848
|
+
i.exit_on_close
|
849
|
+
i.set_title(internal_title?)
|
850
|
+
i.set_size(internal_width?, internal_height?)
|
851
|
+
i.setLocationRelativeTo(nil)
|
852
|
+
i.show_all
|
853
|
+
return i
|
854
|
+
end
|
855
|
+
|
856
|
+
# ========================================================================= #
|
857
|
+
# === set_internal_font
|
858
|
+
# ========================================================================= #
|
859
|
+
def set_internal_font(i)
|
860
|
+
@internal_font = i
|
861
|
+
end
|
862
|
+
|
863
|
+
# ========================================================================= #
|
864
|
+
# The methods that come past this point are "deliberately" not useful.
|
865
|
+
# ========================================================================= #
|
866
|
+
def use_gtk_paradise_project_css_file; end
|
867
|
+
|
868
|
+
# ========================================================================= #
|
869
|
+
# === jruby_font
|
870
|
+
#
|
871
|
+
# Simply delegate towards SwingParadise.jruby_font().
|
872
|
+
# ========================================================================= #
|
873
|
+
def jruby_font(
|
874
|
+
i = 'Sans serif 28'
|
875
|
+
)
|
876
|
+
::SwingParadise.jruby_font(i)
|
877
|
+
end; alias font jruby_font # === font
|
878
|
+
|
879
|
+
# ========================================================================= #
|
880
|
+
# === left_mouse_click?
|
881
|
+
# ========================================================================= #
|
882
|
+
def left_mouse_click?(event)
|
883
|
+
javax.swing.SwingUtilities.isLeftMouseButton(event)
|
884
|
+
end
|
885
|
+
|
886
|
+
# ========================================================================= #
|
887
|
+
# === middle_mouse_click?
|
888
|
+
# ========================================================================= #
|
889
|
+
def middle_mouse_click?(event)
|
890
|
+
javax.swing.SwingUtilities.isMiddleMouseButton(event)
|
891
|
+
end
|
892
|
+
|
893
|
+
# ========================================================================= #
|
894
|
+
# === right_mouse_click?
|
895
|
+
# ========================================================================= #
|
896
|
+
def right_mouse_click?(event)
|
897
|
+
javax.swing.SwingUtilities.isRightMouseButton(event)
|
898
|
+
end
|
899
|
+
|
900
|
+
# ========================================================================= #
|
901
|
+
# === platform?
|
902
|
+
#
|
903
|
+
# Little helper-method to find out whether we are running jruby or
|
904
|
+
# another operating system.
|
905
|
+
# ========================================================================= #
|
906
|
+
def platform?
|
907
|
+
case RUBY_PLATFORM
|
908
|
+
when /java/, /jruby/
|
909
|
+
:java
|
910
|
+
when /linux/ # This is for x86_64-linux, for instance.
|
911
|
+
:linux
|
912
|
+
else
|
913
|
+
:unknown
|
914
|
+
end
|
915
|
+
end
|
916
|
+
|
917
|
+
# ========================================================================= #
|
918
|
+
# === set_commandline_arguments
|
919
|
+
# ========================================================================= #
|
920
|
+
def set_commandline_arguments(i = '')
|
921
|
+
i = [i].flatten.compact
|
922
|
+
@commandline_arguments = i
|
923
|
+
end
|
924
|
+
|
925
|
+
# ========================================================================= #
|
926
|
+
# === commandline_arguments?
|
927
|
+
# ========================================================================= #
|
928
|
+
def commandline_arguments?
|
929
|
+
@commandline_arguments
|
930
|
+
end
|
931
|
+
|
932
|
+
# ========================================================================= #
|
933
|
+
# === first_argument?
|
934
|
+
# ========================================================================= #
|
935
|
+
def first_argument?
|
936
|
+
@commandline_arguments.first
|
937
|
+
end; alias first? first_argument? # === first?
|
938
|
+
|
939
|
+
# ========================================================================= #
|
940
|
+
# === create_menubar
|
941
|
+
# ========================================================================= #
|
942
|
+
def create_menubar
|
943
|
+
JMenuBar.new
|
944
|
+
end; alias create_menu_bar create_menubar # === create_menu_bar
|
945
|
+
|
946
|
+
end
|
947
|
+
|
948
|
+
# =========================================================================== #
|
949
|
+
# === SwingParadise.create_checkbox
|
950
|
+
# =========================================================================== #
|
951
|
+
def self.create_checkbox(
|
952
|
+
i = ''
|
953
|
+
)
|
954
|
+
if i.is_a? Symbol
|
955
|
+
case i
|
956
|
+
# ======================================================================= #
|
957
|
+
# === :is_checked
|
958
|
+
# ======================================================================= #
|
959
|
+
when :is_checked
|
960
|
+
_ = JCheckBox.new
|
961
|
+
_.setSelected(true)
|
962
|
+
end
|
963
|
+
else
|
964
|
+
_ = JCheckBox.new(i)
|
965
|
+
end
|
966
|
+
return _
|
967
|
+
end
|
968
|
+
|
969
|
+
# =========================================================================== #
|
970
|
+
# === SwingParadise.create_grid (grid tag)
|
971
|
+
#
|
972
|
+
# You are encouraged to use something like '4x4' as input argument to
|
973
|
+
# this method, e. g. to create a grid with 4 cells and 4 rows, thus
|
974
|
+
# 16 elements in total.
|
975
|
+
# =========================================================================== #
|
976
|
+
def self.create_grid(
|
977
|
+
argument1 = 3,
|
978
|
+
argument2 = 3
|
979
|
+
)
|
980
|
+
if argument1.is_a?(String) and argument1.include?('x') # Support e. g. "2x2" as input.
|
981
|
+
splitted = argument1.split('x')
|
982
|
+
argument1 = splitted[0].to_i
|
983
|
+
argument2 = splitted[1].to_i
|
984
|
+
end
|
985
|
+
if argument1.is_a?(String) and argument1.empty?
|
986
|
+
argument1 = argument2.to_i
|
987
|
+
end
|
988
|
+
grid_layout = GridLayout.new(argument1, argument2)
|
989
|
+
panel = ::SwingParadise.create_panel(grid_layout)
|
990
|
+
return panel
|
991
|
+
end; self.instance_eval { alias grid create_grid } # === SwingParadise.grid
|
992
|
+
|
993
|
+
end
|