~berthold-daum/zora/trunk

« back to all changes in this revision

Viewing changes to com.bdaum.zoom.ui/src/com/bdaum/zoom/ui/internal/UiActivator.java

  • Committer: bdaum
  • Date: 2015-12-26 10:21:51 UTC
  • Revision ID: berthold.daum@bdaum.de-20151226102151-44f1j5113167thb9
VersionĀ 2.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
package com.bdaum.zoom.ui.internal;
22
22
 
23
 
import java.applet.Applet;
24
 
import java.applet.AudioClip;
25
23
import java.io.ByteArrayInputStream;
26
24
import java.io.File;
27
25
import java.io.IOException;
49
47
import javax.sound.sampled.AudioSystem;
50
48
import javax.sound.sampled.Clip;
51
49
import javax.sound.sampled.DataLine;
 
50
import javax.sound.sampled.LineEvent;
 
51
import javax.sound.sampled.LineListener;
52
52
import javax.sound.sampled.LineUnavailableException;
53
53
import javax.sound.sampled.UnsupportedAudioFileException;
54
54
 
205
205
 
206
206
        private boolean slideShowRunning;
207
207
 
208
 
        private AudioClip audioClip;
 
208
        // private AudioClip audioClip;
209
209
 
210
210
        private boolean showHover = true;
211
211
 
254
254
 
255
255
        private File picasaScanList;
256
256
 
 
257
        private Clip clip;
 
258
 
