Author: bpoussin Date: 2012-09-06 16:42:21 +0200 (Thu, 06 Sep 2012) New Revision: 548 Url: http://forge.codelutin.com/repositories/revision/sammoa/548 Log: bouton stop/start l'un sur l'autre affichage du temps courant en HH:mm:ss Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/SoundPlayer.java Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/SoundPlayer.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/SoundPlayer.java 2012-09-06 14:41:36 UTC (rev 547) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/SoundPlayer.java 2012-09-06 14:42:21 UTC (rev 548) @@ -81,9 +81,10 @@ protected JButton stop; // The Stop button protected JSlider progress; // Shows and sets current position in sound protected JLabel time; // Displays audioPosition as a number - protected JLabel maxTime; - protected int timePad; // le nombre de caratere a ajouter pour le temps + protected FastDateFormat dateFormat = FastDateFormat.getInstance("HH:mm"); + protected FastDateFormat longDateFormat = FastDateFormat.getInstance("HH:mm:ss"); + // Create a SoundPlayer component for the specified file. public SoundPlayer() { this(null); @@ -107,16 +108,18 @@ progress.setPaintTicks(true); progress.setPaintLabels(true); - time = new JLabel("0.0"); // Shows position as a # - maxTime = new JLabel("/0.0"); // Shows position as a # + time = new JLabel("00:00:00"); // Shows position as a # // put those controls in a row - Box row = Box.createHorizontalBox( ); - row.add(play); - row.add(stop); + Box row = Box.createHorizontalBox(); + + Box buttons = Box.createVerticalBox(); + buttons.add(play); + buttons.add(stop); + + row.add(buttons); row.add(progress); row.add(time); - row.add(maxTime); // And add them to this component. setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); @@ -169,9 +172,13 @@ progress.addChangeListener(new ChangeListener( ) { public void stateChanged(ChangeEvent e) { // changement du text de position - int value = progress.getValue( ); - String timeString = value/1000 + "." + (value%1000)/100; - timeString = StringUtils.leftPad(timeString, timePad, '0'); + Date date = getAudioReader().getStartDate(); + long start = 0; + if (date != null) { + start = date.getTime(); + } + int value = progress.getValue(); + String timeString = dateFormat.format(start + value); time.setText(timeString); } }); @@ -206,7 +213,7 @@ break; } } - FastDateFormat dateFormat = FastDateFormat.getInstance("HH:mm"); + /** * On met a la seconde dans le slider */ @@ -221,11 +228,6 @@ progress.setValue((int)getAudioReader().getPosition()); progress.setMaximum(max); - // Affichage du temps - String maxTimeString = (max/1000) + "." + (audioLength % 1000) / 100; - maxTime.setText("/" + maxTimeString); - timePad = maxTimeString.length(); - // calcul de l'espace entre chaque affichage de l'heure en fonction de la longueur du slider double width = progress.getSize().getWidth(); long step = audioLength * 100 / (long)width; // on minimum tous les 100px
participants (1)
-
bpoussin@users.forge.codelutin.com