Changeset 34541 in osm
- Timestamp:
- 2018-08-18T19:24:07+02:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/pdfimport
- Files:
-
- 44 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pdfimport/.classpath
r32680 r34541 3 3 <classpathentry kind="src" path="src"/> 4 4 <classpathentry kind="src" path="resources"/> 5 <classpathentry kind="src" path="test/unit"/> 5 <classpathentry kind="src" output="bintest" path="test/unit"> 6 <attributes> 7 <attribute name="test" value="true"/> 8 </attributes> 9 </classpathentry> 6 10 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> 7 11 <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/> -
applications/editors/josm/plugins/pdfimport/build.xml
r34436 r34541 4 4 <property name="commit.message" value="bug fix"/> 5 5 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 6 <property name="plugin.main.version" value="1 2678"/>6 <property name="plugin.main.version" value="14153"/> 7 7 <property name="plugin.canloadatruntime" value="true"/> 8 8 <!-- Configure these properties (replace "..." accordingly). -
applications/editors/josm/plugins/pdfimport/src/pdfimport/FilePlacement.java
r34398 r34541 14 14 15 15 public class FilePlacement { 16 17 18 19 16 /* 17 * provide data and services to place a PDF-File to world coordinates 18 * enhanced by FilePlacement18 but kept for compatibilty to existing code 19 */ 20 20 protected Projection projection = null; 21 21 protected double minX = 0; -
applications/editors/josm/plugins/pdfimport/src/pdfimport/FilePlacement18.java
r34440 r34541 34 34 35 35 public class FilePlacement18 extends FilePlacement { 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 private void checkCoords(GuiFieldDouble x, GuiFieldDouble y) {54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 public CoorFields(GuiFieldDouble X, GuiFieldDouble Y) {70 x = X;71 y = Y;72 73 74 75 76 77 78 79 80 81 82 83 84 x.requestFocusInWindow();// make shure focus-lost events will be triggered later85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 private FilePlacement18 fc = null;// reference to enclosing FilePlacement112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 36 /* 37 * Handle plasement of a pdf File 38 * provide transformation, load & save, GUI-componennt 39 * superseeds (legacy) class FilePlacement 40 */ 41 42 public class PlacementPanel { 43 private class CoorFields { 44 /* 45 * Coordinte Fields 46 * keep Fields representing a Coordinate together 47 * functionality: allow entering coordinate in the first field and transfer Y-Part to the second field 48 * TODO: encapsulate to Componente 49 */ 50 private GuiFieldDouble x; 51 private GuiFieldDouble y; 52 53 private void checkCoords(GuiFieldDouble x, GuiFieldDouble y) { 54 int splitpos = 0; 55 String val2 = x.getText().trim(); 56 if ((splitpos = val2.indexOf(';')) >= 0) { 57 // Split a coordinate into its parts for ease of data entry 58 y.setText(val2.substring(splitpos + 1).trim()); 59 x.setText(val2.substring(0, splitpos).trim()); 60 } 61 y.checker.check(y); 62 x.checker.check(x); 63 } 64 65 @SuppressWarnings("unused") 66 private CoorFields() { 67 } 68 69 CoorFields(GuiFieldDouble x, GuiFieldDouble y) { 70 this.x = x; 71 this.y = y; 72 x.addFocusListener(new FocusListener() { 73 @Override 74 public void focusLost(FocusEvent e) { 75 checkCoords(x, y); 76 } 77 78 @Override 79 public void focusGained(FocusEvent e) { 80 } 81 }); 82 } 83 public void SetCoor(EastNorth en) { 84 x.requestFocusInWindow(); // make shure focus-lost events will be triggered later 85 x.setValue(en.getX()); 86 y.requestFocusInWindow(); 87 y.setValue(en.getY()); 88 } 89 public EastNorth getCorr() { 90 return new EastNorth(x.getValue(),y.getValue()); 91 } 92 } 93 94 private GuiFieldDouble minXField; 95 private GuiFieldDouble minYField; 96 private GuiFieldDouble minEastField; 97 private GuiFieldDouble minNorthField; 98 private JButton getMinButton; 99 private JButton getMaxButton; 100 private GuiFieldDouble maxNorthField; 101 private GuiFieldDouble maxEastField; 102 private GuiFieldDouble maxYField; 103 private GuiFieldDouble maxXField; 104 private GuiPanel panel; 105 private JLabel hintField; 106 private CoorFields pdfMin; 107 private CoorFields pdfMax; 108 private CoorFields worldMin; 109 private CoorFields worldMax; 110 private GuiProjections projectionChooser; 111 private FilePlacement18 fc = null; // reference to enclosing FilePlacement 112 private JComponent dependsOnValid = null; 113 114 public PlacementPanel(FilePlacement18 parrent) { 115 if (parrent==null) throw new IllegalArgumentException(); 116 fc=parrent; 117 } 118 119 private PlacementPanel () { 120 121 } 122 123 private class Monitor implements FocusListener { 124 125 private PlacementPanel target=null; 126 127 public Monitor(PlacementPanel home) { 128 target=home; 129 } 130 131 @Override 132 public void focusGained(FocusEvent e) { 133 } 134 135 @Override 136 public void focusLost(FocusEvent e) { 137 try { 138 target.Verify(); 139 } catch (Exception ee) { 140 } 141 } 142 } 143 144 void load() { 145 /* 146 * load GUI from setting 147 */ 148 try { 149 minXField.setValue(fc.minX); 150 maxXField.setValue(fc.maxX); 151 minYField.setValue(fc.minY); 152 maxYField.setValue(fc.maxY); 153 minEastField.setValue(fc.minEast); 154 maxEastField.setValue(fc.maxEast); 155 minNorthField.setValue(fc.minNorth); 156 maxNorthField.setValue(fc.maxNorth); 157 projectionChooser.setProjection(fc.projection); 158 } finally { 159 Verify(); 160 } 161 } 162 163 void build() { 164 164 /* 165 165 * Construct Objects 166 166 * 167 167 */ 168 169 170 171 172 173 174 175 176 177 // 178 179 180 181 182 183 // 184 185 186 187 188 189 190 191 192 // 193 194 195 196 197 198 // 199 worldMax = new CoorFields(maxEastField = new GuiFieldDouble(1),maxNorthField = new GuiFieldDouble(1));200 201 202 203 204 // 205 206 207 208 209 210 211 212 213 214 // 215 216 217 // 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 // 309 // 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 168 Monitor monitor = new Monitor(this); 169 projectionChooser = new GuiProjections(); 170 171 pdfMin = new CoorFields(minXField = new GuiFieldDouble(0), minYField = new GuiFieldDouble(0)); 172 minXField.setToolTipText(tr("X-value of bottom left reference point")); 173 minXField.addFocusListener(monitor); 174 minYField.setToolTipText(tr("Y-value of bottom left reference point")); 175 minYField.addFocusListener(monitor); 176 177 // 178 worldMin = new CoorFields(minEastField = new GuiFieldDouble(0), minNorthField = new GuiFieldDouble(0)); 179 minEastField.setToolTipText(tr("East-value of bottom left reference point")); 180 minEastField.addFocusListener(monitor); 181 minNorthField.setToolTipText(tr("North-value of bottom left reference point")); 182 minNorthField.addFocusListener(monitor); 183 // 184 getMinButton = new JButton(tr("Get from Preview")); 185 getMinButton.setToolTipText(tr("Select a single node from preview")); 186 getMinButton.addActionListener(new ActionListener() { 187 @Override 188 public void actionPerformed(ActionEvent e) { 189 setFromCoor(pdfMin); 190 } 191 }); 192 // 193 pdfMax = new CoorFields(maxXField = new GuiFieldDouble(1000), maxYField = new GuiFieldDouble(1000)); 194 maxXField.setToolTipText(tr("X-value of top right reference point")); 195 maxXField.addFocusListener(monitor); 196 maxYField.setToolTipText(tr("Y-value of top right reference point")); 197 maxYField.addFocusListener(monitor); 198 // 199 worldMax = new CoorFields(maxEastField = new GuiFieldDouble(1), maxNorthField = new GuiFieldDouble(1)); 200 maxEastField.setToolTipText(tr("East-value of top right reference point")); 201 maxEastField.addFocusListener(monitor); 202 maxNorthField.setToolTipText(tr("North-value of top right reference point")); 203 maxNorthField.addFocusListener(monitor); 204 // 205 getMaxButton = new JButton(tr("Get from Preview")); 206 getMaxButton.setToolTipText(tr("Select a single node from preview")); 207 getMaxButton.addActionListener(new ActionListener() { 208 @Override 209 public void actionPerformed(ActionEvent e) { 210 setFromCoor(pdfMax); 211 } 212 }); 213 214 // 215 hintField = new JLabel(tr("Check Placement"),SwingConstants.CENTER); 216 hintField.setForeground(Color.RED); 217 // 218 panel = new GuiPanel(new GridBagLayout()); 219 panel.setBorder(BorderFactory.createTitledBorder(tr("Bind to coordinates"))); 220 221 GridBagConstraints cBasic = new GridBagConstraints(GridBagConstraints.RELATIVE, GridBagConstraints.RELATIVE, 222 1, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, 223 new Insets(1, 0, 0, 4), 0, 0); 224 cBasic.gridx = GridBagConstraints.RELATIVE; 225 cBasic.gridy = GridBagConstraints.RELATIVE; 226 cBasic.insets = new Insets(1, 0, 0, 4); 227 cBasic.anchor = GridBagConstraints.LINE_START; 228 cBasic.fill = GridBagConstraints.HORIZONTAL; 229 cBasic.gridheight = 1; 230 cBasic.gridwidth = 1; 231 cBasic.ipadx = 0; 232 cBasic.ipady = 0; 233 cBasic.weightx = 0.0; 234 cBasic.weighty = 0.0; 235 GridBagConstraints cCornerHeading = (GridBagConstraints) cBasic.clone(); 236 cCornerHeading.gridwidth = GridBagConstraints.REMAINDER; 237 cCornerHeading.gridx = 0; 238 cCornerHeading.insets = new Insets(3, 0, 0, 0); 239 240 GridBagConstraints cLine = (GridBagConstraints) cBasic.clone(); 241 242 GridBagConstraints cGetButton = (GridBagConstraints) cBasic.clone(); 243 cGetButton.gridx = 1; 244 cGetButton.gridwidth = GridBagConstraints.REMAINDER; 245 cGetButton.fill = GridBagConstraints.NONE; 246 247 GridBagConstraints c = new GridBagConstraints(); 248 /* 249 * Projection 250 */ 251 panel.add(projectionChooser.getPanel(), cCornerHeading); 252 /* 253 * Max Corner 254 */ 255 panel.add(new JLabel(tr("Top right (max) corner:"),SwingConstants.CENTER), cCornerHeading); 256 c = (GridBagConstraints) cLine.clone(); 257 c.weightx = 0.0; panel.add(new JLabel(tr("X:"),SwingConstants.RIGHT),c); 258 c.weightx = 1.0; panel.add(maxXField, c); 259 c.weightx = 0.0; panel.add(new JLabel(tr("East:"),SwingConstants.RIGHT),c); 260 c.weightx = 1.0; panel.add(maxEastField, c); 261 262 c.gridy = 4; 263 c.weightx = 0.0; panel.add(new JLabel(tr("Y:"),SwingConstants.RIGHT),c); 264 c.weightx = 1.0; panel.add(maxYField, c); 265 c.weightx = 0.0; panel.add(new JLabel(tr("North:"),SwingConstants.RIGHT),c); 266 c.weightx = 1.0; panel.add(maxNorthField, c); 267 panel.add(getMaxButton, cGetButton); 268 /* 269 * Min Corner 270 */ 271 panel.add(new JLabel(tr("Bottom left (min) corner:"),SwingConstants.CENTER), cCornerHeading); 272 c = (GridBagConstraints) cLine.clone(); 273 c.weightx = 0.0; panel.add(new JLabel(tr("X:"),SwingConstants.RIGHT),c); 274 c.weightx = 1.0; panel.add(minXField, c); 275 c.weightx = 0.0; panel.add(new JLabel(tr("East:"),SwingConstants.RIGHT),c); 276 c.weightx = 1.0; panel.add(minEastField, c); 277 278 c.gridy = 8; 279 c.weightx = 0.0; panel.add(new JLabel(tr("Y:"),SwingConstants.RIGHT),c); 280 c.weightx = 1.0; panel.add(minYField, c); 281 c.weightx = 0.0; panel.add(new JLabel(tr("North:"),SwingConstants.RIGHT),c); 282 c.weightx = 1.0; panel.add(minNorthField, c); 283 284 panel.add(getMinButton, cGetButton); 285 /* 286 * Hints 287 */ 288 c.gridx = 0;c.gridy = 11;c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; 289 panel.add(hintField, cGetButton); 290 } 291 292 private EastNorth getSelectedCoor() { 293 /* 294 * Assumtions: 295 * selection is from preview, 296 * preview has been create without any projection / transformation 297 * TODO: enshure this 298 */ 299 hintField.setText(""); 300 Collection<OsmPrimitive> selected = MainApplication.getLayerManager().getEditDataSet().getSelected(); 301 302 if (selected.size() != 1 || !(selected.iterator().next() instanceof Node)) { 303 hintField.setText(tr("Please select exactly one node.")); 304 return null; 305 } 306 307 LatLon ll = ((Node) selected.iterator().next()).getCoor(); 308 // FilePlacement pl = new FilePlacement(); 309 // return pl.reverseTransform(ll); 310 return new EastNorth(ll.lon() * 1000, ll.lat() * 1000); 311 } 312 313 private void Verify() { 314 hintField.setText(""); 315 String Hint = ""; 316 fc.valid = false; 317 FilePlacement placement = fc; 318 try { 319 placement.projection = projectionChooser.getProjection(); 320 try { 321 placement.setPdfBounds(minXField.getValue(), minYField.getValue(), maxXField.getValue(), 322 maxYField.getValue()); 323 placement.setEastNorthBounds(minEastField.getValue(), minNorthField.getValue(), 324 maxEastField.getValue(), maxNorthField.getValue()); 325 } catch (Exception e) { 326 Hint=(tr("Check numbers")); 327 return; 328 } 329 String transformError = placement.prepareTransform(); 330 if (transformError != null) { 331 Hint=(transformError); 332 return; 333 } 334 fc.valid = true; 335 } finally { 336 hintField.setText(Hint); 337 if (dependsOnValid!=null) dependsOnValid.setEnabled(fc.valid && panel.isEnabled()); 338 } 339 340 return; 341 } 342 343 public void setDependsOnValid(JComponent c) { 344 dependsOnValid=c; 345 } 346 347 void setFromCoor(CoorFields f) { 348 EastNorth en = getSelectedCoor(); 349 350 if (en != null) { 351 f.SetCoor(en); 352 } 353 354 } 355 356 } 357 357 358 358 private PlacementPanel panel=null; 359 private boolean valid=false; 359 private boolean valid=false; // the data is consistent and the object ready to use for transformation 360 360 361 361 public boolean isValid() { 362 363 364 365 366 } 367 368 369 362 /* 363 * TODO: compupte it now 364 */ 365 return valid; 366 } 367 public void setDependsOnValid(JComponent c) { 368 panel.setDependsOnValid(c); 369 } 370 370 371 371 public JPanel getGui() { 372 373 374 372 if (panel==null) panel = new PlacementPanel(this); 373 if (panel.panel==null) panel.build(); 374 return panel.panel; 375 375 } 376 376 377 377 public FilePlacement18 () { 378 379 } 380 381 382 383 384 385 386 387 388 389 390 391 392 393 378 panel = new PlacementPanel(this); 379 } 380 381 public void load(File baseFile) throws IOException { 382 File file = new File(baseFile + ".placement"); 383 Properties p = new Properties(); 384 try (FileInputStream s = new FileInputStream(file)){ 385 p.load(s); 386 s.close(); 387 }; 388 fromProperties(p); 389 } 390 391 public void verify() { 392 panel.Verify(); 393 } 394 394 395 395 public void save(File baseFile) throws IOException { 396 397 398 399 400 396 File file = new File(baseFile + ".placement"); 397 FileOutputStream s = new FileOutputStream(file); 398 Properties p = toProperties(); 399 p.store(s, "PDF file placement on OSM"); 400 s.close(); 401 401 } 402 402 … … 406 406 return ProjectionInfo.getProjectionByCode(p.getProperty("Projection", null)); 407 407 } 408 408 return null; 409 409 } 410 410 411 411 private double getDouble(Properties p, String name, double defaultValue) { 412 413 414 415 416 412 try { 413 return Double.parseDouble(p.getProperty(name)); 414 } catch (Exception e) { 415 return defaultValue; 416 } 417 417 } 418 418 419 419 @Override 420 421 422 420 protected void fromProperties(Properties p) { 421 super.fromProperties(p); 422 panel.load(); 423 423 } 424 424 -
applications/editors/josm/plugins/pdfimport/src/pdfimport/GuiFieldBool.java
r34421 r34541 11 11 12 12 public class GuiFieldBool extends JCheckBox { 13 14 15 16 17 13 /* 14 * TODO: evolve to a component with integrated display of dependend components 15 */ 16 private JComponent companion =null; 17 private boolean value = false; 18 18 19 20 21 19 public JComponent getCompanion() { 20 return companion; 21 } 22 22 23 24 25 26 23 public void setCompanion(JComponent c) { 24 companion = c; 25 if (companion != null) companion.setEnabled(isSelected()); 26 } 27 27 28 29 30 28 public boolean getValue() { 29 return super.isSelected(); 30 } 31 31 32 33 34 35 32 public void setValue(boolean value) { 33 this.value = value; 34 super.setSelected(value); 35 } 36 36 37 38 39 40 37 public GuiFieldBool() { 38 super(); 39 addChangeListener(new Monitor()); 40 } 41 41 42 43 44 45 42 public GuiFieldBool(Action a) { 43 super(a); 44 addChangeListener(new Monitor()); 45 } 46 46 47 48 49 50 47 public GuiFieldBool(Icon icon, boolean selected) { 48 super(icon, selected); 49 addChangeListener(new Monitor()); 50 } 51 51 52 53 54 55 52 public GuiFieldBool(Icon icon) { 53 super(icon); 54 addChangeListener(new Monitor()); 55 } 56 56 57 58 59 60 57 public GuiFieldBool(String text, boolean selected) { 58 super(text, selected); 59 addChangeListener(new Monitor()); 60 } 61 61 62 63 64 65 62 public GuiFieldBool(String text, Icon icon, boolean selected) { 63 super(text, icon, selected); 64 addChangeListener(new Monitor()); 65 } 66 66 67 68 69 70 67 public GuiFieldBool(String text, Icon icon) { 68 super(text, icon); 69 addChangeListener(new Monitor()); 70 } 71 71 72 73 74 75 72 public GuiFieldBool(String text) { 73 super(text); 74 addChangeListener(new Monitor()); 75 } 76 76 77 77 private class Monitor implements ChangeListener { 78 78 79 80 81 82 83 84 85 79 @Override 80 public void stateChanged(ChangeEvent e) { 81 GuiFieldBool o = (GuiFieldBool) e.getSource(); 82 value = o.isSelected(); 83 if (o.companion != null) o.companion.setEnabled(value); 84 } 85 } 86 86 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/GuiFieldDouble.java
r34398 r34541 11 11 public class GuiFieldDouble extends GuiFieldString { 12 12 13 14 13 private double value; 14 public CheckDouble checker; 15 15 16 17 18 19 20 16 public GuiFieldDouble() { 17 super(); 18 addFocusListener(checker = new CheckDouble()); 19 setValue(0.0); 20 } 21 21 22 23 24 25 26 22 @SuppressWarnings("unused") 23 private GuiFieldDouble(String text) { 24 super(text); 25 addFocusListener(checker = new CheckDouble()); 26 } 27 27 28 29 30 31 32 28 public GuiFieldDouble(double v) { 29 super(); 30 addFocusListener(checker = new CheckDouble()); 31 setValue(v); 32 } 33 33 34 35 36 37 34 public void setValue(double v) { 35 super.setText(Double.toString(v)); 36 this.checker.check(this); 37 } 38 38 39 40 41 42 39 public double getValue() throws NumberFormatException { 40 if (!dataValid) throw new NumberFormatException(); 41 return value; 42 } 43 43 44 44 public class CheckDouble implements FocusListener { 45 45 46 47 48 46 @Override 47 public void focusGained(FocusEvent e) { 48 } 49 49 50 51 52 53 50 @Override 51 public void focusLost(FocusEvent event) { 52 check((GuiFieldDouble) event.getSource()); 53 } 54 54 55 56 57 58 59 60 61 62 63 64 65 66 55 public void check(GuiFieldDouble field) { 56 try { 57 value = Double.parseDouble(field.getText()); 58 dataValid =true; 59 field.setBorder(defaultBorder); 60 } catch (NumberFormatException e) { 61 field.setBorder(BorderFactory.createLineBorder(Color.red)); 62 value = Double.NaN; 63 dataValid = false; 64 } 65 } 66 } 67 67 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/GuiFieldHex.java
r34398 r34541 16 16 public class GuiFieldHex extends GuiFieldString { 17 17 18 19 18 private int value; 19 public CheckHex checker; 20 20 21 22 23 24 25 21 public GuiFieldHex() { 22 super(); 23 addFocusListener(checker = new CheckHex()); 24 setValue(0); 25 } 26 26 27 28 29 30 31 27 @SuppressWarnings("unused") 28 public GuiFieldHex(String text) { 29 super(text); 30 addFocusListener(checker = new CheckHex()); 31 } 32 32 33 34 35 36 37 33 public GuiFieldHex(int v) { 34 super(); 35 addFocusListener(checker = new CheckHex()); 36 setValue(v); 37 } 38 38 39 40 41 42 43 39 public void setValue(int v) { 40 super.setText("#" + Integer.toHexString(v)); 41 value=v; 42 this.checker.check(this); 43 } 44 44 45 46 47 48 45 public int getValue() throws NumberFormatException { 46 if (!dataValid) throw new NumberFormatException(); 47 return value; 48 } 49 49 50 51 52 53 54 50 @Override 51 public void setEnabled(boolean enabled) { 52 super.setEnabled(enabled); 53 this.checker.check(this); 54 } 55 55 56 56 public class CheckHex implements FocusListener { 57 57 58 59 60 58 @Override 59 public void focusGained(FocusEvent e) { 60 } 61 61 62 63 64 65 62 @Override 63 public void focusLost(FocusEvent event) { 64 check((GuiFieldHex) event.getSource()); 65 } 66 66 67 68 69 70 // 71 72 73 74 75 76 77 78 67 public void check(GuiFieldHex field) { 68 try { 69 value = Integer.decode(field.getText()); 70 // value = Integer.parseUnsignedInt(field.getText().replace("#", ""), 16); 71 dataValid = true; 72 field.setBorder(defaultBorder); 73 } catch (NumberFormatException e) { 74 field.setBorder(BorderFactory.createLineBorder(Color.red)); 75 dataValid = false; 76 } 77 } 78 } 79 79 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/GuiFieldInteger.java
r34398 r34541 12 12 public class GuiFieldInteger extends GuiFieldString { 13 13 14 15 14 private int value; 15 public CheckInteger checker; 16 16 17 18 19 20 21 17 public GuiFieldInteger() { 18 super(); 19 addFocusListener(checker = new CheckInteger()); 20 setValue(0); 21 } 22 22 23 24 25 26 27 23 @SuppressWarnings("unused") 24 private GuiFieldInteger(String text) { 25 super(text); 26 addFocusListener(checker = new CheckInteger()); 27 } 28 28 29 30 31 32 33 29 public GuiFieldInteger(int v) { 30 super(); 31 addFocusListener(checker = new CheckInteger()); 32 setValue(v); 33 } 34 34 35 36 37 38 39 35 public void setValue(int v) { 36 super.setText(Integer.toString(v)); 37 value=v; 38 this.checker.check(this); 39 } 40 40 41 42 43 44 41 public int getValue() throws NumberFormatException { 42 if (!dataValid) throw new NumberFormatException(); 43 return value; 44 } 45 45 46 46 public class CheckInteger implements FocusListener { 47 47 48 49 50 48 @Override 49 public void focusGained(FocusEvent e) { 50 } 51 51 52 53 54 55 52 @Override 53 public void focusLost(FocusEvent event) { 54 check((GuiFieldInteger) event.getSource()); 55 } 56 56 57 58 59 60 61 62 63 64 65 66 67 57 public void check(GuiFieldInteger field) { 58 try { 59 value = Integer.valueOf(field.getText()); 60 dataValid = true; 61 field.setBorder(defaultBorder); 62 } catch (NumberFormatException e) { 63 field.setBorder(BorderFactory.createLineBorder(Color.red)); 64 dataValid = false; 65 } 66 } 67 } 68 68 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/GuiFieldLong.java
r34398 r34541 12 12 public class GuiFieldLong extends GuiFieldString { 13 13 14 15 14 private long value; 15 public CheckLong checker; 16 16 17 18 19 20 21 17 public GuiFieldLong() { 18 super(); 19 addFocusListener(checker = new CheckLong()); 20 setValue(0); 21 } 22 22 23 24 25 26 27 23 @SuppressWarnings("unused") 24 private GuiFieldLong(String text) { 25 super(text); 26 addFocusListener(checker = new CheckLong()); 27 } 28 28 29 30 31 32 33 29 public GuiFieldLong(long v) { 30 super(); 31 addFocusListener(checker = new CheckLong()); 32 setValue(v); 33 } 34 34 35 36 37 38 39 35 public void setValue(long v) { 36 super.setText(Long.toString(v)); 37 value=v; 38 this.checker.check(this); 39 } 40 40 41 42 43 44 41 public long getValue() throws NumberFormatException { 42 if (!dataValid) throw new NumberFormatException(); 43 return value; 44 } 45 45 46 46 public class CheckLong implements FocusListener { 47 47 48 49 50 48 @Override 49 public void focusGained(FocusEvent e) { 50 } 51 51 52 53 54 55 52 @Override 53 public void focusLost(FocusEvent event) { 54 check((GuiFieldLong) event.getSource()); 55 } 56 56 57 58 59 60 61 62 63 64 65 66 67 57 public void check(GuiFieldLong field) { 58 try { 59 value = Long.valueOf(field.getText()); 60 dataValid = true; 61 field.setBorder(defaultBorder); 62 } catch (NumberFormatException e) { 63 field.setBorder(BorderFactory.createLineBorder(Color.red)); 64 dataValid = false; 65 } 66 } 67 } 68 68 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/GuiFieldString.java
r34422 r34541 7 7 8 8 public class GuiFieldString extends JTextField { 9 10 11 9 /* 10 * TODO: integrate presentation of dataValid; 11 */ 12 12 13 14 13 protected Border defaultBorder; 14 protected boolean dataValid; 15 15 16 17 18 19 16 public GuiFieldString() { 17 super(); 18 defaultBorder = getBorder(); 19 } 20 20 21 22 23 24 21 public GuiFieldString(String text) { 22 super(text); 23 defaultBorder = getBorder(); 24 } 25 25 26 27 28 26 public boolean isDataValid() { 27 return dataValid; 28 } 29 29 30 30 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/GuiPanel.java
r34398 r34541 10 10 public class GuiPanel extends JPanel{ 11 11 12 13 14 12 public GuiPanel() { 13 super(); 14 } 15 15 16 17 18 16 public GuiPanel(LayoutManager layout) { 17 super(layout); 18 } 19 19 20 21 22 23 24 25 26 20 @Override 21 public void setEnabled(boolean enabled) { 22 for (Component c : this.getComponents()) { 23 c.setEnabled(enabled); 24 } 25 super.setEnabled(enabled); 26 } 27 27 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/GuiProjections.java
r34422 r34541 16 16 import javax.swing.SwingConstants; 17 17 18 import org.openstreetmap.josm.Main;19 18 import org.openstreetmap.josm.data.ProjectionBounds; 20 19 import org.openstreetmap.josm.data.projection.Projection; 20 import org.openstreetmap.josm.data.projection.ProjectionRegistry; 21 21 import org.openstreetmap.josm.gui.preferences.projection.CodeProjectionChoice; 22 22 import org.openstreetmap.josm.gui.preferences.projection.CustomProjectionChoice; … … 28 28 29 29 public class GuiProjections { 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 if ((p instanceof CodeProjectionChoice)) continue;// can not handle this projection for now53 if ((p instanceof CustomProjectionChoice)) continue;// can not handle this projection for now54 55 56 57 setProjection (Main.getProjection());58 59 60 61 62 63 64 65 if (p==null) return;// better keep the old one66 67 68 69 70 71 72 73 74 75 76 77 78 return;// stop searching79 80 81 82 83 84 85 86 87 88 89 90 91 return;// stop searching92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 // 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 30 /* 31 * provide a component let the user select a projection 32 * TODO: allow preferences for sub-projections like UTM, Gauss-Krüger, etc. 33 * TODO: allow selection of projection by code (EPSG) 34 * TODO: allow selection of custom projection 35 */ 36 private GuiPanel panel = null; 37 private Chooser chooser = null; 38 private JLabel pCode = null; 39 private JLabel pName = null; 40 private JLabel pInfo = null; 41 private Projection projection = null; 42 43 private class Chooser extends JComboBox<ProjectionChoice> { 44 /* 45 * Component to choose a Projection 46 */ 47 public Chooser() { 48 setEditable(false); 49 setToolTipText(tr("Projection of the PDF-Document")); 50 Monitor monitor = new Monitor(); 51 for (ProjectionChoice p : ProjectionPreference.getProjectionChoices()) { 52 if ((p instanceof CodeProjectionChoice)) continue; // can not handle this projection for now 53 if ((p instanceof CustomProjectionChoice)) continue; // can not handle this projection for now 54 addItem(p); 55 } 56 addActionListener(monitor); 57 setProjection (ProjectionRegistry.getProjection()); 58 } 59 60 public void setProjection (Projection p) { 61 /* 62 * set current Projection to @p 63 * update internal variables 64 */ 65 if (p==null) return; // better keep the old one 66 projection = p; 67 pName.setText(p.toString()); 68 pCode.setText(p.toCode()); 69 pInfo.setText(userHints(p)); 70 /* 71 * find projectionChoice that matches current code 72 */ 73 final String projectionCode = p.toCode(); 74 for (ProjectionChoice projectionChoice : ProjectionPreference.getProjectionChoices()) { 75 for (String code : projectionChoice.allCodes()) { 76 if (code.equals(projectionCode)) { 77 setSelectedItem(projectionChoice); 78 return; // stop searching 79 } 80 } 81 } 82 /* 83 * Not found ==> search in combobox 84 */ 85 final String localId = "PdfImport:" + projectionCode; 86 for (int i=getItemCount()-1; i>=0; i--) { 87 ProjectionChoice projectionChoice = getItemAt(i); 88 if (!(projectionChoice instanceof SingleProjectionChoice)) continue; 89 if (localId.equals(projectionChoice.getId())) { 90 setSelectedItem(projectionChoice); 91 return; // stop searching 92 } 93 } 94 /* 95 * Still not found ==> add it now 96 */ 97 Logging.debug("New projection encountered"); 98 ProjectionChoice px = new SingleProjectionChoice(p.toString(), localId, projectionCode) ; 99 addItem(px); 100 setSelectedItem(px); 101 } 102 103 private class Monitor implements ActionListener { 104 /* 105 * (non-Javadoc) 106 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) 107 * 108 * monitor user selection and set internal var accordingly 109 */ 110 @Override 111 public void actionPerformed(ActionEvent e) { 112 try { 113 ProjectionChoice pc = (ProjectionChoice)((Chooser) e.getSource()).getSelectedItem(); 114 setProjection(pc.getProjection()); 115 } catch (Exception X) { 116 } 117 } 118 } 119 } 120 121 public GuiProjections(){ 122 build(); 123 } 124 125 public static String getDefault() { 126 /* 127 * provide default projection 128 */ 129 return Config.getPref().get("projection.default"); 130 } 131 132 public JPanel getPanel() { 133 return panel; 134 } 135 136 public Projection getProjection() { 137 return projection; 138 } 139 140 public void setProjection(Projection p) { 141 chooser.setProjection(p); 142 } 143 144 private String userHints(Projection p) { 145 /* 146 * Provide some hints about projection @p 147 */ 148 String s=""; 149 ProjectionBounds bd; 150 try { 151 bd=p.getWorldBoundsBoxEastNorth(); 152 s += String.format("(%3$.0f %4$.0f) : (%5$.0f %6$.0f)", bd.getCenter().east(),bd.getCenter().north(), bd.getMin().east(),bd.getMin().north(),bd.getMax().east(),bd.getMax().north()); 153 } catch (Exception e) { 154 e.toString(); 155 // Leave it, if we cant get it 156 } 157 return s; 158 } 159 160 private void build() { 161 // JButton specBtn = new JButton(tr("Specifiy")); 162 pCode = new JLabel("code",SwingConstants.RIGHT); 163 pName = new JLabel("Name",SwingConstants.RIGHT); 164 pInfo = new JLabel("Info",SwingConstants.RIGHT); 165 chooser = new Chooser(); 166 167 GridBagConstraints c = new GridBagConstraints(); 168 c.fill = GridBagConstraints.NONE; 169 c.insets = new Insets(1, 1, 1, 4); 170 c.anchor = GridBagConstraints.LINE_END; 171 172 panel = new GuiPanel(new GridBagLayout()); 173 panel.add(new JLabel(tr("Projection:"),SwingConstants.RIGHT),c); 174 panel.add(pCode,c); 175 c.weightx = 1.0; c.gridx = 2; panel.add(chooser,c); 176 c.weightx = 0.0; c.gridy = 1; c.gridx = 0; c.gridwidth = 3; c.anchor = GridBagConstraints.LINE_END; 177 panel.add(pInfo,c); 178 } 179 179 } 180 180 … … 189 189 // 190 190 //ProjectionSubPrefsDialog(Component parent, ProjectionChoice pr) { 191 // 192 // 193 // 194 // 195 // 196 // 197 // 198 // 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 199 //} 200 200 // 201 201 //protected void makeButtonRespondToEnter(SideButton btn) { 202 // 203 // 204 // 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 205 //} 206 206 // 207 207 //protected JPanel buildInputForm() { 208 // 208 // return projPref.getPreferencePanel(null); 209 209 //} 210 210 // 211 211 //protected JPanel buildButtonRow() { 212 // 213 // 214 // 215 // 216 // 217 // 218 // 219 // 220 // 221 // 222 // 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 223 //} 224 224 // 225 225 //protected void build() { 226 // 227 // 228 // 229 // 230 // 231 // 232 // 233 // 234 // 235 // 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 ESCAPE 233 // getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) 234 // .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape"); 235 // getRootPane().getActionMap().put("escape", actCancel); 236 236 //} 237 237 // 238 238 //class OKAction extends AbstractAction { 239 // 240 // 241 // 242 // 243 // 244 // 245 // 246 // 247 // 248 // 249 // 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 // @Override 246 // public void actionPerformed(ActionEvent e) { 247 // projPref.setPreferences(projPref.getPreferences(projPrefPanel)); 248 // setVisible(false); 249 // } 250 250 //} 251 251 // 252 252 //class CancelAction extends AbstractAction { 253 // 254 // 255 // 256 // 257 // 258 // 259 // 260 // 261 // 262 // 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 // @Override 260 // public void actionPerformed(ActionEvent e) { 261 // setVisible(false); 262 // } 263 263 //} 264 264 // 265 265 //@Override 266 266 //public void setVisible(boolean visible) { 267 // 268 // 269 // 270 // 271 // 272 // 273 // 274 //} 275 //} 276 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 #8775 271 // new WindowGeometry(this).remember(getClass().getName() + ".geometry"); 272 // } 273 // super.setVisible(visible); 274 //} 275 //} 276 -
applications/editors/josm/plugins/pdfimport/src/pdfimport/LoadPdfDialog.java
r34438 r34541 34 34 import javax.swing.filechooser.FileFilter; 35 35 36 import org.openstreetmap.josm.Main;37 36 import org.openstreetmap.josm.data.osm.DataSet; 38 37 import org.openstreetmap.josm.data.osm.UploadPolicy; … … 49 48 public class LoadPdfDialog extends JFrame { 50 49 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 // 284 285 286 287 50 public static class MainButtons { 51 public JButton okButton; 52 public JButton cancelButton; 53 public JButton showButton; 54 public JButton saveButton; 55 public JPanel panel; 56 57 public MainButtons() { 58 } 59 60 void build(LoadPdfDialog loadPdfDialog) { 61 /* 62 * build the dialog Window from components 63 */ 64 okButton = new JButton(tr("Import")); 65 okButton.addActionListener(new ActionListener() { 66 @Override 67 public void actionPerformed(ActionEvent e) { 68 loadPdfDialog.importAction(); 69 } 70 }); 71 saveButton = new JButton(tr("Save")); 72 saveButton.addActionListener(new ActionListener() { 73 @Override 74 public void actionPerformed(ActionEvent e) { 75 loadPdfDialog.saveAction(); 76 } 77 }); 78 79 showButton = new JButton(tr("Show target")); 80 showButton.addActionListener(new ActionListener() { 81 @Override 82 public void actionPerformed(ActionEvent e) { 83 loadPdfDialog.showAction(); 84 } 85 }); 86 87 cancelButton = new JButton(tr("Cancel")); 88 cancelButton.addActionListener(new ActionListener() { 89 @Override 90 public void actionPerformed(ActionEvent e) { 91 loadPdfDialog.cancelAction(); 92 } 93 }); 94 95 panel = new JPanel(new FlowLayout()); 96 panel.add(cancelButton); 97 panel.add(showButton); 98 panel.add(okButton); 99 panel.add(saveButton); 100 showButton.setVisible(Preferences.isLegacyActions()); 101 saveButton.setVisible(Preferences.isLegacyActions()); 102 } 103 } 104 105 106 private static class Config { 107 /* 108 * encapsulate options for Path optimizer 109 * provide GUI 110 */ 111 public GuiFieldBool debugModeCheck; 112 public GuiFieldBool mergeCloseNodesCheck; 113 public GuiFieldDouble mergeCloseNodesTolerance; 114 public GuiFieldBool removeSmallObjectsCheck; 115 public GuiFieldDouble removeSmallObjectsSize; 116 public JTextField colorFilterColor; 117 public GuiFieldBool colorFilterCheck; 118 public GuiFieldBool removeParallelSegmentsCheck; 119 public GuiFieldDouble removeParallelSegmentsTolerance; 120 public GuiFieldBool removeLargeObjectsCheck; 121 public GuiFieldDouble removeLargeObjectsSize; 122 public GuiFieldBool limitPathCountCheck; 123 public GuiFieldInteger limitPathCount; 124 public GuiFieldBool splitOnColorChangeCheck; 125 public GuiFieldBool splitOnShapeClosedCheck; 126 public GuiFieldBool splitOnSingleSegmentCheck; 127 public GuiFieldBool splitOnOrthogonalCheck; 128 private JPanel panel; 129 130 public Config() { 131 build(); 132 } 133 134 public JComponent getComponent() { 135 return panel; 136 } 137 138 private void build() { 139 140 141 debugModeCheck = new GuiFieldBool(tr("Debug info"), Preferences.isDebugTags()); 142 143 mergeCloseNodesTolerance = new GuiFieldDouble(Preferences.getMergeNodesValue()); 144 mergeCloseNodesCheck = new GuiFieldBool(tr("Merge close nodes"), Preferences.isMergeNodes()); 145 mergeCloseNodesCheck.setCompanion(mergeCloseNodesTolerance); 146 147 removeSmallObjectsSize = new GuiFieldDouble(Preferences.getRemoveSmallValue()); 148 removeSmallObjectsCheck = new GuiFieldBool(tr("Remove objects smaller than"),Preferences.isRemoveSmall()); 149 removeSmallObjectsCheck.setCompanion(removeSmallObjectsSize); 150 151 removeLargeObjectsSize = new GuiFieldDouble((Preferences.getRemoveLargeValue())); 152 removeLargeObjectsCheck = new GuiFieldBool(tr("Remove objects larger than"),Preferences.isRemoveLarge()); 153 removeLargeObjectsCheck.setCompanion(removeLargeObjectsSize); 154 155 colorFilterColor = new GuiFieldHex(Preferences.getLimitColorValue()); 156 colorFilterCheck = new GuiFieldBool(tr("Only this color"), Preferences.isLimitColor()); 157 colorFilterCheck.setCompanion(colorFilterColor); 158 159 removeParallelSegmentsTolerance = new GuiFieldDouble((Preferences.getRemoveParallelValue())); 160 removeParallelSegmentsCheck = new GuiFieldBool(tr("Remove parallel lines"),Preferences.isRemoveParallel()); 161 removeParallelSegmentsCheck.setCompanion(removeParallelSegmentsTolerance); 162 163 limitPathCount = new GuiFieldInteger((Preferences.getLimitPathValue())); 164 limitPathCountCheck = new GuiFieldBool(tr("Take only first X paths"),Preferences.isLimitPath()); 165 limitPathCountCheck.setCompanion(limitPathCount); 166 167 splitOnColorChangeCheck = new GuiFieldBool(tr("Color/width change"),Preferences.isLayerAttribChange()); 168 splitOnShapeClosedCheck = new GuiFieldBool(tr("Shape closed"), Preferences.isLayerClosed()); 169 170 splitOnSingleSegmentCheck = new GuiFieldBool(tr("Single segments", Preferences.isLayerSegment())); 171 splitOnOrthogonalCheck = new GuiFieldBool(tr("Orthogonal shapes", Preferences.isLayerOrtho())); 172 173 panel = new JPanel(new GridBagLayout()); 174 panel.setBorder(BorderFactory.createTitledBorder(tr("Import settings"))); 175 176 GridBagConstraints cBasic = new GridBagConstraints(); 177 cBasic.gridx = GridBagConstraints.RELATIVE; 178 cBasic.gridy = GridBagConstraints.RELATIVE; 179 cBasic.insets = new Insets(0, 0, 0, 4); 180 cBasic.anchor = GridBagConstraints.LINE_START; 181 cBasic.fill = GridBagConstraints.HORIZONTAL; 182 cBasic.gridheight = 1; 183 cBasic.gridwidth = 1; 184 cBasic.ipadx = 0; 185 cBasic.ipady = 0; 186 cBasic.weightx = 0.0; 187 cBasic.weighty = 0.0; 188 189 GridBagConstraints cLeft = (GridBagConstraints) cBasic.clone(); 190 cLeft.gridx = 0; 191 192 GridBagConstraints cMiddle = (GridBagConstraints) cBasic.clone(); 193 cMiddle.gridx = 1; 194 cMiddle.anchor = GridBagConstraints.LINE_END; 195 196 GridBagConstraints cRight = (GridBagConstraints) cBasic.clone(); 197 cRight.gridx = 2; 198 199 panel.add(mergeCloseNodesCheck, cLeft); 200 panel.add(new JLabel(tr("Tolerance:"),SwingConstants.RIGHT), cMiddle); 201 panel.add(mergeCloseNodesTolerance, cRight); 202 203 panel.add(removeSmallObjectsCheck, cLeft); 204 panel.add(new JLabel(tr("Tolerance:"),SwingConstants.RIGHT), cMiddle); 205 panel.add(removeSmallObjectsSize, cRight); 206 207 panel.add(removeLargeObjectsCheck, cLeft); 208 panel.add(new JLabel(tr("Tolerance:"),SwingConstants.RIGHT), cMiddle); 209 panel.add(removeLargeObjectsSize, cRight); 210 211 panel.add(removeParallelSegmentsCheck, cLeft); 212 panel.add(new JLabel(tr("Max distance:"),SwingConstants.RIGHT), cMiddle); 213 panel.add(removeParallelSegmentsTolerance, cRight); 214 215 panel.add(limitPathCountCheck, cLeft); 216 panel.add(limitPathCount, cRight); 217 218 panel.add(colorFilterCheck, cLeft); 219 panel.add(colorFilterColor, cRight); 220 221 panel.add(debugModeCheck, cLeft); 222 223 cLeft.gridy = 8; panel.add(new JLabel(tr("Introduce separate layers for:")), cLeft); 224 cMiddle.gridy = 8; panel.add(splitOnShapeClosedCheck, cMiddle); 225 cRight.gridy = 8; panel.add(splitOnSingleSegmentCheck, cRight); 226 cMiddle.gridy = 9; panel.add(splitOnColorChangeCheck, cMiddle); 227 cRight.gridy = 9;panel.add(splitOnOrthogonalCheck, cRight); 228 } 229 } 230 231 static class LoadProgressRenderer implements ProgressRenderer { 232 private final JProgressBar pBar; 233 private String title = ""; 234 235 LoadProgressRenderer(JProgressBar pb) { 236 this.pBar = pb; 237 this.pBar.setMinimum(0); 238 this.pBar.setValue(0); 239 this.pBar.setMaximum(1); 240 this.pBar.setString(""); 241 this.pBar.setStringPainted(true); 242 243 } 244 245 @Override 246 public void setCustomText(String message) { 247 this.pBar.setString(this.title + message); 248 } 249 250 @Override 251 public void setIndeterminate(boolean indeterminate) { 252 this.pBar.setIndeterminate(indeterminate); 253 } 254 255 @Override 256 public void setMaximum(int maximum) { 257 this.pBar.setMaximum(maximum); 258 } 259 260 @Override 261 public void setTaskTitle(String taskTitle) { 262 this.title = taskTitle; 263 this.pBar.setString(this.title); 264 } 265 266 @Override 267 public void setValue(int value) { 268 this.pBar.setValue(value); 269 } 270 271 public void finish() { 272 this.pBar.setString(tr("Finished")); 273 this.pBar.setValue(this.pBar.getMaximum()); 274 } 275 276 } 277 278 private File pdfFile; 279 private final FilePlacement18 placement = new FilePlacement18(); 280 281 private PathOptimizer pdfData; 282 // private OsmDataLayer dataLayer; 283 284 private final JButton loadFileButton = new JButton(tr("Load preview ...")); 285 286 private final JProgressBar loadProgress = new JProgressBar(); 288 287 ; 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 // 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 int result = fc.showOpenDialog(Main.parent);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 619 620 621 JOptionPane.showMessageDialog(Main.parent, tr("Could not parse color"));622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 JOptionPane.showMessageDialog(Main.parent, tr("File not found."));641 642 643 644 JOptionPane.showMessageDialog(Main.parent, tr("Error while parsing: {0}", e.getMessage()));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 753 754 288 private OsmDataLayer newLayer; 289 290 private LoadProgressRenderer progressRenderer; 291 292 public LoadPdfDialog() { 293 buildGUI(); 294 removeLayer(); 295 if (Preferences.getGuiMode() == Preferences.GuiMode.Simple) { 296 loadFileButton.setVisible(false); 297 configPanel.panel.setVisible(false); 298 actionPanel.saveButton.setVisible(false); 299 actionPanel.showButton.setVisible(false); 300 setSize(new Dimension(380, 350)); 301 if (!loadAction()) { 302 cancelAction(); 303 return; 304 } 305 } else { 306 setSize(new Dimension(450, 600)); 307 } 308 setAlwaysOnTop(true); 309 setVisible(true); 310 } 311 312 Component placementPanel = placement.getGui(); 313 MainButtons actionPanel = new MainButtons(); 314 Config configPanel = new Config(); 315 316 private void buildGUI() { 317 /* 318 * build the GUI from Components 319 */ 320 GridBagConstraints c = new GridBagConstraints(); 321 c.gridheight = 1; 322 c.gridwidth = 1; 323 c.gridx = 0; 324 c.gridy = GridBagConstraints.RELATIVE; 325 c.fill = GridBagConstraints.BOTH; 326 c.insets = new java.awt.Insets(0, 0, 0, 0); 327 328 actionPanel.build(this); 329 330 loadFileButton.addActionListener(new ActionListener() { 331 @Override 332 public void actionPerformed(ActionEvent e) { 333 loadAction(); 334 } 335 }); 336 337 progressRenderer = new LoadProgressRenderer(loadProgress); 338 339 JPanel panel = new JPanel(new GridBagLayout()); 340 341 panel.add(configPanel.getComponent(), c); 342 c.fill = GridBagConstraints.HORIZONTAL; 343 panel.add(loadFileButton, c); 344 c.fill = GridBagConstraints.BOTH; 345 panel.add(placementPanel, c); 346 panel.add(actionPanel.panel, c); 347 c.fill = GridBagConstraints.HORIZONTAL; 348 panel.add(this.loadProgress, c); 349 350 setContentPane(panel); 351 addWindowListener(new WindowAdapter() { 352 @Override 353 public void windowClosing(WindowEvent e) { 354 cancelAction(); 355 } 356 }); 357 placement.setDependsOnValid(actionPanel.okButton); 358 359 /* 360 * TODO: Make okButton to default Button of Dialog, make cancelButton to react on ESC-Key 361 */ 362 // SwingUtilities.getRootPane(panel).setDefaultButton(actionPanel.okButton); 363 } 364 365 private boolean loadAction() { 366 /* 367 * perform load PDF file to preview 368 * TODO: load preview to previous placement, involves reverse transform 369 */ 370 final File newFileName = this.chooseFile(); 371 372 if (newFileName == null) { 373 return false; 374 } 375 Logging.debug("PdfImport: Load Preview"); 376 this.removeLayer(); 377 378 this.loadFileButton.setEnabled(false); 379 380 this.runAsBackgroundTask(new Runnable() { 381 @Override 382 public void run() { 383 // async part 384 LoadPdfDialog.this.loadProgress.setVisible(true); 385 SwingRenderingProgressMonitor monitor = new SwingRenderingProgressMonitor(progressRenderer); 386 monitor.beginTask("Loading file", 1000); 387 pdfData = loadPDF(newFileName, monitor.createSubTaskMonitor(500, false)); 388 OsmBuilder.Mode mode = LoadPdfDialog.this.configPanel.debugModeCheck.getValue() 389 ? OsmBuilder.Mode.Debug 390 : OsmBuilder.Mode.Draft; 391 392 if (pdfData != null) { 393 LoadPdfDialog.this.newLayer = LoadPdfDialog.this.makeLayer( 394 tr("PDF preview: ") + newFileName.getName(), new FilePlacement(), mode, 395 monitor.createSubTaskMonitor(500, false)); 396 } 397 398 monitor.finishTask(); 399 progressRenderer.finish(); 400 } 401 }, new ActionListener() { 402 403 @Override 404 public void actionPerformed(ActionEvent event) { 405 // sync part 406 LoadPdfDialog.this.pdfFile = newFileName; 407 if (pdfData != null) { 408 Preview.set(newLayer, new FilePlacement()); 409 MainApplication.getMap().mapView.zoomTo(placement.getWorldBounds(pdfData)); 410 try { 411 LoadPdfDialog.this.placement.load(newFileName); 412 } catch (IOException e) { 413 // Saved placement does not exist, corrupt, ... ---> ignore it 414 } finally { 415 LoadPdfDialog.this.placement.verify(); 416 } 417 LoadPdfDialog.this.newLayer = null; 418 LoadPdfDialog.this.loadFileButton.setEnabled(true); 419 LoadPdfDialog.this.placementPanel.setEnabled(true); 420 LoadPdfDialog.this.actionPanel.panel.setEnabled(true); 421 LoadPdfDialog.this.actionPanel.showButton.setEnabled(true); 422 LoadPdfDialog.this.actionPanel.saveButton.setEnabled(true); 423 LoadPdfDialog.this.actionPanel.okButton.setEnabled(true); 424 LoadPdfDialog.this.loadProgress.setVisible(false); 425 } 426 } 427 }); 428 return true; 429 } 430 431 private void importAction() { 432 433 if (!placement.isValid()) return; 434 try { 435 placement.save(pdfFile); 436 } catch (IOException e) { 437 e.toString(); 438 } 439 removeLayer(); 440 441 runAsBackgroundTask(new Runnable() { 442 @Override 443 public void run() { 444 // async part 445 LoadPdfDialog.this.loadProgress.setVisible(true); 446 SwingRenderingProgressMonitor monitor = new SwingRenderingProgressMonitor(progressRenderer); 447 LoadPdfDialog.this.newLayer = LoadPdfDialog.this.makeLayer(tr("PDF: ") + pdfFile.getName(), placement, 448 OsmBuilder.Mode.Final, monitor); 449 progressRenderer.finish(); 450 } 451 }, new ActionListener() { 452 453 @Override 454 public void actionPerformed(ActionEvent e) { 455 // sync part 456 // rebuild layer with latest projection 457 MainApplication.getLayerManager().addLayer(newLayer); 458 MainApplication.getMap().mapView.zoomTo(placement.getWorldBounds(pdfData)); 459 LoadPdfDialog.this.setVisible(false); 460 } 461 }); 462 } 463 464 private void saveAction() { 465 /* 466 * perform save preview layer to file 467 * TODO: is this action valueable? Can be easily performed from main menu 468 */ 469 470 if (!placement.isValid()) return; 471 472 final java.io.File file = this.chooseSaveFile(); 473 474 if (file == null) { 475 return; 476 } 477 478 this.removeLayer(); 479 480 this.runAsBackgroundTask(new Runnable() { 481 @Override 482 public void run() { 483 // async part 484 SwingRenderingProgressMonitor monitor = new SwingRenderingProgressMonitor(progressRenderer); 485 LoadPdfDialog.this.saveLayer(file, placement, monitor); 486 progressRenderer.finish(); 487 } 488 }, new ActionListener() { 489 490 @Override 491 public void actionPerformed(ActionEvent e) { 492 // sync part 493 LoadPdfDialog.this.setVisible(false); 494 } 495 }); 496 } 497 498 private void showAction() { 499 /* 500 * perform show action 501 * TODO: is this action valuable? User can do it easy from OSM Main Menu 502 */ 503 if (!placement.isValid()) return; 504 505 // zoom to new location 506 MainApplication.getMap().mapView.zoomTo(placement.getWorldBounds(pdfData)); 507 MainApplication.getMap().repaint(); 508 } 509 510 private void cancelAction() { 511 /* 512 * perform cancel action 513 */ 514 removeLayer(); 515 setVisible(false); 516 } 517 518 // Implementation methods 519 520 private static JFileChooser loadChooser = null; 521 522 private java.io.File chooseFile() { 523 // get PDF file to load 524 if (loadChooser == null) { 525 loadChooser = new JFileChooser(Preferences.getLoadDir()); 526 loadChooser.setAcceptAllFileFilterUsed(false); 527 loadChooser.setMultiSelectionEnabled(false); 528 loadChooser.setFileFilter(new FileFilter() { 529 @Override 530 public boolean accept(java.io.File pathname) { 531 return pathname.isDirectory() || pathname.getName().endsWith(".pdf"); 532 } 533 534 @Override 535 public String getDescription() { 536 return tr("PDF files"); 537 } 538 }); 539 } else { 540 loadChooser.rescanCurrentDirectory(); 541 } 542 int result = loadChooser.showDialog(this, tr("Import PDF")); 543 if (result != JFileChooser.APPROVE_OPTION) { 544 return null; 545 } else { 546 Preferences.setLoadDir(loadChooser.getSelectedFile().getParentFile().getAbsolutePath()); 547 return loadChooser.getSelectedFile(); 548 } 549 } 550 551 private java.io.File chooseSaveFile() { 552 // get file name 553 JFileChooser fc = new JFileChooser(); 554 fc.setAcceptAllFileFilterUsed(true); 555 fc.setMultiSelectionEnabled(false); 556 fc.setFileFilter(new FileFilter() { 557 @Override 558 public boolean accept(java.io.File pathname) { 559 return pathname.isDirectory() || pathname.getName().endsWith(".osm"); 560 } 561 562 @Override 563 public String getDescription() { 564 return tr("OSM files"); 565 } 566 }); 567 int result = fc.showOpenDialog(MainApplication.getMainFrame()); 568 569 if (result != JFileChooser.APPROVE_OPTION) { 570 return null; 571 } else { 572 return fc.getSelectedFile(); 573 } 574 } 575 576 private void runAsBackgroundTask(final Runnable task, final ActionListener after) { 577 /* 578 * run @task in background (asychronosly , run @after when @task has finished 579 */ 580 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 581 Thread t = new Thread(new Runnable() { 582 @Override 583 public void run() { 584 task.run(); 585 586 SwingUtilities.invokeLater(new Runnable() { 587 @Override 588 public void run() { 589 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 590 after.actionPerformed(null); 591 } 592 }); 593 } 594 }); 595 t.start(); 596 } 597 598 private PathOptimizer loadPDF(File fileName, ProgressMonitor monitor) { 599 /* 600 * postprocess load PDF-file according to options 601 */ 602 603 monitor.beginTask("", 100); 604 monitor.setTicks(0); 605 monitor.setCustomText(tr("Preparing")); 606 607 double nodesTolerance = 0.0; 608 Color color = null; 609 int maxPaths = Integer.MAX_VALUE; 610 611 if (configPanel.mergeCloseNodesCheck.getValue() && configPanel.mergeCloseNodesTolerance.isDataValid()) { 612 nodesTolerance = configPanel.mergeCloseNodesTolerance.getValue(); 613 } 614 615 if (configPanel.colorFilterCheck.getValue()) { 616 try { 617 String colString = this.configPanel.colorFilterColor.getText().replace("#", ""); 618 color = new Color(Integer.parseInt(colString, 16)); 619 } catch (Exception e) { 620 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Could not parse color")); 621 return null; 622 } 623 } 624 625 if (configPanel.limitPathCountCheck.getValue() && configPanel.limitPathCount.isDataValid()) { 626 maxPaths = configPanel.limitPathCount.getValue(); 627 } 628 629 monitor.setTicks(10); 630 monitor.setCustomText(tr("Parsing file")); 631 632 PathOptimizer data = new PathOptimizer(nodesTolerance, color, configPanel.splitOnColorChangeCheck.getValue()); 633 634 try { 635 PdfBoxParser parser = new PdfBoxParser(data); 636 parser.parse(fileName, maxPaths, monitor.createSubTaskMonitor(80, false)); 637 638 } catch (FileNotFoundException e1) { 639 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("File not found.")); 640 return null; 641 } catch (Exception e) { 642 e.printStackTrace(); 643 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Error while parsing: {0}", e.getMessage())); 644 return null; 645 } 646 647 monitor.setTicks(80); 648 649 if (configPanel.removeParallelSegmentsCheck.getValue() && configPanel.removeParallelSegmentsTolerance.isDataValid()) { 650 double tolerance = configPanel.removeParallelSegmentsTolerance.getValue(); 651 monitor.setCustomText(tr("Removing parallel segments")); 652 } 653 654 if (nodesTolerance > 0.0) { 655 monitor.setTicks(83); 656 monitor.setCustomText(tr("Joining nodes")); 657 data.mergeNodes(); 658 } 659 660 monitor.setTicks(85); 661 monitor.setCustomText(tr("Joining adjacent segments")); 662 data.mergeSegments(); 663 664 if (configPanel.removeSmallObjectsCheck.getValue() && configPanel.removeSmallObjectsSize.isDataValid()) { 665 double tolerance = configPanel.removeSmallObjectsSize.getValue(); 666 monitor.setTicks(90); 667 monitor.setCustomText(tr("Removing small objects")); 668 669 data.removeSmallObjects(tolerance); 670 671 } 672 673 if (configPanel.removeLargeObjectsCheck.getValue() && configPanel.removeLargeObjectsSize.isDataValid()) { 674 double tolerance = configPanel.removeLargeObjectsSize.getValue(); 675 monitor.setTicks(90); 676 monitor.setCustomText(tr("Removing large objects")); 677 data.removeLargeObjects(tolerance); 678 } 679 680 monitor.setTicks(95); 681 monitor.setCustomText(tr("Finalizing layers")); 682 data.splitLayersByPathKind(configPanel.splitOnShapeClosedCheck.getValue(), 683 configPanel.splitOnSingleSegmentCheck.getValue(), 684 configPanel.splitOnOrthogonalCheck.getValue()); 685 data.finish(); 686 687 monitor.finishTask(); 688 return data; 689 } 690 691 private OsmDataLayer makeLayer(String name, FilePlacement placement, OsmBuilder.Mode mode, 692 ProgressMonitor monitor) { 693 /* 694 * create a layer from data 695 */ 696 monitor.beginTask(tr("Building JOSM layer"), 100); 697 OsmBuilder builder = new OsmBuilder(placement); 698 DataSet data = builder.build(pdfData.getLayers(), mode, monitor.createSubTaskMonitor(50, false)); 699 data.setUploadPolicy(UploadPolicy.BLOCKED); 700 monitor.setTicks(50); 701 monitor.setCustomText(tr("Postprocessing layer")); 702 OsmDataLayer result = new OsmDataLayer(data, name, null); 703 result.setUploadDiscouraged(true); 704 result.setBackgroundLayer(true); 705 result.onPostLoadFromFile(); 706 707 monitor.finishTask(); 708 return result; 709 } 710 711 private void removeLayer() { 712 /* 713 * remove preview layer 714 */ 715 // if (dataLayer != null) { 716 // MainApplication.getLayerManager().removeLayer(dataLayer); 717 // dataLayer.data.clear(); // saves memory 718 // dataLayer = null; 719 // } 720 Preview.clear(); 721 // No layer ==> no actions 722 actionPanel.showButton.setEnabled(false); 723 actionPanel.saveButton.setEnabled(false); 724 actionPanel.okButton.setEnabled(false); 725 placementPanel.setEnabled(false); 726 727 } 728 729 private void saveLayer(java.io.File file, FilePlacement placement, ProgressMonitor monitor) { 730 /* 731 * save layer to file 732 * TODO: is this methode valuable? Functionality can easily performed from Main-Menu 733 */ 734 monitor.beginTask(tr("Saving to file."), 1000); 735 736 OsmBuilder builder = new OsmBuilder(placement); 737 DataSet data = builder.build(this.pdfData.getLayers(), OsmBuilder.Mode.Final, 738 monitor.createSubTaskMonitor(500, false)); 739 OsmDataLayer layer = new OsmDataLayer(data, file.getName(), file); 740 741 monitor.setCustomText(tr(" Writing to file")); 742 monitor.setTicks(500); 743 744 OsmExporter exporter = new OsmExporter(); 745 746 try { 747 exporter.exportData(file, layer); 748 } catch (IOException e) { 749 Logging.error(e); 750 } 751 752 monitor.finishTask(); 753 } 755 754 756 755 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/PdfImportAction.java
r34425 r34541 33 33 34 34 //show dialog asking to select coordinate axes and input coordinates and projection. 35 36 37 35 /* 36 * TODO: make dialog reusable 37 */ 38 38 LoadPdfDialog dialog = new LoadPdfDialog(); 39 39 dialog.setTitle(tr("Import PDF")); -
applications/editors/josm/plugins/pdfimport/src/pdfimport/PdfImportPlugin.java
r34422 r34541 14 14 * A plugin to import a PDF file. 15 15 */ 16 17 16 public class PdfImportPlugin extends Plugin { 18 17 18 public PdfImportPlugin(PluginInformation info) { 19 super(info); 20 MainMenu.add(MainApplication.getMenu().imagerySubMenu, new PdfImportAction()); 21 new Preferences(getPluginInformation().name); 22 } 19 23 20 public PdfImportPlugin(PluginInformation info){21 super(info); 22 MainMenu.add(MainApplication.getMenu().imagerySubMenu, new PdfImportAction()); 23 new Preferences(getPluginInformation().name);24 24 public static class pdfimportPrefs implements SubPreferenceSetting { 25 @Override 26 public TabPreferenceSetting getTabPreferenceSetting(PreferenceTabbedPane gui) { 27 return null; 28 } 25 29 26 public class pdfimportPrefs implements SubPreferenceSetting 27 { 28 @Override 29 public TabPreferenceSetting getTabPreferenceSetting(PreferenceTabbedPane gui) 30 { 31 return null; 32 } 30 @Override 31 public void addGui(PreferenceTabbedPane gui) { 32 return; 33 } 33 34 34 35 public void addGui(PreferenceTabbedPane gui) {36 return;37 35 @Override 36 public boolean ok() { 37 return false; 38 } 38 39 39 @Override 40 public boolean ok() { 41 return false; 42 } 40 @Override 41 public boolean isExpert() { 42 return false; 43 } 44 } 43 45 44 @Override 45 public boolean isExpert() { 46 return false; 47 } 48 } 49 50 @Override 51 public PreferenceSetting getPreferenceSetting() { 52 /* 53 * TODO: implement it 54 */ 55 return new pdfimportPrefs(); 56 } 46 @Override 47 public PreferenceSetting getPreferenceSetting() { 48 /* 49 * TODO: implement it 50 */ 51 return new pdfimportPrefs(); 52 } 57 53 58 54 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/Preferences.java
r34398 r34541 8 8 public class Preferences { 9 9 10 11 12 10 public enum GuiMode { 11 Auto, Expert, Simple 12 }; 13 13 14 15 returnConfig.getPref().get(Preferences.prefix + "loadDir");16 14 public static String getLoadDir() { 15 return Config.getPref().get(Preferences.prefix + "loadDir"); 16 } 17 17 18 19 20 18 public static void setLoadDir(String loadDir) { 19 Config.getPref().put(Preferences.prefix + "loadDir", loadDir); 20 } 21 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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 37 38 39 40 38 public static boolean isLegacyActions() { 39 return (Config.getPref().getInt(Preferences.prefix + "guiCode", 0) == -1); 40 } 41 41 42 43 44 42 public static boolean isMergeNodes() { 43 return Config.getPref().getBoolean(Preferences.prefix + "mergeNodes"); 44 } 45 45 46 47 48 46 public static double getMergeNodesValue() { 47 return Config.getPref().getDouble(Preferences.prefix + "mergeNodes.value", 1e-3); 48 } 49 49 50 51 52 50 public static boolean isRemoveSmall() { 51 return Config.getPref().getBoolean(Preferences.prefix + "removeSmall"); 52 } 53 53 54 55 56 54 public static double getRemoveSmallValue() { 55 return Config.getPref().getDouble(Preferences.prefix + "removeSmall.value", 1); 56 } 57 57 58 59 60 58 public static boolean isRemoveLarge() { 59 return Config.getPref().getBoolean(Preferences.prefix + "removeLarge"); 60 } 61 61 62 63 64 62 public static double getRemoveLargeValue() { 63 return Config.getPref().getDouble(Preferences.prefix + "removeLarge.value", 10); 64 } 65 65 66 67 68 66 public static boolean isRemoveParallel() { 67 return Config.getPref().getBoolean(Preferences.prefix + "removeParallel"); 68 } 69 69 70 71 72 70 public static double getRemoveParallelValue() { 71 return Config.getPref().getDouble(Preferences.prefix + "removeParallel.value", 3); 72 } 73 73 74 75 76 74 public static boolean isLimitPath() { 75 return Config.getPref().getBoolean(Preferences.prefix + "limitPath"); 76 } 77 77 78 79 80 78 public static int getLimitPathValue() { 79 return Config.getPref().getInt(Preferences.prefix + "limitPath.value", Integer.MAX_VALUE); 80 } 81 81 82 83 84 82 public static boolean isLimitColor() { 83 return Config.getPref().getBoolean(Preferences.prefix + "limitColor"); 84 } 85 85 86 87 88 86 public static String getLimitColorValue() { 87 return Config.getPref().get(Preferences.prefix + "limitColor.value","#000000"); 88 } 89 89 90 91 92 90 public static boolean isDebugTags() { 91 return Config.getPref().getBoolean(Preferences.prefix + "debugTags"); 92 } 93 93 94 95 96 94 public static boolean isLayerClosed() { 95 return Config.getPref().getBoolean(Preferences.prefix + "layerClosed"); 96 } 97 97 98 99 100 98 public static boolean isLayerSegment() { 99 return Config.getPref().getBoolean(Preferences.prefix + "layerSegment"); 100 } 101 101 102 103 104 102 public static boolean isLayerAttribChange() { 103 return Config.getPref().getBoolean(Preferences.prefix + "layerAttribChanges"); 104 } 105 105 106 107 108 106 public static boolean isLayerOrtho() { 107 return Config.getPref().getBoolean(Preferences.prefix + "layerOrtho"); 108 } 109 109 110 110 protected static int GuiCode; 111 111 112 112 private static String prefix; 113 113 114 115 116 114 private Preferences() { 115 return; 116 } 117 117 118 119 120 118 public Preferences (String p) { 119 prefix = p + "." ; 120 } 121 121 122 122 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/Preview.java
r34439 r34541 3 3 */ 4 4 package pdfimport; 5 6 import java.io.File;7 5 8 6 import org.openstreetmap.josm.gui.MainApplication; … … 16 14 */ 17 15 public class Preview { 18 19 20 21 22 23 24 25 16 public static OsmDataLayer dataLayer; 17 public static FilePlacement placement; 18 19 public static synchronized void set (@NotNull OsmDataLayer dataLayer, @NotNull FilePlacement placement) { 20 clear(); 21 Preview.dataLayer = dataLayer; 22 Preview.placement = placement; 23 MainApplication.getLayerManager().addLayer(dataLayer); 26 24 27 28 29 30 31 32 33 34 35 36 37 38 39 // 40 25 } 26 27 public static void clear() { 28 if (Preview.dataLayer != null) { 29 MainApplication.getLayerManager().removeLayer(Preview.dataLayer); 30 Preview.dataLayer.data.clear(); // saves memory 31 } 32 Preview.dataLayer = null; 33 Preview.placement = null; 34 } 35 36 public void save() { 37 // TODO: implement 38 } 41 39 42 40 -
applications/editors/josm/plugins/pdfimport/src/pdfimport/ProjectionInfo.java
r34435 r34541 26 26 } 27 27 28 29 30 31 32 33 34 35 28 public static Projection getProjectionByCode(String code) { 29 try { 30 ProjectionChoice pc = new SingleProjectionChoice(code.toString(), code.toString(), code); 31 Projection p = pc.getProjection(); 32 return p; 33 } catch (Exception e) { 34 throw new IllegalArgumentException(); 35 } 36 36 37 37 // Projection p = allCodes.get(code); -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/PageDrawer.java
r32542 r34541 39 39 import org.apache.pdfbox.util.ResourceLoader; 40 40 import org.apache.pdfbox.util.TextPosition; 41 import org.openstreetmap.josm.tools.Logging; 41 42 42 43 … … 140 141 graphics.setClip(getGraphicsState().getCurrentClippingPath()); 141 142 graphics.drawString(x, y, text.getCharacter(), color); 142 } catch (IOException io) {143 io.printStackTrace();143 } catch (IOException e) { 144 Logging.error(e); 144 145 } 145 146 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/AppendRectangleToPath.java
r23991 r34541 38 38 39 39 40 41 42 43 44 45 46 47 48 40 /** 41 * process : re : append rectangle to path. 42 * @param operator The operator that is being executed. 43 * @param arguments List 44 */ 45 @Override 46 public void process(PDFOperator operator, List<COSBase> arguments) 47 { 48 PageDrawer drawer = (PageDrawer)context; 49 49 50 51 52 53 50 COSNumber x = (COSNumber)arguments.get( 0 ); 51 COSNumber y = (COSNumber)arguments.get( 1 ); 52 COSNumber w = (COSNumber)arguments.get( 2 ); 53 COSNumber h = (COSNumber)arguments.get( 3 ); 54 54 55 56 57 58 59 55 double x1 = x.doubleValue(); 56 double y1 = y.doubleValue(); 57 // create a pair of coordinates for the transformation 58 double x2 = w.doubleValue()+x1; 59 double y2 = h.doubleValue()+y1; 60 60 61 62 61 Point2D startCoords = drawer.transformedPoint(x1,y1); 62 Point2D endCoords = drawer.transformedPoint(x2,y2); 63 63 64 65 66 67 64 float width = (float)(endCoords.getX()-startCoords.getX()); 65 float height = (float)(endCoords.getY()-startCoords.getY()); 66 float xStart = (float)startCoords.getX(); 67 float yStart = (float)startCoords.getY(); 68 68 69 70 71 72 73 74 75 76 77 78 69 // To ensure that the path is created in the right direction, 70 // we have to create it by combining single lines instead of 71 // creating a simple rectangle 72 GeneralPath path = drawer.getLinePath(); 73 path.moveTo(xStart, yStart); 74 path.lineTo(xStart+width, yStart); 75 path.lineTo(xStart+width, yStart+height); 76 path.lineTo(xStart, yStart+height); 77 path.lineTo(xStart, yStart); 78 } 79 79 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/BeginInlineImage.java
r25349 r34541 35 35 { 36 36 37 38 39 40 41 42 43 44 45 46 47 48 37 /** 38 * process : BI : begin inline image. 39 * @param operator The operator that is being executed. 40 * @param arguments List 41 * @throws IOException If there is an error displaying the inline image. 42 */ 43 @Override 44 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 45 { 46 PageDrawer drawer = (PageDrawer)context; 47 drawer.drawImage(); 48 } 49 49 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/ClipEvenOddRule.java
r23991 r34541 38 38 { 39 39 40 41 42 43 40 /** 41 * Log instance. 42 */ 43 private static final Log log = LogFactory.getLog(ClipEvenOddRule.class); 44 44 45 46 47 48 49 50 51 52 53 54 45 /** 46 * process : W* : set clipping path using even odd rule. 47 * @param operator The operator that is being executed. 48 * @param arguments List 49 * 50 * @throws IOException if there is an error during execution. 51 */ 52 @Override 53 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 54 { 55 55 56 57 58 59 60 61 62 63 64 65 56 try 57 { 58 PageDrawer drawer = (PageDrawer)context; 59 drawer.setClippingPath(GeneralPath.WIND_EVEN_ODD); 60 } 61 catch (Exception e) 62 { 63 log.warn(e, e); 64 } 65 } 66 66 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/ClipNonZeroRule.java
r23991 r34541 38 38 { 39 39 40 41 42 43 40 /** 41 * Log instance. 42 */ 43 private static final Log log = LogFactory.getLog(ClipNonZeroRule.class); 44 44 45 46 47 48 49 50 51 52 53 54 45 /** 46 * process : W : Set the clipping path using non zero winding rule. 47 * @param operator The operator that is being executed. 48 * @param arguments List 49 * 50 * @throws IOException If there is an error during the processing. 51 */ 52 @Override 53 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 54 { 55 55 56 57 58 59 60 61 62 63 64 65 56 try 57 { 58 PageDrawer drawer = (PageDrawer)context; 59 drawer.setClippingPath(GeneralPath.WIND_NON_ZERO); 60 } 61 catch (Exception e) 62 { 63 log.warn(e, e); 64 } 65 } 66 66 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/CloseFillEvenOddAndStrokePath.java
r32520 r34541 36 36 { 37 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 38 /** 39 * fill and stroke the path. 40 * @param operator The operator that is being executed. 41 * @param arguments List 42 * 43 * @throws IOException If an error occurs while processing the font. 44 */ 45 @Override 46 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 47 { 48 PageDrawer drawer = (PageDrawer)context; 49 drawer.getLinePath().closePath(); 50 drawer.drawPath(true, true, Path2D.WIND_EVEN_ODD); 51 } 52 52 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/CloseFillNonZeroAndStrokePath.java
r23991 r34541 36 36 { 37 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 38 /** 39 * fill and stroke the path. 40 * @param operator The operator that is being executed. 41 * @param arguments List 42 * 43 * @throws IOException If an error occurs while processing the font. 44 */ 45 @Override 46 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 47 { 48 PageDrawer drawer = (PageDrawer)context; 49 drawer.getLinePath().closePath(); 50 drawer.drawPath(true, true, Path2D.WIND_NON_ZERO); 51 } 52 52 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/ClosePath.java
r25349 r34541 34 34 { 35 35 36 37 38 39 40 41 42 43 44 45 46 47 48 36 /** 37 * process : h : Close path. 38 * @param operator The operator that is being executed. 39 * @param arguments List 40 * 41 * @throws IOException if something went wrong during logging 42 */ 43 @Override 44 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 45 { 46 PageDrawer drawer = (PageDrawer)context; 47 drawer.getLinePath().closePath(); 48 } 49 49 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/CurveTo.java
r23991 r34541 37 37 38 38 39 40 41 42 43 44 45 46 47 39 /** 40 * process : c : Append curved segment to path. 41 * @param operator The operator that is being executed. 42 * @param arguments List 43 */ 44 @Override 45 public void process(PDFOperator operator, List<COSBase> arguments) 46 { 47 PageDrawer drawer = (PageDrawer)context; 48 48 49 50 51 52 53 54 49 COSNumber x1 = (COSNumber)arguments.get( 0 ); 50 COSNumber y1 = (COSNumber)arguments.get( 1 ); 51 COSNumber x2 = (COSNumber)arguments.get( 2 ); 52 COSNumber y2 = (COSNumber)arguments.get( 3 ); 53 COSNumber x3 = (COSNumber)arguments.get( 4 ); 54 COSNumber y3 = (COSNumber)arguments.get( 5 ); 55 55 56 57 58 56 Point2D point1 = drawer.transformedPoint(x1.doubleValue(), y1.doubleValue()); 57 Point2D point2 = drawer.transformedPoint(x2.doubleValue(), y2.doubleValue()); 58 Point2D point3 = drawer.transformedPoint(x3.doubleValue(), y3.doubleValue()); 59 59 60 61 62 60 drawer.getLinePath().curveTo((float)point1.getX(), (float)point1.getY(), 61 (float)point2.getX(), (float)point2.getY(), (float)point3.getX(), (float)point3.getY()); 62 } 63 63 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/CurveToReplicateFinalPoint.java
r23991 r34541 37 37 38 38 39 40 41 42 43 44 45 46 47 39 /** 40 * process : y : Append curved segment to path (final point replicated). 41 * @param operator The operator that is being executed. 42 * @param arguments List 43 */ 44 @Override 45 public void process(PDFOperator operator, List<COSBase> arguments) 46 { 47 PageDrawer drawer = (PageDrawer)context; 48 48 49 50 51 52 49 COSNumber x1 = (COSNumber)arguments.get( 0 ); 50 COSNumber y1 = (COSNumber)arguments.get( 1 ); 51 COSNumber x3 = (COSNumber)arguments.get( 2 ); 52 COSNumber y3 = (COSNumber)arguments.get( 3 ); 53 53 54 55 54 Point2D point1 = drawer.transformedPoint(x1.doubleValue(), y1.doubleValue()); 55 Point2D point3 = drawer.transformedPoint(x3.doubleValue(), y3.doubleValue()); 56 56 57 58 59 57 drawer.getLinePath().curveTo((float)point1.getX(), (float)point1.getY(), 58 (float)point3.getX(), (float)point3.getY(), (float)point3.getX(), (float)point3.getY()); 59 } 60 60 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/CurveToReplicateInitialPoint.java
r23991 r34541 38 38 39 39 40 41 42 43 44 45 46 47 48 40 /** 41 * process : v : Append curved segment to path (initial point replicated). 42 * @param operator The operator that is being executed. 43 * @param arguments List 44 */ 45 @Override 46 public void process(PDFOperator operator, List<COSBase> arguments) 47 { 48 PageDrawer drawer = (PageDrawer)context; 49 49 50 51 52 53 54 55 50 COSNumber x2 = (COSNumber)arguments.get( 0 ); 51 COSNumber y2 = (COSNumber)arguments.get( 1 ); 52 COSNumber x3 = (COSNumber)arguments.get( 2 ); 53 COSNumber y3 = (COSNumber)arguments.get( 3 ); 54 GeneralPath path = drawer.getLinePath(); 55 Point2D currentPoint = path.getCurrentPoint(); 56 56 57 58 57 Point2D point2 = drawer.transformedPoint(x2.doubleValue(), y2.doubleValue()); 58 Point2D point3 = drawer.transformedPoint(x3.doubleValue(), y3.doubleValue()); 59 59 60 61 62 60 drawer.getLinePath().curveTo((float)currentPoint.getX(), (float)currentPoint.getY(), 61 (float)point2.getX(), (float)point2.getY(), (float)point3.getX(), (float)point3.getY()); 62 } 63 63 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/EndPath.java
r23991 r34541 35 35 36 36 37 38 39 40 41 42 43 44 45 46 47 37 /** 38 * process : n : End path. 39 * @param operator The operator that is being executed. 40 * @param arguments List 41 */ 42 @Override 43 public void process(PDFOperator operator, List<COSBase> arguments) 44 { 45 PageDrawer drawer = (PageDrawer)context; 46 drawer.getLinePath().reset(); 47 } 48 48 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/FillEvenOddAndStrokePath.java
r32520 r34541 36 36 { 37 37 38 39 40 41 42 43 44 45 46 47 48 49 50 38 /** 39 * fill and stroke the path. 40 * @param operator The operator that is being executed. 41 * @param arguments List 42 * 43 * @throws IOException If an error occurs while processing the font. 44 */ 45 @Override 46 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 47 { 48 PageDrawer drawer = (PageDrawer)context; 49 drawer.drawPath(true, true, Path2D.WIND_EVEN_ODD); 50 } 51 51 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/FillEvenOddRule.java
r23991 r34541 38 38 { 39 39 40 41 42 43 40 /** 41 * Log instance. 42 */ 43 private static final Log log = LogFactory.getLog(FillEvenOddRule.class); 44 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 45 /** 46 * process : f* : fill path using even odd rule. 47 * @param operator The operator that is being executed. 48 * @param arguments List 49 * 50 * @throws IOException if there is an error during execution. 51 */ 52 @Override 53 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 54 { 55 try 56 { 57 ///dwilson refactoring 58 PageDrawer drawer = (PageDrawer)context; 59 drawer.drawPath(false, true, GeneralPath.WIND_EVEN_ODD); 60 } 61 catch (Exception e) 62 { 63 log.warn(e, e); 64 } 65 } 66 66 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/FillNonZeroAndStrokePath.java
r32520 r34541 36 36 { 37 37 38 39 40 41 42 43 44 45 46 47 48 49 50 38 /** 39 * fill and stroke the path. 40 * @param operator The operator that is being executed. 41 * @param arguments List 42 * 43 * @throws IOException If an error occurs while processing the font. 44 */ 45 @Override 46 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 47 { 48 PageDrawer drawer = (PageDrawer)context; 49 drawer.drawPath(true, true, Path2D.WIND_NON_ZERO); 50 } 51 51 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/FillNonZeroRule.java
r23991 r34541 36 36 { 37 37 38 39 40 41 42 43 44 45 46 47 48 49 50 38 /** 39 * process : F/f : fill path using non zero winding rule. 40 * @param operator The operator that is being executed. 41 * @param arguments List 42 * 43 * @throws IOException If there is an error during the processing. 44 */ 45 @Override 46 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 47 { 48 PageDrawer drawer = (PageDrawer)context; 49 drawer.drawPath(false, true, GeneralPath.WIND_NON_ZERO); 50 } 51 51 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/Invoke.java
r32515 r34541 45 45 46 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 47 /** 48 * process : Do : Paint the specified XObject (section 4.7). 49 * @param operator The operator that is being executed. 50 * @param arguments List 51 * @throws IOException If there is an error invoking the sub object. 52 */ 53 @Override 54 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 55 { 56 PageDrawer drawer = (PageDrawer)context; 57 PDPage page = drawer.getPage(); 58 COSName objectName = (COSName)arguments.get( 0 ); 59 Map<?, ?> xobjects = drawer.getResources().getXObjects(); 60 PDXObject xobject = (PDXObject)xobjects.get( objectName.getName() ); 61 if( xobject instanceof PDXObjectImage ) 62 { 63 drawer.drawImage(); 64 } 65 else if(xobject instanceof PDXObjectForm) 66 { 67 PDXObjectForm form = (PDXObjectForm)xobject; 68 COSStream invoke = (COSStream)form.getCOSObject(); 69 PDResources pdResources = form.getResources(); 70 if(pdResources == null) 71 { 72 pdResources = page.findResources(); 73 } 74 // if there is an optional form matrix, we have to 75 // map the form space to the user space 76 Matrix matrix = form.getMatrix(); 77 if (matrix != null) 78 { 79 Matrix xobjectCTM = matrix.multiply( context.getGraphicsState().getCurrentTransformationMatrix()); 80 context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM); 81 } 82 getContext().processSubStream( page, pdResources, invoke ); 83 } 84 else 85 { 86 //unknown xobject type 87 } 88 88 89 89 90 91 90 //invoke named object. 91 } 92 92 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/LineTo.java
r23991 r34541 37 37 38 38 39 40 41 42 43 44 45 46 47 39 /** 40 * process : l : Append straight line segment to path. 41 * @param operator The operator that is being executed. 42 * @param arguments List 43 */ 44 @Override 45 public void process(PDFOperator operator, List<COSBase> arguments) 46 { 47 PageDrawer drawer = (PageDrawer)context; 48 48 49 50 51 49 //append straight line segment from the current point to the point. 50 COSNumber x = (COSNumber)arguments.get( 0 ); 51 COSNumber y = (COSNumber)arguments.get( 1 ); 52 52 53 54 55 53 Point2D pos = drawer.transformedPoint(x.doubleValue(), y.doubleValue()); 54 drawer.getLinePath().lineTo((float)pos.getX(), (float)pos.getY()); 55 } 56 56 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/MoveTo.java
r23991 r34541 39 39 { 40 40 41 42 43 44 41 /** 42 * Log instance. 43 */ 44 private static final Log log = LogFactory.getLog(MoveTo.class); 45 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 46 /** 47 * process : m : Begin new subpath. 48 * @param operator The operator that is being executed. 49 * @param arguments List 50 * @throws IOException If there is an error processing the operator. 51 */ 52 @Override 53 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 54 { 55 try 56 { 57 PageDrawer drawer = (PageDrawer)context; 58 COSNumber x = (COSNumber)arguments.get( 0 ); 59 COSNumber y = (COSNumber)arguments.get( 1 ); 60 Point2D pos = drawer.transformedPoint(x.doubleValue(), y.doubleValue()); 61 drawer.getLinePath().moveTo((float)pos.getX(), (float)pos.getY()); 62 } 63 catch (Exception exception) 64 { 65 log.warn( exception, exception); 66 } 67 } 68 68 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/SHFill.java
r23991 r34541 37 37 { 38 38 39 40 41 42 43 44 45 46 47 48 49 50 51 39 /** 40 * process : sh : shade fill the path or clipping area. 41 * @param operator The operator that is being executed. 42 * @param arguments List 43 * 44 * @throws IOException if there is an error during execution. 45 */ 46 @Override 47 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 48 { 49 PageDrawer drawer = (PageDrawer)context; 50 drawer.drawPath(false, true, Path2D.WIND_NON_ZERO); 51 } 52 52 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/SetLineCapStyle.java
r23991 r34541 35 35 { 36 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 37 /** 38 * Set the line cap style. 39 * @param operator The operator that is being executed. 40 * @param arguments List 41 * 42 * @throws IOException If an error occurs while processing the font. 43 */ 44 @Override 45 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 46 { 47 super.process( operator, arguments ); 48 int lineCapStyle = context.getGraphicsState().getLineCap(); 49 PageDrawer drawer = (PageDrawer)context; 50 BasicStroke stroke = drawer.getStroke(); 51 if (stroke == null) 52 { 53 drawer.setStroke( new BasicStroke(1,lineCapStyle,BasicStroke.JOIN_MITER) ); 54 } 55 else 56 { 57 drawer.setStroke( new BasicStroke(stroke.getLineWidth(), lineCapStyle, stroke.getLineJoin(), 58 stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase())); 59 } 60 } 61 61 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/SetLineDashPattern.java
r23991 r34541 36 36 { 37 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 38 /** 39 * Set the line dash pattern. 40 * @param operator The operator that is being executed. 41 * @param arguments List 42 * 43 * @throws IOException If an error occurs while processing the font. 44 */ 45 @Override 46 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 47 { 48 super.process( operator, arguments ); 49 PDLineDashPattern lineDashPattern = context.getGraphicsState().getLineDashPattern(); 50 PageDrawer drawer = (PageDrawer)context; 51 BasicStroke stroke = drawer.getStroke(); 52 if (stroke == null) 53 { 54 if (lineDashPattern.isDashPatternEmpty()) 55 { 56 drawer.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f) ); 57 } 58 else 59 { 60 drawer.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, 61 lineDashPattern.getCOSDashPattern().toFloatArray(), lineDashPattern.getPhaseStart()) ); 62 } 63 } 64 else 65 { 66 if (lineDashPattern.isDashPatternEmpty()) 67 { 68 drawer.setStroke( new BasicStroke(stroke.getLineWidth(), stroke.getEndCap(), 69 stroke.getLineJoin(), stroke.getMiterLimit()) ); 70 } 71 else 72 { 73 drawer.setStroke( new BasicStroke(stroke.getLineWidth(), stroke.getEndCap(), stroke.getLineJoin(), 74 stroke.getMiterLimit(), lineDashPattern.getCOSDashPattern().toFloatArray(), 75 lineDashPattern.getPhaseStart()) ); 76 } 77 } 78 } 79 79 80 80 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/SetLineJoinStyle.java
r23991 r34541 35 35 { 36 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 37 /** 38 * Set the line cap style. 39 * @param operator The operator that is being executed. 40 * @param arguments List 41 * 42 * @throws IOException If an error occurs while processing the font. 43 */ 44 @Override 45 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 46 { 47 super.process( operator, arguments ); 48 int lineJoinStyle = context.getGraphicsState().getLineJoin(); 49 PageDrawer drawer = (PageDrawer)context; 50 BasicStroke stroke = drawer.getStroke(); 51 if (stroke == null) 52 { 53 drawer.setStroke( new BasicStroke(1,BasicStroke.CAP_SQUARE,lineJoinStyle) ); 54 } 55 else 56 { 57 drawer.setStroke( new BasicStroke(stroke.getLineWidth(), stroke.getEndCap(), lineJoinStyle, 58 stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase()) ); 59 } 60 } 61 61 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/SetLineMiterLimit.java
r23991 r34541 35 35 { 36 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 37 /** 38 * Set the line dash pattern. 39 * @param operator The operator that is being executed. 40 * @param arguments List 41 * 42 * @throws IOException If an error occurs while processing the font. 43 */ 44 @Override 45 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 46 { 47 super.process(operator, arguments); 48 float miterLimit = (float)context.getGraphicsState().getMiterLimit(); 49 PageDrawer drawer = (PageDrawer)context; 50 BasicStroke stroke = drawer.getStroke(); 51 if (stroke == null) 52 { 53 drawer.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 54 miterLimit, null, 0.0f)); 55 } 56 else 57 { 58 drawer.setStroke( new BasicStroke(stroke.getLineWidth(), stroke.getEndCap(), stroke.getLineJoin(), 59 miterLimit, null, 0.0f)); 60 } 61 } 62 62 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/SetLineWidth.java
r23991 r34541 35 35 { 36 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 37 /** 38 * w Set line width. 39 * @param operator The operator that is being executed. 40 * @param arguments List 41 * @throws IOException If an error occurs while processing the font. 42 */ 43 @Override 44 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 45 { 46 super.process( operator, arguments ); 47 float lineWidth = (float)context.getGraphicsState().getLineWidth(); 48 if (lineWidth == 0) 49 { 50 lineWidth = 1; 51 } 52 PageDrawer drawer = (PageDrawer)context; 53 BasicStroke stroke = drawer.getStroke(); 54 if (stroke == null) 55 { 56 drawer.setStroke( new BasicStroke( lineWidth ) ); 57 } 58 else 59 { 60 drawer.setStroke( new BasicStroke(lineWidth, stroke.getEndCap(), stroke.getLineJoin(), 61 stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase()) ); 62 } 63 } 64 64 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/operators/StrokePath.java
r23991 r34541 35 35 { 36 36 37 38 39 40 41 42 43 44 45 46 47 48 49 37 /** 38 * S stroke the path. 39 * @param operator The operator that is being executed. 40 * @param arguments List 41 * 42 * @throws IOException If an error occurs while processing the font. 43 */ 44 @Override 45 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException 46 { 47 PageDrawer drawer = (PageDrawer)context; 48 drawer.drawPath(true, false, 0); 49 } 50 50 }
Note:
See TracChangeset
for help on using the changeset viewer.