Class: Studium::GUI::Jruby::ExamTrainer
- Inherits:
-
JFrame
- Object
- JFrame
- Studium::GUI::Jruby::ExamTrainer
- Includes:
- SwingParadise::BaseModule
- Defined in:
- lib/studium/gui/jruby/exam_trainer/exam_trainer.rb
Overview
Studium::GUI::Jruby::ExamTrainer
Constant Summary collapse
- USE_THIS_FONT =
#
USE_THIS_FONT
#
Font.new('Serif', Font::PLAIN, 25)
- SMALLER_FONT =
#
SMALLER_FONT
#
Font.new('Serif', Font::PLAIN, 21)
- LARGE_FONT_SIZE =
#
LARGE_FONT_SIZE
#
32
- Y_AXIS_FOR_THE_BOTTOM_BUTTONS =
#
Y_AXIS_FOR_THE_BOTTOM_BUTTONS
#
700
- WIDTH_OF_THE_TEXTVIEWS =
#
WIDTH_OF_THE_TEXTVIEWS
#
1680
- USE_THIS_AS_THE_TOOLTIP_TEXT_FOR_THE_ASK_EXAM_QUESTION_BUTTON =
#
USE_THIS_AS_THE_TOOLTIP_TEXT_FOR_THE_ASK_EXAM_QUESTION_BUTTON
#
'Click this button to ask a new exam question.'
- HEIGHT_FOR_THE_BUTTONS_ON_THE_BOTTOM =
#
HEIGHT_FOR_THE_BUTTONS_ON_THE_BOTTOM
#
100
- NAMESPACE =
#
NAMESPACE
#
inspect
Class Method Summary collapse
-
.[](i = ARGV) ⇒ Object
# === Studium::GUI::Jruby::ExamTrainer[] ========================================================================= #.
Instance Method Summary collapse
-
#bottom_line_in_pixel_size? ⇒ Boolean
# === bottom_line_in_pixel_size? ========================================================================= #.
-
#connect_skeleton ⇒ Object
# === connect_skeleton ========================================================================= #.
-
#create_skeleton ⇒ Object
# === create_skeleton (create tag, skeleton tag) ========================================================================= #.
-
#create_the_ask_an_exam_button ⇒ Object
# === create_the_ask_an_exam_button ========================================================================= #.
-
#create_the_combo_box ⇒ Object
# === create_the_combo_box (combobox tag) ========================================================================= #.
-
#create_the_entries ⇒ Object
# === create_the_entries ========================================================================= #.
-
#create_the_reveal_button ⇒ Object
# === create_the_reveal_button (reveal tag).
-
#create_the_solved_button ⇒ Object
# === create_the_solved_button ========================================================================= #.
-
#determine_the_look_and_feel ⇒ Object
# === determine_the_look_and_feel ========================================================================= #.
-
#do_ask_a_new_exam_question(current_exam_topic = combo_box?.text?.to_s) ⇒ Object
# === do_ask_a_new_exam_question (ask tag) ========================================================================= #.
-
#enhance_entry_n_answered_exam_questions(use_this_font = nil) ⇒ Object
# === enhance_entry_n_answered_exam_questions ========================================================================= #.
-
#enhance_the_entry_containing_n_questions ⇒ Object
# === enhance_the_entry_containing_n_questions ========================================================================= #.
-
#enhance_the_entry_for_sleeping_n_seconds ⇒ Object
# === enhance_the_entry_for_sleeping_n_seconds ========================================================================= #.
-
#enhance_the_entry_percentage(optional_argument = nil) ⇒ Object
# === enhance_the_entry_percentage ========================================================================= #.
-
#enhance_the_the_entry_percentage(optional_use_this_font = nil) ⇒ Object
# === enhance_the_the_entry_percentage ========================================================================= #.
-
#initialize(commandline_arguments = nil, run_already = true) ⇒ ExamTrainer
constructor
# === initialize ========================================================================= #.
-
#large_font? ⇒ Boolean
# === large_font? ========================================================================= #.
-
#medium_font? ⇒ Boolean
# === medium_font? ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#return_the_main_quit_button ⇒ Object
# === return_the_main_quit_button (quit tag) ========================================================================= #.
-
#return_the_panel_containing_most_of_the_entries_in_the_middle ⇒ Object
# === return_the_panel_containing_most_of_the_entries_in_the_middle ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#the_solve_button_was_clicked ⇒ Object
# === the_solve_button_was_clicked ========================================================================= #.
-
#use_jruby? ⇒ Boolean
# === use_jruby? ========================================================================= #.
Constructor Details
#initialize(commandline_arguments = nil, run_already = true) ⇒ ExamTrainer
#
initialize
#
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 77 def initialize( commandline_arguments = nil, run_already = true ) super(TITLE) reset set_commandline_arguments( commandline_arguments ) run if run_already end |
Class Method Details
.[](i = ARGV) ⇒ Object
#
Studium::GUI::Jruby::ExamTrainer[]
#
242 243 244 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 242 def self.[](i = ARGV) new(i) end |
Instance Method Details
#bottom_line_in_pixel_size? ⇒ Boolean
#
bottom_line_in_pixel_size?
#
235 236 237 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 235 def bottom_line_in_pixel_size? Y_AXIS_FOR_THE_BOTTOM_BUTTONS end |
#connect_skeleton ⇒ Object
#
connect_skeleton
#
135 136 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 135 def connect_skeleton end |
#create_skeleton ⇒ Object
#
create_skeleton (create tag, skeleton tag)
#
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 105 def create_skeleton # ======================================================================= # # === @panel # # This should come first in this method. # ======================================================================= # @panel = jpanel # This is an instance of Java::JavaxSwing::JPanel. @panel.set_font(Font.new('Calibri', Font::PLAIN, 30)) @panel.set_border(EmptyBorder.new(3, 3, 3, 3)) @panel.setLayout(nil) @panel.hint = 'The main panel.' create_the_combo_box create_the_entries end |
#create_the_ask_an_exam_button ⇒ Object
#
create_the_ask_an_exam_button
#
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 350 def # ======================================================================= # # Create the button next - it will be an instance of # Java::JavaxSwing::JButton # ======================================================================= # @button_ask_an_exam_question = ( 'Ask an exam question' ) @button_ask_an_exam_question.use_this_font = USE_THIS_FONT @button_ask_an_exam_question.dimensions( x_axis: 185, y_axis: bottom_line_in_pixel_size?, width: 290, height: HEIGHT_FOR_THE_BUTTONS_ON_THE_BOTTOM ) # ======================================================================= # # Set a tool tip next: # ======================================================================= # @button_ask_an_exam_question.hint = USE_THIS_AS_THE_TOOLTIP_TEXT_FOR_THE_ASK_EXAM_QUESTION_BUTTON @button_ask_an_exam_question.on_event {|event| do_ask_a_new_exam_question } @panel << @button_ask_an_exam_question end |
#create_the_combo_box ⇒ Object
#
create_the_combo_box (combobox tag)
#
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 182 def create_the_combo_box # ======================================================================= # # Create the primary combo-box next: # ======================================================================= # _ = combo_box(exam_topics_short_form?) _.set_font(Font.new 'Sans serif', Font::PLAIN, LARGE_FONT_SIZE) _.dimensions( x_axis: 800, # x-position y_axis: 2, # y-position, aka top-towards-bottom. width: 500, # width height: 48 # height ) _.add_action_listener { |event| case event.get_action_command when /comboBoxChanged/ clear_question_buffer clear_answer_buffer current_selection = _.text? entry_current_exam_topic?.set_text(current_selection) end } @internal_hash[:combobox_available_exam_topics] = _ end |
#create_the_entries ⇒ Object
#
create_the_entries
#
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 261 def create_the_entries create_the_entry_for_sleeping_n_seconds # ======================================================================= # # === :entry_current_exam_topic # ======================================================================= # _ = JTextField.new(5) _.setBounds( 200, # x 5, # y 400, # width 48 # height ) _.setFont(USE_THIS_FONT) _.center _.setMargin(Insets.new(10, 10, 10, 10)) @internal_hash[:entry_for_the_current_exam_topic] = _ @panel << _ # Add the entry current exam topic here. end |
#create_the_reveal_button ⇒ Object
#
create_the_reveal_button (reveal tag)
This is the “Reveal the Answer” button.
#
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 380 def _ = ('Reveal the Answer') {{ font: USE_THIS_FONT }} _.on_clicked { text_view_for_the_answer?.set_text( sanitize_this_answer( answer_is?, :filter_away_tags ) ) } _.dimensions( x_axis: 490, y_axis: bottom_line_in_pixel_size?, width: 300, height: HEIGHT_FOR_THE_BUTTONS_ON_THE_BOTTOM ) @panel << _ @button_reveal_the_answer = _ end |
#create_the_solved_button ⇒ Object
#
create_the_solved_button
#
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 209 def # ======================================================================= # # === The solved-button will be created next # ======================================================================= # @button_solved = ( 'Solved' ) @button_solved.set_font(USE_THIS_FONT) @button_solved.dimensions( x_axis: 935, y_axis: Y_AXIS_FOR_THE_BOTTOM_BUTTONS, # up-to-bottom. width: 260, height: HEIGHT_FOR_THE_BUTTONS_ON_THE_BOTTOM ) @button_solved.hint = 'Click this button to solve the exam topic at hand.' @button_solved.setFont(USE_THIS_FONT) @button_solved.on_event {|event| } @button_solved.blue_border(2) @panel << @button_solved end |
#determine_the_look_and_feel ⇒ Object
#
determine_the_look_and_feel
#
148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 148 def determine_the_look_and_feel UIManager.get_installed_look_and_feels.each { |info| info_name = info.name case info_name when 'Nimbus' UIManager.set_look_and_feel(info.class_name) # UIManager.set_look_and_feel(UIManager.getSystemLookAndFeelClassName) #when 'GTK+' # UIManager.set_look_and_feel(info.class_name) end } end |
#do_ask_a_new_exam_question(current_exam_topic = combo_box?.text?.to_s) ⇒ Object
#
do_ask_a_new_exam_question (ask tag)
#
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 283 def do_ask_a_new_exam_question( current_exam_topic = combo_box?.text?.to_s ) answer_buffer?.setText('') # Empty it just in case. update_hash_dataset_of_all_lectures current_exam_topic = entry_for_the_current_exam_topic?.text?.to_s if current_exam_topic.empty? set_current_exam_topic(combo_box?.text?.to_s) current_exam_topic = entry_for_the_current_exam_topic?.text?.to_s end current_exam_topic = Studium.(current_exam_topic) { :be_quiet } if ::Studium.is_this_exam_topic_available?(current_exam_topic) clear_the_answer_buffer # =================================================================== # # (1) Pass the current exam topic into a method that will return # an Array. # =================================================================== # array = Studium.return_an_array_for_this_exam_topic(current_exam_topic) # =================================================================== # # (2) Keep track of the Array next: # =================================================================== # @internal_hash[:array_all_exam_questions] = array @question, @answer = array first = Studium.remove_html(@question) last = Studium.remove_html(@answer) first = word_wrap(first, 80) if first.size > 80 last = word_wrap(last, 80) if last.size > 80 question_buffer?.set_text(first) hash = hash_dataset_of_all_lectures? if current_exam_topic # Protect against nil-values here. _ = hash[current_exam_topic.tr(' ','_').to_sym] if _ # Protect against nil values here as well. set_n_exam_questions_exist_in_total( _[:n_total_questions] ) set_n_exam_questions_were_already_answered( _[:n_questions_answered] ) set_n_percentage_of_questions_answered( # Update the n percentage value answered. _[:percentage_of_questions_answered] ) set_n_exam_questions_are_unanswered( _[:n_total_questions] - _[:n_questions_answered] ) end end Thread.new { current_delay = entry_delay?.text?.to_f # Obtain the current delay from the entry. sleep(current_delay) answer_buffer?.setText(last) } else e 'Not a registered exam-topic: '+current_exam_topic.to_s end end |
#enhance_entry_n_answered_exam_questions(use_this_font = nil) ⇒ Object
#
enhance_entry_n_answered_exam_questions
#
249 250 251 252 253 254 255 256 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 249 def enhance_entry_n_answered_exam_questions( use_this_font = nil ) if use_this_font @entry_n_answered_exam_questions.set_font(use_this_font) end @entry_n_answered_exam_questions.center end |
#enhance_the_entry_containing_n_questions ⇒ Object
#
enhance_the_entry_containing_n_questions
#
410 411 412 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 410 def enhance_the_entry_containing_n_questions @entry_containing_n_questions.center end |
#enhance_the_entry_for_sleeping_n_seconds ⇒ Object
#
enhance_the_entry_for_sleeping_n_seconds
#
435 436 437 438 439 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 435 def enhance_the_entry_for_sleeping_n_seconds _ = @internal_hash[:entry_for_sleeping_n_seconds] _.center _.setMargin(Insets.new(10, 10, 10, 10)) end |
#enhance_the_entry_percentage(optional_argument = nil) ⇒ Object
#
enhance_the_entry_percentage
#
423 424 425 426 427 428 429 430 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 423 def enhance_the_entry_percentage( optional_argument = nil ) _ = entry_percentage? _.center use_this_colour = java_colour(:bisque) _.setBackground(use_this_colour) end |
#enhance_the_the_entry_percentage(optional_use_this_font = nil) ⇒ Object
#
enhance_the_the_entry_percentage
#
417 418 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 417 def enhance_the_the_entry_percentage(optional_use_this_font = nil) end |
#large_font? ⇒ Boolean
#
large_font?
#
141 142 143 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 141 def large_font? LARGE_FONT_SIZE end |
#medium_font? ⇒ Boolean
#
medium_font?
#
34 35 36 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 34 def medium_font? Font.new('Serif', Font::PLAIN, 25) end |
#reset ⇒ Object
#
reset (reset tag)
#
92 93 94 95 96 97 98 99 100 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 92 def reset super() if respond_to?(:super) # ======================================================================= # # === @namespace # ======================================================================= # @namespace = NAMESPACE @internal_hash = {} # Must come before reset_the_shared_variables. reset_the_shared_variables end |
#return_the_main_quit_button ⇒ Object
#
return_the_main_quit_button (quit tag)
#
164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 164 def _ = _.set_font(Font.new('Calibri', Font::PLAIN, 30)) _.dimensions( x_axis: 1200, # x-position y_axis: Y_AXIS_FOR_THE_BOTTOM_BUTTONS, # y-position width: 190, height: HEIGHT_FOR_THE_BUTTONS_ON_THE_BOTTOM ) _.setBorderPainted(true) _.setBorder(BorderFactory.createLineBorder(Color::BLUE, 2)) _.hint = 'Use this button to quit the application.' return _ end |
#return_the_panel_containing_most_of_the_entries_in_the_middle ⇒ Object
#
return_the_panel_containing_most_of_the_entries_in_the_middle
#
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 544 def return_the_panel_containing_most_of_the_entries_in_the_middle panel = create_panel { :left } panel.set_font(Font.new('Calibri', Font::PLAIN, 42)) panel.hint = 'New panel' # ======================================================================= # # Add the "n exam questions in total": # ======================================================================= # _ = text( N_EXAM_QUESTIONS_IN_TOTAL ) _.use_this_font = medium_font? _.setAlignmentX(Component::CENTER_ALIGNMENT) box = new_boxlayout(:new_panel) box.setBorder(BorderFactory.create_uniform_empty_border(6)) box << _ box << create_the_entry_containing_n_questions panel << box # ======================================================================= # # Add the "n unanswered exam questions" next: # ======================================================================= # _ = text( N_UNANSWERED_EXAM_QUESTIONS ) _.use_this_font = medium_font? # ======================================================================= # # === n unanswered exam questions: # ======================================================================= # _.setAlignmentX(Component::CENTER_ALIGNMENT) box = new_boxlayout(:new_panel) box.setBorder(BorderFactory.create_uniform_empty_border(6)) box << _ box << create_the_entry_containing_n_unanswered_exam_questions panel << box # ======================================================================= # # === n answered exam questions: # ======================================================================= # _ = text( N_ANSWERED_EXAM_QUESTIONS ) _.use_this_font = medium_font? _.setAlignmentX(Component::CENTER_ALIGNMENT) box = new_boxlayout(:new_panel) box.setBorder(BorderFactory.create_uniform_empty_border(6)) box << _ box << create_the_entry_containing_n_answered_exam_questions panel << box # ======================================================================= # # Add the label "n % solved" as well as the associated entry: # ======================================================================= # _ = text( N_PERCENT_SOLVED ) _.use_this_font = medium_font? _.setAlignmentX(Component::CENTER_ALIGNMENT) box = new_boxlayout(:new_panel) box.setBorder(BorderFactory.create_uniform_empty_border(6)) box << _ box << create_the_entry_percentage # And the entry here. panel << box # ======================================================================= # # Add the label "sleep n seconds" and then the appropriate entry # ======================================================================= # _ = text(SLEEP_N_SECONDS) _.use_this_font = medium_font? _.setAlignmentX(Component::CENTER_ALIGNMENT) box = new_boxlayout(:new_panel) box.setBorder(BorderFactory.create_uniform_empty_border(6)) box << _ box << return_the_entry_sleep_n_seconds # And the entry here. panel << box # ======================================================================= # # And, finally, position the panel properly: # ======================================================================= # panel.dimensions( x_axis: 15, y_axis: 575, width: 1400, height: HEIGHT_FOR_THE_BUTTONS_ON_THE_BOTTOM ) return panel end |
#run ⇒ Object
#
run (run tag)
#
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 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 444 def run default_close setLocationRelativeTo(nil) set_visible(true) create_skeleton connect_skeleton frame = frame('Exam Trainer') frame.getContentPane.add(@panel) # Add the panel. # ======================================================================= # # === The question buffer # ======================================================================= # _ = text_view _.set_font(Font.new 'Sans serif', Font::PLAIN, LARGE_FONT_SIZE) _.set_bounds(10, 20+48, WIDTH_OF_THE_TEXTVIEWS, 150) # Last two are width and height. @widget_for_the_questions = _ # For the questions. scroll = scroll_pane( question_buffer?, :vertical_always, :horizontal_never ) scroll.set_bounds( 10, 20+48, WIDTH_OF_THE_TEXTVIEWS, 150 ) # Last two are width and height. @panel << scroll # ======================================================================= # # === The answer buffer # ======================================================================= # _ = text_view _.set_font(Font.new 'Sans serif', Font::PLAIN, LARGE_FONT_SIZE) _.set_bounds(10, 180+48, WIDTH_OF_THE_TEXTVIEWS, 150) # Last two are width and height. @text_view_for_the_answer = _ # For the questions. scroll = scroll_pane( @text_view_for_the_answer, :vertical_always, :horizontal_never ) scroll.set_bounds(10, 180+48, WIDTH_OF_THE_TEXTVIEWS, 180) @panel << scroll _ = text_view _.set_font(Font.new 'Sans serif', Font::PLAIN, LARGE_FONT_SIZE) # _.set_bounds(10, 420, WIDTH_OF_THE_TEXTVIEWS, 150) # Last two are width and height. @textarea3 = _ # For the questions. scroll = scroll_pane( @textarea3, :vertical_always, :horizontal_never ) scroll.set_bounds(10, 420, WIDTH_OF_THE_TEXTVIEWS, 150) # Last two are width and height. @panel << scroll # ======================================================================= # # Add the combo box next: # ======================================================================= # @panel << @internal_hash[:combobox_available_exam_topics] @panel << # ======================================================================= # # === Exam question label # ======================================================================= # _ = text('Exam topic: ') _.use_this_font = medium_font? _.dimensions( x_axis: 4, y_axis: 24, width: 220, height: 25 ) @panel << _ # ======================================================================= # # Add the "n exam questions in total": # ======================================================================= # _ = text( N_ANSWERED_EXAM_QUESTIONS ) _.use_this_font = medium_font? @panel << _ # ======================================================================= # # Next add the panel containing most of the entries in the middle: # ======================================================================= # @panel.add(return_the_panel_containing_most_of_the_entries_in_the_middle, BorderLayout::NORTH) frame.exit_on_close frame.set_size(1640, 920) frame.setLocationRelativeTo(nil) frame.show_all frame.setExtendedState(JFrame::MAXIMIZED_BOTH) determine_the_look_and_feel end |
#the_solve_button_was_clicked ⇒ Object
#
the_solve_button_was_clicked
#
126 127 128 129 130 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 126 def _ = Studium::Exams::Solved.new(ARGV, :dont_run_yet) _.set_commandline _.run end |
#use_jruby? ⇒ Boolean
#
use_jruby?
#
403 404 405 |
# File 'lib/studium/gui/jruby/exam_trainer/exam_trainer.rb', line 403 def use_jruby? true end |