Changeset 34541 in osm for applications/editors/josm/plugins/pdfimport/src
- Timestamp:
- 2018-08-18T19:24:07+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/pdfimport/src/pdfimport
- Files:
-
- 42 edited
-
FilePlacement.java (modified) (1 diff)
-
FilePlacement18.java (modified) (2 diffs)
-
GuiFieldBool.java (modified) (1 diff)
-
GuiFieldDouble.java (modified) (1 diff)
-
GuiFieldHex.java (modified) (1 diff)
-
GuiFieldInteger.java (modified) (1 diff)
-
GuiFieldLong.java (modified) (1 diff)
-
GuiFieldString.java (modified) (1 diff)
-
GuiPanel.java (modified) (1 diff)
-
GuiProjections.java (modified) (3 diffs)
-
LoadPdfDialog.java (modified) (2 diffs)
-
PdfImportAction.java (modified) (1 diff)
-
PdfImportPlugin.java (modified) (1 diff)
-
Preferences.java (modified) (1 diff)
-
Preview.java (modified) (2 diffs)
-
ProjectionInfo.java (modified) (1 diff)
-
pdfbox/PageDrawer.java (modified) (2 diffs)
-
pdfbox/operators/AppendRectangleToPath.java (modified) (1 diff)
-
pdfbox/operators/BeginInlineImage.java (modified) (1 diff)
-
pdfbox/operators/ClipEvenOddRule.java (modified) (1 diff)
-
pdfbox/operators/ClipNonZeroRule.java (modified) (1 diff)
-
pdfbox/operators/CloseFillEvenOddAndStrokePath.java (modified) (1 diff)
-
pdfbox/operators/CloseFillNonZeroAndStrokePath.java (modified) (1 diff)
-
pdfbox/operators/ClosePath.java (modified) (1 diff)
-
pdfbox/operators/CurveTo.java (modified) (1 diff)
-
pdfbox/operators/CurveToReplicateFinalPoint.java (modified) (1 diff)
-
pdfbox/operators/CurveToReplicateInitialPoint.java (modified) (1 diff)
-
pdfbox/operators/EndPath.java (modified) (1 diff)
-
pdfbox/operators/FillEvenOddAndStrokePath.java (modified) (1 diff)
-
pdfbox/operators/FillEvenOddRule.java (modified) (1 diff)
-
pdfbox/operators/FillNonZeroAndStrokePath.java (modified) (1 diff)
-
pdfbox/operators/FillNonZeroRule.java (modified) (1 diff)
-
pdfbox/operators/Invoke.java (modified) (1 diff)
-
pdfbox/operators/LineTo.java (modified) (1 diff)
-
pdfbox/operators/MoveTo.java (modified) (1 diff)
-
pdfbox/operators/SHFill.java (modified) (1 diff)
-
pdfbox/operators/SetLineCapStyle.java (modified) (1 diff)
-
pdfbox/operators/SetLineDashPattern.java (modified) (1 diff)
-
pdfbox/operators/SetLineJoinStyle.java (modified) (1 diff)
-
pdfbox/operators/SetLineMiterLimit.java (modified) (1 diff)
-
pdfbox/operators/SetLineWidth.java (modified) (1 diff)
-
pdfbox/operators/StrokePath.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pdfimport/src/pdfimport/FilePlacement.java
r34398 r34541 14 14 15 15 public class FilePlacement { 16 /*17 * provide data and services to place a PDF-File to world coordinates18 * enhanced by FilePlacement18 but kept for compatibilty to existing code19 */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 * Handle plasement of a pdf File38 * provide transformation, load & save, GUI-componennt39 * superseeds (legacy) class FilePlacement40 */41 42 public class PlacementPanel {43 private class CoorFields {44 /*45 * Coordinte Fields46 * keep Fields representing a Coordinate together47 * functionality: allow entering coordinate in the first field and transfer Y-Part to the second field48 * TODO: encapsulate to Componente49 */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 entry58 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 publicCoorFields(GuiFieldDoubleX, GuiFieldDoubleY) {70 x = X;71 y = Y;72 x.addFocusListener(new FocusListener() {73 @Override74 public void focusLost(FocusEvent e) {75 checkCoords(x, y);76 }77 78 @Override79 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 later85 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 FilePlacement112 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 @Override132 public void focusGained(FocusEvent e) {133 }134 135 @Override136 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 setting147 */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() {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 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 @Override188 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 @Override209 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 * Projection250 */251 panel.add(projectionChooser.getPanel(), cCornerHeading);252 /*253 * Max Corner254 */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 Corner270 */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 * Hints287 */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 / transformation297 * TODO: enshure this298 */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 }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; // the data is consistent and the object ready to use for transformation359 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 * TODO: compupte it now364 */365 return valid;366 } 367 public void setDependsOnValid(JComponent c) {368 panel.setDependsOnValid(c);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 if (panel==null) panel = new PlacementPanel(this);373 if (panel.panel==null) panel.build();374 return panel.panel;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 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 }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 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();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 return null;408 return null; 409 409 } 410 410 411 411 private double getDouble(Properties p, String name, double defaultValue) { 412 try {413 return Double.parseDouble(p.getProperty(name));414 } catch (Exception e) {415 return defaultValue;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 protected void fromProperties(Properties p) {421 super.fromProperties(p);422 panel.load();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 * TODO: evolve to a component with integrated display of dependend components15 */16 private JComponent companion =null;17 private boolean value = false;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 public JComponent getCompanion() {20 return companion;21 }19 public JComponent getCompanion() { 20 return companion; 21 } 22 22 23 public void setCompanion(JComponent c) {24 companion = c;25 if (companion != null) companion.setEnabled(isSelected());26 }23 public void setCompanion(JComponent c) { 24 companion = c; 25 if (companion != null) companion.setEnabled(isSelected()); 26 } 27 27 28 public boolean getValue() {29 return super.isSelected();30 }28 public boolean getValue() { 29 return super.isSelected(); 30 } 31 31 32 public void setValue(boolean value) {33 this.value = value;34 super.setSelected(value);35 }32 public void setValue(boolean value) { 33 this.value = value; 34 super.setSelected(value); 35 } 36 36 37 public GuiFieldBool() {38 super();39 addChangeListener(new Monitor());40 }37 public GuiFieldBool() { 38 super(); 39 addChangeListener(new Monitor()); 40 } 41 41 42 public GuiFieldBool(Action a) {43 super(a);44 addChangeListener(new Monitor());45 }42 public GuiFieldBool(Action a) { 43 super(a); 44 addChangeListener(new Monitor()); 45 } 46 46 47 public GuiFieldBool(Icon icon, boolean selected) {48 super(icon, selected);49 addChangeListener(new Monitor());50 }47 public GuiFieldBool(Icon icon, boolean selected) { 48 super(icon, selected); 49 addChangeListener(new Monitor()); 50 } 51 51 52 public GuiFieldBool(Icon icon) {53 super(icon);54 addChangeListener(new Monitor());55 }52 public GuiFieldBool(Icon icon) { 53 super(icon); 54 addChangeListener(new Monitor()); 55 } 56 56 57 public GuiFieldBool(String text, boolean selected) {58 super(text, selected);59 addChangeListener(new Monitor());60 }57 public GuiFieldBool(String text, boolean selected) { 58 super(text, selected); 59 addChangeListener(new Monitor()); 60 } 61 61 62 public GuiFieldBool(String text, Icon icon, boolean selected) {63 super(text, icon, selected);64 addChangeListener(new Monitor());65 }62 public GuiFieldBool(String text, Icon icon, boolean selected) { 63 super(text, icon, selected); 64 addChangeListener(new Monitor()); 65 } 66 66 67 public GuiFieldBool(String text, Icon icon) {68 super(text, icon);69 addChangeListener(new Monitor());70 }67 public GuiFieldBool(String text, Icon icon) { 68 super(text, icon); 69 addChangeListener(new Monitor()); 70 } 71 71 72 public GuiFieldBool(String text) {73 super(text);74 addChangeListener(new Monitor());75 }72 public GuiFieldBool(String text) { 73 super(text); 74 addChangeListener(new Monitor()); 75 } 76 76 77 private class Monitor implements ChangeListener {77 private class Monitor implements ChangeListener { 78 78 79 @Override80 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 }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 private double value;14 public CheckDouble checker;13 private double value; 14 public CheckDouble checker; 15 15 16 public GuiFieldDouble() {17 super();18 addFocusListener(checker = new CheckDouble());19 setValue(0.0);20 }16 public GuiFieldDouble() { 17 super(); 18 addFocusListener(checker = new CheckDouble()); 19 setValue(0.0); 20 } 21 21 22 @SuppressWarnings("unused")23 private GuiFieldDouble(String text) {24 super(text);25 addFocusListener(checker = new CheckDouble());26 }22 @SuppressWarnings("unused") 23 private GuiFieldDouble(String text) { 24 super(text); 25 addFocusListener(checker = new CheckDouble()); 26 } 27 27 28 public GuiFieldDouble(double v) {29 super();30 addFocusListener(checker = new CheckDouble());31 setValue(v);32 }28 public GuiFieldDouble(double v) { 29 super(); 30 addFocusListener(checker = new CheckDouble()); 31 setValue(v); 32 } 33 33 34 public void setValue(double v) {35 super.setText(Double.toString(v));36 this.checker.check(this);37 }34 public void setValue(double v) { 35 super.setText(Double.toString(v)); 36 this.checker.check(this); 37 } 38 38 39 public double getValue() throws NumberFormatException {40 if (!dataValid) throw new NumberFormatException();41 return value;42 }39 public double getValue() throws NumberFormatException { 40 if (!dataValid) throw new NumberFormatException(); 41 return value; 42 } 43 43 44 public class CheckDouble implements FocusListener {44 public class CheckDouble implements FocusListener { 45 45 46 @Override47 public void focusGained(FocusEvent e) {48 }46 @Override 47 public void focusGained(FocusEvent e) { 48 } 49 49 50 @Override51 public void focusLost(FocusEvent event) {52 check((GuiFieldDouble) event.getSource());53 }50 @Override 51 public void focusLost(FocusEvent event) { 52 check((GuiFieldDouble) event.getSource()); 53 } 54 54 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 }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 private int value;19 public CheckHex checker;18 private int value; 19 public CheckHex checker; 20 20 21 public GuiFieldHex() {22 super();23 addFocusListener(checker = new CheckHex());24 setValue(0);25 }21 public GuiFieldHex() { 22 super(); 23 addFocusListener(checker = new CheckHex()); 24 setValue(0); 25 } 26 26 27 @SuppressWarnings("unused")28 public GuiFieldHex(String text) {29 super(text);30 addFocusListener(checker = new CheckHex());31 }27 @SuppressWarnings("unused") 28 public GuiFieldHex(String text) { 29 super(text); 30 addFocusListener(checker = new CheckHex()); 31 } 32 32 33 public GuiFieldHex(int v) {34 super();35 addFocusListener(checker = new CheckHex());36 setValue(v);37 }33 public GuiFieldHex(int v) { 34 super(); 35 addFocusListener(checker = new CheckHex()); 36 setValue(v); 37 } 38 38 39 public void setValue(int v) {40 super.setText("#" + Integer.toHexString(v));41 value=v;42 this.checker.check(this);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 public int getValue() throws NumberFormatException {46 if (!dataValid) throw new NumberFormatException();47 return value;48 }45 public int getValue() throws NumberFormatException { 46 if (!dataValid) throw new NumberFormatException(); 47 return value; 48 } 49 49 50 @Override51 public void setEnabled(boolean enabled) {52 super.setEnabled(enabled);53 this.checker.check(this);54 }50 @Override 51 public void setEnabled(boolean enabled) { 52 super.setEnabled(enabled); 53 this.checker.check(this); 54 } 55 55 56 public class CheckHex implements FocusListener {56 public class CheckHex implements FocusListener { 57 57 58 @Override59 public void focusGained(FocusEvent e) {60 }58 @Override 59 public void focusGained(FocusEvent e) { 60 } 61 61 62 @Override63 public void focusLost(FocusEvent event) {64 check((GuiFieldHex) event.getSource());65 }62 @Override 63 public void focusLost(FocusEvent event) { 64 check((GuiFieldHex) event.getSource()); 65 } 66 66 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 }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 private int value;15 public CheckInteger checker;14 private int value; 15 public CheckInteger checker; 16 16 17 public GuiFieldInteger() {18 super();19 addFocusListener(checker = new CheckInteger());20 setValue(0);21 }17 public GuiFieldInteger() { 18 super(); 19 addFocusListener(checker = new CheckInteger()); 20 setValue(0); 21 } 22 22 23 @SuppressWarnings("unused")24 private GuiFieldInteger(String text) {25 super(text);26 addFocusListener(checker = new CheckInteger());27 }23 @SuppressWarnings("unused") 24 private GuiFieldInteger(String text) { 25 super(text); 26 addFocusListener(checker = new CheckInteger()); 27 } 28 28 29 public GuiFieldInteger(int v) {30 super();31 addFocusListener(checker = new CheckInteger());32 setValue(v);33 }29 public GuiFieldInteger(int v) { 30 super(); 31 addFocusListener(checker = new CheckInteger()); 32 setValue(v); 33 } 34 34 35 public void setValue(int v) {36 super.setText(Integer.toString(v));37 value=v;38 this.checker.check(this);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 public int getValue() throws NumberFormatException {42 if (!dataValid) throw new NumberFormatException();43 return value;44 }41 public int getValue() throws NumberFormatException { 42 if (!dataValid) throw new NumberFormatException(); 43 return value; 44 } 45 45 46 public class CheckInteger implements FocusListener {46 public class CheckInteger implements FocusListener { 47 47 48 @Override49 public void focusGained(FocusEvent e) {50 }48 @Override 49 public void focusGained(FocusEvent e) { 50 } 51 51 52 @Override53 public void focusLost(FocusEvent event) {54 check((GuiFieldInteger) event.getSource());55 }52 @Override 53 public void focusLost(FocusEvent event) { 54 check((GuiFieldInteger) event.getSource()); 55 } 56 56 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 }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 private long value;15 public CheckLong checker;14 private long value; 15 public CheckLong checker; 16 16 17 public GuiFieldLong() {18 super();19 addFocusListener(checker = new CheckLong());20 setValue(0);21 }17 public GuiFieldLong() { 18 super(); 19 addFocusListener(checker = new CheckLong()); 20 setValue(0); 21 } 22 22 23 @SuppressWarnings("unused")24 private GuiFieldLong(String text) {25 super(text);26 addFocusListener(checker = new CheckLong());27 }23 @SuppressWarnings("unused") 24 private GuiFieldLong(String text) { 25 super(text); 26 addFocusListener(checker = new CheckLong()); 27 } 28 28 29 public GuiFieldLong(long v) {30 super();31 addFocusListener(checker = new CheckLong());32 setValue(v);33 }29 public GuiFieldLong(long v) { 30 super(); 31 addFocusListener(checker = new CheckLong()); 32 setValue(v); 33 } 34 34 35 public void setValue(long v) {36 super.setText(Long.toString(v));37 value=v;38 this.checker.check(this);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 public long getValue() throws NumberFormatException {42 if (!dataValid) throw new NumberFormatException();43 return value;44 }41 public long getValue() throws NumberFormatException { 42 if (!dataValid) throw new NumberFormatException(); 43 return value; 44 } 45 45 46 public class CheckLong implements FocusListener {46 public class CheckLong implements FocusListener { 47 47 48 @Override49 public void focusGained(FocusEvent e) {50 }48 @Override 49 public void focusGained(FocusEvent e) { 50 } 51 51 52 @Override53 public void focusLost(FocusEvent event) {54 check((GuiFieldLong) event.getSource());55 }52 @Override 53 public void focusLost(FocusEvent event) { 54 check((GuiFieldLong) event.getSource()); 55 } 56 56 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 }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 * TODO: integrate presentation of dataValid;11 */9 /* 10 * TODO: integrate presentation of dataValid; 11 */ 12 12 13 protected Border defaultBorder;14 protected boolean dataValid;13 protected Border defaultBorder; 14 protected boolean dataValid; 15 15 16 public GuiFieldString() {17 super();18 defaultBorder = getBorder();19 }16 public GuiFieldString() { 17 super(); 18 defaultBorder = getBorder(); 19 } 20 20 21 public GuiFieldString(String text) {22 super(text);23 defaultBorder = getBorder();24 }21 public GuiFieldString(String text) { 22 super(text); 23 defaultBorder = getBorder(); 24 } 25 25 26 public boolean isDataValid() {27 return dataValid;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 public GuiPanel() {13 super();14 }12 public GuiPanel() { 13 super(); 14 } 15 15 16 public GuiPanel(LayoutManager layout) {17 super(layout);18 }16 public GuiPanel(LayoutManager layout) { 17 super(layout); 18 } 19 19 20 @Override21 public void setEnabled(boolean enabled) {22 for (Component c : this.getComponents()) {23 c.setEnabled(enabled);24 }25 super.setEnabled(enabled);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 * provide a component let the user select a projection32 * 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 projection35 */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 Projection46 */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 now53 if ((p instanceof CustomProjectionChoice)) continue;// can not handle this projection for now54 addItem(p);55 }56 addActionListener(monitor);57 setProjection (Main.getProjection());58 }59 60 public void setProjection (Projection p) {61 /*62 * set current Projection to @p63 * update internal variables64 */65 if (p==null) return;// better keep the old one66 projection = p;67 pName.setText(p.toString());68 pCode.setText(p.toCode());69 pInfo.setText(userHints(p));70 /*71 * find projectionChoice that matches current code72 */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 searching79 }80 }81 }82 /*83 * Not found ==> search in combobox84 */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 searching92 }93 }94 /*95 * Still not found ==> add it now96 */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 accordingly109 */110 @Override111 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 projection128 */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 @p147 */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 it156 }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 }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 // 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();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 // btn.setFocusable(true);203 // btn.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");204 // btn.getActionMap().put("enter", btn.getAction());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 // return projPref.getPreferencePanel(null);208 // return projPref.getPreferencePanel(null); 209 209 //} 210 210 // 211 211 //protected JPanel buildButtonRow() { 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;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 // 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 ESCAPE233 // getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)234 // .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape");235 // getRootPane().getActionMap().put("escape", actCancel);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 // 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 // @Override246 // public void actionPerformed(ActionEvent e) {247 // projPref.setPreferences(projPref.getPreferences(projPrefPanel));248 // setVisible(false);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 // 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 // @Override260 // public void actionPerformed(ActionEvent e) {261 // setVisible(false);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 // 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 #8775271 // new WindowGeometry(this).remember(getClass().getName() + ".geometry");272 // }273 // super.setVisible(visible);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 public static class MainButtons {52 public JButton okButton;53 public JButton cancelButton;54 public JButton showButton;55 public JButton saveButton;56 public JPanel panel;57 58 public MainButtons() {59 }60 61 void build(LoadPdfDialog loadPdfDialog) {62 /*63 * build the dialog Window from components64 */65 okButton = new JButton(tr("Import"));66 okButton.addActionListener(new ActionListener() {67 @Override68 public void actionPerformed(ActionEvent e) {69 loadPdfDialog.importAction();70 }71 });72 saveButton = new JButton(tr("Save"));73 saveButton.addActionListener(new ActionListener() {74 @Override75 public void actionPerformed(ActionEvent e) {76 loadPdfDialog.saveAction();77 }78 });79 80 showButton = new JButton(tr("Show target"));81 showButton.addActionListener(new ActionListener() {82 @Override83 public void actionPerformed(ActionEvent e) {84 loadPdfDialog.showAction();85 }86 });87 88 cancelButton = new JButton(tr("Cancel"));89 cancelButton.addActionListener(new ActionListener() {90 @Override91 public void actionPerformed(ActionEvent e) {92 loadPdfDialog.cancelAction();93 }94 });95 96 panel = new JPanel(new FlowLayout());97 panel.add(cancelButton);98 panel.add(showButton);99 panel.add(okButton);100 panel.add(saveButton);101 showButton.setVisible(Preferences.isLegacyActions());102 saveButton.setVisible(Preferences.isLegacyActions());103 }104 }105 106 107 private static class Config {108 /*109 * encapsulate options for Path optimizer110 * provide GUI111 */112 public GuiFieldBool debugModeCheck;113 public GuiFieldBool mergeCloseNodesCheck;114 public GuiFieldDouble mergeCloseNodesTolerance;115 public GuiFieldBool removeSmallObjectsCheck;116 public GuiFieldDouble removeSmallObjectsSize;117 public JTextField colorFilterColor;118 public GuiFieldBool colorFilterCheck;119 public GuiFieldBool removeParallelSegmentsCheck;120 public GuiFieldDouble removeParallelSegmentsTolerance;121 public GuiFieldBool removeLargeObjectsCheck;122 public GuiFieldDouble removeLargeObjectsSize;123 public GuiFieldBool limitPathCountCheck;124 public GuiFieldInteger limitPathCount;125 public GuiFieldBool splitOnColorChangeCheck;126 public GuiFieldBool splitOnShapeClosedCheck;127 public GuiFieldBool splitOnSingleSegmentCheck;128 public GuiFieldBool splitOnOrthogonalCheck;129 private JPanel panel;130 131 public Config() {132 build();133 }134 135 public JComponent getComponent() {136 return panel;137 }138 139 private void build() {140 141 142 debugModeCheck = new GuiFieldBool(tr("Debug info"), Preferences.isDebugTags());143 144 mergeCloseNodesTolerance = new GuiFieldDouble(Preferences.getMergeNodesValue());145 mergeCloseNodesCheck = new GuiFieldBool(tr("Merge close nodes"), Preferences.isMergeNodes());146 mergeCloseNodesCheck.setCompanion(mergeCloseNodesTolerance);147 148 removeSmallObjectsSize = new GuiFieldDouble(Preferences.getRemoveSmallValue());149 removeSmallObjectsCheck = new GuiFieldBool(tr("Remove objects smaller than"),Preferences.isRemoveSmall());150 removeSmallObjectsCheck.setCompanion(removeSmallObjectsSize);151 152 removeLargeObjectsSize = new GuiFieldDouble((Preferences.getRemoveLargeValue()));153 removeLargeObjectsCheck = new GuiFieldBool(tr("Remove objects larger than"),Preferences.isRemoveLarge());154 removeLargeObjectsCheck.setCompanion(removeLargeObjectsSize);155 156 colorFilterColor = new GuiFieldHex(Preferences.getLimitColorValue());157 colorFilterCheck = new GuiFieldBool(tr("Only this color"), Preferences.isLimitColor());158 colorFilterCheck.setCompanion(colorFilterColor);159 160 removeParallelSegmentsTolerance = new GuiFieldDouble((Preferences.getRemoveParallelValue()));161 removeParallelSegmentsCheck = new GuiFieldBool(tr("Remove parallel lines"),Preferences.isRemoveParallel());162 removeParallelSegmentsCheck.setCompanion(removeParallelSegmentsTolerance);163 164 limitPathCount = new GuiFieldInteger((Preferences.getLimitPathValue()));165 limitPathCountCheck = new GuiFieldBool(tr("Take only first X paths"),Preferences.isLimitPath());166 limitPathCountCheck.setCompanion(limitPathCount);167 168 splitOnColorChangeCheck = new GuiFieldBool(tr("Color/width change"),Preferences.isLayerAttribChange());169 splitOnShapeClosedCheck = new GuiFieldBool(tr("Shape closed"), Preferences.isLayerClosed());170 171 splitOnSingleSegmentCheck = new GuiFieldBool(tr("Single segments", Preferences.isLayerSegment()));172 splitOnOrthogonalCheck = new GuiFieldBool(tr("Orthogonal shapes", Preferences.isLayerOrtho()));173 174 panel = new JPanel(new GridBagLayout());175 panel.setBorder(BorderFactory.createTitledBorder(tr("Import settings")));176 177 GridBagConstraints cBasic = new GridBagConstraints();178 cBasic.gridx = GridBagConstraints.RELATIVE;179 cBasic.gridy = GridBagConstraints.RELATIVE;180 cBasic.insets = new Insets(0, 0, 0, 4);181 cBasic.anchor = GridBagConstraints.LINE_START;182 cBasic.fill = GridBagConstraints.HORIZONTAL;183 cBasic.gridheight = 1;184 cBasic.gridwidth = 1;185 cBasic.ipadx = 0;186 cBasic.ipady = 0;187 cBasic.weightx = 0.0;188 cBasic.weighty = 0.0;189 190 GridBagConstraints cLeft = (GridBagConstraints) cBasic.clone();191 cLeft.gridx = 0;192 193 GridBagConstraints cMiddle = (GridBagConstraints) cBasic.clone();194 cMiddle.gridx = 1;195 cMiddle.anchor = GridBagConstraints.LINE_END;196 197 GridBagConstraints cRight = (GridBagConstraints) cBasic.clone();198 cRight.gridx = 2;199 200 panel.add(mergeCloseNodesCheck, cLeft);201 panel.add(new JLabel(tr("Tolerance:"),SwingConstants.RIGHT), cMiddle);202 panel.add(mergeCloseNodesTolerance, cRight);203 204 panel.add(removeSmallObjectsCheck, cLeft);205 panel.add(new JLabel(tr("Tolerance:"),SwingConstants.RIGHT), cMiddle);206 panel.add(removeSmallObjectsSize, cRight);207 208 panel.add(removeLargeObjectsCheck, cLeft);209 panel.add(new JLabel(tr("Tolerance:"),SwingConstants.RIGHT), cMiddle);210 panel.add(removeLargeObjectsSize, cRight);211 212 panel.add(removeParallelSegmentsCheck, cLeft);213 panel.add(new JLabel(tr("Max distance:"),SwingConstants.RIGHT), cMiddle);214 panel.add(removeParallelSegmentsTolerance, cRight);215 216 panel.add(limitPathCountCheck, cLeft);217 panel.add(limitPathCount, cRight);218 219 panel.add(colorFilterCheck, cLeft);220 panel.add(colorFilterColor, cRight);221 222 panel.add(debugModeCheck, cLeft);223 224 cLeft.gridy = 8; panel.add(new JLabel(tr("Introduce separate layers for:")), cLeft);225 cMiddle.gridy = 8; panel.add(splitOnShapeClosedCheck, cMiddle);226 cRight.gridy = 8; panel.add(splitOnSingleSegmentCheck, cRight);227 cMiddle.gridy = 9; panel.add(splitOnColorChangeCheck, cMiddle);228 cRight.gridy = 9;panel.add(splitOnOrthogonalCheck, cRight);229 }230 }231 232 static class LoadProgressRenderer implements ProgressRenderer {233 private final JProgressBar pBar;234 private String title = "";235 236 LoadProgressRenderer(JProgressBar pb) {237 this.pBar = pb;238 this.pBar.setMinimum(0);239 this.pBar.setValue(0);240 this.pBar.setMaximum(1);241 this.pBar.setString("");242 this.pBar.setStringPainted(true);243 244 }245 246 @Override247 public void setCustomText(String message) {248 this.pBar.setString(this.title + message);249 }250 251 @Override252 public void setIndeterminate(boolean indeterminate) {253 this.pBar.setIndeterminate(indeterminate);254 }255 256 @Override257 public void setMaximum(int maximum) {258 this.pBar.setMaximum(maximum);259 }260 261 @Override262 public void setTaskTitle(String taskTitle) {263 this.title = taskTitle;264 this.pBar.setString(this.title);265 }266 267 @Override268 public void setValue(int value) {269 this.pBar.setValue(value);270 }271 272 public void finish() {273 this.pBar.setString(tr("Finished"));274 this.pBar.setValue(this.pBar.getMaximum());275 }276 277 }278 279 private File pdfFile;280 private final FilePlacement18 placement = new FilePlacement18();281 282 private PathOptimizer pdfData;283 // private OsmDataLayer dataLayer;284 285 private final JButton loadFileButton = new JButton(tr("Load preview ..."));286 287 private final JProgressBar loadProgress = new JProgressBar();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 private OsmDataLayer newLayer;290 291 private LoadProgressRenderer progressRenderer;292 293 public LoadPdfDialog() {294 buildGUI();295 removeLayer();296 if (Preferences.getGuiMode() == Preferences.GuiMode.Simple) {297 loadFileButton.setVisible(false);298 configPanel.panel.setVisible(false);299 actionPanel.saveButton.setVisible(false);300 actionPanel.showButton.setVisible(false);301 setSize(new Dimension(380, 350));302 if (!loadAction()) {303 cancelAction();304 return;305 }306 } else {307 setSize(new Dimension(450, 600));308 }309 setAlwaysOnTop(true);310 setVisible(true);311 }312 313 Component placementPanel = placement.getGui();314 MainButtons actionPanel = new MainButtons();315 Config configPanel = new Config();316 317 private void buildGUI() {318 /*319 * build the GUI from Components320 */321 GridBagConstraints c = new GridBagConstraints();322 c.gridheight = 1;323 c.gridwidth = 1;324 c.gridx = 0;325 c.gridy = GridBagConstraints.RELATIVE;326 c.fill = GridBagConstraints.BOTH;327 c.insets = new java.awt.Insets(0, 0, 0, 0);328 329 actionPanel.build(this);330 331 loadFileButton.addActionListener(new ActionListener() {332 @Override333 public void actionPerformed(ActionEvent e) {334 loadAction();335 }336 });337 338 progressRenderer = new LoadProgressRenderer(loadProgress);339 340 JPanel panel = new JPanel(new GridBagLayout());341 342 panel.add(configPanel.getComponent(), c);343 c.fill = GridBagConstraints.HORIZONTAL;344 panel.add(loadFileButton, c);345 c.fill = GridBagConstraints.BOTH;346 panel.add(placementPanel, c);347 panel.add(actionPanel.panel, c);348 c.fill = GridBagConstraints.HORIZONTAL;349 panel.add(this.loadProgress, c);350 351 setContentPane(panel);352 addWindowListener(new WindowAdapter() {353 @Override354 public void windowClosing(WindowEvent e) {355 cancelAction();356 }357 });358 placement.setDependsOnValid(actionPanel.okButton);359 360 /*361 * TODO: Make okButton to default Button of Dialog, make cancelButton to react on ESC-Key362 */363 // SwingUtilities.getRootPane(panel).setDefaultButton(actionPanel.okButton);364 }365 366 private boolean loadAction() {367 /*368 * perform load PDF file to preview369 * TODO: load preview to previous placement, involves reverse transform370 */371 final File newFileName = this.chooseFile();372 373 if (newFileName == null) {374 return false;375 }376 Logging.debug("PdfImport: Load Preview");377 this.removeLayer();378 379 this.loadFileButton.setEnabled(false);380 381 this.runAsBackgroundTask(new Runnable() {382 @Override383 public void run() {384 // async part385 LoadPdfDialog.this.loadProgress.setVisible(true);386 SwingRenderingProgressMonitor monitor = new SwingRenderingProgressMonitor(progressRenderer);387 monitor.beginTask("Loading file", 1000);388 pdfData = loadPDF(newFileName, monitor.createSubTaskMonitor(500, false));389 OsmBuilder.Mode mode = LoadPdfDialog.this.configPanel.debugModeCheck.getValue()390 ? OsmBuilder.Mode.Debug391 : OsmBuilder.Mode.Draft;392 393 if (pdfData != null) {394 LoadPdfDialog.this.newLayer = LoadPdfDialog.this.makeLayer(395 tr("PDF preview: ") + newFileName.getName(), new FilePlacement(), mode,396 monitor.createSubTaskMonitor(500, false));397 }398 399 monitor.finishTask();400 progressRenderer.finish();401 }402 }, new ActionListener() {403 404 @Override405 public void actionPerformed(ActionEvent event) {406 // sync part407 LoadPdfDialog.this.pdfFile = newFileName;408 if (pdfData != null) {409 Preview.set(newLayer, new FilePlacement());410 MainApplication.getMap().mapView.zoomTo(placement.getWorldBounds(pdfData));411 try {412 LoadPdfDialog.this.placement.load(newFileName);413 } catch (IOException e) {414 // Saved placement does not exist, corrupt, ... ---> ignore it415 } finally {416 LoadPdfDialog.this.placement.verify();417 }418 LoadPdfDialog.this.newLayer = null;419 LoadPdfDialog.this.loadFileButton.setEnabled(true);420 LoadPdfDialog.this.placementPanel.setEnabled(true);421 LoadPdfDialog.this.actionPanel.panel.setEnabled(true);422 LoadPdfDialog.this.actionPanel.showButton.setEnabled(true);423 LoadPdfDialog.this.actionPanel.saveButton.setEnabled(true);424 LoadPdfDialog.this.actionPanel.okButton.setEnabled(true);425 LoadPdfDialog.this.loadProgress.setVisible(false);426 }427 }428 });429 return true;430 }431 432 private void importAction() {433 434 if (!placement.isValid()) return;435 try {436 placement.save(pdfFile);437 } catch (IOException e) {438 e.toString();439 }440 removeLayer();441 442 runAsBackgroundTask(new Runnable() {443 @Override444 public void run() {445 // async part446 LoadPdfDialog.this.loadProgress.setVisible(true);447 SwingRenderingProgressMonitor monitor = new SwingRenderingProgressMonitor(progressRenderer);448 LoadPdfDialog.this.newLayer = LoadPdfDialog.this.makeLayer(tr("PDF: ") + pdfFile.getName(), placement,449 OsmBuilder.Mode.Final, monitor);450 progressRenderer.finish();451 }452 }, new ActionListener() {453 454 @Override455 public void actionPerformed(ActionEvent e) {456 // sync part457 // rebuild layer with latest projection458 MainApplication.getLayerManager().addLayer(newLayer);459 MainApplication.getMap().mapView.zoomTo(placement.getWorldBounds(pdfData));460 LoadPdfDialog.this.setVisible(false);461 }462 });463 }464 465 private void saveAction() {466 /*467 * perform save preview layer to file468 * TODO: is this action valueable? Can be easily performed from main menu469 */470 471 if (!placement.isValid()) return;472 473 final java.io.File file = this.chooseSaveFile();474 475 if (file == null) {476 return;477 }478 479 this.removeLayer();480 481 this.runAsBackgroundTask(new Runnable() {482 @Override483 public void run() {484 // async part485 SwingRenderingProgressMonitor monitor = new SwingRenderingProgressMonitor(progressRenderer);486 LoadPdfDialog.this.saveLayer(file, placement, monitor);487 progressRenderer.finish();488 }489 }, new ActionListener() {490 491 @Override492 public void actionPerformed(ActionEvent e) {493 // sync part494 LoadPdfDialog.this.setVisible(false);495 }496 });497 }498 499 private void showAction() {500 /*501 * perform show action502 * TODO: is this action valuable? User can do it easy from OSM Main Menu503 */504 if (!placement.isValid()) return;505 506 // zoom to new location507 MainApplication.getMap().mapView.zoomTo(placement.getWorldBounds(pdfData));508 MainApplication.getMap().repaint();509 }510 511 private void cancelAction() {512 /*513 * perform cancel action514 */515 removeLayer();516 setVisible(false);517 }518 519 // Implementation methods520 521 private static JFileChooser loadChooser = null;522 523 private java.io.File chooseFile() {524 // get PDF file to load525 if (loadChooser == null) {526 loadChooser = new JFileChooser(Preferences.getLoadDir());527 loadChooser.setAcceptAllFileFilterUsed(false);528 loadChooser.setMultiSelectionEnabled(false);529 loadChooser.setFileFilter(new FileFilter() {530 @Override531 public boolean accept(java.io.File pathname) {532 return pathname.isDirectory() || pathname.getName().endsWith(".pdf");533 }534 535 @Override536 public String getDescription() {537 return tr("PDF files");538 }539 });540 } else {541 loadChooser.rescanCurrentDirectory();542 }543 int result = loadChooser.showDialog(this, tr("Import PDF"));544 if (result != JFileChooser.APPROVE_OPTION) {545 return null;546 } else {547 Preferences.setLoadDir(loadChooser.getSelectedFile().getParentFile().getAbsolutePath());548 return loadChooser.getSelectedFile();549 }550 }551 552 private java.io.File chooseSaveFile() {553 // get file name554 JFileChooser fc = new JFileChooser();555 fc.setAcceptAllFileFilterUsed(true);556 fc.setMultiSelectionEnabled(false);557 fc.setFileFilter(new FileFilter() {558 @Override559 public boolean accept(java.io.File pathname) {560 return pathname.isDirectory() || pathname.getName().endsWith(".osm");561 }562 563 @Override564 public String getDescription() {565 return tr("OSM files");566 }567 });568 int result = fc.showOpenDialog(Main.parent);569 570 if (result != JFileChooser.APPROVE_OPTION) {571 return null;572 } else {573 return fc.getSelectedFile();574 }575 }576 577 private void runAsBackgroundTask(final Runnable task, final ActionListener after) {578 /*579 * run @task in background (asychronosly , run @after when @task has finished580 */581 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));582 Thread t = new Thread(new Runnable() {583 @Override584 public void run() {585 task.run();586 587 SwingUtilities.invokeLater(new Runnable() {588 @Override589 public void run() {590 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));591 after.actionPerformed(null);592 }593 });594 }595 });596 t.start();597 }598 599 private PathOptimizer loadPDF(File fileName, ProgressMonitor monitor) {600 /*601 * postprocess load PDF-file according to options602 */603 604 monitor.beginTask("", 100);605 monitor.setTicks(0);606 monitor.setCustomText(tr("Preparing"));607 608 double nodesTolerance = 0.0;609 Color color = null;610 int maxPaths = Integer.MAX_VALUE;611 612 if (configPanel.mergeCloseNodesCheck.getValue() && configPanel.mergeCloseNodesTolerance.isDataValid()) {613 nodesTolerance = configPanel.mergeCloseNodesTolerance.getValue();614 }615 616 if (configPanel.colorFilterCheck.getValue()) {617 try {618 String colString = this.configPanel.colorFilterColor.getText().replace("#", "");619 color = new Color(Integer.parseInt(colString, 16));620 } catch (Exception e) {621 JOptionPane.showMessageDialog(Main.parent, tr("Could not parse color"));622 return null;623 }624 }625 626 if (configPanel.limitPathCountCheck.getValue() && configPanel.limitPathCount.isDataValid()) {627 maxPaths = configPanel.limitPathCount.getValue();628 }629 630 monitor.setTicks(10);631 monitor.setCustomText(tr("Parsing file"));632 633 PathOptimizer data = new PathOptimizer(nodesTolerance, color, configPanel.splitOnColorChangeCheck.getValue());634 635 try {636 PdfBoxParser parser = new PdfBoxParser(data);637 parser.parse(fileName, maxPaths, monitor.createSubTaskMonitor(80, false));638 639 } catch (FileNotFoundException e1) {640 JOptionPane.showMessageDialog(Main.parent, tr("File not found."));641 return null;642 } catch (Exception e) {643 e.printStackTrace();644 JOptionPane.showMessageDialog(Main.parent, tr("Error while parsing: {0}", e.getMessage()));645 return null;646 }647 648 monitor.setTicks(80);649 650 if (configPanel.removeParallelSegmentsCheck.getValue() && configPanel.removeParallelSegmentsTolerance.isDataValid()) {651 double tolerance = configPanel.removeParallelSegmentsTolerance.getValue();652 monitor.setCustomText(tr("Removing parallel segments"));653 }654 655 if (nodesTolerance > 0.0) {656 monitor.setTicks(83);657 monitor.setCustomText(tr("Joining nodes"));658 data.mergeNodes();659 }660 661 monitor.setTicks(85);662 monitor.setCustomText(tr("Joining adjacent segments"));663 data.mergeSegments();664 665 if (configPanel.removeSmallObjectsCheck.getValue() && configPanel.removeSmallObjectsSize.isDataValid()) {666 double tolerance = configPanel.removeSmallObjectsSize.getValue();667 monitor.setTicks(90);668 monitor.setCustomText(tr("Removing small objects"));669 670 data.removeSmallObjects(tolerance);671 672 }673 674 if (configPanel.removeLargeObjectsCheck.getValue() && configPanel.removeLargeObjectsSize.isDataValid()) {675 double tolerance = configPanel.removeLargeObjectsSize.getValue();676 monitor.setTicks(90);677 monitor.setCustomText(tr("Removing large objects"));678 data.removeLargeObjects(tolerance);679 }680 681 monitor.setTicks(95);682 monitor.setCustomText(tr("Finalizing layers"));683 data.splitLayersByPathKind(configPanel.splitOnShapeClosedCheck.getValue(),684 configPanel.splitOnSingleSegmentCheck.getValue(),685 configPanel.splitOnOrthogonalCheck.getValue());686 data.finish();687 688 monitor.finishTask();689 return data;690 }691 692 private OsmDataLayer makeLayer(String name, FilePlacement placement, OsmBuilder.Mode mode,693 ProgressMonitor monitor) {694 /*695 * create a layer from data696 */697 monitor.beginTask(tr("Building JOSM layer"), 100);698 OsmBuilder builder = new OsmBuilder(placement);699 DataSet data = builder.build(pdfData.getLayers(), mode, monitor.createSubTaskMonitor(50, false));700 data.setUploadPolicy(UploadPolicy.BLOCKED);701 monitor.setTicks(50);702 monitor.setCustomText(tr("Postprocessing layer"));703 OsmDataLayer result = new OsmDataLayer(data, name, null);704 result.setUploadDiscouraged(true);705 result.setBackgroundLayer(true);706 result.onPostLoadFromFile();707 708 monitor.finishTask();709 return result;710 }711 712 private void removeLayer() {713 /*714 * remove preview layer715 */716 // if (dataLayer != null) {717 // MainApplication.getLayerManager().removeLayer(dataLayer);718 // dataLayer.data.clear(); // saves memory719 // dataLayer = null;720 // }721 Preview.clear();722 // No layer ==> no actions723 actionPanel.showButton.setEnabled(false);724 actionPanel.saveButton.setEnabled(false);725 actionPanel.okButton.setEnabled(false);726 placementPanel.setEnabled(false);727 728 }729 730 private void saveLayer(java.io.File file, FilePlacement placement, ProgressMonitor monitor) {731 /*732 * save layer to file733 * TODO: is this methode valuable? Functionality can easily performed from Main-Menu734 */735 monitor.beginTask(tr("Saving to file."), 1000);736 737 OsmBuilder builder = new OsmBuilder(placement);738 DataSet data = builder.build(this.pdfData.getLayers(), OsmBuilder.Mode.Final,739 monitor.createSubTaskMonitor(500, false));740 OsmDataLayer layer = new OsmDataLayer(data, file.getName(), file);741 742 monitor.setCustomText(tr(" Writing to file"));743 monitor.setTicks(500);744 745 OsmExporter exporter = new OsmExporter();746 747 try {748 exporter.exportData(file, layer);749 } catch (IOException e) {750 Logging.error(e);751 }752 753 monitor.finishTask();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 * TODO: make dialog reusable37 */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 publicPdfImportPlugin(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 @Override35 publicvoid 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 public enum GuiMode {11 Auto, Expert, Simple12 };10 public enum GuiMode { 11 Auto, Expert, Simple 12 }; 13 13 14 public static String getLoadDir() {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 public static void setLoadDir(String loadDir) {19 Config.getPref().put(Preferences.prefix + "loadDir", loadDir);20 }18 public static void setLoadDir(String loadDir) { 19 Config.getPref().put(Preferences.prefix + "loadDir", loadDir); 20 } 21 21 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 else34 return GuiMode.Simple;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 public static boolean isLegacyActions() {39 return (Config.getPref().getInt(Preferences.prefix + "guiCode", 0) == -1);40 }38 public static boolean isLegacyActions() { 39 return (Config.getPref().getInt(Preferences.prefix + "guiCode", 0) == -1); 40 } 41 41 42 public static boolean isMergeNodes() {43 return Config.getPref().getBoolean(Preferences.prefix + "mergeNodes");44 }42 public static boolean isMergeNodes() { 43 return Config.getPref().getBoolean(Preferences.prefix + "mergeNodes"); 44 } 45 45 46 public static double getMergeNodesValue() {47 return Config.getPref().getDouble(Preferences.prefix + "mergeNodes.value", 1e-3);48 }46 public static double getMergeNodesValue() { 47 return Config.getPref().getDouble(Preferences.prefix + "mergeNodes.value", 1e-3); 48 } 49 49 50 public static boolean isRemoveSmall() {51 return Config.getPref().getBoolean(Preferences.prefix + "removeSmall");52 }50 public static boolean isRemoveSmall() { 51 return Config.getPref().getBoolean(Preferences.prefix + "removeSmall"); 52 } 53 53 54 public static double getRemoveSmallValue() {55 return Config.getPref().getDouble(Preferences.prefix + "removeSmall.value", 1);56 }54 public static double getRemoveSmallValue() { 55 return Config.getPref().getDouble(Preferences.prefix + "removeSmall.value", 1); 56 } 57 57 58 public static boolean isRemoveLarge() {59 return Config.getPref().getBoolean(Preferences.prefix + "removeLarge");60 }58 public static boolean isRemoveLarge() { 59 return Config.getPref().getBoolean(Preferences.prefix + "removeLarge"); 60 } 61 61 62 public static double getRemoveLargeValue() {63 return Config.getPref().getDouble(Preferences.prefix + "removeLarge.value", 10);64 }62 public static double getRemoveLargeValue() { 63 return Config.getPref().getDouble(Preferences.prefix + "removeLarge.value", 10); 64 } 65 65 66 public static boolean isRemoveParallel() {67 return Config.getPref().getBoolean(Preferences.prefix + "removeParallel");68 }66 public static boolean isRemoveParallel() { 67 return Config.getPref().getBoolean(Preferences.prefix + "removeParallel"); 68 } 69 69 70 public static double getRemoveParallelValue() {71 return Config.getPref().getDouble(Preferences.prefix + "removeParallel.value", 3);72 }70 public static double getRemoveParallelValue() { 71 return Config.getPref().getDouble(Preferences.prefix + "removeParallel.value", 3); 72 } 73 73 74 public static boolean isLimitPath() {75 return Config.getPref().getBoolean(Preferences.prefix + "limitPath");76 }74 public static boolean isLimitPath() { 75 return Config.getPref().getBoolean(Preferences.prefix + "limitPath"); 76 } 77 77 78 public static int getLimitPathValue() {79 return Config.getPref().getInt(Preferences.prefix + "limitPath.value", Integer.MAX_VALUE);80 }78 public static int getLimitPathValue() { 79 return Config.getPref().getInt(Preferences.prefix + "limitPath.value", Integer.MAX_VALUE); 80 } 81 81 82 public static boolean isLimitColor() {83 return Config.getPref().getBoolean(Preferences.prefix + "limitColor");84 }82 public static boolean isLimitColor() { 83 return Config.getPref().getBoolean(Preferences.prefix + "limitColor"); 84 } 85 85 86 public static String getLimitColorValue() {87 return Config.getPref().get(Preferences.prefix + "limitColor.value","#000000");88 }86 public static String getLimitColorValue() { 87 return Config.getPref().get(Preferences.prefix + "limitColor.value","#000000"); 88 } 89 89 90 public static boolean isDebugTags() {91 return Config.getPref().getBoolean(Preferences.prefix + "debugTags");92 }90 public static boolean isDebugTags() { 91 return Config.getPref().getBoolean(Preferences.prefix + "debugTags"); 92 } 93 93 94 public static boolean isLayerClosed() {95 return Config.getPref().getBoolean(Preferences.prefix + "layerClosed");96 }94 public static boolean isLayerClosed() { 95 return Config.getPref().getBoolean(Preferences.prefix + "layerClosed"); 96 } 97 97 98 public static boolean isLayerSegment() {99 return Config.getPref().getBoolean(Preferences.prefix + "layerSegment");100 }98 public static boolean isLayerSegment() { 99 return Config.getPref().getBoolean(Preferences.prefix + "layerSegment"); 100 } 101 101 102 public static boolean isLayerAttribChange() {103 return Config.getPref().getBoolean(Preferences.prefix + "layerAttribChanges");104 }102 public static boolean isLayerAttribChange() { 103 return Config.getPref().getBoolean(Preferences.prefix + "layerAttribChanges"); 104 } 105 105 106 public static boolean isLayerOrtho() {107 return Config.getPref().getBoolean(Preferences.prefix + "layerOrtho");108 }106 public static boolean isLayerOrtho() { 107 return Config.getPref().getBoolean(Preferences.prefix + "layerOrtho"); 108 } 109 109 110 protected static int GuiCode;110 protected static int GuiCode; 111 111 112 private static String prefix;112 private static String prefix; 113 113 114 private Preferences() {115 return;116 }114 private Preferences() { 115 return; 116 } 117 117 118 public Preferences (String p) {119 prefix = p + "." ;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 public static OsmDataLayer dataLayer;19 public static FilePlacement placement;20 21 public static synchronized void set (@NotNull OsmDataLayer dataLayer, @NotNull FilePlacement placement) {22 clear();23 Preview.dataLayer = dataLayer;24 Preview.placement = placement;25 MainApplication.getLayerManager().addLayer(dataLayer);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 public static void clear() {30 if (Preview.dataLayer != null) {31 MainApplication.getLayerManager().removeLayer(Preview.dataLayer);32 Preview.dataLayer.data.clear(); // saves memory33 }34 Preview.dataLayer = null;35 Preview.placement = null;36 }37 38 public void save() {39 // TODO: implement40 }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 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 }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 * process : re : append rectangle to path.42 * @param operator The operator that is being executed.43 * @param arguments List44 */45 @Override46 public void process(PDFOperator operator, List<COSBase> arguments)47 {48 PageDrawer drawer = (PageDrawer)context;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 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 );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 double x1 = x.doubleValue();56 double y1 = y.doubleValue();57 // create a pair of coordinates for the transformation58 double x2 = w.doubleValue()+x1;59 double y2 = h.doubleValue()+y1;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 Point2D startCoords = drawer.transformedPoint(x1,y1);62 Point2D endCoords = drawer.transformedPoint(x2,y2);61 Point2D startCoords = drawer.transformedPoint(x1,y1); 62 Point2D endCoords = drawer.transformedPoint(x2,y2); 63 63 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();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 // To ensure that the path is created in the right direction,70 // we have to create it by combining single lines instead of71 // creating a simple rectangle72 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 }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 * process : BI : begin inline image.39 * @param operator The operator that is being executed.40 * @param arguments List41 * @throws IOException If there is an error displaying the inline image.42 */43 @Override44 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException45 {46 PageDrawer drawer = (PageDrawer)context;47 drawer.drawImage();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 * Log instance.42 */43 private static final Log log = LogFactory.getLog(ClipEvenOddRule.class);40 /** 41 * Log instance. 42 */ 43 private static final Log log = LogFactory.getLog(ClipEvenOddRule.class); 44 44 45 /**46 * process : W* : set clipping path using even odd rule.47 * @param operator The operator that is being executed.48 * @param arguments List49 *50 * @throws IOException if there is an error during execution.51 */52 @Override53 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException54 {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 try57 {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 }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 * Log instance.42 */43 private static final Log log = LogFactory.getLog(ClipNonZeroRule.class);40 /** 41 * Log instance. 42 */ 43 private static final Log log = LogFactory.getLog(ClipNonZeroRule.class); 44 44 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 List49 *50 * @throws IOException If there is an error during the processing.51 */52 @Override53 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException54 {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 try57 {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 }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 * fill and stroke the path.40 * @param operator The operator that is being executed.41 * @param arguments List42 *43 * @throws IOException If an error occurs while processing the font.44 */45 @Override46 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException47 {48 PageDrawer drawer = (PageDrawer)context;49 drawer.getLinePath().closePath();50 drawer.drawPath(true, true, Path2D.WIND_EVEN_ODD);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 * fill and stroke the path.40 * @param operator The operator that is being executed.41 * @param arguments List42 *43 * @throws IOException If an error occurs while processing the font.44 */45 @Override46 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException47 {48 PageDrawer drawer = (PageDrawer)context;49 drawer.getLinePath().closePath();50 drawer.drawPath(true, true, Path2D.WIND_NON_ZERO);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 * process : h : Close path.38 * @param operator The operator that is being executed.39 * @param arguments List40 *41 * @throws IOException if something went wrong during logging42 */43 @Override44 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException45 {46 PageDrawer drawer = (PageDrawer)context;47 drawer.getLinePath().closePath();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 * process : c : Append curved segment to path.41 * @param operator The operator that is being executed.42 * @param arguments List43 */44 @Override45 public void process(PDFOperator operator, List<COSBase> arguments)46 {47 PageDrawer drawer = (PageDrawer)context;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 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 );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 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());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 drawer.getLinePath().curveTo((float)point1.getX(), (float)point1.getY(),61 (float)point2.getX(), (float)point2.getY(), (float)point3.getX(), (float)point3.getY());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 * process : y : Append curved segment to path (final point replicated).41 * @param operator The operator that is being executed.42 * @param arguments List43 */44 @Override45 public void process(PDFOperator operator, List<COSBase> arguments)46 {47 PageDrawer drawer = (PageDrawer)context;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 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 );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 Point2D point1 = drawer.transformedPoint(x1.doubleValue(), y1.doubleValue());55 Point2D point3 = drawer.transformedPoint(x3.doubleValue(), y3.doubleValue());54 Point2D point1 = drawer.transformedPoint(x1.doubleValue(), y1.doubleValue()); 55 Point2D point3 = drawer.transformedPoint(x3.doubleValue(), y3.doubleValue()); 56 56 57 drawer.getLinePath().curveTo((float)point1.getX(), (float)point1.getY(),58 (float)point3.getX(), (float)point3.getY(), (float)point3.getX(), (float)point3.getY());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 * process : v : Append curved segment to path (initial point replicated).42 * @param operator The operator that is being executed.43 * @param arguments List44 */45 @Override46 public void process(PDFOperator operator, List<COSBase> arguments)47 {48 PageDrawer drawer = (PageDrawer)context;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 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();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 Point2D point2 = drawer.transformedPoint(x2.doubleValue(), y2.doubleValue());58 Point2D point3 = drawer.transformedPoint(x3.doubleValue(), y3.doubleValue());57 Point2D point2 = drawer.transformedPoint(x2.doubleValue(), y2.doubleValue()); 58 Point2D point3 = drawer.transformedPoint(x3.doubleValue(), y3.doubleValue()); 59 59 60 drawer.getLinePath().curveTo((float)currentPoint.getX(), (float)currentPoint.getY(),61 (float)point2.getX(), (float)point2.getY(), (float)point3.getX(), (float)point3.getY());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 * process : n : End path.39 * @param operator The operator that is being executed.40 * @param arguments List41 */42 @Override43 public void process(PDFOperator operator, List<COSBase> arguments)44 {45 PageDrawer drawer = (PageDrawer)context;46 drawer.getLinePath().reset();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 * fill and stroke the path.40 * @param operator The operator that is being executed.41 * @param arguments List42 *43 * @throws IOException If an error occurs while processing the font.44 */45 @Override46 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException47 {48 PageDrawer drawer = (PageDrawer)context;49 drawer.drawPath(true, true, Path2D.WIND_EVEN_ODD);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 * Log instance.42 */43 private static final Log log = LogFactory.getLog(FillEvenOddRule.class);40 /** 41 * Log instance. 42 */ 43 private static final Log log = LogFactory.getLog(FillEvenOddRule.class); 44 44 45 /**46 * process : f* : fill path using even odd rule.47 * @param operator The operator that is being executed.48 * @param arguments List49 *50 * @throws IOException if there is an error during execution.51 */52 @Override53 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException54 {55 try56 {57 ///dwilson refactoring58 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 }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 * fill and stroke the path.40 * @param operator The operator that is being executed.41 * @param arguments List42 *43 * @throws IOException If an error occurs while processing the font.44 */45 @Override46 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException47 {48 PageDrawer drawer = (PageDrawer)context;49 drawer.drawPath(true, true, Path2D.WIND_NON_ZERO);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 * process : F/f : fill path using non zero winding rule.40 * @param operator The operator that is being executed.41 * @param arguments List42 *43 * @throws IOException If there is an error during the processing.44 */45 @Override46 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException47 {48 PageDrawer drawer = (PageDrawer)context;49 drawer.drawPath(false, true, GeneralPath.WIND_NON_ZERO);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 * process : Do : Paint the specified XObject (section 4.7).49 * @param operator The operator that is being executed.50 * @param arguments List51 * @throws IOException If there is an error invoking the sub object.52 */53 @Override54 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException55 {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 to75 // map the form space to the user space76 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 else85 {86 //unknown xobject type87 }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 //invoke named object.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 * process : l : Append straight line segment to path.41 * @param operator The operator that is being executed.42 * @param arguments List43 */44 @Override45 public void process(PDFOperator operator, List<COSBase> arguments)46 {47 PageDrawer drawer = (PageDrawer)context;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 //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 );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 Point2D pos = drawer.transformedPoint(x.doubleValue(), y.doubleValue());54 drawer.getLinePath().lineTo((float)pos.getX(), (float)pos.getY());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 * Log instance.43 */44 private static final Log log = LogFactory.getLog(MoveTo.class);41 /** 42 * Log instance. 43 */ 44 private static final Log log = LogFactory.getLog(MoveTo.class); 45 45 46 /**47 * process : m : Begin new subpath.48 * @param operator The operator that is being executed.49 * @param arguments List50 * @throws IOException If there is an error processing the operator.51 */52 @Override53 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException54 {55 try56 {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 }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 * process : sh : shade fill the path or clipping area.41 * @param operator The operator that is being executed.42 * @param arguments List43 *44 * @throws IOException if there is an error during execution.45 */46 @Override47 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException48 {49 PageDrawer drawer = (PageDrawer)context;50 drawer.drawPath(false, true, Path2D.WIND_NON_ZERO);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 * Set the line cap style.39 * @param operator The operator that is being executed.40 * @param arguments List41 *42 * @throws IOException If an error occurs while processing the font.43 */44 @Override45 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException46 {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 else56 {57 drawer.setStroke( new BasicStroke(stroke.getLineWidth(), lineCapStyle, stroke.getLineJoin(),58 stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase()));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 * Set the line dash pattern.40 * @param operator The operator that is being executed.41 * @param arguments List42 *43 * @throws IOException If an error occurs while processing the font.44 */45 @Override46 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException47 {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 else59 {60 drawer.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f,61 lineDashPattern.getCOSDashPattern().toFloatArray(), lineDashPattern.getPhaseStart()) );62 }63 }64 else65 {66 if (lineDashPattern.isDashPatternEmpty())67 {68 drawer.setStroke( new BasicStroke(stroke.getLineWidth(), stroke.getEndCap(),69 stroke.getLineJoin(), stroke.getMiterLimit()) );70 }71 else72 {73 drawer.setStroke( new BasicStroke(stroke.getLineWidth(), stroke.getEndCap(), stroke.getLineJoin(),74 stroke.getMiterLimit(), lineDashPattern.getCOSDashPattern().toFloatArray(),75 lineDashPattern.getPhaseStart()) );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 * Set the line cap style.39 * @param operator The operator that is being executed.40 * @param arguments List41 *42 * @throws IOException If an error occurs while processing the font.43 */44 @Override45 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException46 {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 else56 {57 drawer.setStroke( new BasicStroke(stroke.getLineWidth(), stroke.getEndCap(), lineJoinStyle,58 stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase()) );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 * Set the line dash pattern.39 * @param operator The operator that is being executed.40 * @param arguments List41 *42 * @throws IOException If an error occurs while processing the font.43 */44 @Override45 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException46 {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 else57 {58 drawer.setStroke( new BasicStroke(stroke.getLineWidth(), stroke.getEndCap(), stroke.getLineJoin(),59 miterLimit, null, 0.0f));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 * w Set line width.39 * @param operator The operator that is being executed.40 * @param arguments List41 * @throws IOException If an error occurs while processing the font.42 */43 @Override44 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException45 {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 else59 {60 drawer.setStroke( new BasicStroke(lineWidth, stroke.getEndCap(), stroke.getLineJoin(),61 stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase()) );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 * S stroke the path.39 * @param operator The operator that is being executed.40 * @param arguments List41 *42 * @throws IOException If an error occurs while processing the font.43 */44 @Override45 public void process(PDFOperator operator, List<COSBase> arguments) throws IOException46 {47 PageDrawer drawer = (PageDrawer)context;48 drawer.drawPath(true, false, 0);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.
