/*
* 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.image;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import com.visitrend.ndvis.app.NDVis;
import com.visitrend.ndvis.event.api.DataVisualizationChangedEvent;
import com.visitrend.ndvis.event.api.DataVisualizationListener;
import com.visitrend.ndvis.gui.spi.DataVisualization;
import javax.swing.border.EmptyBorder;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.windows.Mode;
import org.openide.windows.WindowManager;
/**
*
* @author John T. Langton - jlangton at visitrend dot com
*
*/
@ActionID(category = "NDVisMainActions", id = "com.visitrend.ndvis.actions.AddNewImageAction")
@ActionRegistration(displayName = "Add New Image")//TODO:Bug 196933, iconBase = "toolbarButtonGraphics/general/New16.gif")
@ActionReferences({
@ActionReference(path = "Menu/File"),
@ActionReference(path = "Toolbars/File")
})
public class AddNewImageAction extends AbstractAction {
private NDVis view;
public AddNewImageAction() {
super("Add New Image");
this.view = NDVis.getDefault();
}
public void actionPerformed(ActionEvent arg0) {
addNewImage();
}
public void addNewImage() {
final DataVisualization imp = new ImagePanel();
imp.getImagePane().setBorder(new EmptyBorder(0, 0, 0, 0));
imp.addImagePanelListener(new DataVisualizationListener() {
@Override
public void originalVisualizationChanged(DataVisualizationChangedEvent event) {
DataVisualization dataVis = (DataVisualization)event.getSource();
dataVis.fireSaveStateChange(true);
dataVis.getTopComponent().requestActive();
}
});
WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
@Override
public void run() {
Mode mode = WindowManager.getDefault().findMode("editor");
if (mode != null) {
mode.dockInto(imp.getTopComponent());
imp.getTopComponent().open();
imp.getTopComponent().requestActive();
}
}
});
// open main window so added image is visible
// Dimension dim = WindowManager.getDefault().getMainWindow().getSize();
// int width = dim.width;
// int height = dim.height;
// but don't change size if user has already made window taller
// if (height < width) {
// setSize(new Dimension(width, width));
// }
view.fireDataVisualizationAdded(imp);
}
}