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);
}
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);
}
}
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);
}
}
}
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;
}
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;
}
Aggregations