MusicRenderer.java
2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.util.ArrayList;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
public class MusicRenderer extends JPanel implements ListCellRenderer<Music> {
private static final long serialVersionUID = 1L;
private static final Color DEFAULT_BACKGROUND = new JPanel().getBackground();
private static final Font defaultFont = new Font(new JLabel().getFont().getName(), Font.PLAIN, new JLabel().getFont().getSize());
private TimeLineJPanel timeLine;
private int infoPadding = 0;
public ArrayList<PatternJPanel> patterns;
public MusicRenderer(TimeLineJPanel timeLine) {
this.timeLine = timeLine;
this.patterns = new ArrayList<>();
}
public void setInfoPadding(int infoPadding) { this.infoPadding = infoPadding; }
@Override
public Component getListCellRendererComponent(JList<? extends Music> list, Music music, int index,
boolean isSelected, boolean cellHasFocus) {
removeAll();
if(music == null)
return this;
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
JPanel infoPanel = new JPanel();
infoPanel.setLayout(new BoxLayout(infoPanel, BoxLayout.LINE_AXIS));
infoPanel.add(Box.createRigidArea(new Dimension(infoPadding, 0)));
JLabel infoLabel = new JLabel("Pattern " + String.valueOf(index) + " : "
+ "(vol : " + String.valueOf(music.getVolume()) + ", "
+ "effect : " + MusicPath.pathNames[music.getMusicPath().getAnimation()] + ", "
+ "effect duration : " + Util.tickToText(music.getMusicPath().getEffectDuration()) + ")");
infoLabel.setFont(defaultFont);
infoPanel.add(infoLabel);
infoPanel.add(Box.createHorizontalGlue());
if(isSelected) {
infoPanel.setBackground(Color.LIGHT_GRAY);
} else {
infoPanel.setBackground(DEFAULT_BACKGROUND);
}
add(infoPanel);
PatternJPanel pattern = new PatternJPanel(music, timeLine);
if(patterns.size() > index)
patterns.set(index, pattern);
else
patterns.add(pattern);
add(pattern);
return this;
}
}