use of org.freeplane.core.ui.ExampleFileFilter in project freeplane by freeplane.
the class ExportDialog method export.
/**
* A function to call again and again in order to export the same XML source file.
* @see #export(Component)
*/
/**
* A function to call again and again in order to export the same XML source file.
* @param parentframe a parent component for the dialogs to appear (can be null).
* @param streamSource
*/
void export(final Component parentframe, final MapModel map) {
final ExportController exportEngineRegistry = ExportController.getContoller();
if (exportEngineRegistry.getFilterMap().isEmpty()) {
JOptionPane.showMessageDialog(parentframe, TextUtils.getText("xslt_export_not_possible"));
return;
}
// Finish to setup the File Chooser...
// And then use it
final String absolutePathWithoutExtension;
final File xmlSourceFile = map.getFile();
if (xmlSourceFile != null) {
absolutePathWithoutExtension = FileUtils.removeExtension(xmlSourceFile.getAbsolutePath());
} else {
absolutePathWithoutExtension = null;
}
final PropertyChangeListener filterChangeListener = new PropertyChangeListener() {
private final File selectedFile = absolutePathWithoutExtension == null ? null : new File(absolutePathWithoutExtension);
public void propertyChange(final PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) {
final FileFilter filter = fileChooser.getFileFilter();
if (!(filter instanceof ExampleFileFilter)) {
return;
}
final File acceptableFile = getAcceptableFile(selectedFile, (ExampleFileFilter) filter);
EventQueue.invokeLater(new Runnable() {
public void run() {
fileChooser.setSelectedFile(acceptableFile);
}
});
return;
}
if (selectedFile != null && evt.getPropertyName().equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) {
final FileFilter filter = fileChooser.getFileFilter();
if (!(filter instanceof ExampleFileFilter)) {
return;
}
final File acceptableFile = getAcceptableFile(selectedFile, (ExampleFileFilter) filter);
final File currentDirectory = fileChooser.getCurrentDirectory();
if (currentDirectory != null) {
final File file = new File(currentDirectory, acceptableFile.getName());
fileChooser.setSelectedFile(file);
} else
fileChooser.setSelectedFile(acceptableFile);
return;
}
}
};
filterChangeListener.propertyChange(new PropertyChangeEvent(fileChooser, JFileChooser.FILE_FILTER_CHANGED_PROPERTY, null, fileChooser.getFileFilter()));
try {
fileChooser.addPropertyChangeListener(filterChangeListener);
final int returnVal = fileChooser.showSaveDialog(parentframe);
final FileFilter currentfileFilter = fileChooser.getFileFilter();
final String lastFileFilterDescription = currentfileFilter.getDescription();
if (currentfileFilter instanceof ExampleFileFilter)
ResourceController.getResourceController().setProperty(LAST_CHOOSEN_EXPORT_FILE_FILTER, lastFileFilterDescription);
if (returnVal == JFileChooser.APPROVE_OPTION) {
// description as key for the map to get the corresponding XSLT file
if (!(currentfileFilter instanceof ExampleFileFilter)) {
UITools.errorMessage(TextUtils.getText("invalid_export_file"));
return;
}
final ExampleFileFilter fileFilter = (ExampleFileFilter) currentfileFilter;
final File selectedFile = getAcceptableFile(fileChooser.getSelectedFile(), fileFilter);
if (selectedFile == null) {
return;
}
if (selectedFile.isDirectory()) {
return;
}
if (selectedFile.exists()) {
final String overwriteText = MessageFormat.format(TextUtils.getText("file_already_exists"), new Object[] { selectedFile.toString() });
final int overwriteMap = JOptionPane.showConfirmDialog(UITools.getCurrentRootComponent(), overwriteText, overwriteText, JOptionPane.YES_NO_OPTION);
if (overwriteMap != JOptionPane.YES_OPTION) {
return;
}
}
final IExportEngine exportEngine = exportEngineRegistry.getFilterMap().get(fileFilter);
exportEngine.export(map, selectedFile);
}
} finally {
fileChooser.removePropertyChangeListener(filterChangeListener);
}
}
use of org.freeplane.core.ui.ExampleFileFilter in project freeplane by freeplane.
the class ImportMindmanagerFiles method actionPerformed.
public void actionPerformed(final ActionEvent e) {
final String type = "mmap";
final Component component = Controller.getCurrentController().getViewController().getCurrentRootComponent();
final JFileChooser chooser = new JFileChooser();
final ExampleFileFilter filter = new ExampleFileFilter(type, null);
chooser.setFileFilter(filter);
chooser.setAcceptAllFileFilterUsed(true);
final File mmFile = Controller.getCurrentController().getMap().getFile();
if (mmFile != null && mmFile.getParentFile() != null) {
chooser.setSelectedFile(mmFile.getParentFile());
}
final int returnVal = chooser.showOpenDialog(component);
if (returnVal != JFileChooser.APPROVE_OPTION) {
return;
}
final File chosenFile = chooser.getSelectedFile();
importMindmanagerFile(chosenFile);
}
use of org.freeplane.core.ui.ExampleFileFilter in project freeplane by freeplane.
the class MTextController method setImageByFileChooser.
public void setImageByFileChooser() {
boolean picturesAmongSelecteds = false;
final ModeController modeController = Controller.getCurrentModeController();
for (final NodeModel node : modeController.getMapController().getSelectedNodes()) {
final URI link = NodeLinks.getLink(node);
if (link != null) {
final String linkString = link.toString();
final String lowerCase = linkString.toLowerCase();
if (lowerCase.endsWith(".png") || lowerCase.endsWith(".jpg") || lowerCase.endsWith(".jpeg") || lowerCase.endsWith(".gif")) {
picturesAmongSelecteds = true;
final String encodedLinkString = HtmlUtils.unicodeToHTMLUnicodeEntity(linkString);
final String strText = "<html><img src=\"" + encodedLinkString + "\">";
((MLinkController) LinkController.getController()).setLink(node, (URI) null, LinkController.LINK_ABSOLUTE);
setNodeText(node, strText);
}
}
}
if (picturesAmongSelecteds) {
return;
}
final Controller controller = modeController.getController();
final ViewController viewController = controller.getViewController();
final NodeModel selectedNode = modeController.getMapController().getSelectedNode();
final MapModel map = selectedNode.getMap();
final File file = map.getFile();
if (file == null && LinkController.getLinkType() == LinkController.LINK_RELATIVE_TO_MINDMAP) {
JOptionPane.showMessageDialog(viewController.getCurrentRootComponent(), TextUtils.getText("not_saved_for_image_error"), "Freeplane", JOptionPane.WARNING_MESSAGE);
return;
}
final ExampleFileFilter filter = new ExampleFileFilter();
filter.addExtension("jpg");
filter.addExtension("jpeg");
filter.addExtension("png");
filter.addExtension("gif");
filter.setDescription(TextUtils.getText("bitmaps"));
final UrlManager urlManager = modeController.getExtension(UrlManager.class);
final JFileChooser chooser = urlManager.getFileChooser(null, false);
chooser.setFileFilter(filter);
chooser.setAcceptAllFileFilterUsed(false);
chooser.setAccessory(new BitmapImagePreview(chooser));
final int returnVal = chooser.showOpenDialog(viewController.getCurrentRootComponent());
if (returnVal != JFileChooser.APPROVE_OPTION) {
return;
}
final File input = chooser.getSelectedFile();
URI uri = input.toURI();
if (uri == null) {
return;
}
// bad hack: try to interpret file as http link
if (!input.exists()) {
uri = LinkController.toRelativeURI(map.getFile(), input, LinkController.LINK_RELATIVE_TO_MINDMAP);
if (uri == null || !"http".equals(uri.getScheme())) {
UITools.errorMessage(TextUtils.format("file_not_found", input.toString()));
return;
}
} else if (LinkController.getLinkType() != LinkController.LINK_ABSOLUTE) {
uri = LinkController.toLinkTypeDependantURI(map.getFile(), input);
}
String uriString = uri.toString();
if (uriString.startsWith("http:/")) {
uriString = "http://" + uriString.substring("http:/".length());
}
final String strText = "<html><img src=\"" + uriString + "\">";
setNodeText(selectedNode, strText);
}
use of org.freeplane.core.ui.ExampleFileFilter in project freeplane by freeplane.
the class ImportXmlFile method actionPerformed.
public void actionPerformed(final ActionEvent e) {
final String type = "xml";
final Component component = Controller.getCurrentController().getViewController().getCurrentRootComponent();
final JFileChooser chooser = new JFileChooser();
final ExampleFileFilter filter = new ExampleFileFilter(type, null);
chooser.setFileFilter(filter);
chooser.setAcceptAllFileFilterUsed(true);
final File mmFile = Controller.getCurrentController().getMap().getFile();
if (mmFile != null && mmFile.getParentFile() != null) {
chooser.setSelectedFile(mmFile.getParentFile());
}
final int returnVal = chooser.showOpenDialog(component);
if (returnVal != JFileChooser.APPROVE_OPTION) {
return;
}
final File chosenFile = chooser.getSelectedFile();
importXmlFile(chosenFile);
}
use of org.freeplane.core.ui.ExampleFileFilter in project freeplane by freeplane.
the class XsltExportEngineFactory method addXsltFile.
private void addXsltFile(final String[] extensions, String description, final File xsltFile) {
final ExampleFileFilter filter = new ExampleFileFilter(extensions, TextUtils.getOptionalTranslation(description));
final XsltExportEngine exporter = new XsltExportEngine(xsltFile);
controller.addExportEngine(filter, exporter);
}
Aggregations