Changeset 34796 in osm
- Timestamp:
- 2018-12-29T07:59:55+01:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/pdfimport/src/org/openstreetmap/josm/plugins/pdfimport
- Files:
-
- 4 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pdfimport/src/org/openstreetmap/josm/plugins/pdfimport/GuiProjections.java
r34609 r34796 159 159 160 160 private void build() { 161 // JButton specBtn = new JButton(tr("Specifiy"));162 161 pCode = new JLabel("code",SwingConstants.RIGHT); 163 162 pName = new JLabel("Name",SwingConstants.RIGHT); … … 178 177 } 179 178 } 180 181 //class ProjectionSubPrefsDialog extends JDialog {182 ///*183 // * note currently non-functional ==> not used184 // */185 //private final ProjectionChoice projPref;186 //private OKAction actOK;187 //private CancelAction actCancel;188 //private JPanel projPrefPanel;189 //190 //ProjectionSubPrefsDialog(Component parent, ProjectionChoice pr) {191 // super(JOptionPane.getFrameForComponent(parent), ModalityType.DOCUMENT_MODAL);192 //193 // projPref = pr;194 //195 // setTitle(tr("Projection Preferences"));196 // setDefaultCloseOperation(DISPOSE_ON_CLOSE);197 //198 // build();199 //}200 //201 //protected void makeButtonRespondToEnter(SideButton btn) {202 // btn.setFocusable(true);203 // btn.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");204 // btn.getActionMap().put("enter", btn.getAction());205 //}206 //207 //protected JPanel buildInputForm() {208 // return projPref.getPreferencePanel(null);209 //}210 //211 //protected JPanel buildButtonRow() {212 // JPanel pnl = new JPanel(new FlowLayout());213 //214 // actOK = new OKAction();215 // actCancel = new CancelAction();216 //217 // SideButton btn;218 // pnl.add(btn = new SideButton(actOK));219 // // makeButtonRespondToEnter(btn);220 // // pnl.add(btn = new SideButton(actCancel));221 // // makeButtonRespondToEnter(btn);222 // return pnl;223 //}224 //225 //protected void build() {226 // projPrefPanel = buildInputForm();227 // getContentPane().setLayout(new BorderLayout());228 // getContentPane().add(projPrefPanel, BorderLayout.CENTER);229 // getContentPane().add(buildButtonRow(), BorderLayout.SOUTH);230 // pack();231 //232 // // make dialog respond to ESCAPE233 // getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)234 // .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape");235 // getRootPane().getActionMap().put("escape", actCancel);236 //}237 //238 //class OKAction extends AbstractAction {239 // OKAction() {240 // putValue(NAME, tr("OK"));241 // putValue(SHORT_DESCRIPTION, tr("Close the dialog and apply projection preferences"));242 // putValue(SMALL_ICON, ImageProvider.get("ok"));243 // }244 //245 // @Override246 // public void actionPerformed(ActionEvent e) {247 // projPref.setPreferences(projPref.getPreferences(projPrefPanel));248 // setVisible(false);249 // }250 //}251 //252 //class CancelAction extends AbstractAction {253 // CancelAction() {254 // putValue(NAME, tr("Cancel"));255 // putValue(SHORT_DESCRIPTION, tr("Close the dialog, discard projection preference changes"));256 // putValue(SMALL_ICON, ImageProvider.get("cancel"));257 // }258 //259 // @Override260 // public void actionPerformed(ActionEvent e) {261 // setVisible(false);262 // }263 //}264 //265 //@Override266 //public void setVisible(boolean visible) {267 // if (visible) {268 // new WindowGeometry(getClass().getName() + ".geometry",269 // WindowGeometry.centerOnScreen(new Dimension(400, 300))).applySafe(this);270 // } else if (isShowing()) { // Avoid IllegalComponentStateException like in #8775271 // new WindowGeometry(this).remember(getClass().getName() + ".geometry");272 // }273 // super.setVisible(visible);274 //}275 //}276 -
applications/editors/josm/plugins/pdfimport/src/org/openstreetmap/josm/plugins/pdfimport/LoadPdfDialog.java
r34660 r34796 11 11 import java.awt.GridBagConstraints; 12 12 import java.awt.GridBagLayout; 13 import java.awt.Insets;14 13 import java.awt.event.ActionEvent; 15 14 import java.awt.event.ActionListener; … … 20 19 import java.io.IOException; 21 20 22 import javax.swing.BorderFactory;23 21 import javax.swing.JButton; 24 import javax.swing.JComponent;25 22 import javax.swing.JFileChooser; 26 23 import javax.swing.JFrame; 27 import javax.swing.JLabel;28 24 import javax.swing.JOptionPane; 29 25 import javax.swing.JPanel; 30 26 import javax.swing.JProgressBar; 31 import javax.swing.JTextField;32 import javax.swing.SwingConstants;33 27 import javax.swing.SwingUtilities; 34 28 import javax.swing.filechooser.FileFilter; … … 47 41 public class LoadPdfDialog extends JFrame { 48 42 49 public static class MainButtons { 50 public JButton okButton; 51 public JButton cancelButton; 52 public JButton showButton; 53 public JButton saveButton; 54 public JPanel panel; 55 56 public MainButtons() { 57 } 58 59 void build(LoadPdfDialog loadPdfDialog) { 60 /* 61 * build the dialog Window from components 62 */ 63 okButton = new JButton(tr("Import")); 64 okButton.addActionListener(new ActionListener() { 65 @Override 66 public void actionPerformed(ActionEvent e) { 67 loadPdfDialog.importAction(); 68 } 69 }); 70 saveButton = new JButton(tr("Save")); 71 saveButton.addActionListener(new ActionListener() { 72 @Override 73 public void actionPerformed(ActionEvent e) { 74 loadPdfDialog.saveAction(); 75 } 76 }); 77 78 showButton = new JButton(tr("Show target")); 79 showButton.addActionListener(new ActionListener() { 80 @Override 81 public void actionPerformed(ActionEvent e) { 82 loadPdfDialog.showAction(); 83 } 84 }); 85 86 cancelButton = new JButton(tr("Cancel")); 87 cancelButton.addActionListener(new ActionListener() { 88 @Override 89 public void actionPerformed(ActionEvent e) { 90 loadPdfDialog.cancelAction(); 91 } 92 }); 93 94 panel = new JPanel(new FlowLayout()); 95 panel.add(cancelButton); 96 panel.add(showButton); 97 panel.add(okButton); 98 panel.add(saveButton); 99 showButton.setVisible(Preferences.isLegacyActions()); 100 saveButton.setVisible(Preferences.isLegacyActions()); 101 } 102 } 103 104 105 private static class Config { 106 /* 107 * encapsulate options for Path optimizer 108 * provide GUI 109 */ 110 public GuiFieldBool debugModeCheck; 111 public GuiFieldBool mergeCloseNodesCheck; 112 public GuiFieldDouble mergeCloseNodesTolerance; 113 public GuiFieldBool removeSmallObjectsCheck; 114 public GuiFieldDouble removeSmallObjectsSize; 115 public JTextField colorFilterColor; 116 public GuiFieldBool colorFilterCheck; 117 public GuiFieldBool removeParallelSegmentsCheck; 118 public GuiFieldDouble removeParallelSegmentsTolerance; 119 public GuiFieldBool removeLargeObjectsCheck; 120 public GuiFieldDouble removeLargeObjectsSize; 121 public GuiFieldBool limitPathCountCheck; 122 public GuiFieldInteger limitPathCount; 123 public GuiFieldBool splitOnColorChangeCheck; 124 public GuiFieldBool splitOnShapeClosedCheck; 125 public GuiFieldBool splitOnSingleSegmentCheck; 126 public GuiFieldBool splitOnOrthogonalCheck; 127 private JPanel panel; 128 129 public Config() { 130 build(); 131 } 132 133 public JComponent getComponent() { 134 return panel; 135 } 136 137 private void build() { 138 139 140 debugModeCheck = new GuiFieldBool(tr("Debug info"), Preferences.isDebugTags()); 141 142 mergeCloseNodesTolerance = new GuiFieldDouble(Preferences.getMergeNodesValue()); 143 mergeCloseNodesCheck = new GuiFieldBool(tr("Merge close nodes"), Preferences.isMergeNodes()); 144 mergeCloseNodesCheck.setCompanion(mergeCloseNodesTolerance); 145 146 removeSmallObjectsSize = new GuiFieldDouble(Preferences.getRemoveSmallValue()); 147 removeSmallObjectsCheck = new GuiFieldBool(tr("Remove objects smaller than"), Preferences.isRemoveSmall()); 148 removeSmallObjectsCheck.setCompanion(removeSmallObjectsSize); 149 150 removeLargeObjectsSize = new GuiFieldDouble(Preferences.getRemoveLargeValue()); 151 removeLargeObjectsCheck = new GuiFieldBool(tr("Remove objects larger than"), Preferences.isRemoveLarge()); 152 removeLargeObjectsCheck.setCompanion(removeLargeObjectsSize); 153 154 colorFilterColor = new GuiFieldHex(Preferences.getLimitColorValue()); 155 colorFilterCheck = new GuiFieldBool(tr("Only this color"), Preferences.isLimitColor()); 156 colorFilterCheck.setCompanion(colorFilterColor); 157 158 removeParallelSegmentsTolerance = new GuiFieldDouble(Preferences.getRemoveParallelValue()); 159 removeParallelSegmentsCheck = new GuiFieldBool(tr("Remove parallel lines"), Preferences.isRemoveParallel()); 160 removeParallelSegmentsCheck.setCompanion(removeParallelSegmentsTolerance); 161 162 limitPathCount = new GuiFieldInteger(Preferences.getLimitPathValue()); 163 limitPathCountCheck = new GuiFieldBool(tr("Take only first X paths"), Preferences.isLimitPath()); 164 limitPathCountCheck.setCompanion(limitPathCount); 165 166 splitOnColorChangeCheck = new GuiFieldBool(tr("Color/width change"), Preferences.isLayerAttribChange()); 167 splitOnShapeClosedCheck = new GuiFieldBool(tr("Shape closed"), Preferences.isLayerClosed()); 168 169 splitOnSingleSegmentCheck = new GuiFieldBool(tr("Single segments", Preferences.isLayerSegment())); 170 splitOnOrthogonalCheck = new GuiFieldBool(tr("Orthogonal shapes", Preferences.isLayerOrtho())); 171 172 panel = new JPanel(new GridBagLayout()); 173 panel.setBorder(BorderFactory.createTitledBorder(tr("Import settings"))); 174 175 GridBagConstraints cBasic = new GridBagConstraints(); 176 cBasic.gridx = GridBagConstraints.RELATIVE; 177 cBasic.gridy = GridBagConstraints.RELATIVE; 178 cBasic.insets = new Insets(0, 0, 0, 4); 179 cBasic.anchor = GridBagConstraints.LINE_START; 180 cBasic.fill = GridBagConstraints.HORIZONTAL; 181 cBasic.gridheight = 1; 182 cBasic.gridwidth = 1; 183 cBasic.ipadx = 0; 184 cBasic.ipady = 0; 185 cBasic.weightx = 0.0; 186 cBasic.weighty = 0.0; 187 188 GridBagConstraints cLeft = (GridBagConstraints) cBasic.clone(); 189 cLeft.gridx = 0; 190 191 GridBagConstraints cMiddle = (GridBagConstraints) cBasic.clone(); 192 cMiddle.gridx = 1; 193 cMiddle.anchor = GridBagConstraints.LINE_END; 194 195 GridBagConstraints cRight = (GridBagConstraints) cBasic.clone(); 196 cRight.gridx = 2; 197 198 panel.add(mergeCloseNodesCheck, cLeft); 199 panel.add(new JLabel(tr("Tolerance:"),SwingConstants.RIGHT), cMiddle); 200 panel.add(mergeCloseNodesTolerance, cRight); 201 202 panel.add(removeSmallObjectsCheck, cLeft); 203 panel.add(new JLabel(tr("Tolerance:"),SwingConstants.RIGHT), cMiddle); 204 panel.add(removeSmallObjectsSize, cRight); 205 206 panel.add(removeLargeObjectsCheck, cLeft); 207 panel.add(new JLabel(tr("Tolerance:"),SwingConstants.RIGHT), cMiddle); 208 panel.add(removeLargeObjectsSize, cRight); 209 210 panel.add(removeParallelSegmentsCheck, cLeft); 211 panel.add(new JLabel(tr("Max distance:"),SwingConstants.RIGHT), cMiddle); 212 panel.add(removeParallelSegmentsTolerance, cRight); 213 214 panel.add(limitPathCountCheck, cLeft); 215 panel.add(limitPathCount, cRight); 216 217 panel.add(colorFilterCheck, cLeft); 218 panel.add(colorFilterColor, cRight); 219 220 panel.add(debugModeCheck, cLeft); 221 222 cLeft.gridy = 8; panel.add(new JLabel(tr("Introduce separate layers for:")), cLeft); 223 cMiddle.gridy = 8; panel.add(splitOnShapeClosedCheck, cMiddle); 224 cRight.gridy = 8; panel.add(splitOnSingleSegmentCheck, cRight); 225 cMiddle.gridy = 9; panel.add(splitOnColorChangeCheck, cMiddle); 226 cRight.gridy = 9;panel.add(splitOnOrthogonalCheck, cRight); 227 } 228 } 229 230 static class LoadProgressRenderer implements ProgressRenderer { 231 private final JProgressBar pBar; 232 private String title = ""; 233 234 LoadProgressRenderer(JProgressBar pb) { 235 this.pBar = pb; 236 this.pBar.setMinimum(0); 237 this.pBar.setValue(0); 238 this.pBar.setMaximum(1); 239 this.pBar.setString(""); 240 this.pBar.setStringPainted(true); 241 242 } 243 244 @Override 245 public void setCustomText(String message) { 246 this.pBar.setString(this.title + message); 247 } 248 249 @Override 250 public void setIndeterminate(boolean indeterminate) { 251 this.pBar.setIndeterminate(indeterminate); 252 } 253 254 @Override 255 public void setMaximum(int maximum) { 256 this.pBar.setMaximum(maximum); 257 } 258 259 @Override 260 public void setTaskTitle(String taskTitle) { 261 this.title = taskTitle; 262 this.pBar.setString(this.title); 263 } 264 265 @Override 266 public void setValue(int value) { 267 this.pBar.setValue(value); 268 } 269 270 public void finish() { 271 this.pBar.setString(tr("Finished")); 272 this.pBar.setValue(this.pBar.getMaximum()); 273 } 274 275 } 276 277 private File pdfFile; 278 private final FilePlacement18 placement = new FilePlacement18(); 279 280 private PathOptimizer pdfData; 281 // private OsmDataLayer dataLayer; 282 283 private final JButton loadFileButton = new JButton(tr("Load preview ...")); 284 285 private final JProgressBar loadProgress = new JProgressBar(); 43 public static class MainButtons { 44 public JButton okButton; 45 public JButton cancelButton; 46 public JButton showButton; 47 public JButton saveButton; 48 public JPanel panel; 49 50 public MainButtons() { 51 } 52 53 void build(LoadPdfDialog loadPdfDialog) { 54 /* 55 * build the dialog Window from components 56 */ 57 okButton = new JButton(tr("Import")); 58 okButton.addActionListener(new ActionListener() { 59 @Override 60 public void actionPerformed(ActionEvent e) { 61 loadPdfDialog.importAction(); 62 } 63 }); 64 saveButton = new JButton(tr("Save")); 65 saveButton.addActionListener(new ActionListener() { 66 @Override 67 public void actionPerformed(ActionEvent e) { 68 loadPdfDialog.saveAction(); 69 } 70 }); 71 72 showButton = new JButton(tr("Show target")); 73 showButton.addActionListener(new ActionListener() { 74 @Override 75 public void actionPerformed(ActionEvent e) { 76 loadPdfDialog.showAction(); 77 } 78 }); 79 80 cancelButton = new JButton(tr("Cancel")); 81 cancelButton.addActionListener(new ActionListener() { 82 @Override 83 public void actionPerformed(ActionEvent e) { 84 loadPdfDialog.cancelAction(); 85 } 86 }); 87 88 panel = new JPanel(new FlowLayout()); 89 panel.add(cancelButton); 90 panel.add(showButton); 91 panel.add(okButton); 92 panel.add(saveButton); 93 showButton.setVisible(Preferences.isLegacyActions()); 94 saveButton.setVisible(Preferences.isLegacyActions()); 95 } 96 } 97 98 static class LoadProgressRenderer implements ProgressRenderer { 99 private final JProgressBar pBar; 100 private String title = ""; 101 102 LoadProgressRenderer(JProgressBar pb) { 103 this.pBar = pb; 104 this.pBar.setMinimum(0); 105 this.pBar.setValue(0); 106 this.pBar.setMaximum(1); 107 this.pBar.setString(""); 108 this.pBar.setStringPainted(true); 109 } 110 111 @Override 112 public void setCustomText(String message) { 113 this.pBar.setString(this.title + message); 114 } 115 116 @Override 117 public void setIndeterminate(boolean indeterminate) { 118 this.pBar.setIndeterminate(indeterminate); 119 } 120 121 @Override 122 public void setMaximum(int maximum) { 123 this.pBar.setMaximum(maximum); 124 } 125 126 @Override 127 public void setTaskTitle(String taskTitle) { 128 this.title = taskTitle; 129 this.pBar.setString(this.title); 130 } 131 132 @Override 133 public void setValue(int value) { 134 this.pBar.setValue(value); 135 } 136 137 public void finish() { 138 this.pBar.setString(tr("Finished")); 139 this.pBar.setValue(this.pBar.getMaximum()); 140 } 141 } 142 143 private File pdfFile; 144 private final FilePlacement18 placement = new FilePlacement18(); 145 146 private PathOptimizer pdfData; 147 148 private final JButton loadFileButton = new JButton(tr("Load preview ...")); 149 150 private final JProgressBar loadProgress = new JProgressBar(); 286 151 ; 287 private OsmDataLayer newLayer; 288 289 private LoadProgressRenderer progressRenderer; 290 291 public LoadPdfDialog() { 292 buildGUI(); 293 removeLayer(); 294 if (Preferences.getGuiMode() == Preferences.GuiMode.Simple) { 295 loadFileButton.setVisible(false); 296 configPanel.panel.setVisible(false); 297 actionPanel.saveButton.setVisible(false); 298 actionPanel.showButton.setVisible(false); 299 setSize(new Dimension(380, 350)); 300 if (!loadAction()) { 301 cancelAction(); 302 return; 303 } 304 } else { 305 setSize(new Dimension(450, 600)); 306 } 307 setAlwaysOnTop(true); 308 setVisible(true); 309 } 310 311 Component placementPanel = placement.getGui(); 312 MainButtons actionPanel = new MainButtons(); 313 Config configPanel = new Config(); 314 315 private void buildGUI() { 316 /* 317 * build the GUI from Components 318 */ 319 GridBagConstraints c = new GridBagConstraints(); 320 c.gridheight = 1; 321 c.gridwidth = 1; 322 c.gridx = 0; 323 c.gridy = GridBagConstraints.RELATIVE; 324 c.fill = GridBagConstraints.BOTH; 325 c.insets = new java.awt.Insets(0, 0, 0, 0); 326 327 actionPanel.build(this); 328 329 loadFileButton.addActionListener(new ActionListener() { 330 @Override 331 public void actionPerformed(ActionEvent e) { 332 loadAction(); 333 } 334 }); 335 336 progressRenderer = new LoadProgressRenderer(loadProgress); 337 338 JPanel panel = new JPanel(new GridBagLayout()); 339 340 panel.add(configPanel.getComponent(), c); 341 c.fill = GridBagConstraints.HORIZONTAL; 342 panel.add(loadFileButton, c); 343 c.fill = GridBagConstraints.BOTH; 344 panel.add(placementPanel, c); 345 panel.add(actionPanel.panel, c); 346 c.fill = GridBagConstraints.HORIZONTAL; 347 panel.add(this.loadProgress, c); 348 349 setContentPane(panel); 350 addWindowListener(new WindowAdapter() { 351 @Override 352 public void windowClosing(WindowEvent e) { 353 cancelAction(); 354 } 355 }); 356 placement.setDependsOnValid(actionPanel.okButton); 357 358 /* 359 * TODO: Make okButton to default Button of Dialog, make cancelButton to react on ESC-Key 360 */ 361 // SwingUtilities.getRootPane(panel).setDefaultButton(actionPanel.okButton); 362 } 363 364 private boolean loadAction() { 365 /* 366 * perform load PDF file to preview 367 * TODO: load preview to previous placement, involves reverse transform 368 */ 369 final File newFileName = this.chooseFile(); 370 371 if (newFileName == null) { 372 return false; 373 } 374 Logging.debug("PdfImport: Load Preview"); 375 this.removeLayer(); 376 377 this.loadFileButton.setEnabled(false); 378 379 this.runAsBackgroundTask(new Runnable() { 380 @Override 381 public void run() { 382 // async part 383 LoadPdfDialog.this.loadProgress.setVisible(true); 384 SwingRenderingProgressMonitor monitor = new SwingRenderingProgressMonitor(progressRenderer); 385 monitor.beginTask("Loading file", 1000); 386 pdfData = loadPDF(newFileName, monitor.createSubTaskMonitor(500, false)); 387 OsmBuilder.Mode mode = LoadPdfDialog.this.configPanel.debugModeCheck.getValue() 388 ? OsmBuilder.Mode.Debug 389 : OsmBuilder.Mode.Draft; 390 391 if (pdfData != null) { 392 LoadPdfDialog.this.newLayer = LoadPdfDialog.this.makeLayer( 393 tr("PDF preview: ") + newFileName.getName(), new FilePlacement(), mode, 394 monitor.createSubTaskMonitor(500, false)); 395 } 396 397 monitor.finishTask(); 398 progressRenderer.finish(); 399 } 400 }, new ActionListener() { 401 402 @Override 403 public void actionPerformed(ActionEvent event) { 404 // sync part 405 LoadPdfDialog.this.pdfFile = newFileName; 406 if (pdfData != null) { 407 Preview.set(newLayer, new FilePlacement()); 408 MainApplication.getMap().mapView.zoomTo(placement.getWorldBounds(pdfData)); 409 try { 410 LoadPdfDialog.this.placement.load(newFileName); 411 } catch (IOException e) { 412 // Saved placement does not exist, corrupt, ... ---> ignore it 413 } finally { 414 LoadPdfDialog.this.placement.verify(); 415 } 416 LoadPdfDialog.this.newLayer = null; 417 LoadPdfDialog.this.loadFileButton.setEnabled(true); 418 LoadPdfDialog.this.placementPanel.setEnabled(true); 419 LoadPdfDialog.this.actionPanel.panel.setEnabled(true); 420 LoadPdfDialog.this.actionPanel.showButton.setEnabled(true); 421 LoadPdfDialog.this.actionPanel.saveButton.setEnabled(true); 422 LoadPdfDialog.this.actionPanel.okButton.setEnabled(true); 423 LoadPdfDialog.this.loadProgress.setVisible(false); 424 } 425 } 426 }); 427 return true; 428 } 429 430 private void importAction() { 431 432 if (!placement.isValid()) return; 433 try { 434 placement.save(pdfFile); 435 } catch (IOException e) { 436 e.toString(); 437 } 438 removeLayer(); 439 440 runAsBackgroundTask(new Runnable() { 441 @Override 442 public void run() { 443 // async part 444 LoadPdfDialog.this.loadProgress.setVisible(true); 445 SwingRenderingProgressMonitor monitor = new SwingRenderingProgressMonitor(progressRenderer); 446 LoadPdfDialog.this.newLayer = LoadPdfDialog.this.makeLayer(tr("PDF: ") + pdfFile.getName(), placement, 447 OsmBuilder.Mode.Final, monitor); 448 progressRenderer.finish(); 449 } 450 }, new ActionListener() { 451 452 @Override 453 public void actionPerformed(ActionEvent e) { 454 // sync part 455 // rebuild layer with latest projection 456 MainApplication.getLayerManager().addLayer(newLayer); 457 MainApplication.getMap().mapView.zoomTo(placement.getWorldBounds(pdfData)); 458 LoadPdfDialog.this.setVisible(false); 459 } 460 }); 461 } 462 463 private void saveAction() { 464 /* 465 * perform save preview layer to file 466 * TODO: is this action valueable? Can be easily performed from main menu 467 */ 468 469 if (!placement.isValid()) return; 470 471 final java.io.File file = this.chooseSaveFile(); 472 473 if (file == null) { 474 return; 475 } 476 477 this.removeLayer(); 478 479 this.runAsBackgroundTask(new Runnable() { 480 @Override 481 public void run() { 482 // async part 483 SwingRenderingProgressMonitor monitor = new SwingRenderingProgressMonitor(progressRenderer); 484 LoadPdfDialog.this.saveLayer(file, placement, monitor); 485 progressRenderer.finish(); 486 } 487 }, new ActionListener() { 488 489 @Override 490 public void actionPerformed(ActionEvent e) { 491 // sync part 492 LoadPdfDialog.this.setVisible(false); 493 } 494 }); 495 } 496 497 private void showAction() { 498 /* 499 * perform show action 500 * TODO: is this action valuable? User can do it easy from OSM Main Menu 501 */ 502 if (!placement.isValid()) return; 503 504 // zoom to new location 505 MainApplication.getMap().mapView.zoomTo(placement.getWorldBounds(pdfData)); 506 MainApplication.getMap().repaint(); 507 } 508 509 private void cancelAction() { 510 /* 511 * perform cancel action 512 */ 513 removeLayer(); 514 setVisible(false); 515 } 516 517 // Implementation methods 518 519 private static JFileChooser loadChooser = null; 520 521 private java.io.File chooseFile() { 522 // get PDF file to load 523 if (loadChooser == null) { 524 loadChooser = new JFileChooser(Preferences.getLoadDir()); 525 loadChooser.setAcceptAllFileFilterUsed(false); 526 loadChooser.setMultiSelectionEnabled(false); 527 loadChooser.setFileFilter(new FileFilter() { 528 @Override 529 public boolean accept(java.io.File pathname) { 530 return pathname.isDirectory() || pathname.getName().endsWith(".pdf"); 531 } 532 533 @Override 534 public String getDescription() { 535 return tr("PDF files"); 536 } 537 }); 538 } else { 539 loadChooser.rescanCurrentDirectory(); 540 } 541 int result = loadChooser.showDialog(this, tr("Import PDF")); 542 if (result != JFileChooser.APPROVE_OPTION) { 543 return null; 544 } else { 545 Preferences.setLoadDir(loadChooser.getSelectedFile().getParentFile().getAbsolutePath()); 546 return loadChooser.getSelectedFile(); 547 } 548 } 549 550 private java.io.File chooseSaveFile() { 551 // get file name 552 JFileChooser fc = new JFileChooser(); 553 fc.setAcceptAllFileFilterUsed(true); 554 fc.setMultiSelectionEnabled(false); 555 fc.setFileFilter(new FileFilter() { 556 @Override 557 public boolean accept(java.io.File pathname) { 558 return pathname.isDirectory() || pathname.getName().endsWith(".osm"); 559 } 560 561 @Override 562 public String getDescription() { 563 return tr("OSM files"); 564 } 565 }); 152 private OsmDataLayer newLayer; 153 154 private LoadProgressRenderer progressRenderer; 155 156 public LoadPdfDialog() { 157 buildGUI(); 158 removeLayer(); 159 if (Preferences.getGuiMode() == Preferences.GuiMode.Simple) { 160 loadFileButton.setVisible(false); 161 configPanel.getComponent().setVisible(false); 162 actionPanel.saveButton.setVisible(false); 163 actionPanel.showButton.setVisible(false); 164 setSize(new Dimension(380, 350)); 165 if (!loadAction()) { 166 cancelAction(); 167 return; 168 } 169 } else { 170 setSize(new Dimension(450, 600)); 171 } 172 setAlwaysOnTop(true); 173 setVisible(true); 174 } 175 176 Component placementPanel = placement.getGui(); 177 MainButtons actionPanel = new MainButtons(); 178 PathOptimizerConfig configPanel = new PathOptimizerConfig(); 179 180 private void buildGUI() { 181 /* 182 * build the GUI from Components 183 */ 184 GridBagConstraints c = new GridBagConstraints(); 185 c.gridheight = 1; 186 c.gridwidth = 1; 187 c.gridx = 0; 188 c.gridy = GridBagConstraints.RELATIVE; 189 c.fill = GridBagConstraints.BOTH; 190 c.insets = new java.awt.Insets(0, 0, 0, 0); 191 192 actionPanel.build(this); 193 194 loadFileButton.addActionListener(new ActionListener() { 195 @Override 196 public void actionPerformed(ActionEvent e) { 197 loadAction(); 198 } 199 }); 200 201 progressRenderer = new LoadProgressRenderer(loadProgress); 202 203 JPanel panel = new JPanel(new GridBagLayout()); 204 205 panel.add(configPanel.getComponent(), c); 206 c.fill = GridBagConstraints.HORIZONTAL; 207 panel.add(loadFileButton, c); 208 c.fill = GridBagConstraints.BOTH; 209 panel.add(placementPanel, c); 210 panel.add(actionPanel.panel, c); 211 c.fill = GridBagConstraints.HORIZONTAL; 212 panel.add(this.loadProgress, c); 213 214 setContentPane(panel); 215 addWindowListener(new WindowAdapter() { 216 @Override 217 public void windowClosing(WindowEvent e) { 218 cancelAction(); 219 } 220 }); 221 placement.setDependsOnValid(actionPanel.okButton); 222 223 /* 224 * TODO: Make okButton to default Button of Dialog, make cancelButton to react on ESC-Key 225 */ 226 // SwingUtilities.getRootPane(panel).setDefaultButton(actionPanel.okButton); 227 } 228 229 private boolean loadAction() { 230 /* 231 * perform load PDF file to preview 232 * TODO: load preview to previous placement, involves reverse transform 233 */ 234 final File newFileName = this.chooseFile(); 235 236 if (newFileName == null) { 237 return false; 238 } 239 Logging.debug("PdfImport: Load Preview"); 240 this.removeLayer(); 241 242 this.loadFileButton.setEnabled(false); 243 244 this.runAsBackgroundTask(new Runnable() { 245 @Override 246 public void run() { 247 // async part 248 LoadPdfDialog.this.loadProgress.setVisible(true); 249 SwingRenderingProgressMonitor monitor = new SwingRenderingProgressMonitor(progressRenderer); 250 monitor.beginTask("Loading file", 1000); 251 pdfData = loadPDF(newFileName, monitor.createSubTaskMonitor(500, false)); 252 OsmBuilder.Mode mode = LoadPdfDialog.this.configPanel.debugModeCheck.getValue() 253 ? OsmBuilder.Mode.Debug 254 : OsmBuilder.Mode.Draft; 255 256 if (pdfData != null) { 257 LoadPdfDialog.this.newLayer = LoadPdfDialog.this.makeLayer( 258 tr("PDF preview: ") + newFileName.getName(), new FilePlacement(), mode, 259 monitor.createSubTaskMonitor(500, false)); 260 } 261 262 monitor.finishTask(); 263 progressRenderer.finish(); 264 } 265 }, new ActionListener() { 266 267 @Override 268 public void actionPerformed(ActionEvent event) { 269 // sync part 270 LoadPdfDialog.this.pdfFile = newFileName; 271 if (pdfData != null) { 272 Preview.set(newLayer, new FilePlacement()); 273 MainApplication.getMap().mapView.zoomTo(placement.getWorldBounds(pdfData)); 274 try { 275 LoadPdfDialog.this.placement.load(newFileName); 276 } catch (IOException e) { 277 // Saved placement does not exist, corrupt, ... ---> ignore it 278 } finally { 279 LoadPdfDialog.this.placement.verify(); 280 } 281 LoadPdfDialog.this.newLayer = null; 282 LoadPdfDialog.this.loadFileButton.setEnabled(true); 283 LoadPdfDialog.this.placementPanel.setEnabled(true); 284 LoadPdfDialog.this.actionPanel.panel.setEnabled(true); 285 LoadPdfDialog.this.actionPanel.showButton.setEnabled(true); 286 LoadPdfDialog.this.actionPanel.saveButton.setEnabled(true); 287 LoadPdfDialog.this.actionPanel.okButton.setEnabled(true); 288 LoadPdfDialog.this.loadProgress.setVisible(false); 289 } 290 } 291 }); 292 return true; 293 } 294 295 private void importAction() { 296 297 if (!placement.isValid()) return; 298 try { 299 placement.save(pdfFile); 300 } catch (IOException e) { 301 e.toString(); 302 } 303 removeLayer(); 304 305 runAsBackgroundTask(new Runnable() { 306 @Override 307 public void run() { 308 // async part 309 LoadPdfDialog.this.loadProgress.setVisible(true); 310 SwingRenderingProgressMonitor monitor = new SwingRenderingProgressMonitor(progressRenderer); 311 LoadPdfDialog.this.newLayer = LoadPdfDialog.this.makeLayer(tr("PDF: ") + pdfFile.getName(), placement, 312 OsmBuilder.Mode.Final, monitor); 313 progressRenderer.finish(); 314 } 315 }, new ActionListener() { 316 317 @Override 318 public void actionPerformed(ActionEvent e) { 319 // sync part 320 // rebuild layer with latest projection 321 MainApplication.getLayerManager().addLayer(newLayer); 322 MainApplication.getMap().mapView.zoomTo(placement.getWorldBounds(pdfData)); 323 LoadPdfDialog.this.setVisible(false); 324 } 325 }); 326 } 327 328 private void saveAction() { 329 /* 330 * perform save preview layer to file 331 * TODO: is this action valueable? Can be easily performed from main menu 332 */ 333 334 if (!placement.isValid()) return; 335 336 final java.io.File file = this.chooseSaveFile(); 337 338 if (file == null) { 339 return; 340 } 341 342 this.removeLayer(); 343 344 this.runAsBackgroundTask(new Runnable() { 345 @Override 346 public void run() { 347 // async part 348 SwingRenderingProgressMonitor monitor = new SwingRenderingProgressMonitor(progressRenderer); 349 LoadPdfDialog.this.saveLayer(file, placement, monitor); 350 progressRenderer.finish(); 351 } 352 }, new ActionListener() { 353 354 @Override 355 public void actionPerformed(ActionEvent e) { 356 // sync part 357 LoadPdfDialog.this.setVisible(false); 358 } 359 }); 360 } 361 362 private void showAction() { 363 /* 364 * perform show action 365 * TODO: is this action valuable? User can do it easy from OSM Main Menu 366 */ 367 if (!placement.isValid()) return; 368 369 // zoom to new location 370 MainApplication.getMap().mapView.zoomTo(placement.getWorldBounds(pdfData)); 371 MainApplication.getMap().repaint(); 372 } 373 374 private void cancelAction() { 375 /* 376 * perform cancel action 377 */ 378 removeLayer(); 379 setVisible(false); 380 } 381 382 // Implementation methods 383 384 private static JFileChooser loadChooser = null; 385 386 private java.io.File chooseFile() { 387 // get PDF file to load 388 if (loadChooser == null) { 389 loadChooser = new JFileChooser(Preferences.getLoadDir()); 390 loadChooser.setAcceptAllFileFilterUsed(false); 391 loadChooser.setMultiSelectionEnabled(false); 392 loadChooser.setFileFilter(new FileFilter() { 393 @Override 394 public boolean accept(java.io.File pathname) { 395 return pathname.isDirectory() || pathname.getName().endsWith(".pdf"); 396 } 397 398 @Override 399 public String getDescription() { 400 return tr("PDF files"); 401 } 402 }); 403 } else { 404 loadChooser.setSelectedFile(null); 405 loadChooser.rescanCurrentDirectory(); 406 } 407 int result = loadChooser.showDialog(this, tr("Import PDF")); 408 if (result != JFileChooser.APPROVE_OPTION) { 409 return null; 410 } else { 411 Preferences.setLoadDir(loadChooser.getSelectedFile().getParentFile().getAbsolutePath()); 412 return loadChooser.getSelectedFile(); 413 } 414 } 415 416 private java.io.File chooseSaveFile() { 417 // get file name 418 JFileChooser fc = new JFileChooser(); 419 fc.setAcceptAllFileFilterUsed(true); 420 fc.setMultiSelectionEnabled(false); 421 fc.setFileFilter(new FileFilter() { 422 @Override 423 public boolean accept(java.io.File pathname) { 424 return pathname.isDirectory() || pathname.getName().endsWith(".osm"); 425 } 426 427 @Override 428 public String getDescription() { 429 return tr("OSM files"); 430 } 431 }); 566 432 int result = fc.showOpenDialog(MainApplication.getMainFrame()); 567 433 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 434 if (result != JFileChooser.APPROVE_OPTION) { 435 return null; 436 } else { 437 return fc.getSelectedFile(); 438 } 439 } 440 441 private void runAsBackgroundTask(final Runnable task, final ActionListener after) { 442 /* 443 * run @task in background (asychronosly , run @after when @task has finished 444 */ 445 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 446 Thread t = new Thread(new Runnable() { 447 @Override 448 public void run() { 449 task.run(); 450 451 SwingUtilities.invokeLater(new Runnable() { 452 @Override 453 public void run() { 454 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 455 after.actionPerformed(null); 456 } 457 }); 458 } 459 }); 460 t.start(); 461 } 462 463 private PathOptimizer loadPDF(File fileName, ProgressMonitor monitor) { 464 /* 465 * postprocess load PDF-file according to options 466 */ 467 468 monitor.beginTask("", 100); 469 monitor.setTicks(0); 470 monitor.setCustomText(tr("Preparing")); 471 472 double nodesTolerance = 0.0; 473 Color color = null; 474 int maxPaths = Integer.MAX_VALUE; 475 476 if (configPanel.mergeCloseNodesCheck.getValue() && configPanel.mergeCloseNodesTolerance.isDataValid()) { 477 nodesTolerance = configPanel.mergeCloseNodesTolerance.getValue(); 478 } 479 480 if (configPanel.colorFilterCheck.getValue()) { 481 try { 482 String colString = this.configPanel.colorFilterColor.getText().replace("#", ""); 483 color = new Color(Integer.parseInt(colString, 16)); 484 } catch (Exception e) { 619 485 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Could not parse color")); 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 // 715 // 716 // 717 // 718 // 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 486 return null; 487 } 488 } 489 490 if (configPanel.limitPathCountCheck.getValue() && configPanel.limitPathCount.isDataValid()) { 491 maxPaths = configPanel.limitPathCount.getValue(); 492 } 493 494 monitor.setTicks(10); 495 monitor.setCustomText(tr("Parsing file")); 496 497 PathOptimizer data = new PathOptimizer(nodesTolerance, color, configPanel.splitOnColorChangeCheck.getValue()); 498 499 try { 500 PdfBoxParser parser = new PdfBoxParser(data); 501 parser.parse(fileName, maxPaths, monitor.createSubTaskMonitor(80, false)); 502 503 } catch (FileNotFoundException e1) { 504 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("File not found.")); 505 return null; 506 } catch (Exception e) { 507 e.printStackTrace(); 508 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Error while parsing: {0}", e.getMessage())); 509 return null; 510 } 511 512 monitor.setTicks(80); 513 514 if (configPanel.removeParallelSegmentsCheck.getValue() && configPanel.removeParallelSegmentsTolerance.isDataValid()) { 515 double tolerance = configPanel.removeParallelSegmentsTolerance.getValue(); 516 monitor.setCustomText(tr("Removing parallel segments")); 517 } 518 519 if (nodesTolerance > 0.0) { 520 monitor.setTicks(83); 521 monitor.setCustomText(tr("Joining nodes")); 522 data.mergeNodes(); 523 } 524 525 monitor.setTicks(85); 526 monitor.setCustomText(tr("Joining adjacent segments")); 527 data.mergeSegments(); 528 529 if (configPanel.removeSmallObjectsCheck.getValue() && configPanel.removeSmallObjectsSize.isDataValid()) { 530 double tolerance = configPanel.removeSmallObjectsSize.getValue(); 531 monitor.setTicks(90); 532 monitor.setCustomText(tr("Removing small objects")); 533 534 data.removeSmallObjects(tolerance); 535 536 } 537 538 if (configPanel.removeLargeObjectsCheck.getValue() && configPanel.removeLargeObjectsSize.isDataValid()) { 539 double tolerance = configPanel.removeLargeObjectsSize.getValue(); 540 monitor.setTicks(90); 541 monitor.setCustomText(tr("Removing large objects")); 542 data.removeLargeObjects(tolerance); 543 } 544 545 monitor.setTicks(95); 546 monitor.setCustomText(tr("Finalizing layers")); 547 data.splitLayersByPathKind(configPanel.splitOnShapeClosedCheck.getValue(), 548 configPanel.splitOnSingleSegmentCheck.getValue(), 549 configPanel.splitOnOrthogonalCheck.getValue()); 550 data.finish(); 551 552 monitor.finishTask(); 553 return data; 554 } 555 556 private OsmDataLayer makeLayer(String name, FilePlacement placement, OsmBuilder.Mode mode, 557 ProgressMonitor monitor) { 558 /* 559 * create a layer from data 560 */ 561 monitor.beginTask(tr("Building JOSM layer"), 100); 562 OsmBuilder builder = new OsmBuilder(placement); 563 DataSet data = builder.build(pdfData.getLayers(), mode, monitor.createSubTaskMonitor(50, false)); 564 data.setUploadPolicy(UploadPolicy.BLOCKED); 565 monitor.setTicks(50); 566 monitor.setCustomText(tr("Postprocessing layer")); 567 OsmDataLayer result = new OsmDataLayer(data, name, null); 568 result.setUploadDiscouraged(true); 569 result.setBackgroundLayer(true); 570 result.onPostLoadFromFile(); 571 572 monitor.finishTask(); 573 return result; 574 } 575 576 private void removeLayer() { 577 /* 578 * remove preview layer 579 */ 580 // if (dataLayer != null) { 581 // MainApplication.getLayerManager().removeLayer(dataLayer); 582 // dataLayer.data.clear(); // saves memory 583 // dataLayer = null; 584 // } 585 Preview.clear(); 586 // No layer ==> no actions 587 actionPanel.showButton.setEnabled(false); 588 actionPanel.saveButton.setEnabled(false); 589 actionPanel.okButton.setEnabled(false); 590 placementPanel.setEnabled(false); 591 592 } 593 594 private void saveLayer(java.io.File file, FilePlacement placement, ProgressMonitor monitor) { 595 /* 596 * save layer to file 597 * TODO: is this methode valuable? Functionality can easily performed from Main-Menu 598 */ 599 monitor.beginTask(tr("Saving to file."), 1000); 600 601 OsmBuilder builder = new OsmBuilder(placement); 602 DataSet data = builder.build(this.pdfData.getLayers(), OsmBuilder.Mode.Final, 603 monitor.createSubTaskMonitor(500, false)); 604 OsmDataLayer layer = new OsmDataLayer(data, file.getName(), file); 605 606 monitor.setCustomText(tr(" Writing to file")); 607 monitor.setTicks(500); 608 609 OsmExporter exporter = new OsmExporter(); 610 611 try { 612 exporter.exportData(file, layer); 613 } catch (IOException e) { 614 Logging.error(e); 615 } 616 617 monitor.finishTask(); 618 } 753 619 754 620 } -
applications/editors/josm/plugins/pdfimport/src/org/openstreetmap/josm/plugins/pdfimport/PdfImportPlugin.java
r34609 r34796 5 5 import org.openstreetmap.josm.gui.MainMenu; 6 6 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 7 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;8 import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;9 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;10 7 import org.openstreetmap.josm.plugins.Plugin; 11 8 import org.openstreetmap.josm.plugins.PluginInformation; … … 14 11 * A plugin to import a PDF file. 15 12 */ 13 16 14 public class PdfImportPlugin extends Plugin { 17 15 18 public PdfImportPlugin(PluginInformation info) {19 super(info);20 MainMenu.add(MainApplication.getMenu().imagerySubMenu, new PdfImportAction());21 new Preferences(getPluginInformation().name);22 }23 16 24 public static class pdfimportPrefs implements SubPreferenceSetting{25 @Override 26 public TabPreferenceSetting getTabPreferenceSetting(PreferenceTabbedPane gui) { 27 return null;28 17 public PdfImportPlugin(PluginInformation info) { 18 super(info); 19 MainMenu.add(MainApplication.getMenu().imagerySubMenu, new PdfImportAction()); 20 new Preferences(getPluginInformation().name); 21 } 29 22 30 @Override 31 public void addGui(PreferenceTabbedPane gui) { 32 return; 33 } 34 35 @Override 36 public boolean ok() { 37 return false; 38 } 39 40 @Override 41 public boolean isExpert() { 42 return false; 43 } 44 } 45 46 @Override 47 public PreferenceSetting getPreferenceSetting() { 48 /* 49 * TODO: implement it 50 */ 51 return new pdfimportPrefs(); 52 } 23 @Override 24 public PreferenceSetting getPreferenceSetting() { 25 return new PreferenceSettings(); 26 } 53 27 54 28 } -
applications/editors/josm/plugins/pdfimport/src/org/openstreetmap/josm/plugins/pdfimport/Preferences.java
r34650 r34796 8 8 public class Preferences { 9 9 10 public enum GuiMode { 11 Auto, Expert, Simple 12 } 13 14 public static String getLoadDir() { 15 return Config.getPref().get(Preferences.prefix + "loadDir"); 16 } 17 18 public static void setLoadDir(String loadDir) { 19 Config.getPref().put(Preferences.prefix + "loadDir", loadDir); 20 } 21 22 public static GuiMode getGuiMode() { 23 int GuiCode = Config.getPref().getInt(Preferences.prefix + "guiCode", 0); 24 switch (GuiCode) { 25 case -1: 26 case 1: 27 return GuiMode.Expert; 28 case 2: 29 return GuiMode.Simple; 30 default: 31 if (Config.getPref().getBoolean("expert")) 32 return GuiMode.Expert; 33 else 34 return GuiMode.Simple; 35 } 36 } 37 38 public static boolean isLegacyActions() { 39 return (Config.getPref().getInt(Preferences.prefix + "guiCode", 0) == -1); 40 } 41 42 public static boolean isMergeNodes() { 43 return Config.getPref().getBoolean(Preferences.prefix + "mergeNodes"); 44 } 45 46 public static double getMergeNodesValue() { 47 return Config.getPref().getDouble(Preferences.prefix + "mergeNodes.value", 1e-3); 48 } 49 50 public static boolean isRemoveSmall() { 51 return Config.getPref().getBoolean(Preferences.prefix + "removeSmall"); 52 } 53 54 public static double getRemoveSmallValue() { 55 return Config.getPref().getDouble(Preferences.prefix + "removeSmall.value", 1); 56 } 57 58 public static boolean isRemoveLarge() { 59 return Config.getPref().getBoolean(Preferences.prefix + "removeLarge"); 60 } 61 62 public static double getRemoveLargeValue() { 63 return Config.getPref().getDouble(Preferences.prefix + "removeLarge.value", 10); 64 } 65 66 public static boolean isRemoveParallel() { 67 return Config.getPref().getBoolean(Preferences.prefix + "removeParallel"); 68 } 69 70 public static double getRemoveParallelValue() { 71 return Config.getPref().getDouble(Preferences.prefix + "removeParallel.value", 3); 72 } 73 74 public static boolean isLimitPath() { 75 return Config.getPref().getBoolean(Preferences.prefix + "limitPath"); 76 } 77 78 public static int getLimitPathValue() { 79 return Config.getPref().getInt(Preferences.prefix + "limitPath.value", Integer.MAX_VALUE); 80 } 81 82 public static boolean isLimitColor() { 83 return Config.getPref().getBoolean(Preferences.prefix + "limitColor"); 84 } 85 86 public static String getLimitColorValue() { 87 return Config.getPref().get(Preferences.prefix + "limitColor.value","#000000"); 88 } 89 90 public static boolean isDebugTags() { 91 return Config.getPref().getBoolean(Preferences.prefix + "debugTags"); 92 } 93 94 public static boolean isLayerClosed() { 95 return Config.getPref().getBoolean(Preferences.prefix + "layerClosed"); 96 } 97 98 public static boolean isLayerSegment() { 99 return Config.getPref().getBoolean(Preferences.prefix + "layerSegment"); 100 } 101 102 public static boolean isLayerAttribChange() { 103 return Config.getPref().getBoolean(Preferences.prefix + "layerAttribChanges"); 104 } 105 106 public static boolean isLayerOrtho() { 107 return Config.getPref().getBoolean(Preferences.prefix + "layerOrtho"); 108 } 109 110 protected static int GuiCode; 111 112 private static String prefix; 113 114 private Preferences() { 115 return; 116 } 117 118 public Preferences (String p) { 119 prefix = p + "." ; 120 } 10 public enum GuiMode { 11 Auto, Expert, Simple 12 }; 13 14 public static String getLoadDir() { 15 return Config.getPref().get(Preferences.prefix + "loadDir"); 16 } 17 18 public static void setLoadDir(String loadDir) { 19 Config.getPref().put(Preferences.prefix + "loadDir", loadDir); 20 } 21 22 public static GuiMode getGuiMode() { 23 int GuiCode = Config.getPref().getInt(Preferences.prefix + "guiCode", 0); 24 switch (GuiCode) { 25 case -1: 26 case 1: 27 return GuiMode.Expert; 28 case 2: 29 return GuiMode.Simple; 30 default: 31 if (Config.getPref().getBoolean("expert")) 32 return GuiMode.Expert; 33 else 34 return GuiMode.Simple; 35 } 36 } 37 38 public static void setGuiCode(int guiCode) { 39 Config.getPref().putInt(Preferences.prefix + "guiCode", guiCode); 40 } 41 42 public static int getGuiCode() { 43 int GuiCode = Config.getPref().getInt(Preferences.prefix + "guiCode", 0); 44 return GuiCode; 45 } 46 47 public static boolean isLegacyActions() { 48 return (Config.getPref().getInt(Preferences.prefix + "guiCode", 0) == -1); 49 } 50 51 public static void setMergeNodes(boolean v) { 52 Config.getPref().putBoolean(Preferences.prefix + "mergeNodes",v); 53 } 54 55 public static boolean isMergeNodes() { 56 return Config.getPref().getBoolean(Preferences.prefix + "mergeNodes"); 57 } 58 59 public static double getMergeNodesValue() { 60 return Config.getPref().getDouble(Preferences.prefix + "mergeNodes.value", 1e-3); 61 } 62 63 public static void setMergeNodesValue(double v) { 64 Config.getPref().putDouble(Preferences.prefix + "mergeNodes.value", v); 65 } 66 67 public static boolean isRemoveSmall() { 68 return Config.getPref().getBoolean(Preferences.prefix + "removeSmall"); 69 } 70 71 public static void setRemoveSmall(boolean v) { 72 Config.getPref().putBoolean(Preferences.prefix + "removeSmall",v); 73 } 74 75 public static double getRemoveSmallValue() { 76 return Config.getPref().getDouble(Preferences.prefix + "removeSmall.value", 1); 77 } 78 79 public static void setRemoveSmallValue(double v) { 80 Config.getPref().putDouble(Preferences.prefix + "removeSmall.value", v); 81 } 82 83 public static boolean isRemoveLarge() { 84 return Config.getPref().getBoolean(Preferences.prefix + "removeLarge"); 85 } 86 87 public static void setRemoveLarge(boolean v) { 88 Config.getPref().putBoolean(Preferences.prefix + "removeLarge",v); 89 } 90 91 public static double getRemoveLargeValue() { 92 return Config.getPref().getDouble(Preferences.prefix + "removeLarge.value", 10); 93 } 94 95 public static void setRemoveLargeValue(double v) { 96 Config.getPref().putDouble(Preferences.prefix + "removeLarge.value", v); 97 } 98 99 public static boolean isRemoveParallel() { 100 return Config.getPref().getBoolean(Preferences.prefix + "removeParallel"); 101 } 102 103 public static void setRemoveParallel(boolean v) { 104 Config.getPref().putBoolean(Preferences.prefix + "removeParallel",v); 105 } 106 107 public static double getRemoveParallelValue() { 108 return Config.getPref().getDouble(Preferences.prefix + "removeParallel.value", 3); 109 } 110 111 public static void setRemoveParallelValue(double v) { 112 Config.getPref().putDouble(Preferences.prefix + "removeParallel.value", v); 113 } 114 115 public static boolean isLimitPath() { 116 return Config.getPref().getBoolean(Preferences.prefix + "limitPath"); 117 } 118 119 public static void setLimitPath(boolean v) { 120 Config.getPref().putBoolean(Preferences.prefix + "limitPath",v); 121 } 122 123 public static int getLimitPathValue() { 124 return Config.getPref().getInt(Preferences.prefix + "limitPath.value", Integer.MAX_VALUE); 125 } 126 127 public static void setLimitPathValue(int v) { 128 Config.getPref().putInt(Preferences.prefix + "limitPath.value", v); 129 } 130 131 public static boolean isLimitColor() { 132 return Config.getPref().getBoolean(Preferences.prefix + "limitColor"); 133 } 134 135 public static void setLimitColor(boolean v) { 136 Config.getPref().putBoolean(Preferences.prefix + "limitColor",v); 137 } 138 139 public static String getLimitColorValue() { 140 return Config.getPref().get(Preferences.prefix + "limitColor.value", "#000000"); 141 } 142 143 public static void setLimitColorValue(String v) { 144 Config.getPref().put(Preferences.prefix + "limitColor.value", v); 145 } 146 147 public static boolean isDebugTags() { 148 return Config.getPref().getBoolean(Preferences.prefix + "debugTags"); 149 } 150 151 public static void setDebugTags(boolean v) { 152 Config.getPref().putBoolean(Preferences.prefix + "debugTags",v); 153 } 154 155 public static boolean isLayerClosed() { 156 return Config.getPref().getBoolean(Preferences.prefix + "layerClosed"); 157 } 158 159 public static void setLayerClosed(boolean v) { 160 Config.getPref().putBoolean(Preferences.prefix + "layerClosed",v); 161 } 162 163 public static boolean isLayerSegment() { 164 boolean v =Config.getPref().getBoolean(Preferences.prefix + "layerSegment"); 165 return Config.getPref().getBoolean(Preferences.prefix + "layerSegment"); 166 } 167 168 public static void setLayerSegment(boolean v) { 169 Config.getPref().putBoolean(Preferences.prefix + "layerSegment",v); 170 } 171 172 public static boolean isLayerAttribChange() { 173 return Config.getPref().getBoolean(Preferences.prefix + "layerAttribChanges"); 174 } 175 176 public static void setLayerAttribChange(boolean v) { 177 Config.getPref().putBoolean(Preferences.prefix + "layerAttribChanges",v); 178 } 179 180 public static boolean isLayerOrtho() { 181 return Config.getPref().getBoolean(Preferences.prefix + "layerOrtho"); 182 } 183 184 public static void setLayerOrtho(boolean v) { 185 Config.getPref().putBoolean(Preferences.prefix + "layerOrtho",v); 186 } 187 188 protected static int GuiCode; 189 190 private static String prefix; 191 192 private Preferences() { 193 return; 194 } 195 196 public Preferences(String p) { 197 prefix = p + "."; 198 } 121 199 122 200 }
Note:
See TracChangeset
for help on using the changeset viewer.