Kolja Strohm 7 years ago
parent
commit
62158f22b1
44 changed files with 337 additions and 222 deletions
  1. 55 45
      doc/chapter/2architecture.tex
  2. 46 12
      doc/chapter/3ui.tex
  3. 12 0
      doc/doc.bib
  4. 4 4
      doc/doc.tex
  5. 0 0
      doc/img/algorithms_animated.pdf
  6. BIN
      doc/img/bk-example-ours.jpg
  7. BIN
      doc/img/bk-example-theirs.png
  8. 0 26
      doc/img/graph.json
  9. 0 0
      doc/img/io.pdf
  10. 0 0
      doc/img/model.pdf
  11. BIN
      doc/img/skizze.png
  12. 0 0
      doc/img/view.pdf
  13. 0 0
      doc/src/.keep
  14. 36 0
      doc/src/graph.json
  15. BIN
      doc/vpp/components.vpp
  16. 37 1
      doc/zotero_backup/NodePlacementAnimation/NodePlacementAnimation.rdf
  17. 0 0
      doc/zotero_backup/NodePlacementAnimation/files/1065/Carstens - Node and Label Placement in a Layered Layout Algor.pdf
  18. 0 31
      src/Algorithms/RandomColorGenerator.java
  19. 1 1
      src/animation/Action.java
  20. 2 2
      src/animation/AlgorithmStage.java
  21. 2 4
      src/animation/AnimatedAlgorithm.java
  22. 1 1
      src/animation/AnimationController.java
  23. 1 1
      src/animation/BackwardAction.java
  24. 6 5
      src/bk/BKNodePlacement.java
  25. 6 6
      src/bk/BlockCalc.java
  26. 4 6
      src/bk/Combine.java
  27. 9 5
      src/bk/Compaction.java
  28. 5 5
      src/bk/ConflictDetection.java
  29. 3 3
      src/bk/ExtremalLayoutCalc.java
  30. 5 9
      src/graph/InitializeNodePositions.java
  31. 3 3
      src/graph/LayeredEdge.java
  32. 2 2
      src/graph/LayeredGraphEdge.java
  33. 4 4
      src/graph/LayeredGraphNode.java
  34. 4 4
      src/graph/LayeredNode.java
  35. 1 4
      src/graph/RandomGraphGenerator.java
  36. 8 4
      src/graph/io/Reader.java
  37. 3 3
      src/graph/io/Writer.java
  38. 7 4
      src/lib/SweepCrossingMinimizer.java
  39. 11 6
      src/main/Main.java
  40. 3 3
      src/view/EdgeView.java
  41. 16 13
      src/view/MainView.java
  42. 3 3
      src/view/NodeView.java
  43. 1 1
      src/view/RenderHelper.java
  44. 36 1
      test3.json

+ 55 - 45
doc/chapter/2architecture.tex

@@ -20,65 +20,70 @@ The structure is as follows:
     \item The object in the JSON file is a node.
     \item A node has the attributes that are displayed in table~\ref{table:node-attributes}.
     \item An edge has the attributes that are displayed in table~\ref{table:edge-attributes}.
+    \item Any additional attributes not listed here are ignored.
+    For example they can be used as comment fields, to make the file more readable.
 \end{itemize}
 For parsing the JSON file the JSON-java library~\cite{leary_json-java:_2018} is used.
 The classes for reading and writing those JSON files are displayed in figure~\ref{fig:io}.
 The internal representation of graphs is further explained in the section~\ref{sec:model}.
 
 \centering
-\begin{longtable}{|p{1.8cm}|p{2.3cm}|p{1.7cm}|p{8.5cm}|}
+\begin{longtable}{|l|l|l|p{8.5cm}|}
     \hline
     Attribute & Type & Optional & Explanation \\\hline\hline
     name & string & yes & If not omitted, this must be unique for a given parent node. \\\hline
     width & integer & yes & The minimum width of the node.
-    The node can be wider if it contains other nodes that need more space. \\\hline
+    The node can be wider if it contains other nodes that need more space.
+    If the whole layout is too large, it is resized, such that all nodes are proportionately shrunk: In that case the minimum width can be undercut.
+    Default 40.\\\hline
     height & integer & yes & The minimum height of the node.
-    The node can be higher if it contains other nodes that need more space. \\\hline
+    The node can be higher if it contains other nodes that need more space.
+    If the whole layout is too large, it is resized, such that all nodes are proportionately shrunk: In that case the minimum height can be undercut.
+    Default 40.\\\hline
     dummy & boolean & yes & Iff this is set to yes, then the node is a dummy node. \\\hline
-    layers & list of lists of nodes & yes & The layers of nodes inside this node (Hierarchy). \\\hline
-    edges & list of edges & yes & The edges between nodes whose parent node is this node. \\\hline
-    \caption{Node Attributes}
+    layers & < < node > > & yes & The layers of nodes inside this node (Hierarchy). \\\hline
+    edges & < edge > & yes & The edges between nodes whose parent node is this node. \\\hline
+    \caption{Node Attributes. < \emph{element type} > is a list.}
     \label{table:node-attributes}
 \end{longtable}
+\raggedright
 
-\begin{figure}[tp]
+\begin{figure}[htp]
     \centering
-    \includegraphics[width=\linewidth, trim={0 20cm 0 0}]{img/IO.pdf}
-    \caption[Class diagram of the \enquote{IO} package]{Class diagram of the \enquote{IO} package, containing utilities for reading and writing graphs.}
+    \includegraphics[width=\linewidth,trim=0 20cm 0 0,clip]{img/io.pdf}
+    \caption[Class diagram of the \enquote{graph.io} package]{Class diagram of the \enquote{graph.io} package, containing utilities for reading and writing graphs.}
     \label{fig:io}
 \end{figure}
 
