Blame view

VRGNYMusicLights/Sources/MusicRenderer.java 1.45 KB
278cdee0   pfrison   VRGNYMusicLights ...
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
  import java.awt.Color;
  import java.awt.Component;
  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 TimeLineJPanel timeLine;
  	
  	public ArrayList<PatternJPanel> patterns;
  	
  	public MusicRenderer(TimeLineJPanel timeLine) {
  		this.timeLine = timeLine;
  		this.patterns = new ArrayList<>();
  	}
  	
  	@Override
  	public Component getListCellRendererComponent(JList<? extends Music> list, Music music, int index,
  			boolean isSelected, boolean cellHasFocus) {
  		removeAll();
  		
  		if(isSelected) {
  			setBackground(Color.LIGHT_GRAY);
  		} else {
  			setBackground(DEFAULT_BACKGROUND);
  		}
  		
  		setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
  		
  		JPanel infoPanel = new JPanel();
  		infoPanel.setLayout(new BoxLayout(infoPanel, BoxLayout.LINE_AXIS));
  		infoPanel.add(new JLabel("Pattern " + String.valueOf(index) + " :"));
  		//TODO rigid area to follow scroll ?
  		infoPanel.add(Box.createHorizontalGlue());
  		add(infoPanel);
  		
  		PatternJPanel pattern = new PatternJPanel(music, timeLine);
  		if(patterns.size() > index)
  			patterns.set(index, pattern);
  		else
  			patterns.add(pattern);
  		add(pattern);
  		
  		return this;
  	}
  }