]> ruin.nu Git - moosique.git/blob - MooViewCounter.java
no 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 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 timeSig1, int timeSig2) {
21                 setBackground(Moosique.getGUI().bgColor);
22                 setPreferredSize(new Dimension(35, 200 * CELL_HEIGHT));
23
24                 switch (timeSig2) {
25                         case  16: measure = timeSig1;           // 1/16
26                                 break;
27                         case  8: measure = timeSig1 * 2;        // 1/16
28                                  halfBeat = measure / timeSig1; // 1/8
29                                 break;
30                         case  4: measure = timeSig1 * 4;        // 1/16
31                                  halfBeat = beat / 2;           // 1/8          
32                                  beat = measure / timeSig1;     // 1/4  
33                                 break;
34                         case  2: measure = timeSig1 * 8;        // 1/16
35                                  halfBeat = beat / 2;           // 1/8
36                                  beat = halfNote / 2;           // 1/4
37                                  halfNote = measure / timeSig1; // 1/2
38                                 break;
39                         case  1: measure = timeSig1 * 16;       // 1/16
40                                  halfBeat = beat / 2;           // 1/8
41                                  beat = halfNote / 2;           // 1/4
42                                  halfNote = measure / 2;        // 1/2
43                                 break;
44                 }
45                 
46         }
47         public void paintComponent(Graphics g) {
48                 super.paintComponent(g);
49                 setBackground(Color.black);
50
51                 if (!(g instanceof Graphics2D)) return;
52                 Graphics2D g2 = (Graphics2D)g;
53                 g2.setColor(Color.white);
54                 for (int c = 0; c < 200; c++) {
55                         g2.drawLine(0, c * CELL_HEIGHT, 5, c * CELL_HEIGHT);                                    // 1/16
56                         g2.drawLine(0, c * CELL_HEIGHT * halfBeat, 10, c * CELL_HEIGHT * halfBeat);             // 1/8
57                         g2.drawLine(0, c * CELL_HEIGHT * beat, 15, c * CELL_HEIGHT * beat);                     // 1/4
58                         g2.drawLine(0, c * CELL_HEIGHT * halfNote, 20, c * CELL_HEIGHT * halfNote);             // 1/2
59                         g2.drawLine(0, c * CELL_HEIGHT * measure, 30, c * CELL_HEIGHT * measure);               // 1/1
60                 }
61         }
62 }