import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import javax.swing.JLabel; import javax.swing.JPanel; public class PatternJPanel extends JPanel { private static final long serialVersionUID = 1L; private static final int HEIGHT = 50; private static final int PADDING = 2; public static final int ZOOM_MULTIPLIER = 10; public static final int PATTERN_HEIGHT = (int) (HEIGHT + new JLabel(" ").getPreferredSize().height); private Music music; private TimeLineJPanel timeLine; private int end; public PatternJPanel(Music music, TimeLineJPanel timeLine) { this.music = music; this.timeLine = timeLine; end = Util.transformZoom(music.getMusicPattern().getStop(), timeLine.getZoomLevel()); setPreferredSize(new Dimension((int) end, HEIGHT)); } public void refreshPreferedSize() { end = Util.transformZoom(music.getMusicPattern().getStop(), timeLine.getZoomLevel()); setPreferredSize(new Dimension((int) end, HEIGHT)); } public int getEnd() { return end; } public Music getMusic() { return music; } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.WHITE); int begin = Util.transformZoom(music.getMusicPattern().getBegin(), timeLine.getZoomLevel()); g.fillRect(begin, 0, end - begin, HEIGHT); MusicPattern pattern = music.getMusicPattern(); g.setColor(Color.BLACK); for(int i=0; i