summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard
diff options
context:
space:
mode:
authorStephan Schwär2020-12-11 00:49:46 +0100
committerStephan Schwär2020-12-11 00:49:46 +0100
commitf0a78f80e0096732a30904a3e3d383b60b70e25c (patch)
tree2d0ca9f54423373ef7525be9398e46ff8a28d6e0 /dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard
parent[client] Prevent scaling of fonts multiple times (diff)
parent[client] improved htmleditor in imageMetadataPage (diff)
downloadtutor-module-f0a78f80e0096732a30904a3e3d383b60b70e25c.tar.gz
tutor-module-f0a78f80e0096732a30904a3e3d383b60b70e25c.tar.xz
tutor-module-f0a78f80e0096732a30904a3e3d383b60b70e25c.zip
Merge remote-tracking branch 'origin/feature/htmlEditorInDescrioptionText' into feature-merge
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java78
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureCreationPageLayout.java72
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java108
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java102
4 files changed, 340 insertions, 20 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java
index 707959f3..4e6257e3 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java
@@ -1,10 +1,17 @@
package org.openslx.dozmod.gui.wizard.layout;
+import java.awt.FlowLayout;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
+import javax.swing.JEditorPane;
+import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
+import javax.swing.JButton;
+import javax.swing.text.StyledEditorKit;
+import javax.swing.text.html.HTMLEditorKit;
+import java.awt.Dimension;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.control.ComboBox;
@@ -20,13 +27,23 @@ import org.openslx.thrifthelper.Comparators;
public abstract class ImageMetaDataPageLayout extends WizardPage {
protected final JComboBox<OperatingSystem> cboOperatingSystem;
- protected final JTextArea txtDescription;
+ protected final JEditorPane txtDescription;
protected final JTextArea startCommand;
protected final QLabel sCommandCaption;
protected final JScrollPane startCommandPane;
protected final JCheckBox chkLicenseRestricted;
protected final JCheckBox chkIsTemplate;
+ 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;
+
+
/**
* wizard page for entering image data at creating or editing an image
*
@@ -36,7 +53,7 @@ public abstract class ImageMetaDataPageLayout extends WizardPage {
super(wizard, I18n.PAGE_LAYOUT.getString("ImageMetaData.WizardPage.title"));
setDescription(I18n.PAGE_LAYOUT.getString("ImageMetaData.WizardPage.description"));
- GridManager grid = new GridManager(this, 2, false);
+ GridManager grid = new GridManager(this, 3, false);
QLabel osCaption = new QLabel(I18n.PAGE_LAYOUT.getString("ImageMetaData.Label.OS.text"));
cboOperatingSystem = new ComboBox<>(Comparators.operatingSystem, new ComboBoxRenderer<OperatingSystem>() {
@@ -49,7 +66,8 @@ public abstract class ImageMetaDataPageLayout extends WizardPage {
});
cboOperatingSystem.setEditable(false);
grid.add(osCaption);
- grid.add(cboOperatingSystem);
+ grid.add(cboOperatingSystem, 2);
+ grid.nextRow();
sCommandCaption = new QLabel(I18n.PAGE_LAYOUT.getString("ImageMetaData.Label.startCommand.text"));
startCommand = new JTextArea(1, 50);
@@ -61,29 +79,67 @@ public abstract class ImageMetaDataPageLayout extends WizardPage {
startCommandPane.setMinimumSize(startCommand.getMinimumSize());
grid.add(sCommandCaption);
grid.add(startCommandPane).fill(true, false).expand(true, false);
+ grid.add(new JPanel());
+ grid.nextRow();
+
+ // buttons for text editing
+ JPanel editingPanel = new JPanel();
+ 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", 15, this));
+ btnBold.setText("");
+ btnItalic = new JButton(new StyledEditorKit.ItalicAction());
+ 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", 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
QLabel descriptionCaption = new QLabel(I18n.PAGE_LAYOUT.getString("ImageMetaData.Label.description.text"));
- txtDescription = new JTextArea(5, 50);
+ txtDescription = new JEditorPane();
txtDescription.setMinimumSize(Gui.getScaledDimension(0, 70));
- txtDescription.setLineWrap(true);
- txtDescription.setWrapStyleWord(true);
- JScrollPane descPane = new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
+ kit = new HTMLEditorKit();
+ txtDescription.setEditorKit(kit);
+ txtDescription.setContentType("text/html");
+ JScrollPane descPane = new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
- descPane.setMinimumSize(txtDescription.getMinimumSize());
grid.add(descriptionCaption);
- grid.add(descPane).fill(true, false).expand(true, false);
+ grid.add(descPane, 2).fill(true, true).expand(true, true);
grid.nextRow();
chkLicenseRestricted = new JCheckBox(
I18n.PAGE_LAYOUT.getString("ImageMetaData.CheckBox.licenseRestricted.text"));
chkLicenseRestricted.setSelected(true);
- grid.add(chkLicenseRestricted, 2);
+ grid.add(chkLicenseRestricted, 3);
grid.nextRow();
// -- end permissions group --
chkIsTemplate = new JCheckBox(I18n.PAGE_LAYOUT.getString("ImageMetaData.CheckBox.isTemplate.text"));
- grid.add(chkIsTemplate, 2);
+ grid.add(chkIsTemplate, 3);
grid.nextRow();
grid.finish(true);
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 91abcf92..771dc60e 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,13 +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.JTextArea;
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;
@@ -17,22 +23,34 @@ import org.openslx.dozmod.gui.helper.I18n;
import org.openslx.dozmod.gui.wizard.Wizard;
import org.openslx.dozmod.gui.wizard.WizardPage;
+import java.awt.Dimension;
+import java.awt.GridLayout;
+
@SuppressWarnings("serial")
public abstract class LectureCreationPageLayout extends WizardPage {
protected final JTextField txtName;
- protected final JTextArea txtDescription;
+ protected final JEditorPane txtDescription;
protected final QDatePickerImpl dtpStartDate;
protected final QDatePickerImpl dtpEndDate;
protected final JSpinner spnStartTime;
protected final JSpinner spnEndTime;
protected final QLabel lblCalcPeriod;
+ 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
*
- * @param editExistingLecture whether to edit existing lecture or create new
- * one
+ * @param editExistingLecture whether to edit existing lecture or create new one
*/
public LectureCreationPageLayout(Wizard wizard, String title) {
super(wizard, title);
@@ -45,9 +63,49 @@ public abstract class LectureCreationPageLayout extends WizardPage {
grid.add(txtName, 2).fill(true, false).expand(true, false);
grid.nextRow();
- txtDescription = new JTextArea(3, 50);
- txtDescription.setLineWrap(true);
- txtDescription.setWrapStyleWord(true);
+ // buttons for text editing
+ JPanel editingPanel = new JPanel();
+ 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", 15, this));
+ btnBold.setText("");
+ btnItalic = new JButton(new StyledEditorKit.ItalicAction());
+ 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", 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,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
txtDescription.setMinimumSize(Gui.getScaledDimension(0, 60));
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java
index 6394ef79..c3fce45c 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java
@@ -4,6 +4,19 @@ import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Collections;
import java.util.List;
+import java.awt.Color;
+
+import javax.swing.Action;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.StyledEditorKit;
+import javax.swing.text.html.HTML;
+import javax.swing.text.html.HTMLDocument;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.io.IOException;
import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
@@ -71,8 +84,100 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout {
reactToUserInput();
}
});
+
+ 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 void onPageEnter() {
// Preselect OS if possible
@@ -107,8 +212,7 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout {
}
/**
- * Called by event listeners. This will set guidance message or error
- * message
+ * Called by event listeners. This will set guidance message or error message
* and call setPageComplete(bool) accordingly.
*/
private void reactToUserInput() {
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 17d71312..71e6fe6d 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;
@@ -67,8 +75,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();