Parcourir la source

neue Option zum setzen der Schriftgröße für die präsentation hinzugefügt

Kolja Strohm il y a 6 ans
Parent
commit
de651da5f7

+ 13 - 84
src/view/MainView.java

@@ -1,7 +1,6 @@
 package view;
 package view;
 
 
 import java.awt.BorderLayout;
 import java.awt.BorderLayout;
-import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.Font;
 import java.awt.GridLayout;
 import java.awt.GridLayout;
@@ -9,6 +8,7 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ActionListener;
 import java.awt.event.ComponentAdapter;
 import java.awt.event.ComponentAdapter;
 import java.awt.event.ComponentEvent;
 import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
 import java.awt.event.KeyEvent;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseEvent;
@@ -29,8 +29,6 @@ import javax.swing.JSplitPane;
 import javax.swing.JTextArea;
 import javax.swing.JTextArea;
 import javax.swing.JTextField;
 import javax.swing.JTextField;
 import javax.swing.JTree;
 import javax.swing.JTree;
-import javax.swing.event.DocumentEvent;
-import javax.swing.event.DocumentListener;
 import javax.swing.filechooser.FileNameExtensionFilter;
 import javax.swing.filechooser.FileNameExtensionFilter;
 import javax.swing.tree.DefaultTreeModel;
 import javax.swing.tree.DefaultTreeModel;
 import javax.swing.tree.TreePath;
 import javax.swing.tree.TreePath;
