From e4d03898f1cf6e7804a272e6a82a4a390c944b06 Mon Sep 17 00:00:00 2001 From: Kuersat Akmaz Date: Fri, 16 Oct 2020 23:58:46 +0200 Subject: [client] added small html editor in LectureDescriptonWindow Issue : #3732 --- .../window/layout/LectureDetailsWindowLayout.java | 37 +++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'dozentenmodul/src/main/java') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java index 0dc3cee2..0f01fd61 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java @@ -7,13 +7,16 @@ import java.awt.Frame; import java.awt.GridBagConstraints; import java.awt.Insets; import java.util.Calendar; +import java.awt.GridLayout; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JDialog; +import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -23,6 +26,7 @@ import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SpinnerDateModel; import javax.swing.text.DateFormatter; +import javax.swing.text.StyledEditorKit; import org.jdatepicker.JDatePicker; import org.openslx.bwlp.thrift.iface.ImageVersionDetails; @@ -53,7 +57,7 @@ public abstract class LectureDetailsWindowLayout extends JDialog { // stuff ending in '...Info' are supposed to be the read-only labels for the information tab protected final QLabel lblTitleInfo; protected final JTextField txtTitle; - protected final JTextArea txtDescription; + protected final JEditorPane txtDescription; protected final QLabel lblImageNameInfo; protected final QLabel txtImageName; protected final JButton btnLinkImage; @@ -106,6 +110,11 @@ public abstract class LectureDetailsWindowLayout extends JDialog { protected final JPanel pnlTabNetshare; protected final JPanel pnlTabLdapFilter; + protected final JButton btnBold; + protected final JButton btnItalic; + protected final JButton btnUnderline; + + public LectureDetailsWindowLayout(Frame modalParent) { super(modalParent, "Veranstaltungsdetails", ModalityType.APPLICATION_MODAL); setResizable(true); @@ -174,10 +183,30 @@ public abstract class LectureDetailsWindowLayout extends JDialog { grdGeneral.add(txtTitle, 4).expand(true, false).fill(true, false); grdGeneral.nextRow(); + // buttons for text editing + JPanel editingPanel = new JPanel(); + editingPanel.setLayout(new GridLayout(1,3)); + JPanel emptyPanel = new JPanel(); + grdGeneral.add(emptyPanel); + btnBold = new JButton( new StyledEditorKit.BoldAction()); + btnBold.setIcon(Gui.getScaledIconResource("/img/bold.png", "B", 24, this)); + btnBold.setText(""); + btnItalic = new JButton(new StyledEditorKit.ItalicAction() ); + btnItalic.setIcon(Gui.getScaledIconResource("/img/italic.png", "B", 24, this)); + btnItalic.setText(""); + btnUnderline = new JButton(new StyledEditorKit.UnderlineAction() ); + btnUnderline.setIcon(Gui.getScaledIconResource("/img/underline.png", "B", 24, this)); + btnUnderline.setText(""); + grdGeneral.add(btnBold); + grdGeneral.add(btnItalic); + grdGeneral.add(btnUnderline); + grdGeneral.add(editingPanel); + + grdGeneral.nextRow(); + // description - txtDescription = new JTextArea(); - txtDescription.setLineWrap(true); - txtDescription.setWrapStyleWord(true); + txtDescription = new JEditorPane(); + txtDescription.setContentType("text/html"); grdGeneral.add(new QLabel("Beschreibung")).anchor(GridBagConstraints.FIRST_LINE_START); JScrollPane jsp = new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); -- cgit v1.2.3-55-g7522 From f78fef2c587784852f276725876c2b1e1f370563 Mon Sep 17 00:00:00 2001 From: Kuersat Akmaz Date: Sat, 17 Oct 2020 14:00:30 +0200 Subject: [client] added small html Editor in LectureCreationpage Issue : #3727 --- .../wizard/layout/LectureCreationPageLayout.java | 45 ++++++++++++++++++---- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'dozentenmodul/src/main/java') 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 5df21c1d..c184b3e2 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 @@ -4,10 +4,13 @@ import java.util.Calendar; 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.JEditorPane; import javax.swing.SpinnerDateModel; import javax.swing.text.DateFormatter; +import javax.swing.text.StyledEditorKit; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.control.QDatePickerImpl; @@ -16,22 +19,28 @@ import org.openslx.dozmod.gui.helper.GridManager; 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; + /** * 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); @@ -44,9 +53,31 @@ 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 GridLayout(1, 3)); + JPanel emptyPanel = new JPanel(); + grid.add(emptyPanel); + btnBold = new JButton(new StyledEditorKit.BoldAction()); + btnBold.setIcon(Gui.getScaledIconResource("/img/bold.png", "B", 24, this)); + btnBold.setText(""); + btnItalic = new JButton(new StyledEditorKit.ItalicAction()); + btnItalic.setIcon(Gui.getScaledIconResource("/img/italic.png", "B", 24, this)); + btnItalic.setText(""); + btnUnderline = new JButton(new StyledEditorKit.UnderlineAction()); + btnUnderline.setIcon(Gui.getScaledIconResource("/img/underline.png", "B", 24, this)); + btnUnderline.setText(""); + editingPanel.add(btnBold); + editingPanel.add(btnItalic); + editingPanel.add(btnUnderline); + grid.add(editingPanel); + grid.add(emptyPanel); + grid.nextRow(); + + // description + txtDescription = new JEditorPane(); + 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)); -- cgit v1.2.3-55-g7522 From 90f96226cec258f5b24cc5ec7349aa9db9ad0944 Mon Sep 17 00:00:00 2001 From: Kuersat Akmaz Date: Sat, 17 Oct 2020 21:47:52 +0200 Subject: [client] Added Html editor into ImageCreationPage Issue : #3732 --- .../dozmod/gui/window/ImageDetailsWindow.java | 3 + .../window/layout/ImageDetailsWindowLayout.java | 75 ++++++++++++++++------ .../gui/wizard/layout/ImageMetaDataPageLayout.java | 45 ++++++++++--- 3 files changed, 97 insertions(+), 26 deletions(-) (limited to 'dozentenmodul/src/main/java') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java index 211ff1b7..c8d3b5a2 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java @@ -821,6 +821,9 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe editable = editable && (ImagePerms.canEdit(image) || ImagePerms.canAdmin(image)); txtTitle.setEditable(editable); txtDescription.setEditable(editable); + btnBold.setEnabled(editable); + btnItalic.setEnabled(editable); + btnUnderline.setEnabled(editable); txtTags.setEditable(editable); cboOperatingSystem.setEnabled(editable); // cboShareMode.setEnabled(editable); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java index 2792e9fd..040fffa5 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java @@ -6,6 +6,7 @@ import java.awt.Font; import java.awt.Frame; import java.awt.GridBagConstraints; import java.awt.Insets; +import java.awt.GridLayout; import javax.swing.BorderFactory; import javax.swing.Box; @@ -13,6 +14,7 @@ import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JDialog; +import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; @@ -20,6 +22,8 @@ import javax.swing.JScrollPane; import javax.swing.JTabbedPane; import javax.swing.JTextArea; import javax.swing.JTextField; +import javax.swing.text.StyledEditorKit; +import javax.swing.JEditorPane; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.ShareMode; @@ -40,7 +44,7 @@ public abstract class ImageDetailsWindowLayout extends JDialog { private static final int ICON_SIZE_Y = 24; protected final JTextField txtTitle; - protected final JTextArea txtDescription; + protected final JEditorPane txtDescription; protected QLabel lblError; protected final PersonLabel lblOwner; @@ -74,6 +78,10 @@ public abstract class ImageDetailsWindowLayout extends JDialog { protected final ImageVersionTable tblVersions; protected final QScrollPane scpVersions; + protected final JButton btnBold; + protected final JButton btnItalic; + protected final JButton btnUnderline; + protected JTabbedPane pnlTabs; protected ImagePermissionConfigurator ctlImagePermissionConfigurator; @@ -88,9 +96,11 @@ public abstract class ImageDetailsWindowLayout extends JDialog { setPreferredSize(Gui.getScaledDimension(630, 680)); ((JPanel) getContentPane()).setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - /* ******************************************************************************* + /* + * ***************************************************************************** + * ** * - * Tab: Overview + * Tab: Overview * ********************************************************************************/ JPanel pnlTabOverview = new JPanel(); @@ -98,14 +108,34 @@ public abstract class ImageDetailsWindowLayout extends JDialog { // name txtTitle = new JTextField(); txtTitle.setFont(txtTitle.getFont().deriveFont(Font.BOLD, txtTitle.getFont().getSize2D() * 1.4f)); - //txtTitle.setMinimumSize(Gui.getScaledDimension(0, 24)); + // txtTitle.setMinimumSize(Gui.getScaledDimension(0, 24)); grid.add(txtTitle, 3).expand(true, false).fill(true, false); grid.nextRow(); + // buttons for text editing + JPanel editingPanel = new JPanel(); + editingPanel.setLayout(new GridLayout(1, 3)); + JPanel emptyPanel = new JPanel(); + grid.add(emptyPanel); + btnBold = new JButton(new StyledEditorKit.BoldAction()); + btnBold.setIcon(Gui.getScaledIconResource("/img/bold.png", "B", 24, this)); + btnBold.setText(""); + btnItalic = new JButton(new StyledEditorKit.ItalicAction()); + btnItalic.setIcon(Gui.getScaledIconResource("/img/italic.png", "B", 24, this)); + btnItalic.setText(""); + btnUnderline = new JButton(new StyledEditorKit.UnderlineAction()); + btnUnderline.setIcon(Gui.getScaledIconResource("/img/underline.png", "B", 24, this)); + btnUnderline.setText(""); + editingPanel.add(btnBold); + editingPanel.add(btnItalic); + editingPanel.add(btnUnderline); + grid.add(editingPanel); + grid.add(emptyPanel); + grid.nextRow(); + // description - txtDescription = new JTextArea(); - txtDescription.setLineWrap(true); - txtDescription.setWrapStyleWord(true); + txtDescription = new JEditorPane(); + txtDescription.setContentType("text/html"); grid.add(new QLabel("Beschreibung")).anchor = GridBagConstraints.FIRST_LINE_START; JScrollPane jsp = new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); @@ -216,12 +246,14 @@ public abstract class ImageDetailsWindowLayout extends JDialog { buttonBar.add(btnUploadToMaster); grid.add(buttonBar, 3).fill(true, false).expand(true, false); grid.nextRow(); - + grid.finish(false); - /* ******************************************************************************* + /* + * ***************************************************************************** + * ** * - * Tab: VM versions + * Tab: VM versions * ********************************************************************************/ JPanel pnlTabVersions = new JPanel(); @@ -231,14 +263,17 @@ public abstract class ImageDetailsWindowLayout extends JDialog { grdVersions.add(scpVersions).fill(true, true).expand(true, true); grdVersions.finish(false); - /* ******************************************************************************* + /* + * ***************************************************************************** + * ** * - * Tab: Permissions + * Tab: Permissions * ********************************************************************************/ JPanel pnlTabPermissions = new JPanel(); ctlImagePermissionConfigurator = new ImagePermissionConfigurator(); - GridManager grdImagePermissionConfigurator = new GridManager(pnlTabPermissions, 1, false, new Insets(8, 2, 8, 2)); + GridManager grdImagePermissionConfigurator = new GridManager(pnlTabPermissions, 1, false, + new Insets(8, 2, 8, 2)); grdImagePermissionConfigurator.add(ctlImagePermissionConfigurator).fill(true, true).expand(true, true); // Panel with the permissions for other users JPanel defaultPermissionPane = new JPanel(); @@ -268,9 +303,11 @@ public abstract class ImageDetailsWindowLayout extends JDialog { grdImagePermissionConfigurator.add(defaultPermissionPane).fill(true, false).expand(false, false); grdImagePermissionConfigurator.finish(false); - /* ******************************************************************************* + /* + * ***************************************************************************** + * ** * - * Bottom panel for buttons + * Bottom panel for buttons * ********************************************************************************/ JPanel pnlButtons = new JPanel(); @@ -286,16 +323,18 @@ public abstract class ImageDetailsWindowLayout extends JDialog { pnlButtons.add(btnClose); pnlButtons.add(btnSaveChanges); - /* ******************************************************************************* + /* + * ***************************************************************************** + * ** * - * Main panel containing the tabs + * Main panel containing the tabs * ********************************************************************************/ pnlTabs = new JTabbedPane(); pnlTabs.addTab("Übersicht", pnlTabOverview); pnlTabs.addTab("VM-Versionen", pnlTabVersions); pnlTabs.addTab("Berechtigungen", pnlTabPermissions); - + add(pnlTabs, BorderLayout.CENTER); add(pnlButtons, BorderLayout.PAGE_END); } 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 358fdd0d..a0104ade 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 @@ -2,9 +2,15 @@ package org.openslx.dozmod.gui.wizard.layout; 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 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; @@ -19,13 +25,17 @@ import org.openslx.thrifthelper.Comparators; public abstract class ImageMetaDataPageLayout extends WizardPage { protected final JComboBox 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; + /** * wizard page for entering image data at creating or editing an image * @@ -62,16 +72,35 @@ public abstract class ImageMetaDataPageLayout extends WizardPage { grid.add(startCommandPane).fill(true, false).expand(true, false); grid.nextRow(); + // buttons for text editing + JPanel editingPanel = new JPanel(); + editingPanel.setLayout(new GridLayout(1, 3)); + JPanel emptyPanel = new JPanel(); + grid.add(emptyPanel); + btnBold = new JButton(new StyledEditorKit.BoldAction()); + btnBold.setIcon(Gui.getScaledIconResource("/img/bold.png", "B", 24, this)); + btnBold.setText(""); + btnItalic = new JButton(new StyledEditorKit.ItalicAction()); + btnItalic.setIcon(Gui.getScaledIconResource("/img/italic.png", "B", 24, this)); + btnItalic.setText(""); + btnUnderline = new JButton(new StyledEditorKit.UnderlineAction()); + btnUnderline.setIcon(Gui.getScaledIconResource("/img/underline.png", "B", 24, this)); + btnUnderline.setText(""); + editingPanel.add(btnBold); + editingPanel.add(btnItalic); + editingPanel.add(btnUnderline); + grid.add(editingPanel); + + grid.nextRow(); + + // description QLabel descriptionCaption = new QLabel("Beschreibung"); - txtDescription = new JTextArea(5, 50); - txtDescription.setMinimumSize(Gui.getScaledDimension(0, 70)); - txtDescription.setLineWrap(true); - txtDescription.setWrapStyleWord(true); - JScrollPane descPane = new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + txtDescription = new JEditorPane(); + 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).fill(true, true).expand(true, true); grid.nextRow(); chkLicenseRestricted = new JCheckBox("VM enthält lizenzpflichtige Software"); -- cgit v1.2.3-55-g7522 From db588481b004b0c3d22b906f693bbc00f6eda042 Mon Sep 17 00:00:00 2001 From: Kuersat Akmaz Date: Thu, 12 Nov 2020 21:42:16 +0100 Subject: [client] added text sizing and color to htmleditor in imagedetailswindow Issue : #3732 --- .../dozmod/gui/window/ImageDetailsWindow.java | 42 ++++++++++++++++++++++ .../window/layout/ImageDetailsWindowLayout.java | 31 +++++++++++----- 2 files changed, 65 insertions(+), 8 deletions(-) (limited to 'dozentenmodul/src/main/java') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java index c8d3b5a2..7a89c54d 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import javax.swing.AbstractAction; +import javax.swing.Action; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JMenuItem; @@ -27,6 +28,7 @@ import javax.swing.JOptionPane; import javax.swing.KeyStroke; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; +import javax.swing.text.StyledEditorKit; import org.apache.log4j.Logger; import org.apache.thrift.TException; @@ -230,6 +232,46 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } }); + 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))); + } + }); + + tblVersions.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); /** diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java index 040fffa5..9490bc72 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java @@ -2,17 +2,19 @@ package org.openslx.dozmod.gui.window.layout; import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Dimension; import java.awt.Font; import java.awt.Frame; import java.awt.GridBagConstraints; import java.awt.Insets; -import java.awt.GridLayout; +import java.awt.FlowLayout; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JCheckBox; +import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JEditorPane; import javax.swing.JFrame; @@ -20,7 +22,6 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; -import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.text.StyledEditorKit; import javax.swing.JEditorPane; @@ -81,7 +82,9 @@ public abstract class ImageDetailsWindowLayout extends JDialog { protected final JButton btnBold; protected final JButton btnItalic; protected final JButton btnUnderline; - + protected final JComboBox cbTxtSize; + protected final JComboBox cbTxtColor; + protected JTabbedPane pnlTabs; protected ImagePermissionConfigurator ctlImagePermissionConfigurator; @@ -114,22 +117,34 @@ public abstract class ImageDetailsWindowLayout extends JDialog { // 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(100,25)); + editingPanel.add(cbTxtColor); + + grid.add(editingPanel).expand(false, true); grid.add(emptyPanel); grid.nextRow(); -- cgit v1.2.3-55-g7522 From d12529b1e3c07dacd7c2d96aa597d5e5e9bd750c Mon Sep 17 00:00:00 2001 From: Kuersat Akmaz Date: Thu, 12 Nov 2020 22:31:59 +0100 Subject: [client] added WYSIWYG button into image datailswindow Issue : #3732 --- .../openslx/dozmod/gui/window/ImageDetailsWindow.java | 19 +++++++++++++++++++ .../gui/window/layout/ImageDetailsWindowLayout.java | 8 ++++++++ 2 files changed, 27 insertions(+) (limited to 'dozentenmodul/src/main/java') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java index 7a89c54d..764cf7eb 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java @@ -271,6 +271,22 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } }); + 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"); + } else { + txtDescription.setContentType("text/html"); + txtDescription.setText(tmp); + btnWysiwyg.setText("Html"); + } + } + }); + tblVersions.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); @@ -866,6 +882,9 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe btnBold.setEnabled(editable); btnItalic.setEnabled(editable); btnUnderline.setEnabled(editable); + btnWysiwyg.setEnabled(editable); + cbTxtColor.setEnabled(editable); + cbTxtSize.setEnabled(editable); txtTags.setEditable(editable); cboOperatingSystem.setEnabled(editable); // cboShareMode.setEnabled(editable); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java index 9490bc72..f2609e89 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java @@ -82,6 +82,8 @@ public abstract class ImageDetailsWindowLayout extends JDialog { protected final JButton btnBold; protected final JButton btnItalic; protected final JButton btnUnderline; + protected final JButton btnWysiwyg; + protected final JComboBox cbTxtSize; protected final JComboBox cbTxtColor; @@ -145,6 +147,12 @@ public abstract class ImageDetailsWindowLayout extends JDialog { editingPanel.add(cbTxtColor); grid.add(editingPanel).expand(false, true); + + emptyPanel.setLayout(new FlowLayout()); + btnWysiwyg = new JButton("HTML"); + btnWysiwyg.setPreferredSize(new Dimension(100,25)); + emptyPanel.add(btnWysiwyg); + grid.add(emptyPanel); grid.nextRow(); -- cgit v1.2.3-55-g7522 From c71369bccd6bbd081e9d1e5daf54b249a1606274 Mon Sep 17 00:00:00 2001 From: Kuersat Akmaz Date: Mon, 30 Nov 2020 21:06:01 +0100 Subject: [client] added fixed htmleditor to imagedetailswindow Issue : #3732 --- .../dozmod/gui/window/ImageDetailsWindow.java | 138 +++++++++++++-------- .../window/layout/ImageDetailsWindowLayout.java | 10 +- 2 files changed, 93 insertions(+), 55 deletions(-) (limited to 'dozentenmodul/src/main/java') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java index 764cf7eb..fc68c708 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java @@ -7,10 +7,13 @@ import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.beans.Encoder; +import java.io.IOException; import java.nio.ByteBuffer; import java.util.Collections; import java.util.Comparator; @@ -28,7 +31,12 @@ import javax.swing.JOptionPane; import javax.swing.KeyStroke; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; +import javax.swing.text.BadLocationException; +import javax.swing.text.DefaultEditorKit; import javax.swing.text.StyledEditorKit; +import javax.swing.text.html.HTML; +import javax.swing.text.html.HTMLDocument; +import javax.swing.text.html.HTMLEditorKit; import org.apache.log4j.Logger; import org.apache.thrift.TException; @@ -266,8 +274,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe break; } - act.actionPerformed(new ActionEvent(act,ActionEvent.ACTION_PERFORMED, - (String)act.getValue(Action.ACTION_COMMAND_KEY))); + act.actionPerformed(new ActionEvent(act,ActionEvent.ACTION_PERFORMED, + (String)act.getValue(Action.ACTION_COMMAND_KEY))); } }); @@ -275,18 +283,43 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe @Override public void actionPerformed(ActionEvent e) { String tmp = txtDescription.getText(); - if (txtDescription.getContentType().equals("text/html")){ - txtDescription.setContentType("text/plain"); + if (txtDescription.getContentType().equals("text/html")) { + txtDescription.setContentType("text/plain"); txtDescription.setText(tmp); btnWysiwyg.setText("Wysiwyg"); + if(ImagePerms.canEdit(image) || ImagePerms.canAdmin(image)) { + btnSaveChanges.setEnabled(true); + } } else { - txtDescription.setContentType("text/html"); + txtDescription.setContentType("text/html"); txtDescription.setText(tmp); btnWysiwyg.setText("Html"); } } }); + 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(); + } + } + } + }); tblVersions.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); @@ -473,8 +506,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe @Override public void run() { if (machineDescription == null) { - Gui.showMessageBox("Konnte VM-Konfiguration nicht abrufen.", MessageType.ERROR, - LOGGER, null); + Gui.showMessageBox("Konnte VM-Konfiguration nicht abrufen.", MessageType.ERROR, LOGGER, + null); return; } @@ -498,9 +531,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe * ********************************************************************************/ /** - * Sets the image to the given imageBaseId. This will also trigger fill() - * which will set the image details fields to the values represented by this - * image. + * Sets the image to the given imageBaseId. This will also trigger fill() which + * will set the image details fields to the values represented by this image. * * @param imageBaseId the id of the image to be displayed */ @@ -510,8 +542,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe MetaDataCache.getVirtualizers(); final ImageMetaCallback callback = new ImageMetaCallback() { @Override - public void fetchedImageDetails(ImageDetailsRead imageDetails, - Map permissions) { + public void fetchedImageDetails(ImageDetailsRead imageDetails, Map permissions) { if (imageDetails == null) { return; } @@ -540,8 +571,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe if (!actionHandler.setImageOwner(image.getImageBaseId(), user)) { return; } - Gui.showMessageBox(me, "Besitzrechte übertragen an " + FormatHelper.userName(user), MessageType.INFO, - null, null); + Gui.showMessageBox(me, "Besitzrechte übertragen an " + FormatHelper.userName(user), MessageType.INFO, null, + null); makeEditable(false); refresh(true); } @@ -568,8 +599,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } } // let the user confirm or abort - if (!Gui.showMessageBox("Wollen Sie diese VM wirklich landesweit veröffentlichen?", - MessageType.QUESTION_YESNO, null, null)) + if (!Gui.showMessageBox("Wollen Sie diese VM wirklich landesweit veröffentlichen?", MessageType.QUESTION_YESNO, + null, null)) return; // start upload to masterserver QuickTimer.scheduleOnce(new Task() { @@ -580,11 +611,10 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe transferId = ThriftManager.getSatClient().publishImageVersion(Session.getSatelliteToken(), image.latestVersionId); } catch (TException e1) { - ThriftError.showMessage(me, LOGGER, e1, - "Upload der VM auf den Masterserver fehlgeschlagen." - + " Prüfen Sie, ob Sie bei der Registrierung dem landesweiten VM-Austausch zugestimmt haben.\n" - + " Sie können dies hier überprüfen:\n" - + DesktopEnvironment.Link.REGISTER_BWIDM.uri.toString() + "\n\n"); + ThriftError.showMessage(me, LOGGER, e1, "Upload der VM auf den Masterserver fehlgeschlagen." + + " Prüfen Sie, ob Sie bei der Registrierung dem landesweiten VM-Austausch zugestimmt haben.\n" + + " Sie können dies hier überprüfen:\n" + + DesktopEnvironment.Link.REGISTER_BWIDM.uri.toString() + "\n\n"); return; } Gui.asyncExec(new Runnable() { @@ -593,9 +623,9 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe MainWindow.addPassiveTransfer(transferId, image.imageName, true); // Inform user Gui.showMessageBox(ImageDetailsWindow.this, - "Die Übertragung läuft direkt zwischen Satellitenserver und" - + " dem " + Branding.getServiceName() + " Zentral-Server.\n" - + "Wenn Sie die " + Branding.getApplicationName() + " schließen, wird der Transfer trotzdem" + "Die Übertragung läuft direkt zwischen Satellitenserver und" + " dem " + + Branding.getServiceName() + " Zentral-Server.\n" + "Wenn Sie die " + + Branding.getApplicationName() + " schließen, wird der Transfer trotzdem" + "weiterlaufen.", MessageType.INFO, null, null); } @@ -605,8 +635,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } /** - * Called by the "Save" button, tries to save the changes internally and - * then react based depending on the outcome of the save + * Called by the "Save" button, tries to save the changes internally and then + * react based depending on the outcome of the save */ private void saveChanges() { boolean saved = saveChangesInternal(); @@ -622,15 +652,16 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } /** - * Helper to only save the changes, nothing else. Updating GUI elements is - * done by saveChanges() + * Helper to only save the changes, nothing else. Updating GUI elements is done + * by saveChanges() * * @return false if any try to save changes failed, true otherwise */ private boolean saveChangesInternal() { // Special case: User has admin rights through default permissions - // -> user removes default admin permissions - // -> first save custom permissions, then the rest (including default permissions) + // -> user removes default admin permissions + // -> first save custom permissions, then the rest (including default + // permissions) if (adminRightsFromDefaultPermissions && changeListenerPermissions.isCurrentlyChanged()) { if (!saveCustomPermissions()) { return false; @@ -648,8 +679,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe actionHandler.updateImageBase(image.getImageBaseId(), ibw); LOGGER.info("Successfully saved new metadata"); } catch (TException e) { - ThriftError.showMessage(me, LOGGER, e, - "Konnte aktualisierte Metadaten nicht an den Server übermitteln"); + ThriftError.showMessage(me, LOGGER, e, "Konnte aktualisierte Metadaten nicht an den Server übermitteln"); return false; } @@ -674,8 +704,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe ctlImagePermissionConfigurator.getPermissions()); LOGGER.info("Successfully saved new custom permissions"); } catch (TException e) { - ThriftError.showMessage(me, LOGGER, e, - "Konnte geänderte Berechtigungen nicht an den Server übermitteln"); + ThriftError.showMessage(me, LOGGER, e, "Konnte geänderte Berechtigungen nicht an den Server übermitteln"); return false; } return true; @@ -691,10 +720,11 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe Gui.showMessageBox(this, "Ausgewählte Version ist ungültig", MessageType.ERROR, null, null); return; } - // using actionHandler here is not needed, as this ThriftAction works for downloads + // using actionHandler here is not needed, as this ThriftAction works for + // downloads // from either the master server or the satellite server - ThriftActions.initDownload(JOptionPane.getFrameForComponent(this), selected.versionId, - image.imageName, image.virtId, image.osId, selected.fileSize, null); + ThriftActions.initDownload(JOptionPane.getFrameForComponent(this), selected.versionId, image.imageName, + image.virtId, image.osId, selected.fileSize, null); } /** @@ -727,15 +757,16 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } /** - * Extends the expiration date for given image versions to current date - * plus the user-supplied duration. + * Extends the expiration date for given image versions to current date plus the + * user-supplied duration. * * @param versions to extend the validity of */ private void extendVersionExpiry(List versions) { int daysToExtend = -1; if (versions.size() > 1) { - // more than one version given, ask the user once and use the value for all versions. + // more than one version given, ask the user once and use the value for all + // versions. daysToExtend = ExpiryDateChooser.askFutureExpiryDuration(this, null); if (daysToExtend == -1) return; @@ -749,7 +780,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe if (daysToExtend == -1) return; } - currentExpiryTimeAsDate = DateTimeHelper.addDaysTo(currentExpiryTimeAsDate, daysToExtend); + currentExpiryTimeAsDate = DateTimeHelper.addDaysTo(currentExpiryTimeAsDate, daysToExtend); try { ThriftManager.getSatClient().setImageVersionExpiry(Session.getSatelliteToken(), img.versionId, currentExpiryTimeAsDate.getTime() / 1000L); @@ -760,8 +791,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } } if (count > 0) { - Gui.showMessageBox(this, "Erfolgreich verlängerte Abbilder: " + count, MessageType.INFO, null, - null); + Gui.showMessageBox(this, "Erfolgreich verlängerte Abbilder: " + count, MessageType.INFO, null, null); refresh(true); } } @@ -836,7 +866,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } txtTags.setText(tagsString); - // init permissions, remember if the user had admin rights through default permissions + // init permissions, remember if the user had admin rights through default + // permissions adminRightsFromDefaultPermissions = image.defaultPermissions.admin; ctlImagePermissionConfigurator.initPanel(customPermissions, image.defaultPermissions, image.ownerId); chkDefaultPermAdmin.setSelected(image.defaultPermissions.admin); @@ -908,11 +939,14 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe win.setVisible(true); } - /* ******************************************************************************* + /* + * ***************************************************************************** + * ** * * Dialog class overrides * - * ******************************************************************************* + * ***************************************************************************** + * ** */ @SuppressWarnings("deprecation") @Override @@ -924,11 +958,14 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe super.show(); } - /* ******************************************************************************* + /* + * ***************************************************************************** + * ** * * UIFeedback implementation * - * ******************************************************************************* + * ***************************************************************************** + * ** */ @Override public boolean wantConfirmQuit() { @@ -945,9 +982,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe * confirmation if so */ private boolean safeClose() { - if (changeMonitor.isCurrentlyModified() - && !Gui.showMessageBox(me, "Änderungen werden verworfen, wollen Sie wirklich schließen?", - MessageType.QUESTION_YESNO, null, null)) + if (changeMonitor.isCurrentlyModified() && !Gui.showMessageBox(me, + "Änderungen werden verworfen, wollen Sie wirklich schließen?", MessageType.QUESTION_YESNO, null, null)) return false; dispose(); return true; diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java index f2609e89..0d5cfd0f 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java @@ -24,7 +24,7 @@ import javax.swing.JScrollPane; import javax.swing.JTabbedPane; import javax.swing.JTextField; import javax.swing.text.StyledEditorKit; -import javax.swing.JEditorPane; +import javax.swing.text.html.HTMLEditorKit; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.ShareMode; @@ -83,10 +83,10 @@ public abstract class ImageDetailsWindowLayout extends JDialog { protected final JButton btnItalic; protected final JButton btnUnderline; protected final JButton btnWysiwyg; - + protected final JComboBox cbTxtSize; protected final JComboBox cbTxtColor; - + protected final HTMLEditorKit kit; protected JTabbedPane pnlTabs; protected ImagePermissionConfigurator ctlImagePermissionConfigurator; @@ -113,7 +113,6 @@ public abstract class ImageDetailsWindowLayout extends JDialog { // name txtTitle = new JTextField(); txtTitle.setFont(txtTitle.getFont().deriveFont(Font.BOLD, txtTitle.getFont().getSize2D() * 1.4f)); - // txtTitle.setMinimumSize(Gui.getScaledDimension(0, 24)); grid.add(txtTitle, 3).expand(true, false).fill(true, false); grid.nextRow(); @@ -158,7 +157,10 @@ public abstract class ImageDetailsWindowLayout extends JDialog { // description txtDescription = new JEditorPane(); + kit = new HTMLEditorKit(); + txtDescription.setEditorKit(kit); txtDescription.setContentType("text/html"); + grid.add(new QLabel("Beschreibung")).anchor = GridBagConstraints.FIRST_LINE_START; JScrollPane jsp = new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); -- cgit v1.2.3-55-g7522 From 2176ce2893fc40284aaa70978324aebc5ba19e50 Mon Sep 17 00:00:00 2001 From: Kuersat Akmaz Date: Mon, 30 Nov 2020 22:14:07 +0100 Subject: [client] fixed htmleditor in LectureDetailsWindown Issue : #3732 --- .../dozmod/gui/window/ImageDetailsWindow.java | 12 + .../dozmod/gui/window/LectureDetailsWindow.java | 251 +++++++++++++++------ .../window/layout/ImageDetailsWindowLayout.java | 2 +- .../window/layout/LectureDetailsWindowLayout.java | 56 ++++- 4 files changed, 240 insertions(+), 81 deletions(-) (limited to 'dozentenmodul/src/main/java') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java index fc68c708..115864c9 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java @@ -290,10 +290,22 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe if(ImagePerms.canEdit(image) || ImagePerms.canAdmin(image)) { btnSaveChanges.setEnabled(true); } + + 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); } } }); 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 19e30fff..bd45f6f1 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 @@ -1,5 +1,6 @@ package org.openslx.dozmod.gui.window; +import java.awt.Color; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -7,6 +8,9 @@ import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.io.IOException; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; @@ -16,11 +20,18 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import javax.swing.Action; import javax.swing.DefaultComboBoxModel; +import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; +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.commons.codec.language.ColognePhonetic; import org.apache.log4j.Logger; import org.apache.thrift.TException; import org.openslx.bwlp.thrift.iface.ImageDetailsRead; @@ -98,7 +109,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements * Image, that the lecture is linked to. */ private ImageDetailsRead image = null; - + /** * Per-User permissions of this lecture */ @@ -113,11 +124,11 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements private final AbstractControlWrapper changeListenerPermissions; - /** + /** * Constructor * * @param modalParent parent of this popup window - * @param callback function to be called when a lecture update occured + * @param callback function to be called when a lecture update occured */ public LectureDetailsWindow(Frame modalParent, LectureUpdatedCallback callback) { super(modalParent); @@ -126,7 +137,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements this.callback = callback; setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - + // Set up change monitor changeMonitor = new DialogChangeMonitor(new DialogChangeMonitor.Callback() { @Override @@ -135,6 +146,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements btnSaveChanges.setEnabled(changeMonitor.isValid() && changeMonitor.wasEverModified()); LOGGER.info("Valid: " + changeMonitor.isValid()); } + @Override public void modificationChanged() { btnSaveChanges.setEnabled(changeMonitor.isValid() && changeMonitor.wasEverModified()); @@ -144,8 +156,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements // Add controls to change monitor changeMonitor.addFixedCombo(cboVersions, Comparators.imageVersionDetails) - .addConstraint( - new DialogChangeMonitor.ValidationConstraint() { + .addConstraint(new DialogChangeMonitor.ValidationConstraint() { public String checkStateValid(ImageVersionDetails userInput) { if (userInput != null && userInput.isValid) return null; @@ -175,19 +186,23 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements changeMonitor.add(chkIsActive); changeMonitor.add(chkCustomPermAdmin); changeMonitor.add(chkCustomPermEdit); - changeMonitor.add(txtTitle).addConstraint(new TextNotEmptyConstraint("Veranstaltungsname darf nicht leer sein")); - changeMonitor.add(txtDescription).addConstraint(new TextNotEmptyConstraint("Beschreibung darf nicht leer sein")); + changeMonitor.add(txtTitle) + .addConstraint(new TextNotEmptyConstraint("Veranstaltungsname darf nicht leer sein")); + changeMonitor.add(txtDescription) + .addConstraint(new TextNotEmptyConstraint("Beschreibung darf nicht leer sein")); changeMonitor.add(dtpEndDate).addConstraint(dateRangeValidator); changeMonitor.add(dtpStartDate).addConstraint(dateRangeValidator); changeMonitor.add(spnEndTime).addConstraint(dateRangeValidator); changeMonitor.add(spnStartTime).addConstraint(dateRangeValidator); - changeMonitor.add(ctlNetrulesConfigurator).addConstraint(new NotNullConstraint("Fehlerhafte Netzwerkregeln")); + changeMonitor.add(ctlNetrulesConfigurator) + .addConstraint(new NotNullConstraint("Fehlerhafte Netzwerkregeln")); changeListenerPermissions = changeMonitor.add(ctlPermissionManager); ctlLocationSelector.addToChangeMonitor(changeMonitor); ctlRunscriptConfigurator.addToChangeMonitor(changeMonitor); ctlNetshareConfigurator.addToChangeMonitor(changeMonitor); ctlLdapFilterConfigurator.addToChangeMonitor(changeMonitor); - // TODO: LDAP/NetShare: Having uncommitted changes in the input fields should be handled too + // TODO: LDAP/NetShare: Having uncommitted changes in the input fields should be + // handled too // End change monitor addWindowListener(new WindowAdapter() { @@ -252,16 +267,120 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements @Override public void userAdded(UserInfo user, UserListWindow window) { window.dispose(); - if (Gui.showMessageBox(me, "Sind Sie sicher, dass sie die Besitzerrechte an " - + "einen anderen Account übertragen wollen?", MessageType.QUESTION_YESNO, - LOGGER, null)) + if (Gui.showMessageBox(me, + "Sind Sie sicher, dass sie die Besitzerrechte an " + + "einen anderen Account übertragen wollen?", + MessageType.QUESTION_YESNO, LOGGER, null)) setLectureOwner(user); } }, "Besitzer festlegen", lecture.ownerId); } }); - - // Update default permissions in the permission manager immediately, so it affects + + 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"); + if (ImagePerms.canEdit(image) || ImagePerms.canAdmin(image)) { + btnSaveChanges.setEnabled(true); + } + + 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(); + } + } + } + }); + + 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 // newly added users final ItemListener updateDefaultPermissionListener = new ItemListener() { @Override @@ -290,10 +409,8 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements } /** - * Sets the lecture to show the details of by setting the 'lecture' and - * 'image' - * members to its metadata. This method will fetch the information from the - * sat + * Sets the lecture to show the details of by setting the 'lecture' and 'image' + * members to its metadata. This method will fetch the information from the sat * * @param lectureId the id of the lecture to be displayed */ @@ -307,8 +424,8 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements lecture = lectureDetails; image = imageDetails; if (lecture != null) { - customPermissions = ThriftActions.getLecturePermissions( - JOptionPane.getFrameForComponent(me), lecture.lectureId); + customPermissions = ThriftActions + .getLecturePermissions(JOptionPane.getFrameForComponent(me), lecture.lectureId); } fillDetails(); } @@ -317,7 +434,8 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements } /** - * Internal callback function when we received the lecture's details from the server + * Internal callback function when we received the lecture's details from the + * server */ private void fillDetails() { if (lecture == null) { @@ -379,10 +497,9 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements Calendar endCal = Calendar.getInstance(); endCal.setTime(new Date(lecture.getEndTime() * 1000l)); - dtpEndDate.getModel().setDate(endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH), - endCal.get(Calendar.DATE)); + dtpEndDate.getModel().setDate(endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH), endCal.get(Calendar.DATE)); spnEndTime.getModel().setValue(endCal.getTime()); - + // now enable the tabs the user can see given its permissions toggleEditable(true); // and always switch to the "About" tab @@ -392,8 +509,8 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements } /** - * Helper to fill the combobox with the versions of the image. The list will - * be sorted by creation timestamp + * Helper to fill the combobox with the versions of the image. The list will be + * sorted by creation timestamp */ private void fillVersionsCombo() { List versions; @@ -420,8 +537,8 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements cboVersions.setModel(new DefaultComboBoxModel( versions.toArray(new ImageVersionDetails[versions.size()]))); cboVersions.setSelectedIndex(-1); // To make the change monitor happy - cboVersions.setSelectedItem(new ImageVersionDetails(lecture.getImageVersionId(), 0, 0, 0, null, true, - true, true, null)); + cboVersions.setSelectedItem( + new ImageVersionDetails(lecture.getImageVersionId(), 0, 0, 0, null, true, true, true, null)); } /** @@ -430,13 +547,12 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements * @param user UserInfo representation of the new owner */ private void setLectureOwner(final UserInfo user) { - if (!ThriftActions.setLectureOwner(JOptionPane.getFrameForComponent(this), lecture.getLectureId(), - user)) { + if (!ThriftActions.setLectureOwner(JOptionPane.getFrameForComponent(this), lecture.getLectureId(), user)) { return; } // success - Gui.showMessageBox(me, "Besitzrechte übertragen an " + FormatHelper.userName(user), MessageType.INFO, - null, null); + Gui.showMessageBox(me, "Besitzrechte übertragen an " + FormatHelper.userName(user), MessageType.INFO, null, + null); toggleEditable(false); String lectureId = lecture.getLectureId(); synchronized (me) { @@ -471,8 +587,8 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements null); return; } - ThriftActions.initDownload(JOptionPane.getFrameForComponent(this), lecture.imageVersionId, - image.imageName, image.virtId, image.osId, versionSize, new DownloadCallback() { + ThriftActions.initDownload(JOptionPane.getFrameForComponent(this), lecture.imageVersionId, image.imageName, + image.virtId, image.osId, versionSize, new DownloadCallback() { @Override public void downloadInitialized(boolean success) { if (!success) { @@ -488,8 +604,8 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements } /** - * Triggers the saving of the changes of this lecture - * And inform the callback function about the outcome + * Triggers the saving of the changes of this lecture And inform the callback + * function about the outcome */ private void saveChanges() { boolean saved = saveChangesInternal(); @@ -511,7 +627,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements long endTime = DateTimeHelper.getDateFrom(dtpEndDate, spnEndTime).getTime() / 1000L; if (!isPeriodValid(startTime, endTime, true)) return false; - + // check, whether autoupdate is selected and choose version accordingly if (image != null) { lecture.imageVersionId = chkAutoUpdate.isSelected() ? image.latestVersionId @@ -529,11 +645,8 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements // first build the LectureWrite from the GUI fields StartupSettings startupSettings = ctlRunscriptConfigurator.getState(); final LectureWrite metadata = new LectureWrite(txtTitle.getText(), txtDescription.getText(), - lecture.getImageVersionId(), chkAutoUpdate.isSelected(), chkIsActive.isSelected(), - startTime, endTime, - startupSettings.serializeItems(), null, - chkIsExam.isSelected(), - chkHasInternetAccess.isSelected(), + lecture.getImageVersionId(), chkAutoUpdate.isSelected(), chkIsActive.isSelected(), startTime, endTime, + startupSettings.serializeItems(), null, chkIsExam.isSelected(), chkHasInternetAccess.isSelected(), lecture.getDefaultPermissions(), ctlLocationSelector.getSelectedLocationsAsIds(), ctlLocationSelector.getOnlyInSelection(), // TODO limitOnlyToAllowedUsers, default to false for now @@ -545,10 +658,9 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements metadata.setLdapFilters(ctlLdapFilterConfigurator.getState()); metadata.setPresetScriptIds(startupSettings.selectedScripts); - // now trigger the actual action + // now trigger the actual action try { - ThriftManager.getSatClient().updateLecture(Session.getSatelliteToken(), - lecture.getLectureId(), metadata); + ThriftManager.getSatClient().updateLecture(Session.getSatelliteToken(), lecture.getLectureId(), metadata); LOGGER.info("Successfully saved new metadata"); } catch (TException e) { ThriftError.showMessage(JOptionPane.getFrameForComponent(this), LOGGER, e, @@ -572,8 +684,8 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements */ private boolean saveCustomPermissions() { try { - ThriftManager.getSatClient().writeLecturePermissions(Session.getSatelliteToken(), - lecture.lectureId, ctlPermissionManager.getPermissions()); + ThriftManager.getSatClient().writeLecturePermissions(Session.getSatelliteToken(), lecture.lectureId, + ctlPermissionManager.getPermissions()); LOGGER.info("Successfully saved custom permissions"); return true; } catch (TException e) { @@ -584,13 +696,12 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements } /** - * Checks if the given start and end date represent a valid time period. - * This is the case, if start < end and if current time < end + * Checks if the given start and end date represent a valid time period. This is + * the case, if start < end and if current time < end * - * @param start date of the period to check - * @param end date of the period to check - * @param feedback true if the user should be shown feedback, false - * otherwise + * @param start date of the period to check + * @param end date of the period to check + * @param feedback true if the user should be shown feedback, false otherwise * @return true if the period is valid, false otherwise */ private boolean isPeriodValid(long start, long end, boolean feedback) { @@ -601,8 +712,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements return true; String msg = "Start der Veranstaltung ist nach dem Enddatum!"; if (feedback) { - Gui.showMessageBox(me, msg, MessageType.ERROR, - LOGGER, null); + Gui.showMessageBox(me, msg, MessageType.ERROR, LOGGER, null); } lblError.setText(msg); return false; @@ -611,8 +721,9 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements /** * Enables/Disables the tabs based on the given flag 'editable'. * - * @param editable when true, will enable the tabs if the user is allowed to see them. - * If false, this will disable all tabs but the first tab "About". + * @param editable when true, will enable the tabs if the user is allowed to see + * them. If false, this will disable all tabs but the first tab + * "About". */ protected void toggleEditable(boolean editable) { // if we don't have a lecture and an image set, just disable @@ -620,7 +731,8 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements // enable the standard tabs that are always enabled setTabEnabled(pnlTabGeneral, editable); setTabEnabled(pnlTabPermissions, editable && LecturePerms.canAdmin(lecture)); - // enable the other tabs that might have been added to the panel (depends on API version) + // enable the other tabs that might have been added to the panel (depends on API + // version) setTabEnabled(pnlTabRestrictions, editable); setTabEnabled(pnlTabLocations, editable); setTabEnabled(pnlTabRunscript, editable); @@ -630,7 +742,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements btnChangeOwner.setEnabled(LecturePerms.canAdmin(lecture)); btnDownloadImage.setEnabled(ImagePerms.canDownload(image)); } - + private void setTabEnabled(JPanel tab, boolean editable) { int index = pnlTabs.indexOfComponent(tab); if (index == -1) // Check if tab exists -- we don't add some, depending on server version @@ -639,11 +751,11 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements } /** - * Opens a new LectureDetailsWindow showing the details of the - * lecture with ID = lectureId + * Opens a new LectureDetailsWindow showing the details of the lecture with ID = + * lectureId * * @param modalParent parent of this window - * @param lectureId id of the lecture to set the details of + * @param lectureId id of the lecture to set the details of */ public static void open(Frame modalParent, String lectureId, LectureUpdatedCallback callback) { LectureDetailsWindow win = new LectureDetailsWindow(modalParent, callback); @@ -661,9 +773,11 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements super.show(); } - /* ******************************************************************************* + /* + * ***************************************************************************** + * ** * - * UIFeedback implementation + * UIFeedback implementation * ********************************************************************************/ @Override @@ -682,11 +796,10 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements * confirmation if so */ private void safeClose() { - if (changeMonitor.isCurrentlyModified() - && !Gui.showMessageBox(me, "Änderungen werden verworfen, wollen Sie wirklich schließen?", - MessageType.QUESTION_YESNO, null, null)) + if (changeMonitor.isCurrentlyModified() && !Gui.showMessageBox(me, + "Änderungen werden verworfen, wollen Sie wirklich schließen?", MessageType.QUESTION_YESNO, null, null)) return; - synchronized(me) { + synchronized (me) { lecture = null; image = null; } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java index 0d5cfd0f..31332cf4 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java @@ -83,7 +83,7 @@ public abstract class ImageDetailsWindowLayout extends JDialog { protected final JButton btnItalic; protected final JButton btnUnderline; protected final JButton btnWysiwyg; - + protected final JComboBox cbTxtSize; protected final JComboBox cbTxtColor; protected final HTMLEditorKit kit; diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java index 0f01fd61..113502d8 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java @@ -2,12 +2,14 @@ package org.openslx.dozmod.gui.window.layout; import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Dimension; import java.awt.Font; import java.awt.Frame; import java.awt.GridBagConstraints; import java.awt.Insets; import java.util.Calendar; import java.awt.GridLayout; +import java.awt.FlowLayout; import javax.swing.BorderFactory; import javax.swing.Box; @@ -15,6 +17,7 @@ import javax.swing.BoxLayout; import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JCheckBox; +import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JEditorPane; import javax.swing.JFrame; @@ -27,6 +30,7 @@ import javax.swing.JTextField; import javax.swing.SpinnerDateModel; import javax.swing.text.DateFormatter; import javax.swing.text.StyledEditorKit; +import javax.swing.text.html.HTMLEditorKit; import org.jdatepicker.JDatePicker; import org.openslx.bwlp.thrift.iface.ImageVersionDetails; @@ -113,6 +117,11 @@ public abstract class LectureDetailsWindowLayout extends JDialog { 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; public LectureDetailsWindowLayout(Frame modalParent) { @@ -185,27 +194,51 @@ public abstract class LectureDetailsWindowLayout extends JDialog { // buttons for text editing JPanel editingPanel = new JPanel(); - editingPanel.setLayout(new GridLayout(1,3)); + + editingPanel.setLayout(new FlowLayout(FlowLayout.LEADING)); JPanel emptyPanel = new JPanel(); grdGeneral.add(emptyPanel); - btnBold = new JButton( new StyledEditorKit.BoldAction()); - btnBold.setIcon(Gui.getScaledIconResource("/img/bold.png", "B", 24, this)); + 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", 24, this)); + 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", 24, this)); + btnUnderline = new JButton(new StyledEditorKit.UnderlineAction()); + btnUnderline.setIcon(Gui.getScaledIconResource("/img/underline.png", "B", 15, this)); btnUnderline.setText(""); - grdGeneral.add(btnBold); - grdGeneral.add(btnItalic); - grdGeneral.add(btnUnderline); + 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(100,25)); + editingPanel.add(cbTxtColor); + grdGeneral.add(editingPanel); - + + + emptyPanel.setLayout(new FlowLayout()); + btnWysiwyg = new JButton("HTML"); + btnWysiwyg.setPreferredSize(new Dimension(100,25)); + emptyPanel.add(btnWysiwyg); + + grdGeneral.add(emptyPanel); + grdGeneral.add(new JPanel()); + grdGeneral.add(new JPanel()); + grdGeneral.nextRow(); // description txtDescription = new JEditorPane(); + kit = new HTMLEditorKit(); + txtDescription.setEditorKit(kit); txtDescription.setContentType("text/html"); grdGeneral.add(new QLabel("Beschreibung")).anchor(GridBagConstraints.FIRST_LINE_START); JScrollPane jsp = new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, @@ -215,6 +248,7 @@ public abstract class LectureDetailsWindowLayout extends JDialog { grdGeneral.add(jsp, 4).expand(true, true).fill(true, true); grdGeneral.nextRow(); + // ID. NOTE: currently disabled txtId = new JTextField(); txtId.setEditable(false); -- cgit v1.2.3-55-g7522 From 64ae169efdac79fa2614a7bf5e60bcbd96701314 Mon Sep 17 00:00:00 2001 From: Kuersat Akmaz Date: Mon, 30 Nov 2020 22:50:07 +0100 Subject: [client] fixed bug in htmleditor in lecturecreationpage Issue : #3732 --- .../dozmod/gui/window/LectureDetailsWindow.java | 6 -- .../wizard/layout/LectureCreationPageLayout.java | 35 ++++++- .../gui/wizard/page/LectureCreationPage.java | 102 +++++++++++++++++++++ 3 files changed, 133 insertions(+), 10 deletions(-) (limited to 'dozentenmodul/src/main/java') 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(), + "
", 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(); -- cgit v1.2.3-55-g7522 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 --- .../gui/wizard/layout/ImageMetaDataPageLayout.java | 48 ++++++--- .../dozmod/gui/wizard/page/ImageMetaDataPage.java | 108 ++++++++++++++++++++- 2 files changed, 143 insertions(+), 13 deletions(-) (limited to 'dozentenmodul/src/main/java') 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() { @@ -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(), + "
", 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