Search in sources :

Example 1 with ExampleFileFilter

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);
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) FileFilter(javax.swing.filechooser.FileFilter) ExampleFileFilter(org.freeplane.core.ui.ExampleFileFilter) ExampleFileFilter(org.freeplane.core.ui.ExampleFileFilter) File(java.io.File)

Example 2 with ExampleFileFilter

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);
}
Also used : JFileChooser(javax.swing.JFileChooser) Component(java.awt.Component) ExampleFileFilter(org.freeplane.core.ui.ExampleFileFilter) File(java.io.File)

Example 3 with ExampleFileFilter

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);
}
Also used : UrlManager(org.freeplane.features.url.UrlManager) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) MapModel(org.freeplane.features.map.MapModel) MMapController(org.freeplane.features.map.mindmapmode.MMapController) MapController(org.freeplane.features.map.MapController) MIconController(org.freeplane.features.icon.mindmapmode.MIconController) IconController(org.freeplane.features.icon.IconController) Controller(org.freeplane.features.mode.Controller) TextController(org.freeplane.features.text.TextController) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) NodeStyleController(org.freeplane.features.nodestyle.NodeStyleController) FormatController(org.freeplane.features.format.FormatController) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) ResourceController(org.freeplane.core.resources.ResourceController) ViewController(org.freeplane.features.ui.ViewController) LinkController(org.freeplane.features.link.LinkController) ModeController(org.freeplane.features.mode.ModeController) MNodeStyleController(org.freeplane.features.nodestyle.mindmapmode.MNodeStyleController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) ScannerController(org.freeplane.features.format.ScannerController) URI(java.net.URI) NodeModel(org.freeplane.features.map.NodeModel) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) JFileChooser(javax.swing.JFileChooser) ViewController(org.freeplane.features.ui.ViewController) BitmapImagePreview(org.freeplane.core.ui.components.BitmapImagePreview) ExampleFileFilter(org.freeplane.core.ui.ExampleFileFilter) File(java.io.File)

Example 4 with ExampleFileFilter

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);
}
Also used : JFileChooser(javax.swing.JFileChooser) Component(java.awt.Component) ExampleFileFilter(org.freeplane.core.ui.ExampleFileFilter) File(java.io.File)

Example 5 with ExampleFileFilter

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);
}
Also used : ExampleFileFilter(org.freeplane.core.ui.ExampleFileFilter)

Aggregations

ExampleFileFilter (org.freeplane.core.ui.ExampleFileFilter)6 File (java.io.File)4 JFileChooser (javax.swing.JFileChooser)3 Component (java.awt.Component)2 ModeController (org.freeplane.features.mode.ModeController)2 MModeController (org.freeplane.features.mode.mindmapmode.MModeController)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 URI (java.net.URI)1 Hashtable (java.util.Hashtable)1 FileFilter (javax.swing.filechooser.FileFilter)1 ResourceController (org.freeplane.core.resources.ResourceController)1 BitmapImagePreview (org.freeplane.core.ui.components.BitmapImagePreview)1 ExportController (org.freeplane.features.export.mindmapmode.ExportController)1 FormatController (org.freeplane.features.format.FormatController)1 ScannerController (org.freeplane.features.format.ScannerController)1 IconController (org.freeplane.features.icon.IconController)1 MIconController (org.freeplane.features.icon.mindmapmode.MIconController)1 LinkController (org.freeplane.features.link.LinkController)1 MLinkController (org.freeplane.features.link.mindmapmode.MLinkController)1