Changeset 27282 in osm for applications/editors/josm/plugins/print
- Timestamp:
- 2011-12-19T00:21:25+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/print
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/print/README
r27258 r27282 25 25 =========== 26 26 27 print.map-scale (integer): 28 The map scale x as in 1:x. 29 Default: 25.000 30 27 31 print.attribution (string): 28 32 The attribution text which will be printed on the page. … … 45 49 Not really user preferences, but a mechanism to reliable backup and 46 50 restore mappaint preferences which are temporary modified for printing. 47 48 KNOWN LIMITATIONS49 =================50 51 * No option to select a more usual scale52 -
applications/editors/josm/plugins/print/build.xml
r27258 r27282 30 30 <project name="print" default="dist" basedir="."> 31 31 <!-- 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."/> 33 33 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 34 34 <property name="plugin.main.version" value="4549"/> -
applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintDialog.java
r27252 r27282 92 92 93 93 /** 94 * The map scale 95 */ 96 protected SpinnerNumberModel scaleModel; 97 98 /** 94 99 * The page preview 95 100 */ 96 101 protected PrintPreview printPreview; 102 103 /** 104 * The map view for preview an printing 105 */ 106 protected PrintableMapView mapView; 97 107 98 108 /** … … 113 123 public PrintDialog(Component parent) { 114 124 super(JOptionPane.getFrameForComponent(parent), tr("Print the Map"), ModalityType.DOCUMENT_MODAL); 125 mapView = new PrintableMapView(); 115 126 job = PrinterJob.getPrinterJob(); 116 127 job.setJobName("JOSM Map"); 128 job.setPrintable(mapView); 117 129 build(); 118 130 updateFields(); … … 165 177 166 178 int row = 0; 167 caption = new JLabel(tr("Printer :"));179 caption = new JLabel(tr("Printer")+":"); 168 180 add(caption, std.grid(2, row)); 169 181 printerField = new JTextField(); … … 172 184 173 185 row++; 174 caption = new JLabel(tr(" Paper:"));186 caption = new JLabel(tr("Media")+":"); 175 187 add(caption, std.grid(2, row)); 176 188 paperField = new JTextField(); … … 179 191 180 192 row++; 181 caption = new JLabel(tr("Orientation :"));193 caption = new JLabel(tr("Orientation")+":"); 182 194 add(caption, std.grid(2, row)); 183 195 orientationField = new JTextField(); … … 186 198 187 199 row++; 188 JButton printerButton = new JButton(tr("Printer settings ..."));200 JButton printerButton = new JButton(tr("Printer settings")+"..."); 189 201 printerButton.setActionCommand("printer-dialog"); 190 202 printerButton.addActionListener(this); … … 195 207 196 208 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)"); 198 236 add(caption, std.grid(2, row)); 199 237 resolutionModel = new SpinnerNumberModel( … … 218 256 }); 219 257 add(resolutionField, std.grid(3, row)); 220 221 row++; 222 caption = new JLabel(tr("Attribution :"));258 259 row++; 260 caption = new JLabel(tr("Attribution")+":"); 223 261 add(caption, std.grid(2, row)); 224 262 … … 280 318 printPreview = new PrintPreview(); 281 319 if (previewCheckBox.isSelected()) { 282 printPreview.setPrintable( new PrintableMapView());320 printPreview.setPrintable(mapView); 283 321 } 284 322 JScrollPane previewPane = new JScrollPane(printPreview, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); … … 355 393 Main.pref.put("print.preview.enabled", previewCheckBox.isSelected()); 356 394 if (previewCheckBox.isSelected() == true) { 357 printPreview.setPrintable( new PrintableMapView());395 printPreview.setPrintable(mapView); 358 396 } 359 397 else { … … 375 413 else if (cmd.equals("print")) { 376 414 try { 377 job.setPrintable(new PrintableMapView());378 415 job.print(attrs); 379 416 } -
applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintPlugin.java
r27252 r27282 47 47 48 48 /** 49 * The default map scale 50 */ 51 public static final int DEF_MAP_SCALE = 25000; 52 53 /** 49 54 * The default resolution 50 55 */ … … 84 89 85 90 /* Make this plugin's preferences known */ 91 Main.pref.putDefault( 92 "print.map-scale", Integer.toString(DEF_MAP_SCALE)); 86 93 Main.pref.putDefault( 87 94 "print.resolution.dpi", Integer.toString(DEF_RESOLUTION_DPI)); -
applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintableMapView.java
r27253 r27282 60 60 61 61 /** 62 * A fixed map scale if greater than zero. 63 */ 64 protected int fixedMapScale = 0; 65 66 /** 62 67 * The factor for scaling the printing graphics to the desired 63 68 * resolution … … 93 98 94 99 /** 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 /** 95 134 * Initialize the PrintableMapView for a particular combination of 96 135 * main MapView, PageFormat and target resolution … … 101 140 int resolution = Main.pref.getInteger("print.resolution.dpi", PrintPlugin.DEF_RESOLUTION_DPI); 102 141 g2dFactor = 72.0/resolution; 103 double widthZoomFactor = g2dFactor * mapView.getWidth() / pageFormat.getImageableWidth();104 double heightZoomFactor = g2dFactor * mapView.getHeight() / pageFormat.getImageableHeight();105 142 setSize((int)(pageFormat.getImageableWidth()/g2dFactor),(int)(pageFormat.getImageableHeight()/g2dFactor)); 106 143 } … … 115 152 super.setSize(width, height); 116 153 zoomTo(mapView.getRealBounds()); 154 rezoomToFixedScale(); 117 155 } 118 156 } … … 127 165 super.setSize(newSize); 128 166 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 } 132 182 133 183 /** … … 174 224 AffineTransform at = g2d.getTransform(); 175 225 g2d.scale(g2dFactor, g2dFactor); 226 System.err.println(" used: "+g2dFactor); 176 227 177 228 Bounds box = getRealBounds(); … … 271 322 272 323 /* 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; 275 326 276 327 Font scaleFront = new Font("Arial", Font.BOLD, FONT_SIZE);
Note:
See TracChangeset
for help on using the changeset viewer.