-\newpage
-
-\TODO{attribute for dummy nodes}
-\begin{longtable}{|p{1.8cm}|p{2cm}|p{1.8cm}|p{8.5cm}|}
-    \hline
-    Attribute & Type & Optional & Explanation \\\hline\hline
-    source & string & no & The name of the source of this edge.
-    Must be a node with the same parent node as the node specified by the \enquote{target} attribute. \\\hline
-    target & string & no & The name of the target of this edge.
-    Must be a node with the same parent node as the node specified by the \enquote{source} attribute. \\\hline
+\begin{table}[htp]
+    \centering
+    \begin{longtable}{|l|l|l|p{8.5cm}|}
+        \hline
+        Attribute & Type & Optional & Explanation \\\hline\hline
+        source & string & no & The name of the source of this edge.
+        Must be a node with the same parent node as the node specified by the \enquote{target} attribute. \\\hline
+        target & string & no & The name of the target of this edge.
+        Must be a node with the same parent node as the node specified by the \enquote{source} attribute. \\\hline
+    \end{longtable}
     \caption{Edge Attributes}
     \label{table:edge-attributes}
-\end{longtable}
-\raggedright
+\end{table}
 
-%\begin{figure}[tp]
+%\begin{figure}[htp]
 %    \centering
 %    \includegraphics[width=0.9\textwidth]{img/json.png}
 %    \caption[Input file format]{Input file format illustrated as a HERM diagram}
 %    \label{fig:iff}
 %\end{figure}
 
-\TODO{Kante in beispielJSON}
 \begin{figure}
-    \begin{lstinputlisting}[language=json,emph={}]{img/graph.json}
+    \begin{lstinputlisting}[language=json,emph={}]{src/graph.json}
     \end{lstinputlisting}
     \caption[Example Input File]{Example Input file that is understood by \appname.}
     \label{fig:json-example}
 \end{figure}
 
-\section{Internal graph representation, \enquote{Model}}\label{sec:model}
+\section{Internal graph representation, \enquote{graph}}\label{sec:model}
 One feature that is important to us, is to be able to work with hierarchical graphs (cf.\ chapter~\ref{ch:progress}).
 Therefore a node not only has edges to other nodes, but also it can contain other nodes and edges.
 So far this is similar to what we described in section~\ref{sec:inputFileFormat}.
@@ -97,31 +102,35 @@ Similarly, edges have additional attributes:
     \item \enquote{bindPoints} is a list of bend points for the edge, including the beginning and end point of the edge.
 \end{itemize}
 
-A class diagram of the package \enquote{Model} is displayed in figure~\ref{fig:model}.
+A class diagram of the package \enquote{graph} is displayed in figure~\ref{fig:model}.
 
-\begin{figure}[tp]
+\begin{figure}[htp]
     \centering
-    \includegraphics[width=\linewidth, trim={0 6cm 0 0}]{img/Model.pdf}
-    \caption{Class diagram of the \enquote{Model} package.}
+    \includegraphics[width=\linewidth,trim=0 6cm 0 0,clip]{img/model.pdf}
+    \caption{Class diagram of the \enquote{graph} package.}
     \label{fig:model}
 \end{figure}
 
-\begin{longtable}{|p{2.8cm}|p{10cm}|}
-    \hline
-    Attribute & Explanation \\\hline\hline
-    root & The root node of the block of this node.
-    Unique for all nodes in the same block. \\\hline
-    sink & The topmost sink in the block graph that can be reached from the block that this node belongs to.
-    Only used for nodes that are the root of a block.
-    Unique for all nodes in the same class. \\\hline
-    shift & The shift of the class that this node belongs to.
-    Only used for nodes that are a sink of a class. \\\hline
+
+\begin{table}[htp]
+    \begin{longtable}{|l|p{10cm}|}
+        \hline
+        Attribute & Explanation \\\hline\hline
+        root & The root node of the block of this node.
+        Unique for all nodes in the same block. \\\hline
+        sink & The topmost sink in the block graph that can be reached from the block that this node belongs to.
+        Only used for nodes that are the root of a block.
+        Unique for all nodes in the same class. \\\hline
+        shift & The shift of the class that this node belongs to.
+        Only used for nodes that are a sink of a class. \\\hline
+    \end{longtable}
     \caption{Variables also used by Brandes and Köpf~\cite{brandes_fast_2001}}
     \label{table:bk-variables}
-\end{longtable}
+\end{table}
 
 \section{The actual algorithm}\label{sec:theActualAlgorithm}
-This section assumes that the reader is familiar with the node placement algorithm by Brandes and Köpf~\cite{brandes_fast_2001}.
+This section expects the reader to be familiar with the node placement algorithm by Brandes and Köpf~\cite{brandes_fast_2001}.
+We recommend section 3.2.1 of Carstens~\cite{carstens_node_2012} for a detailed explanation.
 
 A \enquote{stage} of the algorithm, interface \enquote{AlgorithmStage}, is an interval during which each step of the algorithm is performed in a similar way.
 Each time such a step is performed it returns whether the stage is already finished.
@@ -142,10 +151,11 @@ This works the following:
     \item The algorithm potentially calls the step function of other alogrithms while executing one step.
 \end{enumerate}
 
-\begin{figure}[tp]
+\TODO{outdated}
+\begin{figure}[htp]
     \centering
