⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svgexport.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        pdfMenuItem.addActionListener(listener);                //creating the export dialog boxes        if(getSVGEditor().getParent() instanceof JFrame){        	            jpgExportDialog=new JPGExportDialog(getSVGEditor(), (JFrame)getSVGEditor().getParent());            pngExportDialog=new PNGExportDialog(getSVGEditor(), (JFrame)getSVGEditor().getParent());            bmpExportDialog=new BMPExportDialog(getSVGEditor(), (JFrame)getSVGEditor().getParent());            tiffExportDialog=new TIFFExportDialog(getSVGEditor(), (JFrame)getSVGEditor().getParent());            pdfExportDialog=new PDFExportDialog(getSVGEditor(), (JFrame)getSVGEditor().getParent());        	        }else{        	            jpgExportDialog=new JPGExportDialog(getSVGEditor(), new JFrame(""));            pngExportDialog=new PNGExportDialog(getSVGEditor(), new JFrame(""));            bmpExportDialog=new BMPExportDialog(getSVGEditor(), new JFrame(""));            tiffExportDialog=new TIFFExportDialog(getSVGEditor(), new JFrame(""));            pdfExportDialog=new PDFExportDialog(getSVGEditor(), 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(idexport, export);                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() {}        /**     * returns the message warning that there is an error in the format     * @param exportType the type of the export     * @return the message warning that there is an error in the format     */    protected String getMessageFormatExportError(int exportType) {                String formatErrorMessage="";                switch(exportType) {                case JPG_FORMAT :                        formatErrorMessage=messageformaterrorexportjpg;            break;                    case PNG_FORMAT :                        formatErrorMessage=messageformaterrorexportpng;            break;                    case BMP_FORMAT :                        formatErrorMessage=messageformaterrorexportbmp;            break;                    case TIFF_FORMAT :                        formatErrorMessage=messageformaterrorexporttiff;            break;                    case PDF_FORMAT :                        formatErrorMessage=messageformaterrorexportpdf;            break;        }                return formatErrorMessage;    }        /**     * exports the svg file represented by the given frame     * @param frame a frame     * @param exportType the type of the export action     */    protected void exportAction(final SVGFrame frame, final int exportType){                SwingUtilities.invokeLater(new Runnable() {            public void run() {                                if(frame!=null){                                        //opens a file chooser                    JFileChooser fileChooser=new JFileChooser();                                        //getting the title of the file chooser                    String fileChooserTitle="";                                        //getting the extension                    String extension="";                                        switch(exportType) {                                        case JPG_FORMAT :                                                extension=".jpg";                        fileChooserTitle=jpgExportDialog.getExportDialogTitle();                        break;                                            case PNG_FORMAT :                                                extension=".png";                        fileChooserTitle=pngExportDialog.getExportDialogTitle();                        break;                                            case BMP_FORMAT :                                                extension=".bmp";                        fileChooserTitle=bmpExportDialog.getExportDialogTitle();                        break;                                            case TIFF_FORMAT :                                                extension=".tiff";                        fileChooserTitle=tiffExportDialog.getExportDialogTitle();                        break;                                            case PDF_FORMAT :                                                extension=".pdf";                        fileChooserTitle=pdfExportDialog.getExportDialogTitle();                        break;                    }                                        fileChooser.setDialogTitle(fileChooserTitle);                                        if(getSVGEditor().getResource().getCurrentDirectory()!=null){                                                fileChooser.setCurrentDirectory(getSVGEditor().getResource().getCurrentDirectory());                    }                                        SVGExportFileFilter fileFilter=new SVGExportFileFilter(bundle, exportType);                    fileChooser.setFileFilter(fileFilter);                    fileChooser.setMultiSelectionEnabled(false);                                         File selectedFile=null;                    int returnVal=0, rVal=-1;                                        do{                                                returnVal=fileChooser.showSaveDialog(getSVGEditor().getParent());                                                if(returnVal==JFileChooser.APPROVE_OPTION) {                                                        getSVGEditor().getResource().setCurrentDirectory(fileChooser.getCurrentDirectory());                            selectedFile=fileChooser.getSelectedFile();                                                        if(selectedFile!=null && fileFilter.acceptFile(selectedFile)){                                                                //checking if the selected file already exists, if the entered file has not extension, it is added                                try {                                    String path=selectedFile.toURI().toString();                                                                        if(! path.endsWith(extension)) {                                                                                path+=extension;                                    }                                                                        selectedFile=new File(new URI(path));                                                                    }catch (Exception ex) {}                                                                if(selectedFile.exists()){                                                                        //if the file exist prompts a dialog to confirm that the file will be erased                                    rVal=JOptionPane.showConfirmDialog(                                            getSVGEditor().getParent(),                                             erasefilemessage,                                             erasefiletitle,                                             JOptionPane.YES_NO_OPTION);                                                                        //if the file should be erased                                    if(rVal==JOptionPane.YES_OPTION){                                                                                export(frame, selectedFile.toURI().toString(), true, exportType);                                        break;                                    }                                                                    }else{                                                                        //if the file does not already exists                                    export(frame, selectedFile.toURI().toString(), false, exportType);                                    break;                                }                                                            }else if(selectedFile!=null){                                                                JOptionPane.showMessageDialog(getSVGEditor().getParent(), getMessageFormatExportError(exportType),                                         labelerror,JOptionPane.ERROR_MESSAGE);                                                            }else{                                                                JOptionPane.showMessageDialog(getSVGEditor().getParent(), messageexporterror, labelerror,                                         JOptionPane.ERROR_MESSAGE);                                break;                            }                                                    }else{                                                        break;                        }                                            }while(selectedFile!=null);                }            }        });    }        /**     * exports the document corresponding to the frame to the given destination file     * @param frame a frame     * @param path the destination file path     * @param alreadyExist whether the destination file already exists     * @param exportType the type of the export action     */    protected void export(SVGFrame frame, String path, boolean alreadyExist, int exportType){                //whether the export has been done        boolean hasExported=false;                if(frame!=null && path!=null && ! path.equals("")){            //exporting into the specified format            int res=-1;                        //getting the title of the progress bar            String progressBarDialogTitle="";                        //the extension            String extension="";                        switch(exportType) {                        case JPG_FORMAT :                                extension=".jpg";                                progressBarDialogTitle=jpgExportDialog.getExportDialogTitle();                break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -