diff options
Diffstat (limited to 'python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui')
8 files changed, 671 insertions, 0 deletions
diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CCNewProjectPanel.form b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CCNewProjectPanel.form new file mode 100644 index 000000000000..71e27857a2ee --- /dev/null +++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CCNewProjectPanel.form @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="UTF-8"?> +<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.coursecreator.ui.CCNewProjectPanel"> + <grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <margin top="0" left="0" bottom="0" right="0"/> + <constraints> + <xy x="20" y="20" width="500" height="400"/> + </constraints> + <properties/> + <border type="none"/> + <children> + <component id="fd520" class="javax.swing.JLabel"> + <constraints> + <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"> + <preferred-size width="95" height="-1"/> + </grid> + </constraints> + <properties> + <text value="Name:"/> + </properties> + </component> + <component id="7e88" class="javax.swing.JTextField" binding="myName"> + <constraints> + <grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> + <preferred-size width="150" height="-1"/> + </grid> + </constraints> + <properties/> + </component> + <component id="ec56c" class="javax.swing.JLabel"> + <constraints> + <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text value="Description"/> + </properties> + </component> + <component id="2e2d7" class="javax.swing.JLabel"> + <constraints> + <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"> + <preferred-size width="95" height="-1"/> + </grid> + </constraints> + <properties> + <text value="Author:"/> + </properties> + </component> + <component id="41fe6" class="javax.swing.JTextField" binding="myAuthorField"> + <constraints> + <grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> + <preferred-size width="150" height="-1"/> + </grid> + </constraints> + <properties/> + </component> + <grid id="12f06" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <margin top="0" left="0" bottom="0" right="0"/> + <constraints> + <grid row="2" column="1" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + </constraints> + <properties/> + <border type="line"> + <color color="-6709600"/> + </border> + <children> + <component id="389a7" class="javax.swing.JTextArea" binding="myDescription"> + <constraints> + <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"> + <preferred-size width="150" height="50"/> + </grid> + </constraints> + <properties/> + </component> + </children> + </grid> + </children> + </grid> +</form> diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CCNewProjectPanel.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CCNewProjectPanel.java new file mode 100644 index 000000000000..83a3458576b6 --- /dev/null +++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CCNewProjectPanel.java @@ -0,0 +1,59 @@ +package org.jetbrains.plugins.coursecreator.ui; + +import com.intellij.facet.ui.FacetValidatorsManager; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.ui.DocumentAdapter; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import javax.swing.event.DocumentEvent; + +public class CCNewProjectPanel { + private JPanel myPanel; + private JTextArea myDescription; + private JTextField myName; + private JTextField myAuthorField; + private FacetValidatorsManager myValidationManager; + + + public CCNewProjectPanel() { + final String userName = System.getProperty("user.name"); + if (userName != null) { + myAuthorField.setText(userName); + } + myName.getDocument().addDocumentListener(new MyValidator()); + myDescription.getDocument().addDocumentListener(new MyValidator()); + myAuthorField.getDocument().addDocumentListener(new MyValidator()); + } + + public JPanel getMainPanel() { + return myPanel; + } + + @NotNull + public String getName() { + return StringUtil.notNullize(myName.getText()); + } + + @NotNull + public String getDescription() { + return StringUtil.notNullize(myDescription.getText()); + } + + @NotNull + public String getAuthor() { + return StringUtil.notNullize(myAuthorField.getText()); + } + + public void registerValidators(FacetValidatorsManager manager) { + myValidationManager = manager; + } + + private class MyValidator extends DocumentAdapter { + + @Override + protected void textChanged(DocumentEvent e) { + myValidationManager.validate(); + } + } +} diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateCourseArchiveDialog.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateCourseArchiveDialog.java new file mode 100644 index 000000000000..d6c3bdb24af3 --- /dev/null +++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateCourseArchiveDialog.java @@ -0,0 +1,40 @@ +package org.jetbrains.plugins.coursecreator.ui; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.DialogWrapper; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.coursecreator.actions.CreateCourseArchive; + +import javax.swing.*; + +public class CreateCourseArchiveDialog extends DialogWrapper { + + private CreateCourseArchivePanel myPanel; + private CreateCourseArchive myAction; + + public CreateCourseArchiveDialog(@NotNull final Project project, CreateCourseArchive action) { + super(project); + setTitle("Create Course Archive"); + myPanel = new CreateCourseArchivePanel(project, this); + myAction = action; + init(); + } + + @Nullable + @Override + protected JComponent createCenterPanel() { + return myPanel; + } + + public void enableOKAction(boolean isEnabled) { + myOKAction.setEnabled(isEnabled); + } + + @Override + protected void doOKAction() { + myAction.setZipName(myPanel.getZipName()); + myAction.setLocationDir(myPanel.getLocationPath()); + super.doOKAction(); + } +} diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateCourseArchivePanel.form b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateCourseArchivePanel.form new file mode 100644 index 000000000000..920dcb9494a7 --- /dev/null +++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateCourseArchivePanel.form @@ -0,0 +1,79 @@ +<?xml version="1.0" encoding="UTF-8"?> +<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.coursecreator.ui.CreateCourseArchivePanel"> + <grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <margin top="0" left="0" bottom="0" right="0"/> + <constraints> + <xy x="20" y="20" width="500" height="400"/> + </constraints> + <properties/> + <border type="none"/> + <children> + <grid id="a3b77" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <margin top="0" left="0" bottom="0" right="0"/> + <constraints> + <grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + </constraints> + <properties/> + <border type="none"/> + <children> + <component id="786af" class="javax.swing.JLabel"> + <constraints> + <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text value="Name:"/> + </properties> + </component> + <component id="160bb" class="javax.swing.JTextField" binding="myNameField" default-binding="true"> + <constraints> + <grid row="0" column="1" row-span="2" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> + <preferred-size width="150" height="-1"/> + </grid> + </constraints> + <properties/> + </component> + <component id="628ab" class="javax.swing.JLabel"> + <constraints> + <grid row="1" column="0" row-span="2" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text value="Location:"/> + </properties> + </component> + <component id="aab8" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myLocationField"> + <constraints> + <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> + </constraints> + <properties/> + </component> + <grid id="29be7" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <margin top="0" left="0" bottom="0" right="0"/> + <constraints> + <grid row="3" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + </constraints> + <properties/> + <border type="none"/> + <children> + <component id="4fa15" class="javax.swing.JLabel" binding="myErrorIcon"> + <constraints> + <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text value=""/> + </properties> + </component> + <component id="4bdcf" class="javax.swing.JLabel" binding="myErrorLabel"> + <constraints> + <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text value=""/> + </properties> + </component> + </children> + </grid> + </children> + </grid> + </children> + </grid> +</form> diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateCourseArchivePanel.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateCourseArchivePanel.java new file mode 100644 index 000000000000..4e7deedf7e47 --- /dev/null +++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateCourseArchivePanel.java @@ -0,0 +1,65 @@ +package org.jetbrains.plugins.coursecreator.ui; + +import com.intellij.icons.AllIcons; +import com.intellij.openapi.fileChooser.FileChooserDescriptor; +import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.TextFieldWithBrowseButton; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; + +public class CreateCourseArchivePanel extends JPanel { + private JPanel myPanel; + private JTextField myNameField; + private TextFieldWithBrowseButton myLocationField; + private JLabel myErrorIcon; + private JLabel myErrorLabel; + private CreateCourseArchiveDialog myDlg; + + public CreateCourseArchivePanel(@NotNull final Project project, CreateCourseArchiveDialog dlg) { + setLayout(new BorderLayout()); + add(myPanel, BorderLayout.CENTER); + myErrorIcon.setIcon(AllIcons.Actions.Lightning); + setState(false); + myDlg = dlg; + myNameField.setText("course"); + myLocationField.setText(project.getBasePath()); + FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); + myLocationField.addBrowseFolderListener("Choose location folder", null, project, descriptor); + myLocationField.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String location = myLocationField.getText(); + File file = new File(location); + if (!file.exists() || !file.isDirectory()) { + myDlg.enableOKAction(false); + setError("Invalid location"); + } + myDlg.enableOKAction(true); + } + }); + } + + private void setState(boolean isVisible) { + myErrorIcon.setVisible(isVisible); + myErrorLabel.setVisible(isVisible); + } + + private void setError(String message) { + myErrorLabel.setText(message); + setState(true); + } + + public String getZipName() { + return myNameField.getText(); + } + + public String getLocationPath() { + return myLocationField.getText(); + } +} diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateTaskWindowDialog.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateTaskWindowDialog.java new file mode 100644 index 000000000000..c7e8f715672c --- /dev/null +++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateTaskWindowDialog.java @@ -0,0 +1,153 @@ +package org.jetbrains.plugins.coursecreator.ui; + +import com.intellij.ide.projectView.ProjectView; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.ui.ValidationInfo; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileManager; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.coursecreator.CCProjectService; +import org.jetbrains.plugins.coursecreator.format.TaskWindow; + +import javax.swing.*; +import java.io.*; + +public class CreateTaskWindowDialog extends DialogWrapper { + + public static final String TITLE = "New Task Window"; + private static final Logger LOG = Logger.getInstance(CreateTaskWindowDialog.class.getName()); + private final TaskWindow myTaskWindow; + private final CreateTaskWindowPanel myPanel; + private final Project myProject; + + public Project getProject() { + return myProject; + } + + public CreateTaskWindowDialog(@NotNull final Project project, @NotNull final TaskWindow taskWindow, int lessonIndex, + int taskIndex, String taskFileName, int taskWindowIndex) { + super(project, true); + setTitle(TITLE); + myTaskWindow = taskWindow; + myPanel = new CreateTaskWindowPanel(this); + String generatedHintName = "lesson" + lessonIndex + "task" + taskIndex + taskFileName + "_" + taskWindowIndex; + myPanel.setGeneratedHintName(generatedHintName); + if (taskWindow.getHintName() != null) { + setHintText(project, taskWindow); + } + myProject = project; + String taskWindowTaskText = taskWindow.getTaskText(); + myPanel.setTaskWindowText(taskWindowTaskText != null ? taskWindowTaskText : ""); + String hintName = taskWindow.getHintName(); + myPanel.setHintName(hintName != null ? hintName : ""); + init(); + initValidation(); + } + + private void setHintText(Project project, TaskWindow taskWindow) { + VirtualFile hints = project.getBaseDir().findChild("hints"); + if (hints != null) { + File file = new File(hints.getPath(), taskWindow.getHintName()); + StringBuilder hintText = new StringBuilder(); + if (file.exists()) { + try { + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file))); + String line; + while ((line = bufferedReader.readLine()) != null) { + hintText.append(line).append("\n"); + } + myPanel.doClick(); + //myPanel.enableHint(true); + myPanel.setHintText(hintText.toString()); + } + catch (FileNotFoundException e) { + LOG.error("created hint was not found", e); + } + catch (IOException e) { + LOG.error(e); + } + } + } + } + + @Override + protected void doOKAction() { + String taskWindowText = myPanel.getTaskWindowText(); + myTaskWindow.setTaskText(StringUtil.notNullize(taskWindowText)); + if (myPanel.createHint()) { + String hintName = myPanel.getHintName(); + myTaskWindow.setHint(hintName); + String hintText = myPanel.getHintText(); + createHint(hintName, hintText); + } + super.doOKAction(); + } + + private void createHint(String hintName, String hintText) { + VirtualFile hintsDir = myProject.getBaseDir().findChild("hints"); + if (hintsDir != null) { + File hintFile = new File(hintsDir.getPath(), hintName); + PrintWriter printWriter = null; + try { + printWriter = new PrintWriter(hintFile); + printWriter.print(hintText); + } + catch (FileNotFoundException e) { + //TODO:show error in UI + return; + } + finally { + if (printWriter != null) { + printWriter.close(); + } + } + } + VirtualFileManager.getInstance().refreshWithoutFileWatcher(true); + ProjectView.getInstance(myProject).refresh(); + } + + public void deleteHint() { + VirtualFile hintsDir = myProject.getBaseDir().findChild("hints"); + if (hintsDir != null) { + String hintName = myTaskWindow.getHintName(); + if (hintName == null) { + return; + } + File hintFile = new File(hintsDir.getPath(), hintName); + if (hintFile.exists()) { + CCProjectService.deleteProjectFile(hintFile, myProject); + myTaskWindow.setHint(null); + myPanel.resetHint(); + } + } + } + + @Nullable + @Override + protected JComponent createCenterPanel() { + return myPanel; + } + + @Nullable + @Override + public ValidationInfo doValidate() { + String name = myPanel.getHintName(); + VirtualFile hintsDir = myProject.getBaseDir().findChild("hints"); + if (hintsDir == null) { + return null; + } + VirtualFile child = hintsDir.findChild(name); + if (child == null) { + return null; + } + return myTaskWindow.getHintName() != null ? null : new ValidationInfo("Hint file with such filename already exists"); + } + + public void validateInput() { + super.initValidation(); + } +} diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateTaskWindowPanel.form b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateTaskWindowPanel.form new file mode 100644 index 000000000000..ccd91e4154b0 --- /dev/null +++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateTaskWindowPanel.form @@ -0,0 +1,102 @@ +<?xml version="1.0" encoding="UTF-8"?> +<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.coursecreator.ui.CreateTaskWindowPanel"> + <grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <margin top="0" left="0" bottom="0" right="0"/> + <constraints> + <xy x="20" y="20" width="500" height="400"/> + </constraints> + <properties/> + <border type="none"/> + <children> + <component id="aaa28" class="javax.swing.JLabel"> + <constraints> + <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <labelFor value="b712"/> + <text value="Text:"/> + </properties> + </component> + <component id="d2e2f" class="javax.swing.JLabel" binding="myHintNameLabel"> + <constraints> + <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <enabled value="true"/> + <labelFor value="ddeb1"/> + <text value="Hint name:"/> + </properties> + </component> + <component id="ddeb1" class="javax.swing.JTextField" binding="myHintName"> + <constraints> + <grid row="2" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> + <preferred-size width="150" height="-1"/> + </grid> + </constraints> + <properties> + <text value=""/> + </properties> + </component> + <component id="d322a" class="javax.swing.JLabel" binding="myHintTextLabel"> + <constraints> + <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <labelFor value="d0efc"/> + <text value="Hint text:"/> + </properties> + </component> + <grid id="51a63" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <margin top="0" left="0" bottom="0" right="0"/> + <constraints> + <grid row="3" column="1" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + </constraints> + <properties/> + <border type="line"> + <color color="-6709600"/> + </border> + <children> + <component id="d0efc" class="javax.swing.JTextArea" binding="myHintText"> + <constraints> + <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"> + <preferred-size width="300" height="100"/> + </grid> + </constraints> + <properties/> + </component> + </children> + </grid> + <grid id="cbc70" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <margin top="0" left="0" bottom="0" right="0"/> + <constraints> + <grid row="0" column="1" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"> + <minimum-size width="150" height="-1"/> + <preferred-size width="150" height="-1"/> + </grid> + </constraints> + <properties/> + <border type="line"> + <color color="-6709600"/> + </border> + <children> + <component id="b712" class="javax.swing.JTextArea" binding="myTaskWindowText"> + <constraints> + <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"> + <preferred-size width="300" height="100"/> + </grid> + </constraints> + <properties/> + </component> + </children> + </grid> + <component id="f86b4" class="javax.swing.JCheckBox" binding="myCreateHintCheckBox" default-binding="true"> + <constraints> + <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text value="Create hint"/> + </properties> + </component> + </children> + </grid> +</form> diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateTaskWindowPanel.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateTaskWindowPanel.java new file mode 100644 index 000000000000..21a7eb063c63 --- /dev/null +++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateTaskWindowPanel.java @@ -0,0 +1,96 @@ +package org.jetbrains.plugins.coursecreator.ui; + +import com.intellij.ui.DocumentAdapter; + +import javax.swing.*; +import javax.swing.event.DocumentEvent; +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +public class CreateTaskWindowPanel extends JPanel { + + private final CreateTaskWindowDialog myDialog; + private JPanel myPanel; + private JTextArea myTaskWindowText; + private JTextField myHintName; + private JTextArea myHintText; + private JCheckBox myCreateHintCheckBox; + private JLabel myHintNameLabel; + private JLabel myHintTextLabel; + private String myGeneratedHintName = ""; + + public CreateTaskWindowPanel(CreateTaskWindowDialog dialog) { + super(new BorderLayout()); + add(myPanel, BorderLayout.CENTER); + myDialog = dialog; + enableHint(false); + myCreateHintCheckBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + int state = e.getStateChange(); + // 1 for checked + enableHint(state == 1); + if (state == 2) { + myDialog.deleteHint(); + } + } + }); + + myHintName.getDocument().addDocumentListener(new DocumentAdapter() { + @Override + protected void textChanged(DocumentEvent e) { + myDialog.validateInput(); + } + }); + } + + public void enableHint(boolean isEnable) { + myHintName.setEnabled(isEnable); + myHintText.setEnabled(isEnable); + myHintNameLabel.setEnabled(isEnable); + myHintTextLabel.setEnabled(isEnable); + myHintName.setText(myGeneratedHintName); + } + + public void setTaskWindowText(String taskWindowText) { + myTaskWindowText.setText(taskWindowText); + } + + public void setHintName(String hintName) { + myHintName.setText(hintName); + } + + public void setHintText(String hintText) { + myHintText.setText(hintText); + } + + public String getTaskWindowText() { + return myTaskWindowText.getText(); + } + + public String getHintName() { + return myHintName.getText(); + } + + public String getHintText() { + return myHintText.getText(); + } + + public boolean createHint() { + return myHintName.isEnabled(); + } + + public void doClick() { + myCreateHintCheckBox.doClick(); + } + + public void resetHint() { + myHintName.setText(""); + myHintText.setText(""); + } + + public void setGeneratedHintName(String generatedHintName) { + myGeneratedHintName = generatedHintName; + } +} |