-    \includegraphics[width=\linewidth, trim={0 9cm 0 0}]{img/Algorithms_Animated.pdf}
-    \caption{Class diagram of the package \enquote{Algorithms.Animated}.}
+    \includegraphics[width=\linewidth,trim=0 9cm 0 0,clip]{img/algorithms_animated.pdf}
+    \caption{Class diagram of the package \enquote{algorithms.animated}.}
     \label{fig:animated}
 \end{figure}
 
@@ -158,5 +168,5 @@ The distinguish two kinds of views:
     \item The main window displays four regions for the different extremal layouts while also forwarding keyboard commands to the AnimationController.
     For this we use a JFrame from the Swing library.
     \item \enquote{EdgeView} and \enquote{NodeView} are JPanels, which means they can be drawn onto the JFrame.
-    For this they have to know about which part of the model and which layout they belong to.
+    For this they have to know about which part of the graph and which layout they belong to.
 \end{itemize}

+ 46 - 12
doc/chapter/3ui.tex

@@ -2,10 +2,32 @@ Note that since the application is still under construction, so not all screensh
 
 \section{Graphical presentation of the running algorithm}\label{sec:graphicalPresentationOfTheRunningAlgorithm}
 \TODO{under construction}
-\TODO{reference~\ref{fig:animated}}
-\begin{figure}[tp]
+\TODO{reference~\ref{fig:example}}
+\TODO{reference~\ref{fig:originalpapergraph}}
+\TODO{reference~\ref{fig:sketch}}
+
+\begin{figure}
+    \centering
+    \begin{subfigure}{\textwidth}
+        \centering
+        \includegraphics[width=\linewidth]{img/bk-example-theirs}
+        \caption{An example graph directly taken from the paper of Brandes and Köpf~\cite{brandes_fast_2001}.}
+        \label{fig:theirs}
+    \end{subfigure}\\\vspace{4mm}
+    \begin{subfigure}{\textwidth}
+        \centering
+        \includegraphics[width=0.4\linewidth]{img/bk-example-ours}
+        \caption[The same graph as~\ref{fig:theirs}, displayed by \appname.]{The same graph as~\ref{fig:theirs}, displayed by \appname.
+        The layouts are leftmost (first column), rightmost (second column), lower (first row) and upper (second row), respectively.}
+        \label{fig:ours}
+    \end{subfigure}\\\vspace{4mm}
+    \caption{Comparison of the implementation with the algorithm from the original paper.}
+    \label{fig:originalpapergraph}
+\end{figure}
+
+\begin{figure}[htp]
     \centering
-    \includegraphics[width=0.6\linewidth]{img/example.jpg}
+    \includegraphics[width=0.6\linewidth]{img/example}
     \caption[A simple graph with 5 nodes]{A simple graph with 5 nodes after the four extremal layout have been computed, but not balanced yet.
     The vertical directions are down (upper row), up (lower row) and the horizontal directions are left (left column) and right (right column).
     The background colors of the nodes display which block they belong to: For example the two blue nodes on the top right are in the same block.
@@ -13,20 +35,32 @@ Note that since the application is still under construction, so not all screensh
     A colored circle on a node indicates the class that this node belongs to and is also the color of the topmost sink in the block graph.
     The node that is currently in the focus of the algorithm (whatever this means for the current stage) is highlighted with a grey square (here the node in the rightmost column on the bottom right).
     Although edges are not drawn during the node placement phase we added them here as straight lines to improve readability.}
-    \label{fig:animated}
+    \label{fig:example}
+\end{figure}
+
+\begin{figure}[htp]
+    \centering
+    \includegraphics[width=\linewidth]{img/skizze}
+    \caption[First sketch of the planned layout]{A first sketch of the planned layout, created with Microsoft Paint.
+    The buttons are (first row, from left to right): step over, step into, step out, run, pause, debug; and (second row, from left to right): step back, step back out, run backwards.
+    The actions corresponding to the buttons will be the same as described for the keyboard input in table~\ref{table:keys}, at least for the features that are already implemented.}
+    \label{fig:sketch}
 \end{figure}
 
 \section{User interface}\label{sec:userInterface}
 Currently the only way to interact with the application is by keyboard events.
 It is planned to add both additional commands as well as some kind of graphical interface, see chapter~\ref{ch:progress}.
+The possible inputs are listed in table~\ref{table:keys}.
 
-\begin{longtable}{|l|l|}
-    \hline
-    Key & Action \\\hline\hline
-    Left arrow key & Perform one forward step of the algorithm. \\\hline
-    Right arrow key & Perform one backward step (\enquote{undo one step}) of the algorithm. \\\hline
-    P & Pause/unpause the automatic execution. Initially paused. \\\hline
-    D & Print a debug table to standard out. \\\hline
+\begin{table}[htp]
+    \begin{longtable}{|l|l|}
+        \hline
+        Key & Action \\\hline\hline
+        Left arrow key & Perform one forward step of the algorithm. \\\hline
+        Right arrow key & Perform one backward step (\enquote{undo one step}) of the algorithm. \\\hline
+        P & Pause/unpause the automatic execution. Initially paused. \\\hline
+        D & Print a debug table to standard out. \\\hline
+    \end{longtable}
     \caption{Overview of the currently available keyboard commands.}
     \label{table:keys}
-\end{longtable}
+\end{table}

+ 12 - 0
doc/doc.bib

@@ -49,4 +49,16 @@
 	publisher = {Eclipse Foundation},
 	month = jun,
 	year = {2018}
