LegendView.java 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package view;
  2. import java.awt.BasicStroke;
  3. import java.awt.Color;
  4. import java.awt.Dimension;
  5. import java.awt.FontMetrics;
  6. import java.awt.Graphics;
  7. import java.awt.Graphics2D;
  8. import javax.swing.JPanel;
  9. /**
  10. * displays a legend that describes the shapes and colors
  11. * @author kolja
  12. *
  13. */
  14. public class LegendView extends JPanel {
  15. private static final long serialVersionUID = 1L;
  16. private static final int PADDING = 4;
  17. @Override
  18. public void paintComponent( Graphics g ) {
  19. // Zeichnet die Legende
  20. g.setFont( RenderHelper.font );
  21. FontMetrics fm = g.getFontMetrics(); // Font Metrics berechnen
  22. setPreferredSize( new Dimension( getPreferredSize().width, fm.getHeight() + PADDING * 2 ) );
  23. int height = fm.getHeight() + PADDING * 2;
  24. int x = PADDING;
  25. g.drawString( "Legend:", x, fm.getMaxAscent() + PADDING );
  26. x += fm.stringWidth( "Legend:" ) + PADDING;
  27. // Wurzeln von Blöcken
  28. g.setColor( Color.LIGHT_GRAY );
  29. g.fillOval( x, PADDING, height - PADDING*2, height - PADDING*2 );
  30. x += height;
  31. g.setColor( Color.BLACK );
  32. g.drawString( "block root", x, fm.getMaxAscent() + PADDING );
  33. x += fm.stringWidth( "block root" ) + PADDING * 4;
  34. // Dummy Knoten
  35. g.setColor( Color.LIGHT_GRAY );
  36. g.fillOval( x, PADDING, height / 3, height - PADDING*2 );
  37. x += height / 3 + PADDING;
  38. g.setColor( Color.BLACK );
  39. g.drawString( "dummy node", x, fm.getMaxAscent() + PADDING );
  40. x += fm.stringWidth( "dummy node" ) + PADDING * 4;
  41. // Knoten mit Subgraph
  42. g.setColor( Color.LIGHT_GRAY );
  43. ((Graphics2D)g).setStroke(new BasicStroke(2));
  44. g.drawRect( x, PADDING, height - PADDING * 2, height - PADDING * 2 );
  45. x += height;
  46. g.setColor( Color.BLACK );
  47. g.drawString( "node with subgraph", x, fm.getMaxAscent() + PADDING );
  48. x += fm.stringWidth( "node with subgraph" ) + PADDING * 4;
  49. // Kanten, welche als conflicted markiert wurden
  50. g.setColor( Color.RED );
  51. g.drawLine( x, height / 2, x + height - PADDING * 2, height / 2 );
  52. x += height;
  53. g.setColor( Color.BLACK );
  54. g.drawString( "conflicted edge", x, fm.getMaxAscent() + PADDING );
  55. x += fm.stringWidth( "conflicted edge" ) + PADDING * 4;
  56. // Farbe der Klassen
  57. g.setColor( Color.BLUE );
  58. g.fillRect( x, 0, height, height );
  59. g.setColor( Color.LIGHT_GRAY );
  60. g.fillOval( x + PADDING, PADDING, height - PADDING * 2, height - PADDING * 2 );
  61. x += height + PADDING;
  62. g.setColor( Color.BLACK );
  63. g.drawString( "class color", x, fm.getMaxAscent() + PADDING );
  64. x += fm.stringWidth( "class color" ) + PADDING * 4;
  65. // Farben der Blöcke
  66. g.setColor( Color.LIGHT_GRAY );
  67. g.fillRect( x, 0, height, height );
  68. g.setColor( Color.BLUE );
  69. g.fillOval( x + PADDING, PADDING, height - PADDING * 2, height - PADDING * 2 );
  70. x += height + PADDING;
  71. g.setColor( Color.BLACK );
  72. g.drawString( "block color", x, fm.getMaxAscent() + PADDING );
  73. x += fm.stringWidth( "block color" ) + PADDING * 4;
  74. }
  75. }