Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
p2
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cse332-20sp
p2
Commits
18be7b6f
Commit
18be7b6f
authored
8 years ago
by
Adam Blank
Browse files
Options
Downloads
Patches
Plain Diff
Fixes some annoying uMessage UI things
parent
fd288c49
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
chatter.jar
+0
-0
0 additions, 0 deletions
chatter.jar
src/chat/ChatWindow.java
+50
-36
50 additions, 36 deletions
src/chat/ChatWindow.java
src/chat/MainWindow.java
+18
-15
18 additions, 15 deletions
src/chat/MainWindow.java
src/chat/uMessage.java
+70
-50
70 additions, 50 deletions
src/chat/uMessage.java
with
138 additions
and
101 deletions
chatter.jar
+
0
−
0
View file @
18be7b6f
No preview for this file type
This diff is collapsed.
Click to expand it.
src/chat/ChatWindow.java
+
50
−
36
View file @
18be7b6f
...
...
@@ -100,24 +100,7 @@ public class ChatWindow {
/**
* 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 +120,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 +263,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 +334,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
;
}
...
...
This diff is collapsed.
Click to expand it.
src/chat/MainWindow.java
+
18
−
15
View file @
18be7b6f
...
...
@@ -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,22 +50,26 @@ 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 diff is collapsed.
Click to expand it.
src/chat/uMessage.java
+
70
−
50
View file @
18be7b6f
...
...
@@ -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,65 @@ 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
)
{
}
}
}
}
/**
* 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 +150,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
);
...
...
@@ -143,10 +181,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 +229,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 +244,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 +258,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
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment