001 package com.croftsoft.apps.quiz;
002
003 import java.awt.*;
004 import javax.swing.*;
005
006 import com.croftsoft.core.lang.NullArgumentException;
007
008 /*********************************************************************
009 *
010 * <p />
011 *
012 * @version
013 * 2001-07-11
014 * @since
015 * 2001-07-10
016 * @author
017 * <a href="https://www.croftsoft.com/">David Wallace Croft</a>
018 *********************************************************************/
019
020 public final class QuizItemPanel
021 extends JPanel
022 //////////////////////////////////////////////////////////////////////
023 //////////////////////////////////////////////////////////////////////
024 {
025
026 // private QuizItem quizItem;
027
028 private JTextArea questionJTextArea;
029
030 private JTextArea answerJTextArea;
031
032 private JTextArea referenceJTextArea;
033
034 //////////////////////////////////////////////////////////////////////
035 //////////////////////////////////////////////////////////////////////
036
037 public QuizItemPanel (
038 Color panelBackgroundColor,
039 Color textFieldBackgroundColor )
040 //////////////////////////////////////////////////////////////////////
041 {
042 super ( new GridBagLayout ( ), true ); // isDoubleBuffered
043
044 // the panels currently ignore the colors
045
046 questionJTextArea = new JTextArea ( );
047
048 answerJTextArea = new JTextArea ( );
049
050 referenceJTextArea = new JTextArea ( );
051
052 GridBagConstraints gridBagConstraints = new GridBagConstraints ( );
053
054 gridBagConstraints.fill = GridBagConstraints.BOTH;
055
056 gridBagConstraints.weightx = 1.0;
057
058 gridBagConstraints.gridy = 0;
059
060 gridBagConstraints.weighty = 1.0;
061
062 add ( new JScrollPane ( questionJTextArea ), gridBagConstraints );
063
064 gridBagConstraints.gridy = 1;
065
066 gridBagConstraints.weighty = 3.0;
067
068 add ( new JScrollPane ( answerJTextArea ), gridBagConstraints );
069
070 gridBagConstraints.gridy = 2;
071
072 gridBagConstraints.weighty = 1.0;
073
074 add ( new JScrollPane ( referenceJTextArea ), gridBagConstraints );
075 }
076
077 public QuizItemPanel ( )
078 //////////////////////////////////////////////////////////////////////
079 {
080 this ( null, null );
081 }
082
083 //////////////////////////////////////////////////////////////////////
084 //////////////////////////////////////////////////////////////////////
085
086 public void setQuizItem ( QuizItem quizItem )
087 //////////////////////////////////////////////////////////////////////
088 {
089 String question = null;
090
091 String answer = null;
092
093 String reference = null;
094
095 if ( quizItem != null )
096 {
097 question = quizItem.getQuestion ( );
098
099 answer = quizItem.getAnswer ( );
100
101 reference = quizItem.getReference ( );
102 }
103
104 questionJTextArea .setText ( question != null ? question : "" );
105
106 answerJTextArea .setText ( answer != null ? answer : "" );
107
108 referenceJTextArea.setText ( reference != null ? reference : "" );
109 }
110
111 //////////////////////////////////////////////////////////////////////
112 //////////////////////////////////////////////////////////////////////
113 }