📄 svgprint.java
字号:
/* * Created on 22 déc. 2004============================================= GNU LESSER GENERAL PUBLIC LICENSE Version 2.1 =============================================GLIPS Graffiti Editor, a SVG EditorCopyright (C) 2003 Jordi SUC, Philippe Gil, SARL ITRISThis library is free software; you can redistribute it and/ormodify it under the terms of the GNU Lesser General PublicLicense as published by the Free Software Foundation; eitherversion 2.1 of the License, or (at your option) any later version.This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser General Public License for more details.You should have received a copy of the GNU Lesser General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USAContact : jordi.suc@itris.fr; philippe.gil@itris.fr ============================================= */package fr.itris.glips.svgeditor.svgfile;import fr.itris.glips.svgeditor.*;import fr.itris.glips.svgeditor.canvas.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.event.*;import java.awt.geom.*;import java.util.*;import java.awt.*;import java.awt.event.*;import org.w3c.dom.*;import org.apache.batik.transcoder.*;import org.apache.batik.transcoder.print.*;import fr.itris.glips.svgeditor.resources.*;/** * @author Jordi SUC * the class that creates the static menu item exit in the menu bar */public class SVGPrint extends SVGModuleAdapter{ /** * the ids of the module */ final private String idprint="Print"; /** * the labels */ private String labelprint="", messageprinterror="", labelerror=""; /** * the editor */ private SVGEditor editor; /** * the menu item that will be added to the menubar */ private JMenuItem print; /** * the dialog box used to choose the parameters for the print */ private PrintDialog printDialog=null; /** * the resource bundle */ private ResourceBundle bundle=null; /** * the constructor of the class * @param editor the editor */ public SVGPrint(SVGEditor editor){ this.editor=editor; //gets the labels from the resources bundle=SVGEditor.getBundle(); if(bundle!=null){ try{ labelprint=bundle.getString("labelprint"); messageprinterror=bundle.getString("messageprinterror"); labelerror=bundle.getString("labelerror"); }catch (Exception ex){} } //a listener that listens to the changes of the SVGFrames final ActionListener svgframeListener=new ActionListener(){ public void actionPerformed(ActionEvent e) { final SVGFrame frame=getSVGEditor().getFrameManager().getCurrentFrame(); if(frame!=null){ //enables the menuitem print.setEnabled(true); }else{ //disables the menuitem print.setEnabled(false); } } }; //adds the SVGFrame change listener editor.getFrameManager().addSVGFrameChangedListener(svgframeListener); //getting the icons ImageIcon printIcon=SVGResource.getIcon("Print", false), dprintIcon=SVGResource.getIcon("Print", true); //handling the menu item print=new JMenuItem(labelprint, printIcon); print.setDisabledIcon(dprintIcon); print.setAccelerator(KeyStroke.getKeyStroke("ctrl P")); print.setEnabled(false); //adds a listener to the menu item print.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ SVGFrame frame=getSVGEditor().getFrameManager().getCurrentFrame(); if(frame!=null){ print(frame); } } } ); //creating the print dialog box if(getSVGEditor().getParent() instanceof JFrame){ printDialog=new PrintDialog((JFrame)getSVGEditor().getParent()); }else{ printDialog=new PrintDialog(new JFrame("")); } } /** * @return the editor */ public SVGEditor getSVGEditor(){ return editor; } /** * @return a map associating a menu item id to its menu item object */ public Hashtable getMenuItems(){ Hashtable menuItems=new Hashtable(); menuItems.put(idprint, print); return menuItems; } /** * @return a map associating a tool item id to its tool item object */ public Hashtable getToolItems(){ return null; } /** * Returns the collection of the popup items * @return the collection of the popup items */ public Collection getPopupItems(){ return null; } /** * layout some elements in the module */ public void initialize(){ } /** * @see fr.itris.glips.svgeditor.SVGModuleAdapter#cancelActions() */ public void cancelActions() { } /** * prints the document corresponding to the frame to the given destination file * @param frame a frame */ protected void print(SVGFrame frame){ if(frame!=null){ Document clonedDocument=(Document)frame.getScrollPane().getSVGCanvas().getDocument().cloneNode(true); //creating the transcoder input and output TranscoderInput input=new TranscoderInput(clonedDocument); TranscoderOutput output=new TranscoderOutput(); //the transcoder PrintTranscoder transcoder=new PrintTranscoder(); transcoder.addTranscodingHint(PrintTranscoder.KEY_SHOW_PRINTER_DIALOG, new Boolean(true)); //transcoder.addTranscodingHint(PrintTranscoder.KEY_SHOW_PAGE_DIALOG, new Boolean(true)); try{ transcoder.transcode(input, output); transcoder.print(); }catch (Exception ex){ JOptionPane.showMessageDialog(getSVGEditor().getParent(), messageprinterror, labelerror, JOptionPane.WARNING_MESSAGE); } } } /** * the class of the dialogs used to choose the parameters of the print action for each kind of print format * * @author Jordi SUC */ protected class PrintDialog extends JDialog{ /** * the constant describing a ok action */ public static final int OK_ACTION=0; /** * the constant describing a cancel action */ public static final int CANCEL_ACTION=1; /** * the labels for the prints */ private String labelJpgPrint="", labelPngPrint="", labelTiffPrint="", okLabel="", cancelLabel="", jpgQualityLabel="", pngBitDepthsLabel="", tiffForceTransparentWhite="", pngBestQualityLabel="", printSizeLabel="", jpgPropertiesLabel="", pngPropertiesLabel="", tiffPropertiesLabel="", heightLabel="", widthLabel=""; /** * the panel containing the item to set the size of the printed image */ private JPanel sizeChooserPanel=new JPanel(); /** * the textfields used to specify the size of the printed image */ private final JTextField txtw=new JTextField(), txth=new JTextField(); /** * the jpeg quality */ private float jpgQuality=1.0f; /** * the panel containing the widgets to specify the parameters for the jpg print */ private JPanel jpgPanel=new JPanel(); /** * the bit depths for a png image */ private int pngBitDepths=9; /** * the dimension of the printed image */ private double printWidth=0, printHeight=0; /** * the panel containing the widgets to specify the parameters for the png print */ private JPanel pngPanel=new JPanel(); /** * controls whether the encoder should force the image's fully transparent pixels to be fully transparent white instead of fully transparent black. */ private boolean forceTransparentWhite=false; /** * the panel containing the widgets to specify the parameters for the tiff print */ private JPanel tiffPanel=new JPanel(); /** * the buttons panel */ private JPanel buttonsPanel=new JPanel(); /** * the current action */ private int currentActionState=CANCEL_ACTION; /** * the constructor of the class */ protected PrintDialog(JFrame parent){ super(parent, labelprint, true); if(bundle!=null){ try{ labelJpgPrint=bundle.getString("labeljpgprint"); labelPngPrint=bundle.getString("labelpngprint"); labelTiffPrint=bundle.getString("labeltiffprint"); okLabel=bundle.getString("labelok"); cancelLabel=bundle.getString("labelcancel"); jpgQualityLabel=bundle.getString("labeljpegquality"); pngBitDepthsLabel=bundle.getString("labelpngbitdepths"); tiffForceTransparentWhite=bundle.getString("labeltiffforcetransparentwhite"); pngBestQualityLabel=bundle.getString("labelpngbestquality"); printSizeLabel=bundle.getString("labelprintsize"); jpgPropertiesLabel=bundle.getString("labeljpgproperties"); pngPropertiesLabel=bundle.getString("labelpngproperties"); tiffPropertiesLabel=bundle.getString("labeltiffproperties"); widthLabel=bundle.getString("labelwidth"); heightLabel=bundle.getString("labelheight"); }catch (Exception ex){}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -