12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package view;
- import java.awt.BasicStroke;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import javax.swing.JPanel;
- /**
- * displays a legend that describes the shapes and colors
- * @author kolja
- *
- */
- public class LegendView extends JPanel {
- private static final long serialVersionUID = 1L;
- private static final int PADDING = 4;
- @Override
- public void paintComponent( Graphics g ) {
- // Zeichnet die Legende
- g.setFont( RenderHelper.font );
- FontMetrics fm = g.getFontMetrics(); // Font Metrics berechnen
- setPreferredSize( new Dimension( getPreferredSize().width, fm.getHeight() + PADDING * 2 ) );
-
- int height = fm.getHeight() + PADDING * 2;
-
- 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 );
- x += height;
- 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 );
- g.fillOval( x + PADDING, PADDING, height - PADDING * 2, height - PADDING * 2 );
- x += height + PADDING;
- 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 );
- g.fillOval( x + PADDING, PADDING, height - PADDING * 2, height - PADDING * 2 );
- x += height + PADDING;
- g.setColor( Color.BLACK );
- g.drawString( "block color", x, fm.getMaxAscent() + PADDING );
- x += fm.stringWidth( "block color" ) + PADDING * 4;
- }
- }
|