Search in sources :

Example 1 with ExternalGraphicFilter

use of com.sldeditor.ui.widgets.ExternalGraphicFilter 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)

Aggregations

SLDDataInterface (com.sldeditor.common.SLDDataInterface)1 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)1 ExternalGraphicFilter (com.sldeditor.ui.widgets.ExternalGraphicFilter)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 JFileChooser (javax.swing.JFileChooser)1