Search in sources :

Example 51 with SLDDataInterface

use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.

the class SLDEditorMenus method createSLDMenu.

/**
 * Creates the sld menu.
 *
 * @param appPanel the app panel
 * @param menuBar the menu bar
 */
private void createSLDMenu(JPanel appPanel, JMenuBar menuBar) {
    JMenu mnSld = new JMenu(Localisation.getString(SLDEditorMenus.class, "sld.menu"));
    menuBar.add(mnSld);
    JMenuItem mntmOpenSLD = new JMenuItem(Localisation.getString(SLDEditorMenus.class, "common.open"));
    mntmOpenSLD.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter(Localisation.getString(SLDEditorMenus.class, "sld.files.filter") + " (*." + SLD_FILE_EXTENSION + ")", SLD_FILE_EXTENSION);
            fileChooser.setFileFilter(filter);
            try {
                SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
                if (sldData != null) {
                    File sldFile = sldData.getSLDFile();
                    File f = new File(sldFile.getCanonicalPath());
                    if (f.exists()) {
                        fileChooser.setSelectedFile(f);
                    }
                }
            } catch (IOException e1) {
                ConsoleManager.getInstance().exception(this, e1);
            }
            try {
                int result = fileChooser.showOpenDialog(Controller.getInstance().getFrame());
                if (result == JFileChooser.APPROVE_OPTION) {
                    File selectedFile = fileChooser.getSelectedFile();
                    application.openFile(selectedFile.toURI().toURL());
                }
            } catch (IOException e1) {
                ConsoleManager.getInstance().exception(this, e1);
            }
        }
    });
    mnSld.add(mntmOpenSLD);
    JMenuItem mntmReloadSLD = new JMenuItem(Localisation.getString(SLDEditorMenus.class, "common.reload"));
    mntmReloadSLD.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
            if (sldData != null) {
                URL url = sldData.getSLDURL();
                if (url != null) {
                    application.openFile(url);
                }
            }
        }
    });
    mnSld.add(mntmReloadSLD);
    menuSaveSLDFile = new JMenuItem(Localisation.getString(SLDEditorMenus.class, "common.save"));
    menuSaveSLDFile.setEnabled(false);
    menuSaveSLDFile.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            URL url = null;
            try {
                SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
                if (sldData != null) {
                    if (sldData.getSLDFile() != null) {
                        url = sldData.getSLDFile().toURI().toURL();
                    } else if (sldData.getConnectionData() != null) {
                        url = sldData.getConnectionData().getUrl();
                    }
                }
            } catch (MalformedURLException e1) {
                ConsoleManager.getInstance().exception(SLDEditorMenus.class, e1);
            }
            if (url != null) {
                application.saveFile(url);
            }
        }
    });
    mnSld.add(menuSaveSLDFile);
    menuSaveAsSLDFile = new JMenuItem(Localisation.getString(SLDEditorMenus.class, "common.saveas"));
    menuSaveAsSLDFile.setEnabled(false);
    menuSaveAsSLDFile.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setDialogTitle(Localisation.getString(SLDEditorMenus.class, "sld.save_sld_file"));
            FileNameExtensionFilter filter = new FileNameExtensionFilter(Localisation.getString(SLDEditorMenus.class, "sld.files.filter") + " (*." + SLD_FILE_EXTENSION + ")", SLD_FILE_EXTENSION);
            fileChooser.setFileFilter(filter);
            File sldFile = SLDEditorFile.getInstance().getSLDData().getSLDFile();
            if (sldFile != null) {
                if (sldFile.getParentFile() != null) {
                    fileChooser.setCurrentDirectory(sldFile.getParentFile());
                }
                fileChooser.setSelectedFile(sldFile);
            }
            int userSelection = fileChooser.showSaveDialog(appPanel);
            if (userSelection == JFileChooser.APPROVE_OPTION) {
                File fileToSave = fileChooser.getSelectedFile();
                if (!fileChooser.getFileFilter().accept(fileToSave)) {
                    fileToSave = new File(fileToSave.getAbsolutePath() + "." + SLD_FILE_EXTENSION);
                }
                try {
                    SLDEditorFile.getInstance().setSldFile(fileToSave);
                    application.saveFile(fileToSave.toURI().toURL());
                } catch (MalformedURLException e1) {
                    ConsoleManager.getInstance().exception(SLDEditorMenus.class, e1);
                }
            }
        }
    });
    mnSld.add(menuSaveAsSLDFile);
}
Also used : MalformedURLException(java.net.MalformedURLException) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) SLDDataInterface(com.sldeditor.common.SLDDataInterface) ActionEvent(java.awt.event.ActionEvent) IOException(java.io.IOException) JMenuItem(javax.swing.JMenuItem) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) JMenu(javax.swing.JMenu) URL(java.net.URL)

Example 52 with SLDDataInterface

use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.