+}
+
+@mastersthesis{carstens_node_2012,
+	address = {Kiel},
+	title = {Node and {Label} {Placement} in a {Layered} {Layout} {Algorithm}},
+	abstract = {In graphical modelling, the arrangement of diagram elements can be a tiresome and mechanic work. To free users from this, layout algorithms arrange the diagram elements automatically. Different modelling domains require different layouts. A layout approach suitable for data flow diagrams is the layered layout approach. This approach is structured in several phases, of which one is called node placement. Present implementations are known to produce many edge bends. One task of this thesis is to employ a node placement algorithm which yields significantly less edge bends. Another well known problem in layout algorithms is label placement. Present approaches rely on a post-processing by placing labels after the diagram has been laid out. The approaches presented in this thesis integrate label placement into the layout, resulting in more freedom and clean placements of labels. Evaluation shows that both tasks can be fulfilled, but have to accept a trade-off which is a generally larger drawing of the respective  diagrams.},
+	language = {english},
+	school = {Christian-Albrechts-Universität zu Kiel},
+	author = {Carstens, John Julian},
+	month = sep,
+	year = {2012},
+	file = {Carstens - Node and Label Placement in a Layered Layout Algor.pdf:C\:\\Users\\Eren\\Zotero\\storage\\AE9E539E\\Carstens - Node and Label Placement in a Layered Layout Algor.pdf:application/pdf}
 }

+ 4 - 4
doc/doc.tex