@@ -163,6 +161,7 @@ public class MainView {
      */
      */
     public MainView( LayeredGraphNode graph )
     public MainView( LayeredGraphNode graph )
     {
     {
+        RenderHelper.font = new Font("Monospaced", Font.PLAIN, 12);
         graph.setColor( null, null );
         graph.setColor( null, null );
         frameCounter++;
         frameCounter++;
         this.graph = graph;
         this.graph = graph;
@@ -335,45 +334,12 @@ public class MainView {
         delayText.setBounds( 260, 10, 80, 20 );
         delayText.setBounds( 260, 10, 80, 20 );
         delay = new JTextField( String.valueOf(AnimationController.DEFAULT_DELAY) );
         delay = new JTextField( String.valueOf(AnimationController.DEFAULT_DELAY) );
         delay.setBounds( 260, 30, 90, 20 );
         delay.setBounds( 260, 30, 90, 20 );
-        delay.getDocument().addDocumentListener( new DocumentListener() {
-
-            @Override
-            public void insertUpdate(DocumentEvent e) {
-                try
-                {
-                    controller.setDelay( Integer.parseInt( delay.getText() ) );
-                    delay.setBackground( Color.WHITE );
-                } catch( Exception e1 )
-                {
-                    delay.setBackground( Color.RED );
-                }
-            }
-
-            @Override
-            public void removeUpdate(DocumentEvent e) {
-                try
-                {
-                    controller.setDelay( Integer.parseInt( delay.getText() ) );
-                    delay.setBackground( Color.WHITE );
-                } catch( Exception e1 )
-                {
-                    delay.setBackground( Color.RED );
-                }
-            }
-
+        delay.getDocument().addDocumentListener( new NumberDocumentListener( new NumberDocumentListener.Action() {
             @Override
             @Override
-            public void changedUpdate(DocumentEvent e) {
-                try
-                {
-                    controller.setDelay( Integer.parseInt( delay.getText() ) );
-                    delay.setBackground( Color.WHITE );
-                } catch( Exception e1 )
-                {
-                    delay.setBackground( Color.RED );
-                }
+            public void action(int val) {
+                controller.setDelay( Integer.parseInt( delay.getText() ) );
             }
             }
-            
-        });
+        }, delay ) );
         load = new NiceButton( "load" );
         load = new NiceButton( "load" );
         load.setLocation( 260, 60 );
         load.setLocation( 260, 60 );
         load.setMnemonic( KeyEvent.VK_L );
         load.setMnemonic( KeyEvent.VK_L );
@@ -552,7 +518,7 @@ public class MainView {
         treeView.setBounds( 10,  110,  390, 380 );
         treeView.setBounds( 10,  110,  390, 380 );
         
         
         JTextArea debugText = new JTextArea();
         JTextArea debugText = new JTextArea();
-        debugText.setFont( new Font( "Monospaced", Font.PLAIN, 12 ) );
+        debugText.setFont( RenderHelper.font );
         debugText.setEditable( false );
         debugText.setEditable( false );
         debugText.setBackground( RenderHelper.BACKGROUND_COLOR );
         debugText.setBackground( RenderHelper.BACKGROUND_COLOR );
         debugText.setForeground( RenderHelper.FOREGROUND_COLOR );
         debugText.setForeground( RenderHelper.FOREGROUND_COLOR );
@@ -705,50 +671,13 @@ public class MainView {
 
 
             @Override
             @Override
             public void actionPerformed(ActionEvent e) {
             public void actionPerformed(ActionEvent e) {
-                pl.remove( topLeft );
-                pl.remove( topRight );
-                pl.remove( bottomLeft );
-                pl.remove( bottomRight );
-                pl.remove( combined );
-                layne.remove( combined );
                 controller.setStepOption( optionsDialog.getRunStepsOption() );
                 controller.setStepOption( optionsDialog.getRunStepsOption() );
-                if( optionsDialog.getLayerDisplayOption() == 0 )
-                {
-                    pl.setLayout( grout );
-                    pl.add( topLeft );
-                    pl.add( topRight );
-                    pl.add( bottomLeft );
-                    pl.add( bottomRight );
-                    layne.add( combined, 0 );
-                    pl.revalidate();
-                }
-                else
-                {
-                    pl.setLayout( new BorderLayout() );
-                    switch( algorithm.getAlgorithmState() )
-                    {
-                    case CONFLICTS:
-                        pl.add( topLeft );
-                        break;
-                    case LAYOUT1:
-                        pl.add( topLeft );
-                        break;
-                    case LAYOUT2:
-                        pl.add( topRight );
-                        break;
-                    case LAYOUT3:
-                        pl.add( bottomLeft );
-                        break;
-                    case LAYOUT4:
-                        pl.add( bottomRight );
-                        break;
-                    case COMBINE:
-                        pl.add( combined );
-                        break;
-                    }
-                    pl.revalidate();
-                }
-                frame.repaint();
+                RenderHelper.font = new Font( "Monospaced", Font.PLAIN, optionsDialog.getFontSize() );
+                debugText.setFont( RenderHelper.font );
+                pseudoTree.setFont( RenderHelper.font );
+                pseudoTree.setRowHeight( (int)(15.0/12 * optionsDialog.getFontSize() ) );
+                for( ComponentListener l : frame.getComponentListeners() )
+                    l.componentResized( new ComponentEvent( frame, 0 ) );
             }
             }
             
             
         });
         });

+ 59 - 0
src/view/NumberDocumentListener.java

@@ -0,0 +1,59 @@
+package view;
+
+import java.awt.Color;
+
+import javax.swing.JTextField;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+
+public class NumberDocumentListener implements DocumentListener {
+    
+    public interface Action{
+        public void action( int val );
+    }
+    
+    private Action action;
+    private JTextField field;
+    
+    public NumberDocumentListener( Action callback, JTextField textField )
+    {
+        action = callback;
+        field = textField;
+    }
+    
+    @Override
+    public void insertUpdate(DocumentEvent e) {
+        try
+        {
+            action.action( Integer.parseInt( field.getText() ) );
+            field.setBackground( Color.WHITE );
+        } catch( Exception e1 )
+        {
+            field.setBackground( Color.RED );
+        }
+    }
+
+    @Override
+    public void removeUpdate(DocumentEvent e) {
+        try
+        {
+            action.action( Integer.parseInt( field.getText() ) );
+            field.setBackground( Color.WHITE );
+        } catch( Exception e1 )
+        {
+            field.setBackground( Color.RED );
+        }
+    }
+
+    @Override
+    public void changedUpdate(DocumentEvent e) {
+        try
+        {
+            action.action( Integer.parseInt( field.getText() ) );
+            field.setBackground( Color.WHITE );
+        } catch( Exception e1 )
+        {
+            field.setBackground( Color.RED );
+        }
+    }
+}

+ 22 - 2
src/view/OptionsDialog.java

@@ -10,6 +10,7 @@ import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JComboBox;
 import javax.swing.JDialog;
 import javax.swing.JDialog;
 import javax.swing.JLabel;
 import javax.swing.JLabel;
+import javax.swing.JTextField;
 
 
 public class OptionsDialog extends JDialog {
 public class OptionsDialog extends JDialog {
 
 
@@ -19,11 +20,14 @@ public class OptionsDialog extends JDialog {
     private JComboBox<String> display;
     private JComboBox<String> display;
     private JButton speichern;
     private JButton speichern;
     private JComboBox<String> run;
     private JComboBox<String> run;
+    private JTextField fSize;
+    private int tempFSize = 12;
     
     
     private static class Options
     private static class Options
     {
     {
         public int layoutDisplaySelection = 0;
         public int layoutDisplaySelection = 0;
         public int runStepsSelection = 0;
         public int runStepsSelection = 0;
+        public int fontSize = 12;
     }
     }
     
     
     private Options options;
     private Options options;
@@ -31,7 +35,7 @@ public class OptionsDialog extends JDialog {
     OptionsDialog()
     OptionsDialog()
     {
     {
         setTitle( "Preferences" );
         setTitle( "Preferences" );
-        setLayout( new GridLayout( 3, 2 ) );
+        setLayout( new GridLayout( 4, 2 ) );
         add( new JLabel( "Display layouts:" ) );
         add( new JLabel( "Display layouts:" ) );
         String[] displayValues = { "All", "Only current" };
         String[] displayValues = { "All", "Only current" };
         display = new JComboBox<String>( displayValues );
         display = new JComboBox<String>( displayValues );
@@ -40,6 +44,15 @@ public class OptionsDialog extends JDialog {
         String[] runValues = { "All", "Only expanded" };
         String[] runValues = { "All", "Only expanded" };
         run = new JComboBox<String>( runValues );
         run = new JComboBox<String>( runValues );
         add( run );
         add( run );
+        add( new JLabel( "Font size:" ) );
+        fSize = new JTextField( "12" );
+        add( fSize );
+        fSize.getDocument().addDocumentListener( new NumberDocumentListener( new NumberDocumentListener.Action() {
+            @Override
+            public void action(int val) {
+                tempFSize = val;
+            }
+        }, fSize ) );
         add( new JLabel() );
         add( new JLabel() );
         speichern = new JButton( "Ok" );
         speichern = new JButton( "Ok" );
         speichern.addActionListener( new ActionListener() {
         speichern.addActionListener( new ActionListener() {
@@ -48,9 +61,11 @@ public class OptionsDialog extends JDialog {
             public void actionPerformed(ActionEvent e) {
             public void actionPerformed(ActionEvent e) {
                 try {
                 try {
                     boolean change = options.layoutDisplaySelection != display.getSelectedIndex() ||
                     boolean change = options.layoutDisplaySelection != display.getSelectedIndex() ||
-                            options.runStepsSelection != run.getSelectedIndex();
+                            options.runStepsSelection != run.getSelectedIndex() ||
+                            tempFSize != options.fontSize;
                     options.layoutDisplaySelection = display.getSelectedIndex();
                     options.layoutDisplaySelection = display.getSelectedIndex();
                     options.runStepsSelection = run.getSelectedIndex();
                     options.runStepsSelection = run.getSelectedIndex();
+                    options.fontSize = tempFSize;
                     if( change )
                     if( change )
                     {
                     {
                         for( ActionListener l : listeners )
                         for( ActionListener l : listeners )
@@ -83,6 +98,11 @@ public class OptionsDialog extends JDialog {
         return options.runStepsSelection;
         return options.runStepsSelection;
     }
     }
     
     
+    public int getFontSize()
+    {
+        return options.fontSize;
+    }
+    
     public void addActionListener( ActionListener al )
     public void addActionListener( ActionListener al )
     {
     {
         listeners.add( al );
         listeners.add( al );

+ 3 - 3
src/view/PseudoCodeLines.java

@@ -128,15 +128,15 @@ public class PseudoCodeLines extends JComponent implements MouseListener{
             int number = getLineNumber( node );
             int number = getLineNumber( node );
             Rectangle rect = tree.getRowBounds( i );
             Rectangle rect = tree.getRowBounds( i );
             String text = String.valueOf( number );
             String text = String.valueOf( number );
-            int yPosition = rect.y + rect.height - VERTICAL_PADDING;
+            int yPosition = rect.y + rect.height / 2 + 4;
             if( !node.hasSelectedSubnode() && node.isSelected() )
             if( !node.hasSelectedSubnode() && node.isSelected() )
-                g.drawImage( currentLine.getImage(), HORIZONTAL_PADDING, rect.y + VERTICAL_PADDING - 5, 20, 20, null );
+                g.drawImage( currentLine.getImage(), HORIZONTAL_PADDING, rect.y + rect.height / 2 - 10, 20, 20, null );
             g2d.drawString( text, HORIZONTAL_PADDING * 2 + 20, yPosition );
             g2d.drawString( text, HORIZONTAL_PADDING * 2 + 20, yPosition );
             if( node.hasBreakPoint() )
             if( node.hasBreakPoint() )
             {
             {
                 Color c = g.getColor();
                 Color c = g.getColor();
                 g.setColor( new Color (0xe7887a) );
                 g.setColor( new Color (0xe7887a) );
-                g.fillOval( getWidth() - HORIZONTAL_PADDING - 10, rect.y + VERTICAL_PADDING, 10, 10 );
+                g.fillOval( getWidth() - HORIZONTAL_PADDING - 10, rect.y + rect.height / 2 - 5, 10, 10 );
                 g.setColor( c );
                 g.setColor( c );
             }
             }
         }
         }

+ 1 - 1
src/view/PseudoCodeRenderer.java

@@ -48,7 +48,7 @@ public class PseudoCodeRenderer extends DefaultTreeCellRenderer {
     
     
     @Override
     @Override
     public Font getFont() {
     public Font getFont() {
-        return new Font("Monospaced", Font.PLAIN, 12);
+        return RenderHelper.font;
     }
     }
     
     
     @Override
     @Override

+ 2 - 0
src/view/RenderHelper.java

@@ -1,6 +1,7 @@
 package view;
 package view;
 
 
 import java.awt.Color;
 import java.awt.Color;
+import java.awt.Font;
 import java.awt.Point;
 import java.awt.Point;
 import java.awt.Polygon;
 import java.awt.Polygon;
 import java.awt.Shape;
 import java.awt.Shape;
@@ -16,6 +17,7 @@ public class RenderHelper {
     public static final Color FOREGROUND_COLOR = new Color(0xa9b7c6);
     public static final Color FOREGROUND_COLOR = new Color(0xa9b7c6);
     public static final Color BREAKPOINT_COLOR = new Color(0x6c2020);
     public static final Color BREAKPOINT_COLOR = new Color(0x6c2020);
     public static final Color CURRENT_LINE_COLOR = new Color(0x606366);
     public static final Color CURRENT_LINE_COLOR = new Color(0x606366);
+    public static Font font;
   
   
     /**
     /**
      * creates an arrow shape to draw it, for example as part of an edge.
      * creates an arrow shape to draw it, for example as part of an edge.