001    /**
002     * Created by IntelliJ IDEA.
003     * User: Wei Wang
004     * Date: Apr 25, 2003
005     * Time: 12:37:08 AM
006     */
007    
008    package EVolve.util.phasedetectors;
009    
010    import java.awt.Cursor;
011    
012    import javax.swing.JScrollPane;
013    
014    import EVolve.Scene;
015    import EVolve.util.HelperFuncs;
016    import EVolve.visualization.AxesPanel;
017    import EVolve.visualization.XYViz.XYVisualization;
018    
019    public class PhaseOperation {
020        private PhaseClipboard phaseClipboard;
021    
022        public PhaseOperation() {
023            phaseClipboard = new PhaseClipboard();
024        }
025    
026        public void add() {
027            XYVisualization workingViz = HelperFuncs.getActiveXYViz();
028    
029            if (workingViz == null) return;
030    
031            workingViz.freeze(true);
032            AxesPanel canvas = (AxesPanel)((JScrollPane)workingViz.getPanel()).getViewport().getView();
033            canvas.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
034            new PhaseAddRemover().beginAdd();
035        }
036    
037        public void remove() {
038            XYVisualization workingViz = HelperFuncs.getActiveXYViz();
039    
040            if (workingViz == null) return;
041    
042            workingViz.freeze(true);
043            AxesPanel canvas = (AxesPanel)((JScrollPane)workingViz.getPanel()).getViewport().getView();
044            canvas.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
045            new PhaseAddRemover().beginRemove();
046        }
047    
048        public void copyPhase() {
049            phaseClipboard.copyPhase();
050        }
051    
052        public void pastePhase() {
053            phaseClipboard.pastePhase();
054        }
055    
056        public boolean clipboardIsEmpty() {
057            return phaseClipboard.isEmpty();
058        }
059    
060        public void triggerPhases(int noiseTolerance, float threshold, boolean append) {
061            XYVisualization visual = HelperFuncs.getActiveXYViz();
062    
063            if ((visual == null)&&(visual.getPhaseDetector() == null)) {
064                Scene.showErrorMessage("No phase detector available.");
065                return;
066            }
067    
068            visual.getPhaseDetector().triggerPhases(noiseTolerance, threshold, append);
069        }
070    
071        public void entitySetPhases(int noiseTolerance, float threshold, boolean append) {
072            XYVisualization visual = HelperFuncs.getActiveXYViz();
073    
074            if ((visual == null)&&(visual.getPhaseDetector() == null)) {
075                Scene.showErrorMessage("No phase detector available.");
076                return;
077            }
078    
079            visual.getPhaseDetector().entitySetPhases(noiseTolerance, threshold, append);
080        }
081    
082        public void undo() {
083            XYVisualization visual = HelperFuncs.getActiveXYViz();
084    
085            if ((visual == null)||(visual.getPhaseDetector() == null)) {
086                Scene.showErrorMessage("No undoable actions available.");
087                return;
088            }
089    
090            visual.getPhaseDetector().undo();
091        }
092    
093        public void redo() {
094            XYVisualization visual = HelperFuncs.getActiveXYViz();
095    
096            if ((visual == null)||(visual.getPhaseDetector() == null)) {
097                Scene.showErrorMessage("No redoable actions available.");
098                return;
099            }
100    
101            visual.getPhaseDetector().redo();
102        }
103    
104        public boolean undoable() {
105            XYVisualization visual = HelperFuncs.getActiveXYViz();
106    
107            if ((visual == null)||(visual.getPhaseDetector() == null)) {
108                return false;
109            }
110    
111            return visual.getPhaseDetector().undoable();
112        }
113    
114        public boolean redoable() {
115            XYVisualization visual = HelperFuncs.getActiveXYViz();
116    
117            if ((visual == null)||(visual.getPhaseDetector() == null)) {
118                return false;
119            }
120    
121            return visual.getPhaseDetector().redoable();
122        }
123    }