Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nils Vreman
ScheduLearn
Commits
4f9cf33b
Commit
4f9cf33b
authored
Oct 22, 2018
by
Nils Vreman
Browse files
Tried introducing empty taskset slots
parent
90835c23
Changes
12
Hide whitespace changes
Inline
Side-by-side
data/EDFIsWrong.sl
0 → 100644
View file @
4f9cf33b
1,3,3
1,4,3
1,4,4
1,6,6
data/EDFnotRMS.sl
0 → 100644
View file @
4f9cf33b
2,5,3
2,4,4
2,20,15
data/harmonic.sl
0 → 100644
View file @
4f9cf33b
1,2,2
1,4,4
1,8,8
1,16,16
gui/tasksetgui/AbstractGrid.java
0 → 100644
View file @
4f9cf33b
package
gui.tasksetgui
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.awt.Color
;
import
gui.GridPanel
;
import
gui.UpdateListener
;
public
abstract
class
AbstractGrid
extends
GridPanel
implements
UpdateListener
,
MarkListener
{
private
String
[]
attributes
=
new
String
[]
{
"Pri"
,
"e"
,
"p"
,
"d"
};
private
Map
<
String
,
GridLabel
>
labelMap
;
private
UpdateListener
updateListener
;
private
MarkListener
markListener
;
// attributes should contain [prio, exectime, period, deadline]
public
AbstractGrid
(
String
[]
taskAttributes
)
{
super
(
1
,
4
);
labelMap
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
GridLabel
label
=
getLabel
(
taskAttributes
[
i
]);
//new GridLabel(taskAttributes[i]);
label
.
addUpdateListener
(
this
);
label
.
addMarkListener
(
this
);
if
(
i
==
0
)
label
.
setEditable
(
false
);
// Forbids people from changing priority
add
(
label
);
labelMap
.
put
(
attributes
[
i
],
label
);
}
}
public
AbstractGrid
(
String
prio
,
String
exec
,
String
period
,
String
deadline
)
{
this
(
new
String
[]
{
prio
,
exec
,
period
,
deadline
});
}
/*
* return: attributes from this gridLine
*/
public
int
[]
getAttributes
()
{
int
[]
attr
=
new
int
[
4
];
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
TaskLabel
label
=
(
TaskLabel
)
labelMap
.
get
(
attributes
[
i
]);
attr
[
i
]
=
Integer
.
parseInt
(
label
.
getText
());
}
return
attr
;
}
/*
* Get label based on subclass type
*/
protected
abstract
GridLabel
getLabel
(
String
taskAttributes
);
/*
* Compares two taskgrid objects and returns the equality between the two
*/
public
boolean
equals
(
AbstractGrid
ag
)
{
return
getAttributes
()[
0
]
==
ag
.
getAttributes
()[
0
];
}
/*
* The function to be performed when the observable class is updated.
* NOTE: TWO INTERFACES ARE NEEDED SUCH THAT THE UI ISN'T UPDATED ONLY WHEN MARKED.
*/
public
void
update
(
Object
obj
)
{
updateListener
.
update
(
this
);
}
/*
* The function to be performed when the tasklabel class is marked.
* NOTE: TWO INTERFACES ARE NEEDED SUCH THAT THE UI ISN'T UPDATED ONLY WHEN MARKED.
*/
public
void
markUpdate
(
Object
obj
)
{
markListener
.
markUpdate
(
this
);
}
/*
* Sets observer of this class
* (Would have used observable superclass unless I already had a superclass)
*/
public
void
addUpdateListener
(
UpdateListener
updateListener
)
{
this
.
updateListener
=
updateListener
;
}
/*
* Sets observer of this class
* (Would have used observable superclass unless I already had a superclass)
*/
public
void
addMarkListener
(
MarkListener
markListener
)
{
this
.
markListener
=
markListener
;
}
/*
* Marks all the tasklabels of this taskgrid.
*/
public
void
mark
()
{
colorize
(
Color
.
YELLOW
);
}
/*
* Unmarks all the tasklabels of this taskgrid.
*/
public
void
unmark
()
{
colorize
(
Color
.
WHITE
);
}
//Private help function to reduce code size
private
void
colorize
(
Color
c
)
{
for
(
GridLabel
tl
:
labelMap
.
values
())
{
tl
.
setBackground
(
c
);
}
}
}
gui/tasksetgui/AddButton.java
View file @
4f9cf33b
...
@@ -30,3 +30,23 @@ public class AddButton extends ActionButton {
...
@@ -30,3 +30,23 @@ public class AddButton extends ActionButton {
}
}
}
}
//package gui.tasksetgui;
//
//import java.awt.event.ActionEvent;
//import java.awt.event.ActionListener;
//import javax.swing.JButton;
//
//public class AddButton extends JButton {
// protected AddButton(TasksetDisplay display) {
// super("Add Task");
// addEventHandler(display);
// }
//
// protected void addEventHandler(TasksetDisplay display) {
// addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// display.addEmpty();
// }
// });
// }
//}
gui/tasksetgui/EmptyGrid.java
0 → 100644
View file @
4f9cf33b
package
gui.tasksetgui
;
public
class
EmptyGrid
extends
AbstractGrid
{
// attributes should contain [prio, exectime, period, deadline]
public
EmptyGrid
(
String
[]
taskAttributes
)
{
super
(
taskAttributes
);
}
public
EmptyGrid
()
{
super
(
new
String
[
4
]);
}
public
EmptyGrid
(
String
prio
,
String
exec
,
String
period
,
String
deadline
)
{
super
(
new
String
[]
{
prio
,
exec
,
period
,
deadline
});
}
/*
* Get label based on subclass type
*/
protected
GridLabel
getLabel
(
String
taskAttribute
)
{
return
new
EmptyLabel
(
taskAttribute
);
}
}
gui/tasksetgui/EmptyLabel.java
0 → 100644
View file @
4f9cf33b
package
gui.tasksetgui
;
public
class
EmptyLabel
extends
GridLabel
{
public
EmptyLabel
()
{
super
(
""
);
}
public
EmptyLabel
(
String
text
)
{
super
(
""
);
}
/*
* Sets the text filter for this label
*/
protected
void
setFilter
()
{
setDocument
(
new
EmptyLabelFilter
());
}
}
gui/tasksetgui/EmptyLabelFilter.java
0 → 100644
View file @
4f9cf33b
package
gui.tasksetgui
;
import
javax.swing.text.AttributeSet
;
import
javax.swing.text.BadLocationException
;
import
javax.swing.text.PlainDocument
;
import
java.util.regex.Pattern
;
import
java.util.regex.Matcher
;
public
class
EmptyLabelFilter
extends
PlainDocument
{
public
void
insertString
(
int
offs
,
String
str
,
AttributeSet
a
)
throws
BadLocationException
{
if
(
str
==
null
)
return
;
String
oldString
=
getText
(
0
,
getLength
());
String
newString
=
oldString
.
substring
(
0
,
offs
)
+
str
+
oldString
.
substring
(
offs
);
try
{
Pattern
p
=
Pattern
.
compile
(
"[^0-9 ]"
);
Matcher
m
=
p
.
matcher
(
newString
);
if
(!
m
.
find
())
super
.
insertString
(
offs
,
str
,
a
);
}
catch
(
NumberFormatException
e
)
{}
}
}
gui/tasksetgui/GridLabel.java
0 → 100644
View file @
4f9cf33b
package
gui.tasksetgui
;
import
java.awt.event.ActionListener
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.MouseListener
;
import
java.awt.event.MouseEvent
;
import
java.awt.Color
;
import
javax.swing.JTextField
;
import
gui.UpdateListener
;
public
abstract
class
GridLabel
extends
JTextField
implements
MouseListener
{
private
UpdateListener
updateListener
;
private
MarkListener
markListener
;
public
GridLabel
(
String
text
)
{
// Front-end Characteristics
super
(
text
);
setBackground
(
Color
.
WHITE
);
setOpaque
(
true
);
setFilter
();
setText
(
text
);
// Add Listener for when mouse does something with object
addMouseListener
(
this
);
// Add Listener that does something with object when <Enter> is pressed
addActionListener
(
new
ActionListener
()
{
public
void
actionPerformed
(
ActionEvent
e
)
{
if
(
getText
().
matches
(
"[0-9]+"
))
{
updateListener
.
update
();
}
}
});
}
/*
* Sets the text filter for this label
*/
protected
abstract
void
setFilter
();
/*
* Sets observer of this class
* (Would have used observable superclass unless I already had a superclass)
*/
public
void
addUpdateListener
(
UpdateListener
updateListener
)
{
this
.
updateListener
=
updateListener
;
}
/*
* Sets observer of this class
* (Would have used observable superclass unless I already had a superclass)
*/
public
void
addMarkListener
(
MarkListener
markListener
)
{
this
.
markListener
=
markListener
;
}
// MouseListener Functions.
/*
* Invoked when the mouse button has been clicked (pressed and released) on a component.
*/
public
void
mouseClicked
(
MouseEvent
e
)
{
markListener
.
markUpdate
(
this
);
}
/*
* Invoked when a mouse button has been pressed on a component.
*/
public
void
mousePressed
(
MouseEvent
e
)
{}
/*
* Invoked when a mouse button has been released on a component.
*/
public
void
mouseReleased
(
MouseEvent
e
)
{}
/*
* Invoked when the mouse enters a component.
*/
public
void
mouseEntered
(
MouseEvent
e
)
{}
/*
* Invoked when the mouse exits a component.
*/
public
void
mouseExited
(
MouseEvent
e
)
{}
}
gui/tasksetgui/TaskGrid.java
View file @
4f9cf33b
package
gui.tasksetgui
;
package
gui.tasksetgui
;
import
java.util.HashMap
;
public
class
TaskGrid
extends
AbstractGrid
{
import
java.util.Map
;
import
java.awt.Color
;
import
gui.GridPanel
;
import
gui.UpdateListener
;
public
class
TaskGrid
extends
GridPanel
implements
UpdateListener
,
MarkListener
{
private
String
[]
attributes
=
new
String
[]
{
"Pri"
,
"e"
,
"p"
,
"d"
};
private
Map
<
String
,
TaskLabel
>
labelMap
;
private
UpdateListener
updateListener
;
private
MarkListener
markListener
;
// attributes should contain [prio, exectime, period, deadline]
// attributes should contain [prio, exectime, period, deadline]
public
TaskGrid
(
String
[]
taskAttributes
)
{
public
TaskGrid
(
String
[]
taskAttributes
)
{
super
(
1
,
4
);
super
(
taskAttributes
);
labelMap
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
TaskLabel
label
=
new
TaskLabel
(
taskAttributes
[
i
]);
label
.
addUpdateListener
(
this
);
label
.
addMarkListener
(
this
);
if
(
i
==
0
)
label
.
setEditable
(
false
);
// Forbids people from changing priority
add
(
label
);
labelMap
.
put
(
attributes
[
i
],
label
);
}
}
}
public
TaskGrid
(
String
prio
,
String
exec
,
String
period
,
String
deadline
)
{
public
TaskGrid
(
String
prio
,
String
exec
,
String
period
,
String
deadline
)
{
this
(
new
String
[]
{
prio
,
exec
,
period
,
deadline
});
super
(
new
String
[]
{
prio
,
exec
,
period
,
deadline
});
}
/*
* return: attributes from this gridLine
*/
public
int
[]
getAttributes
()
{
int
[]
attr
=
new
int
[
4
];
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
TaskLabel
label
=
labelMap
.
get
(
attributes
[
i
]);
attr
[
i
]
=
Integer
.
parseInt
(
label
.
getText
());
}
return
attr
;
}
}
/*
/*
*
Compares two taskgrid objects and returns the equality between the two
*
Get label based on subclass type
*/
*/
public
boolean
equals
(
TaskGrid
tg
)
{
protected
GridLabel
getLabel
(
String
taskAttribute
)
{
return
getAttributes
()[
0
]
==
tg
.
getAttributes
()[
0
];
return
new
TaskLabel
(
taskAttribute
);
}
/*
* The function to be performed when the observable class is updated.
* NOTE: TWO INTERFACES ARE NEEDED SUCH THAT THE UI ISN'T UPDATED ONLY WHEN MARKED.
*/
public
void
update
(
Object
obj
)
{
updateListener
.
update
(
this
);
}
/*
* The function to be performed when the tasklabel class is marked.
* NOTE: TWO INTERFACES ARE NEEDED SUCH THAT THE UI ISN'T UPDATED ONLY WHEN MARKED.
*/
public
void
markUpdate
(
Object
obj
)
{
markListener
.
markUpdate
(
this
);
}
/*
* Sets observer of this class
* (Would have used observable superclass unless I already had a superclass)
*/
public
void
addUpdateListener
(
UpdateListener
updateListener
)
{
this
.
updateListener
=
updateListener
;
}
/*
* Sets observer of this class
* (Would have used observable superclass unless I already had a superclass)
*/
public
void
addMarkListener
(
MarkListener
markListener
)
{
this
.
markListener
=
markListener
;
}
/*
* Marks all the tasklabels of this taskgrid.
*/
public
void
mark
()
{
colorize
(
Color
.
YELLOW
);
}
/*
* Unmarks all the tasklabels of this taskgrid.
*/
public
void
unmark
()
{
colorize
(
Color
.
WHITE
);
}
//Private help function to reduce code size
private
void
colorize
(
Color
c
)
{
for
(
TaskLabel
tl
:
labelMap
.
values
())
{
tl
.
setBackground
(
c
);
}
}
}
}
}
gui/tasksetgui/TaskLabel.java
View file @
4f9cf33b
package
gui.tasksetgui
;
package
gui.tasksetgui
;
import
java.awt.event.ActionListener
;
public
class
TaskLabel
extends
GridLabel
{
import
java.awt.event.ActionEvent
;
import
java.awt.event.MouseListener
;
import
java.awt.event.MouseEvent
;
import
java.awt.Color
;
import
javax.swing.JTextField
;
import
gui.UpdateListener
;
public
class
TaskLabel
extends
JTextField
implements
MouseListener
{
private
UpdateListener
updateListener
;
private
MarkListener
markListener
;
public
TaskLabel
(
String
text
)
{
public
TaskLabel
(
String
text
)
{
// Front-end Characteristics
// Front-end Characteristics
super
(
text
);
super
(
text
);
setBackground
(
Color
.
WHITE
);
setOpaque
(
true
);
setDocument
(
new
TaskLabelFilter
());
setText
(
text
);
// Add Listener for when mouse does something with object
addMouseListener
(
this
);
// Add Listener that does something with object when <Enter> is pressed
addActionListener
(
new
ActionListener
()
{
public
void
actionPerformed
(
ActionEvent
e
)
{
if
(
getText
().
matches
(
"[0-9]+"
))
{
updateListener
.
update
();
}
}
});
}
}
/*
/*
* Sets observer of this class
* Sets the text filter for this label
* (Would have used observable superclass unless I already had a superclass)
*/
public
void
addUpdateListener
(
UpdateListener
updateListener
)
{
this
.
updateListener
=
updateListener
;
}
/*
* Sets observer of this class
* (Would have used observable superclass unless I already had a superclass)
*/
public
void
addMarkListener
(
MarkListener
markListener
)
{
this
.
markListener
=
markListener
;
}
// MouseListener Functions.
/*
* Invoked when the mouse button has been clicked (pressed and released) on a component.
*/
*/
p
ublic
void
mouseClicked
(
MouseEvent
e
)
{
p
rotected
void
setFilter
(
)
{
markListener
.
markUpdate
(
this
);
setDocument
(
new
TaskLabelFilter
()
);
}
}
/*
* Invoked when a mouse button has been pressed on a component.
*/
public
void
mousePressed
(
MouseEvent
e
)
{}
/*
* Invoked when a mouse button has been released on a component.
*/
public
void
mouseReleased
(
MouseEvent
e
)
{}
/*
* Invoked when the mouse enters a component.
*/
public
void
mouseEntered
(
MouseEvent
e
)
{}
/*
* Invoked when the mouse exits a component.
*/
public
void
mouseExited
(
MouseEvent
e
)
{}
}
}
gui/tasksetgui/TasksetDisplay.java
View file @
4f9cf33b
...
@@ -23,6 +23,7 @@ public class TasksetDisplay extends BoxPanel implements Observer, UpdateListener
...
@@ -23,6 +23,7 @@ public class TasksetDisplay extends BoxPanel implements Observer, UpdateListener
private
TaskGridHeader
header
=
new
TaskGridHeader
(
" Priority"
,
"Exectime"
,
" Period"
,
"Deadline"
);
private
TaskGridHeader
header
=
new
TaskGridHeader
(
" Priority"
,
"Exectime"
,
" Period"
,
"Deadline"
);
private
List
<
TaskGrid
>
gridList
=
new
ArrayList
<>();
private
List
<
TaskGrid
>
gridList
=
new
ArrayList
<>();
private
Optional
<
TaskGrid
>
marked
=
Optional
.
empty
();
// Used to indicate which taskgrid is marked
private
Optional
<
TaskGrid
>
marked
=
Optional
.
empty
();
// Used to indicate which taskgrid is marked
private
Optional
<
TaskGrid
>
emptyTask
=
Optional
.
empty
();
// Used to indicate which taskgrid is marked
private
final
int
offset
=
200
;
private
final
int
offset
=
200
;
public
TasksetDisplay
(
Taskset
taskset
)
{
public
TasksetDisplay
(
Taskset
taskset
)
{
...
@@ -114,6 +115,19 @@ public class TasksetDisplay extends BoxPanel implements Observer, UpdateListener
...
@@ -114,6 +115,19 @@ public class TasksetDisplay extends BoxPanel implements Observer, UpdateListener
}
catch
(
NoSuchElementException
e
)
{}
}
catch
(
NoSuchElementException
e
)
{}
}
}
/*
* Add empty grid. Not if one already exists
*/
public
void
addEmpty
()
{
if
(!
emptyTask
.
isPresent
())
{
/*
emptyTask = Optional.of(new EmptyGrid());
marked = emptyTask;
markUpdate(emptyTask.get());
*/
}
}
// Private help method.
// Private help method.
private
String
parse
(
int
i
)
{
private
String
parse
(
int
i
)
{
return
String
.
valueOf
(
i
);
return
String
.
valueOf
(
i
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment