]> ruin.nu Git - moosique.git/blob - MooViewCounter.java
*** empty log message ***
[moosique.git] / MooViewCounter.java
1 import javax.swing.*;
2 import java.awt.*;
3
4 /**
5  * 
6  * 
7  * @author  Andersson, Andreen, Lanneskog, Pehrson
8  * @version 1
9  */
10  
11 public class MooViewCounter extends JPanel {
12
13         private int timeSig1, timeSig2, measure, halfBeat, beat, halfNote;
14         private static final int CELL_HEIGHT = 10;
15         
16         /** 
17          * Creates an musical ruler depending on the timesignature
18          */
19
20         public MooViewCounter (int ts1, int ts2) {
21                 timeSig1 = ts1;
22                 timeSig2 = ts2;
23                 setBackground(Color.black);
24                 setPreferredSize(new Dimension(35, 200 * CELL_HEIGHT));
25                 switch (timeSig2) {
26                         case  16: measure = timeSig1;           // 1/16
27                                 break;
28                         case  8: measure = timeSig1 * 2;        // 1/16
29                                  halfBeat = measure / timeSig1; // 1/8
30                                 break;
31                         case  4: measure = timeSig1 * 4;        // 1/16
32                                  halfBeat = beat / 2;           // 1/8          
33                                  beat = measure / timeSig1;     // 1/4  
34                                 break;
35                         case  2: measure = timeSig1 * 8;        // 1/16
36                                  halfBeat = beat / 2;           // 1/8
37                                  beat = halfNote / 2;           // 1/4
38                                  halfNote = measure / timeSig1; // 1/2
39                                 break;
40                         case  1: measure = timeSig1 * 16;       // 1/16
41                                  halfBeat = beat / 2;           // 1/8
42                                  beat = halfNote / 2;           // 1/4
43                                  halfNote = measure / 2;        // 1/2
44                                 break;
45                 }
46                 
47         }
48         public void paintComponent(Graphics g) {
49                 super.paintComponent(g);
50                 setBackground(Color.black);
51
52                 if (!(g instanceof Graphics2D)) return;
53                 Graphics2D g2 = (Graphics2D)g;
54                 g2.setColor(Color.white);
55                 for (int c = 0; c < 200; c++) {
56                         g2.drawLine(0, c * CELL_HEIGHT, 5, c * CELL_HEIGHT);                                    // 1/16
57                         g2.drawLine(0, c * CELL_HEIGHT * halfBeat, 10, c * CELL_HEIGHT * halfBeat);             // 1/8
58                         g2.drawLine(0, c * CELL_HEIGHT * beat, 15, c * CELL_HEIGHT * beat);                     // 1/4
59                         g2.drawLine(0, c * CELL_HEIGHT * halfNote, 20, c * CELL_HEIGHT * halfNote);             // 1/2
60                         g2.drawLine(0, c * CELL_HEIGHT * measure, 30, c * CELL_HEIGHT * measure);               // 1/1
61                 }
62         }
63 }