Changeset 27282 in osm for applications


Ignore:
Timestamp:
2011-12-19T00:21:25+01:00 (13 years ago)
Author:
kpastor
Message:

Added a field to specify the map scale.

Location:
applications/editors/josm/plugins/print
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/print/README

    r27258 r27282  
    2525===========
    2626
     27print.map-scale (integer):
     28The map scale x as in 1:x.
     29Default: 25.000
     30
    2731print.attribution (string):
    2832The attribution text which will be printed on the page.
     
    4549Not really user preferences, but a mechanism to reliable backup and
    4650restore mappaint preferences which are temporary modified for printing.
    47 
    48 KNOWN LIMITATIONS
    49 =================
    50 
    51  * No option to select a more usual scale
    52  
  • applications/editors/josm/plugins/print/build.xml

    r27258 r27282  
    3030<project name="print" default="dist" basedir=".">
    3131    <!-- enter the SVN commit message -->
    32     <property name="commit.message" value="Added a print settings and preview dialog."/>
     32    <property name="commit.message" value="Added a field to specify the map scale."/>
    3333    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    3434    <property name="plugin.main.version" value="4549"/>
  • applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintDialog.java

    r27252 r27282  
    9292   
    9393    /**
     94     * The map scale
     95     */
     96    protected SpinnerNumberModel scaleModel;
     97   
     98    /**
    9499     * The page preview
    95100     */
    96101    protected PrintPreview printPreview;
     102   
     103    /**
     104     * The map view for preview an printing
     105     */
     106    protected PrintableMapView mapView;
    97107   
    98108    /**
     
    113123    public PrintDialog(Component parent) {
    114124        super(JOptionPane.getFrameForComponent(parent), tr("Print the Map"), ModalityType.DOCUMENT_MODAL);
     125        mapView = new PrintableMapView();
    115126        job = PrinterJob.getPrinterJob();
    116127        job.setJobName("JOSM Map");
     128        job.setPrintable(mapView);
    117129        build();
    118130        updateFields();
     
    165177       
    166178        int row = 0;
    167         caption = new JLabel(tr("Printer:"));
     179        caption = new JLabel(tr("Printer")+":");
    168180        add(caption, std.grid(2, row));
    169181        printerField = new JTextField();
     
    172184
    173185        row++;
    174         caption = new JLabel(tr("Paper:"));
     186        caption = new JLabel(tr("Media")+":");
    175187        add(caption, std.grid(2, row));
    176188        paperField = new JTextField();
     
    179191
    180192        row++;
    181         caption = new JLabel(tr("Orientation:"));
     193        caption = new JLabel(tr("Orientation")+":");
    182194        add(caption, std.grid(2, row));
    183195        orientationField = new JTextField();
     
    186198
    187199        row++;
    188         JButton printerButton = new JButton(tr("Printer settings..."));
     200        JButton printerButton = new JButton(tr("Printer settings")+"...");
    189201        printerButton.setActionCommand("printer-dialog");
    190202        printerButton.addActionListener(this);
     
    195207       
    196208        row++;
    197         caption = new JLabel(tr("Resolution (dpi):"));
     209        caption = new JLabel(tr("Scale")+":   1 : ");
     210        add(caption, std.grid(2, row));
     211        int mapScale = (int)Main.pref.getInteger("print.map-scale", PrintPlugin.DEF_MAP_SCALE);
     212        mapView.setFixedMapScale(mapScale);
     213        scaleModel = new SpinnerNumberModel(mapScale, 500, 5000000, 500);
     214        final JSpinner scaleField = new JSpinner(scaleModel);
     215        scaleField.addChangeListener(new ChangeListener() {
     216            public void stateChanged(ChangeEvent evt) {
     217                SwingUtilities.invokeLater(new Runnable() {
     218                    public void run() {
     219                        try {
     220                            scaleField.commitEdit();
     221                            Main.pref.put("print.map-scale",scaleModel.getNumber().toString());
     222                            mapView.setFixedMapScale(scaleModel.getNumber().intValue());
     223                            printPreview.repaint();
     224                        }
     225                        catch (ParseException pe) {
     226                            ; // NOP
     227                        }
     228                    }
     229                });
     230            }
     231        });
     232        add(scaleField, std.grid(3, row));
     233
     234        row++;
     235        caption = new JLabel(tr("Resolution")+":   (dpi)");
    198236        add(caption, std.grid(2, row));
    199237        resolutionModel = new SpinnerNumberModel(
     
    218256        });
    219257        add(resolutionField, std.grid(3, row));
    220 
    221         row++;
    222         caption = new JLabel(tr("Attribution:"));
     258       
     259        row++;
     260        caption = new JLabel(tr("Attribution")+":");
    223261        add(caption, std.grid(2, row));
    224262
     
    280318        printPreview = new PrintPreview();
    281319        if (previewCheckBox.isSelected()) {
    282             printPreview.setPrintable(new PrintableMapView());
     320            printPreview.setPrintable(mapView);
    283321        }
    284322        JScrollPane previewPane = new JScrollPane(printPreview, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
     
    355393            Main.pref.put("print.preview.enabled", previewCheckBox.isSelected());
    356394            if (previewCheckBox.isSelected() == true) {
    357                 printPreview.setPrintable(new PrintableMapView());
     395                printPreview.setPrintable(mapView);
    358396            }
    359397            else {
     
    375413        else if (cmd.equals("print")) {
    376414            try {
    377                 job.setPrintable(new PrintableMapView());
    378415                job.print(attrs);
    379416            }
  • applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintPlugin.java

    r27252 r27282  
    4747
    4848    /**
     49     * The default map scale
     50     */
     51    public static final int DEF_MAP_SCALE = 25000;
     52
     53    /**
    4954     * The default resolution
    5055     */
     
    8489
    8590        /* Make this plugin's preferences known */
     91        Main.pref.putDefault(
     92          "print.map-scale", Integer.toString(DEF_MAP_SCALE));
    8693        Main.pref.putDefault(
    8794          "print.resolution.dpi", Integer.toString(DEF_RESOLUTION_DPI));
  • applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintableMapView.java

    r27253 r27282  
    6060   
    6161    /**
     62     * A fixed map scale if greater than zero.
     63     */
     64    protected int fixedMapScale = 0;
     65   
     66    /**
    6267     * The factor for scaling the printing graphics to the desired
    6368     * resolution
     
    9398
    9499    /**
     100     * Set a fixed map scale 1 : "scale"
     101     *
     102     * @param scale the fixed map scale
     103     */
     104    public void setFixedMapScale(int scale) {
     105        this.fixedMapScale = scale;
     106        rezoomToFixedScale();
     107    }
     108
     109    /**
     110     * Unset the fixed map scale
     111     *
     112     * The map scaling will be chosen automatically such that the
     113     * main windows map view fits on the page format.
     114     */
     115    public void unsetFixedMapScale() {
     116        setFixedMapScale(0);
     117        rezoomToFixedScale();
     118    }
     119
     120    /**
     121     * Get the map scale that will be used for rendering
     122     */     
     123    public int getMapScale() {
     124        if (fixedMapScale > 0 || g2dFactor == 0.0) {
     125            return fixedMapScale;
     126        }
     127
     128        double dist100px = getDist100Pixel() / g2dFactor;
     129        int mapScale = (int) (dist100px * 72.0 / 2.54);
     130        return mapScale;
     131    }
     132
     133    /**
    95134     * Initialize the PrintableMapView for a particular combination of
    96135     * main MapView, PageFormat and target resolution
     
    101140        int resolution = Main.pref.getInteger("print.resolution.dpi", PrintPlugin.DEF_RESOLUTION_DPI);
    102141        g2dFactor = 72.0/resolution;
    103         double widthZoomFactor  = g2dFactor * mapView.getWidth()  / pageFormat.getImageableWidth();
    104         double heightZoomFactor = g2dFactor * mapView.getHeight() / pageFormat.getImageableHeight();
    105142        setSize((int)(pageFormat.getImageableWidth()/g2dFactor),(int)(pageFormat.getImageableHeight()/g2dFactor));
    106143    }
     
    115152            super.setSize(width, height);
    116153            zoomTo(mapView.getRealBounds());
     154            rezoomToFixedScale();
    117155        }
    118156    }
     
    127165            super.setSize(newSize);
    128166            zoomTo(mapView.getRealBounds());
    129         }
    130     }
    131            
     167            rezoomToFixedScale();
     168        }
     169    }
     170
     171    /**
     172     * Adjust the zoom as necessary to establish the fixed scale.
     173     */
     174    protected void rezoomToFixedScale() {
     175        if (fixedMapScale > 0) {
     176            double dist100px = getDist100Pixel() / g2dFactor;
     177            double mapScale = dist100px * 72.0 / 2.54;
     178            double mapFactor = fixedMapScale / mapScale;
     179            zoomToFactor(mapFactor);
     180        }
     181    }
    132182
    133183    /**
     
    174224        AffineTransform at = g2d.getTransform();
    175225        g2d.scale(g2dFactor, g2dFactor);
     226System.err.println(" used: "+g2dFactor);
    176227       
    177228        Bounds box = getRealBounds();
     
    271322       
    272323        /* lexical scale */
    273         int mapScale = (int) (dist100px * 72.0 / 2.54);
    274         String lexicalScale = tr("Scale 1 : {0}", mapScale);
     324        int mapScale = getMapScale();
     325        String lexicalScale = tr("Scale") + " 1 : " + mapScale;
    275326
    276327        Font scaleFront = new Font("Arial", Font.BOLD, FONT_SIZE);
Note: See TracChangeset for help on using the changeset viewer.