diff --git a/GUI/src/main/java/cz/fidentis/analyst/core/OutputWindow.java b/GUI/src/main/java/cz/fidentis/analyst/core/OutputWindow.java new file mode 100644 index 0000000000000000000000000000000000000000..e1b2aa8bc26296203000fa86cf8d16d7d5647139 --- /dev/null +++ b/GUI/src/main/java/cz/fidentis/analyst/core/OutputWindow.java @@ -0,0 +1,85 @@ +package cz.fidentis.analyst.core; + +import java.awt.BorderLayout; +import java.text.SimpleDateFormat; +import java.time.Duration; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import org.openide.windows.TopComponent; +import org.openide.windows.WindowManager; + +/** + * Wrapper for default output window of the Java Netbeans Platform application. + * It enables to write debug messages into the window. + * + * @author Radek Oslejsek + */ +public class OutputWindow { + + private final JTextArea textArea; + + private long lastTime = System.currentTimeMillis(); + + private static OutputWindow instance; + + protected OutputWindow() { + TopComponent outputWin = WindowManager.getDefault().findTopComponent("output"); + textArea = new JTextArea(); + JScrollPane sp = new JScrollPane(textArea); + outputWin.add(sp, BorderLayout.CENTER); + } + + /** + * Prints the message. The duration indicator is set to [+00:00:000] + * + * @param msg Message to be printed + */ + public static void print(String msg) { + instance().textArea.setText(instance().textArea.getText() + + new SimpleDateFormat("HH:mm:ss").format(System.currentTimeMillis()) + + " [+00:00:000]: " + + msg.trim() + + System.lineSeparator() + ); + } + + /** + * Resets the stopwatch for the duration calculation. + */ + public static void resetStopwatch() { + instance().lastTime = System.currentTimeMillis(); + } + + /** + * Prints the message about an operation and the duration of the operation. + * The duration is computed as the difference between current system time and + * the time of calling {@link #resetStopwatch()}. The difference is measured in + * milliseconds and printed as [+mm:ss.SSS] where mm=minutes, ss=seconds, + * and SSS=milliseconds. + * + * @param msg Message to be printed + */ + public static void printDuration(String msg) { + Duration duration = Duration.ofMillis(System.currentTimeMillis() - instance().lastTime); + instance().textArea.setText(instance().textArea.getText() + + new SimpleDateFormat("HH:mm:ss").format(System.currentTimeMillis()) + + " [+" + + String.format( + "%d:%02d.%03d", + duration.toMinutes(), + duration.toSecondsPart(), + duration.toMillisPart()) + + "]: " + + msg.trim() + + System.lineSeparator() + ); + } + + protected static OutputWindow instance() { + if (instance == null) { + instance = new OutputWindow(); + } + return instance; + } + +} diff --git a/GUI/src/main/java/cz/fidentis/analyst/core/ProjectTopComp.java b/GUI/src/main/java/cz/fidentis/analyst/core/ProjectTopComp.java index 5e118f599a3544dd38293962b8ee5527dcbf27f5..2ab22b914c96b6e63f0ee93e85502e48a377cfda 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/core/ProjectTopComp.java +++ b/GUI/src/main/java/cz/fidentis/analyst/core/ProjectTopComp.java @@ -470,8 +470,10 @@ public final class ProjectTopComp extends TopComponent { if (file == null) { System.out.print("No file chosen."); } else { + OutputWindow.resetStopwatch(); String faceId = HumanFaceFactory.instance().loadFace(file); HumanFace face = HumanFaceFactory.instance().getFace(faceId); + OutputWindow.printDuration("Loaded model " + face.getShortName() +" with " + face.getMeshModel().getNumVertices() + " vertices"); try { // simple hack: diff --git a/MeshModel/src/main/java/cz/fidentis/analyst/mesh/core/MeshModel.java b/MeshModel/src/main/java/cz/fidentis/analyst/mesh/core/MeshModel.java index 27694b38cf2debea774354777d07d48b5850942b..d3271fe5ba6fdbb32a6b3142b99ad1d259fe9599 100644 --- a/MeshModel/src/main/java/cz/fidentis/analyst/mesh/core/MeshModel.java +++ b/MeshModel/src/main/java/cz/fidentis/analyst/mesh/core/MeshModel.java @@ -170,4 +170,15 @@ public class MeshModel implements Serializable { } return facets.size() + " facets with " + verts + " vertices"; } + + /** + * Returns number of vertices }sum of all facets). + * @return Number of vertices + */ + public long getNumVertices() { + //int ret = 0; + //facets.stream().map(f -> f.getNumberOfVertices()).reduce(ret, Integer::sum); + //return ret; + return facets.stream().map(f -> f.getNumberOfVertices()).reduce(0, Integer::sum); + } }