Changeset 27252 in osm for applications/editors/josm/plugins/print/src/org
- Timestamp:
- 2011-12-17T00:27:38+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintAction.java
r27046 r27252 28 28 import java.awt.event.ActionEvent; 29 29 import java.awt.event.KeyEvent; 30 import java.awt.print.*;31 30 32 import javax.swing. JOptionPane;31 import javax.swing.SwingUtilities; 33 32 34 33 import org.openstreetmap.josm.Main; … … 40 39 * and takes care of reasonable temporary adjustments to the preferences. 41 40 */ 42 public class PrintAction extends JosmAction {41 public class PrintAction extends JosmAction implements Runnable { 43 42 44 43 /** … … 56 55 57 56 /** 58 * Trigger the printing process.57 * Trigger the printing dialog. 59 58 * 60 59 * @param e not used. 61 60 */ 62 61 public void actionPerformed(ActionEvent e) { 63 PrinterJob job = PrinterJob.getPrinterJob(); 64 job.setPrintable(new PrintableMapView()); 65 if (job.printDialog()) { 66 try { 67 PrintPlugin.adjustPrefs(); 68 job.print(); 69 } 70 catch (PrinterAbortException ex) { 71 String msg = ex.getLocalizedMessage(); 72 if (msg.length() == 0) { 73 msg = tr("Printing has been cancelled."); 74 } 75 JOptionPane.showMessageDialog(Main.main.parent, msg, 76 tr("Printing stopped"), 77 JOptionPane.WARNING_MESSAGE); 78 } 79 catch (PrinterException ex) { 80 String msg = ex.getLocalizedMessage(); 81 if (msg.length() == 0) { 82 msg = tr("Printing has failed."); 83 } 84 JOptionPane.showMessageDialog(Main.main.parent, msg, 85 tr("Printing stopped"), 86 JOptionPane.ERROR_MESSAGE); 87 } 88 finally { 89 PrintPlugin.restorePrefs(); 90 } 91 } 62 // Allow the JOSM GUI to be redrawn before modifying preferences 63 SwingUtilities.invokeLater(this); 92 64 } 93 65 66 /** 67 * Open the printing dialog 68 * 69 * This will temporarily modify the mappaint preferences. 70 */ 71 public void run () { 72 PrintPlugin.adjustPrefs(); 73 PrintDialog window = new PrintDialog(Main.main.parent); 74 window.setVisible(true); 75 PrintPlugin.restorePrefs(); 76 } 94 77 } -
applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintPlugin.java
r27046 r27252 23 23 24 24 package org.openstreetmap.josm.plugins.print; 25 26 import java.awt.Toolkit; 25 27 26 28 import javax.swing.JMenu; … … 47 49 * The default resolution 48 50 */ 49 public static final int DEF_RESOLUTION_DPI = 200;51 public static final int DEF_RESOLUTION_DPI = 100; 50 52 51 53 /** … … 86 88 Main.pref.putDefault( 87 89 "print.attribution", DEF_ATTRIBUTION); 90 Main.pref.putDefault( 91 "print.preview.enabled", new Boolean(false).toString()); 88 92 89 93 restorePrefs(); // Recover after crash if neccesseary … … 183 187 restorePref("mappaint.node.virtual-size"); 184 188 Main.pref.put("print.saved-prefs", false); 189 //Main.main.map.mapView.repaint(); 185 190 } 186 191 } -
applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintableMapView.java
r27066 r27252 27 27 28 28 import java.awt.Color; 29 import java.awt.Dimension; 29 30 import java.awt.Font; 30 31 import java.awt.Graphics; … … 57 58 public class PrintableMapView extends MapView implements Printable { 58 59 59 /**60 * Indicates that the instance has been initialized61 */62 protected boolean initialized;63 64 60 /** 65 61 * The factor for scaling the printing graphics to the desired … … 93 89 94 90 mapView = Main.main.map.mapView; 95 initialized = false;96 91 } 97 92 … … 108 103 double heightZoomFactor = g2dFactor * mapView.getHeight() / pageFormat.getImageableHeight(); 109 104 setSize((int)(pageFormat.getImageableWidth()/g2dFactor),(int)(pageFormat.getImageableHeight()/g2dFactor)); 110 zoomTo(mapView.getRealBounds()); 111 } 105 } 106 107 /** 108 * Resizes this component. 109 */ 110 @Override 111 public void setSize(int width, int height) { 112 Dimension dim = getSize(); 113 if (dim.width != width || dim.height != height) { 114 super.setSize(width, height); 115 zoomTo(mapView.getRealBounds()); 116 } 117 } 118 119 /** 120 * Resizes this component. 121 */ 122 @Override 123 public void setSize(Dimension newSize) { 124 Dimension dim = getSize(); 125 if (dim.width != newSize.width || dim.height != newSize.height) { 126 super.setSize(newSize); 127 zoomTo(mapView.getRealBounds()); 128 } 129 } 130 112 131 113 132 /** … … 129 148 PrinterException { 130 149 if (page > 0) { /* stop after first page */ 131 initialized = false;132 150 return NO_SUCH_PAGE; 133 151 } 134 else if (! initialized) { 135 initialize(pageFormat); 136 initialized = true; 137 } 152 153 initialize(pageFormat); 138 154 139 155 Graphics2D g2d = (Graphics2D)g; … … 324 340 layers, 325 341 new Comparator<Layer>() { 342 @Override 326 343 public int compare(Layer l2, Layer l1) { // l1 and l2 swapped! 327 344 if (l1 instanceof OsmDataLayer && l2 instanceof OsmDataLayer) {
Note:
See TracChangeset
for help on using the changeset viewer.