summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKuersat Akmaz2020-11-30 23:29:06 +0100
committerKuersat Akmaz2020-11-30 23:29:06 +0100
commit42f2761a2a2781a502542a9ae87e756bf93237fa (patch)
tree7d7356f94a908c34ad6872aa7f98c7e8ec225c59
parent[client] fixed bug in htmleditor in lecturecreationpage (diff)
downloadtutor-module-42f2761a2a2781a502542a9ae87e756bf93237fa.tar.gz
tutor-module-42f2761a2a2781a502542a9ae87e756bf93237fa.tar.xz
tutor-module-42f2761a2a2781a502542a9ae87e756bf93237fa.zip
[client] improved htmleditor in imageMetadataPage
Issue : #3732
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java48
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java108
2 files changed, 143 insertions, 13 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 a0104ade..34b38395 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,5 +1,6 @@
package org.openslx.dozmod.gui.wizard.layout;
+import java.awt.FlowLayout;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JEditorPane;
@@ -8,9 +9,9 @@ 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 java.awt.GridLayout;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.control.ComboBox;
@@ -35,6 +36,12 @@ public abstract class ImageMetaDataPageLayout 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;
+
/**
* wizard page for entering image data at creating or editing an image
@@ -45,7 +52,7 @@ public abstract class ImageMetaDataPageLayout extends WizardPage {
super(wizard, "Metadaten");
setDescription("Geben Sie bitte einen aussagekräftigen Namen für die neue VM ein.");
- GridManager grid = new GridManager(this, 2, false);
+ GridManager grid = new GridManager(this, 3, false);
QLabel osCaption = new QLabel("Betriebssystem");
cboOperatingSystem = new ComboBox<>(Comparators.operatingSystem, new ComboBoxRenderer<OperatingSystem>() {
@@ -58,7 +65,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("Startbefehl");
startCommand = new JTextArea(1, 50);
@@ -70,47 +78,65 @@ 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 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);
- grid.add(editingPanel);
+ 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("Beschreibung");
txtDescription = new JEditorPane();
+ kit = new HTMLEditorKit();
+ txtDescription.setEditorKit(kit);
txtDescription.setContentType("text/html");
JScrollPane descPane = new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
grid.add(descriptionCaption);
- grid.add(descPane).fill(true, true).expand(true, true);
+ grid.add(descPane, 2).fill(true, true).expand(true, true);
grid.nextRow();
chkLicenseRestricted = new JCheckBox("VM enthält lizenzpflichtige Software");
chkLicenseRestricted.setSelected(true);
- grid.add(chkLicenseRestricted, 2);
+ grid.add(chkLicenseRestricted, 3);
grid.nextRow();
// -- end permissions group --
chkIsTemplate = new JCheckBox("Vorlage erstellen");
- 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/page/ImageMetaDataPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java
index 1ec57fce..33ff5cd5 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;
@@ -70,8 +83,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
@@ -106,8 +211,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() {