Quellcode durchsuchen

Kommentare in der oberen Hälfe des View Packets

Kolja Strohm vor 5 Jahren
Ursprung
Commit
0cd080394d
5 geänderte Dateien mit 65 neuen und 30 gelöschten Zeilen
  1. 16 0
      src/view/AnimatedView.java
  2. 8 8
      src/view/LegendView.java
  3. 22 14
      src/view/MainView.java
  4. 12 6
      src/view/NodeView.java
  5. 7 2
      src/view/OptionsDialog.java

+ 16 - 0
src/view/AnimatedView.java

@@ -8,8 +8,24 @@ package view;
  */
 public interface AnimatedView {
 
+	/**
+	 * 
+	 * @return Die X Koordinate, die das Model der View hat
+	 */
     public int getVirtualX();
+    /**
+     * 
+     * @return Die Y Koordinate die das Model der View hat
+     */
     public int getVirtualY();
+    /**
+     * 
+     * @return Die Breite des Models der View
+     */
     public int getVirtualWidth();
+    /**
+     * 
+     * @return Die Höhe des Models der View
+     */
     public int getVirtualHeight();
 }

+ 8 - 8
src/view/LegendView.java

@@ -21,9 +21,9 @@ public class LegendView extends JPanel {
 
 	@Override
 	public void paintComponent( Graphics g ) {
-	
+	 // Zeichnet die Legende
 		g.setFont( RenderHelper.font );
-		FontMetrics fm = g.getFontMetrics();
+		FontMetrics fm = g.getFontMetrics(); // Font Metrics berechnen
 		setPreferredSize( new Dimension( getPreferredSize().width, fm.getHeight() + PADDING * 2 ) );
 		
 		int height = fm.getHeight() + PADDING * 2;
@@ -31,21 +31,21 @@ public class LegendView extends JPanel {
 		int x = PADDING;
 		g.drawString( "Legend:", x, fm.getMaxAscent() + PADDING );
 		x += fm.stringWidth( "Legend:" ) + PADDING;
-		
+		// Wurzeln von Blöcken
 		g.setColor( Color.LIGHT_GRAY );
 		g.fillOval( x, PADDING, height - PADDING*2, height - PADDING*2 );
 		x += height;
 		g.setColor( Color.BLACK );
 		g.drawString( "block root", x, fm.getMaxAscent() + PADDING );
 		x += fm.stringWidth( "block root" ) + PADDING * 4;
-        
+        // Dummy Knoten
         g.setColor( Color.LIGHT_GRAY );
         g.fillOval( x, PADDING, height / 3, height - PADDING*2 );
         x += height / 3 + PADDING;
         g.setColor( Color.BLACK );
         g.drawString( "dummy node", x, fm.getMaxAscent() + PADDING );
         x += fm.stringWidth( "dummy node" ) + PADDING * 4;
-		
+		// Knoten mit Subgraph
 		g.setColor( Color.LIGHT_GRAY );
         ((Graphics2D)g).setStroke(new BasicStroke(2));
 		g.drawRect( x, PADDING, height - PADDING * 2, height - PADDING * 2 );
@@ -53,14 +53,14 @@ public class LegendView extends JPanel {
 		g.setColor( Color.BLACK );
 		g.drawString( "node with subgraph", x, fm.getMaxAscent() + PADDING );
 		x += fm.stringWidth( "node with subgraph" ) + PADDING * 4;
-		
+		// Kanten, welche als conflicted markiert wurden
 		g.setColor( Color.RED );
 		g.drawLine( x, height / 2, x + height - PADDING * 2, height / 2 );
 		x += height;
 		g.setColor( Color.BLACK );
 		g.drawString( "conflicted edge", x, fm.getMaxAscent() + PADDING );
 		x += fm.stringWidth( "conflicted edge" ) + PADDING * 4;
-		
+		// Farbe der Klassen
 		g.setColor( Color.BLUE );
 		g.fillRect( x, 0, height, height );
 		g.setColor( Color.LIGHT_GRAY );
@@ -69,7 +69,7 @@ public class LegendView extends JPanel {
 		g.setColor( Color.BLACK );
 		g.drawString( "class color", x, fm.getMaxAscent() + PADDING );
 		x += fm.stringWidth( "class color" ) + PADDING * 4;
-		
+		// Farben der Blöcke
 		g.setColor( Color.LIGHT_GRAY );
 		g.fillRect( x, 0, height, height );
 		g.setColor( Color.BLUE );

+ 22 - 14
src/view/MainView.java

@@ -68,8 +68,9 @@ public class MainView {
      * Random Graph Generator should olny exist once for all windows (so the values will be stored)
      */
     private static final RandomGraphDialog randomDialog = new RandomGraphDialog();
-    private JFrame frame;
-    private ProcessController controller;
+    private JFrame frame; // Zeigt alles an
+    private ProcessController controller; // Kontrolliert den Prozessor
+    // Menu Buttons, Labels and TextFields
     private JButton stepForward;
     private JButton stepForwardInto;
     private JButton stepForwardOut;
@@ -86,12 +87,12 @@ public class MainView {
     private JButton randomGraph;
     private JLabel delayText;
     private JTextField delay;
-    private JTree pseudoTree;
-    private LayeredGraphNode graph;
-    private OptionsDialog optionsDialog;
+    private JTree pseudoTree; // Die Pseudocode Ansicht
+    private LayeredGraphNode graph; // Die interne Graph Repräsentation
+    private OptionsDialog optionsDialog; // Der Dialog mit Optionen
 
     private String debugInfo()
-    {
+    { // Gesammter Debug Text für alle Layouts
         String info = "Debug Information Table: \n";
         info += "_______________________________________________________________________________________________________________________________________________________________________________________________________________________\n";
         info += "|" + TextLayoutHelper.strToLen( "Top -> Bottom :> Left", 51 ) + "| |" + TextLayoutHelper.strToLen( "Top -> Bottom :> Right", 51 ) + "| |" + TextLayoutHelper.strToLen( "Bottom -> Top :> Left", 51 ) + "| |" + TextLayoutHelper.strToLen( "Bottom -> Top :> Right", 51 ) + "|\n";
@@ -133,7 +134,7 @@ public class MainView {
     }
 
     private void showDebugInfo()
-    {
+    { // Erzeuge neues Fenster mit Debug Text
         JFrame debugFrame = new JFrame();
         JTextArea info = new JTextArea();
         info.setEditable( false );
@@ -403,6 +404,7 @@ public class MainView {
             public void mousePressed(MouseEvent e) {
                 TreePath selPath = pseudoTree.getPathForLocation(e.getX(), e.getY());
                 if( selPath != null && e.getClickCount() == 3 ) {
+                	// Setzt einen Breakpoint bei dreifachklick
                     ((PseudoCodeNode)selPath.getLastPathComponent()).setBreakPoint( !((PseudoCodeNode)selPath.getLastPathComponent()).hasBreakPoint() );
                     if( !pseudoTree.isExpanded( selPath ) )
                     {
@@ -417,6 +419,7 @@ public class MainView {
                     pseudoTree.repaint();
                     frame.repaint();
                 }
+                // Erzeuge das Rechtsklick Menü für Collaps und Expand
                 if( e.getButton() == MouseEvent.BUTTON3 )
                 {
                     JPopupMenu menu = new JPopupMenu();
@@ -549,6 +552,7 @@ public class MainView {
         pl.setLayout( grout );
         pl.setLocation( 0, 0 );
         pl.setSize( frame.getSize() );
+        // Erzeugt die Graph Views für die verschiedenen Layouts
         NodeView topLeft = createNodeView( graph, LayoutType.LEFTMOST_UPPER );
         NodeView topRight = createNodeView( graph, LayoutType.RIGHTMOST_UPPER );
         NodeView bottomLeft = createNodeView( graph, LayoutType.LEFTMOST_LOWER );
@@ -615,16 +619,17 @@ public class MainView {
         frame.addComponentListener(new ComponentAdapter()
         {
             public void componentResized(ComponentEvent evt) {
+            	// Aktualisiere die Höhe des Menüs
                 menue.setSize( menue.getWidth(), layne.getHeight() );
                 spane2.setSize( menue.getWidth() - 20, menue.getHeight() - 120 );
                 if( graph.getColor( null ) == null )
-                {
+                { // Falls das Kombinierte Layout nicht gezeichnet werden soll
                     grout.setHgap( 10 );
                     grout.setVgap( 10 );
                     combined.setVisible( false );
                 }
                 else
-                {
+                {// Falsl das Kombinierte Layout gezeichnet werden soll
                     grout.setHgap( layne.getWidth() / 3 );
                     grout.setVgap( layne.getHeight() / 3 );
                     combined.setVisible( true );
@@ -637,14 +642,15 @@ public class MainView {
                 layne.remove( pl );
                 layne.add( pl, 1 );
                 if( optionsDialog != null && optionsDialog.getLayerDisplayOption() == 1 && old != algorithm.getAlgorithmState() )
-                {
+                { // Es soll immer nur das aktuelle LAyout gezeichet werden und der Algorithmus hat ein neues Layout erreicht
+                	// Entferne die Layouts
                     pl.remove( topLeft );
                     pl.remove( topRight );
                     pl.remove( bottomLeft );
                     pl.remove( bottomRight );
                     pl.remove( combined );
                     switch( algorithm.getAlgorithmState() )
-                    {
+                    { // füge das richtige Layout hinzu
                     case CONFLICT_DETECTION:
                         pl.add( topLeft );
                         break;
@@ -687,6 +693,7 @@ public class MainView {
 
             @Override
             public void actionPerformed(ActionEvent e) {
+            	// Es wurden Optionen geändert
                 controller.setStepOption( optionsDialog.getRunStepsOption() );
                 controller.setAutoCollapseOption( optionsDialog.getAutoCollapseOption() );
                 RenderHelper.font = new Font( "Monospaced", Font.PLAIN, optionsDialog.getFontSize() );
@@ -700,7 +707,7 @@ public class MainView {
                 pl.remove( combined );
                 layne.remove( combined );
                 if( optionsDialog.getLayerDisplayOption() == 0)
-                {
+                { // Es sollen alle Layouts angezeigt werden
                 	pl.setLayout( grout );
                     pl.add( topLeft );
                     pl.add( topRight );
@@ -709,10 +716,10 @@ public class MainView {
                 	layne.add( combined, 0 );
                 }
                 else
-                {
+                { // Es soll nur das aktuelle Layout gezeichnet werden
                     pl.setLayout( new BorderLayout() );
                     switch( algorithm.getAlgorithmState() )
-	                {
+	                { // füge das richtige layout hinzu
 	                case CONFLICT_DETECTION:
 	                    pl.add( topLeft );
 	                    break;
@@ -747,6 +754,7 @@ public class MainView {
         processor.start(); // start running the algorithm
     }
 
+    // Erzeugt eine View für einen Graph
     private NodeView createNodeView( LayeredGraphNode gNode, LayoutType lt )
     {
         NodeView graphView = new NodeView( gNode, lt, frame );

+ 12 - 6
src/view/NodeView.java

@@ -195,6 +195,7 @@ public class NodeView extends JPanel implements AnimatedView, MouseListener {
 
     @Override
     public void doLayout() {
+    	// Aktualisiere die Größen der Knindknoten
         double minX = Double.POSITIVE_INFINITY;
         for( Component c : getComponents() )
         {
@@ -205,6 +206,7 @@ public class NodeView extends JPanel implements AnimatedView, MouseListener {
         int x = 0;
         int y = 0;
         int padding = calculatePadding();
+        // Berechne die Skallierung so dass alles in die vorgesehene Zeichenfläche passt
         double scale = Math.min( (getWidth()-padding) / (double)getWidthOfNeededArea(), (getHeight()-padding) / (double)getHeightOfNeededArea());
         x += (getWidth()) / 2 - (getWidthOfNeededArea() * scale ) / 2;
         y += (getHeight()) / 2 - (getHeightOfNeededArea() * scale ) / 2;
@@ -213,6 +215,7 @@ public class NodeView extends JPanel implements AnimatedView, MouseListener {
             if( !(c instanceof AnimatedView) )
                 continue;
             AnimatedView view = (AnimatedView)c;
+            // Setze die neue Position und Größe
             if( c instanceof NodeView )
             {
                 c.setLocation( getScaledX( ((NodeView)c).getVirtualX() - (int)minX ) + x, getScaledY( view.getVirtualY() ) + y);
@@ -234,6 +237,7 @@ public class NodeView extends JPanel implements AnimatedView, MouseListener {
             return;
         updateTooltipText();
         double minX = Double.POSITIVE_INFINITY;
+        // Berechnet minimale X Koordinate für verschiebung bei negativen Koordinaten
         for( Component c : getComponents() )
         {
             if( !(c instanceof AnimatedView) )
@@ -242,6 +246,7 @@ public class NodeView extends JPanel implements AnimatedView, MouseListener {
         }
         int x = 0;
         int padding = calculatePadding();
+        // Berechne Skallierungsfaktor
         double scale = Math.min( (getWidth()-padding) / (double)getWidthOfNeededArea(), (getHeight()-padding) / (double)getHeightOfNeededArea());
         x += (getWidth()-padding) / 2 - (getWidthOfNeededArea() * scale ) / 2 + padding/2;
         for( Component c : getComponents() )
@@ -251,6 +256,7 @@ public class NodeView extends JPanel implements AnimatedView, MouseListener {
                 if( layout != LayoutType.COMBINED )
                 {
                     NodeView v = (NodeView)c;
+                    // Zeichnet den Hintergrund um die Knoten in der Klassenfarbe
                     v.renderClass( g.create( getScaledX( v.getPlainVirtualX() - (int)minX - 12 ) + x, c.getY() - getScaledY(12), getScaledX( v.getPlainVirtualWidth() + 22 ), c.getHeight() + getScaledY(22) ) );
                 }
             }
@@ -274,20 +280,20 @@ public class NodeView extends JPanel implements AnimatedView, MouseListener {
 
     @Override
     public void paintComponent( Graphics g )
-    {
+    { // Zeichnet den Knoten
         Graphics2D g2 = (Graphics2D)g;
         g2.setColor( model.getColor( layout ) );
         g2.setStroke(new BasicStroke(5));
         if( model.getContainedNodes().size() == 0 )
         {
             if( model.getRoot( layout ) == model )
-                g2.fillOval( 0, 0, getWidth(), getHeight() );
+                g2.fillOval( 0, 0, getWidth(), getHeight() ); // Falls Wurzelknoten Kreis
             else
-                g2.fillRect( 0, 0, getWidth(), getHeight() );
+                g2.fillRect( 0, 0, getWidth(), getHeight() ); // Sonnst Rechteck
         }
         boolean selected = model.isSelected( layout );
         if( selected )
-        {
+        { // Wenn Selected dann Schwarz färben
             g.setColor( Color.BLACK );
             if( model.getContainedNodes().size() > 0 )
                 g.setColor( Color.GRAY );
@@ -295,9 +301,9 @@ public class NodeView extends JPanel implements AnimatedView, MouseListener {
         }
         Border linebor = BorderFactory.createLineBorder(model.getColor( layout ), 5);
         if( model.getRoot( layout ) != model || model.getContainedNodes().size() != 0  )
-            linebor.paintBorder( this, g2, 0, 0, getWidth(), getHeight() );
+            linebor.paintBorder( this, g2, 0, 0, getWidth(), getHeight() ); // Falls Subgraph dann nur Rahmen zeichnen
         if( model.isMouseOver() && model.getContainedNodes().size() == 0 )
-        {
+        { // Falls maus über dem Knoten dann weiß markieren
             g.setColor( Color.WHITE );
             g.fillOval( getWidth() / 4, getHeight() / 4, getWidth() / 2, getHeight() / 2 );
         }

+ 7 - 2
src/view/OptionsDialog.java

@@ -30,7 +30,7 @@ public class OptionsDialog extends JDialog {
     private int tempFSize = 12;
     
     private static class Options
-    {
+    { // Speichert die Optionen wie sie zuletzt waren (um zu prüfen ob was geändert wurde)
         public int layoutDisplaySelection = 0;
         public int runStepsSelection = 0;
         public int autoCollapse = 0;
@@ -47,14 +47,17 @@ public class OptionsDialog extends JDialog {
         String[] displayValues = { "All", "Only current" };
         display = new JComboBox<String>( displayValues );
         add( display );
+        // Run Option
         add( new JLabel( "Run steps:" ) );
         String[] runValues = { "All", "Only expanded" };
         run = new JComboBox<String>( runValues );
         add( run );
+        // Automatically collapse option
         add( new JLabel( "Automatically collapse pseudocode:" ) );
         String[] collapseValues = { "No", "Yes" };
         collapse = new JComboBox<String>( collapseValues );
         add( collapse );
+        // Font size Option
         add( new JLabel( "Font size:" ) );
         fSize = new JTextField( "12" );
         add( fSize );
@@ -65,12 +68,14 @@ public class OptionsDialog extends JDialog {
             }
         }, fSize ) );
         add( new JLabel() );
+        // save
         speichern = new JButton( "Ok" );
         speichern.addActionListener( new ActionListener() {
 
             @Override
             public void actionPerformed(ActionEvent e) {
                 try {
+                	// prüfe auf änderungen
                     boolean change = options.layoutDisplaySelection != display.getSelectedIndex() ||
                             options.runStepsSelection != run.getSelectedIndex() ||
                             tempFSize != options.fontSize ||
@@ -82,7 +87,7 @@ public class OptionsDialog extends JDialog {
                     if( change )
                     {
                         for( ActionListener l : listeners )
-                        {
+                        { // benachrichtige die Listener über die Änderungen
                             l.actionPerformed( new ActionEvent(this, 0, "Options changed" ) );
                         }
                     }