@@ -142,7 +142,7 @@ frame=tb}
 % \usepackage{scrhack} % Vermeidung einer Warnung
 
 %\newcommand{\svgfigure}[3]{
-%\begin{figure}[tp]
+%\begin{figure}[htp]
 %    \centering
 %    \includesvg{#1}
 %    \caption{#2}\label{#3}
@@ -150,7 +150,7 @@ frame=tb}
 %}
 
 \newcommand{\svgfigurewidth}[5]{
-\begin{figure}[tp]
+\begin{figure}[htp]
     \centering
     \fontsize{8}{10}\selectfont
     \includesvg[width = #5]{#1}
@@ -159,7 +159,7 @@ frame=tb}
 }
 
 \newcommand{\svgfigurefullwidth}[4]{
-\begin{figure}[tp]
+\begin{figure}[htp]
     \centering
     \includesvg[width = \textwidth]{#1}
     \caption[#2]{#3}\label{#4}
@@ -167,7 +167,7 @@ frame=tb}
 }
 
 \newcommand{\graphicsfigure}[3]{
-\begin{figure}[tp]
+\begin{figure}[htp]
     \centering
     \includegraphics[width=\linewidth]{#1}
     \caption{#2}\label{#3}

+ 0 - 0
doc/img/Algorithms_Animated.pdf → doc/img/algorithms_animated.pdf


BIN
doc/img/bk-example-ours.jpg


BIN
doc/img/bk-example-theirs.png


+ 0 - 26
doc/img/graph.json

@@ -1,26 +0,0 @@
-{
-   "layers":[
-      [
-         {
-            "name":"n2",
-            "width":10,
-            "height":10
-         },
-         {
-            "name":"n1",
-            "width":10,
-            "height":10,
-            "layers":[
-               [
-                  {
-                     "name":"n2",
-                     "width":10,
-                     "height":10
-                  }
-               ]
-            ]
-         }
-      ]
-   ],
-   "name":"n0"
-}

+ 0 - 0
doc/img/IO.pdf → doc/img/io.pdf


+ 0 - 0
doc/img/Model.pdf → doc/img/model.pdf


BIN
doc/img/skizze.png


+ 0 - 0
doc/img/View.pdf → doc/img/view.pdf


+ 0 - 0
doc/src/.keep


+ 36 - 0
doc/src/graph.json

@@ -0,0 +1,36 @@
+{
+  "layers": [
+    [
+      {
+        "width": 10,
+        "height": 10
+      },
+      {
+        "name": "n1",
+        "width": 10,
+        "height": 10,
+        "layers": [
+          [
+            {
+              "name": "n2",
+              "width": 10,
+              "height": 10
+            }
+          ]
+        ]
+      }
+    ],
+    [
+      {
+        "name": "n2"
+      }
+    ]
+  ],
+  "edges": [
+    {
+      "source": "n1",
+      "target": "n2"
+    }
+  ],
+  "name": "n0"
+}

BIN
doc/vpp/components.vpp


+ 37 - 1
doc/zotero_backup/NodePlacementAnimation/NodePlacementAnimation.rdf

@@ -6,7 +6,8 @@
  xmlns:bib="http://purl.org/net/biblio#"
  xmlns:foaf="http://xmlns.com/foaf/0.1/"
  xmlns:link="http://purl.org/rss/1.0/modules/link/"
- xmlns:prism="http://prismstandard.org/namespaces/1.2/basic/">
+ xmlns:prism="http://prismstandard.org/namespaces/1.2/basic/"
+ xmlns:vcard="http://nwalsh.com/rdf/vCard#">
     <bib:BookSection rdf:about="urn:isbn:978-3-540-43309-5%20978-3-540-45848-7">
         <z:itemType>bookSection</z:itemType>
         <dcterms:isPartOf>
@@ -194,4 +195,39 @@
         <dc:title>ELK: Eclipse Layout Kernel - Automatic layout for Java applications</dc:title>
         <z:shortTitle>ELK</z:shortTitle>
     </bib:Data>
+    <bib:Thesis rdf:about="#item_1066">
+        <z:itemType>thesis</z:itemType>
+        <dc:publisher>
+            <foaf:Organization>
+                <vcard:adr>
+                    <vcard:Address>
+                       <vcard:locality>Kiel</vcard:locality>
+                    </vcard:Address>
+                </vcard:adr>
+                <foaf:name>Christian-Albrechts-Universität zu Kiel</foaf:name>
+            </foaf:Organization>
+        </dc:publisher>
+        <bib:authors>
+            <rdf:Seq>
+                <rdf:li>
+                    <foaf:Person>
+                        <foaf:surname>Carstens</foaf:surname>
+                        <foaf:givenname>John Julian</foaf:givenname>
+                    </foaf:Person>
+                </rdf:li>
+            </rdf:Seq>
+        </bib:authors>
+        <link:link rdf:resource="#item_1065"/>
+        <dc:date>September 2012</dc:date>
+        <z:type>master</z:type>
+        <z:language>english</z:language>
+        <dcterms:abstract>In graphical modelling, the arrangement of diagram elements can be a tiresome and mechanic work. To free users from this, layout algorithms arrange the diagram elements automatically. Different modelling domains require different layouts. A layout approach suitable for data flow diagrams is the layered layout approach. This approach is structured in several phases, of which one is called node placement. Present implementations are known to produce many edge bends. One task of this thesis is to employ a node placement algorithm which yields significantly less edge bends. Another well known problem in layout algorithms is label placement. Present approaches rely on a post-processing by placing labels after the diagram has been laid out. The approaches presented in this thesis integrate label placement into the layout, resulting in more freedom and clean placements of labels. Evaluation shows that both tasks can be fulfilled, but have to accept a trade-off which is a generally larger drawing of the respective  diagrams.</dcterms:abstract>
+        <dc:title>Node and Label Placement in a Layered Layout Algorithm</dc:title>
+    </bib:Thesis>
+    <z:Attachment rdf:about="#item_1065">
+        <z:itemType>attachment</z:itemType>
+        <rdf:resource rdf:resource="files/1065/Carstens - Node and Label Placement in a Layered Layout Algor.pdf"/>
+        <dc:title>Carstens - Node and Label Placement in a Layered Layout Algor.pdf</dc:title>
+        <link:type>application/pdf</link:type>
+    </z:Attachment>
 </rdf:RDF>

+ 0 - 0
material/jjc-mt.pdf → doc/zotero_backup/NodePlacementAnimation/files/1065/Carstens - Node and Label Placement in a Layered Layout Algor.pdf


+ 0 - 31
src/Algorithms/RandomColorGenerator.java

@@ -1,31 +0,0 @@
-package Algorithms;
-
-import java.awt.Color;
-import java.util.Random;
-
-/**
- * generates random colors
- * @author kolja
- *
- */
-public class RandomColorGenerator {
-
-	private Random rand;
-	
-	public RandomColorGenerator()
-	{
-		rand = new Random();
-	}
-	
-	/**
-	 * generate a color with random RGB values
-	 * @return the color
-	 */
-	public Color generateColor()
-	{
-		float r = rand.nextFloat();
-		float g = rand.nextFloat();
-		float b = rand.nextFloat();
-		return new Color( r, g, b );
-	}
-}

+ 1 - 1
src/Algorithms/Animated/Action.java → src/animation/Action.java

@@ -1,4 +1,4 @@
-package Algorithms.Animated;
+package animation;
 
 /**
  * An action some kind of command that can be send to the {@link AnimatedAlgorithm} from the {@link AnimationController}.

+ 2 - 2
src/Algorithms/Animated/AlgorithmStage.java → src/animation/AlgorithmStage.java

@@ -1,6 +1,6 @@
-package Algorithms.Animated;
+package animation;
 
-import Algorithms.Animated.BK.BlockCalc;
+import bk.BlockCalc;
 
 /**
  * Represents a specific stage of the algorithm.

+ 2 - 4
src/Algorithms/Animated/AnimatedAlgorithm.java → src/animation/AnimatedAlgorithm.java

@@ -1,6 +1,6 @@
-package Algorithms.Animated;
+package animation;
 
-import Model.LayeredGraphNode;
+import graph.LayeredGraphNode;
 
 public abstract class AnimatedAlgorithm extends Thread implements AlgorithmStage {
 
@@ -11,8 +11,6 @@ public abstract class AnimatedAlgorithm extends Thread implements AlgorithmStage
 	{
 		this.ac = controller;
 		this.graph = graph;
-		if( controller != null )
-			start();
 	}
 	
 	@Override

+ 1 - 1
src/Algorithms/Animated/AnimationController.java → src/animation/AnimationController.java

@@ -1,4 +1,4 @@
-package Algorithms.Animated;
+package animation;
 
 public class AnimationController {
 	

+ 1 - 1
src/Algorithms/Animated/BackwardAction.java → src/animation/BackwardAction.java

@@ -1,4 +1,4 @@
-package Algorithms.Animated;
+package animation;
 
 /**
  * An action that reverts another Action.

+ 6 - 5
src/Algorithms/Animated/BK/BKNodePlacement.java → src/bk/BKNodePlacement.java

@@ -1,9 +1,9 @@
-package Algorithms.Animated.BK;
+package bk;
 
-import Algorithms.Animated.AlgorithmStage;
-import Algorithms.Animated.AnimatedAlgorithm;
-import Algorithms.Animated.AnimationController;
-import Model.LayeredGraphNode;
+import animation.AlgorithmStage;
+import animation.AnimatedAlgorithm;
+import animation.AnimationController;
+import graph.LayeredGraphNode;
 
 /**
  * The main stage of the BK node placement algorithm.
@@ -82,6 +82,7 @@ public class BKNodePlacement extends AnimatedAlgorithm {
 		case LAYOUT1:
 			if( layouts[ 0 ].backwardStep() == StageStatus.FINISHED )
 				state = State.CONFLICTS;
+			break;
 		case LAYOUT2:
 			if( layouts[ 1 ].backwardStep() == AlgorithmStage.StageStatus.FINISHED )
 				state = State.LAYOUT1;

+ 6 - 6
src/Algorithms/Animated/BK/BlockCalc.java → src/bk/BlockCalc.java

@@ -1,14 +1,14 @@
-package Algorithms.Animated.BK;
+package bk;
 
 import java.awt.Color;
 import java.util.ArrayList;
 import java.util.Collections;
 
-import Algorithms.Animated.AlgorithmStage;
-import Algorithms.Animated.BackwardAction;
-import Algorithms.Animated.BK.ExtremalLayoutCalc.LayoutType;
-import Model.LayeredGraphEdge;
-import Model.LayeredGraphNode;
+import animation.AlgorithmStage;
+import animation.BackwardAction;
+import bk.ExtremalLayoutCalc.LayoutType;
+import graph.LayeredGraphEdge;
+import graph.LayeredGraphNode;
 
 /**
  * The stage of the BK node placement algorithm where the blocks are computed.

+ 4 - 6
src/Algorithms/Animated/BK/Combine.java → src/bk/Combine.java

@@ -1,12 +1,10 @@
-package Algorithms.Animated.BK;
+package bk;
 
 import java.awt.Color;
-import java.awt.event.ComponentEvent;
-import java.awt.event.ComponentListener;
 
-import Algorithms.Animated.AlgorithmStage;
-import Model.LayeredGraphNode;
-import View.MainView;
+import animation.AlgorithmStage;
+import graph.LayeredGraphNode;
+import view.MainView;
 
 /**
  * The stage of the combination of the four extremal layouts.

+ 9 - 5
src/Algorithms/Animated/BK/Compaction.java → src/bk/Compaction.java

@@ -1,11 +1,11 @@
-package Algorithms.Animated.BK;
+package bk;
 
 import java.util.ArrayList;
 
-import Algorithms.Animated.AlgorithmStage;
-import Algorithms.Animated.BackwardAction;
-import Algorithms.Animated.BK.ExtremalLayoutCalc.LayoutType;
-import Model.LayeredGraphNode;
+import animation.AlgorithmStage;
+import animation.BackwardAction;
+import bk.ExtremalLayoutCalc.LayoutType;
+import graph.LayeredGraphNode;
 
 /**
  * The stage of compacting the layout.
@@ -45,6 +45,10 @@ public class Compaction implements AlgorithmStage{
 		actions = new ArrayList<>();
 	}
 	
+	/**
+	 * calculates the minimum spacing needed between two left borders of nodes.
+	 * @return the spacing
+	 */
 	public double calcSpacing()
 	{
 		double max = 0;

+ 5 - 5
src/Algorithms/Animated/BK/ConflictDetection.java → src/bk/ConflictDetection.java

@@ -1,11 +1,11 @@
-package Algorithms.Animated.BK;
+package bk;
 
 import java.util.ArrayList;
 
-import Algorithms.Animated.AlgorithmStage;
-import Algorithms.Animated.BackwardAction;
-import Model.LayeredGraphEdge;
-import Model.LayeredGraphNode;
+import animation.AlgorithmStage;
+import animation.BackwardAction;
+import graph.LayeredGraphEdge;
+import graph.LayeredGraphNode;
 
 public class ConflictDetection implements AlgorithmStage {
 

+ 3 - 3
src/Algorithms/Animated/BK/ExtremalLayoutCalc.java → src/bk/ExtremalLayoutCalc.java

@@ -1,7 +1,7 @@
-package Algorithms.Animated.BK;
+package bk;
 
-import Algorithms.Animated.AlgorithmStage;
-import Model.LayeredGraphNode;
+import animation.AlgorithmStage;
+import graph.LayeredGraphNode;
 
 /**
  * The stage where the for extremal layouts are computed.

+ 5 - 9
src/Algorithms/InitializeNodePositions.java → src/graph/InitializeNodePositions.java

@@ -1,9 +1,9 @@
-package Algorithms;
+package graph;
 
+import java.awt.Color;
 import java.util.ArrayList;
 
-import Algorithms.Animated.BK.ExtremalLayoutCalc.LayoutType;
-import Model.LayeredGraphNode;
+import bk.ExtremalLayoutCalc.LayoutType;
 
 
 /**
@@ -18,13 +18,9 @@ public class InitializeNodePositions {
      * @param graph the graph where the node positions are to be set.
      */
     public static void placeNodes( LayeredGraphNode graph ) {
-        
-    	RandomColorGenerator cGen = new RandomColorGenerator();
-        for( LayeredGraphNode n : graph.getContainedNodes() )
+    	for( LayeredGraphNode n : graph.getContainedNodes() )
         {
-            n.setWidth( 40, null );
-            n.setHeight( 40, null );
-            n.setColor( cGen.generateColor(), null );
+            n.setColor( new Color((int)(Math.random() * 0x1000000)), null );
             placeNodes( n );
         }
         int curY = 0;

+ 3 - 3
src/Model/LayeredEdge.java → src/graph/LayeredEdge.java

@@ -1,15 +1,15 @@
-package Model;
+package graph;
 
 import java.awt.Point;
 import java.util.ArrayList;
 
 import org.eclipse.elk.graph.ElkEdge;
 
-import Algorithms.Animated.BK.ExtremalLayoutCalc.LayoutType;
+import bk.ExtremalLayoutCalc.LayoutType;
 
 /**
  * Die Implementation einer Kante aus einem Layered Graphen.
- * Implementiert {@link LayeredGraphEdge.}
+ * Implementiert {@link LayeredGraphEdge}.
  * 
  * @author kolja
  *

+ 2 - 2
src/Model/LayeredGraphEdge.java → src/graph/LayeredGraphEdge.java

@@ -1,11 +1,11 @@
- package Model;
+ package graph;
 
 import java.awt.Point;
 import java.util.ArrayList;
 
 import org.eclipse.elk.graph.ElkEdge;
 
-import Algorithms.Animated.BK.ExtremalLayoutCalc.LayoutType;
+import bk.ExtremalLayoutCalc.LayoutType;
 
 /**
  * Ein Interface, welches die Methoden einer Kante aus einem gelayerten Graphen beschreibt

+ 4 - 4
src/Model/LayeredGraphNode.java → src/graph/LayeredGraphNode.java

@@ -1,4 +1,4 @@
-package Model;
+package graph;
 
 import java.awt.Color;
 import java.util.ArrayList;
@@ -6,7 +6,7 @@ import java.util.ArrayList;
 import org.eclipse.elk.graph.ElkEdge;
 import org.eclipse.elk.graph.ElkNode;
 
-import Algorithms.Animated.BK.ExtremalLayoutCalc.LayoutType;
+import bk.ExtremalLayoutCalc.LayoutType;
 
 /**
  * Ein Interface, welches die Methoden eines Knotens aus einem gelayerten Graphen beschreibt (Ein Knoten kann dabei auch einen weiteren Graphen beinhalten)
@@ -209,8 +209,8 @@ public interface LayeredGraphNode {
     /**
      * F�gt eine neue Kante zum Subgraph hinzu
      * @param original Die Originale Elk Kante
-     * @param sources Der Startknoten
-     * @param targets Der Endknoten
+     * @param source Der Startknoten
+     * @param target Der Endknoten
      * @return Die neue Kante
      */
     LayeredGraphEdge createSimpleEdge( ElkEdge original, LayeredGraphNode source, LayeredGraphNode target );

+ 4 - 4
src/Model/LayeredNode.java → src/graph/LayeredNode.java

@@ -1,4 +1,4 @@
-package Model;
+package graph;
 
 import java.awt.Color;
 import java.util.ArrayList;
@@ -8,12 +8,12 @@ import javax.swing.SwingUtilities;
 import org.eclipse.elk.graph.ElkEdge;
 import org.eclipse.elk.graph.ElkNode;
 
-import Algorithms.Animated.BK.ExtremalLayoutCalc.LayoutType;
-import View.MainView;
+import bk.ExtremalLayoutCalc.LayoutType;
+import view.MainView;
 
 /**
  * Die Implementation eines Knotens in einem Layered Graph.
- * Implementiert {@link LayeredGraphNode.}
+ * Implementiert {@link LayeredGraphNode}.
  * 
  * @author kolja
  *

+ 1 - 4
src/Algorithms/RandomGraphGenerator.java → src/graph/RandomGraphGenerator.java

@@ -1,7 +1,4 @@
-package Algorithms;
-
-import Model.LayeredGraphNode;
-import Model.LayeredNode;
+package graph;
 
 /**
  * creates random {@link LayeredGraphNode}s for testing purposes

+ 8 - 4
src/IO/Reader.java → src/graph/io/Reader.java

@@ -1,4 +1,4 @@
-package IO;
+package graph.io;
 
 import java.io.BufferedReader;
 import java.io.FileReader;
@@ -9,9 +9,9 @@ import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
-import Model.LayeredGraphEdge;
-import Model.LayeredGraphNode;
-import Model.LayeredNode;
+import graph.LayeredGraphEdge;
+import graph.LayeredGraphNode;
+import graph.LayeredNode;
 
 /**
  * reads a {@link LayeredGraphNode} from a JSON file
@@ -69,8 +69,12 @@ public class Reader {
         }
         if( node.has( "width" ) )
             newNode.setWidth( node.getInt( "width" ), null );
+        else
+            newNode.setWidth( 40, null );
         if( node.has( "height" ) )
             newNode.setHeight( node.getInt( "height" ), null );
+        else
+            newNode.setHeight( 40, null );
 		if( node.has( "layers" ) )
 		{
 			JSONArray layers = node.getJSONArray( "layers" );

+ 3 - 3
src/IO/Writer.java → src/graph/io/Writer.java

@@ -1,4 +1,4 @@
-package IO;
+package graph.io;
 
 import java.io.BufferedWriter;
 import java.io.FileWriter;
@@ -9,8 +9,8 @@ import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
-import Model.LayeredGraphEdge;
-import Model.LayeredGraphNode;
+import graph.LayeredGraphEdge;
+import graph.LayeredGraphNode;
 
 /**
  * Writes a {@link LayeredGraphNode} to a JSON file.

+ 7 - 4
src/Algorithms/SweepCrossingMinimizer.java → src/lib/SweepCrossingMinimizer.java

@@ -1,9 +1,9 @@
-package Algorithms;
+package lib;
 
 import java.util.ArrayList;
 
-import Model.LayeredGraphEdge;
-import Model.LayeredGraphNode;
+import graph.LayeredGraphEdge;
+import graph.LayeredGraphNode;
 
 
 /**
@@ -14,7 +14,10 @@ import Model.LayeredGraphNode;
  */
 public class SweepCrossingMinimizer {
 
-    
+    /**
+     * minimizes crossings by sweeping multiple times and locally reducing crossings between pairs of layers
+     * @param graph the graph where the crossings should be minimized.
+     */
     public void minimizeCrossings( LayeredGraphNode graph ) {
         ArrayList< ArrayList< LayeredGraphNode > > layers = graph.getContainedLayers();
         System.out.println( "Number of Detected Crossings before minimization: " + numberOfCrossings( layers ) );

+ 11 - 6
src/Main.java → src/main/Main.java

@@ -1,9 +1,10 @@
-import Algorithms.InitializeNodePositions;
-import Algorithms.RandomGraphGenerator;
-import Algorithms.SweepCrossingMinimizer;
-import IO.Reader;
-import Model.LayeredGraphNode;
-import View.MainView;
+package main;
+import graph.InitializeNodePositions;
+import graph.LayeredGraphNode;
+import graph.RandomGraphGenerator;
+import graph.io.Reader;
+import lib.SweepCrossingMinimizer;
+import view.MainView;
 
 /**
  * The main executable class. Starts the application.
@@ -12,6 +13,10 @@ import View.MainView;
  */
 public class Main {
 
+    /**
+     * Will be run when the application is started.
+     * @param args the command line arguments, currently not in use
+     */
 	public static void main(String[] args) {
 		Reader r = new Reader( "test3.json" );
 		LayeredGraphNode graph = r.readInputGraph();

+ 3 - 3
src/View/EdgeView.java → src/view/EdgeView.java

@@ -1,4 +1,4 @@
-package View;
+package view;
 
 import java.awt.BasicStroke;
 import java.awt.Color;
@@ -10,8 +10,8 @@ import java.util.ArrayList;
 
 import javax.swing.JPanel;
 
-import Algorithms.Animated.BK.ExtremalLayoutCalc.LayoutType;
-import Model.LayeredGraphEdge;
+import bk.ExtremalLayoutCalc.LayoutType;
+import graph.LayeredGraphEdge;
 
 /**
  * A drawable representation of an edge.

+ 16 - 13
src/View/MainView.java → src/view/MainView.java

@@ -1,4 +1,4 @@
-package View;
+package view;
 
 import java.awt.Component;
 import java.awt.GridLayout;
@@ -12,24 +12,27 @@ import javax.swing.JFrame;
 import javax.swing.JLayeredPane;
 import javax.swing.JPanel;
 
-import Algorithms.Animated.Action;
-import Algorithms.Animated.AnimationController;
-import Algorithms.Animated.BK.BKNodePlacement;
-import Algorithms.Animated.BK.ExtremalLayoutCalc.LayoutType;
-import IO.Writer;
-import Model.LayeredGraphEdge;
-import Model.LayeredGraphNode;
+import animation.Action;
+import animation.AnimationController;
+import bk.BKNodePlacement;
+import bk.ExtremalLayoutCalc.LayoutType;
+import graph.LayeredGraphEdge;
+import graph.LayeredGraphNode;
+import graph.io.Writer;
 
 /**
  * The main window of the application.
+ * There should only be one instance of this class at the same time.
+ * The JFrame of that single instance can be accessed by the static field {code MainView.frame}.
  * @author kolja
  *
  */
-public class MainView {
+public class MainView {    
     /**
      * The 'frame' of the main window.
+     * The reason why there can only be one instance of this class.
      */
-	public static JFrame frame;
+    public static JFrame frame;
 	AnimationController controller;
 	
 	private String strToLen( String s, int l )
@@ -50,8 +53,8 @@ public class MainView {
 	public MainView( LayeredGraphNode graph )
 	{
 		controller = new AnimationController();
-		controller.setTimeBetween( 1 );
-		frame = new JFrame();
+		controller.setTimeBetween( 10 );
+		frame = new JFrame(); // this may write to a static field because there should be only one instance of this class.
         frame.setSize( Math.min( (int)graph.getWidth( LayoutType.TOP_BOTTOM_LEFT ) * 2 + 200, 1700 ), Math.min( (int)graph.getHeight( LayoutType.TOP_BOTTOM_LEFT ) * 2 + 200, 900 ) );
 		frame.setLocation( 100, 100 );
 		frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
@@ -171,7 +174,7 @@ public class MainView {
 	    		frame.repaint();
 	        }
 		});
-		new BKNodePlacement( controller, graph );
+		new BKNodePlacement( controller, graph ).start();
 	}
 	
 	private NodeView createNodeView( LayeredGraphNode gNode, LayoutType lt )

+ 3 - 3
src/View/NodeView.java → src/view/NodeView.java

@@ -1,4 +1,4 @@
-package View;
+package view;
 
 import java.awt.BasicStroke;
 import java.awt.Color;
@@ -11,8 +11,8 @@ import java.awt.Point;
 import javax.swing.*;
 import javax.swing.border.Border;
 
-import Algorithms.Animated.BK.ExtremalLayoutCalc.LayoutType;
-import Model.LayeredGraphNode;
+import bk.ExtremalLayoutCalc.LayoutType;
+import graph.LayeredGraphNode;
 
 /**
  * A drawable representation of a node.

+ 1 - 1
src/View/RenderHelper.java → src/view/RenderHelper.java

@@ -1,4 +1,4 @@
-package View;
+package view;
 
 import java.awt.Point;
 import java.awt.Polygon;

+ 36 - 1
test3.json

@@ -1 +1,36 @@
-{"layers": [[{"name":"n2","width":10,"height":10},{"name":"n1","width":10,"height":10,"layers": [[{"name":"n2","width":10,"height":10}]]}]],"name":"n0"}
+{
+  "layers": [
+    [
+      {
+        "width": 10,
+        "height": 10
+      },
+      {
+        "name": "n1",
+        "width": 10,
+        "height": 10,
+        "layers": [
+          [
+            {
+              "name": "n2",
+              "width": 10,
+              "height": 10
+            }
+          ]
+        ]
+      }
+    ],
+    [
+      {
+        "name": "n2"
+      }
+    ]
+  ],
+  "edges": [
+    {
+      "source": "n1",
+      "target": "n2"
+    }
+  ],
+  "name": "n0"
+}