Skip to content

Commit b790161

Browse files
committed
Merge branch 'dev'
2 parents 33f41ee + 374e89c commit b790161

177 files changed

Lines changed: 2834 additions & 1364 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,8 @@ hs_err_pid*
7272

7373
# pmd config file
7474
.eclipse-pmd
75+
.pmd
76+
.pmdruleset.xml
77+
78+
#
79+
*.log.1

SE-Deliverables/Sprintplan8.pdf

5.3 MB
Binary file not shown.
5.31 MB
Binary file not shown.

lifetiles-core/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<artifactId>lifetiles-core</artifactId>
5+
<parent>
6+
<groupId>nl.tudelft.lifetiles</groupId>
7+
<artifactId>lifetiles-parent</artifactId>
8+
<version>1.7-SNAPSHOT</version>
9+
<relativePath>../</relativePath>
10+
</parent>
11+
<name>lifetiles-core</name>
12+
</project>

src/main/java/nl/tudelft/lifetiles/core/controller/AbstractController.java renamed to lifetiles-core/src/main/java/nl/tudelft/lifetiles/core/controller/AbstractController.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.util.List;
66
import java.util.Map;
77
import java.util.concurrent.CopyOnWriteArrayList;
8-
import java.util.function.BiConsumer;
98
import java.util.logging.Level;
109

