summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKuersat Akmaz2020-11-30 22:50:07 +0100
committerKuersat Akmaz2020-11-30 22:50:07 +0100
commit64ae169efdac79fa2614a7bf5e60bcbd96701314 (patch)
tree48aa317a77daf42caef9cfc390c2d9297e771088
parent[client] fixed htmleditor in LectureDetailsWindown (diff)
downloadtutor-module-64ae169efdac79fa2614a7bf5e60bcbd96701314.tar.gz
tutor-module-64ae169efdac79fa2614a7bf5e60bcbd96701314.tar.xz
tutor-module-64ae169efdac79fa2614a7bf5e60bcbd96701314.zip
[client] fixed bug in htmleditor in lecturecreationpage
Issue : #3732
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java6
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureCreationPageLayout.java35
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java102
3 files changed, 133 insertions, 10 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java
index bd45f6f1..33d5f164 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java
@@ -372,12 +372,6 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
}
});
- btnBold.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- btnBold.setBackground(Color.YELLOW);
- }
- });
// Update default permissions in the permission manager immediately, so it
// affects
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureCreationPageLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureCreationPageLayout.java
index c184b3e2..07a4887f 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureCreationPageLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureCreationPageLayout.java
@@ -1,16 +1,19 @@
package org.openslx.dozmod.gui.wizard.layout;
import java.util.Calendar;
+import java.awt.FlowLayout;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.JPanel;
import javax.swing.JButton;
+import javax.swing.JComboBox;
import javax.swing.JEditorPane;
import javax.swing.SpinnerDateModel;
import javax.swing.text.DateFormatter;
import javax.swing.text.StyledEditorKit;
+import javax.swing.text.html.HTMLEditorKit;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.control.QDatePickerImpl;
@@ -36,6 +39,12 @@ public abstract class LectureCreationPageLayout extends WizardPage {
protected final JButton btnBold;
protected final JButton btnItalic;
protected final JButton btnUnderline;
+ protected final JButton btnWysiwyg;
+
+ protected final JComboBox cbTxtSize;
+ protected final JComboBox cbTxtColor;
+ protected final HTMLEditorKit kit;
+
/**
* Page for creating lectures
@@ -55,27 +64,45 @@ public abstract class LectureCreationPageLayout extends WizardPage {
// buttons for text editing
JPanel editingPanel = new JPanel();
- editingPanel.setLayout(new GridLayout(1, 3));
+ editingPanel.setLayout(new FlowLayout(FlowLayout.LEADING));
JPanel emptyPanel = new JPanel();
grid.add(emptyPanel);
btnBold = new JButton(new StyledEditorKit.BoldAction());
- btnBold.setIcon(Gui.getScaledIconResource("/img/bold.png", "B", 24, this));
+ btnBold.setIcon(Gui.getScaledIconResource("/img/bold.png", "B", 15, this));
btnBold.setText("");
btnItalic = new JButton(new StyledEditorKit.ItalicAction());
- btnItalic.setIcon(Gui.getScaledIconResource("/img/italic.png", "B", 24, this));
+ btnItalic.setIcon(Gui.getScaledIconResource("/img/italic.png", "B", 15, this));
btnItalic.setText("");
btnUnderline = new JButton(new StyledEditorKit.UnderlineAction());
- btnUnderline.setIcon(Gui.getScaledIconResource("/img/underline.png", "B", 24, this));
+ btnUnderline.setIcon(Gui.getScaledIconResource("/img/underline.png", "B", 15, this));
btnUnderline.setText("");
editingPanel.add(btnBold);
editingPanel.add(btnItalic);
editingPanel.add(btnUnderline);
+
+ String[] textsizes = {"10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29"};
+ cbTxtSize = new JComboBox<>(textsizes);
+ cbTxtSize.setPreferredSize(new Dimension(65,25));
+ editingPanel.add(cbTxtSize);
+
+ Object[] colors = {"Black", "Blue", "Red", "Yellow", "Green"};
+ cbTxtColor = new JComboBox<>(colors);
+ cbTxtColor.setPreferredSize(new Dimension(95,25));
+ editingPanel.add(cbTxtColor);
+
grid.add(editingPanel);
+ emptyPanel.setLayout(new FlowLayout());
+ btnWysiwyg = new JButton("HTML");
+ btnWysiwyg.setPreferredSize(new Dimension(100,25));
+ emptyPanel.add(btnWysiwyg);
+
grid.add(emptyPanel);
grid.nextRow();
// description
txtDescription = new JEditorPane();
+ kit = new HTMLEditorKit();
+ txtDescription.setEditorKit(kit);
txtDescription.setContentType("text/html");
txtDescription.setPreferredSize(new Dimension(600,800));
JScrollPane descPane = new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java
index 9bb91409..a3bf0a71 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java
@@ -4,9 +4,17 @@ import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
+import java.io.IOException;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import javax.swing.Action;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.StyledEditorKit;
+import javax.swing.text.html.HTML;
+import javax.swing.text.html.HTMLDocument;
import org.apache.log4j.Logger;
import org.openslx.dozmod.gui.helper.DateTimeHelper;
@@ -65,8 +73,102 @@ public class LectureCreationPage extends LectureCreationPageLayout {
dtpStartDate.addActionListener(actionListener);
dtpEndDate.addActionListener(actionListener);
calculateDatePeriod();
+
+ cbTxtSize.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ int size = Integer.parseInt((String) cbTxtSize.getSelectedItem());
+ Action act = new StyledEditorKit.FontSizeAction(String.valueOf(size),size);
+ act.actionPerformed(new ActionEvent(act,ActionEvent.ACTION_PERFORMED,
+ (String)act.getValue(Action.ACTION_COMMAND_KEY)));
+ }
+ });
+
+ cbTxtColor.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String color = (String) cbTxtColor.getSelectedItem();
+ Action act = null;
+
+ switch(color) {
+ case "Black":
+ act = new StyledEditorKit.ForegroundAction("Black", Color.black);
+ break;
+ case "Blue":
+ act = new StyledEditorKit.ForegroundAction("Blue", Color.blue);
+ break;
+ case "Yellow":
+ act = new StyledEditorKit.ForegroundAction("Yellow", Color.yellow);
+ break;
+ case "Red":
+ act = new StyledEditorKit.ForegroundAction("Red", Color.red);
+ break;
+ case "Green":
+ act = new StyledEditorKit.ForegroundAction("Green", Color.green);
+ break;
+ }
+
+ act.actionPerformed(new ActionEvent(act,ActionEvent.ACTION_PERFORMED,
+ (String)act.getValue(Action.ACTION_COMMAND_KEY)));
+ }
+ });
+
+
+ btnWysiwyg.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String tmp = txtDescription.getText();
+ if (txtDescription.getContentType().equals("text/html")) {
+ txtDescription.setContentType("text/plain");
+ txtDescription.setText(tmp);
+ btnWysiwyg.setText("Wysiwyg");
+
+ btnBold.setEnabled(false);
+ btnUnderline.setEnabled(false);
+ btnItalic.setEnabled(false);
+ cbTxtColor.setEnabled(false);
+ cbTxtSize.setEnabled(false);
+ } else {
+ txtDescription.setContentType("text/html");
+ txtDescription.setText(tmp);
+ btnWysiwyg.setText("Html");
+
+ btnBold.setEnabled(true);
+ btnUnderline.setEnabled(true);
+ btnItalic.setEnabled(true);
+ cbTxtColor.setEnabled(true);
+ cbTxtSize.setEnabled(true);
+ }
+ }
+ });
+
+ txtDescription.addKeyListener(new KeyListener() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ }
+
+ @Override
+ public void keyTyped(KeyEvent e) {
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ if (e.getKeyCode() == KeyEvent.VK_ENTER && txtDescription.getContentType().equals("text/html")) {
+ try {
+ kit.insertHTML((HTMLDocument) txtDescription.getDocument(), txtDescription.getCaretPosition(),
+ "<br>", 0, 0, HTML.Tag.BR);
+ txtDescription.setCaretPosition(txtDescription.getCaretPosition()); // This moves caret to next
+ // line
+ } catch (BadLocationException | IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+ });
}
+
+
@Override
protected boolean wantNextOrFinish() {
return reactToUserInput();