View Javadoc

1   package sk.stuba.fiit.foo07.genex.gui;
2   
3   import java.awt.event.ActionEvent;
4   import java.awt.event.ActionListener;
5   
6   import javax.swing.JButton;
7   import javax.swing.JDialog;
8   import javax.swing.JLabel;
9   import javax.swing.JOptionPane;
10  import javax.swing.JScrollPane;
11  import javax.swing.JSeparator;
12  import javax.swing.JTextArea;
13  import javax.swing.WindowConstants;
14  
15  import sk.stuba.fiit.foo07.genex.beans.Answer;
16  
17  /**
18   * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
19   * Builder, which is free for non-commercial use. If Jigloo is being used
20   * commercially (ie, by a corporation, company or business for any purpose
21   * whatever) then you should purchase a license for each developer using Jigloo.
22   * Please visit www.cloudgarden.com for details. Use of Jigloo implies
23   * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
24   * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
25   * ANY CORPORATE OR COMMERCIAL PURPOSE.
26   */
27  public class NewAnswerDialog extends javax.swing.JDialog {
28  
29      /**
30       * 
31       */
32      private static final long serialVersionUID = 2716343263084921488L;
33  
34      private Answer ret;
35  
36      private JButton jBtnCancel;
37      private JTextArea jTxtAnswer;
38      private JSeparator jSeparator2;
39      private JButton jBtnOK;
40      private JScrollPane jScrAnswer;
41      private JLabel jLabel1;
42  
43      public NewAnswerDialog(JDialog frame, Answer ans) {
44          super(frame);
45  
46          if (ans != null)
47              ret = ans;
48          else
49              ret = new Answer();
50  
51          initGUI();
52  
53          if (ret.getText() != null) {
54              setTitle("Upraviť odpoveď");
55              jTxtAnswer.setText(ret.getText());
56              jTxtAnswer.setCaretPosition(0);
57          } else
58              setTitle("Nová odpoveď");
59      }
60  
61      private void initGUI() {
62          try {
63              {
64                  getContentPane().setLayout(null);
65                  this.setResizable(false);
66                  this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
67                  setLocationByPlatform(true);
68                  {
69                      jLabel1 = new JLabel();
70                      getContentPane().add(jLabel1);
71                      jLabel1.setText("Text odpovede");
72                      jLabel1.setBounds(12, 12, 175, 14);
73                      jLabel1.setForeground(new java.awt.Color(100, 0, 0));
74                  }
75                  {
76                      jScrAnswer = new JScrollPane();
77                      getContentPane().add(jScrAnswer);
78                      jScrAnswer.setBounds(12, 32, 371, 116);
79                      {
80                          jTxtAnswer = new JTextArea();
81                          jScrAnswer.setViewportView(jTxtAnswer);
82                          jTxtAnswer.setBackground(new java.awt.Color(255, 255,
83                                  240));
84                      }
85                  }
86                  {
87                      jBtnCancel = new JButton();
88                      getContentPane().add(jBtnCancel);
89                      jBtnCancel.setText("Cancel");
90                      jBtnCancel.setBounds(287, 163, 96, 21);
91                      jBtnCancel.setMnemonic(java.awt.event.KeyEvent.VK_C);
92                      jBtnCancel.addActionListener(new ActionListener() {
93                          public void actionPerformed(ActionEvent evt) {
94                              jBtnCancelActionPerformed(evt);
95                          }
96                      });
97                  }
98                  {
99                      jBtnOK = new JButton();
100                     getContentPane().add(jBtnOK);
101                     jBtnOK.setText("OK");
102                     jBtnOK.setBounds(186, 163, 96, 21);
103                     jBtnOK.setMnemonic(java.awt.event.KeyEvent.VK_O);
104                     jBtnOK.addActionListener(new ActionListener() {
105                         public void actionPerformed(ActionEvent evt) {
106                             jBtnOKActionPerformed(evt);
107                         }
108                     });
109                 }
110                 {
111                     jSeparator2 = new JSeparator();
112                     getContentPane().add(jSeparator2);
113                     jSeparator2.setBounds(12, 154, 368, 9);
114                 }
115             }
116             this.setSize(403, 231);
117         } catch (Exception e) {
118             e.printStackTrace();
119         }
120     }
121 
122     private void jBtnCancelActionPerformed(ActionEvent evt) {
123         ret = null;
124         setVisible(false);
125     }
126 
127     private void jBtnOKActionPerformed(ActionEvent evt) {
128         if (jTxtAnswer.getText().length() == 0) {
129             JOptionPane.showMessageDialog(this, "Musíte zadať text odpovede.",
130                     "Chyba", JOptionPane.ERROR_MESSAGE);
131             return;
132         }
133 
134         ret.setText(jTxtAnswer.getText());
135         ret.setIsCorrect(false);
136 
137         setVisible(false);
138     }
139 
140     public Answer showDialog() {
141         this.setModalityType(ModalityType.DOCUMENT_MODAL);
142 
143         setVisible(true);
144 
145         return ret;
146     }
147 
148 }