/*
* Copyright Jan 15, 2010 John T. Langton
* email: jlangton at visitrend dot com
* www.visitrend.com
*
* License: GPLv2 or (at your option) any later GPL version
*
* This file is part of NDVis.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* There should be a copy of the GNU General Public License applied to
* NDVis in the file "NDVis-license" in the folder "license". If not, see
* <http://www.gnu.org/licenses/> or write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package com.visitrend.ndvis.optimize;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import com.visitrend.ndvis.app.NDVis;
import com.visitrend.ndvis.colormapper.ColorMapper;
import com.visitrend.ndvis.colormapper.util.ColorEngine;
import com.visitrend.ndvis.gui.api.ProgressMonitor;
import com.visitrend.ndvis.gui.api.ProgressMonitorINF;
import com.visitrend.ndvis.gui.spi.DataVisualization;
import com.visitrend.ndvis.thread.MonitoringINF;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.visitrend.ndvis.parameters.Parameters;
/**
*
* @author John T. Langton - jlangton at visitrend dot com
*
*/
@ActionID(category = "NDVisMainActions", id = "com.visitrend.ndvis.actions.OptimizeAction")
@ActionRegistration(displayName = "Optimize")
@ActionReference(path = "Menu/Tools", position = 5)
public class OptimizeAction extends AbstractAction implements MonitoringINF {
private NDVis view;
OptimizerWorker ow;
public OptimizeAction() {
super("Optimize");
this.view = NDVis.getDefault();
}
public void actionPerformed(ActionEvent arg0) {
view.getActiveDataVisualization().getImagePane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
ow = new OptimizerWorker(view);
ProgressMonitorINF mp = new ProgressMonitor(this, ow);
}
public void done() {
view.getActiveDataVisualization().getImagePane().setCursor(null);
if (ow.isCanceled()) {
// then do nothing
return;
} else {
short[] optimal = ow.getOptimal();
DataVisualization dataVis = view.getActiveDataVisualization();
dataVis.getLookup().lookup(Parameters.class).setParamOrder(optimal);
/*
* Make the colorEngine color the current image. The color engine
* will update its order from Parameters, which has been set
* directly above, and then color the image accordingly.
*/
ColorEngine e = dataVis.getLookup().lookup(ColorMapper.class).getEngine();
e.colorImage(dataVis);
}
view.makeActiveVisualizationVisible();
}
}