package org.kjtw.categories; import javax.swing.JPanel; import java.awt.GridBagLayout; import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.Insets; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import org.kjtw.displays.JackGfxStrip; import org.kjtw.process.AudioPlayer; import org.kjtw.process.SRFLoad; import org.kjtw.structures.JackGraphic; import org.kjtw.structures.QHeader; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.io.IOException; import java.util.Hashtable; import javax.swing.JLabel; public class GuestHostQuestion extends JPanel { private static final long serialVersionUID = -6042752868968979550L; /** * */ private JLabel Title; private JLabel Qtext; private JLabel txt1; private JLabel txt2; private JLabel txt3; private JLabel txt4; private JButton btnPlayTitle; private JButton btnPlaypreamble; private JButton btnPlayQ; private JButton btnAnswers; private JButton button_1; private JButton button_2; private JButton button_3; private JButton button_4; private JButton btnAllWrongAnswers; private JButton btnClosingRemark; private JCheckBox chckbxNewCheckBox; private Hashtable<String, byte[]> supplements; private Hashtable<String, JackGraphic> gfx; private SRFLoad QData; private JLabel lblNewLabel; private JButton btnToggleAltTitles; private int titleval; private JButton btnHostIntro; private JButton btnHostIntro_1; private JButton btnHostOutro; /** * Create the panel. * @throws IOException */ public GuestHostQuestion(final QHeader qhd) throws IOException { supplements = new Hashtable<String, byte[]>(); QData = new SRFLoad(qhd.getPath()); supplements = QData.getData(); gfx = QData.getGfx(); JFrame cc = new JFrame(); cc.setTitle("Question Graphics"); cc.getContentPane().add(new JackGfxStrip(gfx.get("off4_24500"))); cc.pack(); cc.setVisible(true); if (qhd.getForced() != null) { qhd.setTitlea(new String(supplements.get("STR_18"))); qhd.setTitleb(new String(supplements.get("STR_19"))); } titleval =0; GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[] {70, 171, 153, 137, 247}; gridBagLayout.rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30}; gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; setLayout(gridBagLayout); btnPlayTitle = new JButton("Play Title"); btnPlayTitle.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { switch (titleval) { case 0: default: { new Thread(new AudioPlayer(supplements.get("snd_1"))).start(); break; } case 1: { new Thread(new AudioPlayer(supplements.get("snd_18"))).start(); break; } case 2: { new Thread(new AudioPlayer(supplements.get("snd_19"))).start(); break; } } } }); lblNewLabel = new JLabel("Difficulty:"+qhd.getDiff()); GridBagConstraints gbc_lblNewLabel = new GridBagConstraints(); gbc_lblNewLabel.gridwidth = 2; gbc_lblNewLabel.anchor = GridBagConstraints.WEST; gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5); gbc_lblNewLabel.gridx = 1; gbc_lblNewLabel.gridy = 0; add(lblNewLabel, gbc_lblNewLabel); GridBagConstraints gbc_btnPlayTitle = new GridBagConstraints(); gbc_btnPlayTitle.fill = GridBagConstraints.HORIZONTAL; gbc_btnPlayTitle.insets = new Insets(0, 0, 5, 5); gbc_btnPlayTitle.gridx = 0; gbc_btnPlayTitle.gridy = 1; add(btnPlayTitle, gbc_btnPlayTitle); Title = new JLabel(qhd.getTitle()); GridBagConstraints gbc_Title = new GridBagConstraints(); gbc_Title.gridwidth = 2; gbc_Title.insets = new Insets(0, 0, 5, 5); gbc_Title.fill = GridBagConstraints.HORIZONTAL; gbc_Title.gridx = 1; gbc_Title.gridy = 1; add(Title, gbc_Title); btnPlaypreamble = new JButton("Preamble"); btnPlaypreamble.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new Thread(new AudioPlayer(supplements.get("snd_2"))).start(); } }); GridBagConstraints gbc_btnPlaypreamble = new GridBagConstraints(); gbc_btnPlaypreamble.fill = GridBagConstraints.HORIZONTAL; gbc_btnPlaypreamble.insets = new Insets(0, 0, 5, 5); gbc_btnPlaypreamble.gridx = 0; gbc_btnPlaypreamble.gridy = 2; add(btnPlaypreamble, gbc_btnPlaypreamble); if (supplements.get("snd_2")==null) { btnPlaypreamble.setEnabled(false); } button_1 = new JButton("1"); button_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new Thread(new AudioPlayer(supplements.get("snd_7"))).start(); } }); GridBagConstraints gbc_button_1 = new GridBagConstraints(); gbc_button_1.fill = GridBagConstraints.HORIZONTAL; gbc_button_1.insets = new Insets(0, 0, 5, 5); gbc_button_1.gridx = 0; gbc_button_1.gridy = 5; add(button_1, gbc_button_1); button_2 = new JButton("2"); button_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new Thread(new AudioPlayer(supplements.get("snd_8"))).start(); } }); if (supplements.get("snd_7")==null) { button_1.setEnabled(false); } if (supplements.get("snd_8")==null) { button_2.setEnabled(false); } btnHostIntro = new JButton("Host intro 1"); GridBagConstraints gbc_btnHostIntro = new GridBagConstraints(); gbc_btnHostIntro.insets = new Insets(0, 0, 5, 5); gbc_btnHostIntro.gridx = 1; gbc_btnHostIntro.gridy = 2; add(btnHostIntro, gbc_btnHostIntro); btnHostIntro.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new Thread(new AudioPlayer(supplements.get("snd_20"))).start(); } }); btnHostIntro_1 = new JButton("Host Intro 2"); GridBagConstraints gbc_btnHostIntro_1 = new GridBagConstraints(); gbc_btnHostIntro_1.insets = new Insets(0, 0, 5, 5); gbc_btnHostIntro_1.gridx = 2; gbc_btnHostIntro_1.gridy = 2; add(btnHostIntro_1, gbc_btnHostIntro_1); btnHostIntro_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new Thread(new AudioPlayer(supplements.get("snd_21"))).start(); } }); btnPlayQ = new JButton("Play Q"); btnPlayQ.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new Thread(new AudioPlayer(supplements.get("snd_3"))).start(); } }); GridBagConstraints gbc_btnPlayQ = new GridBagConstraints(); gbc_btnPlayQ.fill = GridBagConstraints.HORIZONTAL; gbc_btnPlayQ.insets = new Insets(0, 0, 5, 5); gbc_btnPlayQ.gridx = 0; gbc_btnPlayQ.gridy = 3; add(btnPlayQ, gbc_btnPlayQ); Qtext = new JLabel("<html><body style='width:100%'>"+new String(supplements.get("STR_2"))); GridBagConstraints gbc_Qtext = new GridBagConstraints(); gbc_Qtext.gridheight = 2; gbc_Qtext.gridwidth = 2; gbc_Qtext.insets = new Insets(0, 0, 5, 5); gbc_Qtext.fill = GridBagConstraints.BOTH; gbc_Qtext.gridx = 1; gbc_Qtext.gridy = 3; add(Qtext, gbc_Qtext); btnAnswers = new JButton("Answers"); btnAnswers.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new Thread(new AudioPlayer(supplements.get("snd_5"))).start(); } }); GridBagConstraints gbc_btnAnswers = new GridBagConstraints(); gbc_btnAnswers.fill = GridBagConstraints.HORIZONTAL; gbc_btnAnswers.insets = new Insets(0, 0, 5, 5); gbc_btnAnswers.gridx = 0; gbc_btnAnswers.gridy = 4; add(btnAnswers, gbc_btnAnswers); txt1 = new JLabel(new String(supplements.get("STR_3"))); GridBagConstraints gbc_txt1 = new GridBagConstraints(); gbc_txt1.gridwidth = 2; gbc_txt1.insets = new Insets(0, 0, 5, 5); gbc_txt1.fill = GridBagConstraints.HORIZONTAL; gbc_txt1.gridx = 1; gbc_txt1.gridy = 5; add(txt1, gbc_txt1); GridBagConstraints gbc_button_2 = new GridBagConstraints(); gbc_button_2.fill = GridBagConstraints.HORIZONTAL; gbc_button_2.insets = new Insets(0, 0, 5, 5); gbc_button_2.gridx = 0; gbc_button_2.gridy = 6; add(button_2, gbc_button_2); button_3 = new JButton("3"); button_3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new Thread(new AudioPlayer(supplements.get("snd_9"))).start(); } }); if (supplements.get("snd_9")==null) { button_3.setEnabled(false); } txt2 = new JLabel(new String(supplements.get("STR_4"))); GridBagConstraints gbc_txt2 = new GridBagConstraints(); gbc_txt2.gridwidth = 2; gbc_txt2.insets = new Insets(0, 0, 5, 5); gbc_txt2.fill = GridBagConstraints.HORIZONTAL; gbc_txt2.gridx = 1; gbc_txt2.gridy = 6; add(txt2, gbc_txt2); GridBagConstraints gbc_button_3 = new GridBagConstraints(); gbc_button_3.fill = GridBagConstraints.HORIZONTAL; gbc_button_3.insets = new Insets(0, 0, 5, 5); gbc_button_3.gridx = 0; gbc_button_3.gridy = 7; add(button_3, gbc_button_3); button_4 = new JButton("4"); button_4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new Thread(new AudioPlayer(supplements.get("snd_10"))).start(); } }); if (supplements.get("snd_10")==null) { button_4.setEnabled(false); } txt3 = new JLabel(new String(supplements.get("STR_5"))); GridBagConstraints gbc_txt3 = new GridBagConstraints(); gbc_txt3.gridwidth = 2; gbc_txt3.insets = new Insets(0, 0, 5, 5); gbc_txt3.fill = GridBagConstraints.HORIZONTAL; gbc_txt3.gridx = 1; gbc_txt3.gridy = 7; add(txt3, gbc_txt3); GridBagConstraints gbc_button_4 = new GridBagConstraints(); gbc_button_4.fill = GridBagConstraints.HORIZONTAL; gbc_button_4.insets = new Insets(0, 0, 5, 5); gbc_button_4.gridx = 0; gbc_button_4.gridy = 8; add(button_4, gbc_button_4); txt4 = new JLabel(new String(supplements.get("STR_6"))); GridBagConstraints gbc_txt4 = new GridBagConstraints(); gbc_txt4.gridwidth = 2; gbc_txt4.insets = new Insets(0, 0, 5, 5); gbc_txt4.fill = GridBagConstraints.HORIZONTAL; gbc_txt4.gridx = 1; gbc_txt4.gridy = 8; add(txt4, gbc_txt4); btnAllWrongAnswers = new JButton("Play 'all wrong' audio"); btnAllWrongAnswers.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new Thread(new AudioPlayer(supplements.get("snd_11"))).start(); } }); if (supplements.get("snd_11")==null) { btnAllWrongAnswers.setEnabled(false); } chckbxNewCheckBox = new JCheckBox("Show answer"); chckbxNewCheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { txt1.setForeground(Color.BLACK); txt2.setForeground(Color.BLACK); txt3.setForeground(Color.BLACK); txt4.setForeground(Color.BLACK); if (e.getStateChange() == ItemEvent.DESELECTED) { } else { switch (qhd.getAnswer()) { case 1: txt1.setForeground(Color.GREEN); break; case 2: txt2.setForeground(Color.GREEN); break; case 3: txt3.setForeground(Color.GREEN); break; case 4: txt4.setForeground(Color.GREEN); break; } } } }); GridBagConstraints gbc_chckbxNewCheckBox = new GridBagConstraints(); gbc_chckbxNewCheckBox.insets = new Insets(0, 0, 5, 5); gbc_chckbxNewCheckBox.gridx = 0; gbc_chckbxNewCheckBox.gridy = 9; add(chckbxNewCheckBox, gbc_chckbxNewCheckBox); GridBagConstraints gbc_btnAllWrongAnswers = new GridBagConstraints(); gbc_btnAllWrongAnswers.anchor = GridBagConstraints.WEST; gbc_btnAllWrongAnswers.insets = new Insets(0, 0, 5, 5); gbc_btnAllWrongAnswers.gridx = 1; gbc_btnAllWrongAnswers.gridy = 9; add(btnAllWrongAnswers, gbc_btnAllWrongAnswers); btnClosingRemark = new JButton("Closing remark"); btnClosingRemark.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new Thread(new AudioPlayer(supplements.get("snd_6"))).start(); } }); GridBagConstraints gbc_btnClosingRemark = new GridBagConstraints(); gbc_btnClosingRemark.insets = new Insets(0, 0, 5, 5); gbc_btnClosingRemark.anchor = GridBagConstraints.WEST; gbc_btnClosingRemark.gridx = 2; gbc_btnClosingRemark.gridy = 9; add(btnClosingRemark, gbc_btnClosingRemark); btnHostOutro = new JButton("Host Outro"); GridBagConstraints gbc_btnHostOutro = new GridBagConstraints(); gbc_btnHostOutro.insets = new Insets(0, 0, 5, 5); gbc_btnHostOutro.gridx = 1; gbc_btnHostOutro.gridy = 10; add(btnHostOutro, gbc_btnHostOutro); btnHostOutro.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new Thread(new AudioPlayer(supplements.get("snd_22"))).start(); } }); if (qhd.getTitlea() != null) { btnPlayTitle.setText("Play Title 1"); btnToggleAltTitles = new JButton("Toggle alt titles"); btnToggleAltTitles.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { titleval++; if (titleval >2) { titleval =0; } switch (titleval) { case 0: default: { btnPlayTitle.setText("Play Title 1"); Title.setText(qhd.getTitle()); break; } case 1: { btnPlayTitle.setText("Play Title 2"); Title.setText(qhd.getTitlea()); break; } case 2: { btnPlayTitle.setText("Play Title 3"); Title.setText(qhd.getTitleb()); break; } } } }); GridBagConstraints gbc_btnToggleAltTitles = new GridBagConstraints(); gbc_btnToggleAltTitles.insets = new Insets(0, 0, 5, 5); gbc_btnToggleAltTitles.gridx = 0; gbc_btnToggleAltTitles.gridy = 0; add(btnToggleAltTitles, gbc_btnToggleAltTitles); } } }