|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.examples.modules.audioloader; import java.io.*; import java.lang.reflect.InvocationTargetException; import javax.sound.sampled.*; import org.openide.*; import org.openide.execution.NbClassPath; import org.openide.filesystems.*; import org.openide.nodes.*; import org.openide.util.NbBundle; import org.openide.util.WeakListener; public class ClipLengthProperty extends PropertySupport.ReadOnly implements FileChangeListener { private AudioDataNode n; private FileObject fo; private Float value = null; public ClipLengthProperty (AudioDataNode n, FileObject fo) { super ("clipLength", Float.TYPE, NbBundle.getMessage (ClipLengthProperty.class, "PROP_clipLength"), NbBundle.getMessage (ClipLengthProperty.class, "HINT_clipLength")); this.n = n; this.fo = fo; fo.addFileChangeListener (WeakListener.fileChange (this, fo)); } public synchronized Object getValue () throws IllegalAccessException, InvocationTargetException { if (value == null) { try { // Nope, does not support mark/reset: //InputStream is = fo.getInputStream (); File f = NbClassPath.toFile (fo); AudioInputStream ais = AudioSystem.getAudioInputStream (f); try { value = new Float (ais.getFrameLength () / ais.getFormat ().getFrameRate ()); } finally { ais.close (); } } catch (Exception e) { ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, e); throw new InvocationTargetException (e); } } return value; } public synchronized void fileChanged (FileEvent p1) { value = null; n.fireClipLengthChange (); } // Ignore others: public void fileDeleted (FileEvent p1) { } public void fileDataCreated (FileEvent p1) { } public void fileFolderCreated (FileEvent p1) { } public void fileRenamed (FileRenameEvent p1) { } public void fileAttributeChanged (FileAttributeEvent p1) { } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.