Changeset 24060 in osm for applications/editors


Ignore:
Timestamp:
2010-11-04T14:26:45+01:00 (14 years ago)
Author:
extropy
Message:

pdfimport: saving placement coordinates for repeated imports.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pdfimport/src/pdfimport/LoadPdfDialog.java

    r24056 r24060  
    1515import java.io.FileInputStream;
    1616import java.io.FileNotFoundException;
     17import java.io.FileOutputStream;
    1718import java.io.IOException;
    1819import java.util.Collection;
     
    4647public class LoadPdfDialog extends JFrame {
    4748
    48         private String fileName;
     49        private File fileName;
    4950        private PathOptimizer data;
    5051        private final FilePlacement placement;
     
    275276
    276277        private void loadFilePressed() {
    277                 final java.io.File fileName = this.chooseFile();
    278 
    279                 if (fileName == null) {
     278                final File newFileName = this.chooseFile();
     279
     280                if (newFileName == null) {
    280281                        return;
    281282                }
     283
     284                this.removeLayer();
    282285
    283286                this.loadFileButton.setEnabled(false);
    284287                this.loadFileButton.setText(tr("Loading..."));
    285 
    286288
    287289                this.runAsBackgroundTask(
    288290                                new Runnable() {
    289291                                        public void run() {
    290                                                 data = loadPDF(fileName);
     292                                                data = loadPDF(newFileName);
    291293                                        }
    292294                                },
     
    295297                                        public void actionPerformed(ActionEvent e) {
    296298                                                if (data!= null) {
     299                                                        LoadPdfDialog.this.placement.projection = null;
    297300                                                        OsmBuilder.Mode mode = LoadPdfDialog.this.debugModeCheck.isSelected() ? OsmBuilder.Mode.Debug: OsmBuilder.Mode.Draft;
    298                                                         LoadPdfDialog.this.fileName = fileName.getAbsolutePath();
     301                                                        LoadPdfDialog.this.fileName = newFileName;
    299302                                                        LoadPdfDialog.this.makeLayer(tr("PDF file preview"), mode);
    300303                                                        LoadPdfDialog.this.loadFileButton.setText(tr("Loaded"));
    301304                                                        LoadPdfDialog.this.loadFileButton.setEnabled(true);
     305                                                        LoadPdfDialog.this.loadPlacement();
     306                                                        LoadPdfDialog.this.setPlacement();
    302307                                                }
    303308                                        }
     
    308313        private void okPressed() {
    309314
    310                 boolean ok = this.loadTransformation();
     315                boolean ok = this.parsePlacement();
    311316                if (!ok){
    312317                        return;
    313318                }
    314319
     320                this.savePlacement();
     321
    315322                //rebuild layer with latest projection
    316323                this.makeLayer(tr("Imported PDF: ") + this.fileName, OsmBuilder.Mode.Final);
     324
    317325                this.setVisible(false);
    318326        }
    319327
    320328        private void savePressed() {
    321                 boolean ok = this.loadTransformation();
     329                boolean ok = this.parsePlacement();
    322330                if (!ok){
    323331                        return;
     
    329337                        return;
    330338                }
     339
     340                this.savePlacement();
    331341
    332342                //rebuild layer with latest projection
     
    339349        private void showPressed() {
    340350
    341                 boolean ok = this.loadTransformation();
     351                boolean ok = this.parsePlacement();
    342352                if (!ok){
    343353                        return;
     
    532542                data.splitLayersByPathKind();
    533543                data.finish();
    534 
    535                 //load saved transformation
    536                 File propertiesFile = new File(fileName.getAbsoluteFile()+ ".placement");
    537                 try {
    538 
    539                         if (propertiesFile.exists()){
    540                                 Properties p = new Properties();
    541                                 p.load(new FileInputStream(propertiesFile));
    542                                 this.placement.fromProperties(p);
    543                                 this.setTransformation();
    544                         }
    545                 }catch (Exception e){
    546                         e.printStackTrace();
    547                 }
    548 
    549544                return data;
    550545        }
     
    552547
    553548
    554         private boolean loadTransformation() {
     549        private boolean parsePlacement() {
    555550                Object selectedProjection = this.projectionCombo.getSelectedItem();
    556551
     
    584579        }
    585580
    586         private void setTransformation() {
     581        private void setPlacement() {
    587582
    588583                this.projectionCombo.setSelectedItem(placement.projection);
     
    597592        }
    598593
     594
     595        private void loadPlacement() {
     596                //load saved transformation
     597                File propertiesFile = new File(fileName.getAbsoluteFile()+ ".placement");
     598                try {
     599
     600                        if (propertiesFile.exists()){
     601                                Properties p = new Properties();
     602                                p.load(new FileInputStream(propertiesFile));
     603                                this.placement.fromProperties(p);
     604                        }
     605                }catch (Exception e){
     606                        e.printStackTrace();
     607                }
     608        }
     609
     610        private void savePlacement(){
     611                //load saved transformation
     612                File propertiesFile = new File(fileName.getAbsoluteFile()+ ".placement");
     613                try {
     614                        Properties p = this.placement.toProperties();
     615                        p.store(new FileOutputStream(propertiesFile), "PDF file placement on OSM");
     616                } catch (Exception e){
     617                        e.printStackTrace();
     618                }
     619        }
     620
     621
    599622        private void makeLayer(String name, OsmBuilder.Mode mode) {
    600623                this.removeLayer();
Note: See TracChangeset for help on using the changeset viewer.