List of usage examples for javax.swing JEditorPane getClientProperty
public final Object getClientProperty(Object key)
From source file:org.docx4all.ui.menu.FileMenu.java
/** * Saves editor documents to a file./*from w w w .ja v a2 s . c om*/ * * Internal frame may have two editors for presenting two different views * to user namely editor view and source view. WordMLTextPane is used for * editor view and JEditorPane for source view. * The contents of these two editors are synchronized when user switches * from one view to the other. Therefore, there will be ONLY ONE editor * that is dirty and has to be saved by this method. * * @param iframe * @param saveAsFilePath * @param callerActionName * @return */ public boolean save(JInternalFrame iframe, String saveAsFilePath, String callerActionName) { boolean success = true; if (saveAsFilePath == null) { saveAsFilePath = (String) iframe.getClientProperty(WordMLDocument.FILE_PATH_PROPERTY); } if (log.isDebugEnabled()) { log.debug("save(): filePath=" + VFSUtils.getFriendlyName(saveAsFilePath)); } WordMLTextPane editorView = SwingUtil.getWordMLTextPane(iframe); JEditorPane sourceView = SwingUtil.getSourceEditor(iframe); if (sourceView != null && !((Boolean) sourceView.getClientProperty(Constants.LOCAL_VIEWS_SYNCHRONIZED_FLAG)) .booleanValue()) { //signifies that Source View is not synchronised with Editor View yet. //Therefore, it is dirty and has to be saved. if (editorView != null && editorView.getWordMLEditorKit().getPlutextClient() != null) { //Document has to be saved from editor view //by committing local edits success = false; } else { EditorKit kit = sourceView.getEditorKit(); Document doc = sourceView.getDocument(); WordprocessingMLPackage wmlPackage = (WordprocessingMLPackage) doc .getProperty(WordMLDocument.WML_PACKAGE_PROPERTY); DocUtil.write(kit, doc, wmlPackage); success = save(wmlPackage, saveAsFilePath, callerActionName); if (success) { if (saveAsFilePath.endsWith(Constants.DOCX_STRING) || saveAsFilePath.endsWith(Constants.FLAT_OPC_STRING)) { doc.putProperty(WordMLDocument.FILE_PATH_PROPERTY, saveAsFilePath); iframe.putClientProperty(WordMLDocument.FILE_PATH_PROPERTY, saveAsFilePath); } } } return success; } sourceView = null; if (editorView == null) { ;//pass } else if (editorView.getWordMLEditorKit().getPlutextClient() != null) { if (saveAsFilePath.equals(editorView.getDocument().getProperty(WordMLDocument.FILE_PATH_PROPERTY))) { success = commitLocalChanges(editorView, callerActionName); } else { //TODO: Enable saving Plutext document as a new file. WordMLEditor wmlEditor = WordMLEditor.getInstance(WordMLEditor.class); ResourceMap rm = wmlEditor.getContext().getResourceMap(getClass()); String title = rm.getString(callerActionName + ".Action.text"); StringBuilder message = new StringBuilder(); message.append("File "); message.append(saveAsFilePath); message.append(Constants.NEWLINE); message.append(rm.getString(callerActionName + ".Action.wrong.fileName.infoMessage")); wmlEditor.showMessageDialog(title, message.toString(), JOptionPane.INFORMATION_MESSAGE); success = false; } } else { WordMLEditorKit kit = (WordMLEditorKit) editorView.getEditorKit(); kit.saveCaretText(); Document doc = editorView.getDocument(); DocumentElement elem = (DocumentElement) doc.getDefaultRootElement(); DocumentML rootML = (DocumentML) elem.getElementML(); //Do not include the last paragraph when saving. //After saving we put it back. elem = (DocumentElement) elem.getElement(elem.getElementCount() - 1); ElementML paraML = elem.getElementML(); ElementML bodyML = paraML.getParent(); paraML.delete(); success = save(rootML.getWordprocessingMLPackage(), saveAsFilePath, callerActionName); //Remember to put 'paraML' as last paragraph bodyML.addChild(paraML); if (success) { if (saveAsFilePath.endsWith(Constants.DOCX_STRING)) { doc.putProperty(WordMLDocument.FILE_PATH_PROPERTY, saveAsFilePath); iframe.putClientProperty(WordMLDocument.FILE_PATH_PROPERTY, saveAsFilePath); } } } return success; }
From source file:org.docx4all.ui.menu.FileMenu.java
public boolean export(JInternalFrame iframe, String saveAsFilePath, String callerActionName) { log.debug("export(): filePath=" + VFSUtils.getFriendlyName(saveAsFilePath)); WordprocessingMLPackage srcPackage = null; WordMLTextPane editorView = SwingUtil.getWordMLTextPane(iframe); JEditorPane sourceView = SwingUtil.getSourceEditor(iframe); if (sourceView != null && !((Boolean) sourceView.getClientProperty(Constants.LOCAL_VIEWS_SYNCHRONIZED_FLAG)) .booleanValue()) {/*from ww w. ja v a 2 s . c o m*/ //signifies that Source View is not synchronised with Editor View yet. //Therefore, export from Source View. EditorKit kit = sourceView.getEditorKit(); Document doc = sourceView.getDocument(); srcPackage = DocUtil.write(kit, doc, null); editorView = null; } sourceView = null; if (editorView == null) { ;//pass } else { WordMLDocument doc = (WordMLDocument) editorView.getDocument(); DocumentElement root = (DocumentElement) doc.getDefaultRootElement(); DocumentML docML = (DocumentML) root.getElementML(); srcPackage = docML.getWordprocessingMLPackage(); } boolean success = save(XmlUtil.export(srcPackage), saveAsFilePath, callerActionName); log.debug("export(): success=" + success + " filePath=" + VFSUtils.getFriendlyName(saveAsFilePath)); return success; }