cc55b58ec101e02617d99e0d12dd9831bc583d2b
[idea/community.git] / python / educational-core / course-creator / src / com / jetbrains / edu / coursecreator / ui / CCCreateAnswerPlaceholderPanel.java
1 package com.jetbrains.edu.coursecreator.ui;
2
3 import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.ItemEvent;
6 import java.awt.event.ItemListener;
7
8 public class CCCreateAnswerPlaceholderPanel extends JPanel {
9
10   private JPanel myPanel;
11   private JTextArea myHintText;
12   private JCheckBox myCreateHintCheckBox;
13   private JTextField myAnswerPlaceholderText;
14
15   public CCCreateAnswerPlaceholderPanel() {
16     super(new BorderLayout());
17     add(myPanel, BorderLayout.CENTER);
18     enableHint(false);
19     myHintText.setLineWrap(true);
20     myHintText.setWrapStyleWord(true);
21     myCreateHintCheckBox.addItemListener(new ItemListener() {
22       @Override
23       public void itemStateChanged(ItemEvent e) {
24         int state = e.getStateChange();
25         // 1 for checked
26         enableHint(state == 1);
27         if (state == 2) {
28           resetHint();
29         }
30       }
31     });
32
33     myAnswerPlaceholderText.grabFocus();
34   }
35
36   private void enableHint(boolean isEnable) {
37     myHintText.setEnabled(isEnable);
38   }
39
40   public void setAnswerPlaceholderText(String answerPlaceholderText) {
41     myAnswerPlaceholderText.setText(answerPlaceholderText);
42   }
43
44   public void setHintText(String hintText) {
45     myHintText.setText(hintText);
46   }
47
48   public String getAnswerPlaceholderText() {
49     return myAnswerPlaceholderText.getText();
50   }
51
52   public String getHintText() {
53     return myHintText.getText();
54   }
55
56   public void doClick() {
57     myCreateHintCheckBox.doClick();
58   }
59
60   public void resetHint() {
61     myHintText.setText("");
62   }
63
64   public JComponent getPreferredFocusedComponent() {
65     return myAnswerPlaceholderText;
66   }
67 }