Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • sarafa/p2
  • mertht/p2
  • cse332-19au/p2
  • sandchow/p2
  • hanzhang/p2
  • cse332-19sp/p2
  • cse332-20sp/p2
  • cse332-20su-tasks/p2
  • cse332-20su/p2
  • cse332-21su/p2
  • cse332-21wi/p2
  • cse332-21sp/p2
  • cse332-20au/p2
13 results
Show changes
Commits on Source (91)
Showing with 276 additions and 125 deletions
/bin/
.DS_Store
.idea/
*.iml
Ckpt1:
script: curl -s https://courses.cs.washington.edu/courses/cse332/gitlab-ci/p2/ckpt1.sh | bash
Ckpt2:
script: curl -s https://courses.cs.washington.edu/courses/cse332/gitlab-ci/p2/ckpt2.sh | bash
StaticAnalysis:
script: curl -s https://courses.cs.washington.edu/courses/cse332/gitlab-ci/p2/static.sh | bash
\ No newline at end of file
No preview for this file type
File added
File added
File added
File added
File added
File added
File added
javafx.version=11.0.2
javafx.runtime.version=11.0.2+1
javafx.runtime.build=1
File added
File added
File added
File added
This diff is collapsed.
......@@ -30,11 +30,6 @@ import org.alicebot.ab.MagicBooleans;
import org.alicebot.ab.MagicStrings;
import org.alicebot.ab.PCAIMLProcessorExtension;
import com.google.code.chatterbotapi.ChatterBot;
import com.google.code.chatterbotapi.ChatterBotFactory;
import com.google.code.chatterbotapi.ChatterBotSession;
import com.google.code.chatterbotapi.ChatterBotType;
import cse332.misc.WordReader;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
......@@ -53,7 +48,6 @@ public class ChatWindow {
private final StringBuilder content;
public String theirUsername;
public Chat esession;
public ChatterBotSession csession;
private final WordSuggestor[] markov;
private final UMessageServerConnection connection;
private final SpellingCorrector checker;
......@@ -86,38 +80,12 @@ public class ChatWindow {
this.esession = new Chat(bot);
}
else if (this.theirUsername.equals("cleverbot")) {
ChatterBotFactory factory = new ChatterBotFactory();
ChatterBot bot1;
try {
bot1 = factory.create(ChatterBotType.CLEVERBOT);
this.csession = bot1.createSession();
} catch (Exception e) {
}
}
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
try {
String path = new java.io.File(".").getCanonicalPath();
this.content.append("<link rel='stylesheet' type='text/css' href='file:///"
+ path + "/chat.css'>");
this.content.append("<head>");
this.content.append(
" <script language=\"javascript\" type=\"text/javascript\">");
this.content.append(" function toBottom(){");
this.content
.append(" window.scrollTo(0, document.body.scrollHeight);");
this.content.append(" }");
this.content.append(" </script>");
this.content.append("</head>");
this.content.append("<body onload='toBottom()'>");
} catch (IOException e1) {
}
private void initialize() {
this.frame = new JFrame();
this.frame.setBounds(100, 100, 290, 390);
this.frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
......@@ -137,17 +105,28 @@ public class ChatWindow {
gbc_msgScrollPane.gridx = 0;
gbc_msgScrollPane.gridy = 0;
this.chatMessagesPanel = new JFXPanel();
this.frame.getContentPane().add(this.chatMessagesPanel, gbc_msgScrollPane);
Platform.runLater(() -> {
ChatWindow.this.chatMessages = new WebView();
BorderPane borderPane = new BorderPane();
borderPane.setCenter(ChatWindow.this.chatMessages);
Scene scene = new Scene(borderPane, 450, 450);
ChatWindow.this.chatMessagesPanel.setScene(scene);
});
show();
(new Thread() {
public void run() {
try {
String path = new java.io.File(".").getCanonicalPath();
content.append("<link rel='stylesheet' type='text/css' href='file:///"
+ path + "/chat.css'>");
content.append("<head>");
content.append(
" <script language=\"javascript\" type=\"text/javascript\">");
content.append(" function toBottom(){");
content
.append(" window.scrollTo(0, document.body.scrollHeight);");
content.append(" }");
content.append(" </script>");
content.append("</head>");
content.append("<body onload='toBottom()'>");
} catch (IOException e1) {
}
}
}).start();
JPanel suggestionsPanel = new JPanel();
GridBagConstraints gbc_suggestionsPanel = new GridBagConstraints();
......@@ -269,11 +248,29 @@ public class ChatWindow {
}
};
this.frame.addKeyListener(giveFocus);
this.chatMessagesPanel.addKeyListener(giveFocus);
suggestionsPanel.addKeyListener(giveFocus);
myMessagePanel.addKeyListener(giveFocus);
(new Thread() {
public void run() {
chatMessagesPanel = new JFXPanel();
chatMessagesPanel.addKeyListener(giveFocus);
frame.getContentPane().add(chatMessagesPanel, gbc_msgScrollPane);
Platform.runLater(() -> {
ChatWindow.this.chatMessages = new WebView();
BorderPane borderPane = new BorderPane();
borderPane.setCenter(ChatWindow.this.chatMessages);
Scene scene = new Scene(borderPane, 450, 450);
ChatWindow.this.chatMessagesPanel.setScene(scene);
});
}
}).start();
this.frame.pack();
show();
this.myMessage.requestFocusInWindow();
}
......@@ -322,13 +319,15 @@ public class ChatWindow {
String text = ("SOL " + this.myMessage.getText()).trim();
int lastSpace = text.lastIndexOf(' ');
String allButLast = lastSpace > -1 ? text.substring(0, lastSpace) : null;
this.undo = this.myMessage.getText();
String newText = (allButLast.replaceAll("SOL", "") + " " + result).trim();
if (this.myMessage.getText().startsWith(newText)) {
return false;
if (allButLast != null) {
this.undo = this.myMessage.getText();
String newText = (allButLast.replaceAll("SOL", "") + " " + result).trim();
if (this.myMessage.getText().startsWith(newText)) {
return false;
}
this.myMessage.setText(newText);
return true;
}
this.myMessage.setText(newText);
return true;
}
return false;
}
......@@ -374,13 +373,6 @@ public class ChatWindow {
receiveMessage(this.esession.multisentenceRespond(msg));
return;
}
else if (this.theirUsername.equals("cleverbot")) {
try {
receiveMessage(this.csession.think(msg));
return;
} catch (Exception e) {
}
}
else {
try {
this.connection.m_channel(this.theirUsername, msg);
......
......@@ -15,7 +15,6 @@ import javax.swing.JList;
import p2.wordsuggestor.WordSuggestor;
public class MainWindow {
private JFrame frame;
private List<String> usernames;
private final List<ChatWindow> chats;
......@@ -51,27 +50,30 @@ public class MainWindow {
list.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
@SuppressWarnings("unchecked")
JList<String> list = (JList<String>) e.getSource();
if (e.getClickCount() == 2) {
int index = list.locationToIndex(e.getPoint());
for (ChatWindow client : MainWindow.this.chats) {
if (client.theirUsername
.equals(MainWindow.this.usernames.get(index))) {
client.show();
return;
(new Thread() {
public void run() {
@SuppressWarnings("unchecked")
JList<String> list = (JList<String>) e.getSource();
if (e.getClickCount() == 2) {
int index = list.locationToIndex(e.getPoint());
for (ChatWindow client : MainWindow.this.chats) {
if (client.theirUsername
.equals(MainWindow.this.usernames.get(index))) {
client.show();
return;
}
}
MainWindow.this.chats
.add(new ChatWindow(MainWindow.this.usernames.get(index),
MainWindow.this.markov, MainWindow.this.connection));
}
}
MainWindow.this.chats
.add(new ChatWindow(MainWindow.this.usernames.get(index),
MainWindow.this.markov, MainWindow.this.connection));
}
}).start();
}
});
this.usernames = new ArrayList<String>();
this.usernames.add("cleverbot");
this.usernames.add("eliza");
this.model = new UsersModel(this.usernames);
list.setModel(this.model);
......@@ -86,6 +88,9 @@ public class MainWindow {
}
usersSet.remove(this.username);
this.usernames = new ArrayList<String>(usersSet);
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
this.model.update(this.usernames);
}
......
......@@ -6,16 +6,24 @@ import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.BorderLayout;
import java.io.IOException;
import java.util.function.Supplier;
import javax.swing.Box;
import javafx.embed.swing.JFXPanel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JDialog;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import cse332.interfaces.misc.Dictionary;
import cse332.types.AlphabeticString;
......@@ -62,35 +70,66 @@ public class uMessage {
}
@Override
public void run() {
int N = uMessage.N;
try {
uMessage.markov[this.i] = new WordSuggestor(uMessage.CORPUS, N - this.i,
4, uMessage.NEW_OUTER, uMessage.NEW_INNER);
uMessage.loading[this.i] = false;
this.window.update();
} catch (IOException e) {
public void run() {
int N = uMessage.N;
try {
uMessage.markov[this.i] = new WordSuggestor(uMessage.CORPUS, N - this.i,
4, uMessage.NEW_OUTER, uMessage.NEW_INNER);
this.window.update();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
final uMessage window = new uMessage();
window.frmUmessageLogin.setVisible(true);
window.errors.setText("Loading the Markov Data (n = " + uMessage.N + ")...");
uMessage.markov = new WordSuggestor[uMessage.N];
uMessage.loading = new boolean[uMessage.N];
for (int i1 = 0; i1 < uMessage.N; i1++) {
uMessage.loading[i1] = true;
(new Thread() {
public void run() {
new JFXPanel();
}
for (int i2 = 0; i2 < uMessage.N; i2++) {
new Thread(new MarkovLoader(window, i2)).start();
}).start();
final uMessage window = new uMessage();
markov = new WordSuggestor[uMessage.N];
JDialog dialog = new JDialog((JFrame)null, "Please wait...", true);//true means that the dialog created is modal
JLabel lblStatus = new JLabel("<html><b>Loading Markov Data (n = " + uMessage.N + ")...</b><br>Depending on the data structures you're using<br>" +
"and your computer, this might take a bit.</html>");
JProgressBar pbProgress = new JProgressBar(0, 100);
pbProgress.setIndeterminate(true); //we'll use an indeterminate progress bar
dialog.add(BorderLayout.NORTH, lblStatus);
dialog.add(BorderLayout.CENTER, pbProgress);
dialog.addWindowListener(new WindowAdapter() {
@Override public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
dialog.setSize(300, 90);
SwingWorker<Void, Void> sw = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
for (int i2 = 1; i2 < uMessage.N; i2++) {
new Thread(new MarkovLoader(window, i2)).start();
}
new MarkovLoader(window, 0).run();
return null;
}
@Override
protected void done() {
dialog.dispose();//close the modal dialog
window.frmUmessageLogin.setVisible(true);
}
};
sw.execute(); // this will start the processing on a separate thread
dialog.setVisible(true); //this will block user input as long as the processing task is working
}
/**
......@@ -112,7 +151,7 @@ public class uMessage {
gridBagLayout.columnWidths = new int[] { 0, 90, 90, 90, 0, 0 };
gridBagLayout.rowHeights = new int[] { 0, 9, 0, 0 };
gridBagLayout.columnWeights = new double[] { 0.0, 0.0, 1.0, 0.0, 0.0,
Double.MIN_VALUE };
Double.MIN_VALUE };
gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE };
this.frmUmessageLogin.getContentPane().setLayout(gridBagLayout);
......@@ -131,7 +170,7 @@ public class uMessage {
this.frmUmessageLogin.getContentPane().add(this.horizontalStrut,
gbc_horizontalStrut);
JLabel usernameLabel = new JLabel("Username:");
JLabel usernameLabel = new JLabel("UWnetID:");
GridBagConstraints gbc_usernameLabel = new GridBagConstraints();
gbc_usernameLabel.fill = GridBagConstraints.BOTH;
gbc_usernameLabel.insets = new Insets(0, 0, 5, 5);
......@@ -143,10 +182,14 @@ public class uMessage {
this.username.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (update() && e.getKeyCode() == KeyEvent.VK_ENTER) {
uMessage.this.login.setEnabled(false);
login();
}
(new Thread() {
public void run() {
if (update() && e.getKeyCode() == KeyEvent.VK_ENTER) {
uMessage.this.login.setEnabled(false);
login();
}
}
}).start();
}
});
......@@ -187,14 +230,6 @@ public class uMessage {
}
public boolean update() {
boolean noneLoading = true;
for (int i = 0; i < uMessage.loading.length; i++) {
noneLoading &= !uMessage.loading[i];
}
if (noneLoading) {
this.errors.setText("");
this.errors.setForeground(Color.BLACK);
}
if (!this.loggingIn && this.username.getText().length() > 0) {
this.login.setEnabled(true);
this.errors.setForeground(Color.BLACK);
......@@ -210,11 +245,10 @@ public class uMessage {
this.loggingIn = true;
update();
try {
this.connection = new UMessageServerConnection(this,
this.username.getText().replaceAll(" ", ""));
this.connection.go();
} catch (IOException e1) {
}
connection = new UMessageServerConnection(uMessage.this,
username.getText().replaceAll(" ", ""));
connection.go();
} catch (IOException e1) {}
}
public void badNick() {
......@@ -225,19 +259,6 @@ public class uMessage {
}
public void loggedIn(String username) {
boolean noneLoading = false;
while (!noneLoading) {
noneLoading = true;
for (int i = 0; i < uMessage.loading.length; i++) {
noneLoading &= !uMessage.loading[i];
}
try {
Thread.sleep(200);
} catch (InterruptedException e) {
}
}
this.frmUmessageLogin.dispose();
this.window = new MainWindow(username, uMessage.markov, this.connection);
this.loggingIn = false;
......