Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
ipaaca
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ramin Yaghoubzadeh Torky
ipaaca
Commits
156565b9
Commit
156565b9
authored
13 years ago
by
Hendrik Buschmeier
Browse files
Options
Downloads
Patches
Plain Diff
Added Herwin's part of the text printing demo.
parent
c7bf769f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/src/ipaacademo/TextPrinter.java
+131
-0
131 additions, 0 deletions
java/src/ipaacademo/TextPrinter.java
with
131 additions
and
0 deletions
java/src/ipaacademo/TextPrinter.java
0 → 100644
+
131
−
0
View file @
156565b9
package
ipaacademo
;
import
java.util.Set
;
import
ipaaca.AbstractIU
;
import
ipaaca.Initializer
;
import
ipaaca.InputBuffer
;
import
ipaaca.LocalIU
;
import
ipaaca.OutputBuffer
;
import
ipaaca.RemotePushIU
;
import
javax.swing.JFrame
;
import
javax.swing.JLabel
;
import
com.google.common.collect.ImmutableSet
;
public
class
TextPrinter
{
static
{
Initializer
.
initializeIpaacaRsb
();
}
private
static
final
String
CATEGORY
=
"TEXT"
;
private
static
final
double
RATE
=
1
;
private
UpdateThread
updateThread
;
public
TextPrinter
()
{
Set
<
String
>
categories
=
new
ImmutableSet
.
Builder
<
String
>().
add
(
CATEGORY
).
build
();
JLabel
label
=
new
JLabel
(
""
);
updateThread
=
new
UpdateThread
(
new
InputBuffer
(
"TextPrinter"
,
categories
),
label
);
JFrame
frame
=
new
JFrame
(
"IPAACA TextPrinter Demo"
);
frame
.
add
(
label
);
frame
.
setSize
(
1000
,
300
);
frame
.
setVisible
(
true
);
frame
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
}
public
void
start
()
{
updateThread
.
start
();
}
private
static
class
UpdateThread
extends
Thread
{
private
InputBuffer
inBuffer
;
private
JLabel
label
;
public
UpdateThread
(
InputBuffer
inBuffer
,
JLabel
label
)
{
this
.
inBuffer
=
inBuffer
;
this
.
label
=
label
;
}
@Override
public
void
run
()
{
long
startTime
=
System
.
currentTimeMillis
();
while
(
true
)
{
double
duration
=
(
System
.
currentTimeMillis
()-
startTime
)/
1000
d
;
RemotePushIU
iuFirst
=
null
;
for
(
RemotePushIU
iu
:
inBuffer
.
getIUs
())
{
if
(
iu
.
getLinks
(
"PREDECESSOR"
).
isEmpty
())
{
iuFirst
=
iu
;
break
;
}
}
int
numChars
=
(
int
)(
duration
/
RATE
);
AbstractIU
iu
=
iuFirst
;
String
str
=
""
;
for
(
int
i
=
0
;
i
<
numChars
;
i
++)
{
str
+=
iu
.
getPayload
().
get
(
"CONTENT"
);
Set
<
String
>
successor
=
iu
.
getLinks
(
"SUCCESSOR"
);
if
(
successor
!=
null
&&
!
successor
.
isEmpty
())
{
iu
=
inBuffer
.
getIU
(
successor
.
iterator
().
next
());
}
else
{
break
;
}
}
label
.
setText
(
str
);
try
{
Thread
.
sleep
(
100
);
}
catch
(
InterruptedException
e
)
{
Thread
.
interrupted
();
}
}
}
}
public
static
void
main
(
String
args
[])
{
TextPrinter
tp
=
new
TextPrinter
();
OutputBuffer
outBuffer
=
new
OutputBuffer
(
"componentX"
);
String
[]
inputString
=
{
"h"
,
"e"
,
"l"
,
"l"
,
"o"
,
" "
,
"w"
,
"o"
,
"r"
,
"l"
,
"d"
,
"!s"
};
LocalIU
predIU
=
null
;
for
(
String
str:
inputString
)
{
LocalIU
localIU
=
new
LocalIU
();
localIU
.
setCategory
(
CATEGORY
);
outBuffer
.
add
(
localIU
);
localIU
.
getPayload
().
put
(
"CONTENT"
,
str
);
if
(
predIU
!=
null
)
{
localIU
.
setLinks
(
"PREDECESSOR"
,
ImmutableSet
.
of
(
predIU
.
getUid
()));
predIU
.
setLinks
(
"SUCCESSOR"
,
ImmutableSet
.
of
(
localIU
.
getUid
()));
}
predIU
=
localIU
;
}
tp
.
start
();
}
}
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