From 42f2761a2a2781a502542a9ae87e756bf93237fa Mon Sep 17 00:00:00 2001 From: Kuersat Akmaz Date: Mon, 30 Nov 2020 23:29:06 +0100 Subject: [client] improved htmleditor in imageMetadataPage Issue : #3732 --- .../dozmod/gui/wizard/page/ImageMetaDataPage.java | 108 ++++++++++++++++++++- 1 file changed, 106 insertions(+), 2 deletions(-) (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java') 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(), + "
", 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() { -- cgit v1.2.3-55-g7522