From 04fa639aa136ffac9f8d78abaafff6e6a1264468 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Mon, 27 May 2024 17:07:51 +0200 Subject: [PATCH 01/76] Added initial JFrame for P2T Co-authored-by: TimU02 --- .../editor/controller/ActionFactory.java | 2 +- .../main/java/org/woped/file/p2t/P2TUI.java | 245 ++++++++++++++++++ .../java/org/woped/starter/MainFrame.java | 1 + .../controller/vep/GUIViewEventProcessor.java | 11 + 4 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/controller/ActionFactory.java b/WoPeD-Editor/src/main/java/org/woped/editor/controller/ActionFactory.java index 47332f50e..067dd0490 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/controller/ActionFactory.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/controller/ActionFactory.java @@ -643,7 +643,7 @@ public static HashMap createStaticActions(ApplicationMediat STATIC_ACTION_MAP.put( ACTIONID_P2T, new WoPeDAction( - am, AbstractViewEvent.VIEWEVENTTYPE_EDIT, AbstractViewEvent.P2T, null, ACTIONID_P2T)); + am, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.P2T, null, ACTIONID_P2T)); VisualController.getInstance() .addElement( STATIC_ACTION_MAP.get(ACTIONID_P2T), diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java new file mode 100644 index 000000000..03b85c7d0 --- /dev/null +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -0,0 +1,245 @@ +package org.woped.file.p2t; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Frame; +import java.awt.HeadlessException; +import java.awt.Insets; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import javax.swing.AbstractAction; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; +import javax.swing.ImageIcon; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JScrollPane; +import javax.swing.JTextField; +import org.woped.core.controller.AbstractApplicationMediator; +import org.woped.editor.controller.vc.EditorVC; +import org.woped.file.t2p.JTextAreaWithHint; +import org.woped.file.t2p.PlainTextFileReader; +import org.woped.gui.lookAndFeel.WopedButton; +import org.woped.gui.translations.Messages; + +public class P2TUI extends JDialog { + private JTextAreaWithHint textArea; + private JDialog loadDialog; + private AbstractApplicationMediator mediator; + private boolean requested = false; + private String inputText; + + public P2TUI(AbstractApplicationMediator mediator) { + this(null, mediator); + } + + public P2TUI(Frame owner, AbstractApplicationMediator mediator) throws HeadlessException { + super(owner, true); + this.mediator = mediator; + initialize(); + } + + private void initialize() { + this.setVisible(false); + this.getContentPane().setLayout(new BorderLayout()); + this.setUndecorated(false); + this.setResizable(true); + + textArea = new JTextAreaWithHint(); + this.setTitle(Messages.getString("P2T.tooltip")); + this.getContentPane().add(wrapTextArea(initializeTextArea(textArea)), BorderLayout.CENTER); + this.getContentPane().add(initializeButtonsPanel(), BorderLayout.SOUTH); + + this.pack(); + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + this.setLocation((screenSize.width - this.getWidth()) / 3, (screenSize.height - this.getHeight()) / 3); + Dimension size = new Dimension(600, 440); + this.setSize(size); + + // Set previous text if available + int index = 0; + boolean doesContain = false; + if (mediator.getViewControllers().containsKey("EDITOR_VC_" + index)) { + doesContain = true; + while (mediator.getViewControllers().containsKey("EDITOR_VC_" + index)) { + index++; + } + index--; + } + + if (doesContain) { + String lastTextInput = ((EditorVC) mediator.getViewControllers().get("EDITOR_VC_" + index)).getEditorPanel().getT2PText(); + textArea.setText(lastTextInput); + } + } + + private JTextAreaWithHint initializeTextArea(JTextAreaWithHint ta) { + Font f = new Font("Lucia Grande", Font.PLAIN, 13); + String hint = Messages.getString("P2TUI.HowTo"); + ta.setFont(f); + ta.changeHintText(hint); + ta.setLineWrap(true); + ta.setWrapStyleWord(true); + ta.requestFocus(); + ta.requestFocusInWindow(); + ta.setMargin(new Insets(10, 10, 10, 10)); + return ta; + } + + private JScrollPane wrapTextArea(JTextAreaWithHint ta) { + JScrollPane scrollPane = new JScrollPane(ta); + scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + return scrollPane; + } + + private JPanel initializeButtonsPanel() { + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); + buttonPanel.setBorder(BorderFactory.createEmptyBorder(20, 10, 10, 10)); + + String[] lang = {Messages.getString("P2TUI.Lang"), Messages.getString("P2TUI.Lang.English")}; + JComboBox langBox = new JComboBox<>(lang); + langBox.setSelectedIndex(1); + + // Radio buttons for "alt" and "neu" + JRadioButton oldRadioButton = new JRadioButton("Alt"); + JRadioButton newRadioButton = new JRadioButton("Neu"); + ButtonGroup group = new ButtonGroup(); + group.add(oldRadioButton); + group.add(newRadioButton); + + // API Key input field + JLabel apiKeyLabel = new JLabel("API Key:"); + JTextField apiKeyField = new JTextField(); + apiKeyLabel.setVisible(false); + apiKeyField.setVisible(false); + + newRadioButton.addActionListener(e -> { + apiKeyLabel.setVisible(true); + apiKeyField.setVisible(true); + }); + + oldRadioButton.addActionListener(e -> { + apiKeyLabel.setVisible(false); + apiKeyField.setVisible(false); + }); + + // Set "alt" as default selection + oldRadioButton.setSelected(true); + + WopedButton btnGenerate = new WopedButton(new AbstractAction() { + public void actionPerformed(ActionEvent arg0) { + request(); + } + }); + + btnGenerate.setMnemonic(KeyEvent.VK_A); + btnGenerate.setText(Messages.getString("P2TUI.Button.Generate.Text")); + btnGenerate.setIcon(loadIcon(Messages.getString("P2TUI.Button.Generate.Icon"))); + + WopedButton btnErase = new WopedButton(new AbstractAction() { + public void actionPerformed(ActionEvent arg0) { + clearTextArea(); + } + }); + + btnErase.setMnemonic(KeyEvent.VK_L); + btnErase.setText(Messages.getString("P2TUI.Button.Clear.Text")); + btnErase.setIcon(loadIcon(Messages.getString("P2TUI.Button.Clear.Icon"))); + + WopedButton btnUpload = new WopedButton(new AbstractAction() { + public void actionPerformed(ActionEvent arg0) { + readFile(); + } + }); + + btnUpload.setMnemonic(KeyEvent.VK_C); + btnUpload.setText(Messages.getString("P2TUI.Button.Read.Text")); + btnUpload.setIcon(loadIcon(Messages.getString("P2TUI.Button.Read.Icon"))); + + buttonPanel.add(btnUpload); + buttonPanel.add(btnErase); + buttonPanel.add(langBox); + buttonPanel.add(Box.createHorizontalGlue()); + buttonPanel.add(oldRadioButton); + buttonPanel.add(newRadioButton); + buttonPanel.add(apiKeyLabel); + buttonPanel.add(apiKeyField); + buttonPanel.add(btnGenerate); + + return buttonPanel; + } + + private ImageIcon loadIcon(String path) { + java.net.URL imgURL = getClass().getResource(path); + if (imgURL != null) { + return new ImageIcon(imgURL); + } else { + System.err.println("Couldn't find file: " + path); + return null; // or a default icon if you prefer + } + } + + private void request() { + if (requested) return; + requested = true; + + inputText = textArea.getText(); + + if (!inputText.isEmpty()) { + // Implement your request handling here + showLoadingBox(); + } else { + showErrorPopUp("P2TUI.NoText.Title", "P2TUI.NoText.Text"); + } + + requested = false; + } + + private void showLoadingBox() { + JOptionPane jop = new JOptionPane(); + jop.setMessageType(JOptionPane.INFORMATION_MESSAGE); + jop.setMessage(Messages.getString("P2TUI.Loading.Text")); + + loadDialog = jop.createDialog(this, Messages.getString("P2TUI.Loading.Title")); + jop.setOptions(new String[]{Messages.getString("P2TUI.Loading.Cancel")}); + loadDialog.setVisible(true); + + // Thread gets blocked and awaits an UI action. + } + + private void showErrorPopUp(String titleId, String msgId) { + String text[] = {Messages.getString("Dialog.Ok")}; + + String msg = Messages.getStringReplaced(msgId, null); + String title = Messages.getString(titleId); + int optionType = JOptionPane.YES_NO_CANCEL_OPTION; + int messageType = JOptionPane.ERROR_MESSAGE; + + JOptionPane.showOptionDialog(null, msg, title, optionType, messageType, null, text, text[0]); + } + + private void close() { + this.dispose(); + } + + public void clearTextArea() { + if (textArea.getText() != null) { + textArea.setText(null); + } + } + + public void readFile() { + PlainTextFileReader r = new PlainTextFileReader(); + String txt = r.read(); + if (txt != null) textArea.setText(txt); + } +} diff --git a/WoPeD-Starter/src/main/java/org/woped/starter/MainFrame.java b/WoPeD-Starter/src/main/java/org/woped/starter/MainFrame.java index 5268c2b57..c3154020d 100644 --- a/WoPeD-Starter/src/main/java/org/woped/starter/MainFrame.java +++ b/WoPeD-Starter/src/main/java/org/woped/starter/MainFrame.java @@ -1196,6 +1196,7 @@ private JRibbonBand getP2TBand() { return p2tBand; } + private JRibbonBand getWindowsBand() { if (windowsBand == null) { diff --git a/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java b/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java index 263bcdca6..d21aaacad 100644 --- a/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java +++ b/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java @@ -46,6 +46,7 @@ import org.woped.editor.controller.vc.SubprocessEditorVC; import org.woped.editor.help.HelpBrowser; import org.woped.editor.help.action.LaunchDefaultBrowserAction; +import org.woped.file.p2t.P2TUI; import org.woped.file.t2p.T2PUI; import org.woped.gui.translations.Messages; import org.woped.qualanalysis.service.IQualanalysisService; @@ -82,6 +83,16 @@ && getMediator().getUi().getComponent() instanceof JFrame) { } t2p.setVisible(true); break; + case AbstractViewEvent.P2T: + P2TUI p2t; + if (getMediator().getUi() != null + && getMediator().getUi().getComponent() instanceof JFrame) { + p2t = new P2TUI((JFrame) getMediator().getUi(), getMediator()); + } else { + p2t = new P2TUI(getMediator()); + } + p2t.setVisible(true); + break; case AbstractViewEvent.NEW: getMediator().createEditor(true); break; From bb24ad55a128c88903b09446e3f3f856aafd7a0a Mon Sep 17 00:00:00 2001 From: anneke02 Date: Tue, 28 May 2024 10:34:33 +0200 Subject: [PATCH 02/76] Edited JFrame with radio buttons and added descriptions Co-authored-by: TimU02 --- .../main/java/org/woped/file/p2t/P2TUI.java | 144 +++++------------- .../src/main/resources/Messages.properties | 4 + .../src/main/resources/Messages_de.properties | 4 + 3 files changed, 44 insertions(+), 108 deletions(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 03b85c7d0..717c4d111 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -15,27 +15,23 @@ import javax.swing.BoxLayout; import javax.swing.ButtonGroup; import javax.swing.ImageIcon; -import javax.swing.JComboBox; +import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; -import javax.swing.JScrollPane; import javax.swing.JTextField; import org.woped.core.controller.AbstractApplicationMediator; import org.woped.editor.controller.vc.EditorVC; import org.woped.file.t2p.JTextAreaWithHint; -import org.woped.file.t2p.PlainTextFileReader; import org.woped.gui.lookAndFeel.WopedButton; import org.woped.gui.translations.Messages; public class P2TUI extends JDialog { - private JTextAreaWithHint textArea; private JDialog loadDialog; private AbstractApplicationMediator mediator; private boolean requested = false; - private String inputText; public P2TUI(AbstractApplicationMediator mediator) { this(null, mediator); @@ -52,73 +48,35 @@ private void initialize() { this.getContentPane().setLayout(new BorderLayout()); this.setUndecorated(false); this.setResizable(true); + this.setTitle(Messages.getString("P2T.openP2T.text")); - textArea = new JTextAreaWithHint(); - this.setTitle(Messages.getString("P2T.tooltip")); - this.getContentPane().add(wrapTextArea(initializeTextArea(textArea)), BorderLayout.CENTER); - this.getContentPane().add(initializeButtonsPanel(), BorderLayout.SOUTH); + // Add switch button panel to the top left + this.getContentPane().add(initializeSwitchButtonPanel(), BorderLayout.NORTH); + + // Add a single button to the bottom center + this.getContentPane().add(initializeSingleButtonPanel(), BorderLayout.SOUTH); this.pack(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation((screenSize.width - this.getWidth()) / 3, (screenSize.height - this.getHeight()) / 3); - Dimension size = new Dimension(600, 440); + Dimension size = new Dimension(600, 140); this.setSize(size); - - // Set previous text if available - int index = 0; - boolean doesContain = false; - if (mediator.getViewControllers().containsKey("EDITOR_VC_" + index)) { - doesContain = true; - while (mediator.getViewControllers().containsKey("EDITOR_VC_" + index)) { - index++; - } - index--; - } - - if (doesContain) { - String lastTextInput = ((EditorVC) mediator.getViewControllers().get("EDITOR_VC_" + index)).getEditorPanel().getT2PText(); - textArea.setText(lastTextInput); - } - } - - private JTextAreaWithHint initializeTextArea(JTextAreaWithHint ta) { - Font f = new Font("Lucia Grande", Font.PLAIN, 13); - String hint = Messages.getString("P2TUI.HowTo"); - ta.setFont(f); - ta.changeHintText(hint); - ta.setLineWrap(true); - ta.setWrapStyleWord(true); - ta.requestFocus(); - ta.requestFocusInWindow(); - ta.setMargin(new Insets(10, 10, 10, 10)); - return ta; } - private JScrollPane wrapTextArea(JTextAreaWithHint ta) { - JScrollPane scrollPane = new JScrollPane(ta); - scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - return scrollPane; - } - - private JPanel initializeButtonsPanel() { - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); - buttonPanel.setBorder(BorderFactory.createEmptyBorder(20, 10, 10, 10)); - - String[] lang = {Messages.getString("P2TUI.Lang"), Messages.getString("P2TUI.Lang.English")}; - JComboBox langBox = new JComboBox<>(lang); - langBox.setSelectedIndex(1); + private JPanel initializeSwitchButtonPanel() { + JPanel switchButtonPanel = new JPanel(); + switchButtonPanel.setLayout(new BoxLayout(switchButtonPanel, BoxLayout.LINE_AXIS)); + switchButtonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - // Radio buttons for "alt" and "neu" - JRadioButton oldRadioButton = new JRadioButton("Alt"); - JRadioButton newRadioButton = new JRadioButton("Neu"); + JRadioButton oldRadioButton = new JRadioButton(Messages.getString("P2T.oldservice.title")); + JRadioButton newRadioButton = new JRadioButton(Messages.getString("P2T.newservice.title")); ButtonGroup group = new ButtonGroup(); group.add(oldRadioButton); group.add(newRadioButton); - // API Key input field - JLabel apiKeyLabel = new JLabel("API Key:"); + JLabel apiKeyLabel = new JLabel(Messages.getString("P2T.apikey.title")); JTextField apiKeyField = new JTextField(); + apiKeyField.setPreferredSize(new Dimension(200, 25)); // Set the preferred size to make it wider apiKeyLabel.setVisible(false); apiKeyField.setVisible(false); @@ -135,45 +93,33 @@ private JPanel initializeButtonsPanel() { // Set "alt" as default selection oldRadioButton.setSelected(true); - WopedButton btnGenerate = new WopedButton(new AbstractAction() { - public void actionPerformed(ActionEvent arg0) { - request(); - } - }); - - btnGenerate.setMnemonic(KeyEvent.VK_A); - btnGenerate.setText(Messages.getString("P2TUI.Button.Generate.Text")); - btnGenerate.setIcon(loadIcon(Messages.getString("P2TUI.Button.Generate.Icon"))); + switchButtonPanel.add(oldRadioButton); + switchButtonPanel.add(newRadioButton); + switchButtonPanel.add(apiKeyLabel); + switchButtonPanel.add(apiKeyField); - WopedButton btnErase = new WopedButton(new AbstractAction() { - public void actionPerformed(ActionEvent arg0) { - clearTextArea(); - } - }); + return switchButtonPanel; + } - btnErase.setMnemonic(KeyEvent.VK_L); - btnErase.setText(Messages.getString("P2TUI.Button.Clear.Text")); - btnErase.setIcon(loadIcon(Messages.getString("P2TUI.Button.Clear.Icon"))); + private JPanel initializeSingleButtonPanel() { + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); + buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - WopedButton btnUpload = new WopedButton(new AbstractAction() { + JButton singleButton = new JButton(new AbstractAction() { public void actionPerformed(ActionEvent arg0) { - readFile(); + // Implement your action here + request(); } }); - btnUpload.setMnemonic(KeyEvent.VK_C); - btnUpload.setText(Messages.getString("P2TUI.Button.Read.Text")); - btnUpload.setIcon(loadIcon(Messages.getString("P2TUI.Button.Read.Icon"))); + singleButton.setMnemonic(KeyEvent.VK_A); + singleButton.setText(Messages.getString("P2T.tooltip")); + singleButton.setIcon(loadIcon(Messages.getString("P2TUI.Button.Generate.Icon"))); - buttonPanel.add(btnUpload); - buttonPanel.add(btnErase); - buttonPanel.add(langBox); buttonPanel.add(Box.createHorizontalGlue()); - buttonPanel.add(oldRadioButton); - buttonPanel.add(newRadioButton); - buttonPanel.add(apiKeyLabel); - buttonPanel.add(apiKeyField); - buttonPanel.add(btnGenerate); + buttonPanel.add(singleButton); + buttonPanel.add(Box.createHorizontalGlue()); return buttonPanel; } @@ -192,14 +138,8 @@ private void request() { if (requested) return; requested = true; - inputText = textArea.getText(); - - if (!inputText.isEmpty()) { - // Implement your request handling here - showLoadingBox(); - } else { - showErrorPopUp("P2TUI.NoText.Title", "P2TUI.NoText.Text"); - } + // Implement your request handling here + showLoadingBox(); requested = false; } @@ -230,16 +170,4 @@ private void showErrorPopUp(String titleId, String msgId) { private void close() { this.dispose(); } - - public void clearTextArea() { - if (textArea.getText() != null) { - textArea.setText(null); - } - } - - public void readFile() { - PlainTextFileReader r = new PlainTextFileReader(); - String txt = r.read(); - if (txt != null) textArea.setText(txt); - } } diff --git a/WoPeD-GUI/src/main/resources/Messages.properties b/WoPeD-GUI/src/main/resources/Messages.properties index b2cc69c07..537bcc8c5 100644 --- a/WoPeD-GUI/src/main/resources/Messages.properties +++ b/WoPeD-GUI/src/main/resources/Messages.properties @@ -873,6 +873,10 @@ P2T.SizeError =

Modell has too few nodes - no text can be gene P2T.Error.ArcWeights.title = Text generation failed P2T.Error.ArcWeights.message = The net contains arc weights.\nArc weights are not supported by the process 2 text feature. +P2T.oldservice.title = Old +P2T.newservice.title = New +P2T.apikey.title = API Key + #************* ! Text2Process #************* diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index b3c3fe8eb..ee621fc74 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -478,6 +478,9 @@ P2T.SoundError =

Modell ist nicht sound - kein Text generierbar

P2T.SizeError =

Modell hat zuwenige Knoten - kein Text generierbar

P2T.Error.ArcWeights.title = Textgenerierung fehlgeschlagen P2T.Error.ArcWeights.message = Das Netz verwendet Kantengewichte. \nKantengewichte werden bei der Textgenerierung nicht unterst\u00FCtzt. +P2T.oldservice.title = Alt +P2T.newservice.title = Neu +P2T.apikey.title = API Schl\u00FCssel #************* ! Text 2 Process #************* @@ -487,6 +490,7 @@ T2P.openT2P.text = Text zu Prozess T2P.tooltip = Petrinetz erzeugen T2P.Error.ArcWeights.title = Petrinetz-Erzeugung fehlgeschlagen T2P.Error.ArcWeights.message = Das Netz besitzt Kantengewichte.\nKantengewichte werden bei der Prozessgenerierung nicht unterst\u00FCtzt.. + #************* ! Forms #************* From e41faa68c99dc0adfda9b103a72efa2640214a07 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Tue, 28 May 2024 11:09:29 +0200 Subject: [PATCH 03/76] Added API key validation --- .../main/java/org/woped/file/p2t/P2TUI.java | 45 ++++++++++++------- .../src/main/resources/Messages.properties | 2 + .../src/main/resources/Messages_de.properties | 2 + 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 717c4d111..7756e5c7c 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -2,13 +2,15 @@ import java.awt.BorderLayout; import java.awt.Dimension; -import java.awt.Font; import java.awt.Frame; import java.awt.HeadlessException; -import java.awt.Insets; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; import javax.swing.AbstractAction; import javax.swing.BorderFactory; import javax.swing.Box; @@ -23,15 +25,13 @@ import javax.swing.JRadioButton; import javax.swing.JTextField; import org.woped.core.controller.AbstractApplicationMediator; -import org.woped.editor.controller.vc.EditorVC; -import org.woped.file.t2p.JTextAreaWithHint; -import org.woped.gui.lookAndFeel.WopedButton; import org.woped.gui.translations.Messages; public class P2TUI extends JDialog { private JDialog loadDialog; private AbstractApplicationMediator mediator; private boolean requested = false; + private JTextField apiKeyField; public P2TUI(AbstractApplicationMediator mediator) { this(null, mediator); @@ -75,7 +75,7 @@ private JPanel initializeSwitchButtonPanel() { group.add(newRadioButton); JLabel apiKeyLabel = new JLabel(Messages.getString("P2T.apikey.title")); - JTextField apiKeyField = new JTextField(); + apiKeyField = new JTextField(); apiKeyField.setPreferredSize(new Dimension(200, 25)); // Set the preferred size to make it wider apiKeyLabel.setVisible(false); apiKeyField.setVisible(false); @@ -108,14 +108,13 @@ private JPanel initializeSingleButtonPanel() { JButton singleButton = new JButton(new AbstractAction() { public void actionPerformed(ActionEvent arg0) { - // Implement your action here - request(); + validateAPIKey(); } }); singleButton.setMnemonic(KeyEvent.VK_A); - singleButton.setText(Messages.getString("P2T.tooltip")); - singleButton.setIcon(loadIcon(Messages.getString("P2TUI.Button.Generate.Icon"))); + singleButton.setText(Messages.getString("P2T.text")); + //singleButton.setIcon(loadIcon(Messages.getString("P2TUI.Button.Validate.Icon"))); buttonPanel.add(Box.createHorizontalGlue()); buttonPanel.add(singleButton); @@ -134,14 +133,28 @@ private ImageIcon loadIcon(String path) { } } - private void request() { - if (requested) return; - requested = true; + private void validateAPIKey() { + String apiKey = apiKeyField.getText(); + if (!isAPIKeyValid(apiKey)) { + JOptionPane.showMessageDialog(this, Messages.getString("P2T.apikey.invalid"), Messages.getString("P2T.apikey.invalid.title"), JOptionPane.ERROR_MESSAGE); + } + } - // Implement your request handling here - showLoadingBox(); + public static boolean isAPIKeyValid(String apiKey) { + final String TEST_URL = "https://api.openai.com/v1/engines"; + try { + URL url = new URL(TEST_URL); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Authorization", "Bearer " + apiKey); - requested = false; + int responseCode = connection.getResponseCode(); + + return responseCode == 200; + } catch (Exception e) { + e.printStackTrace(); + return false; + } } private void showLoadingBox() { diff --git a/WoPeD-GUI/src/main/resources/Messages.properties b/WoPeD-GUI/src/main/resources/Messages.properties index 537bcc8c5..61641ac4b 100644 --- a/WoPeD-GUI/src/main/resources/Messages.properties +++ b/WoPeD-GUI/src/main/resources/Messages.properties @@ -876,6 +876,8 @@ P2T.Error.ArcWeights.message = The net contains arc weights.\nArc wei P2T.oldservice.title = Old P2T.newservice.title = New P2T.apikey.title = API Key +P2T.apikey.invalid = API Key is not valid +P2T.apikey.invalid.title = Validation Error #************* ! Text2Process diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index ee621fc74..47cd36bcb 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -481,6 +481,8 @@ P2T.Error.ArcWeights.message = Das Netz verwendet Kantengewichte. \nKantengewic P2T.oldservice.title = Alt P2T.newservice.title = Neu P2T.apikey.title = API Schl\u00FCssel +P2T.apikey.invalid = API Schl\u00FCssel ist nicht valide +P2T.apikey.invalid.title = Validierungsfehler #************* ! Text 2 Process #************* From ea50494d5c000a6b8b305ed779b0a271a107ecc4 Mon Sep 17 00:00:00 2001 From: I552396 Date: Tue, 28 May 2024 11:26:08 +0200 Subject: [PATCH 04/76] Add focus in API key field --- WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java | 1 + 1 file changed, 1 insertion(+) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 7756e5c7c..5a48a3ca8 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -83,6 +83,7 @@ private JPanel initializeSwitchButtonPanel() { newRadioButton.addActionListener(e -> { apiKeyLabel.setVisible(true); apiKeyField.setVisible(true); + apiKeyField.requestFocusInWindow(); }); oldRadioButton.addActionListener(e -> { From 2310eefe77d914a1453d4b3b49e57ec1c8f3018a Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Tue, 4 Jun 2024 06:59:39 +0200 Subject: [PATCH 05/76] fork due to lack of write access --- WoPeD-CommonLibs/pom.xml | 11 +- .../main/java/org/woped/file/p2t/P2TUI.java | 132 ++++++++++++++---- WoPeD-Installer/pom.xml | 3 +- WoPeD-Starter/pom.xml | 1 + 4 files changed, 115 insertions(+), 32 deletions(-) diff --git a/WoPeD-CommonLibs/pom.xml b/WoPeD-CommonLibs/pom.xml index 863931064..f234d7d5f 100644 --- a/WoPeD-CommonLibs/pom.xml +++ b/WoPeD-CommonLibs/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 @@ -21,6 +21,13 @@ + + de.dhbw.woped + jgraph + 5.10.2 + system + ${project.basedir}/lib/jgraph-5.10.2.jar + de.dhbw.woped jgraph diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 5a48a3ca8..514c3cdf8 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -3,7 +3,10 @@ import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; import java.awt.HeadlessException; +import java.awt.Insets; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; @@ -13,16 +16,17 @@ import java.net.URL; import javax.swing.AbstractAction; import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; import javax.swing.ButtonGroup; import javax.swing.ImageIcon; import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JScrollPane; import javax.swing.JRadioButton; +import javax.swing.JTextArea; import javax.swing.JTextField; import org.woped.core.controller.AbstractApplicationMediator; import org.woped.gui.translations.Messages; @@ -32,6 +36,9 @@ public class P2TUI extends JDialog { private AbstractApplicationMediator mediator; private boolean requested = false; private JTextField apiKeyField; + private JTextArea promptField; // Changed to JTextArea for multiline + private JCheckBox enablePromptCheckBox; // New Checkbox + private static final String DEFAULT_PROMPT = "Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"; public P2TUI(AbstractApplicationMediator mediator) { this(null, mediator); @@ -50,7 +57,7 @@ private void initialize() { this.setResizable(true); this.setTitle(Messages.getString("P2T.openP2T.text")); - // Add switch button panel to the top left + // Add switch button panel to the top this.getContentPane().add(initializeSwitchButtonPanel(), BorderLayout.NORTH); // Add a single button to the bottom center @@ -59,14 +66,16 @@ private void initialize() { this.pack(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation((screenSize.width - this.getWidth()) / 3, (screenSize.height - this.getHeight()) / 3); - Dimension size = new Dimension(600, 140); + Dimension size = new Dimension(600, 300); // Adjusted size to accommodate new text field and checkbox this.setSize(size); } private JPanel initializeSwitchButtonPanel() { - JPanel switchButtonPanel = new JPanel(); - switchButtonPanel.setLayout(new BoxLayout(switchButtonPanel, BoxLayout.LINE_AXIS)); - switchButtonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + JPanel switchButtonPanel = new JPanel(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + + JPanel radioPanel = new JPanel(new GridBagLayout()); + GridBagConstraints gbcRadio = new GridBagConstraints(); JRadioButton oldRadioButton = new JRadioButton(Messages.getString("P2T.oldservice.title")); JRadioButton newRadioButton = new JRadioButton(Messages.getString("P2T.newservice.title")); @@ -74,37 +83,115 @@ private JPanel initializeSwitchButtonPanel() { group.add(oldRadioButton); group.add(newRadioButton); - JLabel apiKeyLabel = new JLabel(Messages.getString("P2T.apikey.title")); + gbcRadio.gridx = 0; + gbcRadio.gridy = 0; + gbcRadio.insets = new Insets(5, 5, 5, 5); + radioPanel.add(oldRadioButton, gbcRadio); + + gbcRadio.gridx = 1; + gbcRadio.insets = new Insets(5, 0, 5, 5); + radioPanel.add(newRadioButton, gbcRadio); + + gbc.gridx = 0; + gbc.gridy = 0; + gbc.insets = new Insets(5, 5, 5, 5); + gbc.anchor = GridBagConstraints.CENTER; + switchButtonPanel.add(radioPanel, gbc); + + JPanel fieldsPanel = new JPanel(new GridBagLayout()); + + JLabel apiKeyLabel = new JLabel(Messages.getString("P2T.apikey.title") + ":"); apiKeyField = new JTextField(); - apiKeyField.setPreferredSize(new Dimension(200, 25)); // Set the preferred size to make it wider + apiKeyField.setPreferredSize(new Dimension(200, 25)); + + JLabel promptLabel = new JLabel("Prompt:"); + promptField = new JTextArea(DEFAULT_PROMPT); // Changed to JTextArea + promptField.setLineWrap(true); + promptField.setWrapStyleWord(true); + promptField.setRows(5); // Set initial number of rows + promptField.setEnabled(false); // Initially disabled + + JScrollPane promptScrollPane = new JScrollPane(promptField); + promptScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); + promptScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + promptScrollPane.setPreferredSize(new Dimension(200, 100)); + + enablePromptCheckBox = new JCheckBox("Enable editing prompt"); + enablePromptCheckBox.setSelected(false); + enablePromptCheckBox.addActionListener(e -> { + promptField.setEnabled(enablePromptCheckBox.isSelected()); + if (!enablePromptCheckBox.isSelected()) { + promptField.setText(DEFAULT_PROMPT); // Reset text when disabled + promptField.revalidate(); + } + }); + apiKeyLabel.setVisible(false); apiKeyField.setVisible(false); + promptLabel.setVisible(false); + promptScrollPane.setVisible(false); + enablePromptCheckBox.setVisible(false); newRadioButton.addActionListener(e -> { apiKeyLabel.setVisible(true); apiKeyField.setVisible(true); + promptLabel.setVisible(true); + promptScrollPane.setVisible(true); + enablePromptCheckBox.setVisible(true); apiKeyField.requestFocusInWindow(); }); oldRadioButton.addActionListener(e -> { apiKeyLabel.setVisible(false); apiKeyField.setVisible(false); + promptLabel.setVisible(false); + promptScrollPane.setVisible(false); + enablePromptCheckBox.setVisible(false); }); // Set "alt" as default selection oldRadioButton.setSelected(true); - switchButtonPanel.add(oldRadioButton); - switchButtonPanel.add(newRadioButton); - switchButtonPanel.add(apiKeyLabel); - switchButtonPanel.add(apiKeyField); + gbc.gridx = 0; + gbc.gridy = 1; + gbc.anchor = GridBagConstraints.WEST; + gbc.insets = new Insets(5, 5, 5, 5); + fieldsPanel.add(apiKeyLabel, gbc); + + gbc.gridx = 1; + gbc.weightx = 1.0; + gbc.fill = GridBagConstraints.HORIZONTAL; + fieldsPanel.add(apiKeyField, gbc); + + gbc.gridx = 0; + gbc.gridy = 2; + gbc.fill = GridBagConstraints.NONE; + gbc.weightx = 0; + fieldsPanel.add(promptLabel, gbc); + + gbc.gridx = 1; + gbc.weightx = 1.0; + gbc.fill = GridBagConstraints.HORIZONTAL; + fieldsPanel.add(promptScrollPane, gbc); + + gbc.gridx = 0; + gbc.gridy = 3; + gbc.gridwidth = 2; + gbc.weightx = 1.0; + fieldsPanel.add(enablePromptCheckBox, gbc); + + gbc.gridx = 0; + gbc.gridy = 1; + gbc.gridwidth = 2; + gbc.insets = new Insets(10, 0, 0, 0); + gbc.fill = GridBagConstraints.HORIZONTAL; + switchButtonPanel.add(fieldsPanel, gbc); return switchButtonPanel; } private JPanel initializeSingleButtonPanel() { - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); + JPanel buttonPanel = new JPanel(new BorderLayout()); buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); JButton singleButton = new JButton(new AbstractAction() { @@ -115,25 +202,12 @@ public void actionPerformed(ActionEvent arg0) { singleButton.setMnemonic(KeyEvent.VK_A); singleButton.setText(Messages.getString("P2T.text")); - //singleButton.setIcon(loadIcon(Messages.getString("P2TUI.Button.Validate.Icon"))); - buttonPanel.add(Box.createHorizontalGlue()); - buttonPanel.add(singleButton); - buttonPanel.add(Box.createHorizontalGlue()); + buttonPanel.add(singleButton, BorderLayout.CENTER); return buttonPanel; } - private ImageIcon loadIcon(String path) { - java.net.URL imgURL = getClass().getResource(path); - if (imgURL != null) { - return new ImageIcon(imgURL); - } else { - System.err.println("Couldn't find file: " + path); - return null; // or a default icon if you prefer - } - } - private void validateAPIKey() { String apiKey = apiKeyField.getText(); if (!isAPIKeyValid(apiKey)) { diff --git a/WoPeD-Installer/pom.xml b/WoPeD-Installer/pom.xml index 98c449518..b418ad4e2 100644 --- a/WoPeD-Installer/pom.xml +++ b/WoPeD-Installer/pom.xml @@ -35,6 +35,7 @@ org.apache.maven.plugins maven-antrun-plugin + 1.8 com.akathist.maven.plugins.launch4j @@ -327,7 +328,7 @@ - + diff --git a/WoPeD-Starter/pom.xml b/WoPeD-Starter/pom.xml index d4b8021cd..a2321ff39 100644 --- a/WoPeD-Starter/pom.xml +++ b/WoPeD-Starter/pom.xml @@ -37,6 +37,7 @@ maven-antrun-plugin + 1.8 sh.tak.appbundler From d47be3c54d07fe00fb40792970e3e2738e630ebb Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Tue, 4 Jun 2024 12:24:25 +0200 Subject: [PATCH 06/76] Refactored Popup, added field for prompt Refactored the Popup window that includes the switch button added a field for the gpt prompt added a lock for the prompt so that the prompt can only be edited when unlocked --- WoPeD-CommonLibs/pom.xml | 11 +- .../main/java/org/woped/file/p2t/P2TUI.java | 132 ++++++++++++++---- WoPeD-Installer/pom.xml | 5 +- WoPeD-Starter/pom.xml | 5 +- 4 files changed, 118 insertions(+), 35 deletions(-) diff --git a/WoPeD-CommonLibs/pom.xml b/WoPeD-CommonLibs/pom.xml index 863931064..f234d7d5f 100644 --- a/WoPeD-CommonLibs/pom.xml +++ b/WoPeD-CommonLibs/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 @@ -21,6 +21,13 @@ + + de.dhbw.woped + jgraph + 5.10.2 + system + ${project.basedir}/lib/jgraph-5.10.2.jar + de.dhbw.woped jgraph diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 5a48a3ca8..514c3cdf8 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -3,7 +3,10 @@ import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; import java.awt.HeadlessException; +import java.awt.Insets; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; @@ -13,16 +16,17 @@ import java.net.URL; import javax.swing.AbstractAction; import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; import javax.swing.ButtonGroup; import javax.swing.ImageIcon; import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JScrollPane; import javax.swing.JRadioButton; +import javax.swing.JTextArea; import javax.swing.JTextField; import org.woped.core.controller.AbstractApplicationMediator; import org.woped.gui.translations.Messages; @@ -32,6 +36,9 @@ public class P2TUI extends JDialog { private AbstractApplicationMediator mediator; private boolean requested = false; private JTextField apiKeyField; + private JTextArea promptField; // Changed to JTextArea for multiline + private JCheckBox enablePromptCheckBox; // New Checkbox + private static final String DEFAULT_PROMPT = "Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"; public P2TUI(AbstractApplicationMediator mediator) { this(null, mediator); @@ -50,7 +57,7 @@ private void initialize() { this.setResizable(true); this.setTitle(Messages.getString("P2T.openP2T.text")); - // Add switch button panel to the top left + // Add switch button panel to the top this.getContentPane().add(initializeSwitchButtonPanel(), BorderLayout.NORTH); // Add a single button to the bottom center @@ -59,14 +66,16 @@ private void initialize() { this.pack(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation((screenSize.width - this.getWidth()) / 3, (screenSize.height - this.getHeight()) / 3); - Dimension size = new Dimension(600, 140); + Dimension size = new Dimension(600, 300); // Adjusted size to accommodate new text field and checkbox this.setSize(size); } private JPanel initializeSwitchButtonPanel() { - JPanel switchButtonPanel = new JPanel(); - switchButtonPanel.setLayout(new BoxLayout(switchButtonPanel, BoxLayout.LINE_AXIS)); - switchButtonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + JPanel switchButtonPanel = new JPanel(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + + JPanel radioPanel = new JPanel(new GridBagLayout()); + GridBagConstraints gbcRadio = new GridBagConstraints(); JRadioButton oldRadioButton = new JRadioButton(Messages.getString("P2T.oldservice.title")); JRadioButton newRadioButton = new JRadioButton(Messages.getString("P2T.newservice.title")); @@ -74,37 +83,115 @@ private JPanel initializeSwitchButtonPanel() { group.add(oldRadioButton); group.add(newRadioButton); - JLabel apiKeyLabel = new JLabel(Messages.getString("P2T.apikey.title")); + gbcRadio.gridx = 0; + gbcRadio.gridy = 0; + gbcRadio.insets = new Insets(5, 5, 5, 5); + radioPanel.add(oldRadioButton, gbcRadio); + + gbcRadio.gridx = 1; + gbcRadio.insets = new Insets(5, 0, 5, 5); + radioPanel.add(newRadioButton, gbcRadio); + + gbc.gridx = 0; + gbc.gridy = 0; + gbc.insets = new Insets(5, 5, 5, 5); + gbc.anchor = GridBagConstraints.CENTER; + switchButtonPanel.add(radioPanel, gbc); + + JPanel fieldsPanel = new JPanel(new GridBagLayout()); + + JLabel apiKeyLabel = new JLabel(Messages.getString("P2T.apikey.title") + ":"); apiKeyField = new JTextField(); - apiKeyField.setPreferredSize(new Dimension(200, 25)); // Set the preferred size to make it wider + apiKeyField.setPreferredSize(new Dimension(200, 25)); + + JLabel promptLabel = new JLabel("Prompt:"); + promptField = new JTextArea(DEFAULT_PROMPT); // Changed to JTextArea + promptField.setLineWrap(true); + promptField.setWrapStyleWord(true); + promptField.setRows(5); // Set initial number of rows + promptField.setEnabled(false); // Initially disabled + + JScrollPane promptScrollPane = new JScrollPane(promptField); + promptScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); + promptScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + promptScrollPane.setPreferredSize(new Dimension(200, 100)); + + enablePromptCheckBox = new JCheckBox("Enable editing prompt"); + enablePromptCheckBox.setSelected(false); + enablePromptCheckBox.addActionListener(e -> { + promptField.setEnabled(enablePromptCheckBox.isSelected()); + if (!enablePromptCheckBox.isSelected()) { + promptField.setText(DEFAULT_PROMPT); // Reset text when disabled + promptField.revalidate(); + } + }); + apiKeyLabel.setVisible(false); apiKeyField.setVisible(false); + promptLabel.setVisible(false); + promptScrollPane.setVisible(false); + enablePromptCheckBox.setVisible(false); newRadioButton.addActionListener(e -> { apiKeyLabel.setVisible(true); apiKeyField.setVisible(true); + promptLabel.setVisible(true); + promptScrollPane.setVisible(true); + enablePromptCheckBox.setVisible(true); apiKeyField.requestFocusInWindow(); }); oldRadioButton.addActionListener(e -> { apiKeyLabel.setVisible(false); apiKeyField.setVisible(false); + promptLabel.setVisible(false); + promptScrollPane.setVisible(false); + enablePromptCheckBox.setVisible(false); }); // Set "alt" as default selection oldRadioButton.setSelected(true); - switchButtonPanel.add(oldRadioButton); - switchButtonPanel.add(newRadioButton); - switchButtonPanel.add(apiKeyLabel); - switchButtonPanel.add(apiKeyField); + gbc.gridx = 0; + gbc.gridy = 1; + gbc.anchor = GridBagConstraints.WEST; + gbc.insets = new Insets(5, 5, 5, 5); + fieldsPanel.add(apiKeyLabel, gbc); + + gbc.gridx = 1; + gbc.weightx = 1.0; + gbc.fill = GridBagConstraints.HORIZONTAL; + fieldsPanel.add(apiKeyField, gbc); + + gbc.gridx = 0; + gbc.gridy = 2; + gbc.fill = GridBagConstraints.NONE; + gbc.weightx = 0; + fieldsPanel.add(promptLabel, gbc); + + gbc.gridx = 1; + gbc.weightx = 1.0; + gbc.fill = GridBagConstraints.HORIZONTAL; + fieldsPanel.add(promptScrollPane, gbc); + + gbc.gridx = 0; + gbc.gridy = 3; + gbc.gridwidth = 2; + gbc.weightx = 1.0; + fieldsPanel.add(enablePromptCheckBox, gbc); + + gbc.gridx = 0; + gbc.gridy = 1; + gbc.gridwidth = 2; + gbc.insets = new Insets(10, 0, 0, 0); + gbc.fill = GridBagConstraints.HORIZONTAL; + switchButtonPanel.add(fieldsPanel, gbc); return switchButtonPanel; } private JPanel initializeSingleButtonPanel() { - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); + JPanel buttonPanel = new JPanel(new BorderLayout()); buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); JButton singleButton = new JButton(new AbstractAction() { @@ -115,25 +202,12 @@ public void actionPerformed(ActionEvent arg0) { singleButton.setMnemonic(KeyEvent.VK_A); singleButton.setText(Messages.getString("P2T.text")); - //singleButton.setIcon(loadIcon(Messages.getString("P2TUI.Button.Validate.Icon"))); - buttonPanel.add(Box.createHorizontalGlue()); - buttonPanel.add(singleButton); - buttonPanel.add(Box.createHorizontalGlue()); + buttonPanel.add(singleButton, BorderLayout.CENTER); return buttonPanel; } - private ImageIcon loadIcon(String path) { - java.net.URL imgURL = getClass().getResource(path); - if (imgURL != null) { - return new ImageIcon(imgURL); - } else { - System.err.println("Couldn't find file: " + path); - return null; // or a default icon if you prefer - } - } - private void validateAPIKey() { String apiKey = apiKeyField.getText(); if (!isAPIKeyValid(apiKey)) { diff --git a/WoPeD-Installer/pom.xml b/WoPeD-Installer/pom.xml index 98c449518..b32d704c5 100644 --- a/WoPeD-Installer/pom.xml +++ b/WoPeD-Installer/pom.xml @@ -35,6 +35,7 @@ org.apache.maven.plugins maven-antrun-plugin + 1.8 com.akathist.maven.plugins.launch4j @@ -107,7 +108,7 @@ - com.akathist.maven.plugins.launch4j @@ -327,7 +328,7 @@ - + diff --git a/WoPeD-Starter/pom.xml b/WoPeD-Starter/pom.xml index d4b8021cd..7ce97a099 100644 --- a/WoPeD-Starter/pom.xml +++ b/WoPeD-Starter/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 @@ -37,6 +37,7 @@ maven-antrun-plugin + 1.8 sh.tak.appbundler From 4ee2795af3a304ef4d9238a8d36e14f726a2317c Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Sun, 9 Jun 2024 23:29:30 +0200 Subject: [PATCH 07/76] added a settings option for the api key and prompt added a settings option for the api key and prompt --- .../woped/beanconfiguration/configuration.xsd | 74 +- .../general/WoPeDGeneralConfiguration.java | 40 + .../org/woped/config/general/WoPeDconfig.xml | 5 + .../config/DefaultStaticConfiguration.java | 78 +- .../core/config/IGeneralConfiguration.java | 53 +- .../editor/gui/config/ConfNLPToolsPanel.java | 1311 +++++++++-------- 6 files changed, 906 insertions(+), 655 deletions(-) diff --git a/WoPeD-BeanConfiguration/src/main/java/org/woped/beanconfiguration/configuration.xsd b/WoPeD-BeanConfiguration/src/main/java/org/woped/beanconfiguration/configuration.xsd index 69d3d29b1..c7d8adf69 100644 --- a/WoPeD-BeanConfiguration/src/main/java/org/woped/beanconfiguration/configuration.xsd +++ b/WoPeD-BeanConfiguration/src/main/java/org/woped/beanconfiguration/configuration.xsd @@ -3,17 +3,18 @@ - - - - - - - - - - - + + + + + + + + + + + + @@ -101,22 +102,22 @@ - + - - - - - - - - - - + + + + + + + + + + @@ -136,6 +137,15 @@ + + + + + + + + + @@ -191,20 +201,20 @@ - - - - - - + + + + + + - - - - + + + + diff --git a/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDGeneralConfiguration.java b/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDGeneralConfiguration.java index be4155f94..8fee47e12 100644 --- a/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDGeneralConfiguration.java +++ b/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDGeneralConfiguration.java @@ -78,6 +78,9 @@ public boolean initConfig() { if (getConfDocument().getConfiguration().getMetrics() == null) getConfDocument().getConfiguration().addNewMetrics(); + if(getConfDocument().getConfiguration().getGpt() == null) + getConfDocument().getConfiguration().addNewGpt(); + // Check if metrics configuration should be loaded // and react accordingly if (getConfDocument().getConfiguration().getMetrics().getUseMetrics()) { @@ -1475,6 +1478,41 @@ public String getText2ProcessServerURI() { return getConfDocument().getConfiguration().getT2P().getT2PServerURI(); } else return ConfigurationManager.getStandardConfiguration().getText2ProcessServerURI(); } + @Override + public String getGptApiKey() { + if(getConfDocument().getConfiguration().getGpt().isSetGptApiKey()){ + return getConfDocument().getConfiguration().getGpt().getGptApiKey(); + }else return ConfigurationManager.getStandardConfiguration().getGptApiKey(); + } + + @Override + public void setGptApiKey(String apiKey) { + getConfDocument().getConfiguration().getGpt().setGptApiKey(apiKey); + } + + @Override + public boolean getGptShowAgain() { + if(getConfDocument().getConfiguration().getGpt().isSetGptShowAgain()){ + return getConfDocument().getConfiguration().getGpt().getGptShowAgain(); + }else return ConfigurationManager.getStandardConfiguration().getGptShowAgain(); + } + + @Override + public void setGptShowAgain(boolean showAgain) { + getConfDocument().getConfiguration().getGpt().setGptShowAgain(showAgain); + } + + @Override + public String getGptPrompt() { + if(getConfDocument().getConfiguration().getGpt().isSetGptPrompt()){ + return getConfDocument().getConfiguration().getGpt().getGptPrompt(); + }else return ConfigurationManager.getStandardConfiguration().getGptPrompt(); + } + + @Override + public void setGptPrompt(String prompt) { + getConfDocument().getConfiguration().getGpt().setGptPrompt(prompt); + } @Override public void setText2ProcessServerURI(String uri) { @@ -1605,4 +1643,6 @@ public void setYAWLExportGroups(boolean exportGroups) { .getExporting() .setYawlExportGroups(exportGroups); } + + } diff --git a/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDconfig.xml b/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDconfig.xml index 2665ed121..bfba43e06 100644 --- a/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDconfig.xml +++ b/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDconfig.xml @@ -116,4 +116,9 @@ 8081 /t2p + + test + test + + diff --git a/WoPeD-Core/src/main/java/org/woped/core/config/DefaultStaticConfiguration.java b/WoPeD-Core/src/main/java/org/woped/core/config/DefaultStaticConfiguration.java index 88bb24c59..f3d0b9eae 100644 --- a/WoPeD-Core/src/main/java/org/woped/core/config/DefaultStaticConfiguration.java +++ b/WoPeD-Core/src/main/java/org/woped/core/config/DefaultStaticConfiguration.java @@ -12,7 +12,7 @@ /** * Class that provides fallback configuration settings for the general WoPeD configuration part * - * @author Philip Allgaier + * @autor Philip Allgaier */ @SuppressWarnings("JavadocReference") public class DefaultStaticConfiguration implements IGeneralConfiguration { @@ -190,6 +190,11 @@ public class DefaultStaticConfiguration implements IGeneralConfiguration { private boolean yawlExportGroups = false; + // GPT settings + private String gptApiKey = "test"; + private boolean gptShowAgain = true; + private String gptPrompt = "test"; + public DefaultStaticConfiguration() { initConfig(); } @@ -919,29 +924,29 @@ public ApromoreServer[] getApromoreServers() { @Override public void addApromoreServer( - int ID, - String name, - String url, - int port, - String path, - String user, - String pwd, - boolean useProxy, - String proxyUrl, - int proxyPort) {} + int ID, + String name, + String url, + int port, + String path, + String user, + String pwd, + boolean useProxy, + String proxyUrl, + int proxyPort) {} @Override public void changeApromoreServerSettings( - int ID, - String name, - String url, - int port, - String path, - String user, - String pwd, - boolean useProxy, - String proxyUrl, - int proxyPort) {} + int ID, + String name, + String url, + int port, + String path, + String user, + String pwd, + boolean useProxy, + String proxyUrl, + int proxyPort) {} @Override public void removeApromoreServer(int index) {} @@ -1083,4 +1088,35 @@ public boolean isYAWLExportGroups() { public void setYAWLExportGroups(boolean exportGroups) { this.yawlExportGroups = exportGroups; } + + // GPT settings + @Override + public String getGptApiKey() { + return gptApiKey; + } + + @Override + public void setGptApiKey(String apiKey) { + this.gptApiKey = apiKey; + } + + @Override + public boolean getGptShowAgain() { + return gptShowAgain; + } + + @Override + public void setGptShowAgain(boolean showAgain) { + this.gptShowAgain = showAgain; + } + + @Override + public String getGptPrompt() { + return gptPrompt; + } + + @Override + public void setGptPrompt(String prompt) { + this.gptPrompt = prompt; + } } diff --git a/WoPeD-Core/src/main/java/org/woped/core/config/IGeneralConfiguration.java b/WoPeD-Core/src/main/java/org/woped/core/config/IGeneralConfiguration.java index 122d25dd7..33dba995c 100644 --- a/WoPeD-Core/src/main/java/org/woped/core/config/IGeneralConfiguration.java +++ b/WoPeD-Core/src/main/java/org/woped/core/config/IGeneralConfiguration.java @@ -478,28 +478,28 @@ public interface IGeneralConfiguration extends IConfiguration { public ApromoreServer[] getApromoreServers(); public void addApromoreServer( - int ID, - String name, - String url, - int port, - String path, - String user, - String pwd, - boolean useProxy, - String proxyUrl, - int proxyPort); + int ID, + String name, + String url, + int port, + String path, + String user, + String pwd, + boolean useProxy, + String proxyUrl, + int proxyPort); public void changeApromoreServerSettings( - int ID, - String name, - String url, - int port, - String path, - String user, - String pwd, - boolean useProxy, - String proxyUrl, - int proxyPort); + int ID, + String name, + String url, + int port, + String path, + String user, + String pwd, + boolean useProxy, + String proxyUrl, + int proxyPort); public void removeApromoreServer(int index); @@ -560,4 +560,17 @@ public void changeApromoreServerSettings( public boolean isYAWLExportGroups(); public void setYAWLExportGroups(boolean exportGroups); + + // GPT Settings + public String getGptApiKey(); + + public void setGptApiKey(String apiKey); + + public boolean getGptShowAgain(); + + public void setGptShowAgain(boolean showAgain); + + public String getGptPrompt(); + + public void setGptPrompt(String prompt); } diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index bc47190fa..ef750d3fc 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -25,6 +25,7 @@ import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; +import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; @@ -38,601 +39,747 @@ import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; import javax.swing.JTextField; + import org.woped.core.config.ConfigurationManager; import org.woped.gui.lookAndFeel.WopedButton; import org.woped.gui.translations.Messages; /** - * @author Simon Landes
- *
- * The ConfLanguagePanel is the AbstractConfPanel for the - * configuration of the language.
- * Created on: 26.11.2004 Last Change on: 14.11.2005 + * The ConfLanguagePanel is the AbstractConfPanel for the configuration + * of the language. Created on: 26.11.2004 Last Change on: 14.11.2005 */ @SuppressWarnings("serial") public class ConfNLPToolsPanel extends AbstractConfPanel { - private JCheckBox useBox = null; - private JPanel enabledPanel = null; - private JPanel settingsPanel = null; - private JPanel settingsPanel_T2P = null; - - private JTextField serverURLText = null; - private JLabel serverURLLabel = null; - private JLabel serverPortLabel = null; - private JTextField serverPortText = null; - private JTextField managerPathText = null; - private JLabel managerPathLabel = null; - private WopedButton testButton = null; - private WopedButton defaultButton = null; - private JTextField serverURLText_T2P = null; - private JLabel serverURLLabel_T2P = null; - private JLabel serverPortLabel_T2P = null; - private JTextField serverPortText_T2P = null; - private JTextField managerPathText_T2P = null; - private JLabel managerPathLabel_T2P = null; - private WopedButton testButton_T2P = null; - private WopedButton defaultButton_T2P = null; - - /** Constructor for ConfToolsPanel. */ - public ConfNLPToolsPanel(String name) { - super(name); - initialize(); - } - - /** - * @see AbstractConfPanel#applyConfiguration() - */ - public boolean applyConfiguration() { - boolean newsetting = useBox.isSelected(); - boolean oldsetting = ConfigurationManager.getConfiguration().getProcess2TextUse(); - - if (newsetting != oldsetting) { - ConfigurationManager.getConfiguration().setProcess2TextUse(newsetting); - JOptionPane.showMessageDialog( - this, - Messages.getString("Configuration.P2T.Dialog.Restart.Message"), - Messages.getString("Configuration.P2T.Dialog.Restart.Title"), - JOptionPane.INFORMATION_MESSAGE); - } - ConfigurationManager.getConfiguration().setProcess2TextServerHost(getServerURLText().getText()); - ConfigurationManager.getConfiguration() - .setProcess2TextServerURI(getManagerPathText().getText()); - if (getServerPortText().getText().equals("")) { - ConfigurationManager.getConfiguration().setProcess2TextServerPort(0); - } else - ConfigurationManager.getConfiguration() - .setProcess2TextServerPort(Integer.parseInt(getServerPortText().getText())); - ConfigurationManager.getConfiguration().setProcess2TextUse(useBox.isSelected()); - - ConfigurationManager.getConfiguration() - .setText2ProcessServerHost(getServerURLText_T2P().getText()); - - ConfigurationManager.getConfiguration() - .setText2ProcessServerURI(getManagerPathText_T2P().getText()); - - if (getServerPortText_T2P().getText().equals("")) { - ConfigurationManager.getConfiguration().setText2ProcessServerPort(0); - } else - ConfigurationManager.getConfiguration() - .setText2ProcessServerPort(Integer.parseInt(getServerPortText_T2P().getText())); - - return true; - } - - /** - * @see AbstractConfPanel#readConfiguration() - */ - public void readConfiguration() { - - getServerURLText().setText(ConfigurationManager.getConfiguration().getProcess2TextServerHost()); - getManagerPathText() - .setText(ConfigurationManager.getConfiguration().getProcess2TextServerURI()); - getServerPortText() - .setText("" + ConfigurationManager.getConfiguration().getProcess2TextServerPort()); - getUseBox().setSelected(ConfigurationManager.getConfiguration().getProcess2TextUse()); - - getServerURLText_T2P() - .setText(ConfigurationManager.getConfiguration().getText2ProcessServerHost()); - getManagerPathText_T2P() - .setText(ConfigurationManager.getConfiguration().getText2ProcessServerURI()); - - getServerPortText_T2P() - .setText("" + ConfigurationManager.getConfiguration().getText2ProcessServerPort()); - } - - private void initialize() { - JPanel contentPanel = new JPanel(); - contentPanel.setLayout(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - c.anchor = GridBagConstraints.NORTH; - c.fill = GridBagConstraints.HORIZONTAL; - - c.weightx = 1; - c.gridx = 0; - c.gridy = 0; - contentPanel.add(getEnabledPanel(), c); - - c.weightx = 1; - c.gridx = 0; - c.gridy = 1; - contentPanel.add(getSettingsPanel(), c); - - c.weightx = 1; - c.gridx = 0; - c.gridy = 3; - contentPanel.add(getSettingsPanel_T2P(), c); - - // dummy - c.fill = GridBagConstraints.VERTICAL; - c.weighty = 1; - c.gridy = 4; - contentPanel.add(new JPanel(), c); - - setMainPanel(contentPanel); - } - - // ################## GUI COMPONENTS #################### */ - - private JTextField getServerURLText() { - if (serverURLText == null) { - serverURLText = new JTextField(); - serverURLText.setColumns(40); - serverURLText.setEnabled(true); - serverURLText.setToolTipText( - "" + Messages.getString("Configuration.P2T.Label.ServerHost") + ""); - } - return serverURLText; - } - - private JTextField getServerURLText_T2P() { - if (serverURLText_T2P == null) { - serverURLText_T2P = new JTextField(); - serverURLText_T2P.setColumns(40); - serverURLText_T2P.setEnabled(true); - serverURLText_T2P.setToolTipText( - "" + Messages.getString("Configuration.T2P.Label.ServerHost") + ""); - } - return serverURLText_T2P; - } - - private JPanel getEnabledPanel() { - if (enabledPanel == null) { - enabledPanel = new JPanel(); - enabledPanel.setLayout(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - c.anchor = GridBagConstraints.WEST; - - enabledPanel.setBorder( - BorderFactory.createCompoundBorder( - BorderFactory.createTitledBorder( - Messages.getTitle("Configuration.P2T.Enabled.Panel")), - BorderFactory.createEmptyBorder(10, 10, 10, 10))); - - c.weightx = 1; - c.gridx = 1; - c.gridy = 0; - enabledPanel.add(getUseBox(), c); - } - return enabledPanel; - } - - private JPanel getSettingsPanel() { - if (settingsPanel == null) { - settingsPanel = new JPanel(); - settingsPanel.setLayout(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - c.anchor = GridBagConstraints.WEST; - - settingsPanel.setBorder( - BorderFactory.createCompoundBorder( - BorderFactory.createTitledBorder( - Messages.getString("Configuration.P2T.Settings.Panel.Title")), - BorderFactory.createEmptyBorder(10, 10, 10, 10))); - c.weightx = 1; - c.gridx = 0; - c.gridy = 0; - settingsPanel.add(getServerURLLabel(), c); - - c.weightx = 1; - c.gridx = 1; - c.gridy = 0; - c.gridwidth = 2; - settingsPanel.add(getServerURLText(), c); - - c.weightx = 1; - c.gridx = 0; - c.gridy = 1; - c.gridwidth = 1; - settingsPanel.add(getServerPortLabel(), c); - - c.weightx = 1; - c.gridx = 1; - c.gridy = 1; - settingsPanel.add(getServerPortText(), c); - - c.weightx = 1; - c.gridx = 2; - c.gridy = 1; - settingsPanel.add(getTestButton(), c); - - c.weightx = 1; - c.gridx = 0; - c.gridy = 2; - settingsPanel.add(getManagerPathLabel(), c); - - c.weightx = 1; - c.gridx = 1; - c.gridy = 2; - c.gridwidth = 2; - settingsPanel.add(getManagerPathText(), c); - - c.weightx = 1; - c.gridx = 1; - c.gridy = 4; - settingsPanel.add(getDefaultButton(), c); - } - - settingsPanel.setVisible(getUseBox().isSelected()); - return settingsPanel; - } - - private JPanel getSettingsPanel_T2P() { - if (settingsPanel_T2P == null) { - settingsPanel_T2P = new JPanel(); - settingsPanel_T2P.setLayout(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - c.anchor = GridBagConstraints.WEST; - - settingsPanel_T2P.setBorder( - BorderFactory.createCompoundBorder( - BorderFactory.createTitledBorder( - Messages.getString("Configuration.T2P.Settings.Panel.Title")), - BorderFactory.createEmptyBorder(10, 10, 10, 10))); - c.weightx = 1; - c.gridx = 0; - c.gridy = 0; - settingsPanel_T2P.add(getServerURLLabel_T2P(), c); - - c.weightx = 1; - c.gridx = 1; - c.gridy = 0; - c.gridwidth = 2; - settingsPanel_T2P.add(getServerURLText_T2P(), c); - - c.weightx = 1; - c.gridx = 0; - c.gridy = 1; - c.gridwidth = 1; - settingsPanel_T2P.add(getServerPortLabel_T2P(), c); - - c.weightx = 1; - c.gridx = 1; - c.gridy = 1; - settingsPanel_T2P.add(getServerPortText_T2P(), c); - - c.weightx = 1; - c.gridx = 2; - c.gridy = 1; - settingsPanel_T2P.add(getTestButton_T2P(), c); - - c.weightx = 1; - c.gridx = 0; - c.gridy = 2; - settingsPanel_T2P.add(getManagerPathLabel_T2P(), c); - - c.weightx = 1; - c.gridx = 1; - c.gridy = 2; - c.gridwidth = 2; - settingsPanel_T2P.add(getManagerPathText_T2P(), c); - - c.weightx = 1; - c.gridx = 1; - c.gridy = 4; - settingsPanel_T2P.add(getDefaultButton_T2P(), c); - } - - settingsPanel_T2P.setVisible(getUseBox_T2P().isSelected()); - return settingsPanel_T2P; - } - - class CheckboxListener implements ItemListener { - - public void itemStateChanged(ItemEvent ie) { - JCheckBox jcb = (JCheckBox) ie.getSource(); - if (jcb == useBox) { - getSettingsPanel().setVisible(jcb.isSelected()); - getSettingsPanel_T2P().setVisible(jcb.isSelected()); - } - } - } - - private JLabel getServerURLLabel() { - if (serverURLLabel == null) { - serverURLLabel = - new JLabel( - "" + Messages.getString("Configuration.P2T.Label.ServerHost") + ""); - serverURLLabel.setHorizontalAlignment(JLabel.RIGHT); - } - return serverURLLabel; - } - - private JLabel getServerURLLabel_T2P() { - if (serverURLLabel_T2P == null) { - serverURLLabel_T2P = - new JLabel( - "" + Messages.getString("Configuration.T2P.Label.ServerHost") + ""); - serverURLLabel_T2P.setHorizontalAlignment(JLabel.RIGHT); - } - return serverURLLabel_T2P; - } - - private JLabel getServerPortLabel() { - if (serverPortLabel == null) { - serverPortLabel = - new JLabel( - "" + Messages.getString("Configuration.P2T.Label.ServerPort") + ""); - serverPortLabel.setHorizontalAlignment(JLabel.RIGHT); - } - return serverPortLabel; - } - - private JLabel getServerPortLabel_T2P() { - if (serverPortLabel_T2P == null) { - serverPortLabel_T2P = - new JLabel( - "" + Messages.getString("Configuration.T2P.Label.ServerPort") + ""); - serverPortLabel_T2P.setHorizontalAlignment(JLabel.RIGHT); - } - return serverPortLabel_T2P; - } - - private JTextField getServerPortText() { - if (serverPortText == null) { - serverPortText = new JTextField(); - serverPortText.setColumns(4); - serverPortText.setEnabled(true); - serverPortText.setToolTipText( - "" + Messages.getString("Configuration.P2T.Label.ServerPort") + ""); - } - return serverPortText; - } - - private JTextField getServerPortText_T2P() { - if (serverPortText_T2P == null) { - serverPortText_T2P = new JTextField(); - serverPortText_T2P.setColumns(4); - serverPortText_T2P.setEnabled(true); - serverPortText_T2P.setToolTipText( - "" + Messages.getString("Configuration.T2P.Label.ServerPort") + ""); - } - return serverPortText_T2P; - } - - private JCheckBox getUseBox() { - if (useBox == null) { - useBox = new JCheckBox(Messages.getString("Configuration.P2T.Label.Use")); - useBox.setEnabled(true); - useBox.setToolTipText( - "" + Messages.getString("Configuration.P2T.Label.Use") + ""); - CheckboxListener cbl = new CheckboxListener(); - useBox.addItemListener(cbl); - } - - return useBox; - } - - private JCheckBox getUseBox_T2P() { - if (useBox == null) { - useBox = new JCheckBox(Messages.getString("Configuration.P2T.Label.Use")); - useBox.setEnabled(true); - useBox.setToolTipText( - "" + Messages.getString("Configuration.T2P.Label.Use") + ""); - CheckboxListener cbl = new CheckboxListener(); - useBox.addItemListener(cbl); - } - - return useBox; - } - - private JLabel getManagerPathLabel() { - if (managerPathLabel == null) { - managerPathLabel = - new JLabel( - "" + Messages.getString("Configuration.P2T.Label.ServerURI") + ""); - managerPathLabel.setHorizontalAlignment(JLabel.RIGHT); - } - return managerPathLabel; - } - - private JLabel getManagerPathLabel_T2P() { - if (managerPathLabel_T2P == null) { - managerPathLabel_T2P = - new JLabel( - "" + Messages.getString("Configuration.T2P.Label.ServerURI") + ""); - managerPathLabel_T2P.setHorizontalAlignment(JLabel.RIGHT); - } - return managerPathLabel_T2P; - } - - private JTextField getManagerPathText() { - if (managerPathText == null) { - managerPathText = new JTextField(); - managerPathText.setColumns(40); - managerPathText.setEnabled(true); - managerPathText.setToolTipText( - "" + Messages.getString("Configuration.P2T.Label.ServerURI") + ""); - } - return managerPathText; - } - - private JTextField getManagerPathText_T2P() { - if (managerPathText_T2P == null) { - managerPathText_T2P = new JTextField(); - managerPathText_T2P.setColumns(40); - managerPathText_T2P.setEnabled(true); - managerPathText_T2P.setToolTipText( - "" + Messages.getString("Configuration.T2P.Label.ServerURI") + ""); - } - return managerPathText_T2P; - } - - private WopedButton getTestButton() { - if (testButton == null) { - testButton = new WopedButton(); - testButton.setText(Messages.getTitle("Button.TestConnection")); - testButton.setIcon(Messages.getImageIcon("Button.TestConnection")); - testButton.setMnemonic(Messages.getMnemonic("Button.TestConnection")); - testButton.setPreferredSize(new Dimension(160, 25)); - testButton.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - testProcess2TextConnection(); - } - }); - } - - return testButton; - } - - private WopedButton getTestButton_T2P() { - if (testButton_T2P == null) { - testButton_T2P = new WopedButton(); - testButton_T2P.setText(Messages.getTitle("Button.TestConnection")); - testButton_T2P.setIcon(Messages.getImageIcon("Button.TestConnection")); - testButton_T2P.setMnemonic(Messages.getMnemonic("Button.TestConnection")); - testButton_T2P.setPreferredSize(new Dimension(160, 25)); - testButton_T2P.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - testText2ProcessConnection(); + private JCheckBox useBox = null; + private JPanel enabledPanel = null; + private JPanel settingsPanel = null; + private JPanel settingsPanel_T2P = null; + private JPanel additionalPanel = null; + + private JTextField serverURLText = null; + private JLabel serverURLLabel = null; + private JLabel serverPortLabel = null; + private JTextField serverPortText = null; + private JTextField managerPathText = null; + private JLabel managerPathLabel = null; + private WopedButton testButton = null; + private WopedButton defaultButton = null; + private JTextField serverURLText_T2P = null; + private JLabel serverURLLabel_T2P = null; + private JLabel serverPortLabel_T2P = null; + private JTextField serverPortText_T2P = null; + private JTextField managerPathText_T2P = null; + private JLabel managerPathLabel_T2P = null; + private WopedButton testButton_T2P = null; + private WopedButton defaultButton_T2P = null; + + // Components for additionalPanel + private JTextField apiKeyText = null; + private JCheckBox showAgainBox = null; + private WopedButton resetButton = null; + private JTextArea promptText = null; + private WopedButton checkConnectionButton = null; + + /** + * Constructor for ConfToolsPanel. + */ + public ConfNLPToolsPanel(String name) { + super(name); + initialize(); + } + + /** + * @see AbstractConfPanel#applyConfiguration() + */ + public boolean applyConfiguration() { + boolean newsetting = useBox.isSelected(); + boolean oldsetting = ConfigurationManager.getConfiguration().getProcess2TextUse(); + + if (newsetting != oldsetting) { + ConfigurationManager.getConfiguration().setProcess2TextUse(newsetting); + JOptionPane.showMessageDialog( + this, + Messages.getString("Configuration.P2T.Dialog.Restart.Message"), + Messages.getString("Configuration.P2T.Dialog.Restart.Title"), + JOptionPane.INFORMATION_MESSAGE); + } + ConfigurationManager.getConfiguration().setProcess2TextServerHost(getServerURLText().getText()); + ConfigurationManager.getConfiguration().setProcess2TextServerURI(getManagerPathText().getText()); + if (getServerPortText().getText().equals("")) { + ConfigurationManager.getConfiguration().setProcess2TextServerPort(0); + } else + ConfigurationManager.getConfiguration() + .setProcess2TextServerPort(Integer.parseInt(getServerPortText().getText())); + ConfigurationManager.getConfiguration().setProcess2TextUse(useBox.isSelected()); + + ConfigurationManager.getConfiguration().setText2ProcessServerHost(getServerURLText_T2P().getText()); + + ConfigurationManager.getConfiguration().setText2ProcessServerURI(getManagerPathText_T2P().getText()); + + if (getServerPortText_T2P().getText().equals("")) { + ConfigurationManager.getConfiguration().setText2ProcessServerPort(0); + } else + ConfigurationManager.getConfiguration() + .setText2ProcessServerPort(Integer.parseInt(getServerPortText_T2P().getText())); + + // Save additional panel configurations + ConfigurationManager.getConfiguration().setGptApiKey(getApiKeyText().getText()); + ConfigurationManager.getConfiguration().setGptShowAgain(getShowAgainBox().isSelected()); + ConfigurationManager.getConfiguration().setGptPrompt(getPromptText().getText()); + + return true; + } + + /** + * @see AbstractConfPanel#readConfiguration() + */ + public void readConfiguration() { + + getServerURLText().setText(ConfigurationManager.getConfiguration().getProcess2TextServerHost()); + getManagerPathText().setText(ConfigurationManager.getConfiguration().getProcess2TextServerURI()); + getServerPortText().setText("" + ConfigurationManager.getConfiguration().getProcess2TextServerPort()); + getUseBox().setSelected(ConfigurationManager.getConfiguration().getProcess2TextUse()); + + getServerURLText_T2P().setText(ConfigurationManager.getConfiguration().getText2ProcessServerHost()); + getManagerPathText_T2P().setText(ConfigurationManager.getConfiguration().getText2ProcessServerURI()); + + getServerPortText_T2P().setText("" + ConfigurationManager.getConfiguration().getText2ProcessServerPort()); + + // Load additional panel configurations + getApiKeyText().setText(ConfigurationManager.getConfiguration().getGptApiKey()); + getShowAgainBox().setSelected(ConfigurationManager.getConfiguration().getGptShowAgain()); + getPromptText().setText(ConfigurationManager.getConfiguration().getGptPrompt()); + } + + private void initialize() { + JPanel contentPanel = new JPanel(); + contentPanel.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.anchor = GridBagConstraints.NORTH; + c.fill = GridBagConstraints.HORIZONTAL; + c.insets = new Insets(2, 0, 2, 0); // Small vertical gap between elements + + c.weightx = 1; + c.gridx = 0; + c.gridy = 0; + contentPanel.add(getEnabledPanel(), c); + + c.weightx = 1; + c.gridx = 0; + c.gridy = 1; + contentPanel.add(getSettingsPanel(), c); + + c.weightx = 1; + c.gridx = 0; + c.gridy = 2; + contentPanel.add(getSettingsPanel_T2P(), c); + + c.weightx = 1; + c.gridx = 0; + c.gridy = 3; + contentPanel.add(getAdditionalPanel(), c); + + // dummy + c.fill = GridBagConstraints.VERTICAL; + c.weighty = 1; + c.gridy = 4; + contentPanel.add(new JPanel(), c); + + setMainPanel(contentPanel); + } + + // ################## GUI COMPONENTS #################### */ + + private JTextField getServerURLText() { + if (serverURLText == null) { + serverURLText = new JTextField(); + serverURLText.setColumns(40); + serverURLText.setEnabled(true); + serverURLText.setToolTipText( + "" + Messages.getString("Configuration.P2T.Label.ServerHost") + ""); + } + return serverURLText; + } + + private JTextField getServerURLText_T2P() { + if (serverURLText_T2P == null) { + serverURLText_T2P = new JTextField(); + serverURLText_T2P.setColumns(40); + serverURLText_T2P.setEnabled(true); + serverURLText_T2P.setToolTipText( + "" + Messages.getString("Configuration.T2P.Label.ServerHost") + ""); + } + return serverURLText_T2P; + } + + private JPanel getEnabledPanel() { + if (enabledPanel == null) { + enabledPanel = new JPanel(); + enabledPanel.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.anchor = GridBagConstraints.WEST; + c.insets = new Insets(2, 0, 2, 0); // Small vertical gap between elements + + enabledPanel.setBorder( + BorderFactory.createCompoundBorder( + BorderFactory.createTitledBorder(Messages.getTitle("Configuration.P2T.Enabled.Panel")), + BorderFactory.createEmptyBorder(10, 10, 10, 10))); + + c.weightx = 1; + c.gridx = 1; + c.gridy = 0; + enabledPanel.add(getUseBox(), c); + } + return enabledPanel; + } + + private JPanel getSettingsPanel() { + if (settingsPanel == null) { + settingsPanel = new JPanel(); + settingsPanel.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.anchor = GridBagConstraints.WEST; + c.insets = new Insets(2, 0, 2, 0); // Small vertical gap between elements + + settingsPanel.setBorder( + BorderFactory.createCompoundBorder( + BorderFactory.createTitledBorder(Messages.getString("Configuration.P2T.Settings.Panel.Title")), + BorderFactory.createEmptyBorder(10, 10, 10, 10))); + c.weightx = 1; + c.gridx = 0; + c.gridy = 0; + settingsPanel.add(getServerURLLabel(), c); + + c.weightx = 1; + c.gridx = 1; + c.gridy = 0; + c.gridwidth = 2; + settingsPanel.add(getServerURLText(), c); + + c.weightx = 1; + c.gridx = 0; + c.gridy = 1; + c.gridwidth = 1; + settingsPanel.add(getServerPortLabel(), c); + + c.weightx = 1; + c.gridx = 1; + c.gridy = 1; + settingsPanel.add(getServerPortText(), c); + + c.weightx = 1; + c.gridx = 2; + c.gridy = 1; + settingsPanel.add(getTestButton(), c); + + c.weightx = 1; + c.gridx = 0; + c.gridy = 2; + settingsPanel.add(getManagerPathLabel(), c); + + c.weightx = 1; + c.gridx = 1; + c.gridy = 2; + c.gridwidth = 2; + settingsPanel.add(getManagerPathText(), c); + + c.weightx = 1; + c.gridx = 1; + c.gridy = 4; + settingsPanel.add(getDefaultButton(), c); + } + + settingsPanel.setVisible(getUseBox().isSelected()); + return settingsPanel; + } + + private JPanel getSettingsPanel_T2P() { + if (settingsPanel_T2P == null) { + settingsPanel_T2P = new JPanel(); + settingsPanel_T2P.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.anchor = GridBagConstraints.WEST; + c.insets = new Insets(2, 0, 2, 0); // Small vertical gap between elements + + settingsPanel_T2P.setBorder( + BorderFactory.createCompoundBorder( + BorderFactory.createTitledBorder(Messages.getString("Configuration.T2P.Settings.Panel.Title")), + BorderFactory.createEmptyBorder(10, 10, 10, 10))); + c.weightx = 1; + c.gridx = 0; + c.gridy = 0; + settingsPanel_T2P.add(getServerURLLabel_T2P(), c); + + c.weightx = 1; + c.gridx = 1; + c.gridy = 0; + c.gridwidth = 2; + settingsPanel_T2P.add(getServerURLText_T2P(), c); + + c.weightx = 1; + c.gridx = 0; + c.gridy = 1; + c.gridwidth = 1; + settingsPanel_T2P.add(getServerPortLabel_T2P(), c); + + c.weightx = 1; + c.gridx = 1; + c.gridy = 1; + settingsPanel_T2P.add(getServerPortText_T2P(), c); + + c.weightx = 1; + c.gridx = 2; + c.gridy = 1; + settingsPanel_T2P.add(getTestButton_T2P(), c); + + c.weightx = 1; + c.gridx = 0; + c.gridy = 2; + settingsPanel_T2P.add(getManagerPathLabel_T2P(), c); + + c.weightx = 1; + c.gridx = 1; + c.gridy = 2; + c.gridwidth = 2; + settingsPanel_T2P.add(getManagerPathText_T2P(), c); + + c.weightx = 1; + c.gridx = 1; + c.gridy = 4; + settingsPanel_T2P.add(getDefaultButton_T2P(), c); + } + + settingsPanel_T2P.setVisible(getUseBox_T2P().isSelected()); + return settingsPanel_T2P; + } + + private JPanel getAdditionalPanel() { + if (additionalPanel == null) { + additionalPanel = new JPanel(); + additionalPanel.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.anchor = GridBagConstraints.WEST; + c.insets = new Insets(2, 0, 2, 0); // Small vertical gap between elements + + additionalPanel.setBorder( + BorderFactory.createCompoundBorder( + BorderFactory.createTitledBorder("GPT Settings"), + BorderFactory.createEmptyBorder(10, 10, 10, 10))); + + c.weightx = 1; + c.gridx = 0; + c.gridy = 0; + additionalPanel.add(new JLabel("API-Key:"), c); + + c.weightx = 1; + c.gridx = 1; + c.gridy = 0; + additionalPanel.add(getApiKeyText(), c); + + c.weightx = 1; + c.gridx = 0; + c.gridy = 1; + additionalPanel.add(new JLabel("Prompt:"), c); + + c.weightx = 1; + c.gridx = 1; + c.gridy = 1; + c.gridwidth = 2; + additionalPanel.add(getPromptTextScrollPane(), c); + + c.weightx = 1; + c.gridx = 0; + c.gridy = 2; + additionalPanel.add(getShowAgainBox(), c); + + c.weightx = 1; + c.gridx = 1; + c.gridy = 2; + additionalPanel.add(getResetButton(), c); + + c.weightx = 1; + c.gridx = 2; + c.gridy = 2; + additionalPanel.add(getCheckConnectionButton(), c); + + } + return additionalPanel; + } + + private JScrollPane getPromptTextScrollPane() { + JScrollPane scrollPane = new JScrollPane(getPromptText()); + scrollPane.setPreferredSize(new Dimension(getApiKeyText().getPreferredSize().width, 100)); + return scrollPane; + } + + private JTextField getApiKeyText() { + if (apiKeyText == null) { + apiKeyText = new JTextField(); + apiKeyText.setColumns(40); + apiKeyText.setEnabled(true); + } + return apiKeyText; + } + + private JTextArea getPromptText() { + if (promptText == null) { + promptText = new JTextArea(); + promptText.setColumns(40); + promptText.setRows(5); + promptText.setLineWrap(true); + promptText.setWrapStyleWord(true); + promptText.setEnabled(true); + promptText.setText( + "Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"); + } + return promptText; + } + + private JCheckBox getShowAgainBox() { + if (showAgainBox == null) { + showAgainBox = new JCheckBox("Show Again"); + showAgainBox.setEnabled(true); + showAgainBox.setToolTipText("Test"); + } + return showAgainBox; + } + + private WopedButton getResetButton() { + if (resetButton == null) { + resetButton = new WopedButton(); + resetButton.setText("Auf Standard zurücksetzen"); + resetButton.setPreferredSize(new Dimension(200, 25)); + resetButton.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + setDefaultValuesGPT(); + System.out.println(ConfigurationManager.getConfiguration().getGptShowAgain()); + System.out.println(ConfigurationManager.getConfiguration().getGptPrompt()); + } + }); + } + return resetButton; + } + + private WopedButton getCheckConnectionButton() { + if (checkConnectionButton == null) { + checkConnectionButton = new WopedButton(); + checkConnectionButton.setText("Verbindung überprüfen"); + checkConnectionButton.setIcon(Messages.getImageIcon("Button.TestConnection")); + checkConnectionButton.setMnemonic(Messages.getMnemonic("Button.TestConnection")); + checkConnectionButton.setPreferredSize(new Dimension(200, 25)); + checkConnectionButton.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + testGPTConnection(); + } + }); + } + return checkConnectionButton; + } + + private void testGPTConnection() { + // Implement connection test logic for GPT here + JOptionPane.showMessageDialog( + this.getAdditionalPanel(), + "GPT connection test not implemented.", + "Connection Test", + JOptionPane.INFORMATION_MESSAGE); + } + + private void setDefaultValuesGPT() { + getApiKeyText().setText(ConfigurationManager.getStandardConfiguration().getGptApiKey()); + getShowAgainBox().setSelected(ConfigurationManager.getStandardConfiguration().getGptShowAgain()); + getPromptText().setText(ConfigurationManager.getStandardConfiguration().getGptPrompt()); + } + + class CheckboxListener implements ItemListener { + + public void itemStateChanged(ItemEvent ie) { + JCheckBox jcb = (JCheckBox) ie.getSource(); + if (jcb == useBox) { + getSettingsPanel().setVisible(jcb.isSelected()); + getSettingsPanel_T2P().setVisible(jcb.isSelected()); } - }); + } + } + + private JLabel getServerURLLabel() { + if (serverURLLabel == null) { + serverURLLabel = + new JLabel("" + Messages.getString("Configuration.P2T.Label.ServerHost") + ""); + serverURLLabel.setHorizontalAlignment(JLabel.RIGHT); + } + return serverURLLabel; + } + + private JLabel getServerURLLabel_T2P() { + if (serverURLLabel_T2P == null) { + serverURLLabel_T2P = + new JLabel("" + Messages.getString("Configuration.T2P.Label.ServerHost") + ""); + serverURLLabel_T2P.setHorizontalAlignment(JLabel.RIGHT); + } + return serverURLLabel_T2P; + } + + private JLabel getServerPortLabel() { + if (serverPortLabel == null) { + serverPortLabel = + new JLabel("" + Messages.getString("Configuration.P2T.Label.ServerPort") + ""); + serverPortLabel.setHorizontalAlignment(JLabel.RIGHT); + } + return serverPortLabel; + } + + private JLabel getServerPortLabel_T2P() { + if (serverPortLabel_T2P == null) { + serverPortLabel_T2P = + new JLabel("" + Messages.getString("Configuration.T2P.Label.ServerPort") + ""); + serverPortLabel_T2P.setHorizontalAlignment(JLabel.RIGHT); + } + return serverPortLabel_T2P; + } + + private JTextField getServerPortText() { + if (serverPortText == null) { + serverPortText = new JTextField(); + serverPortText.setColumns(4); + serverPortText.setEnabled(true); + serverPortText.setToolTipText("" + Messages.getString("Configuration.P2T.Label.ServerPort") + ""); + } + return serverPortText; } - return testButton_T2P; - } + private JTextField getServerPortText_T2P() { + if (serverPortText_T2P == null) { + serverPortText_T2P = new JTextField(); + serverPortText_T2P.setColumns(4); + serverPortText_T2P.setEnabled(true); + serverPortText_T2P.setToolTipText("" + Messages.getString("Configuration.T2P.Label.ServerPort") + ""); + } + return serverPortText_T2P; + } + + private JCheckBox getUseBox() { + if (useBox == null) { + useBox = new JCheckBox(Messages.getString("Configuration.P2T.Label.Use")); + useBox.setEnabled(true); + useBox.setToolTipText("" + Messages.getString("Configuration.P2T.Label.Use") + ""); + CheckboxListener cbl = new CheckboxListener(); + useBox.addItemListener(cbl); + } + + return useBox; + } + + private JCheckBox getUseBox_T2P() { + if (useBox == null) { + useBox = new JCheckBox(Messages.getString("Configuration.P2T.Label.Use")); + useBox.setEnabled(true); + useBox.setToolTipText("" + Messages.getString("Configuration.T2P.Label.Use") + ""); + CheckboxListener cbl = new CheckboxListener(); + useBox.addItemListener(cbl); + } + + return useBox; + } + + private JLabel getManagerPathLabel() { + if (managerPathLabel == null) { + managerPathLabel = + new JLabel("" + Messages.getString("Configuration.P2T.Label.ServerURI") + ""); + managerPathLabel.setHorizontalAlignment(JLabel.RIGHT); + } + return managerPathLabel; + } + + private JLabel getManagerPathLabel_T2P() { + if (managerPathLabel_T2P == null) { + managerPathLabel_T2P = + new JLabel("" + Messages.getString("Configuration.T2P.Label.ServerURI") + ""); + managerPathLabel_T2P.setHorizontalAlignment(JLabel.RIGHT); + } + return managerPathLabel_T2P; + } - private WopedButton getDefaultButton() { - if (defaultButton == null) { - defaultButton = new WopedButton(); - defaultButton.setText(Messages.getTitle("Button.SetToDefault")); - defaultButton.setPreferredSize(new Dimension(200, 25)); - defaultButton.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - setDefaultValues(); + private JTextField getManagerPathText() { + if (managerPathText == null) { + managerPathText = new JTextField(); + managerPathText.setColumns(40); + managerPathText.setEnabled(true); + managerPathText.setToolTipText("" + Messages.getString("Configuration.P2T.Label.ServerURI") + ""); + } + return managerPathText; + } + + private JTextField getManagerPathText_T2P() { + if (managerPathText_T2P == null) { + managerPathText_T2P = new JTextField(); + managerPathText_T2P.setColumns(40); + managerPathText_T2P.setEnabled(true); + managerPathText_T2P.setToolTipText("" + Messages.getString("Configuration.T2P.Label.ServerURI") + ""); + } + return managerPathText_T2P; + } + + private WopedButton getTestButton() { + if (testButton == null) { + testButton = new WopedButton(); + testButton.setText(Messages.getTitle("Button.TestConnection")); + testButton.setIcon(Messages.getImageIcon("Button.TestConnection")); + testButton.setMnemonic(Messages.getMnemonic("Button.TestConnection")); + testButton.setPreferredSize(new Dimension(160, 25)); + testButton.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + testProcess2TextConnection(); + } + }); + } + + return testButton; + } + + private WopedButton getTestButton_T2P() { + if (testButton_T2P == null) { + testButton_T2P = new WopedButton(); + testButton_T2P.setText(Messages.getTitle("Button.TestConnection")); + testButton_T2P.setIcon(Messages.getImageIcon("Button.TestConnection")); + testButton_T2P.setMnemonic(Messages.getMnemonic("Button.TestConnection")); + testButton_T2P.setPreferredSize(new Dimension(160, 25)); + testButton_T2P.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + testText2ProcessConnection(); + } + }); + } + + return testButton_T2P; + } + + private WopedButton getDefaultButton() { + if (defaultButton == null) { + defaultButton = new WopedButton(); + defaultButton.setText(Messages.getTitle("Button.SetToDefault")); + defaultButton.setPreferredSize(new Dimension(200, 25)); + defaultButton.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + setDefaultValues(); + } + }); + } + return defaultButton; + } + + private WopedButton getDefaultButton_T2P() { + if (defaultButton_T2P == null) { + defaultButton_T2P = new WopedButton(); + defaultButton_T2P.setText(Messages.getTitle("Button.SetToDefault")); + defaultButton_T2P.setPreferredSize(new Dimension(200, 25)); + defaultButton_T2P.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + setDefaultValues_T2P(); + } + }); + } + return defaultButton_T2P; + } + + private void testProcess2TextConnection() { + URL url = null; + String connection = + "http://" + + getServerURLText().getText() + + ":" + + getServerPortText().getText() + + getManagerPathText().getText(); + String arg[] = {connection, ""}; + + try { + url = new URL(connection); + URLConnection urlConnection = url.openConnection(); + + if (urlConnection.getContent() != null) { + arg[1] = "P2T"; + JOptionPane.showMessageDialog( + this.getSettingsPanel(), + Messages.getString("Paraphrasing.Webservice.Success.Message", arg), + Messages.getString("Paraphrasing.Webservice.Success.Title"), + JOptionPane.INFORMATION_MESSAGE); } - }); - } - return defaultButton; - } - - private WopedButton getDefaultButton_T2P() { - if (defaultButton_T2P == null) { - defaultButton_T2P = new WopedButton(); - defaultButton_T2P.setText(Messages.getTitle("Button.SetToDefault")); - defaultButton_T2P.setPreferredSize(new Dimension(200, 25)); - defaultButton_T2P.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - setDefaultValues_T2P(); + } catch (MalformedURLException mue) { + JOptionPane.showMessageDialog( + this.getSettingsPanel(), + Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), + Messages.getString("Paraphrasing.Webservice.Error.Title"), + JOptionPane.ERROR_MESSAGE); + } catch (IOException ex) { + JOptionPane.showMessageDialog( + this.getSettingsPanel(), + Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), + Messages.getString("Paraphrasing.Webservice.Error.Title"), + JOptionPane.ERROR_MESSAGE); + } + } + + private void testText2ProcessConnection() { + URL url = null; + String connection = + "http://" + + getServerURLText_T2P().getText() + + ":" + + getServerPortText_T2P().getText() + + getManagerPathText_T2P().getText() + + ""; + String arg[] = {connection, ""}; + + try { + url = new URL(connection); + URLConnection urlConnection = url.openConnection(); + if (urlConnection.getContent() != null) { + arg[1] = "T2P"; + JOptionPane.showMessageDialog( + this.getSettingsPanel_T2P(), + Messages.getString("Paraphrasing.Webservice.Success.Message", arg), + Messages.getString("Paraphrasing.Webservice.Success.Title"), + JOptionPane.INFORMATION_MESSAGE); } - }); - } - return defaultButton_T2P; - } - - private void testProcess2TextConnection() { - URL url = null; - String connection = - "http://" - + getServerURLText().getText() - + ":" - + getServerPortText().getText() - + getManagerPathText().getText(); - String arg[] = {connection, ""}; - - try { - url = new URL(connection); - URLConnection urlConnection = url.openConnection(); - - if (urlConnection.getContent() != null) { - arg[1] = "P2T"; - JOptionPane.showMessageDialog( - this.getSettingsPanel(), - Messages.getString("Paraphrasing.Webservice.Success.Message", arg), - Messages.getString("Paraphrasing.Webservice.Success.Title"), - JOptionPane.INFORMATION_MESSAGE); - } - } catch (MalformedURLException mue) { - JOptionPane.showMessageDialog( - this.getSettingsPanel(), - Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), - Messages.getString("Paraphrasing.Webservice.Error.Title"), - JOptionPane.ERROR_MESSAGE); - } catch (IOException ex) { - JOptionPane.showMessageDialog( - this.getSettingsPanel(), - Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), - Messages.getString("Paraphrasing.Webservice.Error.Title"), - JOptionPane.ERROR_MESSAGE); - } - } - - private void testText2ProcessConnection() { - URL url = null; - String connection = - "http://" - + getServerURLText_T2P().getText() - + ":" - + getServerPortText_T2P().getText() - + getManagerPathText_T2P().getText() - + ""; - String arg[] = {connection, ""}; - - try { - url = new URL(connection); - URLConnection urlConnection = url.openConnection(); - if (urlConnection.getContent() != null) { - arg[1] = "T2P"; - JOptionPane.showMessageDialog( - this.getSettingsPanel_T2P(), - Messages.getString("Paraphrasing.Webservice.Success.Message", arg), - Messages.getString("Paraphrasing.Webservice.Success.Title"), - JOptionPane.INFORMATION_MESSAGE); - } - } catch (MalformedURLException mue) { - JOptionPane.showMessageDialog( - this.getSettingsPanel_T2P(), - Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), - Messages.getString("Paraphrasing.Webservice.Error.Title"), - JOptionPane.ERROR_MESSAGE); - } catch (IOException ex) { - JOptionPane.showMessageDialog( - this.getSettingsPanel_T2P(), - Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), - Messages.getString("Paraphrasing.Webservice.Error.Title"), - JOptionPane.ERROR_MESSAGE); - } - } - - private void setDefaultValues() { - getServerURLText() - .setText(ConfigurationManager.getStandardConfiguration().getProcess2TextServerHost()); - getManagerPathText() - .setText(ConfigurationManager.getStandardConfiguration().getProcess2TextServerURI()); - getServerPortText() - .setText("" + ConfigurationManager.getStandardConfiguration().getProcess2TextServerPort()); - } - - private void setDefaultValues_T2P() { - getServerURLText_T2P() - .setText(ConfigurationManager.getStandardConfiguration().getText2ProcessServerHost()); - getManagerPathText_T2P() - .setText(ConfigurationManager.getStandardConfiguration().getText2ProcessServerURI()); - getServerPortText_T2P() - .setText("" + ConfigurationManager.getStandardConfiguration().getText2ProcessServerPort()); - } + } catch (MalformedURLException mue) { + JOptionPane.showMessageDialog( + this.getSettingsPanel_T2P(), + Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), + Messages.getString("Paraphrasing.Webservice.Error.Title"), + JOptionPane.ERROR_MESSAGE); + } catch (IOException ex) { + JOptionPane.showMessageDialog( + this.getSettingsPanel_T2P(), + Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), + Messages.getString("Paraphrasing.Webservice.Error.Title"), + JOptionPane.ERROR_MESSAGE); + } + } + + private void setDefaultValues() { + getServerURLText() + .setText(ConfigurationManager.getStandardConfiguration().getProcess2TextServerHost()); + getManagerPathText() + .setText(ConfigurationManager.getStandardConfiguration().getProcess2TextServerURI()); + getServerPortText() + .setText("" + ConfigurationManager.getStandardConfiguration().getProcess2TextServerPort()); + } + + private void setDefaultValues_T2P() { + getServerURLText_T2P() + .setText(ConfigurationManager.getStandardConfiguration().getText2ProcessServerHost()); + getManagerPathText_T2P() + .setText(ConfigurationManager.getStandardConfiguration().getText2ProcessServerURI()); + getServerPortText_T2P() + .setText("" + ConfigurationManager.getStandardConfiguration().getText2ProcessServerPort()); + } } From 4006920123af577a6bbdc6726610b04fbd84a093 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Mon, 10 Jun 2024 00:25:58 +0200 Subject: [PATCH 08/76] added api key validation --- .../editor/gui/config/ConfNLPToolsPanel.java | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index ef750d3fc..7eca86a10 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -31,6 +31,7 @@ import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.io.IOException; +import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -482,12 +483,38 @@ public void actionPerformed(ActionEvent e) { } private void testGPTConnection() { - // Implement connection test logic for GPT here - JOptionPane.showMessageDialog( - this.getAdditionalPanel(), - "GPT connection test not implemented.", - "Connection Test", - JOptionPane.INFORMATION_MESSAGE); + String apiKey = apiKeyText.getText(); // Annahme: Methode zum Abrufen des API-Schlüssels ist vorhanden + String urlString = "https://api.openai.com/v1/engines"; + + try { + URL url = new URL(urlString); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Authorization", "Bearer " + apiKey); + connection.connect(); + + int responseCode = connection.getResponseCode(); + String message; + + if (responseCode == 200) { + message = "GPT connection successful. Response Code: " + responseCode; + } else { + message = "GPT connection failed. Response Code: " + responseCode; + } + + JOptionPane.showMessageDialog( + this.getAdditionalPanel(), + message, + "Connection Test", + JOptionPane.INFORMATION_MESSAGE); + + } catch (IOException e) { + JOptionPane.showMessageDialog( + this.getAdditionalPanel(), + "GPT connection test failed: " + e.getMessage(), + "Connection Test", + JOptionPane.ERROR_MESSAGE); + } } private void setDefaultValuesGPT() { From 9ae6edf499f67f2edda503e2bb24356915d7f5bc Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Mon, 10 Jun 2024 00:30:21 +0200 Subject: [PATCH 09/76] added default prompt in settings --- .../org/woped/core/config/DefaultStaticConfiguration.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WoPeD-Core/src/main/java/org/woped/core/config/DefaultStaticConfiguration.java b/WoPeD-Core/src/main/java/org/woped/core/config/DefaultStaticConfiguration.java index f3d0b9eae..157fd6155 100644 --- a/WoPeD-Core/src/main/java/org/woped/core/config/DefaultStaticConfiguration.java +++ b/WoPeD-Core/src/main/java/org/woped/core/config/DefaultStaticConfiguration.java @@ -191,9 +191,9 @@ public class DefaultStaticConfiguration implements IGeneralConfiguration { private boolean yawlExportGroups = false; // GPT settings - private String gptApiKey = "test"; + private String gptApiKey = ""; private boolean gptShowAgain = true; - private String gptPrompt = "test"; + private String gptPrompt = "Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"; public DefaultStaticConfiguration() { initConfig(); From c4b02fe27842d77d7cfb834c19375801f78b7c07 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Mon, 10 Jun 2024 00:40:06 +0200 Subject: [PATCH 10/76] added clause so that old/new UI doesn't show if checkAgain == false added a clause that makes sure, that the UI to choose between the old / new option doesn't show if it's not enabled in the settings --- .../starter/controller/vep/GUIViewEventProcessor.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java b/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java index d21aaacad..338d9bbf3 100644 --- a/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java +++ b/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java @@ -87,11 +87,14 @@ && getMediator().getUi().getComponent() instanceof JFrame) { P2TUI p2t; if (getMediator().getUi() != null && getMediator().getUi().getComponent() instanceof JFrame) { - p2t = new P2TUI((JFrame) getMediator().getUi(), getMediator()); + { + p2t = new P2TUI((JFrame) getMediator().getUi(), getMediator());} } else { p2t = new P2TUI(getMediator()); } - p2t.setVisible(true); + if(ConfigurationManager.getConfiguration().getGptShowAgain()){ + p2t.setVisible(true); + } break; case AbstractViewEvent.NEW: getMediator().createEditor(true); From 1d705eb7baa5da2253337875597e82f6e93c4130 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Mon, 10 Jun 2024 00:50:58 +0200 Subject: [PATCH 11/76] added checkbox in p2tUI "don't show again" Added a checkbox that allows the user to hide the new/old option upon using p2t nlp tools --- .../src/main/java/org/woped/file/p2t/P2TUI.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 514c3cdf8..da61b87c4 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -38,6 +38,7 @@ public class P2TUI extends JDialog { private JTextField apiKeyField; private JTextArea promptField; // Changed to JTextArea for multiline private JCheckBox enablePromptCheckBox; // New Checkbox + private JCheckBox showAgainCheckBox; // New Checkbox private static final String DEFAULT_PROMPT = "Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"; public P2TUI(AbstractApplicationMediator mediator) { @@ -66,7 +67,7 @@ private void initialize() { this.pack(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation((screenSize.width - this.getWidth()) / 3, (screenSize.height - this.getHeight()) / 3); - Dimension size = new Dimension(600, 300); // Adjusted size to accommodate new text field and checkbox + Dimension size = new Dimension(600, 350); // Adjusted size to accommodate new text field and checkbox this.setSize(size); } @@ -126,11 +127,16 @@ private JPanel initializeSwitchButtonPanel() { } }); + showAgainCheckBox = new JCheckBox("Don't show Again"); + showAgainCheckBox.setSelected(true); + showAgainCheckBox.setToolTipText("Placeholder"); + apiKeyLabel.setVisible(false); apiKeyField.setVisible(false); promptLabel.setVisible(false); promptScrollPane.setVisible(false); enablePromptCheckBox.setVisible(false); + showAgainCheckBox.setVisible(false); // Initially hidden newRadioButton.addActionListener(e -> { apiKeyLabel.setVisible(true); @@ -138,6 +144,7 @@ private JPanel initializeSwitchButtonPanel() { promptLabel.setVisible(true); promptScrollPane.setVisible(true); enablePromptCheckBox.setVisible(true); + showAgainCheckBox.setVisible(true); // Show when new service is selected apiKeyField.requestFocusInWindow(); }); @@ -147,6 +154,7 @@ private JPanel initializeSwitchButtonPanel() { promptLabel.setVisible(false); promptScrollPane.setVisible(false); enablePromptCheckBox.setVisible(false); + showAgainCheckBox.setVisible(false); // Hide when old service is selected }); // Set "alt" as default selection @@ -180,6 +188,12 @@ private JPanel initializeSwitchButtonPanel() { gbc.weightx = 1.0; fieldsPanel.add(enablePromptCheckBox, gbc); + gbc.gridx = 0; + gbc.gridy = 4; + gbc.gridwidth = 2; + gbc.weightx = 1.0; + fieldsPanel.add(showAgainCheckBox, gbc); // Add "Show Again" checkbox + gbc.gridx = 0; gbc.gridy = 1; gbc.gridwidth = 2; From 0f0c449fd325323437fe7caee7cd508d377ed4fa Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Mon, 10 Jun 2024 00:57:12 +0200 Subject: [PATCH 12/76] refactored apikey validation refactored the apiKey validation so that it only checks validity, if the "new" option is actually selected via the radio button --- .../src/main/java/org/woped/file/p2t/P2TUI.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index da61b87c4..0fdae44c5 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -39,6 +39,8 @@ public class P2TUI extends JDialog { private JTextArea promptField; // Changed to JTextArea for multiline private JCheckBox enablePromptCheckBox; // New Checkbox private JCheckBox showAgainCheckBox; // New Checkbox + private JRadioButton newRadioButton = null; + private JRadioButton oldRadioButton = null; private static final String DEFAULT_PROMPT = "Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"; public P2TUI(AbstractApplicationMediator mediator) { @@ -78,8 +80,8 @@ private JPanel initializeSwitchButtonPanel() { JPanel radioPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbcRadio = new GridBagConstraints(); - JRadioButton oldRadioButton = new JRadioButton(Messages.getString("P2T.oldservice.title")); - JRadioButton newRadioButton = new JRadioButton(Messages.getString("P2T.newservice.title")); + oldRadioButton = new JRadioButton(Messages.getString("P2T.oldservice.title")); + newRadioButton = new JRadioButton(Messages.getString("P2T.newservice.title")); ButtonGroup group = new ButtonGroup(); group.add(oldRadioButton); group.add(newRadioButton); @@ -210,7 +212,14 @@ private JPanel initializeSingleButtonPanel() { JButton singleButton = new JButton(new AbstractAction() { public void actionPerformed(ActionEvent arg0) { - validateAPIKey(); + if (newRadioButton.isSelected()) { + validateAPIKey(); + //GPT Aufrufen + } + else { + //GPT Aufrufen + } + } }); From 72cda0ef3bacf86c70e9fe528fc39ef9e5d25ddb Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Mon, 10 Jun 2024 01:41:38 +0200 Subject: [PATCH 13/76] added logic to show again button in old/new UI, added config changes based on apikey / prompt added logic to show again button in old/new UI, added config changes based on apikey / prompt --- .../woped/beanconfiguration/configuration.xsd | 2 +- .../editor/gui/config/ConfNLPToolsPanel.java | 2 +- .../main/java/org/woped/file/p2t/P2TUI.java | 53 +++++++++++-------- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/WoPeD-BeanConfiguration/src/main/java/org/woped/beanconfiguration/configuration.xsd b/WoPeD-BeanConfiguration/src/main/java/org/woped/beanconfiguration/configuration.xsd index c7d8adf69..e03fccdf6 100644 --- a/WoPeD-BeanConfiguration/src/main/java/org/woped/beanconfiguration/configuration.xsd +++ b/WoPeD-BeanConfiguration/src/main/java/org/woped/beanconfiguration/configuration.xsd @@ -141,7 +141,7 @@ - + diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index 7eca86a10..9d333a3af 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -128,7 +128,7 @@ public boolean applyConfiguration() { // Save additional panel configurations ConfigurationManager.getConfiguration().setGptApiKey(getApiKeyText().getText()); - ConfigurationManager.getConfiguration().setGptShowAgain(getShowAgainBox().isSelected()); + ConfigurationManager.getConfiguration().setGptShowAgain(true); ConfigurationManager.getConfiguration().setGptPrompt(getPromptText().getText()); return true; diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 0fdae44c5..0a44968e3 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -9,15 +9,13 @@ import java.awt.Insets; import java.awt.Toolkit; import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.KeyEvent; -import java.io.BufferedReader; -import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import javax.swing.AbstractAction; import javax.swing.BorderFactory; import javax.swing.ButtonGroup; -import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JDialog; @@ -28,6 +26,9 @@ import javax.swing.JRadioButton; import javax.swing.JTextArea; import javax.swing.JTextField; + +import org.woped.core.config.ConfigurationManager; +import org.woped.core.config.IConfiguration; import org.woped.core.controller.AbstractApplicationMediator; import org.woped.gui.translations.Messages; @@ -38,7 +39,7 @@ public class P2TUI extends JDialog { private JTextField apiKeyField; private JTextArea promptField; // Changed to JTextArea for multiline private JCheckBox enablePromptCheckBox; // New Checkbox - private JCheckBox showAgainCheckBox; // New Checkbox + private JCheckBox dontshowAgainCheckBox; // New Checkbox private JRadioButton newRadioButton = null; private JRadioButton oldRadioButton = null; private static final String DEFAULT_PROMPT = "Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"; @@ -129,16 +130,17 @@ private JPanel initializeSwitchButtonPanel() { } }); - showAgainCheckBox = new JCheckBox("Don't show Again"); - showAgainCheckBox.setSelected(true); - showAgainCheckBox.setToolTipText("Placeholder"); + dontshowAgainCheckBox = new JCheckBox("Show Again"); + dontshowAgainCheckBox.setSelected(ConfigurationManager.getConfiguration().getGptShowAgain()); + dontshowAgainCheckBox.setToolTipText("Placeholder"); apiKeyLabel.setVisible(false); + apiKeyField.setText(ConfigurationManager.getConfiguration().getGptApiKey()); apiKeyField.setVisible(false); promptLabel.setVisible(false); promptScrollPane.setVisible(false); enablePromptCheckBox.setVisible(false); - showAgainCheckBox.setVisible(false); // Initially hidden + dontshowAgainCheckBox.setVisible(false); // Initially hidden newRadioButton.addActionListener(e -> { apiKeyLabel.setVisible(true); @@ -146,7 +148,7 @@ private JPanel initializeSwitchButtonPanel() { promptLabel.setVisible(true); promptScrollPane.setVisible(true); enablePromptCheckBox.setVisible(true); - showAgainCheckBox.setVisible(true); // Show when new service is selected + dontshowAgainCheckBox.setVisible(true); // Show when new service is selected apiKeyField.requestFocusInWindow(); }); @@ -156,7 +158,7 @@ private JPanel initializeSwitchButtonPanel() { promptLabel.setVisible(false); promptScrollPane.setVisible(false); enablePromptCheckBox.setVisible(false); - showAgainCheckBox.setVisible(false); // Hide when old service is selected + dontshowAgainCheckBox.setVisible(false); // Hide when old service is selected }); // Set "alt" as default selection @@ -194,7 +196,7 @@ private JPanel initializeSwitchButtonPanel() { gbc.gridy = 4; gbc.gridwidth = 2; gbc.weightx = 1.0; - fieldsPanel.add(showAgainCheckBox, gbc); // Add "Show Again" checkbox + fieldsPanel.add(dontshowAgainCheckBox, gbc); // Add "Show Again" checkbox gbc.gridx = 0; gbc.gridy = 1; @@ -210,24 +212,29 @@ private JPanel initializeSingleButtonPanel() { JPanel buttonPanel = new JPanel(new BorderLayout()); buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - JButton singleButton = new JButton(new AbstractAction() { - public void actionPerformed(ActionEvent arg0) { - if (newRadioButton.isSelected()) { - validateAPIKey(); - //GPT Aufrufen - } - else { - //GPT Aufrufen - } - - } - }); + JButton singleButton = new JButton(); singleButton.setMnemonic(KeyEvent.VK_A); singleButton.setText(Messages.getString("P2T.text")); buttonPanel.add(singleButton, BorderLayout.CENTER); + singleButton.addActionListener(e -> { + if (newRadioButton.isSelected()) { + validateAPIKey(); + ConfigurationManager.getConfiguration().setGptApiKey(apiKeyField.getText()); + ConfigurationManager.getConfiguration().setGptPrompt(promptField.getText()); + + if(!dontshowAgainCheckBox.isSelected()){ + ConfigurationManager.getConfiguration().setGptShowAgain(false); + } + //GPT Aufrufen + } + else { + //GPT Aufrufen + } + + }); return buttonPanel; } From 444322d7e795c6b099f5f98982574cfe650eaa44 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Mon, 10 Jun 2024 09:26:33 +0200 Subject: [PATCH 14/76] bixfix where prompt didnt update when changed in settings bixfix where prompt didnt update when changed in settings --- WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java | 1 + 1 file changed, 1 insertion(+) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 0a44968e3..e7c57ee98 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -114,6 +114,7 @@ private JPanel initializeSwitchButtonPanel() { promptField.setWrapStyleWord(true); promptField.setRows(5); // Set initial number of rows promptField.setEnabled(false); // Initially disabled + promptField.setText(ConfigurationManager.getConfiguration().getGptPrompt()); JScrollPane promptScrollPane = new JScrollPane(promptField); promptScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); From 24207970991479669a4a6ef41ab1e9a8a3bafee0 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Mon, 10 Jun 2024 11:26:25 +0200 Subject: [PATCH 15/76] Refactor strings of P2TUI --- .../editor/gui/config/ConfNLPToolsPanel.java | 10 ++--- .../main/java/org/woped/file/p2t/P2TUI.java | 6 +-- .../src/main/resources/Messages.properties | 13 ++++-- .../src/main/resources/Messages_de.properties | 42 ++++++++++++------- 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index 9d333a3af..945f09e93 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -373,7 +373,7 @@ private JPanel getAdditionalPanel() { c.weightx = 1; c.gridx = 0; c.gridy = 0; - additionalPanel.add(new JLabel("API-Key:"), c); + additionalPanel.add(new JLabel(Messages.getString("Configuration.GPT.apikey.Title")), c); c.weightx = 1; c.gridx = 1; @@ -383,7 +383,7 @@ private JPanel getAdditionalPanel() { c.weightx = 1; c.gridx = 0; c.gridy = 1; - additionalPanel.add(new JLabel("Prompt:"), c); + additionalPanel.add(new JLabel(Messages.getString("Configuration.GPT.prompt.Title")), c); c.weightx = 1; c.gridx = 1; @@ -441,7 +441,7 @@ private JTextArea getPromptText() { private JCheckBox getShowAgainBox() { if (showAgainBox == null) { - showAgainBox = new JCheckBox("Show Again"); + showAgainBox = new JCheckBox(Messages.getString("Configuration.GPT.show.again.Title")); showAgainBox.setEnabled(true); showAgainBox.setToolTipText("Test"); } @@ -451,7 +451,7 @@ private JCheckBox getShowAgainBox() { private WopedButton getResetButton() { if (resetButton == null) { resetButton = new WopedButton(); - resetButton.setText("Auf Standard zurücksetzen"); + resetButton.setText(Messages.getString("Configuration.GPT.standard.Title")); resetButton.setPreferredSize(new Dimension(200, 25)); resetButton.addActionListener( new ActionListener() { @@ -468,7 +468,7 @@ public void actionPerformed(ActionEvent e) { private WopedButton getCheckConnectionButton() { if (checkConnectionButton == null) { checkConnectionButton = new WopedButton(); - checkConnectionButton.setText("Verbindung überprüfen"); + checkConnectionButton.setText(Messages.getString("Configuration.GPT.connection.Title")); checkConnectionButton.setIcon(Messages.getImageIcon("Button.TestConnection")); checkConnectionButton.setMnemonic(Messages.getMnemonic("Button.TestConnection")); checkConnectionButton.setPreferredSize(new Dimension(200, 25)); diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index a9e0c570e..553a08d0e 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -111,7 +111,7 @@ private JPanel initializeSwitchButtonPanel() { apiKeyField = new JTextField(); apiKeyField.setPreferredSize(new Dimension(200, 25)); - JLabel promptLabel = new JLabel("Prompt:"); + JLabel promptLabel = new JLabel(Messages.getString("P2T.prompt.title") + ":"); promptField = new JTextArea(DEFAULT_PROMPT); // Changed to JTextArea promptField.setLineWrap(true); promptField.setWrapStyleWord(true); @@ -126,7 +126,7 @@ private JPanel initializeSwitchButtonPanel() { promptScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); promptScrollPane.setPreferredSize(new Dimension(200, 100)); - enablePromptCheckBox = new JCheckBox("Enable editing prompt"); + enablePromptCheckBox = new JCheckBox(Messages.getString("P2T.prompt.checkbox.enable.title")); enablePromptCheckBox.setSelected(false); enablePromptCheckBox.addActionListener(e -> { promptField.setEnabled(enablePromptCheckBox.isSelected()); @@ -137,7 +137,7 @@ private JPanel initializeSwitchButtonPanel() { }); - dontshowAgainCheckBox = new JCheckBox("Show Again"); + dontshowAgainCheckBox = new JCheckBox(Messages.getString("P2T.popup.show.again.title")); dontshowAgainCheckBox.setSelected(ConfigurationManager.getConfiguration().getGptShowAgain()); dontshowAgainCheckBox.setToolTipText("Placeholder"); apiKeyLabel.setVisible(false); diff --git a/WoPeD-GUI/src/main/resources/Messages.properties b/WoPeD-GUI/src/main/resources/Messages.properties index 61641ac4b..65acb5854 100644 --- a/WoPeD-GUI/src/main/resources/Messages.properties +++ b/WoPeD-GUI/src/main/resources/Messages.properties @@ -870,14 +870,16 @@ P2T.loading = Generating text... P2T.ArcError = <>Model has arc weights - no text can be generated

P2T.SoundError =

Modell is not sound - no text can be generated

P2T.SizeError =

Modell has too few nodes - no text can be generated

- P2T.Error.ArcWeights.title = Text generation failed P2T.Error.ArcWeights.message = The net contains arc weights.\nArc weights are not supported by the process 2 text feature. -P2T.oldservice.title = Old -P2T.newservice.title = New +P2T.oldservice.title = Algorithm +P2T.newservice.title = LLM P2T.apikey.title = API Key P2T.apikey.invalid = API Key is not valid P2T.apikey.invalid.title = Validation Error +P2T.prompt.title = Prompt +P2T.prompt.checkbox.enable.title = Enable editing +P2T.popup.show.again.title = Show again #************* ! Text2Process @@ -1277,6 +1279,11 @@ Configuration.P2T.Label.ServerPort = Port Configuration.P2T.Label.ServerURI = URI Configuration.P2T.Label.Use = Enable NLP Tools Configuration.P2T.Settings.Panel.Title = Process2Text server settings +Configuration.GPT.apikey.Title = API Key +Configuration.GPT.prompt.Title = Prompt +Configuration.GPT.show.again.Title = Show again +Configuration.GPT.standard.Title = Reset to standard +Configuration.GPT.connection.Title = Test connection Configuration.T2P.Settings.Panel.Title = Text2Process server settings Configuration.T2P.Dialog.Restart.Title = Restart Configuration.T2P.Label.ServerHost = Server Host diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index 47cd36bcb..1edc29258 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -467,22 +467,26 @@ DataOutput.textBandTitle = Ausgabe #************* ! Process 2 Text #************* -P2T.textBandTitle = NLP Tools -P2T.text = In Text umwandeln -P2T.openP2T.text = Process zu Text -P2T.openP2T.header = Eingabetext -P2T.tooltip = Textuelle Beschreibung erzeugen -P2T.loading = Erzeuge Text... -P2T.ArcError =

Modell hat Kantengewichte - kein Text generierbar

-P2T.SoundError =

Modell ist nicht sound - kein Text generierbar

-P2T.SizeError =

Modell hat zuwenige Knoten - kein Text generierbar

-P2T.Error.ArcWeights.title = Textgenerierung fehlgeschlagen -P2T.Error.ArcWeights.message = Das Netz verwendet Kantengewichte. \nKantengewichte werden bei der Textgenerierung nicht unterst\u00FCtzt. -P2T.oldservice.title = Alt -P2T.newservice.title = Neu -P2T.apikey.title = API Schl\u00FCssel -P2T.apikey.invalid = API Schl\u00FCssel ist nicht valide -P2T.apikey.invalid.title = Validierungsfehler +P2T.textBandTitle = NLP Tools +P2T.text = In Text umwandeln +P2T.openP2T.text = Process zu Text +P2T.openP2T.header = Eingabetext +P2T.tooltip = Textuelle Beschreibung erzeugen +P2T.loading = Erzeuge Text... +P2T.ArcError =

Modell hat Kantengewichte - kein Text generierbar

+P2T.SoundError =

Modell ist nicht sound - kein Text generierbar

+P2T.SizeError =

Modell hat zuwenige Knoten - kein Text generierbar

+P2T.Error.ArcWeights.title = Textgenerierung fehlgeschlagen +P2T.Error.ArcWeights.message = Das Netz verwendet Kantengewichte. \nKantengewichte werden bei der Textgenerierung nicht unterst\u00FCtzt. +P2T.oldservice.title = Algorithmus +P2T.newservice.title = LLM +P2T.apikey.title = API Schl\u00FCssel +P2T.apikey.invalid = API Schl\u00FCssel ist nicht valide +P2T.apikey.invalid.title = Validierungsfehler +P2T.prompt.title = Prompt +P2T.prompt.checkbox.enable.title = Bearbeitung aktivieren +P2T.popup.show.again.title = Erneut anzeigen + #************* ! Text 2 Process #************* @@ -814,6 +818,11 @@ Configuration.P2T.Label.Use = NLP Tools aktivieren Configuration.P2T.Settings.Panel.Title = Process2Text Servereinstellungen Configuration.T2P.Settings.Panel.Title = Text2Process Servereinstellungen Configuration.P2T.Title = NLP Tools +Configuration.GPT.apikey.Title = API Schl\u00FCssel +Configuration.GPT.prompt.Title = Prompt +Configuration.GPT.show.again.Title = Erneut anzeigen +Configuration.GPT.standard.Title = Auf Standard zur\u00FCcksetzen +Configuration.GPT.connection.Title = Verbindung \u00FCberpr\u00FCfen Configuration.T2P.Dialog.Restart.Title = Neustart Configuration.T2P.Label.ServerHost = Server Host Configuration.T2P.Label.ServerPort = Port @@ -836,6 +845,7 @@ Configuration.YAWL.Panel.Export.ExplicitPlaces = *.yawl Dat Configuration.YAWL.Panel.Export.ExplicitPlaces.ToolTip = Alle Stellen im Petrinetz werden zu Conditions in YAWL exportiert Configuration.YAWL.Panel.Export.Groups = *.ybkp Dateien mit Gruppen exportieren Configuration.YAWL.Panel.Export.Groups.ToolTip = Alle Gruppen im Ressourcen Editor werden zu OrgGroups in YAWL exportiert + #************* ! Exit-Config #************* From 1c01d29d65f2776de281b3e25cc192ad1fa378a1 Mon Sep 17 00:00:00 2001 From: I552396 Date: Mon, 10 Jun 2024 11:29:43 +0200 Subject: [PATCH 16/76] Make visibility of GPT settings selectable --- .../java/org/woped/editor/gui/config/ConfNLPToolsPanel.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index 9d333a3af..b698e187e 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -407,6 +407,8 @@ private JPanel getAdditionalPanel() { additionalPanel.add(getCheckConnectionButton(), c); } + + additionalPanel.setVisible(getUseBox().isSelected()); return additionalPanel; } @@ -530,6 +532,7 @@ public void itemStateChanged(ItemEvent ie) { if (jcb == useBox) { getSettingsPanel().setVisible(jcb.isSelected()); getSettingsPanel_T2P().setVisible(jcb.isSelected()); + getAdditionalPanel().setVisible(jcb.isSelected()); } } } @@ -594,7 +597,7 @@ private JCheckBox getUseBox() { if (useBox == null) { useBox = new JCheckBox(Messages.getString("Configuration.P2T.Label.Use")); useBox.setEnabled(true); - useBox.setToolTipText("" + Messages.getString("Configuration.P2T.Label.Use") + ""); + useBox.setToolTipText("" + Messages.getString("Configuration.P2T.Label.Use") + ""); CheckboxListener cbl = new CheckboxListener(); useBox.addItemListener(cbl); } From 76f23d7c37434203233459b8535f7fcf8a4a726c Mon Sep 17 00:00:00 2001 From: I552396 Date: Mon, 10 Jun 2024 11:33:31 +0200 Subject: [PATCH 17/76] Fix bug --- .../java/org/woped/editor/gui/config/ConfNLPToolsPanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index bba999059..83371a0e1 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -597,7 +597,7 @@ private JCheckBox getUseBox() { if (useBox == null) { useBox = new JCheckBox(Messages.getString("Configuration.P2T.Label.Use")); useBox.setEnabled(true); - useBox.setToolTipText("" + Messages.getString("Configuration.P2T.Label.Use") + ""); + useBox.setToolTipText("" + Messages.getString("Configuration.P2T.Label.Use") + ""); CheckboxListener cbl = new CheckboxListener(); useBox.addItemListener(cbl); } From 01d6992e5f45f9d1856735bed66036e1c7419520 Mon Sep 17 00:00:00 2001 From: TimU02 Date: Mon, 10 Jun 2024 11:29:43 +0200 Subject: [PATCH 18/76] Make visibility of GPT settings selectable --- .../java/org/woped/editor/gui/config/ConfNLPToolsPanel.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index 9d333a3af..b698e187e 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -407,6 +407,8 @@ private JPanel getAdditionalPanel() { additionalPanel.add(getCheckConnectionButton(), c); } + + additionalPanel.setVisible(getUseBox().isSelected()); return additionalPanel; } @@ -530,6 +532,7 @@ public void itemStateChanged(ItemEvent ie) { if (jcb == useBox) { getSettingsPanel().setVisible(jcb.isSelected()); getSettingsPanel_T2P().setVisible(jcb.isSelected()); + getAdditionalPanel().setVisible(jcb.isSelected()); } } } @@ -594,7 +597,7 @@ private JCheckBox getUseBox() { if (useBox == null) { useBox = new JCheckBox(Messages.getString("Configuration.P2T.Label.Use")); useBox.setEnabled(true); - useBox.setToolTipText("" + Messages.getString("Configuration.P2T.Label.Use") + ""); + useBox.setToolTipText("" + Messages.getString("Configuration.P2T.Label.Use") + ""); CheckboxListener cbl = new CheckboxListener(); useBox.addItemListener(cbl); } From 6d47e603511bca95bea38ed43d17aebf3cbe198a Mon Sep 17 00:00:00 2001 From: anneke02 Date: Mon, 10 Jun 2024 11:26:25 +0200 Subject: [PATCH 19/76] Refactor strings of P2TUI --- .../editor/gui/config/ConfNLPToolsPanel.java | 10 ++--- .../main/java/org/woped/file/p2t/P2TUI.java | 6 +-- .../src/main/resources/Messages.properties | 13 ++++-- .../src/main/resources/Messages_de.properties | 42 ++++++++++++------- 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index b698e187e..bba999059 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -373,7 +373,7 @@ private JPanel getAdditionalPanel() { c.weightx = 1; c.gridx = 0; c.gridy = 0; - additionalPanel.add(new JLabel("API-Key:"), c); + additionalPanel.add(new JLabel(Messages.getString("Configuration.GPT.apikey.Title")), c); c.weightx = 1; c.gridx = 1; @@ -383,7 +383,7 @@ private JPanel getAdditionalPanel() { c.weightx = 1; c.gridx = 0; c.gridy = 1; - additionalPanel.add(new JLabel("Prompt:"), c); + additionalPanel.add(new JLabel(Messages.getString("Configuration.GPT.prompt.Title")), c); c.weightx = 1; c.gridx = 1; @@ -443,7 +443,7 @@ private JTextArea getPromptText() { private JCheckBox getShowAgainBox() { if (showAgainBox == null) { - showAgainBox = new JCheckBox("Show Again"); + showAgainBox = new JCheckBox(Messages.getString("Configuration.GPT.show.again.Title")); showAgainBox.setEnabled(true); showAgainBox.setToolTipText("Test"); } @@ -453,7 +453,7 @@ private JCheckBox getShowAgainBox() { private WopedButton getResetButton() { if (resetButton == null) { resetButton = new WopedButton(); - resetButton.setText("Auf Standard zurücksetzen"); + resetButton.setText(Messages.getString("Configuration.GPT.standard.Title")); resetButton.setPreferredSize(new Dimension(200, 25)); resetButton.addActionListener( new ActionListener() { @@ -470,7 +470,7 @@ public void actionPerformed(ActionEvent e) { private WopedButton getCheckConnectionButton() { if (checkConnectionButton == null) { checkConnectionButton = new WopedButton(); - checkConnectionButton.setText("Verbindung überprüfen"); + checkConnectionButton.setText(Messages.getString("Configuration.GPT.connection.Title")); checkConnectionButton.setIcon(Messages.getImageIcon("Button.TestConnection")); checkConnectionButton.setMnemonic(Messages.getMnemonic("Button.TestConnection")); checkConnectionButton.setPreferredSize(new Dimension(200, 25)); diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index a9e0c570e..553a08d0e 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -111,7 +111,7 @@ private JPanel initializeSwitchButtonPanel() { apiKeyField = new JTextField(); apiKeyField.setPreferredSize(new Dimension(200, 25)); - JLabel promptLabel = new JLabel("Prompt:"); + JLabel promptLabel = new JLabel(Messages.getString("P2T.prompt.title") + ":"); promptField = new JTextArea(DEFAULT_PROMPT); // Changed to JTextArea promptField.setLineWrap(true); promptField.setWrapStyleWord(true); @@ -126,7 +126,7 @@ private JPanel initializeSwitchButtonPanel() { promptScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); promptScrollPane.setPreferredSize(new Dimension(200, 100)); - enablePromptCheckBox = new JCheckBox("Enable editing prompt"); + enablePromptCheckBox = new JCheckBox(Messages.getString("P2T.prompt.checkbox.enable.title")); enablePromptCheckBox.setSelected(false); enablePromptCheckBox.addActionListener(e -> { promptField.setEnabled(enablePromptCheckBox.isSelected()); @@ -137,7 +137,7 @@ private JPanel initializeSwitchButtonPanel() { }); - dontshowAgainCheckBox = new JCheckBox("Show Again"); + dontshowAgainCheckBox = new JCheckBox(Messages.getString("P2T.popup.show.again.title")); dontshowAgainCheckBox.setSelected(ConfigurationManager.getConfiguration().getGptShowAgain()); dontshowAgainCheckBox.setToolTipText("Placeholder"); apiKeyLabel.setVisible(false); diff --git a/WoPeD-GUI/src/main/resources/Messages.properties b/WoPeD-GUI/src/main/resources/Messages.properties index 61641ac4b..65acb5854 100644 --- a/WoPeD-GUI/src/main/resources/Messages.properties +++ b/WoPeD-GUI/src/main/resources/Messages.properties @@ -870,14 +870,16 @@ P2T.loading = Generating text... P2T.ArcError = <>Model has arc weights - no text can be generated

P2T.SoundError =

Modell is not sound - no text can be generated

P2T.SizeError =

Modell has too few nodes - no text can be generated

- P2T.Error.ArcWeights.title = Text generation failed P2T.Error.ArcWeights.message = The net contains arc weights.\nArc weights are not supported by the process 2 text feature. -P2T.oldservice.title = Old -P2T.newservice.title = New +P2T.oldservice.title = Algorithm +P2T.newservice.title = LLM P2T.apikey.title = API Key P2T.apikey.invalid = API Key is not valid P2T.apikey.invalid.title = Validation Error +P2T.prompt.title = Prompt +P2T.prompt.checkbox.enable.title = Enable editing +P2T.popup.show.again.title = Show again #************* ! Text2Process @@ -1277,6 +1279,11 @@ Configuration.P2T.Label.ServerPort = Port Configuration.P2T.Label.ServerURI = URI Configuration.P2T.Label.Use = Enable NLP Tools Configuration.P2T.Settings.Panel.Title = Process2Text server settings +Configuration.GPT.apikey.Title = API Key +Configuration.GPT.prompt.Title = Prompt +Configuration.GPT.show.again.Title = Show again +Configuration.GPT.standard.Title = Reset to standard +Configuration.GPT.connection.Title = Test connection Configuration.T2P.Settings.Panel.Title = Text2Process server settings Configuration.T2P.Dialog.Restart.Title = Restart Configuration.T2P.Label.ServerHost = Server Host diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index 47cd36bcb..1edc29258 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -467,22 +467,26 @@ DataOutput.textBandTitle = Ausgabe #************* ! Process 2 Text #************* -P2T.textBandTitle = NLP Tools -P2T.text = In Text umwandeln -P2T.openP2T.text = Process zu Text -P2T.openP2T.header = Eingabetext -P2T.tooltip = Textuelle Beschreibung erzeugen -P2T.loading = Erzeuge Text... -P2T.ArcError =

Modell hat Kantengewichte - kein Text generierbar

-P2T.SoundError =

Modell ist nicht sound - kein Text generierbar

-P2T.SizeError =

Modell hat zuwenige Knoten - kein Text generierbar

-P2T.Error.ArcWeights.title = Textgenerierung fehlgeschlagen -P2T.Error.ArcWeights.message = Das Netz verwendet Kantengewichte. \nKantengewichte werden bei der Textgenerierung nicht unterst\u00FCtzt. -P2T.oldservice.title = Alt -P2T.newservice.title = Neu -P2T.apikey.title = API Schl\u00FCssel -P2T.apikey.invalid = API Schl\u00FCssel ist nicht valide -P2T.apikey.invalid.title = Validierungsfehler +P2T.textBandTitle = NLP Tools +P2T.text = In Text umwandeln +P2T.openP2T.text = Process zu Text +P2T.openP2T.header = Eingabetext +P2T.tooltip = Textuelle Beschreibung erzeugen +P2T.loading = Erzeuge Text... +P2T.ArcError =

Modell hat Kantengewichte - kein Text generierbar

+P2T.SoundError =

Modell ist nicht sound - kein Text generierbar

+P2T.SizeError =

Modell hat zuwenige Knoten - kein Text generierbar

+P2T.Error.ArcWeights.title = Textgenerierung fehlgeschlagen +P2T.Error.ArcWeights.message = Das Netz verwendet Kantengewichte. \nKantengewichte werden bei der Textgenerierung nicht unterst\u00FCtzt. +P2T.oldservice.title = Algorithmus +P2T.newservice.title = LLM +P2T.apikey.title = API Schl\u00FCssel +P2T.apikey.invalid = API Schl\u00FCssel ist nicht valide +P2T.apikey.invalid.title = Validierungsfehler +P2T.prompt.title = Prompt +P2T.prompt.checkbox.enable.title = Bearbeitung aktivieren +P2T.popup.show.again.title = Erneut anzeigen + #************* ! Text 2 Process #************* @@ -814,6 +818,11 @@ Configuration.P2T.Label.Use = NLP Tools aktivieren Configuration.P2T.Settings.Panel.Title = Process2Text Servereinstellungen Configuration.T2P.Settings.Panel.Title = Text2Process Servereinstellungen Configuration.P2T.Title = NLP Tools +Configuration.GPT.apikey.Title = API Schl\u00FCssel +Configuration.GPT.prompt.Title = Prompt +Configuration.GPT.show.again.Title = Erneut anzeigen +Configuration.GPT.standard.Title = Auf Standard zur\u00FCcksetzen +Configuration.GPT.connection.Title = Verbindung \u00FCberpr\u00FCfen Configuration.T2P.Dialog.Restart.Title = Neustart Configuration.T2P.Label.ServerHost = Server Host Configuration.T2P.Label.ServerPort = Port @@ -836,6 +845,7 @@ Configuration.YAWL.Panel.Export.ExplicitPlaces = *.yawl Dat Configuration.YAWL.Panel.Export.ExplicitPlaces.ToolTip = Alle Stellen im Petrinetz werden zu Conditions in YAWL exportiert Configuration.YAWL.Panel.Export.Groups = *.ybkp Dateien mit Gruppen exportieren Configuration.YAWL.Panel.Export.Groups.ToolTip = Alle Gruppen im Ressourcen Editor werden zu OrgGroups in YAWL exportiert + #************* ! Exit-Config #************* From 73477423ab6c182ffdf1d0fe4308cb489df4a5f4 Mon Sep 17 00:00:00 2001 From: TimU02 Date: Mon, 10 Jun 2024 11:33:31 +0200 Subject: [PATCH 20/76] Fix bug --- .../java/org/woped/editor/gui/config/ConfNLPToolsPanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index bba999059..83371a0e1 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -597,7 +597,7 @@ private JCheckBox getUseBox() { if (useBox == null) { useBox = new JCheckBox(Messages.getString("Configuration.P2T.Label.Use")); useBox.setEnabled(true); - useBox.setToolTipText("" + Messages.getString("Configuration.P2T.Label.Use") + ""); + useBox.setToolTipText("" + Messages.getString("Configuration.P2T.Label.Use") + ""); CheckboxListener cbl = new CheckboxListener(); useBox.addItemListener(cbl); } From ac66f0f6158d4f377698e8e86ec94d22d739d9b3 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Mon, 10 Jun 2024 14:10:23 +0200 Subject: [PATCH 21/76] Fix string of messages file --- WoPeD-GUI/src/main/resources/Messages_de.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index 1edc29258..36ddd1c14 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -822,7 +822,7 @@ Configuration.GPT.apikey.Title = API Schl\u Configuration.GPT.prompt.Title = Prompt Configuration.GPT.show.again.Title = Erneut anzeigen Configuration.GPT.standard.Title = Auf Standard zur\u00FCcksetzen -Configuration.GPT.connection.Title = Verbindung \u00FCberpr\u00FCfen +Configuration.GPT.connection.Title = Verbindung pr\u00FCfen Configuration.T2P.Dialog.Restart.Title = Neustart Configuration.T2P.Label.ServerHost = Server Host Configuration.T2P.Label.ServerPort = Port From ae78aeefb14be838e93253d584aebc22b0f231bb Mon Sep 17 00:00:00 2001 From: TimU02 Date: Mon, 10 Jun 2024 14:41:44 +0200 Subject: [PATCH 22/76] Enable old Service call from popup --- .../org/woped/editor/controller/ActionFactory.java | 13 +++++++++++++ .../src/main/java/org/woped/file/p2t/P2TUI.java | 8 +++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/controller/ActionFactory.java b/WoPeD-Editor/src/main/java/org/woped/editor/controller/ActionFactory.java index 067dd0490..8574a1008 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/controller/ActionFactory.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/controller/ActionFactory.java @@ -62,6 +62,8 @@ public class ActionFactory { public static final String ACTIONID_UPDATENETS = "Action.UpdateNets"; public static final String ACTIONID_P2T = "ToolBar.P2T"; + + public static final String ACTIONID_P2T_OLD = "Ausführen"; public static final String ACTIONID_T2P = "ToolBar.T2P"; public static final String ACTIONID_DRAWMODE_PLACE = "ToolBar.DrawPlace"; @@ -651,6 +653,17 @@ public static HashMap createStaticActions(ApplicationMediat VisualController.WITH_EDITOR, VisualController.P2T); + STATIC_ACTION_MAP.put( + ACTIONID_P2T_OLD, + new WoPeDAction( + am, AbstractViewEvent.VIEWEVENTTYPE_EDIT, AbstractViewEvent.P2T, null, ACTIONID_P2T_OLD)); + VisualController.getInstance() + .addElement( + STATIC_ACTION_MAP.get(ACTIONID_P2T_OLD), + VisualController.WITH_EDITOR, + VisualController.WITH_EDITOR, + VisualController.P2T); + STATIC_ACTION_MAP.put( ACTIONID_T2P, new WoPeDAction( diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 553a08d0e..41dea06ab 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -30,6 +30,9 @@ import org.woped.core.config.ConfigurationManager; import org.woped.core.config.IConfiguration; import org.woped.core.controller.AbstractApplicationMediator; +import org.woped.core.controller.AbstractViewEvent; +import org.woped.editor.action.ActionButtonListener; +import org.woped.editor.controller.ActionFactory; import org.woped.gui.translations.Messages; public class P2TUI extends JDialog { @@ -43,6 +46,7 @@ public class P2TUI extends JDialog { private JCheckBox dontshowAgainCheckBox; // New Checkbox private JRadioButton newRadioButton = null; private JRadioButton oldRadioButton = null; + private AbstractApplicationMediator m_mediator = null; private static final String DEFAULT_PROMPT = "Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"; @@ -249,7 +253,9 @@ private JPanel initializeSingleButtonPanel() { //GPT Aufrufen } else { - //GPT Aufrufen + singleButton.addActionListener( + new ActionButtonListener( + m_mediator, ActionFactory.ACTIONID_P2T_OLD, AbstractViewEvent.P2T, singleButton)); } }); From dbf61f2d5bc286c2663d466ea319ab20b0052ec0 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Mon, 10 Jun 2024 17:24:37 +0200 Subject: [PATCH 23/76] added new config, so that the client remebers which version the enduser used --- .../woped/beanconfiguration/configuration.xsd | 1 + .../general/WoPeDGeneralConfiguration.java | 13 ++++++++++++ .../org/woped/config/general/WoPeDconfig.xml | 1 + .../config/DefaultStaticConfiguration.java | 12 +++++++++++ .../core/config/IGeneralConfiguration.java | 4 ++++ .../main/java/org/woped/file/p2t/P2TUI.java | 21 ++++++++++++------- .../controller/vep/GUIViewEventProcessor.java | 10 +++++++++ 7 files changed, 54 insertions(+), 8 deletions(-) diff --git a/WoPeD-BeanConfiguration/src/main/java/org/woped/beanconfiguration/configuration.xsd b/WoPeD-BeanConfiguration/src/main/java/org/woped/beanconfiguration/configuration.xsd index e03fccdf6..8aa46cfb4 100644 --- a/WoPeD-BeanConfiguration/src/main/java/org/woped/beanconfiguration/configuration.xsd +++ b/WoPeD-BeanConfiguration/src/main/java/org/woped/beanconfiguration/configuration.xsd @@ -143,6 +143,7 @@ + diff --git a/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDGeneralConfiguration.java b/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDGeneralConfiguration.java index 8fee47e12..e5b8be8ad 100644 --- a/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDGeneralConfiguration.java +++ b/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDGeneralConfiguration.java @@ -1514,6 +1514,19 @@ public void setGptPrompt(String prompt) { getConfDocument().getConfiguration().getGpt().setGptPrompt(prompt); } + @Override + public void setGptUseNew(boolean useNew){ + getConfDocument().getConfiguration().getGpt().setGptUseNew(useNew); + } + + @Override + public boolean getGptUseNew(){ + if(getConfDocument().getConfiguration().getGpt().getGptUseNew()){ + return getConfDocument().getConfiguration().getGpt().getGptUseNew(); + } else return ConfigurationManager.getStandardConfiguration().getGptUseNew(); + } + + @Override public void setText2ProcessServerURI(String uri) { getConfDocument().getConfiguration().getT2P().setT2PServerURI(uri); diff --git a/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDconfig.xml b/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDconfig.xml index bfba43e06..6f6b836ba 100644 --- a/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDconfig.xml +++ b/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDconfig.xml @@ -119,6 +119,7 @@ test test + true diff --git a/WoPeD-Core/src/main/java/org/woped/core/config/DefaultStaticConfiguration.java b/WoPeD-Core/src/main/java/org/woped/core/config/DefaultStaticConfiguration.java index 157fd6155..04fad1581 100644 --- a/WoPeD-Core/src/main/java/org/woped/core/config/DefaultStaticConfiguration.java +++ b/WoPeD-Core/src/main/java/org/woped/core/config/DefaultStaticConfiguration.java @@ -194,6 +194,18 @@ public class DefaultStaticConfiguration implements IGeneralConfiguration { private String gptApiKey = ""; private boolean gptShowAgain = true; private String gptPrompt = "Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"; + private boolean gptUseNew = false; + + public boolean isGptUseNew() { + return gptUseNew; + } + + public void setGptUseNew(boolean gptUseNew) { + this.gptUseNew = gptUseNew; + } + public boolean getGptUseNew(){ + return gptUseNew; + } public DefaultStaticConfiguration() { initConfig(); diff --git a/WoPeD-Core/src/main/java/org/woped/core/config/IGeneralConfiguration.java b/WoPeD-Core/src/main/java/org/woped/core/config/IGeneralConfiguration.java index 33dba995c..0b6e2e387 100644 --- a/WoPeD-Core/src/main/java/org/woped/core/config/IGeneralConfiguration.java +++ b/WoPeD-Core/src/main/java/org/woped/core/config/IGeneralConfiguration.java @@ -573,4 +573,8 @@ public void changeApromoreServerSettings( public String getGptPrompt(); public void setGptPrompt(String prompt); + + public void setGptUseNew(boolean useNew); + + public boolean getGptUseNew(); } diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 41dea06ab..b96f8650c 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -31,6 +31,7 @@ import org.woped.core.config.IConfiguration; import org.woped.core.controller.AbstractApplicationMediator; import org.woped.core.controller.AbstractViewEvent; +import org.woped.core.controller.ViewEvent; import org.woped.editor.action.ActionButtonListener; import org.woped.editor.controller.ActionFactory; import org.woped.gui.translations.Messages; @@ -173,7 +174,7 @@ private JPanel initializeSwitchButtonPanel() { promptScrollPane.setVisible(false); enablePromptCheckBox.setVisible(false); - dontshowAgainCheckBox.setVisible(false); // Hide when old service is selected + dontshowAgainCheckBox.setVisible(true); // Hide when old service is selected }); @@ -237,7 +238,9 @@ private JPanel initializeSingleButtonPanel() { singleButton.setText(Messages.getString("P2T.text")); buttonPanel.add(singleButton, BorderLayout.CENTER); - + singleButton.addActionListener( + new ActionButtonListener( + m_mediator, ActionFactory.ACTIONID_P2T_OLD, AbstractViewEvent.P2T, singleButton)); singleButton.addActionListener(e -> { if (newRadioButton.isSelected()) { validateAPIKey(); @@ -247,15 +250,17 @@ private JPanel initializeSingleButtonPanel() { ConfigurationManager.getConfiguration().setGptPrompt(promptField.getText()); - if(!dontshowAgainCheckBox.isSelected()){ + if (!dontshowAgainCheckBox.isSelected()) { ConfigurationManager.getConfiguration().setGptShowAgain(false); + ConfigurationManager.getConfiguration().setGptUseNew(true); } //GPT Aufrufen - } - else { - singleButton.addActionListener( - new ActionButtonListener( - m_mediator, ActionFactory.ACTIONID_P2T_OLD, AbstractViewEvent.P2T, singleButton)); + } else { + if (!dontshowAgainCheckBox.isSelected()) { + ConfigurationManager.getConfiguration().setGptShowAgain(false); + ConfigurationManager.getConfiguration().setGptUseNew(false); + } + } }); diff --git a/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java b/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java index 338d9bbf3..95b219786 100644 --- a/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java +++ b/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java @@ -95,6 +95,16 @@ && getMediator().getUi().getComponent() instanceof JFrame) { if(ConfigurationManager.getConfiguration().getGptShowAgain()){ p2t.setVisible(true); } + if(!ConfigurationManager.getConfiguration().getGptShowAgain()){ + if(ConfigurationManager.getConfiguration().getGptUseNew()){ + System.out.println("neu"); + //TODO: HIER NEUER API CALL + } + if(!ConfigurationManager.getConfiguration().getGptUseNew()){ + System.out.println("alt"); + //TODO: HIER ALTER API CALL + } + } break; case AbstractViewEvent.NEW: getMediator().createEditor(true); From 1e23f67d6f08b749cbb713a9be4dda7dbc9b87c1 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Tue, 11 Jun 2024 01:26:52 +0200 Subject: [PATCH 24/76] preparations for implementation of logic in transform buttons --- .../editor/controller/ActionFactory.java | 13 ++ .../main/java/org/woped/file/p2t/P2TUI.java | 7 +- .../woped/qualanalysis/p2t/P2TSideBar.java | 6 +- .../qualanalysis/p2t/WebServiceThread.java | 125 ++++++++-------- .../qualanalysis/p2t/WebServiceThreadLLM.java | 135 ++++++++++++++++++ 5 files changed, 218 insertions(+), 68 deletions(-) create mode 100644 WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/controller/ActionFactory.java b/WoPeD-Editor/src/main/java/org/woped/editor/controller/ActionFactory.java index 8574a1008..7e1dfd7d2 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/controller/ActionFactory.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/controller/ActionFactory.java @@ -63,6 +63,7 @@ public class ActionFactory { public static final String ACTIONID_P2T = "ToolBar.P2T"; + public static final String ACTIONID_P2t_NEW = "Ausführen.Neu"; public static final String ACTIONID_P2T_OLD = "Ausführen"; public static final String ACTIONID_T2P = "ToolBar.T2P"; @@ -664,6 +665,18 @@ public static HashMap createStaticActions(ApplicationMediat VisualController.WITH_EDITOR, VisualController.P2T); + STATIC_ACTION_MAP.put( + ACTIONID_P2t_NEW, + new WoPeDAction( + am, AbstractViewEvent.VIEWEVENTTYPE_EDIT, AbstractViewEvent.P2T, null, ACTIONID_P2t_NEW)); + VisualController.getInstance() + .addElement( + STATIC_ACTION_MAP.get(ACTIONID_P2t_NEW), + VisualController.WITH_EDITOR, + VisualController.WITH_EDITOR, + VisualController.P2T); + + STATIC_ACTION_MAP.put( ACTIONID_T2P, new WoPeDAction( diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index b96f8650c..40dc29a1a 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -35,6 +35,8 @@ import org.woped.editor.action.ActionButtonListener; import org.woped.editor.controller.ActionFactory; import org.woped.gui.translations.Messages; +import org.woped.qualanalysis.p2t.P2TSideBar; +import org.woped.qualanalysis.p2t.WebServiceThreadLLM; public class P2TUI extends JDialog { private JDialog loadDialog; @@ -238,9 +240,10 @@ private JPanel initializeSingleButtonPanel() { singleButton.setText(Messages.getString("P2T.text")); buttonPanel.add(singleButton, BorderLayout.CENTER); + singleButton.addActionListener( new ActionButtonListener( - m_mediator, ActionFactory.ACTIONID_P2T_OLD, AbstractViewEvent.P2T, singleButton)); + m_mediator, ActionFactory.ACTIONID_P2t_NEW, AbstractViewEvent.P2T, singleButton)); singleButton.addActionListener(e -> { if (newRadioButton.isSelected()) { validateAPIKey(); @@ -254,7 +257,7 @@ private JPanel initializeSingleButtonPanel() { ConfigurationManager.getConfiguration().setGptShowAgain(false); ConfigurationManager.getConfiguration().setGptUseNew(true); } - //GPT Aufrufen + } else { if (!dontshowAgainCheckBox.isSelected()) { ConfigurationManager.getConfiguration().setGptShowAgain(false); diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java index fc606da44..a7f9261e6 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java @@ -35,7 +35,7 @@ public class P2TSideBar extends JPanel implements ActionListener { private JButton buttonLoad = null; private JButton buttonExport = null; private JLabel labelLoading = null; - private WebServiceThread webService = null; + private WebServiceThreadLLM webService = null; private boolean threadInProgress = false; private boolean firstTimeDisplayed = false; @@ -320,7 +320,7 @@ public String getDescription() { private void getText() { clean(); - // Ensure their are no arc weights + // Ensure there are no arc weights if (editor.getModelProcessor().usesArcWeights()) { this.textpane.setText(Messages.getString("P2T.Error.ArcWeights.title")); showErrorMessage("P2T.Error.ArcWeights"); @@ -350,7 +350,7 @@ private void getText() { this.textpane.setText(Messages.getString("P2T.loading")); this.showLoadingAnimation(true); - webService = new WebServiceThread(this); + webService = new WebServiceThreadLLM(this); webService.start(); while (!webService.getIsFinished()) { try { diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java index b18fd55a2..877a04b3a 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java @@ -3,79 +3,78 @@ import java.io.ByteArrayOutputStream; import javax.servlet.http.HttpServletResponse; import javax.swing.*; + import org.woped.core.config.ConfigurationManager; import org.woped.core.controller.IEditor; import org.woped.gui.translations.Messages; public class WebServiceThread extends Thread { - private P2TSideBar paraphrasingPanel; - private String[][] result = null; - private boolean isFinished; - private HttpRequest request; - private HttpResponse response; - - public WebServiceThread(P2TSideBar paraphrasingPanel) { - this.paraphrasingPanel = paraphrasingPanel; - isFinished = false; - } + private P2TSideBar paraphrasingPanel; + private String[][] result = null; + private boolean isFinished; + private HttpRequest request; + private HttpResponse response; - public boolean getIsFinished() { - return isFinished; - } - public void run() { - IEditor editor = paraphrasingPanel.getEditor(); - paraphrasingPanel.showLoadingAnimation(true); - String url = - "http://" - + ConfigurationManager.getConfiguration().getProcess2TextServerHost() - + ":" - + ConfigurationManager.getConfiguration().getProcess2TextServerPort() - + ConfigurationManager.getConfiguration().getProcess2TextServerURI() - + "/generateText"; - - String[] arg = {url, "P2T"}; - try { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - new PNMLExport().saveToStream(editor, stream); - String text = stream.toString(); - String output; - request = new HttpRequest(url, text); - response = request.getResponse(); - output = response.getBody(); - output = output.replaceAll("\\s*\n\\s*", ""); - isFinished = true; - paraphrasingPanel.setNaturalTextParser(new Process2Text(output)); - } finally { + public WebServiceThread(P2TSideBar paraphrasingPanel) { + this.paraphrasingPanel = paraphrasingPanel; + isFinished = false; } - ; - switch (response.responseCode) { - case HttpServletResponse.SC_NO_CONTENT: - case HttpServletResponse.SC_REQUEST_TIMEOUT: - case HttpServletResponse.SC_INTERNAL_SERVER_ERROR: - JOptionPane.showMessageDialog( - null, - Messages.getString("Paraphrasing.Webservice.Error.TryAgain", arg), - Messages.getString("Paraphrasing.Webservice.Error.Title"), - JOptionPane.INFORMATION_MESSAGE); - break; - case HttpServletResponse.SC_SERVICE_UNAVAILABLE: - case HttpServletResponse.SC_NOT_FOUND: - case HttpServletResponse.SC_METHOD_NOT_ALLOWED: - case -1: - JOptionPane.showMessageDialog( - null, - Messages.getString("Paraphrasing.Webservice.Error.Contact", arg) - + "\n" - + Messages.getString("Paraphrasing.Webservice.Settings"), - Messages.getString("Paraphrasing.Webservice.Error.Title"), - JOptionPane.INFORMATION_MESSAGE); + public boolean getIsFinished() { + return isFinished; } - paraphrasingPanel.showLoadingAnimation(false); - paraphrasingPanel.enableButtons(true); - paraphrasingPanel.setThreadInProgress(false); - } + public void run() { + IEditor editor = paraphrasingPanel.getEditor(); + paraphrasingPanel.showLoadingAnimation(true); + String url = + "http://" + + ConfigurationManager.getConfiguration().getProcess2TextServerHost() + + ":" + + ConfigurationManager.getConfiguration().getProcess2TextServerPort() + + ConfigurationManager.getConfiguration().getProcess2TextServerURI() + + "/generateText"; + + String[] arg = {url, "P2T"}; + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + new PNMLExport().saveToStream(editor, stream); + String text = stream.toString(); + String output; + request = new HttpRequest(url, text); + response = request.getResponse(); + output = response.getBody(); + output = output.replaceAll("\\s*\n\\s*", ""); + isFinished = true; + paraphrasingPanel.setNaturalTextParser(new Process2Text(output)); + + + switch (response.responseCode) { + case HttpServletResponse.SC_NO_CONTENT: + case HttpServletResponse.SC_REQUEST_TIMEOUT: + case HttpServletResponse.SC_INTERNAL_SERVER_ERROR: + JOptionPane.showMessageDialog( + null, + Messages.getString("Paraphrasing.Webservice.Error.TryAgain", arg), + Messages.getString("Paraphrasing.Webservice.Error.Title"), + JOptionPane.INFORMATION_MESSAGE); + break; + case HttpServletResponse.SC_SERVICE_UNAVAILABLE: + case HttpServletResponse.SC_NOT_FOUND: + case HttpServletResponse.SC_METHOD_NOT_ALLOWED: + case -1: + JOptionPane.showMessageDialog( + null, + Messages.getString("Paraphrasing.Webservice.Error.Contact", arg) + + "\n" + + Messages.getString("Paraphrasing.Webservice.Settings"), + Messages.getString("Paraphrasing.Webservice.Error.Title"), + JOptionPane.INFORMATION_MESSAGE); + } + + paraphrasingPanel.showLoadingAnimation(false); + paraphrasingPanel.enableButtons(true); + paraphrasingPanel.setThreadInProgress(false); + } } diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java new file mode 100644 index 000000000..e3365c4d0 --- /dev/null +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java @@ -0,0 +1,135 @@ +package org.woped.qualanalysis.p2t; + +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.Scanner; +import javax.servlet.http.HttpServletResponse; +import javax.swing.JOptionPane; +import org.woped.core.config.ConfigurationManager; +import org.woped.core.controller.IEditor; +import org.woped.gui.translations.Messages; + +public class WebServiceThreadLLM extends Thread { + + private P2TSideBar paraphrasingPanel; + private String[][] result = null; + private boolean isFinished; + private String apiKey; + private String prompt; + private String gptModel; + + public WebServiceThreadLLM(P2TSideBar paraphrasingPanel) { + this.paraphrasingPanel = paraphrasingPanel; + isFinished = false; + } + + public boolean getIsFinished() { + return isFinished; + } + + public void run() { + apiKey = ConfigurationManager.getConfiguration().getGptApiKey(); + prompt = ConfigurationManager.getConfiguration().getGptPrompt(); + gptModel = "gpt-4-turbo"; + + IEditor editor = paraphrasingPanel.getEditor(); + paraphrasingPanel.showLoadingAnimation(true); + + String testUrl = "http://localhost:8080/p2t/generateTextLLM"; + String url = + "http://" + + ConfigurationManager.getConfiguration().getProcess2TextServerHost() + + ":" + + ConfigurationManager.getConfiguration().getProcess2TextServerPort() + + ConfigurationManager.getConfiguration().getProcess2TextServerURI() + + "/generateTextLLM"; + + String fullTestUrl = testUrl + "?apiKey=" + apiKey + "&prompt=" + prompt + "&gptModel=" + gptModel; + String fullUrl = url + "?apiKey=" + apiKey + "&prompt=" + prompt + "&gptModel=" + gptModel; + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + new PNMLExport().saveToStream(editor, stream); + String text = stream.toString(); + System.out.println(text); + String output; + + try { + // URL-Parameter kodieren + String encodedApiKey = URLEncoder.encode(apiKey, StandardCharsets.UTF_8.toString()); + String encodedPrompt = URLEncoder.encode(prompt, StandardCharsets.UTF_8.toString()); + String encodedGptModel = URLEncoder.encode(gptModel, StandardCharsets.UTF_8.toString()); + + // URL mit Parametern aufbauen + String urlWithParams = String.format("%s?apiKey=%s&prompt=%s&gptModel=%s", + testUrl, encodedApiKey, encodedPrompt, encodedGptModel); + URL urlObj = new URL(urlWithParams); + + // Verbindung aufbauen + HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection(); + conn.setDoOutput(true); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "text/plain"); + + // Request-Body senden + try (OutputStream os = conn.getOutputStream()) { + byte[] input = text.getBytes(StandardCharsets.UTF_8); + os.write(input, 0, input.length); + } + + // Antwort lesen + int responseCode = conn.getResponseCode(); + if (responseCode == HttpURLConnection.HTTP_OK) { + try (Scanner scanner = new Scanner(conn.getInputStream(), StandardCharsets.UTF_8.name())) { + output = scanner.useDelimiter("\\A").next(); + output = output.replaceAll("\\s*\n\\s*", ""); + paraphrasingPanel.setNaturalTextParser(new Process2Text(output)); + System.out.println(output); + } + } else { + output = "Request failed. Response Code: " + responseCode; + System.out.println(output); + } + + // Fehlerbehandlung basierend auf Response Code + switch (responseCode) { + case HttpServletResponse.SC_NO_CONTENT: + case HttpServletResponse.SC_REQUEST_TIMEOUT: + case HttpServletResponse.SC_INTERNAL_SERVER_ERROR: + JOptionPane.showMessageDialog( + null, + Messages.getString("Paraphrasing.Webservice.Error.TryAgain"), + Messages.getString("Paraphrasing.Webservice.Error.Title"), + JOptionPane.INFORMATION_MESSAGE); + break; + case HttpServletResponse.SC_SERVICE_UNAVAILABLE: + case HttpServletResponse.SC_NOT_FOUND: + case HttpServletResponse.SC_METHOD_NOT_ALLOWED: + case -1: + JOptionPane.showMessageDialog( + null, + Messages.getString("Paraphrasing.Webservice.Error.Contact") + + "\n" + + Messages.getString("Paraphrasing.Webservice.Settings"), + Messages.getString("Paraphrasing.Webservice.Error.Title"), + JOptionPane.INFORMATION_MESSAGE); + break; + } + } catch (Exception e) { + e.printStackTrace(); + JOptionPane.showMessageDialog( + null, + "Error processing request: " + e.getMessage(), + "Error", + JOptionPane.ERROR_MESSAGE); + } finally { + isFinished = true; + paraphrasingPanel.showLoadingAnimation(false); + paraphrasingPanel.enableButtons(true); + paraphrasingPanel.setThreadInProgress(false); + } + } +} From 52cccde62d726b195fe43c910060e131b1f15899 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Wed, 12 Jun 2024 15:48:47 +0200 Subject: [PATCH 25/76] Added Option to choose GPT Model in Settings Added Option to choose GPT Model in Settings --- WoPeD-Editor/pom.xml | 5 + .../editor/gui/config/ConfNLPToolsPanel.java | 439 ++++++++---------- .../org/woped/editor/tools/ApiHelper.java | 47 ++ .../main/java/org/woped/file/p2t/P2TUI.java | 26 +- .../qualanalysis/p2t/WebServiceThreadLLM.java | 5 +- 5 files changed, 260 insertions(+), 262 deletions(-) create mode 100644 WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java diff --git a/WoPeD-Editor/pom.xml b/WoPeD-Editor/pom.xml index 9f6d682ee..bc244741e 100644 --- a/WoPeD-Editor/pom.xml +++ b/WoPeD-Editor/pom.xml @@ -26,6 +26,11 @@ jcalendar 1.3.2
+ + com.googlecode.json-simple + json-simple + 1.1.1 + de.dhbw.woped WoPeD-CommonLibs diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index 83371a0e1..f869641ac 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -1,25 +1,3 @@ -/* - * - * Copyright (C) 2004-2005, see @author in JavaDoc for the author - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * - * For contact information please visit http://woped.dhbw-karlsruhe.de - * - */ package org.woped.editor.gui.config; import java.awt.Dimension; @@ -35,23 +13,15 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; -import javax.swing.BorderFactory; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; +import java.util.List; +import javax.swing.*; +import org.json.simple.parser.ParseException; import org.woped.core.config.ConfigurationManager; +import org.woped.editor.tools.ApiHelper; import org.woped.gui.lookAndFeel.WopedButton; import org.woped.gui.translations.Messages; -/** - * The ConfLanguagePanel is the AbstractConfPanel for the configuration - * of the language. Created on: 26.11.2004 Last Change on: 14.11.2005 - */ @SuppressWarnings("serial") public class ConfNLPToolsPanel extends AbstractConfPanel { private JCheckBox useBox = null; @@ -84,17 +54,15 @@ public class ConfNLPToolsPanel extends AbstractConfPanel { private JTextArea promptText = null; private WopedButton checkConnectionButton = null; - /** - * Constructor for ConfToolsPanel. - */ + // New components + private JComboBox modelComboBox = null; + public ConfNLPToolsPanel(String name) { super(name); initialize(); + fetchAndFillModels(); } - /** - * @see AbstractConfPanel#applyConfiguration() - */ public boolean applyConfiguration() { boolean newsetting = useBox.isSelected(); boolean oldsetting = ConfigurationManager.getConfiguration().getProcess2TextUse(); @@ -111,9 +79,10 @@ public boolean applyConfiguration() { ConfigurationManager.getConfiguration().setProcess2TextServerURI(getManagerPathText().getText()); if (getServerPortText().getText().equals("")) { ConfigurationManager.getConfiguration().setProcess2TextServerPort(0); - } else + } else { ConfigurationManager.getConfiguration() .setProcess2TextServerPort(Integer.parseInt(getServerPortText().getText())); + } ConfigurationManager.getConfiguration().setProcess2TextUse(useBox.isSelected()); ConfigurationManager.getConfiguration().setText2ProcessServerHost(getServerURLText_T2P().getText()); @@ -122,11 +91,11 @@ public boolean applyConfiguration() { if (getServerPortText_T2P().getText().equals("")) { ConfigurationManager.getConfiguration().setText2ProcessServerPort(0); - } else + } else { ConfigurationManager.getConfiguration() .setText2ProcessServerPort(Integer.parseInt(getServerPortText_T2P().getText())); + } - // Save additional panel configurations ConfigurationManager.getConfiguration().setGptApiKey(getApiKeyText().getText()); ConfigurationManager.getConfiguration().setGptShowAgain(true); ConfigurationManager.getConfiguration().setGptPrompt(getPromptText().getText()); @@ -134,11 +103,7 @@ public boolean applyConfiguration() { return true; } - /** - * @see AbstractConfPanel#readConfiguration() - */ public void readConfiguration() { - getServerURLText().setText(ConfigurationManager.getConfiguration().getProcess2TextServerHost()); getManagerPathText().setText(ConfigurationManager.getConfiguration().getProcess2TextServerURI()); getServerPortText().setText("" + ConfigurationManager.getConfiguration().getProcess2TextServerPort()); @@ -146,10 +111,8 @@ public void readConfiguration() { getServerURLText_T2P().setText(ConfigurationManager.getConfiguration().getText2ProcessServerHost()); getManagerPathText_T2P().setText(ConfigurationManager.getConfiguration().getText2ProcessServerURI()); - getServerPortText_T2P().setText("" + ConfigurationManager.getConfiguration().getText2ProcessServerPort()); - // Load additional panel configurations getApiKeyText().setText(ConfigurationManager.getConfiguration().getGptApiKey()); getShowAgainBox().setSelected(ConfigurationManager.getConfiguration().getGptShowAgain()); getPromptText().setText(ConfigurationManager.getConfiguration().getGptPrompt()); @@ -161,7 +124,7 @@ private void initialize() { GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.NORTH; c.fill = GridBagConstraints.HORIZONTAL; - c.insets = new Insets(2, 0, 2, 0); // Small vertical gap between elements + c.insets = new Insets(2, 0, 2, 0); c.weightx = 1; c.gridx = 0; @@ -181,9 +144,8 @@ private void initialize() { c.weightx = 1; c.gridx = 0; c.gridy = 3; - contentPanel.add(getAdditionalPanel(), c); + contentPanel.add(getGPTPanel(), c); - // dummy c.fill = GridBagConstraints.VERTICAL; c.weighty = 1; c.gridy = 4; @@ -192,15 +154,12 @@ private void initialize() { setMainPanel(contentPanel); } - // ################## GUI COMPONENTS #################### */ - private JTextField getServerURLText() { if (serverURLText == null) { serverURLText = new JTextField(); serverURLText.setColumns(40); serverURLText.setEnabled(true); - serverURLText.setToolTipText( - "" + Messages.getString("Configuration.P2T.Label.ServerHost") + ""); + serverURLText.setToolTipText("" + Messages.getString("Configuration.P2T.Label.ServerHost") + ""); } return serverURLText; } @@ -210,8 +169,7 @@ private JTextField getServerURLText_T2P() { serverURLText_T2P = new JTextField(); serverURLText_T2P.setColumns(40); serverURLText_T2P.setEnabled(true); - serverURLText_T2P.setToolTipText( - "" + Messages.getString("Configuration.T2P.Label.ServerHost") + ""); + serverURLText_T2P.setToolTipText("" + Messages.getString("Configuration.T2P.Label.ServerHost") + ""); } return serverURLText_T2P; } @@ -222,15 +180,12 @@ private JPanel getEnabledPanel() { enabledPanel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.WEST; - c.insets = new Insets(2, 0, 2, 0); // Small vertical gap between elements + c.insets = new Insets(2, 0, 2, 0); - enabledPanel.setBorder( - BorderFactory.createCompoundBorder( - BorderFactory.createTitledBorder(Messages.getTitle("Configuration.P2T.Enabled.Panel")), - BorderFactory.createEmptyBorder(10, 10, 10, 10))); + enabledPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Messages.getTitle("Configuration.P2T.Enabled.Panel")), BorderFactory.createEmptyBorder(10, 10, 10, 10))); c.weightx = 1; - c.gridx = 1; + c.gridx = 0; // Move further left c.gridy = 0; enabledPanel.add(getUseBox(), c); } @@ -243,12 +198,9 @@ private JPanel getSettingsPanel() { settingsPanel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.WEST; - c.insets = new Insets(2, 0, 2, 0); // Small vertical gap between elements + c.insets = new Insets(2, 0, 2, 0); - settingsPanel.setBorder( - BorderFactory.createCompoundBorder( - BorderFactory.createTitledBorder(Messages.getString("Configuration.P2T.Settings.Panel.Title")), - BorderFactory.createEmptyBorder(10, 10, 10, 10))); + settingsPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Messages.getString("Configuration.P2T.Settings.Panel.Title")), BorderFactory.createEmptyBorder(10, 10, 10, 10))); c.weightx = 1; c.gridx = 0; c.gridy = 0; @@ -288,8 +240,8 @@ private JPanel getSettingsPanel() { settingsPanel.add(getManagerPathText(), c); c.weightx = 1; - c.gridx = 1; - c.gridy = 4; + c.gridx = 3; + c.gridy = 1; settingsPanel.add(getDefaultButton(), c); } @@ -303,12 +255,9 @@ private JPanel getSettingsPanel_T2P() { settingsPanel_T2P.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.WEST; - c.insets = new Insets(2, 0, 2, 0); // Small vertical gap between elements + c.insets = new Insets(2, 0, 2, 0); - settingsPanel_T2P.setBorder( - BorderFactory.createCompoundBorder( - BorderFactory.createTitledBorder(Messages.getString("Configuration.T2P.Settings.Panel.Title")), - BorderFactory.createEmptyBorder(10, 10, 10, 10))); + settingsPanel_T2P.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Messages.getString("Configuration.T2P.Settings.Panel.Title")), BorderFactory.createEmptyBorder(10, 10, 10, 10))); c.weightx = 1; c.gridx = 0; c.gridy = 0; @@ -348,8 +297,8 @@ private JPanel getSettingsPanel_T2P() { settingsPanel_T2P.add(getManagerPathText_T2P(), c); c.weightx = 1; - c.gridx = 1; - c.gridy = 4; + c.gridx = 3; + c.gridy = 1; settingsPanel_T2P.add(getDefaultButton_T2P(), c); } @@ -357,18 +306,15 @@ private JPanel getSettingsPanel_T2P() { return settingsPanel_T2P; } - private JPanel getAdditionalPanel() { + private JPanel getGPTPanel() { if (additionalPanel == null) { additionalPanel = new JPanel(); additionalPanel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.WEST; - c.insets = new Insets(2, 0, 2, 0); // Small vertical gap between elements + c.insets = new Insets(2, 0, 2, 0); - additionalPanel.setBorder( - BorderFactory.createCompoundBorder( - BorderFactory.createTitledBorder("GPT Settings"), - BorderFactory.createEmptyBorder(10, 10, 10, 10))); + additionalPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("GPT Settings"), BorderFactory.createEmptyBorder(10, 10, 10, 10))); c.weightx = 1; c.gridx = 0; @@ -391,21 +337,31 @@ private JPanel getAdditionalPanel() { c.gridwidth = 2; additionalPanel.add(getPromptTextScrollPane(), c); - c.weightx = 1; + // Add the new row with the label and combo box + c.weightx = 0; c.gridx = 0; c.gridy = 2; - additionalPanel.add(getShowAgainBox(), c); + additionalPanel.add(new JLabel("GPT-Model"), c); c.weightx = 1; c.gridx = 1; c.gridy = 2; - additionalPanel.add(getResetButton(), c); + additionalPanel.add(getModelComboBox(), c); + + c.weightx = 1; + c.gridx = 0; + c.gridy = 3; + additionalPanel.add(getShowAgainBox(), c); c.weightx = 1; c.gridx = 2; - c.gridy = 2; - additionalPanel.add(getCheckConnectionButton(), c); + c.gridy = 3; + additionalPanel.add(getResetButton(), c); + c.weightx = 1; + c.gridx = 1; + c.gridy = 3; + additionalPanel.add(getCheckConnectionButton(), c); } additionalPanel.setVisible(getUseBox().isSelected()); @@ -435,8 +391,7 @@ private JTextArea getPromptText() { promptText.setLineWrap(true); promptText.setWrapStyleWord(true); promptText.setEnabled(true); - promptText.setText( - "Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"); + promptText.setText("Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"); } return promptText; } @@ -455,14 +410,13 @@ private WopedButton getResetButton() { resetButton = new WopedButton(); resetButton.setText(Messages.getString("Configuration.GPT.standard.Title")); resetButton.setPreferredSize(new Dimension(200, 25)); - resetButton.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - setDefaultValuesGPT(); - System.out.println(ConfigurationManager.getConfiguration().getGptShowAgain()); - System.out.println(ConfigurationManager.getConfiguration().getGptPrompt()); - } - }); + resetButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + setDefaultValuesGPT(); + System.out.println(ConfigurationManager.getConfiguration().getGptShowAgain()); + System.out.println(ConfigurationManager.getConfiguration().getGptPrompt()); + } + }); } return resetButton; } @@ -473,19 +427,18 @@ private WopedButton getCheckConnectionButton() { checkConnectionButton.setText(Messages.getString("Configuration.GPT.connection.Title")); checkConnectionButton.setIcon(Messages.getImageIcon("Button.TestConnection")); checkConnectionButton.setMnemonic(Messages.getMnemonic("Button.TestConnection")); - checkConnectionButton.setPreferredSize(new Dimension(200, 25)); - checkConnectionButton.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - testGPTConnection(); - } - }); + checkConnectionButton.setPreferredSize(new Dimension(170, 25)); + checkConnectionButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + testGPTConnection(); + } + }); } return checkConnectionButton; } private void testGPTConnection() { - String apiKey = apiKeyText.getText(); // Annahme: Methode zum Abrufen des API-Schlüssels ist vorhanden + String apiKey = apiKeyText.getText(); String urlString = "https://api.openai.com/v1/engines"; try { @@ -505,92 +458,56 @@ private void testGPTConnection() { } JOptionPane.showMessageDialog( - this.getAdditionalPanel(), + this.getGPTPanel(), message, "Connection Test", JOptionPane.INFORMATION_MESSAGE); } catch (IOException e) { JOptionPane.showMessageDialog( - this.getAdditionalPanel(), + this.getGPTPanel(), "GPT connection test failed: " + e.getMessage(), "Connection Test", JOptionPane.ERROR_MESSAGE); } } - private void setDefaultValuesGPT() { - getApiKeyText().setText(ConfigurationManager.getStandardConfiguration().getGptApiKey()); - getShowAgainBox().setSelected(ConfigurationManager.getStandardConfiguration().getGptShowAgain()); - getPromptText().setText(ConfigurationManager.getStandardConfiguration().getGptPrompt()); - } + private void fetchAndFillModels() { - class CheckboxListener implements ItemListener { - public void itemStateChanged(ItemEvent ie) { - JCheckBox jcb = (JCheckBox) ie.getSource(); - if (jcb == useBox) { - getSettingsPanel().setVisible(jcb.isSelected()); - getSettingsPanel_T2P().setVisible(jcb.isSelected()); - getAdditionalPanel().setVisible(jcb.isSelected()); + new Thread(() -> { + try { + List models = ApiHelper.fetchModels(); + SwingUtilities.invokeLater(() -> { + for (String model : models) { + modelComboBox.addItem(model); + } + }); + } catch (IOException | ParseException e) { + SwingUtilities.invokeLater(() -> { + JOptionPane.showMessageDialog( + this.getGPTPanel(), + "Failed to fetch models: " + e.getMessage(), + "Fetch Models", + JOptionPane.ERROR_MESSAGE); + }); } - } + }).start(); } - private JLabel getServerURLLabel() { - if (serverURLLabel == null) { - serverURLLabel = - new JLabel("" + Messages.getString("Configuration.P2T.Label.ServerHost") + ""); - serverURLLabel.setHorizontalAlignment(JLabel.RIGHT); - } - return serverURLLabel; - } - - private JLabel getServerURLLabel_T2P() { - if (serverURLLabel_T2P == null) { - serverURLLabel_T2P = - new JLabel("" + Messages.getString("Configuration.T2P.Label.ServerHost") + ""); - serverURLLabel_T2P.setHorizontalAlignment(JLabel.RIGHT); - } - return serverURLLabel_T2P; - } - - private JLabel getServerPortLabel() { - if (serverPortLabel == null) { - serverPortLabel = - new JLabel("" + Messages.getString("Configuration.P2T.Label.ServerPort") + ""); - serverPortLabel.setHorizontalAlignment(JLabel.RIGHT); - } - return serverPortLabel; - } - - private JLabel getServerPortLabel_T2P() { - if (serverPortLabel_T2P == null) { - serverPortLabel_T2P = - new JLabel("" + Messages.getString("Configuration.T2P.Label.ServerPort") + ""); - serverPortLabel_T2P.setHorizontalAlignment(JLabel.RIGHT); - } - return serverPortLabel_T2P; - } - - private JTextField getServerPortText() { - if (serverPortText == null) { - serverPortText = new JTextField(); - serverPortText.setColumns(4); - serverPortText.setEnabled(true); - serverPortText.setToolTipText("" + Messages.getString("Configuration.P2T.Label.ServerPort") + ""); - } - return serverPortText; + private void setDefaultValuesGPT() { + getApiKeyText().setText(ConfigurationManager.getStandardConfiguration().getGptApiKey()); + getShowAgainBox().setSelected(ConfigurationManager.getStandardConfiguration().getGptShowAgain()); + getPromptText().setText(ConfigurationManager.getStandardConfiguration().getGptPrompt()); } - private JTextField getServerPortText_T2P() { - if (serverPortText_T2P == null) { - serverPortText_T2P = new JTextField(); - serverPortText_T2P.setColumns(4); - serverPortText_T2P.setEnabled(true); - serverPortText_T2P.setToolTipText("" + Messages.getString("Configuration.T2P.Label.ServerPort") + ""); + private JComboBox getModelComboBox() { + if (modelComboBox == null) { + modelComboBox = new JComboBox<>(); + modelComboBox.setEnabled(true); + modelComboBox.setToolTipText("Select a model"); } - return serverPortText_T2P; + return modelComboBox; } private JCheckBox getUseBox() { @@ -619,8 +536,7 @@ private JCheckBox getUseBox_T2P() { private JLabel getManagerPathLabel() { if (managerPathLabel == null) { - managerPathLabel = - new JLabel("" + Messages.getString("Configuration.P2T.Label.ServerURI") + ""); + managerPathLabel = new JLabel("" + Messages.getString("Configuration.P2T.Label.ServerURI") + ""); managerPathLabel.setHorizontalAlignment(JLabel.RIGHT); } return managerPathLabel; @@ -628,8 +544,7 @@ private JLabel getManagerPathLabel() { private JLabel getManagerPathLabel_T2P() { if (managerPathLabel_T2P == null) { - managerPathLabel_T2P = - new JLabel("" + Messages.getString("Configuration.T2P.Label.ServerURI") + ""); + managerPathLabel_T2P = new JLabel("" + Messages.getString("Configuration.T2P.Label.ServerURI") + ""); managerPathLabel_T2P.setHorizontalAlignment(JLabel.RIGHT); } return managerPathLabel_T2P; @@ -662,12 +577,11 @@ private WopedButton getTestButton() { testButton.setIcon(Messages.getImageIcon("Button.TestConnection")); testButton.setMnemonic(Messages.getMnemonic("Button.TestConnection")); testButton.setPreferredSize(new Dimension(160, 25)); - testButton.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - testProcess2TextConnection(); - } - }); + testButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + testProcess2TextConnection(); + } + }); } return testButton; @@ -680,12 +594,11 @@ private WopedButton getTestButton_T2P() { testButton_T2P.setIcon(Messages.getImageIcon("Button.TestConnection")); testButton_T2P.setMnemonic(Messages.getMnemonic("Button.TestConnection")); testButton_T2P.setPreferredSize(new Dimension(160, 25)); - testButton_T2P.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - testText2ProcessConnection(); - } - }); + testButton_T2P.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + testText2ProcessConnection(); + } + }); } return testButton_T2P; @@ -696,12 +609,7 @@ private WopedButton getDefaultButton() { defaultButton = new WopedButton(); defaultButton.setText(Messages.getTitle("Button.SetToDefault")); defaultButton.setPreferredSize(new Dimension(200, 25)); - defaultButton.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - setDefaultValues(); - } - }); + defaultButton.addActionListener(e -> setDefaultValues()); } return defaultButton; } @@ -711,24 +619,14 @@ private WopedButton getDefaultButton_T2P() { defaultButton_T2P = new WopedButton(); defaultButton_T2P.setText(Messages.getTitle("Button.SetToDefault")); defaultButton_T2P.setPreferredSize(new Dimension(200, 25)); - defaultButton_T2P.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - setDefaultValues_T2P(); - } - }); + defaultButton_T2P.addActionListener(e -> setDefaultValues_T2P()); } return defaultButton_T2P; } private void testProcess2TextConnection() { URL url = null; - String connection = - "http://" - + getServerURLText().getText() - + ":" - + getServerPortText().getText() - + getManagerPathText().getText(); + String connection = "http://" + getServerURLText().getText() + ":" + getServerPortText().getText() + getManagerPathText().getText(); String arg[] = {connection, ""}; try { @@ -737,36 +635,18 @@ private void testProcess2TextConnection() { if (urlConnection.getContent() != null) { arg[1] = "P2T"; - JOptionPane.showMessageDialog( - this.getSettingsPanel(), - Messages.getString("Paraphrasing.Webservice.Success.Message", arg), - Messages.getString("Paraphrasing.Webservice.Success.Title"), - JOptionPane.INFORMATION_MESSAGE); + JOptionPane.showMessageDialog(this.getSettingsPanel(), Messages.getString("Paraphrasing.Webservice.Success.Message", arg), Messages.getString("Paraphrasing.Webservice.Success.Title"), JOptionPane.INFORMATION_MESSAGE); } } catch (MalformedURLException mue) { - JOptionPane.showMessageDialog( - this.getSettingsPanel(), - Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), - Messages.getString("Paraphrasing.Webservice.Error.Title"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(this.getSettingsPanel(), Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), Messages.getString("Paraphrasing.Webservice.Error.Title"), JOptionPane.ERROR_MESSAGE); } catch (IOException ex) { - JOptionPane.showMessageDialog( - this.getSettingsPanel(), - Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), - Messages.getString("Paraphrasing.Webservice.Error.Title"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(this.getSettingsPanel(), Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), Messages.getString("Paraphrasing.Webservice.Error.Title"), JOptionPane.ERROR_MESSAGE); } } private void testText2ProcessConnection() { - URL url = null; - String connection = - "http://" - + getServerURLText_T2P().getText() - + ":" - + getServerPortText_T2P().getText() - + getManagerPathText_T2P().getText() - + ""; + URL url; + String connection = "http://" + getServerURLText_T2P().getText() + ":" + getServerPortText_T2P().getText() + getManagerPathText_T2P().getText(); String arg[] = {connection, ""}; try { @@ -774,42 +654,87 @@ private void testText2ProcessConnection() { URLConnection urlConnection = url.openConnection(); if (urlConnection.getContent() != null) { arg[1] = "T2P"; - JOptionPane.showMessageDialog( - this.getSettingsPanel_T2P(), - Messages.getString("Paraphrasing.Webservice.Success.Message", arg), - Messages.getString("Paraphrasing.Webservice.Success.Title"), - JOptionPane.INFORMATION_MESSAGE); + JOptionPane.showMessageDialog(this.getSettingsPanel_T2P(), Messages.getString("Paraphrasing.Webservice.Success.Message", arg), Messages.getString("Paraphrasing.Webservice.Success.Title"), JOptionPane.INFORMATION_MESSAGE); } } catch (MalformedURLException mue) { - JOptionPane.showMessageDialog( - this.getSettingsPanel_T2P(), - Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), - Messages.getString("Paraphrasing.Webservice.Error.Title"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(this.getSettingsPanel_T2P(), Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), Messages.getString("Paraphrasing.Webservice.Error.Title"), JOptionPane.ERROR_MESSAGE); } catch (IOException ex) { - JOptionPane.showMessageDialog( - this.getSettingsPanel_T2P(), - Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), - Messages.getString("Paraphrasing.Webservice.Error.Title"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(this.getSettingsPanel_T2P(), Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), Messages.getString("Paraphrasing.Webservice.Error.Title"), JOptionPane.ERROR_MESSAGE); } } private void setDefaultValues() { - getServerURLText() - .setText(ConfigurationManager.getStandardConfiguration().getProcess2TextServerHost()); - getManagerPathText() - .setText(ConfigurationManager.getStandardConfiguration().getProcess2TextServerURI()); - getServerPortText() - .setText("" + ConfigurationManager.getStandardConfiguration().getProcess2TextServerPort()); + getServerURLText().setText(ConfigurationManager.getStandardConfiguration().getProcess2TextServerHost()); + getManagerPathText().setText(ConfigurationManager.getStandardConfiguration().getProcess2TextServerURI()); + getServerPortText().setText("" + ConfigurationManager.getStandardConfiguration().getProcess2TextServerPort()); } private void setDefaultValues_T2P() { - getServerURLText_T2P() - .setText(ConfigurationManager.getStandardConfiguration().getText2ProcessServerHost()); - getManagerPathText_T2P() - .setText(ConfigurationManager.getStandardConfiguration().getText2ProcessServerURI()); - getServerPortText_T2P() - .setText("" + ConfigurationManager.getStandardConfiguration().getText2ProcessServerPort()); + getServerURLText_T2P().setText(ConfigurationManager.getStandardConfiguration().getText2ProcessServerHost()); + getManagerPathText_T2P().setText(ConfigurationManager.getStandardConfiguration().getText2ProcessServerURI()); + getServerPortText_T2P().setText("" + ConfigurationManager.getStandardConfiguration().getText2ProcessServerPort()); + } + + class CheckboxListener implements ItemListener { + public void itemStateChanged(ItemEvent ie) { + JCheckBox jcb = (JCheckBox) ie.getSource(); + if (jcb == useBox) { + getSettingsPanel().setVisible(jcb.isSelected()); + getSettingsPanel_T2P().setVisible(jcb.isSelected()); + getGPTPanel().setVisible(jcb.isSelected()); + } + } + } + + private JLabel getServerURLLabel() { + if (serverURLLabel == null) { + serverURLLabel = new JLabel("" + Messages.getString("Configuration.P2T.Label.ServerHost") + ""); + serverURLLabel.setHorizontalAlignment(JLabel.RIGHT); + } + return serverURLLabel; + } + + private JLabel getServerURLLabel_T2P() { + if (serverURLLabel_T2P == null) { + serverURLLabel_T2P = new JLabel("" + Messages.getString("Configuration.T2P.Label.ServerHost") + ""); + serverURLLabel_T2P.setHorizontalAlignment(JLabel.RIGHT); + } + return serverURLLabel_T2P; + } + + private JLabel getServerPortLabel() { + if (serverPortLabel == null) { + serverPortLabel = new JLabel("" + Messages.getString("Configuration.P2T.Label.ServerPort") + ""); + serverPortLabel.setHorizontalAlignment(JLabel.RIGHT); + } + return serverPortLabel; + } + + private JLabel getServerPortLabel_T2P() { + if (serverPortLabel_T2P == null) { + serverPortLabel_T2P = new JLabel("" + Messages.getString("Configuration.T2P.Label.ServerPort") + ""); + serverPortLabel_T2P.setHorizontalAlignment(JLabel.RIGHT); + } + return serverPortLabel_T2P; + } + + private JTextField getServerPortText() { + if (serverPortText == null) { + serverPortText = new JTextField(); + serverPortText.setColumns(4); + serverPortText.setEnabled(true); + serverPortText.setToolTipText("" + Messages.getString("Configuration.P2T.Label.ServerPort") + ""); + } + return serverPortText; + } + + private JTextField getServerPortText_T2P() { + if (serverPortText_T2P == null) { + serverPortText_T2P = new JTextField(); + serverPortText_T2P.setColumns(4); + serverPortText_T2P.setEnabled(true); + serverPortText_T2P.setToolTipText("" + Messages.getString("Configuration.T2P.Label.ServerPort") + ""); + } + return serverPortText_T2P; } } diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java b/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java new file mode 100644 index 000000000..96b784fa3 --- /dev/null +++ b/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java @@ -0,0 +1,47 @@ +package org.woped.editor.tools; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import org.json.simple.JSONArray; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +public class ApiHelper { + + public static List fetchModels() throws IOException, ParseException { + String urlString = "http://localhost:8080/p2t/gptModels"; + List models = new ArrayList<>(); + + URL url = new URL(urlString); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.connect(); + + int responseCode = connection.getResponseCode(); + if (responseCode == 200) { + BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String inputLine; + StringBuilder content = new StringBuilder(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + + JSONParser parser = new JSONParser(); + JSONArray modelsArray = (JSONArray) parser.parse(content.toString()); + for (Object model : modelsArray) { + models.add(model.toString()); + } + } else { + throw new IOException("Failed to fetch models. Response Code: " + responseCode); + } + + return models; + } +} diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 40dc29a1a..62d332a50 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -9,7 +9,6 @@ import java.awt.Insets; import java.awt.Toolkit; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.net.HttpURLConnection; import java.net.URL; @@ -18,6 +17,7 @@ import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JCheckBox; +import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; @@ -143,6 +143,11 @@ private JPanel initializeSwitchButtonPanel() { } }); + // Add JComboBox + JLabel gptModelLabel = new JLabel("GPT-Model:"); + gptModelLabel.setVisible(false); // Inititally hidden + JComboBox exampleComboBox = new JComboBox<>(new String[]{"Example 1", "Example 2", "Example 3"}); + exampleComboBox.setVisible(false); // Initially hidden dontshowAgainCheckBox = new JCheckBox(Messages.getString("P2T.popup.show.again.title")); dontshowAgainCheckBox.setSelected(ConfigurationManager.getConfiguration().getGptShowAgain()); @@ -163,6 +168,8 @@ private JPanel initializeSwitchButtonPanel() { promptLabel.setVisible(true); promptScrollPane.setVisible(true); enablePromptCheckBox.setVisible(true); + gptModelLabel.setVisible(true); // Show when new service is selected + exampleComboBox.setVisible(true); // Show when new service is selected dontshowAgainCheckBox.setVisible(true); // Show when new service is selected @@ -175,6 +182,8 @@ private JPanel initializeSwitchButtonPanel() { promptLabel.setVisible(false); promptScrollPane.setVisible(false); enablePromptCheckBox.setVisible(false); + gptModelLabel.setVisible(false); // Hide when old service is selected + exampleComboBox.setVisible(false); // Hide when old service is selected dontshowAgainCheckBox.setVisible(true); // Hide when old service is selected @@ -213,14 +222,25 @@ private JPanel initializeSwitchButtonPanel() { fieldsPanel.add(enablePromptCheckBox, gbc); gbc.gridx = 0; + gbc.gridy = 4; + gbc.gridwidth = 1; + gbc.weightx = 0; + fieldsPanel.add(gptModelLabel, gbc); // Add label before JComboBox + gbc.gridx = 1; gbc.gridy = 4; + gbc.gridwidth = 1; + gbc.weightx = 1.0; + gbc.fill = GridBagConstraints.HORIZONTAL; + fieldsPanel.add(exampleComboBox, gbc); // Add JComboBox to the panel + + gbc.gridx = 0; + gbc.gridy = 5; gbc.gridwidth = 2; gbc.weightx = 1.0; fieldsPanel.add(dontshowAgainCheckBox, gbc); // Add "Show Again" checkbox gbc.gridx = 0; - gbc.gridy = 1; gbc.gridwidth = 2; gbc.insets = new Insets(10, 0, 0, 0); @@ -243,7 +263,7 @@ private JPanel initializeSingleButtonPanel() { singleButton.addActionListener( new ActionButtonListener( - m_mediator, ActionFactory.ACTIONID_P2t_NEW, AbstractViewEvent.P2T, singleButton)); + m_mediator, ActionFactory.ACTIONID_P2T_OLD, AbstractViewEvent.P2T, singleButton)); singleButton.addActionListener(e -> { if (newRadioButton.isSelected()) { validateAPIKey(); diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java index e3365c4d0..fa1da29a9 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java @@ -48,8 +48,7 @@ public void run() { + ConfigurationManager.getConfiguration().getProcess2TextServerURI() + "/generateTextLLM"; - String fullTestUrl = testUrl + "?apiKey=" + apiKey + "&prompt=" + prompt + "&gptModel=" + gptModel; - String fullUrl = url + "?apiKey=" + apiKey + "&prompt=" + prompt + "&gptModel=" + gptModel; + ByteArrayOutputStream stream = new ByteArrayOutputStream(); new PNMLExport().saveToStream(editor, stream); @@ -57,6 +56,8 @@ public void run() { System.out.println(text); String output; + //TODO Diese logik in die Buttons implementieren!! + try { // URL-Parameter kodieren String encodedApiKey = URLEncoder.encode(apiKey, StandardCharsets.UTF_8.toString()); From eec2a1cf1936932f2a5ae5e6a4415e018a4296a9 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Wed, 12 Jun 2024 16:23:03 +0200 Subject: [PATCH 26/76] Added Dropdownmenu for gpt models in old / new switch panel Added Dropdownmenu for gpt models in old / new switch panel --- .../editor/gui/config/ConfNLPToolsPanel.java | 2 - .../main/java/org/woped/file/p2t/P2TUI.java | 92 ++++++++++--------- 2 files changed, 50 insertions(+), 44 deletions(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index f869641ac..a041766f6 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -473,8 +473,6 @@ private void testGPTConnection() { } private void fetchAndFillModels() { - - new Thread(() -> { try { List models = ApiHelper.fetchModels(); diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 62d332a50..3e1800202 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -8,35 +8,21 @@ import java.awt.HeadlessException; import java.awt.Insets; import java.awt.Toolkit; -import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; +import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; -import javax.swing.AbstractAction; -import javax.swing.BorderFactory; -import javax.swing.ButtonGroup; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JRadioButton; -import javax.swing.JTextArea; -import javax.swing.JTextField; +import java.util.List; +import javax.swing.*; +import org.json.simple.parser.ParseException; import org.woped.core.config.ConfigurationManager; -import org.woped.core.config.IConfiguration; import org.woped.core.controller.AbstractApplicationMediator; import org.woped.core.controller.AbstractViewEvent; -import org.woped.core.controller.ViewEvent; import org.woped.editor.action.ActionButtonListener; import org.woped.editor.controller.ActionFactory; +import org.woped.editor.tools.ApiHelper; import org.woped.gui.translations.Messages; -import org.woped.qualanalysis.p2t.P2TSideBar; -import org.woped.qualanalysis.p2t.WebServiceThreadLLM; public class P2TUI extends JDialog { private JDialog loadDialog; @@ -46,10 +32,11 @@ public class P2TUI extends JDialog { private JTextArea promptField; // Changed to JTextArea for multiline private JCheckBox enablePromptCheckBox; // New Checkbox - private JCheckBox dontshowAgainCheckBox; // New Checkbox + private JCheckBox showAgainCheckBox; // New Checkbox private JRadioButton newRadioButton = null; private JRadioButton oldRadioButton = null; private AbstractApplicationMediator m_mediator = null; + JComboBox modelComboBox; private static final String DEFAULT_PROMPT = "Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"; @@ -80,8 +67,9 @@ private void initialize() { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation((screenSize.width - this.getWidth()) / 3, (screenSize.height - this.getHeight()) / 3); - Dimension size = new Dimension(600, 350); // Adjusted size to accommodate new text field and checkbox + Dimension size = new Dimension(600, 375); this.setSize(size); + fetchAndFillModels(); } private JPanel initializeSwitchButtonPanel() { @@ -119,11 +107,11 @@ private JPanel initializeSwitchButtonPanel() { apiKeyField.setPreferredSize(new Dimension(200, 25)); JLabel promptLabel = new JLabel(Messages.getString("P2T.prompt.title") + ":"); - promptField = new JTextArea(DEFAULT_PROMPT); // Changed to JTextArea + promptField = new JTextArea(DEFAULT_PROMPT); promptField.setLineWrap(true); promptField.setWrapStyleWord(true); - promptField.setRows(5); // Set initial number of rows - promptField.setEnabled(false); // Initially disabled + promptField.setRows(5); + promptField.setEnabled(false); promptField.setText(ConfigurationManager.getConfiguration().getGptPrompt()); @@ -145,13 +133,12 @@ private JPanel initializeSwitchButtonPanel() { // Add JComboBox JLabel gptModelLabel = new JLabel("GPT-Model:"); - gptModelLabel.setVisible(false); // Inititally hidden - JComboBox exampleComboBox = new JComboBox<>(new String[]{"Example 1", "Example 2", "Example 3"}); - exampleComboBox.setVisible(false); // Initially hidden - - dontshowAgainCheckBox = new JCheckBox(Messages.getString("P2T.popup.show.again.title")); - dontshowAgainCheckBox.setSelected(ConfigurationManager.getConfiguration().getGptShowAgain()); - dontshowAgainCheckBox.setToolTipText("Placeholder"); + gptModelLabel.setVisible(false); // Initially hidden + modelComboBox = new JComboBox<>(); + modelComboBox.setVisible(false); // Initially hidden + showAgainCheckBox = new JCheckBox(Messages.getString("P2T.popup.show.again.title")); + showAgainCheckBox.setSelected(ConfigurationManager.getConfiguration().getGptShowAgain()); + showAgainCheckBox.setToolTipText("Placeholder"); apiKeyLabel.setVisible(false); apiKeyField.setText(ConfigurationManager.getConfiguration().getGptApiKey()); apiKeyField.setVisible(false); @@ -159,7 +146,7 @@ private JPanel initializeSwitchButtonPanel() { promptScrollPane.setVisible(false); enablePromptCheckBox.setVisible(false); - dontshowAgainCheckBox.setVisible(false); // Initially hidden + showAgainCheckBox.setVisible(false); // Initially hidden newRadioButton.addActionListener(e -> { @@ -168,10 +155,10 @@ private JPanel initializeSwitchButtonPanel() { promptLabel.setVisible(true); promptScrollPane.setVisible(true); enablePromptCheckBox.setVisible(true); - gptModelLabel.setVisible(true); // Show when new service is selected - exampleComboBox.setVisible(true); // Show when new service is selected - - dontshowAgainCheckBox.setVisible(true); // Show when new service is selected + gptModelLabel.setVisible(true); + modelComboBox.setVisible(true); + modelComboBox.setSelectedIndex(4); + showAgainCheckBox.setVisible(true); apiKeyField.requestFocusInWindow(); }); @@ -183,9 +170,9 @@ private JPanel initializeSwitchButtonPanel() { promptScrollPane.setVisible(false); enablePromptCheckBox.setVisible(false); gptModelLabel.setVisible(false); // Hide when old service is selected - exampleComboBox.setVisible(false); // Hide when old service is selected + modelComboBox.setVisible(false); // Hide when old service is selected - dontshowAgainCheckBox.setVisible(true); // Hide when old service is selected + showAgainCheckBox.setVisible(true); // Hide when old service is selected }); @@ -232,13 +219,13 @@ private JPanel initializeSwitchButtonPanel() { gbc.gridwidth = 1; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; - fieldsPanel.add(exampleComboBox, gbc); // Add JComboBox to the panel + fieldsPanel.add(modelComboBox, gbc); // Add JComboBox to the panel gbc.gridx = 0; gbc.gridy = 5; gbc.gridwidth = 2; gbc.weightx = 1.0; - fieldsPanel.add(dontshowAgainCheckBox, gbc); // Add "Show Again" checkbox + fieldsPanel.add(showAgainCheckBox, gbc); // Add "Show Again" checkbox gbc.gridx = 0; gbc.gridy = 1; @@ -273,13 +260,13 @@ private JPanel initializeSingleButtonPanel() { ConfigurationManager.getConfiguration().setGptPrompt(promptField.getText()); - if (!dontshowAgainCheckBox.isSelected()) { + if (!showAgainCheckBox.isSelected()) { ConfigurationManager.getConfiguration().setGptShowAgain(false); ConfigurationManager.getConfiguration().setGptUseNew(true); } } else { - if (!dontshowAgainCheckBox.isSelected()) { + if (!showAgainCheckBox.isSelected()) { ConfigurationManager.getConfiguration().setGptShowAgain(false); ConfigurationManager.getConfiguration().setGptUseNew(false); } @@ -290,6 +277,27 @@ private JPanel initializeSingleButtonPanel() { return buttonPanel; } + private void fetchAndFillModels() { + new Thread(() -> { + try { + List models = ApiHelper.fetchModels(); + SwingUtilities.invokeLater(() -> { + for (String model : models) { + modelComboBox.addItem(model); + } + }); + } catch (IOException | ParseException e) { + SwingUtilities.invokeLater(() -> { + JOptionPane.showMessageDialog( + this.initializeSwitchButtonPanel(), + "Failed to fetch models: " + e.getMessage(), + "Fetch Models", + JOptionPane.ERROR_MESSAGE); + }); + } + }).start(); + } + private void validateAPIKey() { String apiKey = apiKeyField.getText(); From da4d467373d38fb76a92239fe3923f609127047b Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Wed, 12 Jun 2024 22:03:44 +0200 Subject: [PATCH 27/76] Added config for GPT Model so that the client remebers what was last used Added config for GPT Model so that the client remebers what was last used --- .../woped/beanconfiguration/configuration.xsd | 1 + .../general/WoPeDGeneralConfiguration.java | 10 +++++++ .../config/DefaultStaticConfiguration.java | 9 ++++++ .../core/config/IGeneralConfiguration.java | 4 +++ .../editor/gui/config/ConfNLPToolsPanel.java | 28 ++++++++++++++++--- .../org/woped/editor/tools/ApiHelper.java | 2 +- .../main/java/org/woped/file/p2t/P2TUI.java | 20 +++++++++---- 7 files changed, 63 insertions(+), 11 deletions(-) diff --git a/WoPeD-BeanConfiguration/src/main/java/org/woped/beanconfiguration/configuration.xsd b/WoPeD-BeanConfiguration/src/main/java/org/woped/beanconfiguration/configuration.xsd index 8aa46cfb4..8e6b0de4d 100644 --- a/WoPeD-BeanConfiguration/src/main/java/org/woped/beanconfiguration/configuration.xsd +++ b/WoPeD-BeanConfiguration/src/main/java/org/woped/beanconfiguration/configuration.xsd @@ -144,6 +144,7 @@ + diff --git a/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDGeneralConfiguration.java b/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDGeneralConfiguration.java index e5b8be8ad..b8011d14f 100644 --- a/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDGeneralConfiguration.java +++ b/WoPeD-Configuration/src/main/java/org/woped/config/general/WoPeDGeneralConfiguration.java @@ -1490,6 +1490,16 @@ public void setGptApiKey(String apiKey) { getConfDocument().getConfiguration().getGpt().setGptApiKey(apiKey); } + public String getGptModel(){ + if(getConfDocument().getConfiguration().getGpt().isSetGptModel()){ + return getConfDocument().getConfiguration().getGpt().getGptModel(); + } else return ConfigurationManager.getStandardConfiguration().getGptModel(); + } + + public void setGptModel(String model){ + getConfDocument().getConfiguration().getGpt().setGptModel(model); + } + @Override public boolean getGptShowAgain() { if(getConfDocument().getConfiguration().getGpt().isSetGptShowAgain()){ diff --git a/WoPeD-Core/src/main/java/org/woped/core/config/DefaultStaticConfiguration.java b/WoPeD-Core/src/main/java/org/woped/core/config/DefaultStaticConfiguration.java index 04fad1581..132147e78 100644 --- a/WoPeD-Core/src/main/java/org/woped/core/config/DefaultStaticConfiguration.java +++ b/WoPeD-Core/src/main/java/org/woped/core/config/DefaultStaticConfiguration.java @@ -195,6 +195,7 @@ public class DefaultStaticConfiguration implements IGeneralConfiguration { private boolean gptShowAgain = true; private String gptPrompt = "Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"; private boolean gptUseNew = false; + private String gptModel = null; public boolean isGptUseNew() { return gptUseNew; @@ -207,6 +208,14 @@ public boolean getGptUseNew(){ return gptUseNew; } + public void setGptModel(String gptModel) { + this.gptModel = gptModel; + } + + public String getGptModel() { + return gptModel; + } + public DefaultStaticConfiguration() { initConfig(); } diff --git a/WoPeD-Core/src/main/java/org/woped/core/config/IGeneralConfiguration.java b/WoPeD-Core/src/main/java/org/woped/core/config/IGeneralConfiguration.java index 0b6e2e387..b0821c8b6 100644 --- a/WoPeD-Core/src/main/java/org/woped/core/config/IGeneralConfiguration.java +++ b/WoPeD-Core/src/main/java/org/woped/core/config/IGeneralConfiguration.java @@ -577,4 +577,8 @@ public void changeApromoreServerSettings( public void setGptUseNew(boolean useNew); public boolean getGptUseNew(); + + public void setGptModel(String model); + + public String getGptModel(); } diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index a041766f6..0203aea2c 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -16,6 +16,7 @@ import java.util.List; import javax.swing.*; +import com.sun.codemodel.JCatchBlock; import org.json.simple.parser.ParseException; import org.woped.core.config.ConfigurationManager; import org.woped.editor.tools.ApiHelper; @@ -53,14 +54,24 @@ public class ConfNLPToolsPanel extends AbstractConfPanel { private WopedButton resetButton = null; private JTextArea promptText = null; private WopedButton checkConnectionButton = null; + List models; + { + try { + models = ApiHelper.fetchModels(); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } + } + private String[] models2 = models.toArray(new String[0]); // New components - private JComboBox modelComboBox = null; + private JComboBox modelComboBox = new JComboBox(models2); public ConfNLPToolsPanel(String name) { super(name); initialize(); - fetchAndFillModels(); } public boolean applyConfiguration() { @@ -95,10 +106,10 @@ public boolean applyConfiguration() { ConfigurationManager.getConfiguration() .setText2ProcessServerPort(Integer.parseInt(getServerPortText_T2P().getText())); } - ConfigurationManager.getConfiguration().setGptApiKey(getApiKeyText().getText()); ConfigurationManager.getConfiguration().setGptShowAgain(true); ConfigurationManager.getConfiguration().setGptPrompt(getPromptText().getText()); + ConfigurationManager.getConfiguration().setGptModel(modelComboBox.getSelectedItem().toString()); return true; } @@ -112,10 +123,11 @@ public void readConfiguration() { getServerURLText_T2P().setText(ConfigurationManager.getConfiguration().getText2ProcessServerHost()); getManagerPathText_T2P().setText(ConfigurationManager.getConfiguration().getText2ProcessServerURI()); getServerPortText_T2P().setText("" + ConfigurationManager.getConfiguration().getText2ProcessServerPort()); - getApiKeyText().setText(ConfigurationManager.getConfiguration().getGptApiKey()); getShowAgainBox().setSelected(ConfigurationManager.getConfiguration().getGptShowAgain()); getPromptText().setText(ConfigurationManager.getConfiguration().getGptPrompt()); + System.out.println(ConfigurationManager.getConfiguration().getGptModel()); + } private void initialize() { @@ -152,6 +164,7 @@ private void initialize() { contentPanel.add(new JPanel(), c); setMainPanel(contentPanel); + } private JTextField getServerURLText() { @@ -365,6 +378,13 @@ private JPanel getGPTPanel() { } additionalPanel.setVisible(getUseBox().isSelected()); + //fetchAndFillModels(); + for (int i = 0; i < modelComboBox.getItemCount(); i++){ + if (modelComboBox.getItemAt(i).equals(ConfigurationManager.getConfiguration().getGptModel())){ + modelComboBox.setSelectedIndex(i); + break; + } + } return additionalPanel; } diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java b/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java index 96b784fa3..03f9647e7 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java @@ -41,7 +41,7 @@ public static List fetchModels() throws IOException, ParseException { } else { throw new IOException("Failed to fetch models. Response Code: " + responseCode); } - + System.out.println(models); return models; } } diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 3e1800202..e5cfed5ef 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -8,6 +8,8 @@ import java.awt.HeadlessException; import java.awt.Insets; import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.io.IOException; import java.net.HttpURLConnection; @@ -157,7 +159,12 @@ private JPanel initializeSwitchButtonPanel() { enablePromptCheckBox.setVisible(true); gptModelLabel.setVisible(true); modelComboBox.setVisible(true); - modelComboBox.setSelectedIndex(4); + for (int i = 0; i < modelComboBox.getItemCount(); i++){ + if(modelComboBox.getItemAt(i).equals(ConfigurationManager.getConfiguration().getGptModel())){ + modelComboBox.setSelectedIndex(i); + break; + } + } showAgainCheckBox.setVisible(true); apiKeyField.requestFocusInWindow(); @@ -169,15 +176,15 @@ private JPanel initializeSwitchButtonPanel() { promptLabel.setVisible(false); promptScrollPane.setVisible(false); enablePromptCheckBox.setVisible(false); - gptModelLabel.setVisible(false); // Hide when old service is selected - modelComboBox.setVisible(false); // Hide when old service is selected + gptModelLabel.setVisible(false); + modelComboBox.setVisible(false); - showAgainCheckBox.setVisible(true); // Hide when old service is selected + showAgainCheckBox.setVisible(true); }); - // Set "alt" as default selection + oldRadioButton.setSelected(true); gbc.gridx = 0; @@ -258,7 +265,8 @@ private JPanel initializeSingleButtonPanel() { ConfigurationManager.getConfiguration().setGptApiKey(apiKeyField.getText()); ConfigurationManager.getConfiguration().setGptPrompt(promptField.getText()); - + ConfigurationManager.getConfiguration().setGptModel(modelComboBox.getSelectedItem().toString()); + System.out.println(modelComboBox.getSelectedItem().toString()); if (!showAgainCheckBox.isSelected()) { ConfigurationManager.getConfiguration().setGptShowAgain(false); From 9c81bab27d847e571d7a6d354bf7d63f7eb0be30 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Thu, 13 Jun 2024 01:43:20 +0200 Subject: [PATCH 28/76] connected the client to the p2t backend connected the client to the p2t backend so that the transformation works (sometimes) --- .../src/main/java/org/woped/file/p2t/P2TUI.java | 4 ++-- .../src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java | 2 +- .../java/org/woped/qualanalysis/p2t/WebServiceThread.java | 4 ++++ .../java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java | 5 +++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index e5cfed5ef..cd3d9c5d4 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -148,7 +148,7 @@ private JPanel initializeSwitchButtonPanel() { promptScrollPane.setVisible(false); enablePromptCheckBox.setVisible(false); - showAgainCheckBox.setVisible(false); // Initially hidden + showAgainCheckBox.setVisible(true); newRadioButton.addActionListener(e -> { @@ -257,7 +257,7 @@ private JPanel initializeSingleButtonPanel() { singleButton.addActionListener( new ActionButtonListener( - m_mediator, ActionFactory.ACTIONID_P2T_OLD, AbstractViewEvent.P2T, singleButton)); + m_mediator, ActionFactory.ACTIONID_P2T_OLD, AbstractViewEvent.P2T, singleButton)); singleButton.addActionListener(e -> { if (newRadioButton.isSelected()) { validateAPIKey(); diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java index a7f9261e6..3b2abb17b 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java @@ -361,7 +361,7 @@ private void getText() { } this.textpane.setText(""); - if (naturalTextParser != null) this.textpane.setText(naturalTextParser.getHtmlText()); + if (naturalTextParser != null) this.textpane.setText(webService.getText()); setThreadInProgress(false); webService = null; diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java index 877a04b3a..f8d59c8fb 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java @@ -15,6 +15,7 @@ public class WebServiceThread extends Thread { private boolean isFinished; private HttpRequest request; private HttpResponse response; + private String text; public WebServiceThread(P2TSideBar paraphrasingPanel) { @@ -50,6 +51,7 @@ public void run() { paraphrasingPanel.setNaturalTextParser(new Process2Text(output)); + switch (response.responseCode) { case HttpServletResponse.SC_NO_CONTENT: case HttpServletResponse.SC_REQUEST_TIMEOUT: @@ -77,4 +79,6 @@ public void run() { paraphrasingPanel.enableButtons(true); paraphrasingPanel.setThreadInProgress(false); } + + } diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java index fa1da29a9..b57c1f1e8 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java @@ -21,6 +21,7 @@ public class WebServiceThreadLLM extends Thread { private String apiKey; private String prompt; private String gptModel; + private String text; public WebServiceThreadLLM(P2TSideBar paraphrasingPanel) { this.paraphrasingPanel = paraphrasingPanel; @@ -89,6 +90,7 @@ public void run() { output = output.replaceAll("\\s*\n\\s*", ""); paraphrasingPanel.setNaturalTextParser(new Process2Text(output)); System.out.println(output); + setText(output); } } else { output = "Request failed. Response Code: " + responseCode; @@ -133,4 +135,7 @@ public void run() { paraphrasingPanel.setThreadInProgress(false); } } + + public void setText(String output) {this.text = output;} + public String getText() {return this.text;} } From 6c259693f11a1cc9f5d753fa77fddf97cfb1f834 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Thu, 13 Jun 2024 02:08:34 +0200 Subject: [PATCH 29/76] close popup on text-generation, added gptmodel selection to api call --- .../src/main/java/org/woped/file/p2t/P2TUI.java | 17 ++++++++++++----- .../qualanalysis/p2t/WebServiceThreadLLM.java | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index cd3d9c5d4..41bf34757 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -21,7 +21,9 @@ import org.woped.core.config.ConfigurationManager; import org.woped.core.controller.AbstractApplicationMediator; import org.woped.core.controller.AbstractViewEvent; +import org.woped.core.controller.ViewEvent; import org.woped.editor.action.ActionButtonListener; +import org.woped.editor.action.WoPeDAction; import org.woped.editor.controller.ActionFactory; import org.woped.editor.tools.ApiHelper; import org.woped.gui.translations.Messages; @@ -148,7 +150,7 @@ private JPanel initializeSwitchButtonPanel() { promptScrollPane.setVisible(false); enablePromptCheckBox.setVisible(false); - showAgainCheckBox.setVisible(true); + showAgainCheckBox.setVisible(true); newRadioButton.addActionListener(e -> { @@ -255,10 +257,9 @@ private JPanel initializeSingleButtonPanel() { buttonPanel.add(singleButton, BorderLayout.CENTER); - singleButton.addActionListener( - new ActionButtonListener( - m_mediator, ActionFactory.ACTIONID_P2T_OLD, AbstractViewEvent.P2T, singleButton)); + singleButton.addActionListener(e -> { + dispose(); if (newRadioButton.isSelected()) { validateAPIKey(); @@ -280,10 +281,16 @@ private JPanel initializeSingleButtonPanel() { } } - + executeAction(); }); return buttonPanel; } + private void executeAction() { + WoPeDAction action = ActionFactory.getStaticAction(ActionFactory.ACTIONID_P2T_OLD); + action.actionPerformed( + new ViewEvent(this, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.P2T, null)); + } + private void fetchAndFillModels() { new Thread(() -> { diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java index b57c1f1e8..32494d005 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java @@ -35,7 +35,7 @@ public boolean getIsFinished() { public void run() { apiKey = ConfigurationManager.getConfiguration().getGptApiKey(); prompt = ConfigurationManager.getConfiguration().getGptPrompt(); - gptModel = "gpt-4-turbo"; + gptModel = ConfigurationManager.getConfiguration().getGptModel(); IEditor editor = paraphrasingPanel.getEditor(); paraphrasingPanel.showLoadingAnimation(true); From 9d92449224de6d98507ebc5e9ab1bf85ab8802be Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Thu, 13 Jun 2024 13:38:23 +0200 Subject: [PATCH 30/76] Added logic to both old and new Call Added logic to both old and new Call, however it only works on localhost right now for some reason --- .../main/java/org/woped/file/p2t/P2TUI.java | 4 +- .../woped/qualanalysis/p2t/P2TSideBar.java | 48 ++++++++++++++----- .../qualanalysis/p2t/WebServiceThread.java | 19 ++++---- .../qualanalysis/p2t/WebServiceThreadLLM.java | 3 -- 4 files changed, 50 insertions(+), 24 deletions(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 41bf34757..fbbd85708 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -259,7 +259,7 @@ private JPanel initializeSingleButtonPanel() { singleButton.addActionListener(e -> { - dispose(); + //dispose(); if (newRadioButton.isSelected()) { validateAPIKey(); @@ -267,6 +267,7 @@ private JPanel initializeSingleButtonPanel() { ConfigurationManager.getConfiguration().setGptApiKey(apiKeyField.getText()); ConfigurationManager.getConfiguration().setGptPrompt(promptField.getText()); ConfigurationManager.getConfiguration().setGptModel(modelComboBox.getSelectedItem().toString()); + ConfigurationManager.getConfiguration().setGptUseNew(true); System.out.println(modelComboBox.getSelectedItem().toString()); if (!showAgainCheckBox.isSelected()) { @@ -275,6 +276,7 @@ private JPanel initializeSingleButtonPanel() { } } else { + ConfigurationManager.getConfiguration().setGptUseNew(false); if (!showAgainCheckBox.isSelected()) { ConfigurationManager.getConfiguration().setGptShowAgain(false); ConfigurationManager.getConfiguration().setGptUseNew(false); diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java index 3b2abb17b..25eb5d06d 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java @@ -16,6 +16,8 @@ import javax.swing.event.HyperlinkListener; import javax.swing.filechooser.FileFilter; import javax.swing.text.BadLocationException; + +import org.woped.core.config.ConfigurationManager; import org.woped.core.controller.IEditor; import org.woped.core.model.ModelElementContainer; import org.woped.core.utilities.LoggerManager; @@ -36,6 +38,7 @@ public class P2TSideBar extends JPanel implements ActionListener { private JButton buttonExport = null; private JLabel labelLoading = null; private WebServiceThreadLLM webService = null; + private WebServiceThread webServiceOld = null; private boolean threadInProgress = false; private boolean firstTimeDisplayed = false; @@ -347,21 +350,42 @@ private void getText() { this.textpane.setText(Messages.getString("P2T.SoundError")); return; } - - this.textpane.setText(Messages.getString("P2T.loading")); - this.showLoadingAnimation(true); - webService = new WebServiceThreadLLM(this); - webService.start(); - while (!webService.getIsFinished()) { - try { - Thread.sleep(500); - } catch (InterruptedException e1) { - // ignore + //New LLM + if(ConfigurationManager.getConfiguration().getGptUseNew()){ + System.out.println(ConfigurationManager.getConfiguration().getGptUseNew()); + this.textpane.setText(Messages.getString("P2T.loading")); + this.showLoadingAnimation(true); + webService = new WebServiceThreadLLM(this); + webService.start(); + while (!webService.getIsFinished()) { + try { + Thread.sleep(500); + } catch (InterruptedException e1) { + // ignore + } } + this.textpane.setText(""); + + if (naturalTextParser != null) this.textpane.setText(webService.getText()); } - this.textpane.setText(""); - if (naturalTextParser != null) this.textpane.setText(webService.getText()); + if(!ConfigurationManager.getConfiguration().getGptUseNew()){ + System.out.println(ConfigurationManager.getConfiguration().getGptUseNew()); + this.textpane.setText(Messages.getString("P2T.loading")); + this.showLoadingAnimation(true); + webServiceOld = new WebServiceThread(this); + webServiceOld.start(); + while (!webServiceOld.getIsFinished()) { + try{ + Thread.sleep(500); + }catch (InterruptedException e1){ + //ignore? + } + this.textpane.setText(""); + + if (naturalTextParser != null) this.textpane.setText(webServiceOld.getText()); + } + } setThreadInProgress(false); webService = null; diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java index f8d59c8fb..cd3087c61 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java @@ -27,16 +27,11 @@ public boolean getIsFinished() { return isFinished; } + public void run() { IEditor editor = paraphrasingPanel.getEditor(); paraphrasingPanel.showLoadingAnimation(true); - String url = - "http://" - + ConfigurationManager.getConfiguration().getProcess2TextServerHost() - + ":" - + ConfigurationManager.getConfiguration().getProcess2TextServerPort() - + ConfigurationManager.getConfiguration().getProcess2TextServerURI() - + "/generateText"; + String url ="http://localhost:8080/p2t/generateText"; String[] arg = {url, "P2T"}; ByteArrayOutputStream stream = new ByteArrayOutputStream(); @@ -47,11 +42,11 @@ public void run() { response = request.getResponse(); output = response.getBody(); output = output.replaceAll("\\s*\n\\s*", ""); + setText(output); isFinished = true; paraphrasingPanel.setNaturalTextParser(new Process2Text(output)); - switch (response.responseCode) { case HttpServletResponse.SC_NO_CONTENT: case HttpServletResponse.SC_REQUEST_TIMEOUT: @@ -80,5 +75,13 @@ public void run() { paraphrasingPanel.setThreadInProgress(false); } + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + } diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java index 32494d005..6d29ced38 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java @@ -54,7 +54,6 @@ public void run() { ByteArrayOutputStream stream = new ByteArrayOutputStream(); new PNMLExport().saveToStream(editor, stream); String text = stream.toString(); - System.out.println(text); String output; //TODO Diese logik in die Buttons implementieren!! @@ -89,12 +88,10 @@ public void run() { output = scanner.useDelimiter("\\A").next(); output = output.replaceAll("\\s*\n\\s*", ""); paraphrasingPanel.setNaturalTextParser(new Process2Text(output)); - System.out.println(output); setText(output); } } else { output = "Request failed. Response Code: " + responseCode; - System.out.println(output); } // Fehlerbehandlung basierend auf Response Code From dd883d2e9ecd03965afcb452d6bcbbc9cc859b30 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Thu, 13 Jun 2024 13:46:17 +0200 Subject: [PATCH 31/76] Old Service now works apart from localhost --- .../org/woped/qualanalysis/p2t/WebServiceThread.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java index cd3087c61..f92028b39 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java @@ -31,8 +31,13 @@ public boolean getIsFinished() { public void run() { IEditor editor = paraphrasingPanel.getEditor(); paraphrasingPanel.showLoadingAnimation(true); - String url ="http://localhost:8080/p2t/generateText"; - + String url = + "http://" + + ConfigurationManager.getConfiguration().getProcess2TextServerHost() + + ":" + + ConfigurationManager.getConfiguration().getProcess2TextServerPort() + + ConfigurationManager.getConfiguration().getProcess2TextServerURI() + + "/generateText"; String[] arg = {url, "P2T"}; ByteArrayOutputStream stream = new ByteArrayOutputStream(); new PNMLExport().saveToStream(editor, stream); @@ -42,6 +47,7 @@ public void run() { response = request.getResponse(); output = response.getBody(); output = output.replaceAll("\\s*\n\\s*", ""); + System.out.println(output); setText(output); isFinished = true; paraphrasingPanel.setNaturalTextParser(new Process2Text(output)); From dbe02f025415c79c5c8b538d0ad504748d6b7959 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Thu, 13 Jun 2024 13:52:37 +0200 Subject: [PATCH 32/76] Added API call from initial GUI Added API call from initial GUI from initial GUI if the popup isn't supposed to show again --- .../starter/controller/vep/GUIViewEventProcessor.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java b/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java index 95b219786..7b764e99e 100644 --- a/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java +++ b/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java @@ -41,6 +41,8 @@ import org.woped.core.model.petrinet.SubProcessModel; import org.woped.core.utilities.FileFilterImpl; import org.woped.core.utilities.LoggerManager; +import org.woped.editor.action.WoPeDAction; +import org.woped.editor.controller.ActionFactory; import org.woped.editor.controller.VisualController; import org.woped.editor.controller.vc.EditorVC; import org.woped.editor.controller.vc.SubprocessEditorVC; @@ -98,10 +100,16 @@ && getMediator().getUi().getComponent() instanceof JFrame) { if(!ConfigurationManager.getConfiguration().getGptShowAgain()){ if(ConfigurationManager.getConfiguration().getGptUseNew()){ System.out.println("neu"); + WoPeDAction action = ActionFactory.getStaticAction(ActionFactory.ACTIONID_P2T_OLD); + action.actionPerformed( + new ViewEvent(this, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.P2T, null)); //TODO: HIER NEUER API CALL } if(!ConfigurationManager.getConfiguration().getGptUseNew()){ System.out.println("alt"); + WoPeDAction action = ActionFactory.getStaticAction(ActionFactory.ACTIONID_P2T_OLD); + action.actionPerformed( + new ViewEvent(this, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.P2T, null)); //TODO: HIER ALTER API CALL } } From fa821cebb47879a9dea89e5ba77606eae8a5484d Mon Sep 17 00:00:00 2001 From: zbbhelen Date: Sat, 15 Jun 2024 12:38:25 +0200 Subject: [PATCH 33/76] Refactor Strings of P2TUI --- .../src/main/java/org/woped/file/p2t/P2TUI.java | 10 +++++----- WoPeD-GUI/src/main/resources/Messages.properties | 5 +++++ WoPeD-GUI/src/main/resources/Messages_de.properties | 5 +++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index fbbd85708..3e70b845b 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -42,7 +42,7 @@ public class P2TUI extends JDialog { private AbstractApplicationMediator m_mediator = null; JComboBox modelComboBox; - private static final String DEFAULT_PROMPT = "Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"; + private static final String DEFAULT_PROMPT = Messages.getString("P2T.prompt.default"); public P2TUI(AbstractApplicationMediator mediator) { this(null, mediator); @@ -136,13 +136,13 @@ private JPanel initializeSwitchButtonPanel() { }); // Add JComboBox - JLabel gptModelLabel = new JLabel("GPT-Model:"); + JLabel gptModelLabel = new JLabel(Messages.getString("P2T.gptModel.title")); gptModelLabel.setVisible(false); // Initially hidden modelComboBox = new JComboBox<>(); modelComboBox.setVisible(false); // Initially hidden showAgainCheckBox = new JCheckBox(Messages.getString("P2T.popup.show.again.title")); showAgainCheckBox.setSelected(ConfigurationManager.getConfiguration().getGptShowAgain()); - showAgainCheckBox.setToolTipText("Placeholder"); + showAgainCheckBox.setToolTipText(Messages.getString("P2T.popup.placeholder.title")); apiKeyLabel.setVisible(false); apiKeyField.setText(ConfigurationManager.getConfiguration().getGptApiKey()); apiKeyField.setVisible(false); @@ -307,8 +307,8 @@ private void fetchAndFillModels() { SwingUtilities.invokeLater(() -> { JOptionPane.showMessageDialog( this.initializeSwitchButtonPanel(), - "Failed to fetch models: " + e.getMessage(), - "Fetch Models", + Messages.getString("P2T.exception.fail.title") + e.getMessage(), + Messages.getString("P2T.exception.fetch.models.title"), JOptionPane.ERROR_MESSAGE); }); } diff --git a/WoPeD-GUI/src/main/resources/Messages.properties b/WoPeD-GUI/src/main/resources/Messages.properties index 65acb5854..dc1c25398 100644 --- a/WoPeD-GUI/src/main/resources/Messages.properties +++ b/WoPeD-GUI/src/main/resources/Messages.properties @@ -880,6 +880,11 @@ P2T.apikey.invalid.title = Validation Error P2T.prompt.title = Prompt P2T.prompt.checkbox.enable.title = Enable editing P2T.popup.show.again.title = Show again +P2T.popup.placeholder.title = Placeholder +P2T.prompt.default = Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece! +P2T.gptModel.title = GPT-Model: +P2T.exception.fail.title = Failed to fetch models: +P2T.exception.fetch.models.title = Fetch Models #************* ! Text2Process diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index 36ddd1c14..671822bf5 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -486,6 +486,11 @@ P2T.apikey.invalid.title = Validierungsfehler P2T.prompt.title = Prompt P2T.prompt.checkbox.enable.title = Bearbeitung aktivieren P2T.popup.show.again.title = Erneut anzeigen +P2T.popup.placeholder.title = Platzhalter +P2T.prompt.default = Erstellen Sie aus der vorgegebenen BPMN einen klar strukturierten und verständlichen Fließtext, der auch für einen unkundigen Leser verständlich ist. Der Text sollte in der Zusammenfassung gut lesbar sein und alle wichtigen Inhalte enthalten; falls es Unterpunkte gibt, werden diese mit geeigneten Satzanfängen in den Text integriert, um einen gut strukturierten und leicht lesbaren Text zu erhalten. Keinesfalls sollte die Ausgabe Unterpunkte oder Absätze enthalten, sondern alle Vorgänge in einem Stück abdecken! +P2T.gptModel.title = GPT-Model: +P2T.exception.fail.title = Modelle konnten nicht abgerufen werden: +P2T.exception.fetch.models.title = Modelle abrufen #************* ! Text 2 Process From 9cd9b59f3165f793f38066fb904d03852bd52a66 Mon Sep 17 00:00:00 2001 From: zbbhelen Date: Sat, 15 Jun 2024 13:29:47 +0200 Subject: [PATCH 34/76] Refactor Strings of ConfNLPToolsPanel --- .../editor/gui/config/ConfNLPToolsPanel.java | 16 ++++++++-------- WoPeD-GUI/src/main/resources/Messages.properties | 9 +++++++++ .../src/main/resources/Messages_de.properties | 8 +++++++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index 0203aea2c..9adebde11 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -354,7 +354,7 @@ private JPanel getGPTPanel() { c.weightx = 0; c.gridx = 0; c.gridy = 2; - additionalPanel.add(new JLabel("GPT-Model"), c); + additionalPanel.add(new JLabel(Messages.getString("Configuration.GPT.Model")), c); c.weightx = 1; c.gridx = 1; @@ -411,7 +411,7 @@ private JTextArea getPromptText() { promptText.setLineWrap(true); promptText.setWrapStyleWord(true); promptText.setEnabled(true); - promptText.setText("Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"); + promptText.setText(Messages.getString("Configuration.prompt.test")); } return promptText; } @@ -472,22 +472,22 @@ private void testGPTConnection() { String message; if (responseCode == 200) { - message = "GPT connection successful. Response Code: " + responseCode; + message = Messages.getString("Configuration.GPT.successful.connection.title") + responseCode; } else { - message = "GPT connection failed. Response Code: " + responseCode; + message = Messages.getString("Configuration.GPT.failed.connection.title") + responseCode; } JOptionPane.showMessageDialog( this.getGPTPanel(), message, - "Connection Test", + Messages.getString("Configuration.GPT.connection.test.title"), JOptionPane.INFORMATION_MESSAGE); } catch (IOException e) { JOptionPane.showMessageDialog( this.getGPTPanel(), - "GPT connection test failed: " + e.getMessage(), - "Connection Test", + Messages.getString("Configuration.GPT.connection.test.failed.title") + e.getMessage(), + Messages.getString("Configuration.GPT.connection.test.title"), JOptionPane.ERROR_MESSAGE); } } @@ -523,7 +523,7 @@ private JComboBox getModelComboBox() { if (modelComboBox == null) { modelComboBox = new JComboBox<>(); modelComboBox.setEnabled(true); - modelComboBox.setToolTipText("Select a model"); + modelComboBox.setToolTipText(Messages.getString("Configuration.P2T.get.model")); } return modelComboBox; } diff --git a/WoPeD-GUI/src/main/resources/Messages.properties b/WoPeD-GUI/src/main/resources/Messages.properties index dc1c25398..4bb1bbde3 100644 --- a/WoPeD-GUI/src/main/resources/Messages.properties +++ b/WoPeD-GUI/src/main/resources/Messages.properties @@ -1284,11 +1284,16 @@ Configuration.P2T.Label.ServerPort = Port Configuration.P2T.Label.ServerURI = URI Configuration.P2T.Label.Use = Enable NLP Tools Configuration.P2T.Settings.Panel.Title = Process2Text server settings +Configuration.P2T.get.model = Select a model Configuration.GPT.apikey.Title = API Key Configuration.GPT.prompt.Title = Prompt Configuration.GPT.show.again.Title = Show again Configuration.GPT.standard.Title = Reset to standard Configuration.GPT.connection.Title = Test connection +Configuration.GPT.successful.connection.title = GPT connection successful. Response Code: +Configuration.GPT.failed.connection.title = GPT connection failed. Response Code: +Configuration.GPT.connection.test.title = Connection Test +Configuration.GPT.connection.test.failed.title = GPT connection test failed: Configuration.T2P.Settings.Panel.Title = Text2Process server settings Configuration.T2P.Dialog.Restart.Title = Restart Configuration.T2P.Label.ServerHost = Server Host @@ -1311,6 +1316,10 @@ Configuration.YAWL.Panel.Export.ExplicitPlaces = Export *.y Configuration.YAWL.Panel.Export.ExplicitPlaces.ToolTip = All places in the petrinet will be exported to explicit conditions in YAWL Configuration.YAWL.Panel.Export.Groups = Export *.ybkp files with groups Configuration.YAWL.Panel.Export.Groups.ToolTip = All groups from the resource editor will be exported to OrgGroups in YAWL +Configuration.GPT.Model = GPT-Model +Configuration.prompt.test = Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece! + + #************* ! Transition #************* diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index 671822bf5..13ee726b2 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -821,6 +821,7 @@ Configuration.P2T.Label.ServerPort = Port Configuration.P2T.Label.ServerURI = URI Configuration.P2T.Label.Use = NLP Tools aktivieren Configuration.P2T.Settings.Panel.Title = Process2Text Servereinstellungen +Configuration.P2T.get.model = Wählen Sie ein Modell Configuration.T2P.Settings.Panel.Title = Text2Process Servereinstellungen Configuration.P2T.Title = NLP Tools Configuration.GPT.apikey.Title = API Schl\u00FCssel @@ -828,6 +829,10 @@ Configuration.GPT.prompt.Title = Prompt Configuration.GPT.show.again.Title = Erneut anzeigen Configuration.GPT.standard.Title = Auf Standard zur\u00FCcksetzen Configuration.GPT.connection.Title = Verbindung pr\u00FCfen +Configuration.GPT.successful.connection.title = GPT-Verbindung erfolgreich. Antwort-Code: +Configuration.GPT.failed.connection.title = GPT-Verbindung fehlgeschlagen. Antwort-Code: +Configuration.GPT.connection.test.title = Verbindungstest +Configuration.GPT.connection.test.failed.title = GPT-Verbindungstest fehlgeschlagen: Configuration.T2P.Dialog.Restart.Title = Neustart Configuration.T2P.Label.ServerHost = Server Host Configuration.T2P.Label.ServerPort = Port @@ -850,7 +855,8 @@ Configuration.YAWL.Panel.Export.ExplicitPlaces = *.yawl Dat Configuration.YAWL.Panel.Export.ExplicitPlaces.ToolTip = Alle Stellen im Petrinetz werden zu Conditions in YAWL exportiert Configuration.YAWL.Panel.Export.Groups = *.ybkp Dateien mit Gruppen exportieren Configuration.YAWL.Panel.Export.Groups.ToolTip = Alle Gruppen im Ressourcen Editor werden zu OrgGroups in YAWL exportiert - +Configuration.GPT.Model = GPT-Model +Configuration.prompt.test = Erstellen Sie aus der vorgegebenen BPMN einen klar strukturierten und verständlichen Fließtext, der auch für einen unkundigen Leser verständlich ist. Der Text sollte in der Zusammenfassung gut lesbar sein und alle wichtigen Inhalte enthalten; falls es Unterpunkte gibt, werden diese mit geeigneten Satzanfängen in den Text integriert, um einen gut strukturierten und leicht lesbaren Text zu erhalten. Keinesfalls sollte die Ausgabe Unterpunkte oder Absätze enthalten, sondern alle Vorgänge in einem Stück abdecken! #************* ! Exit-Config #************* From 122e563c3e0e7be946f1629ff3aed70d7377689e Mon Sep 17 00:00:00 2001 From: zbbhelen Date: Sat, 15 Jun 2024 13:39:30 +0200 Subject: [PATCH 35/76] Revert "Refactor Strings of P2TUI" This reverts commit fa821cebb47879a9dea89e5ba77606eae8a5484d. --- .../src/main/java/org/woped/file/p2t/P2TUI.java | 10 +++++----- WoPeD-GUI/src/main/resources/Messages.properties | 5 ----- WoPeD-GUI/src/main/resources/Messages_de.properties | 5 ----- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 3e70b845b..fbbd85708 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -42,7 +42,7 @@ public class P2TUI extends JDialog { private AbstractApplicationMediator m_mediator = null; JComboBox modelComboBox; - private static final String DEFAULT_PROMPT = Messages.getString("P2T.prompt.default"); + private static final String DEFAULT_PROMPT = "Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"; public P2TUI(AbstractApplicationMediator mediator) { this(null, mediator); @@ -136,13 +136,13 @@ private JPanel initializeSwitchButtonPanel() { }); // Add JComboBox - JLabel gptModelLabel = new JLabel(Messages.getString("P2T.gptModel.title")); + JLabel gptModelLabel = new JLabel("GPT-Model:"); gptModelLabel.setVisible(false); // Initially hidden modelComboBox = new JComboBox<>(); modelComboBox.setVisible(false); // Initially hidden showAgainCheckBox = new JCheckBox(Messages.getString("P2T.popup.show.again.title")); showAgainCheckBox.setSelected(ConfigurationManager.getConfiguration().getGptShowAgain()); - showAgainCheckBox.setToolTipText(Messages.getString("P2T.popup.placeholder.title")); + showAgainCheckBox.setToolTipText("Placeholder"); apiKeyLabel.setVisible(false); apiKeyField.setText(ConfigurationManager.getConfiguration().getGptApiKey()); apiKeyField.setVisible(false); @@ -307,8 +307,8 @@ private void fetchAndFillModels() { SwingUtilities.invokeLater(() -> { JOptionPane.showMessageDialog( this.initializeSwitchButtonPanel(), - Messages.getString("P2T.exception.fail.title") + e.getMessage(), - Messages.getString("P2T.exception.fetch.models.title"), + "Failed to fetch models: " + e.getMessage(), + "Fetch Models", JOptionPane.ERROR_MESSAGE); }); } diff --git a/WoPeD-GUI/src/main/resources/Messages.properties b/WoPeD-GUI/src/main/resources/Messages.properties index 4bb1bbde3..83c8d1cd5 100644 --- a/WoPeD-GUI/src/main/resources/Messages.properties +++ b/WoPeD-GUI/src/main/resources/Messages.properties @@ -880,11 +880,6 @@ P2T.apikey.invalid.title = Validation Error P2T.prompt.title = Prompt P2T.prompt.checkbox.enable.title = Enable editing P2T.popup.show.again.title = Show again -P2T.popup.placeholder.title = Placeholder -P2T.prompt.default = Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece! -P2T.gptModel.title = GPT-Model: -P2T.exception.fail.title = Failed to fetch models: -P2T.exception.fetch.models.title = Fetch Models #************* ! Text2Process diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index 13ee726b2..e2b926d41 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -486,11 +486,6 @@ P2T.apikey.invalid.title = Validierungsfehler P2T.prompt.title = Prompt P2T.prompt.checkbox.enable.title = Bearbeitung aktivieren P2T.popup.show.again.title = Erneut anzeigen -P2T.popup.placeholder.title = Platzhalter -P2T.prompt.default = Erstellen Sie aus der vorgegebenen BPMN einen klar strukturierten und verständlichen Fließtext, der auch für einen unkundigen Leser verständlich ist. Der Text sollte in der Zusammenfassung gut lesbar sein und alle wichtigen Inhalte enthalten; falls es Unterpunkte gibt, werden diese mit geeigneten Satzanfängen in den Text integriert, um einen gut strukturierten und leicht lesbaren Text zu erhalten. Keinesfalls sollte die Ausgabe Unterpunkte oder Absätze enthalten, sondern alle Vorgänge in einem Stück abdecken! -P2T.gptModel.title = GPT-Model: -P2T.exception.fail.title = Modelle konnten nicht abgerufen werden: -P2T.exception.fetch.models.title = Modelle abrufen #************* ! Text 2 Process From d484abef2d1d77797d1be84fa4826b5f1208f0bf Mon Sep 17 00:00:00 2001 From: zbbhelen Date: Sat, 15 Jun 2024 13:41:13 +0200 Subject: [PATCH 36/76] Revert "Refactor Strings of ConfNLPToolsPanel" This reverts commit 9cd9b59f3165f793f38066fb904d03852bd52a66. --- .../editor/gui/config/ConfNLPToolsPanel.java | 16 ++++++++-------- WoPeD-GUI/src/main/resources/Messages.properties | 9 --------- .../src/main/resources/Messages_de.properties | 8 +------- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index 9adebde11..0203aea2c 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -354,7 +354,7 @@ private JPanel getGPTPanel() { c.weightx = 0; c.gridx = 0; c.gridy = 2; - additionalPanel.add(new JLabel(Messages.getString("Configuration.GPT.Model")), c); + additionalPanel.add(new JLabel("GPT-Model"), c); c.weightx = 1; c.gridx = 1; @@ -411,7 +411,7 @@ private JTextArea getPromptText() { promptText.setLineWrap(true); promptText.setWrapStyleWord(true); promptText.setEnabled(true); - promptText.setText(Messages.getString("Configuration.prompt.test")); + promptText.setText("Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"); } return promptText; } @@ -472,22 +472,22 @@ private void testGPTConnection() { String message; if (responseCode == 200) { - message = Messages.getString("Configuration.GPT.successful.connection.title") + responseCode; + message = "GPT connection successful. Response Code: " + responseCode; } else { - message = Messages.getString("Configuration.GPT.failed.connection.title") + responseCode; + message = "GPT connection failed. Response Code: " + responseCode; } JOptionPane.showMessageDialog( this.getGPTPanel(), message, - Messages.getString("Configuration.GPT.connection.test.title"), + "Connection Test", JOptionPane.INFORMATION_MESSAGE); } catch (IOException e) { JOptionPane.showMessageDialog( this.getGPTPanel(), - Messages.getString("Configuration.GPT.connection.test.failed.title") + e.getMessage(), - Messages.getString("Configuration.GPT.connection.test.title"), + "GPT connection test failed: " + e.getMessage(), + "Connection Test", JOptionPane.ERROR_MESSAGE); } } @@ -523,7 +523,7 @@ private JComboBox getModelComboBox() { if (modelComboBox == null) { modelComboBox = new JComboBox<>(); modelComboBox.setEnabled(true); - modelComboBox.setToolTipText(Messages.getString("Configuration.P2T.get.model")); + modelComboBox.setToolTipText("Select a model"); } return modelComboBox; } diff --git a/WoPeD-GUI/src/main/resources/Messages.properties b/WoPeD-GUI/src/main/resources/Messages.properties index 83c8d1cd5..65acb5854 100644 --- a/WoPeD-GUI/src/main/resources/Messages.properties +++ b/WoPeD-GUI/src/main/resources/Messages.properties @@ -1279,16 +1279,11 @@ Configuration.P2T.Label.ServerPort = Port Configuration.P2T.Label.ServerURI = URI Configuration.P2T.Label.Use = Enable NLP Tools Configuration.P2T.Settings.Panel.Title = Process2Text server settings -Configuration.P2T.get.model = Select a model Configuration.GPT.apikey.Title = API Key Configuration.GPT.prompt.Title = Prompt Configuration.GPT.show.again.Title = Show again Configuration.GPT.standard.Title = Reset to standard Configuration.GPT.connection.Title = Test connection -Configuration.GPT.successful.connection.title = GPT connection successful. Response Code: -Configuration.GPT.failed.connection.title = GPT connection failed. Response Code: -Configuration.GPT.connection.test.title = Connection Test -Configuration.GPT.connection.test.failed.title = GPT connection test failed: Configuration.T2P.Settings.Panel.Title = Text2Process server settings Configuration.T2P.Dialog.Restart.Title = Restart Configuration.T2P.Label.ServerHost = Server Host @@ -1311,10 +1306,6 @@ Configuration.YAWL.Panel.Export.ExplicitPlaces = Export *.y Configuration.YAWL.Panel.Export.ExplicitPlaces.ToolTip = All places in the petrinet will be exported to explicit conditions in YAWL Configuration.YAWL.Panel.Export.Groups = Export *.ybkp files with groups Configuration.YAWL.Panel.Export.Groups.ToolTip = All groups from the resource editor will be exported to OrgGroups in YAWL -Configuration.GPT.Model = GPT-Model -Configuration.prompt.test = Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece! - - #************* ! Transition #************* diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index e2b926d41..36ddd1c14 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -816,7 +816,6 @@ Configuration.P2T.Label.ServerPort = Port Configuration.P2T.Label.ServerURI = URI Configuration.P2T.Label.Use = NLP Tools aktivieren Configuration.P2T.Settings.Panel.Title = Process2Text Servereinstellungen -Configuration.P2T.get.model = Wählen Sie ein Modell Configuration.T2P.Settings.Panel.Title = Text2Process Servereinstellungen Configuration.P2T.Title = NLP Tools Configuration.GPT.apikey.Title = API Schl\u00FCssel @@ -824,10 +823,6 @@ Configuration.GPT.prompt.Title = Prompt Configuration.GPT.show.again.Title = Erneut anzeigen Configuration.GPT.standard.Title = Auf Standard zur\u00FCcksetzen Configuration.GPT.connection.Title = Verbindung pr\u00FCfen -Configuration.GPT.successful.connection.title = GPT-Verbindung erfolgreich. Antwort-Code: -Configuration.GPT.failed.connection.title = GPT-Verbindung fehlgeschlagen. Antwort-Code: -Configuration.GPT.connection.test.title = Verbindungstest -Configuration.GPT.connection.test.failed.title = GPT-Verbindungstest fehlgeschlagen: Configuration.T2P.Dialog.Restart.Title = Neustart Configuration.T2P.Label.ServerHost = Server Host Configuration.T2P.Label.ServerPort = Port @@ -850,8 +845,7 @@ Configuration.YAWL.Panel.Export.ExplicitPlaces = *.yawl Dat Configuration.YAWL.Panel.Export.ExplicitPlaces.ToolTip = Alle Stellen im Petrinetz werden zu Conditions in YAWL exportiert Configuration.YAWL.Panel.Export.Groups = *.ybkp Dateien mit Gruppen exportieren Configuration.YAWL.Panel.Export.Groups.ToolTip = Alle Gruppen im Ressourcen Editor werden zu OrgGroups in YAWL exportiert -Configuration.GPT.Model = GPT-Model -Configuration.prompt.test = Erstellen Sie aus der vorgegebenen BPMN einen klar strukturierten und verständlichen Fließtext, der auch für einen unkundigen Leser verständlich ist. Der Text sollte in der Zusammenfassung gut lesbar sein und alle wichtigen Inhalte enthalten; falls es Unterpunkte gibt, werden diese mit geeigneten Satzanfängen in den Text integriert, um einen gut strukturierten und leicht lesbaren Text zu erhalten. Keinesfalls sollte die Ausgabe Unterpunkte oder Absätze enthalten, sondern alle Vorgänge in einem Stück abdecken! + #************* ! Exit-Config #************* From d7b5abec8e778123984ca33a508f0811b074bafc Mon Sep 17 00:00:00 2001 From: zbbhelen Date: Sat, 15 Jun 2024 15:41:49 +0200 Subject: [PATCH 37/76] add "json-simple" dependency for "ParseException" of P2TUI --- WoPeD-FileInterface/pom.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/WoPeD-FileInterface/pom.xml b/WoPeD-FileInterface/pom.xml index 3e0f5ee45..4e0bea0f4 100644 --- a/WoPeD-FileInterface/pom.xml +++ b/WoPeD-FileInterface/pom.xml @@ -114,7 +114,13 @@ WoPeD-QualAnalysis ${project.version} -
+ + com.googlecode.json-simple + json-simple + 1.1.1 + compile + +
From c5ad7c91df18744e17747a0c03fba8130efefee1 Mon Sep 17 00:00:00 2001 From: zbbhelen Date: Sat, 15 Jun 2024 16:13:52 +0200 Subject: [PATCH 38/76] Refactor Strings of P2TUI --- .../src/main/java/org/woped/file/p2t/P2TUI.java | 8 ++++---- WoPeD-GUI/src/main/resources/Messages.properties | 5 ++++- WoPeD-GUI/src/main/resources/Messages_de.properties | 5 ++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index fbbd85708..7f0148ec1 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -136,13 +136,13 @@ private JPanel initializeSwitchButtonPanel() { }); // Add JComboBox - JLabel gptModelLabel = new JLabel("GPT-Model:"); + JLabel gptModelLabel = new JLabel(Messages.getString("P2T.get.GPTmodel.title")); gptModelLabel.setVisible(false); // Initially hidden modelComboBox = new JComboBox<>(); modelComboBox.setVisible(false); // Initially hidden showAgainCheckBox = new JCheckBox(Messages.getString("P2T.popup.show.again.title")); showAgainCheckBox.setSelected(ConfigurationManager.getConfiguration().getGptShowAgain()); - showAgainCheckBox.setToolTipText("Placeholder"); + showAgainCheckBox.setToolTipText(Messages.getString("P2T.popup.tool.tip.text")); apiKeyLabel.setVisible(false); apiKeyField.setText(ConfigurationManager.getConfiguration().getGptApiKey()); apiKeyField.setVisible(false); @@ -307,8 +307,8 @@ private void fetchAndFillModels() { SwingUtilities.invokeLater(() -> { JOptionPane.showMessageDialog( this.initializeSwitchButtonPanel(), - "Failed to fetch models: " + e.getMessage(), - "Fetch Models", + Messages.getString("P2T.exception.fail.fetch.models") + e.getMessage(), + Messages.getString("P2T.exception.fetch.models"), JOptionPane.ERROR_MESSAGE); }); } diff --git a/WoPeD-GUI/src/main/resources/Messages.properties b/WoPeD-GUI/src/main/resources/Messages.properties index 65acb5854..656ca41e6 100644 --- a/WoPeD-GUI/src/main/resources/Messages.properties +++ b/WoPeD-GUI/src/main/resources/Messages.properties @@ -880,7 +880,10 @@ P2T.apikey.invalid.title = Validation Error P2T.prompt.title = Prompt P2T.prompt.checkbox.enable.title = Enable editing P2T.popup.show.again.title = Show again - +P2T.get.GPTmodel.title = GPT-Model: +P2T.popup.tool.tip.text = Placeholder +P2T.exception.fail.fetch.models = Failed to fetch models: +P2T.exception.fetch.models = Fetch Models #************* ! Text2Process #************* diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index 36ddd1c14..5720e7b47 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -486,7 +486,10 @@ P2T.apikey.invalid.title = Validierungsfehler P2T.prompt.title = Prompt P2T.prompt.checkbox.enable.title = Bearbeitung aktivieren P2T.popup.show.again.title = Erneut anzeigen - +P2T.get.GPTmodel.title = GPT-Model: +P2T.popup.tool.tip.text = Platzhalter +P2T.exception.fail.fetch.models = Modelle konnten nicht abgerufen werden: +P2T.exception.fetch.models = Modelle abrufen #************* ! Text 2 Process #************* From 7eb7d6b1c7be631b67f47165881388eb011bb199 Mon Sep 17 00:00:00 2001 From: zbbhelen Date: Sat, 15 Jun 2024 17:25:57 +0200 Subject: [PATCH 39/76] Refactor Strings of ConfNLPToolsPanel --- .../editor/gui/config/ConfNLPToolsPanel.java | 16 ++++++++-------- WoPeD-GUI/src/main/resources/Messages.properties | 10 ++++++++++ .../src/main/resources/Messages_de.properties | 10 ++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index 0203aea2c..74a805b0b 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -327,7 +327,7 @@ private JPanel getGPTPanel() { c.anchor = GridBagConstraints.WEST; c.insets = new Insets(2, 0, 2, 0); - additionalPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("GPT Settings"), BorderFactory.createEmptyBorder(10, 10, 10, 10))); + additionalPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Messages.getString("Configuration.GPT.settings.Title")), BorderFactory.createEmptyBorder(10, 10, 10, 10))); c.weightx = 1; c.gridx = 0; @@ -354,7 +354,7 @@ private JPanel getGPTPanel() { c.weightx = 0; c.gridx = 0; c.gridy = 2; - additionalPanel.add(new JLabel("GPT-Model"), c); + additionalPanel.add(new JLabel(Messages.getString("Configuration.GPT.model.Title")), c); c.weightx = 1; c.gridx = 1; @@ -420,7 +420,7 @@ private JCheckBox getShowAgainBox() { if (showAgainBox == null) { showAgainBox = new JCheckBox(Messages.getString("Configuration.GPT.show.again.Title")); showAgainBox.setEnabled(true); - showAgainBox.setToolTipText("Test"); + showAgainBox.setToolTipText(Messages.getString("Configuration.GPT.tool.tip.text.Title")); } return showAgainBox; } @@ -472,22 +472,22 @@ private void testGPTConnection() { String message; if (responseCode == 200) { - message = "GPT connection successful. Response Code: " + responseCode; + message = Messages.getString("Configuration.GPT.connection.successful.Title") + responseCode; } else { - message = "GPT connection failed. Response Code: " + responseCode; + message = Messages.getString("Configuration.GPT.connection.failed.Title") + responseCode; } JOptionPane.showMessageDialog( this.getGPTPanel(), message, - "Connection Test", + Messages.getString("Configuration.GPT.connection.test.Title"), JOptionPane.INFORMATION_MESSAGE); } catch (IOException e) { JOptionPane.showMessageDialog( this.getGPTPanel(), - "GPT connection test failed: " + e.getMessage(), - "Connection Test", + Messages.getString("Configuration.GPT.connection.test.failed.Title") + e.getMessage(), + Messages.getString("Configuration.GPT.connection.test.Title"), JOptionPane.ERROR_MESSAGE); } } diff --git a/WoPeD-GUI/src/main/resources/Messages.properties b/WoPeD-GUI/src/main/resources/Messages.properties index 656ca41e6..5bf3e7659 100644 --- a/WoPeD-GUI/src/main/resources/Messages.properties +++ b/WoPeD-GUI/src/main/resources/Messages.properties @@ -1287,6 +1287,16 @@ Configuration.GPT.prompt.Title = Prompt Configuration.GPT.show.again.Title = Show again Configuration.GPT.standard.Title = Reset to standard Configuration.GPT.connection.Title = Test connection +Configuration.GPT.settings.Title = GPT Settings +Configuration.GPT.model.Title = GPT-Model +Configuration.GPT.tool.tip.text.Title = Test +Configuration.GPT.connection.successful.Title = GPT connection successful. Response Code: +Configuration.GPT.connection.failed.Title = GPT connection failed. Response Code: +Configuration.GPT.connection.test.Title = Connection Test +Configuration.GPT.connection.test.failed.Title = GPT connection test failed: + + + Configuration.T2P.Settings.Panel.Title = Text2Process server settings Configuration.T2P.Dialog.Restart.Title = Restart Configuration.T2P.Label.ServerHost = Server Host diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index 5720e7b47..521f8d60b 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -826,6 +826,16 @@ Configuration.GPT.prompt.Title = Prompt Configuration.GPT.show.again.Title = Erneut anzeigen Configuration.GPT.standard.Title = Auf Standard zur\u00FCcksetzen Configuration.GPT.connection.Title = Verbindung pr\u00FCfen +Configuration.GPT.settings.Title = GPT Einstellung +Configuration.GPT.model.Title = GPT-Model +Configuration.GPT.tool.tip.text.Title = Test +Configuration.GPT.connection.successful.Title = GPT-Verbindung erfolgreich. Antwort-Code: +Configuration.GPT.connection.failed.Title = GPT-Verbindung fehlgeschlagen. Antwort-Code: +Configuration.GPT.connection.test.Title = Verbindung Test +Configuration.GPT.connection.test.failed.Title = GPT-Verbindungstest fehlgeschlagen: + + + Configuration.T2P.Dialog.Restart.Title = Neustart Configuration.T2P.Label.ServerHost = Server Host Configuration.T2P.Label.ServerPort = Port From e90835e732707d6fecd13047f5c686e8fb221ee8 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Mon, 17 Jun 2024 09:22:28 +0200 Subject: [PATCH 40/76] Cleanup, formatting --- .../main/java/org/woped/file/p2t/P2TUI.java | 14 +- .../controller/vep/GUIViewEventProcessor.java | 730 +++++++++--------- 2 files changed, 369 insertions(+), 375 deletions(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 7f0148ec1..fdf991b76 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -161,8 +161,8 @@ private JPanel initializeSwitchButtonPanel() { enablePromptCheckBox.setVisible(true); gptModelLabel.setVisible(true); modelComboBox.setVisible(true); - for (int i = 0; i < modelComboBox.getItemCount(); i++){ - if(modelComboBox.getItemAt(i).equals(ConfigurationManager.getConfiguration().getGptModel())){ + for (int i = 0; i < modelComboBox.getItemCount(); i++) { + if (modelComboBox.getItemAt(i).equals(ConfigurationManager.getConfiguration().getGptModel())) { modelComboBox.setSelectedIndex(i); break; } @@ -287,10 +287,10 @@ private JPanel initializeSingleButtonPanel() { }); return buttonPanel; } + private void executeAction() { WoPeDAction action = ActionFactory.getStaticAction(ActionFactory.ACTIONID_P2T_OLD); - action.actionPerformed( - new ViewEvent(this, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.P2T, null)); + action.actionPerformed(new ViewEvent(this, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.P2T, null)); } @@ -305,11 +305,7 @@ private void fetchAndFillModels() { }); } catch (IOException | ParseException e) { SwingUtilities.invokeLater(() -> { - JOptionPane.showMessageDialog( - this.initializeSwitchButtonPanel(), - Messages.getString("P2T.exception.fail.fetch.models") + e.getMessage(), - Messages.getString("P2T.exception.fetch.models"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(this.initializeSwitchButtonPanel(), Messages.getString("P2T.exception.fail.fetch.models") + e.getMessage(), Messages.getString("P2T.exception.fetch.models"), JOptionPane.ERROR_MESSAGE); }); } }).start(); diff --git a/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java b/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java index 7b764e99e..5c873d271 100644 --- a/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java +++ b/WoPeD-Starter/src/main/java/org/woped/starter/controller/vep/GUIViewEventProcessor.java @@ -30,6 +30,7 @@ import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JOptionPane; + import org.woped.core.config.ConfigurationManager; import org.woped.core.controller.AbstractEventProcessor; import org.woped.core.controller.AbstractViewEvent; @@ -63,389 +64,386 @@ * @author Simon Landes
*/ public class GUIViewEventProcessor extends AbstractEventProcessor { - public GUIViewEventProcessor(DefaultApplicationMediator mediator) { - super(mediator); - } - - public void processViewEvent(AbstractViewEvent event) { - IEditor editor; - if (event.getSource() instanceof EditorVC) { - editor = (EditorVC) event.getSource(); - } else { - editor = getMediator().getUi().getEditorFocus(); + public GUIViewEventProcessor(DefaultApplicationMediator mediator) { + super(mediator); } - switch (event.getOrder()) { - case AbstractViewEvent.T2P: - T2PUI t2p; - if (getMediator().getUi() != null - && getMediator().getUi().getComponent() instanceof JFrame) { - t2p = new T2PUI((JFrame) getMediator().getUi(), getMediator()); - } else { - t2p = new T2PUI(getMediator()); - } - t2p.setVisible(true); - break; - case AbstractViewEvent.P2T: - P2TUI p2t; - if (getMediator().getUi() != null - && getMediator().getUi().getComponent() instanceof JFrame) { - { - p2t = new P2TUI((JFrame) getMediator().getUi(), getMediator());} - } else { - p2t = new P2TUI(getMediator()); - } - if(ConfigurationManager.getConfiguration().getGptShowAgain()){ - p2t.setVisible(true); - } - if(!ConfigurationManager.getConfiguration().getGptShowAgain()){ - if(ConfigurationManager.getConfiguration().getGptUseNew()){ - System.out.println("neu"); - WoPeDAction action = ActionFactory.getStaticAction(ActionFactory.ACTIONID_P2T_OLD); - action.actionPerformed( - new ViewEvent(this, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.P2T, null)); - //TODO: HIER NEUER API CALL - } - if(!ConfigurationManager.getConfiguration().getGptUseNew()){ - System.out.println("alt"); - WoPeDAction action = ActionFactory.getStaticAction(ActionFactory.ACTIONID_P2T_OLD); - action.actionPerformed( - new ViewEvent(this, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.P2T, null)); - //TODO: HIER ALTER API CALL - } - } - break; - case AbstractViewEvent.NEW: - getMediator().createEditor(true); - break; - case AbstractViewEvent.OPEN_SUBPROCESS: + + public void processViewEvent(AbstractViewEvent event) { + IEditor editor; if (event.getSource() instanceof EditorVC) { - editor = (EditorVC) event.getSource(); + editor = (EditorVC) event.getSource(); } else { - editor = getMediator().getUi().getEditorFocus(); - } - Object cell = editor.getGraph().getSelectionCell(); - if (cell instanceof GroupModel) { - - cell = ((GroupModel) cell).getMainElement(); - if (cell instanceof SubProcessModel) { - SubProcessModel model = (SubProcessModel) cell; - - IEditor subEditor = getMediator().createSubprocessEditor(true, editor, model); - // rotate of sub process like main process - if (editor.isRotateSelected() != model.getDirection()) { - subEditor.rotateLayout(); - model.setDirection(editor.isRotateSelected()); - } - } + editor = getMediator().getUi().getEditorFocus(); } - break; + switch (event.getOrder()) { + case AbstractViewEvent.T2P: + T2PUI t2p; + if (getMediator().getUi() != null + && getMediator().getUi().getComponent() instanceof JFrame) { + t2p = new T2PUI((JFrame) getMediator().getUi(), getMediator()); + } else { + t2p = new T2PUI(getMediator()); + } + t2p.setVisible(true); + break; + case AbstractViewEvent.P2T: + P2TUI p2t; + if (getMediator().getUi() != null + && getMediator().getUi().getComponent() instanceof JFrame) { + { + p2t = new P2TUI((JFrame) getMediator().getUi(), getMediator()); + } + } else { + p2t = new P2TUI(getMediator()); + } + if (ConfigurationManager.getConfiguration().getGptShowAgain()) { + p2t.setVisible(true); + } + if (!ConfigurationManager.getConfiguration().getGptShowAgain()) { + if (ConfigurationManager.getConfiguration().getGptUseNew()) { + WoPeDAction action = ActionFactory.getStaticAction(ActionFactory.ACTIONID_P2T_OLD); + action.actionPerformed( + new ViewEvent(this, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.P2T, null)); + } + if (!ConfigurationManager.getConfiguration().getGptUseNew()) { + WoPeDAction action = ActionFactory.getStaticAction(ActionFactory.ACTIONID_P2T_OLD); + action.actionPerformed( + new ViewEvent(this, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.P2T, null)); + } + } + break; + case AbstractViewEvent.NEW: + getMediator().createEditor(true); + break; + case AbstractViewEvent.OPEN_SUBPROCESS: + if (event.getSource() instanceof EditorVC) { + editor = (EditorVC) event.getSource(); + } else { + editor = getMediator().getUi().getEditorFocus(); + } + Object cell = editor.getGraph().getSelectionCell(); + if (cell instanceof GroupModel) { - case AbstractViewEvent.SELECT_EDITOR: - selectEditor(editor); - break; + cell = ((GroupModel) cell).getMainElement(); + if (cell instanceof SubProcessModel) { + SubProcessModel model = (SubProcessModel) cell; - case AbstractViewEvent.INCONIFY_EDITOR: - getMediator().getUi().hideEditor(editor); - VisualController.getInstance() - .propertyChange(new PropertyChangeEvent(this, "InternalFrameCount", null, editor)); - break; - case AbstractViewEvent.CLOSE: - closeEditor(editor); - break; - case AbstractViewEvent.ABOUT: - AboutUI about; - if (getMediator().getUi() != null - && getMediator().getUi().getComponent() instanceof JFrame) { - about = new AboutUI((JFrame) getMediator().getUi()); - } else { - about = new AboutUI(); - } - about.setVisible(true); - break; - - case AbstractViewEvent.BUGREPORT: - BugReportUI bugReport; - if (getMediator().getUi() != null - && getMediator().getUi().getComponent() instanceof JFrame) { - bugReport = new BugReportUI((JFrame) getMediator().getUi()); - } else { - bugReport = new BugReportUI(); - } - bugReport.setVisible(true); - break; - - case AbstractViewEvent.HELP: - try { - showHelpPage((String) event.getData()); - } catch (Exception e) { - LoggerManager.error( - Constants.GUI_LOGGER, - "Cannot find HTML manual files in " + event.getData() + "." + e.getMessage()); - JOptionPane.showMessageDialog( - getMediator().getUi().getComponent(), - Messages.getString("Help.Message.HTMLManualFileNotFound") + " in " + event.getData(), - Messages.getString("Help.Message.notFound"), - JOptionPane.ERROR_MESSAGE); - } - break; - case AbstractViewEvent.HELP_CONTENTS: - try { - showHelpContents(); - } catch (Exception e) { - LoggerManager.error( - Constants.GUI_LOGGER, "Cannot find HTML contents file. " + e.getMessage()); - JOptionPane.showMessageDialog( - getMediator().getUi().getComponent(), - Messages.getString("Help.Message.HTMLManualFileNotFound"), - Messages.getString("Help.Message.notFound"), - JOptionPane.ERROR_MESSAGE); + IEditor subEditor = getMediator().createSubprocessEditor(true, editor, model); + // rotate of sub process like main process + if (editor.isRotateSelected() != model.getDirection()) { + subEditor.rotateLayout(); + model.setDirection(editor.isRotateSelected()); + } + } + } + break; + + case AbstractViewEvent.SELECT_EDITOR: + selectEditor(editor); + break; + + case AbstractViewEvent.INCONIFY_EDITOR: + getMediator().getUi().hideEditor(editor); + VisualController.getInstance() + .propertyChange(new PropertyChangeEvent(this, "InternalFrameCount", null, editor)); + break; + case AbstractViewEvent.CLOSE: + closeEditor(editor); + break; + case AbstractViewEvent.ABOUT: + AboutUI about; + if (getMediator().getUi() != null + && getMediator().getUi().getComponent() instanceof JFrame) { + about = new AboutUI((JFrame) getMediator().getUi()); + } else { + about = new AboutUI(); + } + about.setVisible(true); + break; + + case AbstractViewEvent.BUGREPORT: + BugReportUI bugReport; + if (getMediator().getUi() != null + && getMediator().getUi().getComponent() instanceof JFrame) { + bugReport = new BugReportUI((JFrame) getMediator().getUi()); + } else { + bugReport = new BugReportUI(); + } + bugReport.setVisible(true); + break; + + case AbstractViewEvent.HELP: + try { + showHelpPage((String) event.getData()); + } catch (Exception e) { + LoggerManager.error( + Constants.GUI_LOGGER, + "Cannot find HTML manual files in " + event.getData() + "." + e.getMessage()); + JOptionPane.showMessageDialog( + getMediator().getUi().getComponent(), + Messages.getString("Help.Message.HTMLManualFileNotFound") + " in " + event.getData(), + Messages.getString("Help.Message.notFound"), + JOptionPane.ERROR_MESSAGE); + } + break; + case AbstractViewEvent.HELP_CONTENTS: + try { + showHelpContents(); + } catch (Exception e) { + LoggerManager.error( + Constants.GUI_LOGGER, "Cannot find HTML contents file. " + e.getMessage()); + JOptionPane.showMessageDialog( + getMediator().getUi().getComponent(), + Messages.getString("Help.Message.HTMLManualFileNotFound"), + Messages.getString("Help.Message.notFound"), + JOptionPane.ERROR_MESSAGE); + } + break; + + case AbstractViewEvent.UPDATE: + break; + case AbstractViewEvent.EXIT: + quit(); + break; + case AbstractViewEvent.ZOOMED: + break; + case AbstractViewEvent.FACEBOOK: + new LaunchDefaultBrowserAction(Messages.getString("Community.Facebook.link"), null) + .displayURL(); + break; + case AbstractViewEvent.TWITTER: + new LaunchDefaultBrowserAction(Messages.getString("Community.Twitter.link"), null) + .displayURL(); + break; + case AbstractViewEvent.GOOGLEPLUS: + //noinspection SpellCheckingInspection + new LaunchDefaultBrowserAction(Messages.getString("Community.Googleplus.link"), null) + .displayURL(); + break; + case AbstractViewEvent.COMMUNITY: + new LaunchDefaultBrowserAction(Messages.getString("Community.Community.link"), null) + .displayURL(); + break; + case AbstractViewEvent.REGISTER: + new RegistrationUI((JFrame) getMediator().getUi(), false); + break; } - break; - - case AbstractViewEvent.UPDATE: - break; - case AbstractViewEvent.EXIT: - quit(); - break; - case AbstractViewEvent.ZOOMED: - break; - case AbstractViewEvent.FACEBOOK: - new LaunchDefaultBrowserAction(Messages.getString("Community.Facebook.link"), null) - .displayURL(); - break; - case AbstractViewEvent.TWITTER: - new LaunchDefaultBrowserAction(Messages.getString("Community.Twitter.link"), null) - .displayURL(); - break; - case AbstractViewEvent.GOOGLEPLUS: - //noinspection SpellCheckingInspection - new LaunchDefaultBrowserAction(Messages.getString("Community.Googleplus.link"), null) - .displayURL(); - break; - case AbstractViewEvent.COMMUNITY: - new LaunchDefaultBrowserAction(Messages.getString("Community.Community.link"), null) - .displayURL(); - break; - case AbstractViewEvent.REGISTER: - new RegistrationUI((JFrame) getMediator().getUi(), false); - break; - } - } - - private void quit() { - Vector editorList = new Vector<>(getMediator().getUi().getAllEditors()); - boolean canceled = false; - for (IEditor editor : editorList) { - processViewEvent( - new ViewEvent(editor, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.CLOSE)); - if (getMediator().getUi().getAllEditors().contains(editor)) { - canceled = true; - break; - } - } - if (!canceled) { - // If window is maximized don't store the current size, since that - // would lead to strange results when later leaving the maximised state - // such as too large windows and negative positions - ConfigurationManager.getConfiguration() - .setMaximizeWindow(getMediator().getUi().isMaximized()); - if (!getMediator().getUi().isMaximized()) { - ConfigurationManager.getConfiguration().setWindowX(getMediator().getUi().getX()); - ConfigurationManager.getConfiguration().setWindowY(getMediator().getUi().getY()); - ConfigurationManager.getConfiguration().setWindowSize(getMediator().getUi().getSize()); - } - ConfigurationManager.getConfiguration().saveConfig(); - try { - LoggerManager.info(Constants.GUI_LOGGER, "EXIT WoPeD"); - System.exit(0); - } catch (AccessControlException ace) { - getMediator().getUi().setVisible(false); - } - } else { - LoggerManager.debug(Constants.GUI_LOGGER, "User has canceled quit-operation."); } - } - - private void selectEditor(IEditor editor) { - ((EditorVC) editor).getEditorPanel().getContainer().setVisible(true); - if (((EditorVC) editor).getEditorPanel().getContainer() instanceof JInternalFrame) { - try { - ((JInternalFrame) ((EditorVC) editor).getEditorPanel().getContainer()).setIcon(false); - } catch (PropertyVetoException e) { - //noinspection SpellCheckingInspection - LoggerManager.warn(Constants.GUI_LOGGER, "Could not deiconify the editor"); - } - } - VisualController.getInstance() - .propertyChange(new PropertyChangeEvent(this, "FrameSelection", null, editor)); - // notify the editor aware vc - for (Object o : getMediator().getEditorAwareVCs()) { - ((IEditorAware) o).selectEditor(editor); - } - } - - /** - * Close the Editor... will start the the save procedure if necessary. - * - * @param editor the editor to close - * @return returns if editor could be close or not. - */ - private boolean closeEditor(IEditor editor) { - boolean closeEditor = false; - if (editor instanceof EditorVC) { - EditorVC editorVC = (EditorVC) editor; - if ((editor instanceof SubprocessEditorVC) && !editorVC.isTokenGameEnabled()) { - - @SuppressWarnings("SpellCheckingInspection") - IQualanalysisService qualanService = - QualAnalysisServiceFactory.createNewQualAnalysisService(editor); - - String inputID = ((SubprocessEditorVC) editor).getSubprocessInput().getId(); - String outputID = editor.getId(); - - // Try to get the first source place of the model as well as the - // first sink place - // Note that there is a chance neither a source nor a sink actually exist - // so we need to check whether the iterator is valid!! - String ainputID = null; - String aoutputID = null; - Iterator i = qualanService.getSinkPlaces().iterator(); - if (i.hasNext()) { - ainputID = i.next().getId(); + + private void quit() { + Vector editorList = new Vector<>(getMediator().getUi().getAllEditors()); + boolean canceled = false; + for (IEditor editor : editorList) { + processViewEvent( + new ViewEvent(editor, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.CLOSE)); + if (getMediator().getUi().getAllEditors().contains(editor)) { + canceled = true; + break; + } } - i = qualanService.getSourcePlaces().iterator(); - if (i.hasNext()) aoutputID = i.next().getId(); - - if (qualanService.getNotStronglyConnectedNodes().size() > 0 - || qualanService.getSinkPlaces().size() > 1 - || qualanService.getSourcePlaces().size() > 1 - || inputID.equals(ainputID) - || outputID.equals(aoutputID)) { - String errorMessage = - Messages.getString( - "Action.CloseSubProcessEditor.StructuralAnalysisResult.Message.Start"); - - if (qualanService.getNotStronglyConnectedNodes().size() > 0) { - errorMessage += - Messages.getString( - "Action.CloseSubProcessEditor.StructuralAnalysisResult.Message.StronglyConnected"); - } - if (qualanService.getSourcePlaces().size() > 1) { - errorMessage += - Messages.getString( - "Action.CloseSubProcessEditor.StructuralAnalysisResult.Message.Source"); - } else { - if (inputID.equals(ainputID)) { - errorMessage += - Messages.getString( - "Action.CloseSubProcessEditor.StructuralAnalysisResult.Message.Input"); + if (!canceled) { + // If window is maximized don't store the current size, since that + // would lead to strange results when later leaving the maximised state + // such as too large windows and negative positions + ConfigurationManager.getConfiguration() + .setMaximizeWindow(getMediator().getUi().isMaximized()); + if (!getMediator().getUi().isMaximized()) { + ConfigurationManager.getConfiguration().setWindowX(getMediator().getUi().getX()); + ConfigurationManager.getConfiguration().setWindowY(getMediator().getUi().getY()); + ConfigurationManager.getConfiguration().setWindowSize(getMediator().getUi().getSize()); } - } - - if (qualanService.getSinkPlaces().size() > 1) { - errorMessage += - Messages.getString( - "Action.CloseSubProcessEditor.StructuralAnalysisResult.Message.Sink"); - } else { - if (outputID.equals(aoutputID)) { - errorMessage += - Messages.getString( - "Action.CloseSubProcessEditor.StructuralAnalysisResult.Message.Output"); + ConfigurationManager.getConfiguration().saveConfig(); + try { + LoggerManager.info(Constants.GUI_LOGGER, "EXIT WoPeD"); + System.exit(0); + } catch (AccessControlException ace) { + getMediator().getUi().setVisible(false); } - } - - errorMessage += - Messages.getString( - "Action.CloseSubProcessEditor.StructuralAnalysisResult.Message.End"); - - String textMessages[] = { - Messages.getString("Dialog.Yes"), Messages.getString("Dialog.No") - }; - - int value = - JOptionPane.showOptionDialog( - editorVC.getEditorPanel(), - errorMessage, - Messages.getString("Action.CloseSubProcessEditor.StructuralAnalysisResult.Title"), - JOptionPane.YES_NO_OPTION, - JOptionPane.WARNING_MESSAGE, - null, - textMessages, - textMessages[0]); - - if (value == JOptionPane.YES_OPTION) { - closeEditor = true; - } - } else { - closeEditor = true; + LoggerManager.debug(Constants.GUI_LOGGER, "User has canceled quit-operation."); + } + } + + private void selectEditor(IEditor editor) { + ((EditorVC) editor).getEditorPanel().getContainer().setVisible(true); + if (((EditorVC) editor).getEditorPanel().getContainer() instanceof JInternalFrame) { + try { + ((JInternalFrame) ((EditorVC) editor).getEditorPanel().getContainer()).setIcon(false); + } catch (PropertyVetoException e) { + //noinspection SpellCheckingInspection + LoggerManager.warn(Constants.GUI_LOGGER, "Could not deiconify the editor"); + } } - } else if (editorVC.isSubprocessEditor() && editorVC.isTokenGameEnabled()) { - closeEditor = true; - } else { - if (!editorVC.isSaved()) { - // Check sample net - if (editorVC.getDefaultFileType() != FileFilterImpl.SAMPLEFilter) { - String args[] = {editorVC.getName()}; - - String textMessages[] = { - Messages.getString("Dialog.Yes"), - Messages.getString("Dialog.No"), - Messages.getString("Dialog.Cancel") - }; - - int value = - JOptionPane.showOptionDialog( - editorVC.getEditorPanel(), - Messages.getStringReplaced("Action.Confirm.File.Save.Text", args), - Messages.getString("Action.Confirm.File.Save.Title"), - JOptionPane.YES_NO_CANCEL_OPTION, - JOptionPane.ERROR_MESSAGE, - null, - textMessages, - textMessages[0]); - - if (value == (JOptionPane.YES_OPTION)) { - // try to save - getMediator() - .processViewEvent( - new ViewEvent( - editor, AbstractViewEvent.VIEWEVENTTYPE_FILE, AbstractViewEvent.SAVE)); - closeEditor = editorVC.isSaved(); - } else if (value == JOptionPane.NO_OPTION) { - closeEditor = true; - } else if (value == JOptionPane.CANCEL_OPTION) { - closeEditor = false; + VisualController.getInstance() + .propertyChange(new PropertyChangeEvent(this, "FrameSelection", null, editor)); + // notify the editor aware vc + for (Object o : getMediator().getEditorAwareVCs()) { + ((IEditorAware) o).selectEditor(editor); + } + } + + /** + * Close the Editor... will start the the save procedure if necessary. + * + * @param editor the editor to close + * @return returns if editor could be close or not. + */ + private boolean closeEditor(IEditor editor) { + boolean closeEditor = false; + if (editor instanceof EditorVC) { + EditorVC editorVC = (EditorVC) editor; + if ((editor instanceof SubprocessEditorVC) && !editorVC.isTokenGameEnabled()) { + + @SuppressWarnings("SpellCheckingInspection") + IQualanalysisService qualanService = + QualAnalysisServiceFactory.createNewQualAnalysisService(editor); + + String inputID = ((SubprocessEditorVC) editor).getSubprocessInput().getId(); + String outputID = editor.getId(); + + // Try to get the first source place of the model as well as the + // first sink place + // Note that there is a chance neither a source nor a sink actually exist + // so we need to check whether the iterator is valid!! + String ainputID = null; + String aoutputID = null; + Iterator i = qualanService.getSinkPlaces().iterator(); + if (i.hasNext()) { + ainputID = i.next().getId(); + } + i = qualanService.getSourcePlaces().iterator(); + if (i.hasNext()) aoutputID = i.next().getId(); + + if (qualanService.getNotStronglyConnectedNodes().size() > 0 + || qualanService.getSinkPlaces().size() > 1 + || qualanService.getSourcePlaces().size() > 1 + || inputID.equals(ainputID) + || outputID.equals(aoutputID)) { + String errorMessage = + Messages.getString( + "Action.CloseSubProcessEditor.StructuralAnalysisResult.Message.Start"); + + if (qualanService.getNotStronglyConnectedNodes().size() > 0) { + errorMessage += + Messages.getString( + "Action.CloseSubProcessEditor.StructuralAnalysisResult.Message.StronglyConnected"); + } + if (qualanService.getSourcePlaces().size() > 1) { + errorMessage += + Messages.getString( + "Action.CloseSubProcessEditor.StructuralAnalysisResult.Message.Source"); + } else { + if (inputID.equals(ainputID)) { + errorMessage += + Messages.getString( + "Action.CloseSubProcessEditor.StructuralAnalysisResult.Message.Input"); + } + } + + if (qualanService.getSinkPlaces().size() > 1) { + errorMessage += + Messages.getString( + "Action.CloseSubProcessEditor.StructuralAnalysisResult.Message.Sink"); + } else { + if (outputID.equals(aoutputID)) { + errorMessage += + Messages.getString( + "Action.CloseSubProcessEditor.StructuralAnalysisResult.Message.Output"); + } + } + + errorMessage += + Messages.getString( + "Action.CloseSubProcessEditor.StructuralAnalysisResult.Message.End"); + + String textMessages[] = { + Messages.getString("Dialog.Yes"), Messages.getString("Dialog.No") + }; + + int value = + JOptionPane.showOptionDialog( + editorVC.getEditorPanel(), + errorMessage, + Messages.getString("Action.CloseSubProcessEditor.StructuralAnalysisResult.Title"), + JOptionPane.YES_NO_OPTION, + JOptionPane.WARNING_MESSAGE, + null, + textMessages, + textMessages[0]); + + if (value == JOptionPane.YES_OPTION) { + closeEditor = true; + } + + } else { + closeEditor = true; + } + } else if (editorVC.isSubprocessEditor() && editorVC.isTokenGameEnabled()) { + closeEditor = true; + } else { + if (!editorVC.isSaved()) { + // Check sample net + if (editorVC.getDefaultFileType() != FileFilterImpl.SAMPLEFilter) { + String args[] = {editorVC.getName()}; + + String textMessages[] = { + Messages.getString("Dialog.Yes"), + Messages.getString("Dialog.No"), + Messages.getString("Dialog.Cancel") + }; + + int value = + JOptionPane.showOptionDialog( + editorVC.getEditorPanel(), + Messages.getStringReplaced("Action.Confirm.File.Save.Text", args), + Messages.getString("Action.Confirm.File.Save.Title"), + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.ERROR_MESSAGE, + null, + textMessages, + textMessages[0]); + + if (value == (JOptionPane.YES_OPTION)) { + // try to save + getMediator() + .processViewEvent( + new ViewEvent( + editor, AbstractViewEvent.VIEWEVENTTYPE_FILE, AbstractViewEvent.SAVE)); + closeEditor = editorVC.isSaved(); + } else if (value == JOptionPane.NO_OPTION) { + closeEditor = true; + } else if (value == JOptionPane.CANCEL_OPTION) { + closeEditor = false; + } + + } else { + closeEditor = true; + } + } else { + closeEditor = true; + } } + } - } else { - closeEditor = true; - } - } else { - closeEditor = true; + if (closeEditor) { + getMediator().removeViewController(editor); + // notify the editor aware vc + for (Object o : getMediator().getEditorAwareVCs()) { + ((IEditorAware) o).removeEditor(editor); + } + VisualController.getInstance() + .propertyChange(new PropertyChangeEvent(this, "InternalFrameCount", null, editor)); } - } + return closeEditor; + } + + private void showHelpPage(String fileName) throws Exception { + HelpBrowser br = HelpBrowser.getInstance(); + br.showURL(fileName); } - if (closeEditor) { - getMediator().removeViewController(editor); - // notify the editor aware vc - for (Object o : getMediator().getEditorAwareVCs()) { - ((IEditorAware) o).removeEditor(editor); - } - VisualController.getInstance() - .propertyChange(new PropertyChangeEvent(this, "InternalFrameCount", null, editor)); + private void showHelpContents() throws Exception { + HelpBrowser br = HelpBrowser.getInstance(); + br.showURL(Messages.getString("Help.File.Contents")); } - return closeEditor; - } - - private void showHelpPage(String fileName) throws Exception { - HelpBrowser br = HelpBrowser.getInstance(); - br.showURL(fileName); - } - - private void showHelpContents() throws Exception { - HelpBrowser br = HelpBrowser.getInstance(); - br.showURL(Messages.getString("Help.File.Contents")); - } } From 014df70dec0cb9cc87dbdbff9c40c0ed69d0f5c6 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Mon, 17 Jun 2024 12:53:29 +0200 Subject: [PATCH 41/76] made sure that settings dont crash if service isn't available made sure that settings dont crash if service isn't available --- .../editor/gui/config/ConfNLPToolsPanel.java | 10 ++++------ .../org/woped/qualanalysis/p2t/P2TSideBar.java | 15 +++++++-------- .../org/woped/qualanalysis/p2t/Process2Text.java | 2 +- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index 74a805b0b..9cc05fcec 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -13,10 +13,10 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; +import java.util.Arrays; import java.util.List; import javax.swing.*; -import com.sun.codemodel.JCatchBlock; import org.json.simple.parser.ParseException; import org.woped.core.config.ConfigurationManager; import org.woped.editor.tools.ApiHelper; @@ -54,14 +54,12 @@ public class ConfNLPToolsPanel extends AbstractConfPanel { private WopedButton resetButton = null; private JTextArea promptText = null; private WopedButton checkConnectionButton = null; - List models; + List models = Arrays.asList("") ; { try { models = ApiHelper.fetchModels(); - } catch (IOException e) { - throw new RuntimeException(e); - } catch (ParseException e) { - throw new RuntimeException(e); + } catch (IOException | ParseException ignored) { + } } diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java index 25eb5d06d..2f766ee32 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java @@ -31,15 +31,13 @@ /** The sidebar to be used for displaying of the natural text-presentation (Process2Text). */ public class P2TSideBar extends JPanel implements ActionListener { - private IEditor editor; + private final IEditor editor; private JEditorPane textpane = null; private Process2Text naturalTextParser = null; private JButton buttonLoad = null; private JButton buttonExport = null; private JLabel labelLoading = null; - private WebServiceThreadLLM webService = null; - private WebServiceThread webServiceOld = null; - private boolean threadInProgress = false; + private boolean threadInProgress = false; private boolean firstTimeDisplayed = false; /** @@ -230,7 +228,7 @@ public void actionPerformed(ActionEvent e) { // If we already have a text/process description, ask for overwrite // confirmation. - if (naturalTextParser != null && naturalTextParser.getXmlText().length() > 0) { + if (naturalTextParser != null && !naturalTextParser.getXmlText().isEmpty()) { if (JOptionPane.showConfirmDialog( null, Messages.getString("Paraphrasing.Load.Question.Content"), @@ -256,7 +254,7 @@ public void actionPerformed(ActionEvent e) { if (e.getSource() == this.buttonExport) { boolean fileTypeOk = false; - if (this.textpane.getText().length() > 0) { + if (!this.textpane.getText().isEmpty()) { JFileChooser jFileChooser = new JFileChooser(); jFileChooser.setFileFilter( new FileFilter() { @@ -351,7 +349,8 @@ private void getText() { return; } //New LLM - if(ConfigurationManager.getConfiguration().getGptUseNew()){ + WebServiceThreadLLM webService = null; + if(ConfigurationManager.getConfiguration().getGptUseNew()){ System.out.println(ConfigurationManager.getConfiguration().getGptUseNew()); this.textpane.setText(Messages.getString("P2T.loading")); this.showLoadingAnimation(true); @@ -373,7 +372,7 @@ private void getText() { System.out.println(ConfigurationManager.getConfiguration().getGptUseNew()); this.textpane.setText(Messages.getString("P2T.loading")); this.showLoadingAnimation(true); - webServiceOld = new WebServiceThread(this); + WebServiceThread webServiceOld = new WebServiceThread(this); webServiceOld.start(); while (!webServiceOld.getIsFinished()) { try{ diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/Process2Text.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/Process2Text.java index d637b65f3..04b6de338 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/Process2Text.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/Process2Text.java @@ -40,7 +40,7 @@ public String[] getText(String id) { } } - return temptexts.toArray(new String[temptexts.size()]); + return temptexts.toArray(new String[0]); } private void parseXmlToHtml() { From 721caf17727f1967d6bae60658e54298ac2cd1d6 Mon Sep 17 00:00:00 2001 From: zbbhelen Date: Wed, 26 Jun 2024 16:44:55 +0200 Subject: [PATCH 42/76] P2TUI Unit Test --- WoPeD-FileInterface/pom.xml | 49 ++++++++++++++++- .../main/java/org/woped/file/p2t/P2TUI.java | 2 +- .../java/org/woped/file/p2t/P2TUITest.java | 52 +++++++++++++++++++ 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java diff --git a/WoPeD-FileInterface/pom.xml b/WoPeD-FileInterface/pom.xml index 4e0bea0f4..1f5171fc2 100644 --- a/WoPeD-FileInterface/pom.xml +++ b/WoPeD-FileInterface/pom.xml @@ -120,7 +120,54 @@ 1.1.1 compile - + + junit + junit + 4.13.2 + test + + + org.jsoup + jsoup + 1.10.2 + + + org.junit.jupiter + junit-jupiter-engine + 5.7.0 + test + + + org.junit.jupiter + junit-jupiter + 5.7.0 + test + + + org.mockito + mockito-core + 5.7.0 + test + + + org.mockito + mockito-inline + 5.2.0 + test + + + org.projectlombok + lombok + 1.18.30 + provided + + + org.mockito + mockito-core + 5.7.0 + test + + diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index fdf991b76..259caecb7 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -32,7 +32,7 @@ public class P2TUI extends JDialog { private JDialog loadDialog; private AbstractApplicationMediator mediator; private boolean requested = false; - private JTextField apiKeyField; + JTextField apiKeyField; private JTextArea promptField; // Changed to JTextArea for multiline private JCheckBox enablePromptCheckBox; // New Checkbox diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java new file mode 100644 index 000000000..e592f4383 --- /dev/null +++ b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java @@ -0,0 +1,52 @@ +package org.woped.file.p2t; + +import org.junit.Before; +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.woped.core.controller.AbstractApplicationMediator; + +import javax.swing.*; + +import java.awt.*; +import java.net.HttpURLConnection; +import java.net.URL; + +import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +@RunWith(MockitoJUnitRunner.class) +class P2TUITest { + private P2TUI p2tui; + private JTextField apiKeyField; + + @Before + public void setUp() { + AbstractApplicationMediator mockMediator = mock(AbstractApplicationMediator.class); + p2tui = new P2TUI(mockMediator); + apiKeyField = mock(JTextField.class); + p2tui.apiKeyField = apiKeyField; + } + + @Test + public void testIsAPIKeyValid_withValidKey() { + String validApiKey = "your_actual_valid_api_key"; + + boolean isValid = p2tui.isAPIKeyValid(validApiKey); + + assertTrue(isValid); + } + + @Test + public void testIsAPIKeyValid_withInvalidKey() { + String invalidApiKey = "invalidApiKey"; + + boolean isValid = p2tui.isAPIKeyValid(invalidApiKey); + + assertFalse(isValid); + } + +} + From dd3f2000e8aa684f48b5a20e52cba5748fc3826a Mon Sep 17 00:00:00 2001 From: anneke02 Date: Sat, 29 Jun 2024 16:49:21 +0200 Subject: [PATCH 43/76] Remove unused mediator --- WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java | 1 - 1 file changed, 1 deletion(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 259caecb7..01bd5c3b8 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -39,7 +39,6 @@ public class P2TUI extends JDialog { private JCheckBox showAgainCheckBox; // New Checkbox private JRadioButton newRadioButton = null; private JRadioButton oldRadioButton = null; - private AbstractApplicationMediator m_mediator = null; JComboBox modelComboBox; private static final String DEFAULT_PROMPT = "Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"; From 78a00879841df790cc50912e66236a2ed0cd96ed Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Mon, 1 Jul 2024 12:11:12 +0200 Subject: [PATCH 44/76] Made sure that popup window closes upon generating a text Made sure that popup window closes upon generating a text aswell as minor clean up --- .../main/java/org/woped/file/p2t/P2TUI.java | 36 ++++++++++--------- .../woped/qualanalysis/p2t/P2TSideBar.java | 2 -- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 01bd5c3b8..ffb1ed8d5 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -140,8 +140,9 @@ private JPanel initializeSwitchButtonPanel() { modelComboBox = new JComboBox<>(); modelComboBox.setVisible(false); // Initially hidden showAgainCheckBox = new JCheckBox(Messages.getString("P2T.popup.show.again.title")); + showAgainCheckBox.setToolTipText("Durch das Entfernen dieses Hakens wird wird das Popup-Fenster nicht erneut angezeigt, der Client merkt sich jedoch den zuletzt ausgewählten Modus," + + "unter den NLP Einstellungen kann das Fenster wieder aktiviert werden"); showAgainCheckBox.setSelected(ConfigurationManager.getConfiguration().getGptShowAgain()); - showAgainCheckBox.setToolTipText(Messages.getString("P2T.popup.tool.tip.text")); apiKeyLabel.setVisible(false); apiKeyField.setText(ConfigurationManager.getConfiguration().getGptApiKey()); apiKeyField.setVisible(false); @@ -260,29 +261,30 @@ private JPanel initializeSingleButtonPanel() { singleButton.addActionListener(e -> { //dispose(); if (newRadioButton.isSelected()) { - validateAPIKey(); + if (validateAPIKey()) { - - ConfigurationManager.getConfiguration().setGptApiKey(apiKeyField.getText()); - ConfigurationManager.getConfiguration().setGptPrompt(promptField.getText()); - ConfigurationManager.getConfiguration().setGptModel(modelComboBox.getSelectedItem().toString()); - ConfigurationManager.getConfiguration().setGptUseNew(true); - System.out.println(modelComboBox.getSelectedItem().toString()); - - if (!showAgainCheckBox.isSelected()) { - ConfigurationManager.getConfiguration().setGptShowAgain(false); + ConfigurationManager.getConfiguration().setGptApiKey(apiKeyField.getText()); + ConfigurationManager.getConfiguration().setGptPrompt(promptField.getText()); + ConfigurationManager.getConfiguration().setGptModel(modelComboBox.getSelectedItem().toString()); ConfigurationManager.getConfiguration().setGptUseNew(true); - } + if (!showAgainCheckBox.isSelected()) { + ConfigurationManager.getConfiguration().setGptShowAgain(false); + ConfigurationManager.getConfiguration().setGptUseNew(true); + } + executeAction(); + dispose(); + } } else { ConfigurationManager.getConfiguration().setGptUseNew(false); if (!showAgainCheckBox.isSelected()) { ConfigurationManager.getConfiguration().setGptShowAgain(false); ConfigurationManager.getConfiguration().setGptUseNew(false); - } + } + executeAction(); + dispose(); } - executeAction(); }); return buttonPanel; } @@ -311,11 +313,13 @@ private void fetchAndFillModels() { } - private void validateAPIKey() { + private boolean validateAPIKey() { String apiKey = apiKeyField.getText(); - if (!isAPIKeyValid(apiKey)) { + boolean apiKeyValid = isAPIKeyValid(apiKey); + if (!apiKeyValid) { JOptionPane.showMessageDialog(this, Messages.getString("P2T.apikey.invalid"), Messages.getString("P2T.apikey.invalid.title"), JOptionPane.ERROR_MESSAGE); } + return apiKeyValid; } public static boolean isAPIKeyValid(String apiKey) { diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java index 2f766ee32..71bd46e02 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/P2TSideBar.java @@ -351,7 +351,6 @@ private void getText() { //New LLM WebServiceThreadLLM webService = null; if(ConfigurationManager.getConfiguration().getGptUseNew()){ - System.out.println(ConfigurationManager.getConfiguration().getGptUseNew()); this.textpane.setText(Messages.getString("P2T.loading")); this.showLoadingAnimation(true); webService = new WebServiceThreadLLM(this); @@ -369,7 +368,6 @@ private void getText() { } if(!ConfigurationManager.getConfiguration().getGptUseNew()){ - System.out.println(ConfigurationManager.getConfiguration().getGptUseNew()); this.textpane.setText(Messages.getString("P2T.loading")); this.showLoadingAnimation(true); WebServiceThread webServiceOld = new WebServiceThread(this); From edbdbe5a905a454ad039af3a08211c180b6024cf Mon Sep 17 00:00:00 2001 From: zbbhelen Date: Mon, 1 Jul 2024 18:26:32 +0200 Subject: [PATCH 45/76] update P2TUI Unit Test --- WoPeD-FileInterface/pom.xml | 6 +++ .../main/java/org/woped/file/p2t/P2TUI.java | 2 +- .../java/org/woped/file/p2t/P2TUITest.java | 50 ++++++++++++++++--- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/WoPeD-FileInterface/pom.xml b/WoPeD-FileInterface/pom.xml index 1f5171fc2..afd2e28c2 100644 --- a/WoPeD-FileInterface/pom.xml +++ b/WoPeD-FileInterface/pom.xml @@ -167,6 +167,12 @@ 5.7.0 test + + org.mockito + mockito-junit-jupiter + 5.12.0 + test + diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index ffb1ed8d5..1050c9f73 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -313,7 +313,7 @@ private void fetchAndFillModels() { } - private boolean validateAPIKey() { + boolean validateAPIKey() { String apiKey = apiKeyField.getText(); boolean apiKeyValid = isAPIKeyValid(apiKey); if (!apiKeyValid) { diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java index e592f4383..03aaa4834 100644 --- a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java +++ b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java @@ -1,15 +1,21 @@ package org.woped.file.p2t; import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.runner.RunWith; +import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.woped.core.controller.AbstractApplicationMediator; import javax.swing.*; import java.awt.*; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.net.HttpURLConnection; import java.net.URL; @@ -17,17 +23,21 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) class P2TUITest { private P2TUI p2tui; - private JTextField apiKeyField; + @Mock + private JTextField mockApiKeyField; + @Mock + private AbstractApplicationMediator mockMediator; - @Before - public void setUp() { - AbstractApplicationMediator mockMediator = mock(AbstractApplicationMediator.class); + @BeforeEach + public void setUp() throws IOException { + mockMediator = mock(AbstractApplicationMediator.class); + mockApiKeyField = mock(JTextField.class); p2tui = new P2TUI(mockMediator); - apiKeyField = mock(JTextField.class); - p2tui.apiKeyField = apiKeyField; + p2tui.apiKeyField = mockApiKeyField; + } @Test @@ -48,5 +58,31 @@ public void testIsAPIKeyValid_withInvalidKey() { assertFalse(isValid); } + @Test + public void testValidateAPIKey_withValidKey() { + // Stubbing behavior of mockApiKeyField + when(mockApiKeyField.getText()).thenReturn("your_actual_valid_api_key"); + // Call the method you want to test + boolean isValid = p2tui.validateAPIKey(); + + // Assert the expected outcome + assertTrue(isValid); + } + + @Test + public void testValidateAPIKey_withInvalidKey() { + // Stubbing behavior of mockApiKeyField + when(mockApiKeyField.getText()).thenReturn("invalidApiKey"); + // Call the method you want to test + boolean isValid = p2tui.validateAPIKey(); + + // Assert the expected outcome + assertFalse(isValid); + } + + + + + } From d584d460df28df24ebe85f5144e67d5cac3e7727 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Tue, 2 Jul 2024 00:09:10 +0200 Subject: [PATCH 46/76] Refactoring, Cleanup, Comments Refactoring, Cleanup, Comments --- .../qualanalysis/p2t/WebServiceThread.java | 13 +++++-- .../qualanalysis/p2t/WebServiceThreadLLM.java | 35 ++++++++++++------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java index f92028b39..5819f8ec7 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java @@ -11,7 +11,6 @@ public class WebServiceThread extends Thread { private P2TSideBar paraphrasingPanel; - private String[][] result = null; private boolean isFinished; private HttpRequest request; private HttpResponse response; @@ -31,13 +30,19 @@ public boolean getIsFinished() { public void run() { IEditor editor = paraphrasingPanel.getEditor(); paraphrasingPanel.showLoadingAnimation(true); - String url = + + String url = "http://localhost:8080/p2t/generateText"; + + /*String url = "http://" + ConfigurationManager.getConfiguration().getProcess2TextServerHost() + ":" + ConfigurationManager.getConfiguration().getProcess2TextServerPort() + ConfigurationManager.getConfiguration().getProcess2TextServerURI() - + "/generateText"; + + "/generateText";*/ + + + String[] arg = {url, "P2T"}; ByteArrayOutputStream stream = new ByteArrayOutputStream(); new PNMLExport().saveToStream(editor, stream); @@ -81,6 +86,8 @@ public void run() { paraphrasingPanel.setThreadInProgress(false); } + // Setter- und Getter für das Ergebnis des Algorithmus + public String getText() { return text; } diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java index 6d29ced38..893e4d1c1 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java @@ -9,6 +9,7 @@ import java.util.Scanner; import javax.servlet.http.HttpServletResponse; import javax.swing.JOptionPane; + import org.woped.core.config.ConfigurationManager; import org.woped.core.controller.IEditor; import org.woped.gui.translations.Messages; @@ -16,7 +17,6 @@ public class WebServiceThreadLLM extends Thread { private P2TSideBar paraphrasingPanel; - private String[][] result = null; private boolean isFinished; private String apiKey; private String prompt; @@ -40,15 +40,17 @@ public void run() { IEditor editor = paraphrasingPanel.getEditor(); paraphrasingPanel.showLoadingAnimation(true); - String testUrl = "http://localhost:8080/p2t/generateTextLLM"; - String url = + String url = "http://localhost:8080/p2t/generateTextLLM"; + + // Dieser URL Parameter ist für den Livegang des LLM basierten Process2Text Services vorbereitet + + /*String url = "http://" + ConfigurationManager.getConfiguration().getProcess2TextServerHost() + ":" + ConfigurationManager.getConfiguration().getProcess2TextServerPort() + ConfigurationManager.getConfiguration().getProcess2TextServerURI() - + "/generateTextLLM"; - + + "/generateTextLLM";*/ ByteArrayOutputStream stream = new ByteArrayOutputStream(); @@ -56,17 +58,16 @@ public void run() { String text = stream.toString(); String output; - //TODO Diese logik in die Buttons implementieren!! try { // URL-Parameter kodieren - String encodedApiKey = URLEncoder.encode(apiKey, StandardCharsets.UTF_8.toString()); - String encodedPrompt = URLEncoder.encode(prompt, StandardCharsets.UTF_8.toString()); - String encodedGptModel = URLEncoder.encode(gptModel, StandardCharsets.UTF_8.toString()); + String encodedApiKey = URLEncoder.encode(apiKey, StandardCharsets.UTF_8); + String encodedPrompt = URLEncoder.encode(prompt, StandardCharsets.UTF_8); + String encodedGptModel = URLEncoder.encode(gptModel, StandardCharsets.UTF_8); // URL mit Parametern aufbauen String urlWithParams = String.format("%s?apiKey=%s&prompt=%s&gptModel=%s", - testUrl, encodedApiKey, encodedPrompt, encodedGptModel); + url, encodedApiKey, encodedPrompt, encodedGptModel); URL urlObj = new URL(urlWithParams); // Verbindung aufbauen @@ -84,7 +85,7 @@ public void run() { // Antwort lesen int responseCode = conn.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { - try (Scanner scanner = new Scanner(conn.getInputStream(), StandardCharsets.UTF_8.name())) { + try (Scanner scanner = new Scanner(conn.getInputStream(), StandardCharsets.UTF_8)) { output = scanner.useDelimiter("\\A").next(); output = output.replaceAll("\\s*\n\\s*", ""); paraphrasingPanel.setNaturalTextParser(new Process2Text(output)); @@ -95,6 +96,7 @@ public void run() { } // Fehlerbehandlung basierend auf Response Code + switch (responseCode) { case HttpServletResponse.SC_NO_CONTENT: case HttpServletResponse.SC_REQUEST_TIMEOUT: @@ -133,6 +135,13 @@ public void run() { } } - public void setText(String output) {this.text = output;} - public String getText() {return this.text;} + // Setter- und Getter für das Ergebnis des LLM + + public void setText(String output) { + this.text = output; + } + + public String getText() { + return this.text; + } } From 6ce1412c6bcd49a700d7d4b1ff0c8a3f129b4c1a Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Tue, 2 Jul 2024 00:12:49 +0200 Subject: [PATCH 47/76] removed unused method --- .../editor/gui/config/ConfNLPToolsPanel.java | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index 9cc05fcec..f89c867eb 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -490,27 +490,6 @@ private void testGPTConnection() { } } - private void fetchAndFillModels() { - new Thread(() -> { - try { - List models = ApiHelper.fetchModels(); - SwingUtilities.invokeLater(() -> { - for (String model : models) { - modelComboBox.addItem(model); - } - }); - } catch (IOException | ParseException e) { - SwingUtilities.invokeLater(() -> { - JOptionPane.showMessageDialog( - this.getGPTPanel(), - "Failed to fetch models: " + e.getMessage(), - "Fetch Models", - JOptionPane.ERROR_MESSAGE); - }); - } - }).start(); - } - private void setDefaultValuesGPT() { getApiKeyText().setText(ConfigurationManager.getStandardConfiguration().getGptApiKey()); getShowAgainBox().setSelected(ConfigurationManager.getStandardConfiguration().getGptShowAgain()); From e79744587bc7612eac8564d57861de7c8f2b5585 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Tue, 2 Jul 2024 00:22:41 +0200 Subject: [PATCH 48/76] translated comments, refactored compoents, removed unused components --- .../editor/gui/config/ConfNLPToolsPanel.java | 16 +++++----------- .../src/main/java/org/woped/file/p2t/P2TUI.java | 4 ---- .../woped/qualanalysis/p2t/WebServiceThread.java | 2 +- .../qualanalysis/p2t/WebServiceThreadLLM.java | 13 ++++++------- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index f89c867eb..85b442c46 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -13,7 +13,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; -import java.util.Arrays; import java.util.List; import javax.swing.*; @@ -23,7 +22,6 @@ import org.woped.gui.lookAndFeel.WopedButton; import org.woped.gui.translations.Messages; -@SuppressWarnings("serial") public class ConfNLPToolsPanel extends AbstractConfPanel { private JCheckBox useBox = null; private JPanel enabledPanel = null; @@ -54,7 +52,7 @@ public class ConfNLPToolsPanel extends AbstractConfPanel { private WopedButton resetButton = null; private JTextArea promptText = null; private WopedButton checkConnectionButton = null; - List models = Arrays.asList("") ; + List models = List.of(""); { try { models = ApiHelper.fetchModels(); @@ -86,7 +84,7 @@ public boolean applyConfiguration() { } ConfigurationManager.getConfiguration().setProcess2TextServerHost(getServerURLText().getText()); ConfigurationManager.getConfiguration().setProcess2TextServerURI(getManagerPathText().getText()); - if (getServerPortText().getText().equals("")) { + if (getServerPortText().getText().isEmpty()) { ConfigurationManager.getConfiguration().setProcess2TextServerPort(0); } else { ConfigurationManager.getConfiguration() @@ -98,7 +96,7 @@ public boolean applyConfiguration() { ConfigurationManager.getConfiguration().setText2ProcessServerURI(getManagerPathText_T2P().getText()); - if (getServerPortText_T2P().getText().equals("")) { + if (getServerPortText_T2P().getText().isEmpty()) { ConfigurationManager.getConfiguration().setText2ProcessServerPort(0); } else { ConfigurationManager.getConfiguration() @@ -622,7 +620,7 @@ private WopedButton getDefaultButton_T2P() { private void testProcess2TextConnection() { URL url = null; String connection = "http://" + getServerURLText().getText() + ":" + getServerPortText().getText() + getManagerPathText().getText(); - String arg[] = {connection, ""}; + String[] arg = {connection, ""}; try { url = new URL(connection); @@ -632,8 +630,6 @@ private void testProcess2TextConnection() { arg[1] = "P2T"; JOptionPane.showMessageDialog(this.getSettingsPanel(), Messages.getString("Paraphrasing.Webservice.Success.Message", arg), Messages.getString("Paraphrasing.Webservice.Success.Title"), JOptionPane.INFORMATION_MESSAGE); } - } catch (MalformedURLException mue) { - JOptionPane.showMessageDialog(this.getSettingsPanel(), Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), Messages.getString("Paraphrasing.Webservice.Error.Title"), JOptionPane.ERROR_MESSAGE); } catch (IOException ex) { JOptionPane.showMessageDialog(this.getSettingsPanel(), Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), Messages.getString("Paraphrasing.Webservice.Error.Title"), JOptionPane.ERROR_MESSAGE); } @@ -642,7 +638,7 @@ private void testProcess2TextConnection() { private void testText2ProcessConnection() { URL url; String connection = "http://" + getServerURLText_T2P().getText() + ":" + getServerPortText_T2P().getText() + getManagerPathText_T2P().getText(); - String arg[] = {connection, ""}; + String[] arg = {connection, ""}; try { url = new URL(connection); @@ -651,8 +647,6 @@ private void testText2ProcessConnection() { arg[1] = "T2P"; JOptionPane.showMessageDialog(this.getSettingsPanel_T2P(), Messages.getString("Paraphrasing.Webservice.Success.Message", arg), Messages.getString("Paraphrasing.Webservice.Success.Title"), JOptionPane.INFORMATION_MESSAGE); } - } catch (MalformedURLException mue) { - JOptionPane.showMessageDialog(this.getSettingsPanel_T2P(), Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), Messages.getString("Paraphrasing.Webservice.Error.Title"), JOptionPane.ERROR_MESSAGE); } catch (IOException ex) { JOptionPane.showMessageDialog(this.getSettingsPanel_T2P(), Messages.getString("Paraphrasing.Webservice.Error.WebserviceException.Message", arg), Messages.getString("Paraphrasing.Webservice.Error.Title"), JOptionPane.ERROR_MESSAGE); } diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 1050c9f73..54ed62114 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -30,12 +30,9 @@ public class P2TUI extends JDialog { private JDialog loadDialog; - private AbstractApplicationMediator mediator; - private boolean requested = false; JTextField apiKeyField; private JTextArea promptField; // Changed to JTextArea for multiline private JCheckBox enablePromptCheckBox; // New Checkbox - private JCheckBox showAgainCheckBox; // New Checkbox private JRadioButton newRadioButton = null; private JRadioButton oldRadioButton = null; @@ -49,7 +46,6 @@ public P2TUI(AbstractApplicationMediator mediator) { public P2TUI(Frame owner, AbstractApplicationMediator mediator) throws HeadlessException { super(owner, true); - this.mediator = mediator; initialize(); } diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java index 5819f8ec7..318a703dc 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java @@ -86,7 +86,7 @@ public void run() { paraphrasingPanel.setThreadInProgress(false); } - // Setter- und Getter für das Ergebnis des Algorithmus + // Setter- und Getter for the result of the algorithm public String getText() { return text; diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java index 893e4d1c1..273e53562 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java @@ -42,8 +42,7 @@ public void run() { String url = "http://localhost:8080/p2t/generateTextLLM"; - // Dieser URL Parameter ist für den Livegang des LLM basierten Process2Text Services vorbereitet - + // This URL parameter is prepared for the go-live of the LLM-based Process2Text service /*String url = "http://" + ConfigurationManager.getConfiguration().getProcess2TextServerHost() @@ -60,29 +59,29 @@ public void run() { try { - // URL-Parameter kodieren + // Encode URL parameters String encodedApiKey = URLEncoder.encode(apiKey, StandardCharsets.UTF_8); String encodedPrompt = URLEncoder.encode(prompt, StandardCharsets.UTF_8); String encodedGptModel = URLEncoder.encode(gptModel, StandardCharsets.UTF_8); - // URL mit Parametern aufbauen + // Construct URL with parameters String urlWithParams = String.format("%s?apiKey=%s&prompt=%s&gptModel=%s", url, encodedApiKey, encodedPrompt, encodedGptModel); URL urlObj = new URL(urlWithParams); - // Verbindung aufbauen + // Establish connection HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "text/plain"); - // Request-Body senden + // Send request body try (OutputStream os = conn.getOutputStream()) { byte[] input = text.getBytes(StandardCharsets.UTF_8); os.write(input, 0, input.length); } - // Antwort lesen + // Read response int responseCode = conn.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { try (Scanner scanner = new Scanner(conn.getInputStream(), StandardCharsets.UTF_8)) { From 162e58781340c406b7dd5a70996e79e4f47dd46e Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Tue, 2 Jul 2024 00:45:29 +0200 Subject: [PATCH 49/76] fixed a bug where the keyfield for the apikey aswell as the dropdownmenu didnt show in p2tui / popup windows when GPT Models couldn't be fetched fixed a bug where the keyfield for the apikey aswell as the dropdownmenu didnt show in p2tui / popup windows when GPT Models couldn't be fetched also: Bugfix, cleanup, made apikeyfield private again --- .../main/java/org/woped/file/p2t/P2TUI.java | 27 ++---- .../java/org/woped/file/p2t/P2TUITest.java | 88 ------------------- 2 files changed, 8 insertions(+), 107 deletions(-) delete mode 100644 WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 54ed62114..0b1bb8e07 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -30,10 +30,10 @@ public class P2TUI extends JDialog { private JDialog loadDialog; - JTextField apiKeyField; - private JTextArea promptField; // Changed to JTextArea for multiline - private JCheckBox enablePromptCheckBox; // New Checkbox - private JCheckBox showAgainCheckBox; // New Checkbox + private JTextField apiKeyField; + private JTextArea promptField; + private JCheckBox enablePromptCheckBox; + private JCheckBox showAgainCheckBox; private JRadioButton newRadioButton = null; private JRadioButton oldRadioButton = null; JComboBox modelComboBox; @@ -68,6 +68,8 @@ private void initialize() { Dimension size = new Dimension(600, 375); this.setSize(size); + + // Initialize models asynchronously fetchAndFillModels(); } @@ -114,7 +116,6 @@ private JPanel initializeSwitchButtonPanel() { promptField.setText(ConfigurationManager.getConfiguration().getGptPrompt()); - JScrollPane promptScrollPane = new JScrollPane(promptField); promptScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); promptScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); @@ -136,7 +137,7 @@ private JPanel initializeSwitchButtonPanel() { modelComboBox = new JComboBox<>(); modelComboBox.setVisible(false); // Initially hidden showAgainCheckBox = new JCheckBox(Messages.getString("P2T.popup.show.again.title")); - showAgainCheckBox.setToolTipText("Durch das Entfernen dieses Hakens wird wird das Popup-Fenster nicht erneut angezeigt, der Client merkt sich jedoch den zuletzt ausgewählten Modus," + + showAgainCheckBox.setToolTipText("Durch das Entfernen dieses Hakens wird das Popup-Fenster nicht erneut angezeigt, der Client merkt sich jedoch den zuletzt ausgewählten Modus," + "unter den NLP Einstellungen kann das Fenster wieder aktiviert werden"); showAgainCheckBox.setSelected(ConfigurationManager.getConfiguration().getGptShowAgain()); apiKeyLabel.setVisible(false); @@ -148,7 +149,6 @@ private JPanel initializeSwitchButtonPanel() { showAgainCheckBox.setVisible(true); - newRadioButton.addActionListener(e -> { apiKeyLabel.setVisible(true); apiKeyField.setVisible(true); @@ -178,11 +178,8 @@ private JPanel initializeSwitchButtonPanel() { modelComboBox.setVisible(false); showAgainCheckBox.setVisible(true); - - }); - oldRadioButton.setSelected(true); gbc.gridx = 0; @@ -253,9 +250,7 @@ private JPanel initializeSingleButtonPanel() { buttonPanel.add(singleButton, BorderLayout.CENTER); - singleButton.addActionListener(e -> { - //dispose(); if (newRadioButton.isSelected()) { if (validateAPIKey()) { @@ -290,7 +285,6 @@ private void executeAction() { action.actionPerformed(new ViewEvent(this, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.P2T, null)); } - private void fetchAndFillModels() { new Thread(() -> { try { @@ -302,13 +296,12 @@ private void fetchAndFillModels() { }); } catch (IOException | ParseException e) { SwingUtilities.invokeLater(() -> { - JOptionPane.showMessageDialog(this.initializeSwitchButtonPanel(), Messages.getString("P2T.exception.fail.fetch.models") + e.getMessage(), Messages.getString("P2T.exception.fetch.models"), JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(this, Messages.getString("P2T.exception.fail.fetch.models") + e.getMessage(), Messages.getString("P2T.exception.fetch.models"), JOptionPane.ERROR_MESSAGE); }); } }).start(); } - boolean validateAPIKey() { String apiKey = apiKeyField.getText(); boolean apiKeyValid = isAPIKeyValid(apiKey); @@ -357,8 +350,4 @@ private void showErrorPopUp(String titleId, String msgId) { JOptionPane.showOptionDialog(null, msg, title, optionType, messageType, null, text, text[0]); } - - private void close() { - this.dispose(); - } } diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java deleted file mode 100644 index 03aaa4834..000000000 --- a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.woped.file.p2t; - -import org.junit.Before; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; -import org.mockito.junit.jupiter.MockitoExtension; -import org.woped.core.controller.AbstractApplicationMediator; - -import javax.swing.*; - -import java.awt.*; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.net.HttpURLConnection; -import java.net.URL; - -import static org.junit.Assert.assertFalse; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - -@ExtendWith(MockitoExtension.class) -class P2TUITest { - private P2TUI p2tui; - @Mock - private JTextField mockApiKeyField; - @Mock - private AbstractApplicationMediator mockMediator; - - @BeforeEach - public void setUp() throws IOException { - mockMediator = mock(AbstractApplicationMediator.class); - mockApiKeyField = mock(JTextField.class); - p2tui = new P2TUI(mockMediator); - p2tui.apiKeyField = mockApiKeyField; - - } - - @Test - public void testIsAPIKeyValid_withValidKey() { - String validApiKey = "your_actual_valid_api_key"; - - boolean isValid = p2tui.isAPIKeyValid(validApiKey); - - assertTrue(isValid); - } - - @Test - public void testIsAPIKeyValid_withInvalidKey() { - String invalidApiKey = "invalidApiKey"; - - boolean isValid = p2tui.isAPIKeyValid(invalidApiKey); - - assertFalse(isValid); - } - - @Test - public void testValidateAPIKey_withValidKey() { - // Stubbing behavior of mockApiKeyField - when(mockApiKeyField.getText()).thenReturn("your_actual_valid_api_key"); - // Call the method you want to test - boolean isValid = p2tui.validateAPIKey(); - - // Assert the expected outcome - assertTrue(isValid); - } - - @Test - public void testValidateAPIKey_withInvalidKey() { - // Stubbing behavior of mockApiKeyField - when(mockApiKeyField.getText()).thenReturn("invalidApiKey"); - // Call the method you want to test - boolean isValid = p2tui.validateAPIKey(); - - // Assert the expected outcome - assertFalse(isValid); - } - - - - - -} - From 35b8de02c5c71f042d955fc8823e9a92b2da0880 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Tue, 2 Jul 2024 15:51:38 +0200 Subject: [PATCH 50/76] Added refactoring of prompt string --- WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java | 2 +- .../src/test/java/org/woped/file/p2t/P2TUITest.java | 2 +- WoPeD-GUI/src/main/resources/Messages.properties | 1 + WoPeD-GUI/src/main/resources/Messages_de.properties | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 01bd5c3b8..6caa968e3 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -41,7 +41,7 @@ public class P2TUI extends JDialog { private JRadioButton oldRadioButton = null; JComboBox modelComboBox; - private static final String DEFAULT_PROMPT = "Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece!"; + private static final String DEFAULT_PROMPT = Messages.getString("P2T.prompt.text"); public P2TUI(AbstractApplicationMediator mediator) { this(null, mediator); diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java index e592f4383..e4c13e758 100644 --- a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java +++ b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java @@ -43,7 +43,7 @@ public void testIsAPIKeyValid_withValidKey() { public void testIsAPIKeyValid_withInvalidKey() { String invalidApiKey = "invalidApiKey"; - boolean isValid = p2tui.isAPIKeyValid(invalidApiKey); + boolean isValid = P2TUI.isAPIKeyValid(invalidApiKey); assertFalse(isValid); } diff --git a/WoPeD-GUI/src/main/resources/Messages.properties b/WoPeD-GUI/src/main/resources/Messages.properties index 5bf3e7659..276182aa5 100644 --- a/WoPeD-GUI/src/main/resources/Messages.properties +++ b/WoPeD-GUI/src/main/resources/Messages.properties @@ -882,6 +882,7 @@ P2T.prompt.checkbox.enable.title = Enable editing P2T.popup.show.again.title = Show again P2T.get.GPTmodel.title = GPT-Model: P2T.popup.tool.tip.text = Placeholder +P2T.prompt.text = Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece! P2T.exception.fail.fetch.models = Failed to fetch models: P2T.exception.fetch.models = Fetch Models #************* diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index 521f8d60b..a46165611 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -488,6 +488,7 @@ P2T.prompt.checkbox.enable.title = Bearbeitung aktivieren P2T.popup.show.again.title = Erneut anzeigen P2T.get.GPTmodel.title = GPT-Model: P2T.popup.tool.tip.text = Platzhalter +P2T.prompt.text = Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece! P2T.exception.fail.fetch.models = Modelle konnten nicht abgerufen werden: P2T.exception.fetch.models = Modelle abrufen #************* From baad9422ca80d4b033c961870954d015554e19d3 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Tue, 2 Jul 2024 15:55:35 +0200 Subject: [PATCH 51/76] Delete prints --- .../java/org/woped/editor/gui/config/ConfNLPToolsPanel.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index 9cc05fcec..5114dc4cf 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -124,8 +124,6 @@ public void readConfiguration() { getApiKeyText().setText(ConfigurationManager.getConfiguration().getGptApiKey()); getShowAgainBox().setSelected(ConfigurationManager.getConfiguration().getGptShowAgain()); getPromptText().setText(ConfigurationManager.getConfiguration().getGptPrompt()); - System.out.println(ConfigurationManager.getConfiguration().getGptModel()); - } private void initialize() { @@ -431,8 +429,6 @@ private WopedButton getResetButton() { resetButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setDefaultValuesGPT(); - System.out.println(ConfigurationManager.getConfiguration().getGptShowAgain()); - System.out.println(ConfigurationManager.getConfiguration().getGptPrompt()); } }); } From b52868e48249ea5771b8f944435e921bd782645a Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Tue, 2 Jul 2024 21:24:14 +0200 Subject: [PATCH 52/76] added a fetchgptmodels button for fetching gpt models added a fetchgptmodels button for fetching gpt models in p2t and confnlptools adjusted backend call for fetching gpt models --- .../editor/gui/config/ConfNLPToolsPanel.java | 61 ++++++++++++++----- .../org/woped/editor/tools/ApiHelper.java | 7 ++- .../main/java/org/woped/file/p2t/P2TUI.java | 36 ++++++++--- 3 files changed, 80 insertions(+), 24 deletions(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index f8aa38254..78141e6b8 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -10,7 +10,6 @@ import java.awt.event.ItemListener; import java.io.IOException; import java.net.HttpURLConnection; -import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.List; @@ -51,19 +50,9 @@ public class ConfNLPToolsPanel extends AbstractConfPanel { private JCheckBox showAgainBox = null; private WopedButton resetButton = null; private JTextArea promptText = null; + private WopedButton fetchGPTModelsButton = null; private WopedButton checkConnectionButton = null; - List models = List.of(""); - { - try { - models = ApiHelper.fetchModels(); - } catch (IOException | ParseException ignored) { - - } - } - - private String[] models2 = models.toArray(new String[0]); - // New components - private JComboBox modelComboBox = new JComboBox(models2); + private JComboBox modelComboBox = new JComboBox(); public ConfNLPToolsPanel(String name) { super(name); @@ -350,29 +339,45 @@ private JPanel getGPTPanel() { c.gridy = 2; additionalPanel.add(new JLabel(Messages.getString("Configuration.GPT.model.Title")), c); + // Adjust the constraints for the combo box c.weightx = 1; c.gridx = 1; c.gridy = 2; + c.gridwidth = 1; + c.insets = new Insets(2, 0, 2, 12); // Add padding to the right of the combo box + c.fill = GridBagConstraints.HORIZONTAL; additionalPanel.add(getModelComboBox(), c); + // Adjust the constraints for the fetchModels button + c.weightx = 0; + c.gridx = 2; + c.gridy = 2; + c.insets = new Insets(2, 0, 2, 10); + additionalPanel.add(getFetchGPTModelsButton(), c); + + // Adjust the constraints for the show again checkbox c.weightx = 1; c.gridx = 0; c.gridy = 3; + c.insets = new Insets(2, 0, 2, 0); additionalPanel.add(getShowAgainBox(), c); + // Adjust the constraints for the reset button c.weightx = 1; c.gridx = 2; c.gridy = 3; + c.insets = new Insets(2, 0, 2, 10); // Add padding to the right of the checkbox additionalPanel.add(getResetButton(), c); + // Adjust the constraints for the check connection button c.weightx = 1; c.gridx = 1; c.gridy = 3; + c.insets = new Insets(2, 0, 2, 12); // Reset insets for the button additionalPanel.add(getCheckConnectionButton(), c); } additionalPanel.setVisible(getUseBox().isSelected()); - //fetchAndFillModels(); for (int i = 0; i < modelComboBox.getItemCount(); i++){ if (modelComboBox.getItemAt(i).equals(ConfigurationManager.getConfiguration().getGptModel())){ modelComboBox.setSelectedIndex(i); @@ -433,6 +438,16 @@ public void actionPerformed(ActionEvent e) { return resetButton; } + private WopedButton getFetchGPTModelsButton(){ + if (fetchGPTModelsButton == null){ + fetchGPTModelsButton = new WopedButton(); + fetchGPTModelsButton.setText("fetchModels"); + fetchGPTModelsButton.setPreferredSize(new Dimension(200, 25)); + fetchGPTModelsButton.addActionListener(e -> fetchAndFillModels()); + } + return fetchGPTModelsButton; + } + private WopedButton getCheckConnectionButton() { if (checkConnectionButton == null) { checkConnectionButton = new WopedButton(); @@ -722,4 +737,22 @@ private JTextField getServerPortText_T2P() { } return serverPortText_T2P; } + private void fetchAndFillModels() { + new Thread(() -> { + try { + List models = ApiHelper.fetchModels(apiKeyText.getText()); + SwingUtilities.invokeLater(() -> { + for (String model : models) { + modelComboBox.addItem(model); + } + modelComboBox.setSelectedItem(ConfigurationManager.getConfiguration().getGptModel()); + }); + } catch (IOException | ParseException e) { + SwingUtilities.invokeLater(() -> { + JOptionPane.showMessageDialog(this, Messages.getString("P2T.exception.fail.fetch.models") + e.getMessage(), Messages.getString("P2T.exception.fetch.models"), JOptionPane.ERROR_MESSAGE); + }); + } + }).start(); + } + } diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java b/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java index 03f9647e7..4c69b5d4b 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java @@ -14,8 +14,8 @@ public class ApiHelper { - public static List fetchModels() throws IOException, ParseException { - String urlString = "http://localhost:8080/p2t/gptModels"; + public static List fetchModels(String apiKey) throws IOException, ParseException { + String urlString = "http://localhost:8080/p2t/gptModels?apiKey=" + apiKey; List models = new ArrayList<>(); URL url = new URL(urlString); @@ -39,7 +39,8 @@ public static List fetchModels() throws IOException, ParseException { models.add(model.toString()); } } else { - throw new IOException("Failed to fetch models. Response Code: " + responseCode); + throw new IOException("Failed to fetch models. Response Code: " + responseCode + "\n" + + "please check your API Key"); } System.out.println(models); return models; diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index cce1ddabe..fd939d8c4 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -22,7 +22,6 @@ import org.woped.core.controller.AbstractApplicationMediator; import org.woped.core.controller.AbstractViewEvent; import org.woped.core.controller.ViewEvent; -import org.woped.editor.action.ActionButtonListener; import org.woped.editor.action.WoPeDAction; import org.woped.editor.controller.ActionFactory; import org.woped.editor.tools.ApiHelper; @@ -70,7 +69,7 @@ private void initialize() { this.setSize(size); // Initialize models asynchronously - fetchAndFillModels(); + } private JPanel initializeSwitchButtonPanel() { @@ -105,7 +104,7 @@ private JPanel initializeSwitchButtonPanel() { JLabel apiKeyLabel = new JLabel(Messages.getString("P2T.apikey.title") + ":"); apiKeyField = new JTextField(); - apiKeyField.setPreferredSize(new Dimension(200, 25)); + apiKeyField.setPreferredSize(new Dimension(300, 25)); JLabel promptLabel = new JLabel(Messages.getString("P2T.prompt.title") + ":"); promptField = new JTextArea(DEFAULT_PROMPT); @@ -135,7 +134,19 @@ private JPanel initializeSwitchButtonPanel() { JLabel gptModelLabel = new JLabel(Messages.getString("P2T.get.GPTmodel.title")); gptModelLabel.setVisible(false); // Initially hidden modelComboBox = new JComboBox<>(); + modelComboBox.setPreferredSize(new Dimension(150, 25)); modelComboBox.setVisible(false); // Initially hidden + + // Add fetchModels Button + JButton fetchModelsButton = new JButton("fetchModels"); + fetchModelsButton.setPreferredSize(new Dimension(120, 25)); + fetchModelsButton.setVisible(false); // Initially hidden + fetchModelsButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + fetchAndFillModels(); + }} + ); + showAgainCheckBox = new JCheckBox(Messages.getString("P2T.popup.show.again.title")); showAgainCheckBox.setToolTipText("Durch das Entfernen dieses Hakens wird das Popup-Fenster nicht erneut angezeigt, der Client merkt sich jedoch den zuletzt ausgewählten Modus," + "unter den NLP Einstellungen kann das Fenster wieder aktiviert werden"); @@ -157,6 +168,7 @@ private JPanel initializeSwitchButtonPanel() { enablePromptCheckBox.setVisible(true); gptModelLabel.setVisible(true); modelComboBox.setVisible(true); + fetchModelsButton.setVisible(true); for (int i = 0; i < modelComboBox.getItemCount(); i++) { if (modelComboBox.getItemAt(i).equals(ConfigurationManager.getConfiguration().getGptModel())) { modelComboBox.setSelectedIndex(i); @@ -176,6 +188,7 @@ private JPanel initializeSwitchButtonPanel() { enablePromptCheckBox.setVisible(false); gptModelLabel.setVisible(false); modelComboBox.setVisible(false); + fetchModelsButton.setVisible(false); showAgainCheckBox.setVisible(true); }); @@ -201,7 +214,7 @@ private JPanel initializeSwitchButtonPanel() { gbc.gridx = 1; gbc.weightx = 1.0; - gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.fill = GridBagConstraints.BOTH; fieldsPanel.add(promptScrollPane, gbc); gbc.gridx = 0; @@ -219,10 +232,16 @@ private JPanel initializeSwitchButtonPanel() { gbc.gridx = 1; gbc.gridy = 4; gbc.gridwidth = 1; - gbc.weightx = 1.0; + gbc.weightx = 0.5; gbc.fill = GridBagConstraints.HORIZONTAL; fieldsPanel.add(modelComboBox, gbc); // Add JComboBox to the panel + gbc.gridx = 2; + gbc.gridy = 4; + gbc.gridwidth = 1; + gbc.weightx = 0.5; + fieldsPanel.add(fetchModelsButton, gbc); // Add fetchModels button to the panel + gbc.gridx = 0; gbc.gridy = 5; gbc.gridwidth = 2; @@ -233,7 +252,9 @@ private JPanel initializeSwitchButtonPanel() { gbc.gridy = 1; gbc.gridwidth = 2; gbc.insets = new Insets(10, 0, 0, 0); - gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.fill = GridBagConstraints.BOTH; + gbc.weightx = 1.0; + gbc.weighty = 1.0; switchButtonPanel.add(fieldsPanel, gbc); return switchButtonPanel; @@ -288,11 +309,12 @@ private void executeAction() { private void fetchAndFillModels() { new Thread(() -> { try { - List models = ApiHelper.fetchModels(); + List models = ApiHelper.fetchModels(apiKeyField.getText()); SwingUtilities.invokeLater(() -> { for (String model : models) { modelComboBox.addItem(model); } + modelComboBox.setSelectedItem(ConfigurationManager.getConfiguration().getGptModel()); }); } catch (IOException | ParseException e) { SwingUtilities.invokeLater(() -> { From 24e6c91faa14754c2214d6e7e6f615290ea277d8 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Wed, 3 Jul 2024 15:09:46 +0200 Subject: [PATCH 53/76] Fixed a Bug where the prompt would reset if the boolean value of the promptcheckbox changed --- WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java | 1 - 1 file changed, 1 deletion(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index fd939d8c4..3bfed18db 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -125,7 +125,6 @@ private JPanel initializeSwitchButtonPanel() { enablePromptCheckBox.addActionListener(e -> { promptField.setEnabled(enablePromptCheckBox.isSelected()); if (!enablePromptCheckBox.isSelected()) { - promptField.setText(DEFAULT_PROMPT); // Reset text when disabled promptField.revalidate(); } }); From 5ec0db37d5f3a7ed3328c29fa9a88b50d9a4c1dd Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Wed, 3 Jul 2024 22:36:13 +0200 Subject: [PATCH 54/76] CleanUp + Logging Logging yet to be finished --- .../org/woped/editor/tools/ApiHelper.java | 8 ++++- .../main/java/org/woped/file/p2t/P2TUI.java | 32 ++++++++++++++++--- .../qualanalysis/p2t/WebServiceThread.java | 1 - 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java b/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java index 4c69b5d4b..1f312faf4 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java @@ -11,10 +11,14 @@ import org.json.simple.JSONArray; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; +import org.woped.core.utilities.LoggerManager; +import org.woped.editor.Constants; public class ApiHelper { public static List fetchModels(String apiKey) throws IOException, ParseException { + LoggerManager.info(Constants.EDITOR_LOGGER,"Started Fetching GPT Models"); + String urlString = "http://localhost:8080/p2t/gptModels?apiKey=" + apiKey; List models = new ArrayList<>(); @@ -38,11 +42,13 @@ public static List fetchModels(String apiKey) throws IOException, ParseE for (Object model : modelsArray) { models.add(model.toString()); } + + LoggerManager.info(Constants.EDITOR_LOGGER,"Finished Fetching GPT Models"); } else { + LoggerManager.error(Constants.EDITOR_LOGGER, "Failed to Fetch GPT Models"); throw new IOException("Failed to fetch models. Response Code: " + responseCode + "\n" + "please check your API Key"); } - System.out.println(models); return models; } } diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 3bfed18db..60385f2be 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -15,6 +15,7 @@ import java.net.HttpURLConnection; import java.net.URL; import java.util.List; +import java.util.logging.Logger; import javax.swing.*; import org.json.simple.parser.ParseException; @@ -22,12 +23,15 @@ import org.woped.core.controller.AbstractApplicationMediator; import org.woped.core.controller.AbstractViewEvent; import org.woped.core.controller.ViewEvent; +import org.woped.core.utilities.LoggerManager; +import org.woped.editor.Constants; import org.woped.editor.action.WoPeDAction; import org.woped.editor.controller.ActionFactory; import org.woped.editor.tools.ApiHelper; import org.woped.gui.translations.Messages; public class P2TUI extends JDialog { + private JDialog loadDialog; private JTextField apiKeyField; private JTextArea promptField; @@ -68,7 +72,7 @@ private void initialize() { Dimension size = new Dimension(600, 375); this.setSize(size); - // Initialize models asynchronously + LoggerManager.info(Constants.EDITOR_LOGGER, "P2TUI initialized"); } @@ -126,7 +130,11 @@ private JPanel initializeSwitchButtonPanel() { promptField.setEnabled(enablePromptCheckBox.isSelected()); if (!enablePromptCheckBox.isSelected()) { promptField.revalidate(); + LoggerManager.info(Constants.EDITOR_LOGGER, "Prompt Editing Disabled"); + } else { + LoggerManager.info(Constants.EDITOR_LOGGER, "Prompt Editing Enabled"); } + }); // Add JComboBox @@ -141,15 +149,27 @@ private JPanel initializeSwitchButtonPanel() { fetchModelsButton.setPreferredSize(new Dimension(120, 25)); fetchModelsButton.setVisible(false); // Initially hidden fetchModelsButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - fetchAndFillModels(); - }} + public void actionPerformed(ActionEvent e) { + fetchAndFillModels(); + } + } ); showAgainCheckBox = new JCheckBox(Messages.getString("P2T.popup.show.again.title")); showAgainCheckBox.setToolTipText("Durch das Entfernen dieses Hakens wird das Popup-Fenster nicht erneut angezeigt, der Client merkt sich jedoch den zuletzt ausgewählten Modus," + "unter den NLP Einstellungen kann das Fenster wieder aktiviert werden"); showAgainCheckBox.setSelected(ConfigurationManager.getConfiguration().getGptShowAgain()); + showAgainCheckBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (showAgainCheckBox.isSelected()) { + LoggerManager.info(Constants.EDITOR_LOGGER,"Show Again Checkbox Selected"); + } + else { + LoggerManager.info(Constants.EDITOR_LOGGER,"Show Again Checkbox not Selected"); + } + } + }); apiKeyLabel.setVisible(false); apiKeyField.setText(ConfigurationManager.getConfiguration().getGptApiKey()); apiKeyField.setVisible(false); @@ -177,6 +197,8 @@ public void actionPerformed(ActionEvent e) { showAgainCheckBox.setVisible(true); apiKeyField.requestFocusInWindow(); + + LoggerManager.info(Constants.EDITOR_LOGGER, "LLM Service Selected"); }); oldRadioButton.addActionListener(e -> { @@ -190,6 +212,8 @@ public void actionPerformed(ActionEvent e) { fetchModelsButton.setVisible(false); showAgainCheckBox.setVisible(true); + + LoggerManager.info(Constants.EDITOR_LOGGER, "Algorithm Service Selected"); }); oldRadioButton.setSelected(true); diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java index 318a703dc..f1d4b71ab 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThread.java @@ -52,7 +52,6 @@ public void run() { response = request.getResponse(); output = response.getBody(); output = output.replaceAll("\\s*\n\\s*", ""); - System.out.println(output); setText(output); isFinished = true; paraphrasingPanel.setNaturalTextParser(new Process2Text(output)); From 40273b927d2bae9627ef7af257572ff59b91e66a Mon Sep 17 00:00:00 2001 From: zbbhelen Date: Thu, 4 Jul 2024 09:58:04 +0200 Subject: [PATCH 55/76] cleanup --- WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java | 1 - 1 file changed, 1 deletion(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 60385f2be..1cff7df21 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -15,7 +15,6 @@ import java.net.HttpURLConnection; import java.net.URL; import java.util.List; -import java.util.logging.Logger; import javax.swing.*; import org.json.simple.parser.ParseException; From 8ac6196714a646756314da9ef4783ed7ac902545 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Fri, 5 Jul 2024 08:04:07 +0200 Subject: [PATCH 56/76] Initiale test for P2TUI --- .../core/config/ConfigurationManager.java | 1 + .../main/java/org/woped/file/p2t/P2TUI.java | 14 ++++- .../java/org/woped/file/p2t/P2TUITest.java | 55 +++++++++++++++++++ .../src/main/resources/Messages_de.properties | 2 +- 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java diff --git a/WoPeD-Core/src/main/java/org/woped/core/config/ConfigurationManager.java b/WoPeD-Core/src/main/java/org/woped/core/config/ConfigurationManager.java index 90091d32a..d32a84e2d 100644 --- a/WoPeD-Core/src/main/java/org/woped/core/config/ConfigurationManager.java +++ b/WoPeD-Core/src/main/java/org/woped/core/config/ConfigurationManager.java @@ -33,4 +33,5 @@ public static boolean hasNonStaticMetricsConfiguration() { if (metricsConfiguration != null) return true; else return false; } + } diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 1cff7df21..3abeac946 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -42,6 +42,10 @@ public class P2TUI extends JDialog { private static final String DEFAULT_PROMPT = Messages.getString("P2T.prompt.text"); + public P2TUI() { + initialize(); + } + public P2TUI(AbstractApplicationMediator mediator) { this(null, mediator); } @@ -51,7 +55,7 @@ public P2TUI(Frame owner, AbstractApplicationMediator mediator) throws HeadlessE initialize(); } - private void initialize() { + void initialize() { this.setVisible(false); this.getContentPane().setLayout(new BorderLayout()); this.setUndecorated(false); @@ -75,7 +79,7 @@ private void initialize() { } - private JPanel initializeSwitchButtonPanel() { + JPanel initializeSwitchButtonPanel() { JPanel switchButtonPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); @@ -394,4 +398,10 @@ private void showErrorPopUp(String titleId, String msgId) { JOptionPane.showOptionDialog(null, msg, title, optionType, messageType, null, text, text[0]); } + + public Object getApiKeyField() { + return apiKeyField; + } + + } diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java new file mode 100644 index 000000000..9110dcbcf --- /dev/null +++ b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java @@ -0,0 +1,55 @@ +package org.woped.file.p2t; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.woped.core.config.ConfigurationManager; +import org.woped.core.config.IGeneralConfiguration; +import org.woped.core.controller.AbstractApplicationMediator; +import org.woped.gui.translations.Messages; + +import javax.swing.*; + +import java.awt.*; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +public class P2TUITest { + + private P2TUI p2tui; + private MockedStatic messagesMock; + private MockedStatic configManagerMock; + + + @BeforeEach + public void setUp() { + p2tui = new P2TUI(); + // Mock the static Messages class + messagesMock = mockStatic(Messages.class); + messagesMock.when(() -> Messages.getString("P2T.openP2T.text")).thenReturn("Prozess zu Text"); + messagesMock.when(() -> Messages.getString("P2T.oldservice.title")).thenReturn("Algorithmus"); + messagesMock.when(() -> Messages.getString("P2T.newservice.title")).thenReturn("LLM"); + messagesMock.when(() -> Messages.getString("P2T.apikey.title")).thenReturn("API Schl\\u00FCssel"); + messagesMock.when(() -> Messages.getString("P2T.prompt.title")).thenReturn("Prompt"); + messagesMock.when(() -> Messages.getString("P2T.prompt.checkbox.enable.title")).thenReturn("Bearbeitung aktivieren"); + messagesMock.when(() -> Messages.getString("P2T.get.GPTmodel.title")).thenReturn("GPT-Model:"); + messagesMock.when(() -> Messages.getString("P2T.popup.show.again.title")).thenReturn("Erneut anzeigen"); + + } + + @Test + public void testInitialize() { + assertFalse(p2tui.isVisible(), "P2TUI should be visible"); + assertTrue(p2tui.getLayout() instanceof BorderLayout, "P2TUI layout should be BorderLayout"); + assertFalse(p2tui.isUndecorated(), "P2TUI shouldn't be undecorated"); + assertTrue(p2tui.isResizable(), "P2TUI should be resizable"); + + assertEquals(Messages.getString("P2T.openP2T.text"), p2tui.getTitle(), "P2TUI title should be 'Open P2T'"); + + // Überprüfe die Größe des Dialogs + assertEquals(new Dimension(600, 375), p2tui.getSize(), "Dialog should have size 600x375"); + + } +i} \ No newline at end of file diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index a46165611..68a6ac836 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -469,7 +469,7 @@ DataOutput.textBandTitle = Ausgabe #************* P2T.textBandTitle = NLP Tools P2T.text = In Text umwandeln -P2T.openP2T.text = Process zu Text +P2T.openP2T.text = Prozess zu Text P2T.openP2T.header = Eingabetext P2T.tooltip = Textuelle Beschreibung erzeugen P2T.loading = Erzeuge Text... From 595e37e4869b53797332b843f1f4343253f9a033 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Fri, 5 Jul 2024 08:06:23 +0200 Subject: [PATCH 57/76] Remove accidental character --- .../src/test/java/org/woped/file/p2t/P2TUITest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java index 9110dcbcf..b5ce480c4 100644 --- a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java +++ b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java @@ -48,8 +48,7 @@ public void testInitialize() { assertEquals(Messages.getString("P2T.openP2T.text"), p2tui.getTitle(), "P2TUI title should be 'Open P2T'"); - // Überprüfe die Größe des Dialogs assertEquals(new Dimension(600, 375), p2tui.getSize(), "Dialog should have size 600x375"); } -i} \ No newline at end of file +} \ No newline at end of file From 1c925986e4e7bc319fde901d662b18e4e76e7eb0 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Fri, 5 Jul 2024 08:52:39 +0200 Subject: [PATCH 58/76] Add tests for initializeSwitchButtonPanel Co-authored-by: TimU02 --- .../java/org/woped/file/p2t/P2TUITest.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java index b5ce480c4..c0ef2dc78 100644 --- a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java +++ b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java @@ -9,10 +9,12 @@ import org.woped.core.controller.AbstractApplicationMediator; import org.woped.gui.translations.Messages; + import javax.swing.*; import java.awt.*; +import static org.junit.Assert.assertThat; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; @@ -51,4 +53,63 @@ public void testInitialize() { assertEquals(new Dimension(600, 375), p2tui.getSize(), "Dialog should have size 600x375"); } + + @Test + public void initializeSwitchButtonPanel() { + JPanel switchButtonPanel = p2tui.initializeSwitchButtonPanel(); + assertNotNull(switchButtonPanel, "SwitchButtonPanel should be null"); + assertTrue(switchButtonPanel.getLayout() instanceof GridBagLayout, "Layout should be GridBagLayout"); + + Component[] components = switchButtonPanel.getComponents(); + assertEquals(2, components.length, "SwitchButtonPanel should have 2 components"); + + JPanel radioPanel = (JPanel) components[0]; + assertEquals(2, radioPanel.getComponentCount()); + + JRadioButton oldRadioButton = (JRadioButton) radioPanel.getComponent(0); + JRadioButton newRadioButton = (JRadioButton) radioPanel.getComponent(1); + + assertEquals(Messages.getString("P2T.oldservice.title"), oldRadioButton.getText(), "Old service radio button should have text 'Algorithmus'"); + assertEquals(Messages.getString("P2T.newservice.title"), newRadioButton.getText(), "New service radio button should have text 'LLM'"); + + JPanel fieldsPanel = (JPanel) components[1]; + assertTrue(fieldsPanel.getComponentCount() > 0, "Fields panel should have at least one component"); + + JLabel apiKeyLabel = (JLabel) fieldsPanel.getComponent(0); + assertNotNull(apiKeyLabel, "apiKeyLabel should not be null"); + assertEquals(Messages.getString("P2T.apikey.title") + ":", apiKeyLabel.getText(), "apiKeyLabel text should be correct"); + + JTextField apiKeyField = (JTextField) fieldsPanel.getComponent(1); + assertNotNull(apiKeyField, "apiKeyField should not be null"); + assertEquals(new Dimension(300, 25), apiKeyField.getPreferredSize(), "apiKeyField preferred size should be correct"); + + JLabel promptLabel = (JLabel) fieldsPanel.getComponent(2); + assertNotNull(promptLabel, "promptLabel should not be null"); + assertEquals(Messages.getString("P2T.prompt.title") + ":", promptLabel.getText(), "promptLabel text should be correct"); + + JScrollPane promptScrollPane = (JScrollPane) fieldsPanel.getComponent(3); + assertNotNull(promptScrollPane, "promptScrollPane should not be null"); + assertEquals(new Dimension(200, 100), promptScrollPane.getPreferredSize(), "promptScrollPane preferred size should be correct"); + + JCheckBox enablePromptCheckBox = (JCheckBox) fieldsPanel.getComponent(4); + assertNotNull(enablePromptCheckBox, "enablePromptCheckBox should not be null"); + assertFalse(enablePromptCheckBox.isSelected(), "enablePromptCheckBox should not be selected"); + + JLabel gptModelLabel = (JLabel) fieldsPanel.getComponent(5); + assertNotNull(gptModelLabel, "gptModelLabel should not be null"); + + JComboBox modelComboBox = (JComboBox) fieldsPanel.getComponent(6); + assertNotNull(modelComboBox, "modelComboBox should not be null"); + + JButton fetchModelsButton = (JButton) fieldsPanel.getComponent(7); + assertNotNull(fetchModelsButton, "fetchModelsButton should not be null"); + assertEquals("fetchModels", fetchModelsButton.getText(), "fetchModelsButton text should be correct"); + + JCheckBox showAgainCheckBox = (JCheckBox) fieldsPanel.getComponent(8); + assertNotNull(showAgainCheckBox, "showAgainCheckBox should not be null"); + assertEquals(Messages.getString("P2T.popup.show.again.title"), showAgainCheckBox.getText(), "showAgainCheckBox text should be correct"); + assertEquals(ConfigurationManager.getConfiguration().getGptShowAgain(), showAgainCheckBox.isSelected(), "showAgainCheckBox selected state should be correct"); + } + + } \ No newline at end of file From ec3870af941da2144e8ba13475865dafe0e350d6 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Fri, 5 Jul 2024 09:36:50 +0200 Subject: [PATCH 59/76] Finalize test for initializeSwitchButtonPanel Co-authored-by: TimU02 --- .../main/java/org/woped/file/p2t/P2TUI.java | 8 +-- .../java/org/woped/file/p2t/P2TUITest.java | 52 +++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 3abeac946..07ebea2a1 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -55,6 +55,10 @@ public P2TUI(Frame owner, AbstractApplicationMediator mediator) throws HeadlessE initialize(); } + public Object getApiKeyField() { + return apiKeyField; + } + void initialize() { this.setVisible(false); this.getContentPane().setLayout(new BorderLayout()); @@ -399,9 +403,5 @@ private void showErrorPopUp(String titleId, String msgId) { JOptionPane.showOptionDialog(null, msg, title, optionType, messageType, null, text, text[0]); } - public Object getApiKeyField() { - return apiKeyField; - } - } diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java index c0ef2dc78..bef266ec6 100644 --- a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java +++ b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java @@ -1,5 +1,6 @@ package org.woped.file.p2t; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; @@ -41,6 +42,12 @@ public void setUp() { } + @AfterEach + public void tearDown() { + // Close the static mock + messagesMock.close(); + } + @Test public void testInitialize() { assertFalse(p2tui.isVisible(), "P2TUI should be visible"); @@ -91,6 +98,16 @@ public void initializeSwitchButtonPanel() { assertNotNull(promptScrollPane, "promptScrollPane should not be null"); assertEquals(new Dimension(200, 100), promptScrollPane.getPreferredSize(), "promptScrollPane preferred size should be correct"); + JTextArea promptField = (JTextArea) promptScrollPane.getViewport().getView(); + assertNotNull(promptField, "promptField should not be null"); + + assertTrue(promptField.getLineWrap(), "promptField line wrap should be enabled"); + assertTrue(promptField.getWrapStyleWord(), "promptField wrap style should be word"); + + assertFalse(promptField.isEnabled(), "promptField should be disabled"); + assertEquals(5, promptField.getRows(), "promptField rows should be 5"); + + JCheckBox enablePromptCheckBox = (JCheckBox) fieldsPanel.getComponent(4); assertNotNull(enablePromptCheckBox, "enablePromptCheckBox should not be null"); assertFalse(enablePromptCheckBox.isSelected(), "enablePromptCheckBox should not be selected"); @@ -109,6 +126,41 @@ public void initializeSwitchButtonPanel() { assertNotNull(showAgainCheckBox, "showAgainCheckBox should not be null"); assertEquals(Messages.getString("P2T.popup.show.again.title"), showAgainCheckBox.getText(), "showAgainCheckBox text should be correct"); assertEquals(ConfigurationManager.getConfiguration().getGptShowAgain(), showAgainCheckBox.isSelected(), "showAgainCheckBox selected state should be correct"); + + // Simulate selecting the new radio button + newRadioButton.doClick(); + assertTrue(apiKeyLabel.isVisible(), "apiKeyLabel should be visible after selecting new service"); + assertTrue(apiKeyField.isVisible(), "apiKeyField should be visible after selecting new service"); + assertTrue(promptLabel.isVisible(), "promptLabel should be visible after selecting new service"); + assertTrue(promptScrollPane.isVisible(), "promptScrollPane should be visible after selecting new service"); + assertTrue(enablePromptCheckBox.isVisible(), "enablePromptCheckBox should be visible after selecting new service"); + assertTrue(gptModelLabel.isVisible(), "gptModelLabel should be visible after selecting new service"); + assertTrue(modelComboBox.isVisible(), "modelComboBox should be visible after selecting new service"); + assertTrue(fetchModelsButton.isVisible(), "fetchModelsButton should be visible after selecting new service"); + + // Simulate selecting the old radio button + oldRadioButton.doClick(); + assertFalse(apiKeyLabel.isVisible(), "apiKeyLabel should be hidden after selecting old service"); + assertFalse(apiKeyField.isVisible(), "apiKeyField should be hidden after selecting old service"); + assertFalse(promptLabel.isVisible(), "promptLabel should be hidden after selecting old service"); + assertFalse(promptScrollPane.isVisible(), "promptScrollPane should be hidden after selecting old service"); + assertFalse(enablePromptCheckBox.isVisible(), "enablePromptCheckBox should be hidden after selecting old service"); + assertFalse(gptModelLabel.isVisible(), "gptModelLabel should be hidden after selecting old service"); + assertFalse(modelComboBox.isVisible(), "modelComboBox should be hidden after selecting old service"); + assertFalse(fetchModelsButton.isVisible(), "fetchModelsButton should be hidden after selecting old service"); + + showAgainCheckBox.doClick(); + assertFalse(showAgainCheckBox.isSelected(), "showAgainCheckBox should be unchecked after click"); + showAgainCheckBox.doClick(); + assertTrue(showAgainCheckBox.isSelected(), "showAgainCheckBox should be checked after click"); + + // Test enablePromptCheckBox + // Simulate enabling prompt editing + enablePromptCheckBox.doClick(); + assertTrue(promptField.isEnabled(), "promptField should be enabled after checking enablePromptCheckBox"); + // Simulate disabling prompt editing + enablePromptCheckBox.doClick(); + assertFalse(promptField.isEnabled(), "promptField should be disabled after unchecking enablePromptCheckBox"); } From d735e13cdb71d8ec667801df7d1cfcf8826a3ff7 Mon Sep 17 00:00:00 2001 From: zbbhelen Date: Fri, 5 Jul 2024 09:47:00 +0200 Subject: [PATCH 60/76] add test for IsAPIKeyValid --- .../java/org/woped/file/p2t/P2TUITest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java index bef266ec6..ae221ab05 100644 --- a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java +++ b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java @@ -3,6 +3,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; import org.woped.core.config.ConfigurationManager; @@ -163,5 +164,25 @@ public void initializeSwitchButtonPanel() { assertFalse(promptField.isEnabled(), "promptField should be disabled after unchecking enablePromptCheckBox"); } + @Test + public void testIsAPIKeyValid_withValidKey() { + String validApiKey = "your_actual_valid_api_key"; + + boolean isValid = p2tui.isAPIKeyValid(validApiKey); + + assertTrue(isValid); + } + + @Test + public void testIsAPIKeyValid_withInvalidKey() { + String invalidApiKey = "invalidApiKey"; + + boolean isValid = p2tui.isAPIKeyValid(invalidApiKey); + + assertFalse(isValid); + } + + + } \ No newline at end of file From f4e0f290bcd3bd5f73e9cd4b5a6bfefb5f973d85 Mon Sep 17 00:00:00 2001 From: zbbhelen Date: Fri, 5 Jul 2024 09:50:07 +0200 Subject: [PATCH 61/76] add Test for ValidateAPIKey --- .../java/org/woped/file/p2t/P2TUITest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java index ae221ab05..bf8c4bee8 100644 --- a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java +++ b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java @@ -25,6 +25,8 @@ public class P2TUITest { private P2TUI p2tui; private MockedStatic messagesMock; private MockedStatic configManagerMock; + @Mock + private JTextField mockApiKeyField; @BeforeEach @@ -182,6 +184,24 @@ public void testIsAPIKeyValid_withInvalidKey() { assertFalse(isValid); } + @Test + public void testValidateAPIKey_withValidKey() { + when(mockApiKeyField.getText()).thenReturn("your_actual_valid_api_key"); + + boolean isValid = p2tui.validateAPIKey(); + + assertTrue(isValid); + } + + @Test + public void testValidateAPIKey_withInvalidKey() { + when(mockApiKeyField.getText()).thenReturn("invalidApiKey"); + + boolean isValid = p2tui.validateAPIKey(); + + assertFalse(isValid); + } + From c9b4f8520b5c6377bd20192edd689aa9c0b0f3a0 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Fri, 5 Jul 2024 10:32:27 +0200 Subject: [PATCH 62/76] Delete api key tests --- .../java/org/woped/file/p2t/P2TUITest.java | 49 ++----------------- 1 file changed, 5 insertions(+), 44 deletions(-) diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java index bf8c4bee8..b5d3dbf40 100644 --- a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java +++ b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java @@ -3,18 +3,21 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; import org.woped.core.config.ConfigurationManager; import org.woped.core.config.IGeneralConfiguration; -import org.woped.core.controller.AbstractApplicationMediator; +import org.woped.core.controller.AbstractViewEvent; +import org.woped.core.controller.ViewEvent; +import org.woped.editor.action.WoPeDAction; +import org.woped.editor.controller.ActionFactory; import org.woped.gui.translations.Messages; import javax.swing.*; import java.awt.*; +import java.awt.event.KeyEvent; import static org.junit.Assert.assertThat; import static org.junit.jupiter.api.Assertions.*; @@ -25,8 +28,6 @@ public class P2TUITest { private P2TUI p2tui; private MockedStatic messagesMock; private MockedStatic configManagerMock; - @Mock - private JTextField mockApiKeyField; @BeforeEach @@ -165,44 +166,4 @@ public void initializeSwitchButtonPanel() { enablePromptCheckBox.doClick(); assertFalse(promptField.isEnabled(), "promptField should be disabled after unchecking enablePromptCheckBox"); } - - @Test - public void testIsAPIKeyValid_withValidKey() { - String validApiKey = "your_actual_valid_api_key"; - - boolean isValid = p2tui.isAPIKeyValid(validApiKey); - - assertTrue(isValid); - } - - @Test - public void testIsAPIKeyValid_withInvalidKey() { - String invalidApiKey = "invalidApiKey"; - - boolean isValid = p2tui.isAPIKeyValid(invalidApiKey); - - assertFalse(isValid); - } - - @Test - public void testValidateAPIKey_withValidKey() { - when(mockApiKeyField.getText()).thenReturn("your_actual_valid_api_key"); - - boolean isValid = p2tui.validateAPIKey(); - - assertTrue(isValid); - } - - @Test - public void testValidateAPIKey_withInvalidKey() { - when(mockApiKeyField.getText()).thenReturn("invalidApiKey"); - - boolean isValid = p2tui.validateAPIKey(); - - assertFalse(isValid); - } - - - - } \ No newline at end of file From 7c5dcc5eaa43200fdd4f140f696f80464e280864 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Fri, 5 Jul 2024 10:35:14 +0200 Subject: [PATCH 63/76] Add test for SingleButtonPanel Co-authored-by: TimU02 --- .../src/main/java/org/woped/file/p2t/P2TUI.java | 2 +- .../src/test/java/org/woped/file/p2t/P2TUITest.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 07ebea2a1..a91aa4a05 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -290,7 +290,7 @@ public void actionPerformed(ActionEvent e) { return switchButtonPanel; } - private JPanel initializeSingleButtonPanel() { + JPanel initializeSingleButtonPanel() { JPanel buttonPanel = new JPanel(new BorderLayout()); buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java index b5d3dbf40..ea2ae2498 100644 --- a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java +++ b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java @@ -166,4 +166,17 @@ public void initializeSwitchButtonPanel() { enablePromptCheckBox.doClick(); assertFalse(promptField.isEnabled(), "promptField should be disabled after unchecking enablePromptCheckBox"); } + + @Test + public void testInitializeSingleButtonPanel(){ + JPanel buttonPanel = p2tui.initializeSingleButtonPanel(); + assertNotNull(buttonPanel, "ButtonPanel should not be null"); + assertTrue(buttonPanel.getLayout() instanceof BorderLayout, "ButtonPanel layout should be BorderLayout"); + + JButton singleButton = (JButton) buttonPanel.getComponent(0); + assertNotNull(singleButton, "SingleButton should not be null"); + assertTrue(singleButton.getMnemonic() == KeyEvent.VK_A, "SingleButton mnemonic should be correct"); + assertEquals(Messages.getString("P2T.text"), singleButton.getText(), "SingleButton text should be correct"); + + } } \ No newline at end of file From 9a8303bc90182ef0891b9fd3db1e302759b0a95a Mon Sep 17 00:00:00 2001 From: anneke02 Date: Fri, 5 Jul 2024 10:41:03 +0200 Subject: [PATCH 64/76] Add test for executeAction in P2TUI Co-authored-by: TimU02 --- .../src/main/java/org/woped/file/p2t/P2TUI.java | 2 +- .../test/java/org/woped/file/p2t/P2TUITest.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index a91aa4a05..2e3e5639c 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -331,7 +331,7 @@ JPanel initializeSingleButtonPanel() { return buttonPanel; } - private void executeAction() { + void executeAction() { WoPeDAction action = ActionFactory.getStaticAction(ActionFactory.ACTIONID_P2T_OLD); action.actionPerformed(new ViewEvent(this, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.P2T, null)); } diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java index ea2ae2498..35b984650 100644 --- a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java +++ b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java @@ -179,4 +179,21 @@ public void testInitializeSingleButtonPanel(){ assertEquals(Messages.getString("P2T.text"), singleButton.getText(), "SingleButton text should be correct"); } + + @Test + public void testExecuteAction() { + // Mock ActionFactory.getStaticAction to return a mocked WoPeDAction + WoPeDAction mockedAction = mock(WoPeDAction.class); + try (MockedStatic mockedStatic = mockStatic(ActionFactory.class)) { + mockedStatic.when(() -> ActionFactory.getStaticAction(ActionFactory.ACTIONID_P2T_OLD)).thenReturn(mockedAction); + ViewEvent expectedViewEvent = new ViewEvent(p2tui, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.P2T, null); + p2tui.executeAction(); + mockedStatic.verify(() -> ActionFactory.getStaticAction(ActionFactory.ACTIONID_P2T_OLD)); + + verify(mockedAction).actionPerformed(argThat(actionEvent -> + actionEvent.getSource() == expectedViewEvent.getSource() && + actionEvent.getID() == expectedViewEvent.getID() + )); + } + } } \ No newline at end of file From 7db307a95c1e718d2463da091056efae74c1c335 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Fri, 5 Jul 2024 11:10:55 +0200 Subject: [PATCH 65/76] Added api key valid test method for invalid case --- .../main/java/org/woped/file/p2t/P2TUI.java | 3 +- .../java/org/woped/file/p2t/P2TUITest.java | 32 ++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 2e3e5639c..e11a21011 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -336,7 +336,7 @@ void executeAction() { action.actionPerformed(new ViewEvent(this, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.P2T, null)); } - private void fetchAndFillModels() { + void fetchAndFillModels() { new Thread(() -> { try { List models = ApiHelper.fetchModels(apiKeyField.getText()); @@ -403,5 +403,4 @@ private void showErrorPopUp(String titleId, String msgId) { JOptionPane.showOptionDialog(null, msg, title, optionType, messageType, null, text, text[0]); } - } diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java index 35b984650..aa6129f8f 100644 --- a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java +++ b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java @@ -1,5 +1,6 @@ package org.woped.file.p2t; +import org.junit.Assert; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -11,6 +12,7 @@ import org.woped.core.controller.ViewEvent; import org.woped.editor.action.WoPeDAction; import org.woped.editor.controller.ActionFactory; +import org.woped.editor.tools.ApiHelper; import org.woped.gui.translations.Messages; @@ -18,6 +20,11 @@ import java.awt.*; import java.awt.event.KeyEvent; +import java.io.IOException; +import java.text.ParseException; +import java.util.Arrays; +import java.util.List; + import static org.junit.Assert.assertThat; import static org.junit.jupiter.api.Assertions.*; @@ -28,11 +35,13 @@ public class P2TUITest { private P2TUI p2tui; private MockedStatic messagesMock; private MockedStatic configManagerMock; - + private MockedStatic apiHelperMock; @BeforeEach public void setUp() { p2tui = new P2TUI(); + + apiHelperMock = mockStatic(ApiHelper.class); // Mock the static Messages class messagesMock = mockStatic(Messages.class); messagesMock.when(() -> Messages.getString("P2T.openP2T.text")).thenReturn("Prozess zu Text"); @@ -181,19 +190,12 @@ public void testInitializeSingleButtonPanel(){ } @Test - public void testExecuteAction() { - // Mock ActionFactory.getStaticAction to return a mocked WoPeDAction - WoPeDAction mockedAction = mock(WoPeDAction.class); - try (MockedStatic mockedStatic = mockStatic(ActionFactory.class)) { - mockedStatic.when(() -> ActionFactory.getStaticAction(ActionFactory.ACTIONID_P2T_OLD)).thenReturn(mockedAction); - ViewEvent expectedViewEvent = new ViewEvent(p2tui, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.P2T, null); - p2tui.executeAction(); - mockedStatic.verify(() -> ActionFactory.getStaticAction(ActionFactory.ACTIONID_P2T_OLD)); - - verify(mockedAction).actionPerformed(argThat(actionEvent -> - actionEvent.getSource() == expectedViewEvent.getSource() && - actionEvent.getID() == expectedViewEvent.getID() - )); - } + public void testIsAPIKeyValid_withInvalidKey() { + String invalidApiKey = "invalidApiKey"; + + boolean isValid = p2tui.isAPIKeyValid(invalidApiKey); + + assertFalse(isValid); } + } \ No newline at end of file From 3f0364cf87c799a9db918db5043dfa459c8390eb Mon Sep 17 00:00:00 2001 From: TimU02 Date: Fri, 5 Jul 2024 11:18:34 +0200 Subject: [PATCH 66/76] Delete unused methods --- .../main/java/org/woped/file/p2t/P2TUI.java | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index e11a21011..7ea0e33f6 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -55,10 +55,6 @@ public P2TUI(Frame owner, AbstractApplicationMediator mediator) throws HeadlessE initialize(); } - public Object getApiKeyField() { - return apiKeyField; - } - void initialize() { this.setVisible(false); this.getContentPane().setLayout(new BorderLayout()); @@ -380,27 +376,4 @@ public static boolean isAPIKeyValid(String apiKey) { } } - private void showLoadingBox() { - JOptionPane jop = new JOptionPane(); - jop.setMessageType(JOptionPane.INFORMATION_MESSAGE); - jop.setMessage(Messages.getString("P2TUI.Loading.Text")); - - loadDialog = jop.createDialog(this, Messages.getString("P2TUI.Loading.Title")); - jop.setOptions(new String[]{Messages.getString("P2TUI.Loading.Cancel")}); - loadDialog.setVisible(true); - - // Thread gets blocked and awaits an UI action. - } - - private void showErrorPopUp(String titleId, String msgId) { - String text[] = {Messages.getString("Dialog.Ok")}; - - String msg = Messages.getStringReplaced(msgId, null); - String title = Messages.getString(titleId); - int optionType = JOptionPane.YES_NO_CANCEL_OPTION; - int messageType = JOptionPane.ERROR_MESSAGE; - - JOptionPane.showOptionDialog(null, msg, title, optionType, messageType, null, text, text[0]); - } - } From edcb43872c5efde4c0aec0c0bb1eea4a9d580672 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Fri, 5 Jul 2024 11:22:03 +0200 Subject: [PATCH 67/76] Refactor test for P2TUI methods --- .../java/org/woped/file/p2t/P2TUITest.java | 27 ++++--------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java index aa6129f8f..948ce28cc 100644 --- a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java +++ b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java @@ -1,32 +1,16 @@ package org.woped.file.p2t; -import org.junit.Assert; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; -import org.mockito.Mockito; import org.woped.core.config.ConfigurationManager; -import org.woped.core.config.IGeneralConfiguration; -import org.woped.core.controller.AbstractViewEvent; -import org.woped.core.controller.ViewEvent; -import org.woped.editor.action.WoPeDAction; -import org.woped.editor.controller.ActionFactory; import org.woped.editor.tools.ApiHelper; import org.woped.gui.translations.Messages; - - import javax.swing.*; - import java.awt.*; import java.awt.event.KeyEvent; -import java.io.IOException; -import java.text.ParseException; -import java.util.Arrays; -import java.util.List; - - -import static org.junit.Assert.assertThat; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; @@ -34,15 +18,15 @@ public class P2TUITest { private P2TUI p2tui; private MockedStatic messagesMock; - private MockedStatic configManagerMock; - private MockedStatic apiHelperMock; @BeforeEach public void setUp() { p2tui = new P2TUI(); - apiHelperMock = mockStatic(ApiHelper.class); - // Mock the static Messages class + initializeMockMessages(); + } + + private void initializeMockMessages() { messagesMock = mockStatic(Messages.class); messagesMock.when(() -> Messages.getString("P2T.openP2T.text")).thenReturn("Prozess zu Text"); messagesMock.when(() -> Messages.getString("P2T.oldservice.title")).thenReturn("Algorithmus"); @@ -52,7 +36,6 @@ public void setUp() { messagesMock.when(() -> Messages.getString("P2T.prompt.checkbox.enable.title")).thenReturn("Bearbeitung aktivieren"); messagesMock.when(() -> Messages.getString("P2T.get.GPTmodel.title")).thenReturn("GPT-Model:"); messagesMock.when(() -> Messages.getString("P2T.popup.show.again.title")).thenReturn("Erneut anzeigen"); - } @AfterEach From b0e8ea554a3b6ff5004e2a75f37a5f99b203a2e8 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Fri, 5 Jul 2024 11:22:29 +0200 Subject: [PATCH 68/76] Remove unused import --- .../src/test/java/org/woped/file/p2t/P2TUITest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java index 948ce28cc..4e0ab5a8c 100644 --- a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java +++ b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java @@ -6,7 +6,6 @@ import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; import org.woped.core.config.ConfigurationManager; -import org.woped.editor.tools.ApiHelper; import org.woped.gui.translations.Messages; import javax.swing.*; import java.awt.*; From 289028805c667f8d425c2b8ba3d46b261fc29012 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Fri, 5 Jul 2024 11:56:39 +0200 Subject: [PATCH 69/76] Refactoring minor refactoring --- .../java/org/woped/editor/controller/ActionFactory.java | 8 ++++---- .../org/woped/qualanalysis/p2t/WebServiceThreadLLM.java | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/controller/ActionFactory.java b/WoPeD-Editor/src/main/java/org/woped/editor/controller/ActionFactory.java index 7e1dfd7d2..7d01a5683 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/controller/ActionFactory.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/controller/ActionFactory.java @@ -63,7 +63,7 @@ public class ActionFactory { public static final String ACTIONID_P2T = "ToolBar.P2T"; - public static final String ACTIONID_P2t_NEW = "Ausführen.Neu"; + public static final String ACTIONID_P2T_NEW = "Ausführen.Neu"; public static final String ACTIONID_P2T_OLD = "Ausführen"; public static final String ACTIONID_T2P = "ToolBar.T2P"; @@ -666,12 +666,12 @@ public static HashMap createStaticActions(ApplicationMediat VisualController.P2T); STATIC_ACTION_MAP.put( - ACTIONID_P2t_NEW, + ACTIONID_P2T_NEW, new WoPeDAction( - am, AbstractViewEvent.VIEWEVENTTYPE_EDIT, AbstractViewEvent.P2T, null, ACTIONID_P2t_NEW)); + am, AbstractViewEvent.VIEWEVENTTYPE_EDIT, AbstractViewEvent.P2T, null, ACTIONID_P2T_NEW)); VisualController.getInstance() .addElement( - STATIC_ACTION_MAP.get(ACTIONID_P2t_NEW), + STATIC_ACTION_MAP.get(ACTIONID_P2T_NEW), VisualController.WITH_EDITOR, VisualController.WITH_EDITOR, VisualController.P2T); diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java index 273e53562..8d170735c 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java @@ -12,6 +12,7 @@ import org.woped.core.config.ConfigurationManager; import org.woped.core.controller.IEditor; +import org.woped.core.utilities.LoggerManager; import org.woped.gui.translations.Messages; public class WebServiceThreadLLM extends Thread { @@ -37,6 +38,8 @@ public void run() { prompt = ConfigurationManager.getConfiguration().getGptPrompt(); gptModel = ConfigurationManager.getConfiguration().getGptModel(); + LoggerManager.info(Constants.EDITOR_LOGGER,"Started Fetching GPT Models"); + IEditor editor = paraphrasingPanel.getEditor(); paraphrasingPanel.showLoadingAnimation(true); From 4e34f9f909e574fd06f1df6f457ccb15b48a3677 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Fri, 5 Jul 2024 12:02:30 +0200 Subject: [PATCH 70/76] Add doc and JavaDoc to P2TUI and tests --- .../main/java/org/woped/file/p2t/P2TUI.java | 51 +++++++++++++++++++ .../java/org/woped/file/p2t/P2TUITest.java | 8 +++ 2 files changed, 59 insertions(+) diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 7ea0e33f6..6fa3f3fbf 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -55,6 +55,14 @@ public P2TUI(Frame owner, AbstractApplicationMediator mediator) throws HeadlessE initialize(); } + /** + * Initialize the dialog + *

+ * The dialog is initialized with a switch button panel at the top and a single button panel at the bottom. + * The switch button panel contains a radio button group to switch between the old and new services. + * The single button panel contains a single button to execute the action. + * The dialog is initially hidden. + */ void initialize() { this.setVisible(false); this.getContentPane().setLayout(new BorderLayout()); @@ -79,6 +87,19 @@ void initialize() { } + /** + * Initialize the switch button panel + *

+ * The switch button panel contains a radio button group to switch between the old and new services. + * The new service requires an API key and a prompt text. + * The prompt text is disabled by default and can be enabled by checking the enable prompt checkbox. + * The prompt text is a text area with a default text. + * The panel also contains a JComboBox to select the GPT model. + * The panel also contains a button to fetch the available models. + * The panel also contains a checkbox to show the popup again. + * The panel is initially hidden. + * @return JPanel containing the switch button panel + */ JPanel initializeSwitchButtonPanel() { JPanel switchButtonPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); @@ -286,6 +307,12 @@ public void actionPerformed(ActionEvent e) { return switchButtonPanel; } + /** + * Initialize the single button panel + *

+ * The single button panel contains a single button to execute the action. + * @return JPanel containing the single button panel + */ JPanel initializeSingleButtonPanel() { JPanel buttonPanel = new JPanel(new BorderLayout()); buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); @@ -327,11 +354,22 @@ JPanel initializeSingleButtonPanel() { return buttonPanel; } + /** + * Execute the action + *

+ * The action is executed based on the selected radio button. + */ void executeAction() { WoPeDAction action = ActionFactory.getStaticAction(ActionFactory.ACTIONID_P2T_OLD); action.actionPerformed(new ViewEvent(this, AbstractViewEvent.VIEWEVENTTYPE_GUI, AbstractViewEvent.P2T, null)); } + /** + * Fetch and fill the models + *

+ * Fetch the models from the API and fill the models in the JComboBox. + * If the models cannot be fetched, an error message is displayed. + */ void fetchAndFillModels() { new Thread(() -> { try { @@ -350,6 +388,14 @@ void fetchAndFillModels() { }).start(); } + /** + * Validate the API key + *

+ * Validate the API key by sending a request to the API. + * If the API key is invalid, an error message is displayed. + * If the API key is valid, return true. + * @return + */ boolean validateAPIKey() { String apiKey = apiKeyField.getText(); boolean apiKeyValid = isAPIKeyValid(apiKey); @@ -359,6 +405,11 @@ boolean validateAPIKey() { return apiKeyValid; } + /** + * Check if the API key is valid + * @param apiKey API key + * @return true if the API key is valid, false otherwise + */ public static boolean isAPIKeyValid(String apiKey) { final String TEST_URL = "https://api.openai.com/v1/engines"; try { diff --git a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java index 4e0ab5a8c..931eec906 100644 --- a/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java +++ b/WoPeD-FileInterface/src/test/java/org/woped/file/p2t/P2TUITest.java @@ -18,6 +18,7 @@ public class P2TUITest { private P2TUI p2tui; private MockedStatic messagesMock; + // This method is called before each test @BeforeEach public void setUp() { p2tui = new P2TUI(); @@ -25,6 +26,7 @@ public void setUp() { initializeMockMessages(); } + // This method initializes the mock for the Messages class private void initializeMockMessages() { messagesMock = mockStatic(Messages.class); messagesMock.when(() -> Messages.getString("P2T.openP2T.text")).thenReturn("Prozess zu Text"); @@ -37,12 +39,14 @@ private void initializeMockMessages() { messagesMock.when(() -> Messages.getString("P2T.popup.show.again.title")).thenReturn("Erneut anzeigen"); } + // This method is called after each test @AfterEach public void tearDown() { // Close the static mock messagesMock.close(); } + // This method tests the initialize method @Test public void testInitialize() { assertFalse(p2tui.isVisible(), "P2TUI should be visible"); @@ -56,6 +60,7 @@ public void testInitialize() { } + // This method tests the initializeSwitchButtonPanel method @Test public void initializeSwitchButtonPanel() { JPanel switchButtonPanel = p2tui.initializeSwitchButtonPanel(); @@ -144,6 +149,7 @@ public void initializeSwitchButtonPanel() { assertFalse(modelComboBox.isVisible(), "modelComboBox should be hidden after selecting old service"); assertFalse(fetchModelsButton.isVisible(), "fetchModelsButton should be hidden after selecting old service"); + // Simulate clicking the showAgainCheckBox showAgainCheckBox.doClick(); assertFalse(showAgainCheckBox.isSelected(), "showAgainCheckBox should be unchecked after click"); showAgainCheckBox.doClick(); @@ -158,6 +164,7 @@ public void initializeSwitchButtonPanel() { assertFalse(promptField.isEnabled(), "promptField should be disabled after unchecking enablePromptCheckBox"); } + // This method tests the initializeButtonPanel method @Test public void testInitializeSingleButtonPanel(){ JPanel buttonPanel = p2tui.initializeSingleButtonPanel(); @@ -171,6 +178,7 @@ public void testInitializeSingleButtonPanel(){ } + // This method tests the isAPIKeyValid method with an invalid key @Test public void testIsAPIKeyValid_withInvalidKey() { String invalidApiKey = "invalidApiKey"; From b25ce19ade255435efd957f8f1398c5919e70ce9 Mon Sep 17 00:00:00 2001 From: Marcel2511 Date: Sun, 7 Jul 2024 11:27:37 +0200 Subject: [PATCH 71/76] refactoring refactoring --- .../editor/gui/config/ConfNLPToolsPanel.java | 36 +++++++++---------- .../main/java/org/woped/file/p2t/P2TUI.java | 2 +- .../src/main/resources/Messages.properties | 3 +- .../src/main/resources/Messages_de.properties | 7 ++-- .../qualanalysis/p2t/WebServiceThreadLLM.java | 3 +- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java index 78141e6b8..6626a6d2d 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/gui/config/ConfNLPToolsPanel.java @@ -26,7 +26,7 @@ public class ConfNLPToolsPanel extends AbstractConfPanel { private JPanel enabledPanel = null; private JPanel settingsPanel = null; private JPanel settingsPanel_T2P = null; - private JPanel additionalPanel = null; + private JPanel settingsPanel_GPT = null; private JTextField serverURLText = null; private JLabel serverURLLabel = null; @@ -303,41 +303,41 @@ private JPanel getSettingsPanel_T2P() { } private JPanel getGPTPanel() { - if (additionalPanel == null) { - additionalPanel = new JPanel(); - additionalPanel.setLayout(new GridBagLayout()); + if (settingsPanel_GPT == null) { + settingsPanel_GPT = new JPanel(); + settingsPanel_GPT.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.WEST; c.insets = new Insets(2, 0, 2, 0); - additionalPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Messages.getString("Configuration.GPT.settings.Title")), BorderFactory.createEmptyBorder(10, 10, 10, 10))); + settingsPanel_GPT.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Messages.getString("Configuration.GPT.settings.Title")), BorderFactory.createEmptyBorder(10, 10, 10, 10))); c.weightx = 1; c.gridx = 0; c.gridy = 0; - additionalPanel.add(new JLabel(Messages.getString("Configuration.GPT.apikey.Title")), c); + settingsPanel_GPT.add(new JLabel(Messages.getString("Configuration.GPT.apikey.Title")), c); c.weightx = 1; c.gridx = 1; c.gridy = 0; - additionalPanel.add(getApiKeyText(), c); + settingsPanel_GPT.add(getApiKeyText(), c); c.weightx = 1; c.gridx = 0; c.gridy = 1; - additionalPanel.add(new JLabel(Messages.getString("Configuration.GPT.prompt.Title")), c); + settingsPanel_GPT.add(new JLabel(Messages.getString("Configuration.GPT.prompt.Title")), c); c.weightx = 1; c.gridx = 1; c.gridy = 1; c.gridwidth = 2; - additionalPanel.add(getPromptTextScrollPane(), c); + settingsPanel_GPT.add(getPromptTextScrollPane(), c); // Add the new row with the label and combo box c.weightx = 0; c.gridx = 0; c.gridy = 2; - additionalPanel.add(new JLabel(Messages.getString("Configuration.GPT.model.Title")), c); + settingsPanel_GPT.add(new JLabel(Messages.getString("Configuration.GPT.model.Title")), c); // Adjust the constraints for the combo box c.weightx = 1; @@ -346,45 +346,45 @@ private JPanel getGPTPanel() { c.gridwidth = 1; c.insets = new Insets(2, 0, 2, 12); // Add padding to the right of the combo box c.fill = GridBagConstraints.HORIZONTAL; - additionalPanel.add(getModelComboBox(), c); + settingsPanel_GPT.add(getModelComboBox(), c); // Adjust the constraints for the fetchModels button c.weightx = 0; c.gridx = 2; c.gridy = 2; c.insets = new Insets(2, 0, 2, 10); - additionalPanel.add(getFetchGPTModelsButton(), c); + settingsPanel_GPT.add(getFetchGPTModelsButton(), c); // Adjust the constraints for the show again checkbox c.weightx = 1; c.gridx = 0; c.gridy = 3; c.insets = new Insets(2, 0, 2, 0); - additionalPanel.add(getShowAgainBox(), c); + settingsPanel_GPT.add(getShowAgainBox(), c); // Adjust the constraints for the reset button c.weightx = 1; c.gridx = 2; c.gridy = 3; c.insets = new Insets(2, 0, 2, 10); // Add padding to the right of the checkbox - additionalPanel.add(getResetButton(), c); + settingsPanel_GPT.add(getResetButton(), c); // Adjust the constraints for the check connection button c.weightx = 1; c.gridx = 1; c.gridy = 3; c.insets = new Insets(2, 0, 2, 12); // Reset insets for the button - additionalPanel.add(getCheckConnectionButton(), c); + settingsPanel_GPT.add(getCheckConnectionButton(), c); } - additionalPanel.setVisible(getUseBox().isSelected()); + settingsPanel_GPT.setVisible(getUseBox().isSelected()); for (int i = 0; i < modelComboBox.getItemCount(); i++){ if (modelComboBox.getItemAt(i).equals(ConfigurationManager.getConfiguration().getGptModel())){ modelComboBox.setSelectedIndex(i); break; } } - return additionalPanel; + return settingsPanel_GPT; } private JScrollPane getPromptTextScrollPane() { @@ -441,7 +441,7 @@ public void actionPerformed(ActionEvent e) { private WopedButton getFetchGPTModelsButton(){ if (fetchGPTModelsButton == null){ fetchGPTModelsButton = new WopedButton(); - fetchGPTModelsButton.setText("fetchModels"); + fetchGPTModelsButton.setText(Messages.getString("P2T.fetchmodels.button")); fetchGPTModelsButton.setPreferredSize(new Dimension(200, 25)); fetchGPTModelsButton.addActionListener(e -> fetchAndFillModels()); } diff --git a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java index 0006502fc..d74def14d 100644 --- a/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java +++ b/WoPeD-FileInterface/src/main/java/org/woped/file/p2t/P2TUI.java @@ -174,7 +174,7 @@ JPanel initializeSwitchButtonPanel() { modelComboBox.setVisible(false); // Initially hidden // Add fetchModels Button - JButton fetchModelsButton = new JButton("fetchModels"); + JButton fetchModelsButton = new JButton(Messages.getString("P2T.fetchmodels.button")); fetchModelsButton.setPreferredSize(new Dimension(120, 25)); fetchModelsButton.setVisible(false); // Initially hidden fetchModelsButton.addActionListener(new ActionListener() { diff --git a/WoPeD-GUI/src/main/resources/Messages.properties b/WoPeD-GUI/src/main/resources/Messages.properties index 276182aa5..86334009c 100644 --- a/WoPeD-GUI/src/main/resources/Messages.properties +++ b/WoPeD-GUI/src/main/resources/Messages.properties @@ -885,6 +885,7 @@ P2T.popup.tool.tip.text = Placeholder P2T.prompt.text = Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece! P2T.exception.fail.fetch.models = Failed to fetch models: P2T.exception.fetch.models = Fetch Models +P2T.fetchmodels.button = Fetch GPT Models #************* ! Text2Process #************* @@ -1288,7 +1289,7 @@ Configuration.GPT.prompt.Title = Prompt Configuration.GPT.show.again.Title = Show again Configuration.GPT.standard.Title = Reset to standard Configuration.GPT.connection.Title = Test connection -Configuration.GPT.settings.Title = GPT Settings +Configuration.GPT.settings.Title = GPT-Settings Configuration.GPT.model.Title = GPT-Model Configuration.GPT.tool.tip.text.Title = Test Configuration.GPT.connection.successful.Title = GPT connection successful. Response Code: diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index 68a6ac836..65988c5b8 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -480,8 +480,8 @@ P2T.Error.ArcWeights.title = Textgenerierung fehlgeschlagen P2T.Error.ArcWeights.message = Das Netz verwendet Kantengewichte. \nKantengewichte werden bei der Textgenerierung nicht unterst\u00FCtzt. P2T.oldservice.title = Algorithmus P2T.newservice.title = LLM -P2T.apikey.title = API Schl\u00FCssel -P2T.apikey.invalid = API Schl\u00FCssel ist nicht valide +P2T.apikey.title = API-Schl\u00FCssel +P2T.apikey.invalid = API-Schl\u00FCssel ist nicht valide P2T.apikey.invalid.title = Validierungsfehler P2T.prompt.title = Prompt P2T.prompt.checkbox.enable.title = Bearbeitung aktivieren @@ -491,6 +491,7 @@ P2T.popup.tool.tip.text = Platzhalter P2T.prompt.text = Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece! P2T.exception.fail.fetch.models = Modelle konnten nicht abgerufen werden: P2T.exception.fetch.models = Modelle abrufen +P2T.fetchmodels.button = GPT Modelle abrufen #************* ! Text 2 Process #************* @@ -827,7 +828,7 @@ Configuration.GPT.prompt.Title = Prompt Configuration.GPT.show.again.Title = Erneut anzeigen Configuration.GPT.standard.Title = Auf Standard zur\u00FCcksetzen Configuration.GPT.connection.Title = Verbindung pr\u00FCfen -Configuration.GPT.settings.Title = GPT Einstellung +Configuration.GPT.settings.Title = GPT-Einstellungn Configuration.GPT.model.Title = GPT-Model Configuration.GPT.tool.tip.text.Title = Test Configuration.GPT.connection.successful.Title = GPT-Verbindung erfolgreich. Antwort-Code: diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java index 8d170735c..fa47fbe8f 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java @@ -38,7 +38,8 @@ public void run() { prompt = ConfigurationManager.getConfiguration().getGptPrompt(); gptModel = ConfigurationManager.getConfiguration().getGptModel(); - LoggerManager.info(Constants.EDITOR_LOGGER,"Started Fetching GPT Models"); + // LoggerManager.info(Constants.EDITOR_LOGGER,"Started Fetching GPT Models"); + IEditor editor = paraphrasingPanel.getEditor(); paraphrasingPanel.showLoadingAnimation(true); From 96d46c3bb20a27f4f69024ff6546e78519e0b8b3 Mon Sep 17 00:00:00 2001 From: TimU02 Date: Sun, 7 Jul 2024 15:04:36 +0200 Subject: [PATCH 72/76] Refactor Strings --- WoPeD-GUI/src/main/resources/Messages_de.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index 65988c5b8..c0181487d 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -486,12 +486,12 @@ P2T.apikey.invalid.title = Validierungsfehler P2T.prompt.title = Prompt P2T.prompt.checkbox.enable.title = Bearbeitung aktivieren P2T.popup.show.again.title = Erneut anzeigen -P2T.get.GPTmodel.title = GPT-Model: +P2T.get.GPTmodel.title = GPT-Modell: P2T.popup.tool.tip.text = Platzhalter P2T.prompt.text = Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece! P2T.exception.fail.fetch.models = Modelle konnten nicht abgerufen werden: P2T.exception.fetch.models = Modelle abrufen -P2T.fetchmodels.button = GPT Modelle abrufen +P2T.fetchmodels.button = GPT-Modelle abrufen #************* ! Text 2 Process #************* From a610dc83460090392fef7d8f7f0576d0fc01eaa2 Mon Sep 17 00:00:00 2001 From: TimU02 Date: Sun, 7 Jul 2024 15:11:52 +0200 Subject: [PATCH 73/76] Refactor String --- WoPeD-GUI/src/main/resources/Messages_de.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index c0181487d..2f99c4f53 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -833,7 +833,7 @@ Configuration.GPT.model.Title = GPT-Model Configuration.GPT.tool.tip.text.Title = Test Configuration.GPT.connection.successful.Title = GPT-Verbindung erfolgreich. Antwort-Code: Configuration.GPT.connection.failed.Title = GPT-Verbindung fehlgeschlagen. Antwort-Code: -Configuration.GPT.connection.test.Title = Verbindung Test +Configuration.GPT.connection.test.Title = Verbindung prüfen Configuration.GPT.connection.test.failed.Title = GPT-Verbindungstest fehlgeschlagen: From 0db9eddf0de4116c609e7dde947448099ece64c6 Mon Sep 17 00:00:00 2001 From: anneke02 Date: Sun, 7 Jul 2024 15:34:23 +0200 Subject: [PATCH 74/76] Refactor settings strings --- WoPeD-GUI/src/main/resources/Messages_de.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index 2f99c4f53..d2f20ea06 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -828,12 +828,12 @@ Configuration.GPT.prompt.Title = Prompt Configuration.GPT.show.again.Title = Erneut anzeigen Configuration.GPT.standard.Title = Auf Standard zur\u00FCcksetzen Configuration.GPT.connection.Title = Verbindung pr\u00FCfen -Configuration.GPT.settings.Title = GPT-Einstellungn +Configuration.GPT.settings.Title = GPT-Einstellungen Configuration.GPT.model.Title = GPT-Model Configuration.GPT.tool.tip.text.Title = Test Configuration.GPT.connection.successful.Title = GPT-Verbindung erfolgreich. Antwort-Code: Configuration.GPT.connection.failed.Title = GPT-Verbindung fehlgeschlagen. Antwort-Code: -Configuration.GPT.connection.test.Title = Verbindung prüfen +Configuration.GPT.connection.test.Title = Verbindung pr\u00FCfen Configuration.GPT.connection.test.failed.Title = GPT-Verbindungstest fehlgeschlagen: From 4315d241d718ef0e3f59ad0a5874b94f5016aa9b Mon Sep 17 00:00:00 2001 From: TimU02 Date: Sun, 7 Jul 2024 15:40:00 +0200 Subject: [PATCH 75/76] Refactor Strings --- .../src/main/java/org/woped/editor/tools/ApiHelper.java | 2 +- WoPeD-GUI/src/main/resources/Messages.properties | 2 +- WoPeD-GUI/src/main/resources/Messages_de.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java b/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java index 1f312faf4..d7f80663f 100644 --- a/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java +++ b/WoPeD-Editor/src/main/java/org/woped/editor/tools/ApiHelper.java @@ -47,7 +47,7 @@ public static List fetchModels(String apiKey) throws IOException, ParseE } else { LoggerManager.error(Constants.EDITOR_LOGGER, "Failed to Fetch GPT Models"); throw new IOException("Failed to fetch models. Response Code: " + responseCode + "\n" + - "please check your API Key"); + "Please check your API Key"); } return models; } diff --git a/WoPeD-GUI/src/main/resources/Messages.properties b/WoPeD-GUI/src/main/resources/Messages.properties index 86334009c..66a86212c 100644 --- a/WoPeD-GUI/src/main/resources/Messages.properties +++ b/WoPeD-GUI/src/main/resources/Messages.properties @@ -883,7 +883,7 @@ P2T.popup.show.again.title = Show again P2T.get.GPTmodel.title = GPT-Model: P2T.popup.tool.tip.text = Placeholder P2T.prompt.text = Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece! -P2T.exception.fail.fetch.models = Failed to fetch models: +P2T.exception.fail.fetch.models = Failed to fetch models: P2T.exception.fetch.models = Fetch Models P2T.fetchmodels.button = Fetch GPT Models #************* diff --git a/WoPeD-GUI/src/main/resources/Messages_de.properties b/WoPeD-GUI/src/main/resources/Messages_de.properties index d2f20ea06..6a6971587 100644 --- a/WoPeD-GUI/src/main/resources/Messages_de.properties +++ b/WoPeD-GUI/src/main/resources/Messages_de.properties @@ -489,7 +489,7 @@ P2T.popup.show.again.title = Erneut anzeigen P2T.get.GPTmodel.title = GPT-Modell: P2T.popup.tool.tip.text = Platzhalter P2T.prompt.text = Create a clearly structured and comprehensible continuous text from the given BPMN that is understandable for an uninformed reader. The text should be easy to read in the summary and contain all important content; if there are subdivided points, these are integrated into the text with suitable sentence beginnings in order to obtain a well-structured and easy-to-read text. Under no circumstances should the output contain sub-items or paragraphs, but should cover all processes in one piece! -P2T.exception.fail.fetch.models = Modelle konnten nicht abgerufen werden: +P2T.exception.fail.fetch.models = Modelle konnten nicht abgerufen werden: P2T.exception.fetch.models = Modelle abrufen P2T.fetchmodels.button = GPT-Modelle abrufen #************* From dee699c1e3da5ff76f517e2bce6466345eb395eb Mon Sep 17 00:00:00 2001 From: zbbhelen Date: Sun, 7 Jul 2024 16:41:13 +0200 Subject: [PATCH 76/76] remove unused import --- .../java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java index fa47fbe8f..f4a44b3b7 100644 --- a/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java +++ b/WoPeD-QualAnalysis/src/main/java/org/woped/qualanalysis/p2t/WebServiceThreadLLM.java @@ -12,7 +12,6 @@ import org.woped.core.config.ConfigurationManager; import org.woped.core.controller.IEditor; -import org.woped.core.utilities.LoggerManager; import org.woped.gui.translations.Messages; public class WebServiceThreadLLM extends Thread { @@ -40,7 +39,6 @@ public void run() { // LoggerManager.info(Constants.EDITOR_LOGGER,"Started Fetching GPT Models"); - IEditor editor = paraphrasingPanel.getEditor(); paraphrasingPanel.showLoadingAnimation(true); @@ -55,13 +53,11 @@ public void run() { + ConfigurationManager.getConfiguration().getProcess2TextServerURI() + "/generateTextLLM";*/ - ByteArrayOutputStream stream = new ByteArrayOutputStream(); new PNMLExport().saveToStream(editor, stream); String text = stream.toString(); String output; - try { // Encode URL parameters String encodedApiKey = URLEncoder.encode(apiKey, StandardCharsets.UTF_8);