chatbot enhancements

This commit is contained in:
Bane Stojkovic
2025-04-07 21:29:57 +02:00
parent 0c8883529d
commit 99f8030fac
6 changed files with 620 additions and 584 deletions
+9 -9
View File
@@ -836,7 +836,7 @@
<option value="-Xdock:name=DIY Layout Creator"/>
<option value="-Xdock:icon=Contents/Resources/diylc.icns"/>
</bundleapp>
<echo message="Creating unsigned zip for distribution..."/>
<!-- Create unsigned zip for distribution -->
<zip destfile="${project.build.directory}/diylc-${project.version}-osx-x86-unsigned.zip">
@@ -1027,22 +1027,22 @@
<delete dir="${jre.dest.osx}" />
<mkdir dir="${jre.dest.osx}" />
<mkdir dir="${project.build.directory}/downloads" />
<!-- Download JRE -->
<get src="${jdk.url.osx}"
dest="${project.build.directory}/downloads/${jdk.archive.osx}"
<get src="${jdk.url.osx}"
dest="${project.build.directory}/downloads/${jdk.archive.osx}"
usetimestamp="true" />
<!-- Extract JRE -->
<untar src="${project.build.directory}/downloads/${jdk.archive.osx}"
dest="${jre.dest.osx}"
<untar src="${project.build.directory}/downloads/${jdk.archive.osx}"
dest="${jre.dest.osx}"
compression="gzip" />
<!-- Move files up one level -->
<move todir="${jre.dest.osx}">
<fileset dir="${jre.dest.osx}/jdk-${jdk.version}-jre" />
</move>
<!-- Remove empty top-level folder -->
<delete dir="${jre.dest.osx}/jdk-${jdk.version}-jre" />
</target>
@@ -1150,7 +1150,7 @@
<option value="-Xdock:name=DIY Layout Creator"/>
<option value="-Xdock:icon=Contents/Resources/diylc.icns"/>
</bundleapp>
<echo message="Creating unsigned zip for distribution..."/>
<!-- Create unsigned zip for distribution -->
<zip destfile="${project.build.directory}/diylc-${project.version}-osx-arm-unsigned.zip">
@@ -13,6 +13,8 @@ import org.diylc.swing.ISwingUI;
import org.diylc.utils.FileUtils;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.awt.*;
import java.util.List;
import java.util.Objects;
@@ -26,6 +28,7 @@ public class ChatbotPane extends JPanel {
public static final String ME = "Me: ";
public static final String AI_ASSISTANT = "AI Assistant: ";
public static final String FREE_TIER = "Free";
public static final String GET_PREMIUM_URL = "www.diy-fever.com/get-premium";
public static Font DEFAULT_FONT = new Font("Square721 BT", Font.PLAIN, 12);
private static final Font MONOSPACED_FONT = new Font("Monospaced", Font.PLAIN, 12);
@@ -35,7 +38,10 @@ public class ChatbotPane extends JPanel {
"<style>" + "body { font-family: %s; font-size: %dpt; color: rgb(%d,%d,%d); background-color: rgb(%d,%d,%d); padding: 0px; margin: 0; }" + "pre { white-space: pre-wrap; margin: 0; }" + ".user { color: #98C379; }" + // Softer green that's easier on the eyes
".assistant { color: #61AFEF; }" + // Lighter, more vibrant blue
".system { color: #E5C07B; }" + // Warmer, muted yellow
".temporary { color: #555555; }" + "</style>", MONOSPACED_FONT.getFamily(),
".temporary { color: #555555; }" +
"a { color: #C678DD; text-decoration: none; }" + // Purple link color
"a:hover { color: #E06C75; text-decoration: underline; }" + // Red hover color
"</style>", MONOSPACED_FONT.getFamily(),
MONOSPACED_FONT.getSize(), TERMINAL_FG.getRed(), TERMINAL_FG.getGreen(),
TERMINAL_FG.getBlue(), TERMINAL_BG.getRed(), TERMINAL_BG.getGreen(), TERMINAL_BG.getBlue());
private static final Color PROMPT_BG = new Color(60, 60, 60); // Slightly brighter than TERMINAL_BG
@@ -245,13 +251,25 @@ public class ChatbotPane extends JPanel {
} else {
if (subscriptionInfo != null) {
getPremiumButton().setVisible(FREE_TIER.equals(subscriptionInfo.getTier()));
appendSection(ChatbotService.SYSTEM,
"Your are currently subscribed to the '" + subscriptionInfo.getTier() + "' tier, expiring on " + subscriptionInfo.getEndDate() + ", with " + subscriptionInfo.getRemainingCredits() + " credits remaining.");
String subscriptionInfoText = "Your are currently subscribed to the '" + subscriptionInfo.getTier() + "' tier, expiring on " + subscriptionInfo.getEndDate() + ", with " + subscriptionInfo.getRemainingCredits() + " credits remaining.";
if (FREE_TIER.equals(subscriptionInfo.getTier())) {
subscriptionInfoText +=
" To subscribe to the Premium tier, unlock advanced AI models and virtually limitless usage, visit <a href='http://" + GET_PREMIUM_URL + "'>" + GET_PREMIUM_URL + "</a>.";
}
appendSection(ChatbotService.SYSTEM, subscriptionInfoText);
}
fetchChatHistory();
getAskButton().setEnabled(true);
getClearButton().setEnabled(true);
}
// Scroll to the end of the chat pane
SwingUtilities.invokeLater(() -> {
JScrollPane scrollPane = (JScrollPane) getChatEditorPane().getParent().getParent();
JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
verticalScrollBar.setValue(verticalScrollBar.getMaximum());
});
}
private void fetchChatHistory() {
@@ -278,6 +296,22 @@ public class ChatbotPane extends JPanel {
chatEditorPane.setContentType("text/html");
chatEditorPane.setText(HTML_STYLE + "<body></body>");
chatEditorPane.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent hle) {
if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
System.out.println(hle.getURL());
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(hle.getURL().toURI());
} catch (Exception ex) {
LOG.error("Could not open link: " + hle.getURL(), ex);
}
}
}
});
refreshChat(null);
}
return chatEditorPane;
@@ -58,10 +58,12 @@ public class ChatbotPlugin implements IPlugIn {
switch (eventType) {
case FILE_STATUS_CHANGED:
case PROJECT_LOADED:
getChatbotPane().refreshChat(null);
break;
case CLOUD_LOGGED_IN:
case CLOUD_LOGGED_OUT:
SubscriptionEntity subscriptionInfo = null;
if (params.length > 0) {
if (params.length > 0 && params[0] instanceof SubscriptionEntity) {
subscriptionInfo = (SubscriptionEntity) params[0];
}
getChatbotPane().refreshChat(subscriptionInfo);
@@ -1,225 +1,225 @@
/*
DIY Layout Creator (DIYLC).
Copyright (c) 2009-2018 held jointly by the individual authors.
This file is part of DIYLC.
DIYLC is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DIYLC 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
*/
package org.diylc.swing.plugins.cloud;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.ListIterator;
import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
import org.diylc.plugins.cloud.service.CloudService;
import org.diylc.swingframework.ButtonDialog;
import org.diylc.common.EventType;
import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ITask;
import org.diylc.core.IView;
import org.diylc.plugins.cloud.service.CloudException;
import org.diylc.presenter.Presenter;
import org.diylc.swing.ISwingUI;
import org.diylc.swing.gui.DialogFactory;
import org.diylc.swing.gui.DummyView;
import org.diylc.utils.IconLoader;
import org.diylc.swing.plugins.cloud.view.ChangePasswordDialog;
import org.diylc.swing.plugins.cloud.view.LoginDialog;
import org.diylc.swing.plugins.cloud.view.UploadDialog;
import org.diylc.swing.plugins.cloud.view.UserEditDialog;
import org.diylc.swing.plugins.cloud.view.browser.CloudBrowserFrame;
import org.diylc.swing.plugins.cloud.view.browser.UploadManagerFrame;
import org.diylc.swing.plugins.file.FileFilterEnum;
import org.diylc.swing.plugins.cloud.actions.*;
public class CloudPlugIn implements IPlugIn {
private static final String ONLINE_TITLE = "Cloud";
private final static Logger LOG = Logger.getLogger(CloudPlugIn.class);
private ISwingUI swingUI;
private IPlugInPort plugInPort;
private IPlugInPort thumbnailPresenter;
private ThumbnailGenerator thumbnailGenerator;
private CloudService cloudService;
private LibraryAction libraryAction;
private LoginAction loginAction;
private LogOutAction logOutAction;
private CreateAccountAction createAccountAction;
private ManageAccountAction manageAccountAction;
private UploadAction uploadAction;
private ChangePasswordAction changePasswordAction;
private ManageProjectsAction manageProjectsAction;
private CloudBrowserFrame cloudBrowser;
public CloudPlugIn(ISwingUI swingUI) {
super();
this.swingUI = swingUI;
this.thumbnailPresenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
this.thumbnailGenerator = new ThumbnailGenerator(thumbnailPresenter);
// Initialize actions
this.libraryAction = new LibraryAction(this);
this.loginAction = new LoginAction(this);
this.logOutAction = new LogOutAction(this);
this.createAccountAction = new CreateAccountAction(this);
this.manageAccountAction = new ManageAccountAction(this);
this.uploadAction = new UploadAction(this);
this.changePasswordAction = new ChangePasswordAction(this);
this.manageProjectsAction = new ManageProjectsAction(this);
swingUI.injectMenuAction(getLibraryAction(), ONLINE_TITLE);
swingUI.injectMenuAction(null, ONLINE_TITLE);
swingUI.injectMenuAction(getLoginAction(), ONLINE_TITLE);
swingUI.injectMenuAction(getCreateAccountAction(), ONLINE_TITLE);
swingUI.injectMenuAction(null, ONLINE_TITLE);
swingUI.injectMenuAction(getUploadAction(), ONLINE_TITLE);
swingUI.injectMenuAction(getManageProjectsAction(), ONLINE_TITLE);
swingUI.injectMenuAction(null, ONLINE_TITLE);
swingUI.injectMenuAction(getManageAccountAction(), ONLINE_TITLE);
swingUI.injectMenuAction(getChangePasswordAction(), ONLINE_TITLE);
swingUI.injectMenuAction(getLogOutAction(), ONLINE_TITLE);
// default state
getUploadAction().setEnabled(false);
getManageProjectsAction().setEnabled(false);
getManageAccountAction().setEnabled(false);
getChangePasswordAction().setEnabled(false);
getLogOutAction().setEnabled(false);
}
@Override
public void connect(IPlugInPort plugInPort) {
this.plugInPort = plugInPort;
this.cloudService = plugInPort.getCloudService();
}
public CloudBrowserFrame getCloudBrowser() {
if (cloudBrowser == null) {
cloudBrowser = new CloudBrowserFrame(swingUI, plugInPort);
}
return cloudBrowser;
}
public UploadManagerFrame createUploadManagerFrame() {
return new UploadManagerFrame(swingUI, plugInPort);
}
public LibraryAction getLibraryAction() {
return libraryAction;
}
public LoginAction getLoginAction() {
return loginAction;
}
public LogOutAction getLogOutAction() {
return logOutAction;
}
public CreateAccountAction getCreateAccountAction() {
return createAccountAction;
}
public ManageAccountAction getManageAccountAction() {
return manageAccountAction;
}
public UploadAction getUploadAction() {
return uploadAction;
}
public ChangePasswordAction getChangePasswordAction() {
return changePasswordAction;
}
public ManageProjectsAction getManageProjectsAction() {
return manageProjectsAction;
}
@Override
public EnumSet<EventType> getSubscribedEventTypes() {
return EnumSet.of(EventType.CLOUD_LOGGED_IN, EventType.CLOUD_LOGGED_OUT);
}
@Override
public void processMessage(EventType eventType, Object... params) {
switch (eventType) {
case CLOUD_LOGGED_IN:
loggedIn();
break;
case CLOUD_LOGGED_OUT:
loggedOut();
break;
}
}
public void loggedIn() {
getLoginAction().setEnabled(false);
getCreateAccountAction().setEnabled(false);
getLogOutAction().setEnabled(true);
getManageAccountAction().setEnabled(true);
getUploadAction().setEnabled(true);
getManageProjectsAction().setEnabled(true);
getChangePasswordAction().setEnabled(true);
}
public void loggedOut() {
getLoginAction().setEnabled(true);
getCreateAccountAction().setEnabled(true);
getLogOutAction().setEnabled(false);
getManageAccountAction().setEnabled(false);
getUploadAction().setEnabled(false);
getManageProjectsAction().setEnabled(false);
getChangePasswordAction().setEnabled(false);
}
// Getters for action classes
public ISwingUI getSwingUI() {
return swingUI;
}
public IPlugInPort getPlugInPort() {
return plugInPort;
}
public IPlugInPort getThumbnailPresenter() {
return thumbnailPresenter;
}
public ThumbnailGenerator getThumbnailGenerator() {
return thumbnailGenerator;
}
public CloudService getCloudService() {
return cloudService;
}
}
/*
DIY Layout Creator (DIYLC).
Copyright (c) 2009-2018 held jointly by the individual authors.
This file is part of DIYLC.
DIYLC is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DIYLC 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
*/
package org.diylc.swing.plugins.cloud;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.ListIterator;
import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
import org.diylc.plugins.cloud.service.CloudService;
import org.diylc.swingframework.ButtonDialog;
import org.diylc.common.EventType;
import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ITask;
import org.diylc.core.IView;
import org.diylc.plugins.cloud.service.CloudException;
import org.diylc.presenter.Presenter;
import org.diylc.swing.ISwingUI;
import org.diylc.swing.gui.DialogFactory;
import org.diylc.swing.gui.DummyView;
import org.diylc.utils.IconLoader;
import org.diylc.swing.plugins.cloud.view.ChangePasswordDialog;
import org.diylc.swing.plugins.cloud.view.LoginDialog;
import org.diylc.swing.plugins.cloud.view.UploadDialog;
import org.diylc.swing.plugins.cloud.view.UserEditDialog;
import org.diylc.swing.plugins.cloud.view.browser.CloudBrowserFrame;
import org.diylc.swing.plugins.cloud.view.browser.UploadManagerFrame;
import org.diylc.swing.plugins.file.FileFilterEnum;
import org.diylc.swing.plugins.cloud.actions.*;
public class CloudPlugIn implements IPlugIn {
private static final String ONLINE_TITLE = "Cloud";
private final static Logger LOG = Logger.getLogger(CloudPlugIn.class);
private ISwingUI swingUI;
private IPlugInPort plugInPort;
private IPlugInPort thumbnailPresenter;
private ThumbnailGenerator thumbnailGenerator;
private CloudService cloudService;
private LibraryAction libraryAction;
private LoginAction loginAction;
private LogOutAction logOutAction;
private CreateAccountAction createAccountAction;
private ManageAccountAction manageAccountAction;
private UploadAction uploadAction;
private ChangePasswordAction changePasswordAction;
private ManageProjectsAction manageProjectsAction;
private CloudBrowserFrame cloudBrowser;
public CloudPlugIn(ISwingUI swingUI) {
super();
this.swingUI = swingUI;
this.thumbnailPresenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
this.thumbnailGenerator = new ThumbnailGenerator(thumbnailPresenter);
// Initialize actions
this.libraryAction = new LibraryAction(this);
this.loginAction = new LoginAction(this);
this.logOutAction = new LogOutAction(this);
this.createAccountAction = new CreateAccountAction(this);
this.manageAccountAction = new ManageAccountAction(this);
this.uploadAction = new UploadAction(this);
this.changePasswordAction = new ChangePasswordAction(this);
this.manageProjectsAction = new ManageProjectsAction(this);
swingUI.injectMenuAction(getLibraryAction(), ONLINE_TITLE);
swingUI.injectMenuAction(null, ONLINE_TITLE);
swingUI.injectMenuAction(getLoginAction(), ONLINE_TITLE);
swingUI.injectMenuAction(getCreateAccountAction(), ONLINE_TITLE);
swingUI.injectMenuAction(null, ONLINE_TITLE);
swingUI.injectMenuAction(getUploadAction(), ONLINE_TITLE);
swingUI.injectMenuAction(getManageProjectsAction(), ONLINE_TITLE);
swingUI.injectMenuAction(null, ONLINE_TITLE);
swingUI.injectMenuAction(getManageAccountAction(), ONLINE_TITLE);
swingUI.injectMenuAction(getChangePasswordAction(), ONLINE_TITLE);
swingUI.injectMenuAction(getLogOutAction(), ONLINE_TITLE);
// default state
getUploadAction().setEnabled(false);
getManageProjectsAction().setEnabled(false);
getManageAccountAction().setEnabled(false);
getChangePasswordAction().setEnabled(false);
getLogOutAction().setEnabled(false);
}
@Override
public void connect(IPlugInPort plugInPort) {
this.plugInPort = plugInPort;
this.cloudService = plugInPort.getCloudService();
}
public CloudBrowserFrame getCloudBrowser() {
if (cloudBrowser == null) {
cloudBrowser = new CloudBrowserFrame(swingUI, plugInPort);
}
return cloudBrowser;
}
public UploadManagerFrame createUploadManagerFrame() {
return new UploadManagerFrame(swingUI, plugInPort);
}
public LibraryAction getLibraryAction() {
return libraryAction;
}
public LoginAction getLoginAction() {
return loginAction;
}
public LogOutAction getLogOutAction() {
return logOutAction;
}
public CreateAccountAction getCreateAccountAction() {
return createAccountAction;
}
public ManageAccountAction getManageAccountAction() {
return manageAccountAction;
}
public UploadAction getUploadAction() {
return uploadAction;
}
public ChangePasswordAction getChangePasswordAction() {
return changePasswordAction;
}
public ManageProjectsAction getManageProjectsAction() {
return manageProjectsAction;
}
@Override
public EnumSet<EventType> getSubscribedEventTypes() {
return EnumSet.of(EventType.CLOUD_LOGGED_IN, EventType.CLOUD_LOGGED_OUT);
}
@Override
public void processMessage(EventType eventType, Object... params) {
switch (eventType) {
case CLOUD_LOGGED_IN:
loggedIn();
break;
case CLOUD_LOGGED_OUT:
loggedOut();
break;
}
}
public void loggedIn() {
getLoginAction().setEnabled(false);
getCreateAccountAction().setEnabled(false);
getLogOutAction().setEnabled(true);
getManageAccountAction().setEnabled(true);
getUploadAction().setEnabled(true);
getManageProjectsAction().setEnabled(true);
getChangePasswordAction().setEnabled(true);
}
public void loggedOut() {
getLoginAction().setEnabled(true);
getCreateAccountAction().setEnabled(true);
getLogOutAction().setEnabled(false);
getManageAccountAction().setEnabled(false);
getUploadAction().setEnabled(false);
getManageProjectsAction().setEnabled(false);
getChangePasswordAction().setEnabled(false);
}
// Getters for action classes
public ISwingUI getSwingUI() {
return swingUI;
}
public IPlugInPort getPlugInPort() {
return plugInPort;
}
public IPlugInPort getThumbnailPresenter() {
return thumbnailPresenter;
}
public ThumbnailGenerator getThumbnailGenerator() {
return thumbnailGenerator;
}
public CloudService getCloudService() {
return cloudService;
}
}
@@ -1,345 +1,345 @@
/*
DIY Layout Creator (DIYLC).
Copyright (c) 2009-2018 held jointly by the individual authors.
This file is part of DIYLC.
DIYLC is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DIYLC 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
*/
package org.diylc.swing.plugins.cloud.view;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.diylc.swingframework.ButtonDialog;
import org.diylc.plugins.cloud.model.UserEntity;
import org.diylc.swing.gui.components.HTMLTextArea;
public class UserEditDialog extends ButtonDialog {
private static final long serialVersionUID = 1L;
private JPanel mainPanel;
private JTextField userNameField;
private JPasswordField passwordField;
private JPasswordField confirmPasswordField;
private JTextField emailField;
private JTextField websiteField;
private JTextArea bioArea;
private JScrollPane bioPane;
private String userName;
private String password;
private String email;
private String website;
private String bio;
private UserEntity existingEntity;
public UserEditDialog(JFrame owner, UserEntity existingEntity) {
super(owner, existingEntity == null ? "New Account" : "Manage Account", new String[] {OK, CANCEL});
this.existingEntity = existingEntity;
setMinimumSize(new Dimension(240, 32));
layoutGui();
refreshState();
}
public String getUserName() {
return userName;
}
public String getPassword() {
return password;
}
public String getEmail() {
return email;
}
public String getWebsite() {
return website;
}
public String getBio() {
return bio;
}
@Override
protected JComponent getMainComponent() {
if (mainPanel == null) {
mainPanel = new JPanel(new GridBagLayout());
mainPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.NONE;
gbc.insets = new Insets(4, 2, 2, 2);
gbc.gridx = 0;
gbc.gridy = 0;
mainPanel.add(new JLabel("User Name:"), gbc);
if (existingEntity == null) {
gbc.gridy = 1;
mainPanel.add(new JLabel("Password:"), gbc);
gbc.gridy = 2;
mainPanel.add(new JLabel("Confirm Password:"), gbc);
}
gbc.gridy = 3;
mainPanel.add(new JLabel("eMail:"), gbc);
gbc.gridy = 4;
mainPanel.add(new JLabel("Website:"), gbc);
gbc.gridy = 5;
mainPanel.add(new JLabel("Short Bio:"), gbc);
gbc.gridx = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(2, 2, 2, 2);
gbc.weightx = 1;
gbc.gridy = 0;
mainPanel.add(getUserNameField(), gbc);
if (existingEntity == null) {
gbc.gridy = 1;
mainPanel.add(getPasswordField(), gbc);
gbc.gridy = 2;
mainPanel.add(getConfirmPasswordField(), gbc);
}
gbc.gridy = 3;
mainPanel.add(getEmailField(), gbc);
gbc.gridy = 4;
mainPanel.add(getWebsiteField(), gbc);
gbc.gridy = 5;
gbc.fill = GridBagConstraints.BOTH;
mainPanel.add(getBioPane(), gbc);
}
return mainPanel;
}
private void refreshState() {
this.userName = getUserNameField().getText();
String password = new String(getPasswordField().getPassword());
String confirmPassword = new String(getConfirmPasswordField().getPassword());
if (password.equals(confirmPassword)) {
this.password = password;
} else {
this.password = null;
}
this.email = getEmailField().getText();
this.website = getWebsiteField().getText();
this.bio = getBioArea().getText();
JButton okButton = getButton(OK);
okButton.setEnabled(!this.userName.isEmpty()
&& !this.email.isEmpty() && this.email.contains("@")
&& (this.existingEntity != null || ((this.password != null) && (this.password.length() > 0))));
}
private JTextField getUserNameField() {
if (userNameField == null) {
userNameField = new JTextField();
if (existingEntity != null) {
userNameField.setText(existingEntity.getUsername());
userNameField.setEditable(false);
}
userNameField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void insertUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void changedUpdate(DocumentEvent e) {
refreshState();
}
});
}
return userNameField;
}
private JPasswordField getPasswordField() {
if (passwordField == null) {
passwordField = new JPasswordField();
passwordField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void insertUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void changedUpdate(DocumentEvent e) {
refreshState();
}
});
}
return passwordField;
}
private JPasswordField getConfirmPasswordField() {
if (confirmPasswordField == null) {
confirmPasswordField = new JPasswordField();
confirmPasswordField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void insertUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void changedUpdate(DocumentEvent e) {
refreshState();
}
});
}
return confirmPasswordField;
}
private JTextField getEmailField() {
if (emailField == null) {
emailField = new JTextField();
if (existingEntity != null) {
emailField.setText(existingEntity.getEmail());
emailField.setEditable(false);
}
emailField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void insertUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void changedUpdate(DocumentEvent e) {
refreshState();
}
});
}
return emailField;
}
private JTextField getWebsiteField() {
if (websiteField == null) {
websiteField = new JTextField();
if (existingEntity != null)
websiteField.setText(existingEntity.getWebsite());
websiteField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void insertUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void changedUpdate(DocumentEvent e) {
refreshState();
}
});
}
return websiteField;
}
private JScrollPane getBioPane() {
if (bioPane == null) {
bioPane = new JScrollPane(getBioArea());
bioPane.setPreferredSize(new Dimension(192, 64));
bioPane.setBorder(getBioArea().getBorder());
getBioArea().setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
}
return bioPane;
}
private JTextArea getBioArea() {
if (bioArea == null) {
bioArea = new HTMLTextArea();
if (existingEntity != null)
bioArea.setText(existingEntity.getBio());
bioArea.setFont(getUserNameField().getFont());
bioArea.setBorder(getUserNameField().getBorder());
bioArea.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void insertUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void changedUpdate(DocumentEvent e) {
refreshState();
}
});
}
return bioArea;
}
}
/*
DIY Layout Creator (DIYLC).
Copyright (c) 2009-2018 held jointly by the individual authors.
This file is part of DIYLC.
DIYLC is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DIYLC 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
*/
package org.diylc.swing.plugins.cloud.view;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.diylc.swingframework.ButtonDialog;
import org.diylc.plugins.cloud.model.UserEntity;
import org.diylc.swing.gui.components.HTMLTextArea;
public class UserEditDialog extends ButtonDialog {
private static final long serialVersionUID = 1L;
private JPanel mainPanel;
private JTextField userNameField;
private JPasswordField passwordField;
private JPasswordField confirmPasswordField;
private JTextField emailField;
private JTextField websiteField;
private JTextArea bioArea;
private JScrollPane bioPane;
private String userName;
private String password;
private String email;
private String website;
private String bio;
private UserEntity existingEntity;
public UserEditDialog(JFrame owner, UserEntity existingEntity) {
super(owner, existingEntity == null ? "New Account" : "Manage Account", new String[] {OK, CANCEL});
this.existingEntity = existingEntity;
setMinimumSize(new Dimension(240, 32));
layoutGui();
refreshState();
}
public String getUserName() {
return userName;
}
public String getPassword() {
return password;
}
public String getEmail() {
return email;
}
public String getWebsite() {
return website;
}
public String getBio() {
return bio;
}
@Override
protected JComponent getMainComponent() {
if (mainPanel == null) {
mainPanel = new JPanel(new GridBagLayout());
mainPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.NONE;
gbc.insets = new Insets(4, 2, 2, 2);
gbc.gridx = 0;
gbc.gridy = 0;
mainPanel.add(new JLabel("User Name:"), gbc);
if (existingEntity == null) {
gbc.gridy = 1;
mainPanel.add(new JLabel("Password:"), gbc);
gbc.gridy = 2;
mainPanel.add(new JLabel("Confirm Password:"), gbc);
}
gbc.gridy = 3;
mainPanel.add(new JLabel("eMail:"), gbc);
gbc.gridy = 4;
mainPanel.add(new JLabel("Website:"), gbc);
gbc.gridy = 5;
mainPanel.add(new JLabel("Short Bio:"), gbc);
gbc.gridx = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(2, 2, 2, 2);
gbc.weightx = 1;
gbc.gridy = 0;
mainPanel.add(getUserNameField(), gbc);
if (existingEntity == null) {
gbc.gridy = 1;
mainPanel.add(getPasswordField(), gbc);
gbc.gridy = 2;
mainPanel.add(getConfirmPasswordField(), gbc);
}
gbc.gridy = 3;
mainPanel.add(getEmailField(), gbc);
gbc.gridy = 4;
mainPanel.add(getWebsiteField(), gbc);
gbc.gridy = 5;
gbc.fill = GridBagConstraints.BOTH;
mainPanel.add(getBioPane(), gbc);
}
return mainPanel;
}
private void refreshState() {
this.userName = getUserNameField().getText();
String password = new String(getPasswordField().getPassword());
String confirmPassword = new String(getConfirmPasswordField().getPassword());
if (password.equals(confirmPassword)) {
this.password = password;
} else {
this.password = null;
}
this.email = getEmailField().getText();
this.website = getWebsiteField().getText();
this.bio = getBioArea().getText();
JButton okButton = getButton(OK);
okButton.setEnabled(!this.userName.isEmpty()
&& !this.email.isEmpty() && this.email.contains("@")
&& (this.existingEntity != null || ((this.password != null) && (this.password.length() > 0))));
}
private JTextField getUserNameField() {
if (userNameField == null) {
userNameField = new JTextField();
if (existingEntity != null) {
userNameField.setText(existingEntity.getUsername());
userNameField.setEditable(false);
}
userNameField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void insertUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void changedUpdate(DocumentEvent e) {
refreshState();
}
});
}
return userNameField;
}
private JPasswordField getPasswordField() {
if (passwordField == null) {
passwordField = new JPasswordField();
passwordField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void insertUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void changedUpdate(DocumentEvent e) {
refreshState();
}
});
}
return passwordField;
}
private JPasswordField getConfirmPasswordField() {
if (confirmPasswordField == null) {
confirmPasswordField = new JPasswordField();
confirmPasswordField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void insertUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void changedUpdate(DocumentEvent e) {
refreshState();
}
});
}
return confirmPasswordField;
}
private JTextField getEmailField() {
if (emailField == null) {
emailField = new JTextField();
if (existingEntity != null) {
emailField.setText(existingEntity.getEmail());
emailField.setEditable(false);
}
emailField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void insertUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void changedUpdate(DocumentEvent e) {
refreshState();
}
});
}
return emailField;
}
private JTextField getWebsiteField() {
if (websiteField == null) {
websiteField = new JTextField();
if (existingEntity != null)
websiteField.setText(existingEntity.getWebsite());
websiteField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void insertUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void changedUpdate(DocumentEvent e) {
refreshState();
}
});
}
return websiteField;
}
private JScrollPane getBioPane() {
if (bioPane == null) {
bioPane = new JScrollPane(getBioArea());
bioPane.setPreferredSize(new Dimension(192, 64));
bioPane.setBorder(getBioArea().getBorder());
getBioArea().setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
}
return bioPane;
}
private JTextArea getBioArea() {
if (bioArea == null) {
bioArea = new HTMLTextArea();
if (existingEntity != null)
bioArea.setText(existingEntity.getBio());
bioArea.setFont(getUserNameField().getFont());
bioArea.setBorder(getUserNameField().getBorder());
bioArea.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void insertUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void changedUpdate(DocumentEvent e) {
refreshState();
}
});
}
return bioArea;
}
}
+1 -1
View File
@@ -235,7 +235,7 @@ INSERT INTO diylc_knowledge_base(category, section, content) VALUES ('User Manua
'DIYLC AI Assistant is an integrated feature that allows users to interact with DIY Layout Creator (DIYLC) using natural language. It functions as a chatbot powered by the OpenAI API to generate helpful responses. The AI Assistant is available only while logged into the DIYLC Cloud with an active account and requires an internet connection.
There are two subscription tiers for using the AI Assistant:
- Free Tier: Provides limited monthly usage and access to basic AI models. This option is automatically available to all registered DIYLC Cloud users.
- Premium Tier: Offers up to 1000 requests per month using more advanced AI models. The Premium subscription is exclusively available to Patreon supporters with the "Premium AI" tier. Once you become a premium supporter, your premium status will be semi-automatically transferred to your DIYLC Cloud account. If your email used to subscribe to the premium tier is different from the email used to login to the DIYLC Cloud, please reach out to bancika@gmail.com to manually transfer your premium status.
- Premium Tier: Offers up to 1000 requests per month using more advanced AI models. The Premium subscription can be purchased at http://www.diy-fever.com/get-premium. If your email used to subscribe to the premium tier is different from the email used to login to the DIYLC Cloud, please reach out to bancika@gmail.com to manually activate your premium status.
');
DELETE FROM diylc_knowledge_base WHERE section = 'AI Assitant/Chatbot/ChatGPT/GPT - Using the AI Assistant';