001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: /*
042: * SaveAnimationAsImage.java
043: *
044: * Created on November 22, 2005, 12:04 PM
045: *
046: * To change this template, choose Tools | Template Manager
047: * and open the template in the editor.
048: */
049:
050: package org.netbeans.modules.mobility.svgcore.export;
051:
052: import java.awt.Dialog;
053: import java.awt.Dimension;
054: import java.awt.event.ComponentAdapter;
055: import java.awt.event.ComponentEvent;
056: import org.netbeans.modules.mobility.svgcore.SVGDataObject;
057: import org.openide.DialogDescriptor;
058: import org.openide.DialogDisplayer;
059: import org.openide.nodes.Node;
060: import org.openide.util.Exceptions;
061: import org.openide.util.HelpCtx;
062: import org.openide.util.NbBundle;
063: import org.openide.util.actions.CookieAction;
064:
065: /**
066: *
067: * @author Pavel Benes, suchys
068: */
069: public class SaveAnimationAsImageAction extends CookieAction {
070:
071: /** Creates a new instance of SaveAnimationAsImage */
072: public SaveAnimationAsImageAction() {
073: }
074:
075: protected void initialize() {
076: super .initialize();
077: // see org.openide.util.actions.SystemAction.iconResource() javadoc for more details
078: putValue("noIconInMenu", Boolean.TRUE); //NOI18N
079: }
080:
081: public static void setDialogMinimumSize(final Dialog dlg) {
082: dlg.pack();
083: dlg.setSize(dlg.getPreferredSize());
084:
085: dlg.addComponentListener(new ComponentAdapter() {
086: public void componentResized(ComponentEvent e) {
087: int w = dlg.getWidth();
088: int h = dlg.getHeight();
089: final Dimension minSize = dlg.getPreferredSize();
090:
091: int _w = Math.max(w, minSize.width);
092: int _h = Math.max(h, minSize.height);
093:
094: if (w != _w || h != _h) {
095: dlg.setSize(new Dimension(_w, _h));
096: }
097: }
098: });
099: }
100:
101: protected void performAction(Node[] n) {
102: SVGDataObject doj = (SVGDataObject) n[0].getLookup().lookup(
103: SVGDataObject.class);
104: if (doj != null) {
105: try {
106: SVGAnimationRasterizerPanel panel = new SVGAnimationRasterizerPanel(
107: doj);
108: DialogDescriptor dd = new DialogDescriptor(panel,
109: NbBundle.getMessage(
110: SaveAnimationAsImageAction.class,
111: "TITLE_AnimationExport"));
112:
113: Dialog dlg = DialogDisplayer.getDefault().createDialog(
114: dd);
115: setDialogMinimumSize(dlg);
116: dlg.setVisible(true);
117:
118: if (dd.getValue() == DialogDescriptor.OK_OPTION) {
119: AnimationRasterizer.export(doj, panel);
120: }
121: } catch (Exception e) {
122: Exceptions.printStackTrace(e);
123: }
124: }
125: }
126:
127: public String getName() {
128: return NbBundle.getMessage(SaveAnimationAsImageAction.class,
129: "LBL_ExportAnimationAction"); //NOI18N
130: }
131:
132: public HelpCtx getHelpCtx() {
133: return HelpCtx.DEFAULT_HELP;
134: }
135:
136: protected int mode() {
137: return CookieAction.MODE_ONE;
138: }
139:
140: protected Class[] cookieClasses() {
141: return new Class[] { SVGDataObject.class };
142: }
143:
144: protected boolean asynchronous() {
145: return false;
146: }
147: }
|