(Job job)
| 220 | } |
| 221 | |
| 222 | public void exportJS(Job job) { |
| 223 | XMLControlElement control = new XMLControlElement(); |
| 224 | |
| 225 | try { |
| 226 | control.readXML(job.getXML()); |
| 227 | } catch (Exception ex) { |
| 228 | System.err.println("Error reading XML for export."); |
| 229 | } |
| 230 | OSPLog.fine("Exporting XML"); |
| 231 | OSPLog.finer("XML=" + control.toXML()); |
| 232 | AsyncFileChooser chooser = OSPRuntime.getChooser(); |
| 233 | if (chooser == null) { |
| 234 | return; |
| 235 | } |
| 236 | String oldTitle = chooser.getDialogTitle(); |
| 237 | chooser.setDialogTitle("Export"); |
| 238 | int result = -1; |
| 239 | try { |
| 240 | result = chooser.showSaveDialog(null); |
| 241 | } catch (Throwable e) { |
| 242 | e.printStackTrace(); |
| 243 | } |
| 244 | chooser.setDialogTitle(oldTitle); |
| 245 | if (result == JFileChooser.APPROVE_OPTION) { |
| 246 | File file = chooser.getSelectedFile(); |
| 247 | // check to see if file already exists |
| 248 | org.opensourcephysics.display.OSPRuntime.chooserDir = chooser.getCurrentDirectory().toString(); |
| 249 | String fileName = file.getAbsolutePath(); |
| 250 | // String fileName = XML.getRelativePath(file.getAbsolutePath()); |
| 251 | if ((fileName == null) || fileName.trim().equals("")) { |
| 252 | return; |
| 253 | } |
| 254 | int i = fileName.toLowerCase().lastIndexOf(".xml"); |
| 255 | if (i != fileName.length() - 4) { |
| 256 | fileName += ".xml"; |
| 257 | file = new File(fileName); |
| 258 | } |
| 259 | if (/** @j2sNative false && */ |
| 260 | file.exists()) { |
| 261 | int selected = JOptionPane.showConfirmDialog(null, "Replace existing " + file.getName() + "?", |
| 262 | "Replace File", JOptionPane.YES_NO_CANCEL_OPTION); |
| 263 | if (selected != JOptionPane.YES_OPTION) { |
| 264 | return; |
| 265 | } |
| 266 | } |
| 267 | control.write(fileName); |
| 268 | } |
| 269 | OSPLog.fine("Done Exporting"); |
| 270 | |
| 271 | } |
| 272 | |
| 273 | /* |
| 274 | * Displays the export dialog with a given XML file. |
no test coverage detected