1110
import javafx.fxml.Initializable;
@@ -28,7 +27,7 @@ public abstract class AbstractController implements Initializable {
2827
/**
2928
* The listeners for messages.
3029
*/
31-
private final Map<Message, List<BiConsumer<AbstractController, Object[]>>> listeners;
30+
private final Map<Message, List<ShoutCallback>> listeners;
3231

3332
/**
3433
* Create a new controller and register it.
@@ -43,16 +42,18 @@ public AbstractController() {
4342
*
4443
* @param message
4544
* the message
45+
* @param subject
46+
* The subject of this message.
4647
* @param args
4748
* the arguments of the message
4849
*/
49-
protected final void shout(final Message message, final Object... args) {
50+
protected final void shout(final Message message, final String subject,
51+
final Object... args) {
5052
for (AbstractController c : controllers) {
51-
List<BiConsumer<AbstractController, Object[]>> listenersOther = c
52-
.getListeners(message);
53+
List<ShoutCallback> listenersOther = c.getListeners(message);
5354
if (listenersOther != null) {
5455
listenersOther.stream().forEach(
55-
listener -> listener.accept(this, args));
56+
listener -> listener.accept(this, subject, args));
5657
}
5758
}
5859

@@ -68,11 +69,11 @@ protected final void shout(final Message message, final Object... args) {
6869
* the action to perform when recieving the message
6970
*/
7071
protected final void listen(final Message message,
71-
final BiConsumer<AbstractController, Object[]> action) {
72+
final ShoutCallback action) {
7273
if (listeners.containsKey(message)) {
7374
listeners.get(message).add(action);
7475
} else {
75-
List<BiConsumer<AbstractController, Object[]>> newListeners;
76+
List<ShoutCallback> newListeners;
7677
newListeners = new ArrayList<>();
7778
newListeners.add(action);
7879
listeners.put(message, newListeners);
@@ -86,8 +87,7 @@ protected final void listen(final Message message,
8687
* the message
8788
* @return a map of listeners for messages
8889
*/
89-
private List<BiConsumer<AbstractController, Object[]>> getListeners(
90-
final Message message) {
90+
private List<ShoutCallback> getListeners(final Message message) {
9191
return listeners.get(message);
9292
}
9393

src/main/java/nl/tudelft/lifetiles/core/controller/MainController.java renamed to lifetiles-core/src/main/java/nl/tudelft/lifetiles/core/controller/MainController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public final void initialize(final URL location,
3838

3939
repaint(true);
4040

41-
listen(Message.OPENED, (controller, args) -> {
41+
listen(Message.OPENED, (controller, subject, args) -> {
4242
repaint(false);
4343
});
4444
}

src/main/java/nl/tudelft/lifetiles/core/controller/MenuController.java renamed to lifetiles-core/src/main/java/nl/tudelft/lifetiles/core/controller/MenuController.java

Lines changed: 103 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33
import java.io.File;
44
import java.io.IOException;
55
import java.net.URL;
6-
import java.util.ArrayList;
7-
import java.util.Arrays;
8-
import java.util.HashSet;
9-
import java.util.List;
10-
import java.util.Map;
116
import java.util.ResourceBundle;
12-
import java.util.Set;
137

148
import javafx.event.ActionEvent;
159
import javafx.fxml.FXML;
@@ -21,12 +15,9 @@
2115
import javafx.stage.Window;
2216
import nl.tudelft.lifetiles.core.util.FileUtils;
2317
import nl.tudelft.lifetiles.core.util.Message;
24-
import nl.tudelft.lifetiles.graph.controller.GraphController;
25-
import nl.tudelft.lifetiles.graph.model.Graph;
2618
import nl.tudelft.lifetiles.notification.controller.NotificationController;
2719
import nl.tudelft.lifetiles.notification.model.AbstractNotification;
2820
import nl.tudelft.lifetiles.notification.model.NotificationFactory;
29-
import nl.tudelft.lifetiles.sequence.model.Sequence;
3021

3122
/**
3223
* The controller of the menu bar.
@@ -40,6 +31,22 @@ public class MenuController extends AbstractController {
4031
* Constant annotation extension, currently as defined by client: '.txt'.
4132
*/
4233
private static final String ANNOTATION_EXTENSION = ".txt";
34+
/**
35+
* Extension of the node file.
36+
*/
37+
private static final String NODE_EXTENSION = ".node.graph";
38+
/**
39+
* Extension of the edge file.
40+
*/
41+
private static final String EDGE_EXTENSION = ".edge.graph";
42+
/**
43+
* Extension of the tree file.
44+
*/
45+
private static final String TREE_EXTENSION = ".nwk";
46+
/**
47+
* Extension of the sequence meta data file.
48+
*/
49+
private static final String META_EXTENSION = ".meta";
4350

4451
/**
4552
* The initial x-coordinate of the window.
@@ -62,11 +69,6 @@ public class MenuController extends AbstractController {
6269
*/
6370
private NotificationFactory nf;
6471

65-
/**
66-
* all sequences, to reset the filters.
67-
*/
68-
private Set<Sequence> sequences;
69-
7072
/**
7173
* Handle action related to "Open" menu item.
7274
*
@@ -79,7 +81,7 @@ private void openAction(final ActionEvent event) {
7981
loadDataFiles();
8082
} catch (IOException e) {
8183
AbstractNotification notification = nf.getNotification(e);
82-
shout(NotificationController.NOTIFY, notification);
84+
shout(NotificationController.NOTIFY, "", notification);
8385
}
8486
}
8587

@@ -91,9 +93,7 @@ private void openAction(final ActionEvent event) {
9193
*/
9294
@FXML
9395
private void resetAction(final ActionEvent event) {
94-
if (sequences != null) {
95-
shout(Message.FILTERED, sequences);
96-
}
96+
shout(Message.RESET, "");
9797
}
9898

9999
/**
@@ -113,31 +113,95 @@ private void loadDataFiles() throws IOException {
113113
if (directory == null) {
114114
return;
115115
}
116+
loadGraph(directory);
117+
loadTree(directory);
118+
loadAnnotations(directory);
119+
loadMetaData(directory);
120+
}
116121

117-
List<File> dataFiles = new ArrayList<>();
118-
List<File> annotations = FileUtils.findByExtension(directory,
119-
ANNOTATION_EXTENSION);
122+
/**
123+
* Loads the graph from files in the specified directory.
124+
*
125+
* @param directory
126+
* The directory in which to locate the files.
127+
* @throws IOException
128+
* When the directory does not contain exactly one graph file
129+
* and one node file.
130+
*/
131+
private void loadGraph(final File directory) throws IOException {
132+
File nodeFile = FileUtils.getSingleFileByExtension(directory,
133+
NODE_EXTENSION);
134+
File edgeFile = FileUtils.getSingleFileByExtension(directory,
135+
EDGE_EXTENSION);
136+
shout(Message.OPENED, "graph", nodeFile, edgeFile);
137+
}
120138

121-
List<String> exts = Arrays.asList(".node.graph", ".edge.graph", ".nwk");
122-
for (String ext : exts) {
123-
List<File> hits = FileUtils.findByExtension(directory, ext);
124-
if (hits.size() != 1) {
125-
throw new IOException("Expected 1 " + ext + " file intead of "
126-
+ hits.size());
127-
}
139+
/**
140+
* Loads the sequence meta-data file in the specified directory.
141+
*
142+
* @param directory
143+
* The directory in which to locate the files.
144+
* @throws IOException
145+
* When the directory does not contain exactly one graph file
146+
* and one node file.
147+
*/
148+
private void loadMetaData(final File directory) throws IOException {
149+
File metaDataFile = loadOrWarn(directory, META_EXTENSION);
150+
if (metaDataFile != null) {
151+
shout(Message.OPENED, "meta", metaDataFile);
152+
}
153+
}
154+
155+
/**
156+
* Loads the annotations from a file in the specified directory.
157+
*
158+
* @param directory
159+
* The directory from which to load annotations.
160+
*/
161+
private void loadAnnotations(final File directory) {
162+
File annotationFile = loadOrWarn(directory, ANNOTATION_EXTENSION);
163+
if (annotationFile != null) {
164+
shout(Message.OPENED, "annotations", annotationFile);
165+
}
166+
}
128167

129-
dataFiles.add(hits.get(0));
168+
/**
169+
* Loads the tree from a file in the specified directory.
170+
*
171+
* @param directory
172+
* The directory in which to search for the tree file.
173+
*/
174+
private void loadTree(final File directory) {
175+
File treeFile = loadOrWarn(directory, TREE_EXTENSION);
176+
if (treeFile != null) {
177+
shout(Message.OPENED, "tree", treeFile);
130178
}
179+
}
131180

132-
shout(Message.OPENED, dataFiles.get(0), dataFiles.get(1),
133-
dataFiles.get(2));
134-
if (annotations == null || annotations.isEmpty()) {
135-
shout(NotificationController.NOTIFY, nf.getNotification(
136-
"Annotation file (" + ANNOTATION_EXTENSION
137-
+ ") can't be found", NotificationFactory.WARNING));
138-
} else {
139-
shout(GraphController.ANNOTATIONS, annotations.get(0));
181+
/**
182+
* Loads a file from the specified directory, with the specified extension,
183+
* and give a warning.
184+
*
185+
* @param directory
186+
* The directory in which to search for the file.
187+
* @param extension
188+
* The extension to search for.
189+
* @return The found file.
190+
*/
191+
private File loadOrWarn(final File directory, final String extension) {
192+
try {
193+
File file = FileUtils
194+
.getSingleFileByExtension(directory, extension);
195+
return file;
196+
} catch (IOException e) {
197+
shout(NotificationController.NOTIFY,
198+
"",
199+
nf.getNotification(
200+
extension
201+
+ " file could not be found or multiple files found ",
202+
NotificationFactory.WARNING));
140203
}
204+
return null;
141205
}
142206

143207
/**
@@ -152,7 +216,7 @@ private void insertAnnotationsAction(final ActionEvent event) {
152216
loadAnnotationsFile();
153217
} catch (IOException e) {
154218
AbstractNotification notification = nf.getNotification(e);
155-
shout(NotificationController.NOTIFY, notification);
219+
shout(NotificationController.NOTIFY, "", notification);
156220
}
157221
}
158222

@@ -175,7 +239,7 @@ private void loadAnnotationsFile() throws IOException {
175239
return;
176240
}
177241

178-
shout(GraphController.ANNOTATIONS, file);
242+
shout(Message.OPENED, "annotations", file);
179243
}
180244

181245
/**
@@ -210,15 +274,5 @@ public final void initialize(final URL location,
210274
final ResourceBundle resources) {
211275
addDraggableNode(menuBar);
212276
nf = new NotificationFactory();
213-
// listen to loaded to get the sequence list
214-
listen(Message.LOADED,
215-
(controller, args) -> {
216-
if (controller instanceof GraphController) {
217-
assert args[0] instanceof Graph;
218-
assert (args[1] instanceof Map<?, ?>);
219-
Map<String, Sequence> sequenceMap = (Map<String, Sequence>) args[1];
220-
sequences = new HashSet<Sequence>(sequenceMap.values());
221-
}
222-
});
223277
}
224278
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package nl.tudelft.lifetiles.core.controller;
2+
3+
/**
4+
* Function interface for shouts.
5+
*
6+
* @author Rutger van den Berg
7+
*
8+
*/
9+
@FunctionalInterface
10+
public interface ShoutCallback {
11+
/**
12+
* @param sender
13+
* The sending controller.
14+
* @param subject
15+
* The subject of the message.
16+
* @param args
17+
* The optional arguments.
18+
*/
19+
void accept(AbstractController sender, String subject, Object[] args);
20+
}

0 commit comments

Comments
 (0)