257
259
        /*
258
260
         * (non-Javadoc)
259
261
         *
454
456
                                isResetImage, isResetStatus, isResetExif, isResetIptc,
455
457
                                isResetGps, isResetFaceData, processSidecars, rawimport, this,
456
458
                                dnguncompressed, dnglinear, deriverelations, autoDerive,
457
 
                                applyXmp, dngfolder.trim(), alarmonprompt,
458
 
                                alarmonfinish, inBackground, makerNotes, archiveRecipes,
 
459
                                applyXmp, dngfolder.trim(), alarmonprompt, alarmonfinish,
 
460
                                inBackground, makerNotes, archiveRecipes,
459
461
                                meta.getJpegQuality(), showImported,
460
462
                                getEnabledRelationDetectors(), obtainAutoRules());
461
463
        }
634
636
                return slideShowRunning;
635
637
        }
636
638
 
637
 
        public AudioClip getAudioClip() {
638
 
                return audioClip;
639
 
 
640
 
        }
641
 
 
642
 
        public void setAudioClip(AudioClip sound) {
643
 
                audioClip = sound;
644
 
        }
645
 
 
646
639
        public boolean getShowHover() {
647
640
                return showHover;
648
641
        }
781
774
                                } else {
782
775
                                        final IDbManager dbManager = activator.getDbManager();
783
776
                                        if (dbManager.getFile() != null) {
 
777
                                                Meta meta = dbManager.getMeta(false);
 
778
                                                if (meta != null) {
 
779
                                                        meta.setLastSessionEnd(new Date());
 
780
                                                        dbManager.safeTransaction(null, meta);
 
781
                                                }
784
782
                                                if (mode != CatalogListener.TASKBAR) {
785
783
                                                        Set<String> postponed = Core.getCore()
786
784
                                                                        .getDbFactory().getLireService()
787
785
                                                                        .postponeIndexing();
788
786
                                                        waitOnCancel(Constants.OPERATIONJOBFAMILY);
789
787
                                                        waitOnCancel(Constants.FILETRANSFER);
790
 
                                                        if (!postponed.isEmpty()) {
791
 
                                                                Meta meta = dbManager.getMeta(true);
792
 
                                                                if (meta != null) {
793
 
                                                                        meta.setPostponed(postponed);
794
 
                                                                        dbManager.safeTransaction(null, meta);
795
 
                                                                }
 
788
                                                        if (!postponed.isEmpty() && meta != null) {
 
789
                                                                meta.setPostponed(postponed);
 
790
                                                                dbManager.safeTransaction(null, meta);
796
791
                                                        }
797
792
                                                        if (repairCat) {
798
793
                                                                repairCat = false;
810
805
                                                        activator.deleteTrashCan();
811
806
                                                if (!BatchActivator.isFastExit()
812
807
                                                                && dbManager.isEmbedded()) {
813
 
                                                        Meta meta = dbManager.getMeta(true);
814
808
                                                        boolean hasBackups = meta == null
815
809
                                                                        || meta.getBackupLocation() != null
816
810
                                                                        && meta.getBackupLocation().length() > 0;
920
914
        }
921
915
 
922
916
        public void playVoicenote(final Asset asset) {
923
 
                stopAudio();
924
917
                if (asset != null) {
925
918
                        if (asset.getFileState() == IVolumeManager.PEER) {
926
919
                                final IPeerService peerService = Core.getCore()
939
932
                                        }
940
933
                                }
941
934
                        }
942
 
                        play(Core.getCore().getVolumeManager().findVoiceFile(asset));
 
935
                        URI voiceURI = Core.getCore().getVolumeManager()
 
936
                                        .findVoiceFile(asset);
 
937
                        try {
 
938
                                playSoundfile(voiceURI.toURL(), null);
 
939
                        } catch (MalformedURLException e) {
 
940
                                // should not happen
 
941
                        }
943
942
                }
944
943
        }
945
944
 
972
971
                                                if (peerService.transferRemoteFile(
973
972
                                                                new NullProgressMonitor(), assetOrigin,
974
973
                                                                voiceInfo, tempFile)) {
975
 
                                                        play(tempFile.toURI());
 
974
                                                        playSoundfile(tempFile.toURI().toURL(), null);
976
975
                                                }
977
976
                                        }
978
977
                                } catch (URISyntaxException e) {
994
993
                }
995
994
        }
996
995
 
997
 
        private void play(URI uri) {
998
 
                if (uri != null) {
999
 
                        try {
1000
 
                                AudioClip sound = Applet.newAudioClip(uri.toURL());
1001
 
                                sound.play();
1002
 
                                setAudioClip(sound);
1003
 
                        } catch (MalformedURLException e) {
1004
 
                                // ignore
1005
 
                        }
1006
 
                }
1007
 
        }
1008
 
 
1009
996
        public void stopAudio() {
1010
 
                AudioClip sound = getAudioClip();
1011
 
                if (sound != null) {
1012
 
                        sound.stop();
1013
 
                        setAudioClip(null);
1014
 
                }
 
997
                if (clip != null)
 
998
                        clip.stop();
1015
999
        }
1016
1000
 
1017
1001
        public IImageViewer[] getImageViewers() {
1091
1075
                        URL url = FileLocator.findFileURL(getBundle(),
1092
1076
                                        "/sound/" + sound + ".wav", true); //$NON-NLS-1$ //$NON-NLS-2$
1093
1077
                        if (url != null)
1094
 
                                playSoundfile(url);
 
1078
                                playSoundfile(url, null);
1095
1079
                } catch (IOException e) {
1096
1080
                        // do nothing
1097
1081
                }
1098
1082
        }
1099
1083
 
1100
 
        public void playSoundfile(URL clipURL) {
1101
 
                try {
1102
 
                        AudioInputStream ais = AudioSystem.getAudioInputStream(clipURL);
 
1084
        public long getSoundfileLengthInMicroseconds(URL clipURL) {
 
1085
                try {
 
1086
                        final AudioInputStream ais = AudioSystem
 
1087
                                        .getAudioInputStream(clipURL);
 
1088
                        Clip clip = (Clip) AudioSystem.getLine(new DataLine.Info(
 
1089
                                        Clip.class, ais.getFormat()));
 
1090
                        long musec = clip.getMicrosecondLength();
 
1091
                        ais.close();
 
1092
                        return musec;
 
1093
                } catch (Exception e) {
 
1094
                        return 0L;
 
1095
                }
 
1096
        }
 
1097
 
 
1098
        public void playSoundfile(URL clipURL, final Runnable onStop) {
 
1099
                stopAudio();
 
1100
                try {
 
1101
                        final AudioInputStream ais = AudioSystem
 
1102
                                        .getAudioInputStream(clipURL);
 
1103
                        clip = (Clip) AudioSystem.getLine(new DataLine.Info(Clip.class, ais
 
1104
                                        .getFormat()));
1103
1105
                        try {
1104
 
                                Clip clip = (Clip) AudioSystem.getLine(new DataLine.Info(
1105
 
                                                Clip.class, ais.getFormat()));
1106
 
                                try {
1107
 
                                        try {
1108
 
                                                clip.open(ais);
1109
 
                                        } catch (IllegalStateException e) {
1110
 
                                                // line already open
 
1106
                                clip.open(ais);
 
1107
                        } catch (IllegalStateException e) {
 
1108
                                // line already open
 
1109
                        }
 
1110
                        clip.addLineListener(new LineListener() {
 
1111
                                public void update(LineEvent event) {
 
1112
                                        if (event.getType() == LineEvent.Type.STOP) {
 
1113
                                                clip.close();
 
1114
                                                clip = null;
 
1115
                                                try {
 
1116
                                                        ais.close();
 
1117
                                                        if (onStop != null)
 
1118
                                                                onStop.run();
 
1119
                                                } catch (IOException e) {
 
1120
                                                        // ignore
 
1121
                                                }
1111
1122
                                        }
1112
 
                                        clip.start();
1113
 
                                        while (clip.isRunning())
1114
 
                                                Thread.yield();
1115
 
                                } finally {
1116
 
                                        clip.close();
1117
1123
                                }
1118
 
                        } finally {
1119
 
                                ais.close();
1120
 
                        }
 
1124
                        });
 
1125
                        clip.start();
1121
1126
                } catch (IOException e) {
1122
1127
                        // do nothing
1123
1128
                } catch (LineUnavailableException e) {