1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/platform/samples/AudioStation/fftview/src/org/foo/fftview/FFTComponent.java Thu Dec 07 17:39:56 2006 +0000
1.3 @@ -0,0 +1,107 @@
1.4 +/*
1.5 + * The contents of this file are subject to the terms of the Common Development
1.6 + * and Distribution License (the License). You may not use this file except in
1.7 + * compliance with the License.
1.8 + *
1.9 + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
1.10 + * or http://www.netbeans.org/cddl.txt.
1.11 + *
1.12 + * When distributing Covered Code, include this CDDL Header Notice in each file
1.13 + * and include the License file at http://www.netbeans.org/cddl.txt.
1.14 + * If applicable, add the following below the CDDL Header, with the fields
1.15 + * enclosed by brackets [] replaced by your own identifying information:
1.16 + * "Portions Copyrighted [year] [name of copyright owner]"
1.17 + */
1.18 +
1.19 +
1.20 +package org.foo.fftview;
1.21 +
1.22 +import java.beans.PropertyChangeEvent;
1.23 +import java.beans.PropertyChangeListener;
1.24 +import javax.swing.Action;
1.25 +import javax.swing.JComponent;
1.26 +import javax.swing.JPanel;
1.27 +import org.foo.wavsupport.api.WavCookie;
1.28 +import org.foo.wavutils.FFTGraph;
1.29 +import org.foo.wavutils.WrappedAudioInputStream;
1.30 +import org.netbeans.core.spi.multiview.CloseOperationState;
1.31 +import org.netbeans.core.spi.multiview.MultiViewElement;
1.32 +import org.netbeans.core.spi.multiview.MultiViewElementCallback;
1.33 +import org.openide.awt.UndoRedo;
1.34 +import org.openide.loaders.DataObject;
1.35 +import org.openide.util.Lookup;
1.36 +
1.37 +/**
1.38 + *
1.39 + * @author runger
1.40 + */
1.41 +public class FFTComponent implements MultiViewElement {
1.42 +
1.43 + private DataObject dobj;
1.44 + private final FFTGraph graph = new FFTGraph();
1.45 +
1.46 + public FFTComponent(DataObject dobj)
1.47 + {
1.48 + super();
1.49 +
1.50 + this.dobj = dobj;
1.51 + final WavCookie c = (WavCookie)dobj.getCookie(WavCookie.class);
1.52 + assert(c != null);
1.53 +
1.54 + graph.createGraph(c.getAudioInputStream());
1.55 +
1.56 + c.addPropertyChangeListener(new PropertyChangeListener() {
1.57 + public void propertyChange(PropertyChangeEvent evt) {
1.58 + if (evt.getPropertyName().equals(WavCookie.PROP_WAVEFORM))
1.59 + {
1.60 + WrappedAudioInputStream wais = c.getAudioInputStream();
1.61 + if (wais == null)
1.62 + graph.clearGraph();
1.63 + else
1.64 + graph.createGraph(wais);
1.65 + }
1.66 + }
1.67 + });
1.68 + }
1.69 +
1.70 + public JComponent getVisualRepresentation() {
1.71 + return graph;
1.72 + }
1.73 +
1.74 + public JComponent getToolbarRepresentation() {
1.75 + return new JPanel();
1.76 + }
1.77 +
1.78 + public void setMultiViewCallback(MultiViewElementCallback multiViewElementCallback) {
1.79 + // do nothing (don't need the callback)
1.80 + }
1.81 +
1.82 + public CloseOperationState canCloseElement() {
1.83 + // The main wav component handles asking the user to save.
1.84 + // THIS component is OK whatever the outcome.
1.85 + return CloseOperationState.STATE_OK;
1.86 + }
1.87 +
1.88 + public void componentDeactivated() {}
1.89 + public void componentActivated() {}
1.90 + public void componentHidden() {}
1.91 + public void componentShowing() {}
1.92 + public void componentClosed() {}
1.93 + public void componentOpened() {}
1.94 +
1.95 + public Object writeReplace() {
1.96 + return null;
1.97 + }
1.98 +
1.99 + public Action[] getActions() {
1.100 + return new Action[0];
1.101 + }
1.102 +
1.103 + public Lookup getLookup() {
1.104 + return dobj.getNodeDelegate().getLookup();
1.105 + }
1.106 +
1.107 + public UndoRedo getUndoRedo() {
1.108 + return new UndoRedo.Manager();
1.109 + }
1.110 +}
2.1 --- a/platform/samples/AudioStation/fftview/src/org/foo/fftview/FFTViewDescriptor.java Thu Dec 07 17:34:00 2006 +0000
2.2 +++ b/platform/samples/AudioStation/fftview/src/org/foo/fftview/FFTViewDescriptor.java Thu Dec 07 17:39:56 2006 +0000
2.3 @@ -60,7 +60,7 @@
2.4 }
2.5
2.6 public MultiViewElement createElement() {
2.7 - return new FFTTopComponent(dobj);
2.8 + return new FFTComponent(dobj);
2.9 }
2.10
2.11 public void setWavDataObject(DataObject wav) {
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/platform/samples/AudioStation/wavsupport/src/org/foo/wavsupport/ui/WavComponent.java Thu Dec 07 17:39:56 2006 +0000
3.3 @@ -0,0 +1,166 @@
3.4 +/*
3.5 + * The contents of this file are subject to the terms of the Common Development
3.6 + * and Distribution License (the License). You may not use this file except in
3.7 + * compliance with the License.
3.8 + *
3.9 + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
3.10 + * or http://www.netbeans.org/cddl.txt.
3.11 + *
3.12 + * When distributing Covered Code, include this CDDL Header Notice in each file
3.13 + * and include the License file at http://www.netbeans.org/cddl.txt.
3.14 + * If applicable, add the following below the CDDL Header, with the fields
3.15 + * enclosed by brackets [] replaced by your own identifying information:
3.16 + * "Portions Copyrighted [year] [name of copyright owner]"
3.17 + */
3.18 +
3.19 +package org.foo.wavsupport.ui;
3.20 +
3.21 +import java.beans.PropertyVetoException;
3.22 +import java.io.IOException;
3.23 +import javax.swing.Action;
3.24 +import javax.swing.JComponent;
3.25 +import javax.swing.JPanel;
3.26 +import org.netbeans.core.spi.multiview.CloseOperationState;
3.27 +import org.netbeans.core.spi.multiview.MultiViewElement;
3.28 +import org.netbeans.core.spi.multiview.MultiViewElementCallback;
3.29 +import org.netbeans.core.spi.multiview.MultiViewFactory;
3.30 +import org.openide.ErrorManager;
3.31 +import org.openide.awt.UndoRedo;
3.32 +import org.openide.cookies.SaveCookie;
3.33 +import org.openide.loaders.DataObject;
3.34 +import org.openide.nodes.Node;
3.35 +import org.openide.util.HelpCtx;
3.36 +import org.openide.util.Lookup;
3.37 +import org.openide.util.actions.NodeAction;
3.38 +
3.39 +/**
3.40 + *
3.41 + * @author runger
3.42 + */
3.43 +public class WavComponent implements MultiViewElement {
3.44 +
3.45 + private static final CloseOperationState CLOSE_OPERATION_STATE = createCloseOperationState();
3.46 + private transient WavPanel wavPanel;
3.47 +
3.48 + public WavComponent(DataObject dobj)
3.49 + {
3.50 + super();
3.51 + wavPanel = new WavPanel(dobj);
3.52 + }
3.53 +
3.54 + public Action[] getActions() {
3.55 + return new Action[0];
3.56 + }
3.57 +
3.58 + public Lookup getLookup() {
3.59 + return wavPanel.getWavDataObject().getNodeDelegate().getLookup();
3.60 + }
3.61 +
3.62 + public UndoRedo getUndoRedo() {
3.63 + return new UndoRedo.Manager();
3.64 + }
3.65 +
3.66 + public JComponent getVisualRepresentation() {
3.67 + return wavPanel;
3.68 + }
3.69 +
3.70 + public JComponent getToolbarRepresentation() {
3.71 + // don't need any widgets on the toolbar
3.72 + return new JPanel();
3.73 + }
3.74 +
3.75 + public CloseOperationState canCloseElement() {
3.76 + if (wavPanel.getWavDataObject().isModified())
3.77 + {
3.78 + return CLOSE_OPERATION_STATE;
3.79 + }
3.80 + else
3.81 + {
3.82 + return CloseOperationState.STATE_OK;
3.83 + }
3.84 + }
3.85 +
3.86 + public void setMultiViewCallback(MultiViewElementCallback multiViewElementCallback) {
3.87 + // don't need this
3.88 + }
3.89 +
3.90 + // similar semantics as the equivalent methods in TopComponent
3.91 + public void componentDeactivated() {}
3.92 + public void componentActivated() {}
3.93 + public void componentHidden() {}
3.94 + public void componentShowing() {}
3.95 + public void componentClosed() {}
3.96 + public void componentOpened() {}
3.97 +
3.98 + public Object writeReplace() {
3.99 + return null;
3.100 + }
3.101 +
3.102 + private static CloseOperationState createCloseOperationState()
3.103 + {
3.104 + return MultiViewFactory.createUnsafeCloseState(
3.105 + "File Not Saved", new ProceedAction(), new DiscardAction());
3.106 + }
3.107 +
3.108 + private static class ProceedAction extends NodeAction
3.109 + {
3.110 + protected void performAction(Node[] node) {
3.111 + try
3.112 + {
3.113 + if (node != null && node.length > 0)
3.114 + {
3.115 + SaveCookie sc = (SaveCookie)node[0].getCookie(SaveCookie.class);
3.116 + sc.save();
3.117 + }
3.118 + }
3.119 + catch(IOException ex)
3.120 + {
3.121 + ErrorManager.getDefault().notify(ex);
3.122 + }
3.123 + }
3.124 +
3.125 + protected boolean enable(Node[] node) {
3.126 + return true;
3.127 + }
3.128 +
3.129 + public String getName() {
3.130 + return "Save";
3.131 + }
3.132 +
3.133 + public HelpCtx getHelpCtx() {
3.134 + return null;
3.135 + }
3.136 + }
3.137 +
3.138 + private static class DiscardAction extends NodeAction
3.139 + {
3.140 + protected void performAction(Node[] node) {
3.141 + if (node != null && node.length > 0)
3.142 + {
3.143 + DataObject dobj = (DataObject)node[0].getCookie(DataObject.class);
3.144 + try
3.145 + {
3.146 + // throw away what's in memory. The DataObject will
3.147 + // be recreated from disk.
3.148 + dobj.setValid(false);
3.149 + }
3.150 + catch (PropertyVetoException ex)
3.151 + {
3.152 + ErrorManager.getDefault().notify(ex);
3.153 + }
3.154 + }
3.155 + }
3.156 +
3.157 + protected boolean enable(Node[] node) {
3.158 + return true;
3.159 + }
3.160 +
3.161 + public String getName() {
3.162 + return "Discard";
3.163 + }
3.164 +
3.165 + public HelpCtx getHelpCtx() {
3.166 + return null;
3.167 + }
3.168 + }
3.169 +}
4.1 --- a/platform/samples/AudioStation/wavsupport/src/org/foo/wavsupport/ui/WavPanelMultiViewDescriptor.java Thu Dec 07 17:34:00 2006 +0000
4.2 +++ b/platform/samples/AudioStation/wavsupport/src/org/foo/wavsupport/ui/WavPanelMultiViewDescriptor.java Thu Dec 07 17:39:56 2006 +0000
4.3 @@ -58,7 +58,7 @@
4.4 }
4.5
4.6 public MultiViewElement createElement() {
4.7 - return new WavTopComponent(dobj);
4.8 + return new WavComponent(dobj);
4.9 }
4.10
4.11 public void setWavDataObject(DataObject wav) {