00001 package i2bpro.layer.Panels;
00002
00003 import i2bpro.layer.Layer;
00004 import i2bpro.playlist.PlayList;
00005 import i2bpro.player.Player;
00006 import i2bpro.player.PositionUpdate;
00007 import java.awt.BorderLayout;
00008 import java.awt.event.MouseWheelEvent;
00009 import java.awt.event.MouseWheelListener;
00010 import javax.swing.JLabel;
00011 import javax.swing.JPanel;
00012 import javax.swing.JSlider;
00013 import javax.swing.SwingConstants;
00014 import javax.swing.border.EmptyBorder;
00015 import javax.swing.event.ChangeEvent;
00016 import javax.swing.event.ChangeListener;
00017
00018
00019
00036 public final class PositionPanel extends JPanel
00037 {
00038
00039 private JSlider position = new JSlider(SwingConstants.HORIZONTAL);
00040 private JLabel nullLabel = new JLabel("00:00:00");
00041 private JLabel positionLabel = new JLabel("00:00:00");
00042 private JLabel totalTimeLabel = new JLabel("00:00:00");
00043
00044
00045
00052 public PositionPanel()
00053 {
00054 setLayout(new BorderLayout());
00055 initPosition();
00056 initLabels();
00057 addListener();
00058 }
00059
00060
00061
00070 private void initPosition()
00071 {
00072 position.setEnabled(false);
00073 add(positionLabel, BorderLayout.SOUTH);
00074 }
00075
00076
00077
00084 private void initLabels()
00085 {
00086 positionLabel.setLocation(100,1);
00087 positionLabel.setHorizontalAlignment(JLabel.CENTER);
00088 nullLabel.setBorder(new EmptyBorder(5,5,5,5));
00089 totalTimeLabel.setBorder(new EmptyBorder(5,5,5,5));
00090 positionLabel.setBorder(new EmptyBorder(0,0,5,0));
00091 add(position, BorderLayout.CENTER);
00092 add(nullLabel, BorderLayout.WEST);
00093 add(totalTimeLabel, BorderLayout.EAST);
00094 }
00095
00096
00097
00108 public void PlayerStarted()
00109 {
00110 Layer.getInstance().setPositionUpdate(true);
00111 if (position.isEnabled() == false)
00112 {
00113 position.setMinimum(0);
00114 position.setMaximum(Player.getInstance().getDuration().getSeconds());
00115 position.setEnabled(true);
00116 totalTimeLabel.setText(Player.getInstance().getDuration().getString());
00117 }
00118 startPositionUpdate();
00119 }
00120
00121
00122
00131 public void PlayerStopped()
00132 {
00133 if (PlayList.getInstance().getPlayList().size() > 0)
00134 {
00135 position.setMinimum(0);
00136 position.setMaximum(0);
00137 position.setValue(0);
00138 position.setEnabled(false);
00139 }
00140 Layer.getInstance().setPositionUpdate(true);
00141 position.setMaximum(0);
00142 positionLabel.setText("00:00:00");
00143 totalTimeLabel.setText("00:00:00");
00144 Layer.getInstance().setPositionUpdate(false);
00145 }
00146
00147
00148
00156 private void startPositionUpdate()
00157 {
00158 PositionUpdate posUpdate = new PositionUpdate();
00159 posUpdate.start();
00160 }
00161
00162
00163
00170 private void addListener()
00171 {
00172 position.addChangeListener(new ChangeListener()
00173 {
00192 public void stateChanged(ChangeEvent e)
00193 {
00194 if (Layer.getInstance().isPositionUpdate())
00195 {
00196 Layer.getInstance().setPositionUpdate(false);
00197 } else {
00198 if (Player.getInstance().getState() > 0)
00199 {
00200 Player.getInstance().setPosition(position.getValue());
00201 }
00202 if (Player.getInstance().getState() == 2)
00203 positionLabel.setText(
00204 Player.getInstance().getPosition().getString());
00205 }
00206 }
00207 });
00208
00209
00210
00218 position.addMouseWheelListener(new MouseWheelListener()
00219 {
00227 public void mouseWheelMoved(MouseWheelEvent e)
00228 {
00229 position.setValue(position.getValue() - e.getUnitsToScroll());
00230 }
00231 });
00232 }
00233
00234
00235
00245 public void setPositionLabel(String text) { positionLabel.setText(text); }
00246
00247
00248
00259 public void setPositionValue(int val)
00260 {
00261 position.setValue(val);
00262 }
00263 }