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 { private static final long serialVersionUID = 1L; private static final Color DEFAULT_BACKGROUND = new JPanel().getBackground(); private TimeLineJPanel timeLine; public ArrayList patterns; public MusicRenderer(TimeLineJPanel timeLine) { this.timeLine = timeLine; this.patterns = new ArrayList<>(); } @Override public Component getListCellRendererComponent(JList 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; } }