7 * @author Andersson, Andreen, Lanneskog, Pehrson
11 public class MooViewCounter extends JPanel {
13 private int measure, halfBeat, beat, halfNote;
14 private static final int CELL_HEIGHT = 10;
17 * Creates an musical ruler depending on the timesignature
20 public MooViewCounter (int timeSig1, int timeSig2) {
21 setBackground(Moosique.getGUI().bgColor);
22 setPreferredSize(new Dimension(35, 200 * CELL_HEIGHT));
25 case 16: measure = timeSig1; // 1/16
27 case 8: measure = timeSig1 * 2; // 1/16
28 halfBeat = measure / timeSig1; // 1/8
30 case 4: measure = timeSig1 * 4; // 1/16
31 halfBeat = beat / 2; // 1/8
32 beat = measure / timeSig1; // 1/4
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
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
47 public void paintComponent(Graphics g) {
48 super.paintComponent(g);
49 setBackground(Color.black);
51 if (!(g instanceof Graphics2D)) return;
52 Graphics2D g2 = (Graphics2D)g;
53 g2.setColor(Color.black);
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