the class SLDEditor method openFile.

/**
 * Open file.
 *
 * @param url the url
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.SLDEditorInterface#openFile(java.net.URL)
     */
@Override
public void openFile(URL url) {
    List<SLDDataInterface> sldDataList = null;
    for (ExtensionInterface extension : extensionList) {
        if (sldDataList == null) {
            sldDataList = extension.open(url);
        }
    }
    if (sldDataList != null) {
        SelectedFiles selectedFiles = new SelectedFiles();
        selectedFiles.setSldData(sldDataList);
        loadSLDString(selectedFiles);
    }
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) SelectedFiles(com.sldeditor.common.filesystem.SelectedFiles) ExtensionInterface(com.sldeditor.extension.ExtensionInterface)

Example 53 with SLDDataInterface

use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.

the class ExternalGraphicDetails method buttonPressed.

/**
 * Button pressed.
 *
 * @param buttonExternal the button external
 */
@Override
public void buttonPressed(Component buttonExternal) {
    JFileChooser fc = new JFileChooser();
    if (externalURL != null) {
        String filename = externalURL.toExternalForm();
        SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
        if (RelativePath.hasHost(externalURL)) {
            if (sldData != null) {
                File currentFile = sldData.getSLDFile();
                if (currentFile != null) {
                    fc.setCurrentDirectory(currentFile.getParentFile());
                }
            }
        } else {
            File currentFile = ExternalFilenames.getFile(sldData, filename);
            if (currentFile.exists()) {
                fc.setCurrentDirectory(currentFile.getParentFile());
            }
        }
    }
    fc.addChoosableFileFilter(new ExternalGraphicFilter());
    int returnVal = fc.showOpenDialog(buttonExternal);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
            userSelectedFileURL(fc.getSelectedFile().toURI().toURL());
        } catch (MalformedURLException e1) {
            ConsoleManager.getInstance().exception(this, e1);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) JFileChooser(javax.swing.JFileChooser) SLDDataInterface(com.sldeditor.common.SLDDataInterface) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) ExternalGraphicFilter(com.sldeditor.ui.widgets.ExternalGraphicFilter)

Example 54 with SLDDataInterface

use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.

the class RelativePath method convert.

/**
 * Convert URL to absolute/relative path.
 *
 * @param externalFileURL the external file URL
 * @param useRelativePaths the use relative paths
 * @return the string
 */
public static String convert(URL externalFileURL, boolean useRelativePaths) {
    String path = "";
    if (externalFileURL != null) {
        if (isLocalFile(externalFileURL)) {
            if (useRelativePaths) {
                File f = new File(externalFileURL.getFile());
                File folder = null;
                SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
                if ((sldData != null) && (sldData.getSLDFile() != null)) {
                    folder = sldData.getSLDFile().getParentFile();
                }
                if (folder == null) {
                    folder = new File(System.getProperty("user.dir"));
                }
                path = getRelativePath(f, folder);
            } else {
                path = externalFileURL.toExternalForm();
            }
        } else {
            path = externalFileURL.toExternalForm();
        }
    }
    return path;
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Example 55 with SLDDataInterface

use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.

the class NewSLDPanel method showDialog.

/**
 * Show dialog.
 *
 * @param parent the parent
 * @return the created SLD if selected
 */
public List<SLDDataInterface> showDialog(JFrame parent) {
    List<SLDDataInterface> newSLDList = null;
    selected = null;
    if (parent != null) {
        this.setLocationRelativeTo(parent);
        int x = ((parent.getWidth() - getWidth()) / 2);
        int y = ((parent.getHeight() - getHeight()) / 2);
        this.setLocation(x, y);
    }
    setVisible(true);
    if (selected != null) {
        newSLDList = new ArrayList<SLDDataInterface>();
        StyledLayerDescriptor sld = selected.create();
        if (sldWriter == null) {
            sldWriter = SLDWriterFactory.createWriter(null);
        }
        newSLDList.add(new SLDData(new StyleWrapper(selected.getName()), sldWriter.encodeSLD(null, sld)));
        return newSLDList;
    }
    return null;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper)

Aggregations

SLDDataInterface (com.sldeditor.common.SLDDataInterface)72 File (java.io.File)34 IOException (java.io.IOException)21 SLDData (com.sldeditor.common.data.SLDData)20 ArrayList (java.util.ArrayList)20 Test (org.junit.Test)20 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)17 URL (java.net.URL)17 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)14 StyleWrapper (com.sldeditor.common.data.StyleWrapper)12 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)12 FileNotFoundException (java.io.FileNotFoundException)12 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)12 URISyntaxException (java.net.URISyntaxException)10 NodeInterface (com.sldeditor.common.NodeInterface)9 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)7 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)6 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)5 FSTree (com.sldeditor.datasource.extension.filesystem.node.FSTree)5 GeoServerWorkspaceNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode)5