### Eclipse Workspace Patch 1.0
#P josm
diff --git src/org/openstreetmap/josm/gui/preferences/imagery/ImageryProvidersPanel.java src/org/openstreetmap/josm/gui/preferences/imagery/ImageryProvidersPanel.java
index 3ed985e..da1c09d 100644
|
|
|
|
| 15 | 15 | import java.awt.event.MouseEvent; |
| 16 | 16 | import java.io.IOException; |
| 17 | 17 | import java.net.MalformedURLException; |
| | 18 | import java.net.URI; |
| 18 | 19 | import java.net.URL; |
| 19 | 20 | import java.util.ArrayList; |
| 20 | 21 | import java.util.HashMap; |
| … |
… |
|
| 126 | 127 | @Override |
| 127 | 128 | public Component getTableCellRendererComponent(JTable table, Object value, boolean |
| 128 | 129 | isSelected, boolean hasFocus, int row, int column) { |
| 129 | | JLabel label = (JLabel) super.getTableCellRendererComponent( |
| | 130 | final JLabel label = (JLabel) super.getTableCellRendererComponent( |
| 130 | 131 | table, value, isSelected, hasFocus, row, column); |
| 131 | 132 | GuiHelper.setBackgroundReadable(label, UIManager.getColor("Table.background")); |
| 132 | 133 | if (value != null) { // Fix #8159 |
| … |
… |
|
| 158 | 159 | @SuppressWarnings("unchecked") |
| 159 | 160 | public final Component getTableCellRendererComponent(JTable table, Object value, boolean |
| 160 | 161 | isSelected, boolean hasFocus, int row, int column) { |
| 161 | | T obj = (T) value; |
| 162 | | JLabel label = (JLabel) super.getTableCellRendererComponent( |
| | 162 | final T obj = (T) value; |
| | 163 | final JLabel label = (JLabel) super.getTableCellRendererComponent( |
| 163 | 164 | table, mapper.apply(obj), isSelected, hasFocus, row, column); |
| 164 | 165 | GuiHelper.setBackgroundReadable(label, |
| 165 | 166 | isSelected ? UIManager.getColor("Table.selectionBackground") : UIManager.getColor("Table.background")); |
| … |
… |
|
| 215 | 216 | activeTable = new JTable(activeModel) { |
| 216 | 217 | @Override |
| 217 | 218 | public String getToolTipText(MouseEvent e) { |
| 218 | | java.awt.Point p = e.getPoint(); |
| | 219 | final java.awt.Point p = e.getPoint(); |
| 219 | 220 | try { |
| 220 | 221 | return activeModel.getValueAt(rowAtPoint(p), columnAtPoint(p)).toString(); |
| 221 | 222 | } catch (ArrayIndexOutOfBoundsException ex) { |
| … |
… |
|
| 251 | 252 | mod.getColumn(1).setCellRenderer(new ImageryURLTableCellRenderer(layerInfo.getAllDefaultLayers())); |
| 252 | 253 | mod.getColumn(0).setPreferredWidth(200); |
| 253 | 254 | |
| 254 | | RemoveEntryAction remove = new RemoveEntryAction(); |
| | 255 | final RemoveEntryAction remove = new RemoveEntryAction(); |
| 255 | 256 | activeTable.getSelectionModel().addListSelectionListener(remove); |
| 256 | 257 | |
| 257 | 258 | add(new JLabel(tr("Available default entries:")), GBC.std().insets(5, 5, 0, 0)); |
| 258 | 259 | add(new JLabel(tr("Boundaries of selected imagery entries:")), GBC.eol().insets(5, 5, 0, 0)); |
| 259 | 260 | |
| 260 | 261 | // Add default item list |
| 261 | | JPanel defaultPane = new JPanel(new GridBagLayout()); |
| 262 | | JScrollPane scrolldef = new JScrollPane(defaultTable); |
| | 262 | final JPanel defaultPane = new JPanel(new GridBagLayout()); |
| | 263 | final JScrollPane scrolldef = new JScrollPane(defaultTable); |
| 263 | 264 | defaultPane.add(defaultFilter, GBC.eol().insets(0, 0, 0, 0).fill(GridBagConstraints.HORIZONTAL)); |
| 264 | 265 | defaultPane.add(scrolldef, GBC.eol().insets(0, 0, 0, 0).fill(GridBagConstraints.BOTH)); |
| 265 | 266 | add(defaultPane, GBC.std().fill(GridBagConstraints.BOTH).weight(1.0, 0.6).insets(5, 0, 0, 0)); |
| … |
… |
|
| 282 | 283 | defaultTableListener = new DefListSelectionListener(); |
| 283 | 284 | defaultTable.getSelectionModel().addListSelectionListener(defaultTableListener); |
| 284 | 285 | |
| 285 | | HtmlPanel help = new HtmlPanel(tr("New default entries can be added in the <a href=\"{0}\">Wiki</a>.", |
| | 286 | final HtmlPanel help = new HtmlPanel(tr("New default entries can be added in the <a href=\"{0}\">Wiki</a>.", |
| 286 | 287 | Config.getUrls().getJOSMWebsite()+"/wiki/Maps")); |
| 287 | 288 | help.enableClickableHyperlinks(); |
| 288 | 289 | add(help, GBC.eol().insets(5, 0, 0, 0).fill(GBC.HORIZONTAL)); |
| 289 | 290 | |
| 290 | | ActivateAction activate = new ActivateAction(); |
| | 291 | final ActivateAction activate = new ActivateAction(); |
| 291 | 292 | defaultTable.getSelectionModel().addListSelectionListener(activate); |
| 292 | | JButton btnActivate = new JButton(activate); |
| | 293 | final JButton btnActivate = new JButton(activate); |
| 293 | 294 | |
| 294 | 295 | middleToolbar = new JToolBar(JToolBar.HORIZONTAL); |
| 295 | 296 | middleToolbar.setFloatable(false); |
| … |
… |
|
| 301 | 302 | |
| 302 | 303 | add(Box.createHorizontalGlue(), GBC.eol().fill(GridBagConstraints.HORIZONTAL)); |
| 303 | 304 | |
| 304 | | JPanel activePanel = new JPanel(new BorderLayout()); |
| | 305 | final JPanel activePanel = new JPanel(new BorderLayout()); |
| 305 | 306 | activePanel.add(new JLabel(tr("Selected entries:")), BorderLayout.NORTH); |
| 306 | | JScrollPane scroll = new JScrollPane(activeTable); |
| | 307 | final JScrollPane scroll = new JScrollPane(activeTable); |
| 307 | 308 | activePanel.add(scroll, BorderLayout.CENTER); |
| 308 | 309 | |
| 309 | 310 | activeToolbar = new JToolBar(JToolBar.VERTICAL); |
| … |
… |
|
| 364 | 365 | * @param i model index |
| 365 | 366 | */ |
| 366 | 367 | private void updateBoundsAndShapes(int i) { |
| 367 | | ImageryBounds bounds = defaultModel.getRow(i).getBounds(); |
| | 368 | final ImageryBounds bounds = defaultModel.getRow(i).getBounds(); |
| 368 | 369 | if (bounds != null) { |
| 369 | | int viewIndex = defaultTable.convertRowIndexToView(i); |
| 370 | | List<Shape> shapes = bounds.getShapes(); |
| | 370 | final int viewIndex = defaultTable.convertRowIndexToView(i); |
| | 371 | final List<Shape> shapes = bounds.getShapes(); |
| 371 | 372 | if (!Utils.isEmpty(shapes)) { |
| 372 | 373 | if (defaultTable.getSelectionModel().isSelectedIndex(viewIndex)) { |
| 373 | 374 | if (!mapPolygons.containsKey(i)) { |
| 374 | | List<MapPolygon> list = new ArrayList<>(); |
| | 375 | final List<MapPolygon> list = new ArrayList<>(); |
| 375 | 376 | mapPolygons.put(i, list); |
| 376 | 377 | // Add new map polygons |
| 377 | 378 | for (Shape shape : shapes) { |
| 378 | | MapPolygon polygon = new MapPolygonImpl(shape.getPoints()); |
| | 379 | final MapPolygon polygon = new MapPolygonImpl(shape.getPoints()); |
| 379 | 380 | list.add(polygon); |
| 380 | 381 | defaultMap.addMapPolygon(polygon); |
| 381 | 382 | } |
| … |
… |
|
| 392 | 393 | if (defaultTable.getSelectionModel().isSelectedIndex(viewIndex)) { |
| 393 | 394 | if (!mapRectangles.containsKey(i)) { |
| 394 | 395 | // Add new map rectangle |
| 395 | | Coordinate topLeft = new Coordinate(bounds.getMaxLat(), bounds.getMinLon()); |
| 396 | | Coordinate bottomRight = new Coordinate(bounds.getMinLat(), bounds.getMaxLon()); |
| 397 | | MapRectangle rectangle = new MapRectangleImpl(topLeft, bottomRight); |
| | 396 | final Coordinate topLeft = new Coordinate(bounds.getMaxLat(), bounds.getMinLon()); |
| | 397 | final Coordinate bottomRight = new Coordinate(bounds.getMinLat(), bounds.getMaxLon()); |
| | 398 | final MapRectangle rectangle = new MapRectangleImpl(topLeft, bottomRight); |
| 398 | 399 | mapRectangles.put(i, rectangle); |
| 399 | 400 | defaultMap.addMapRectangle(rectangle); |
| 400 | 401 | } |
| … |
… |
|
| 409 | 410 | |
| 410 | 411 | private <T> void doCleanupResidualBounds(Map<Integer, T> map, Consumer<T> removalEffect) { |
| 411 | 412 | for (Iterator<Entry<Integer, T>> it = map.entrySet().iterator(); it.hasNext();) { |
| 412 | | Entry<Integer, T> e = it.next(); |
| 413 | | int viewIndex = defaultTable.convertRowIndexToView(e.getKey()); |
| | 413 | final Entry<Integer, T> e = it.next(); |
| | 414 | final int viewIndex = defaultTable.convertRowIndexToView(e.getKey()); |
| 414 | 415 | if (!defaultTable.getSelectionModel().isSelectedIndex(viewIndex)) { |
| 415 | 416 | it.remove(); |
| 416 | 417 | removalEffect.accept(e.getValue()); |
| … |
… |
|
| 479 | 480 | try { |
| 480 | 481 | activeModel.addRow(p.getImageryInfo()); |
| 481 | 482 | } catch (IllegalArgumentException ex) { |
| 482 | | if (Utils.isEmpty(ex.getMessage())) |
| 483 | | throw ex; |
| 484 | | else { |
| | 483 | if (Utils.isEmpty(ex.getMessage())) { |
| | 484 | throw ex; |
| | 485 | } else { |
| 485 | 486 | JOptionPane.showMessageDialog(MainApplication.getMainFrame(), |
| 486 | 487 | ex.getMessage(), tr("Error"), |
| 487 | 488 | JOptionPane.ERROR_MESSAGE); |
| … |
… |
|
| 543 | 544 | |
| 544 | 545 | @Override |
| 545 | 546 | public void actionPerformed(ActionEvent e) { |
| 546 | | int[] lines = defaultTable.getSelectedRows(); |
| | 547 | final int[] lines = defaultTable.getSelectedRows(); |
| 547 | 548 | if (lines.length == 0) { |
| 548 | 549 | JOptionPane.showMessageDialog( |
| 549 | 550 | gui, |
| … |
… |
|
| 553 | 554 | return; |
| 554 | 555 | } |
| 555 | 556 | |
| 556 | | Set<String> acceptedEulas = new HashSet<>(); |
| | 557 | final Set<String> acceptedEulas = new HashSet<>(); |
| 557 | 558 | |
| 558 | | outer: |
| 559 | 559 | for (int line : lines) { |
| 560 | | ImageryInfo info = defaultModel.getRow(defaultTable.convertRowIndexToModel(line)); |
| | 560 | final ImageryInfo info = defaultModel.getRow(defaultTable.convertRowIndexToModel(line)); |
| 561 | 561 | |
| 562 | 562 | // Check if an entry with exactly the same values already exists |
| | 563 | boolean alreadyExists = false; |
| 563 | 564 | for (int j = 0; j < activeModel.getRowCount(); j++) { |
| 564 | 565 | if (info.equalsBaseValues(activeModel.getRow(j))) { |
| 565 | 566 | // Select the already existing row so the user has |
| 566 | 567 | // some feedback in case an entry exists |
| 567 | 568 | activeTable.getSelectionModel().setSelectionInterval(j, j); |
| 568 | 569 | activeTable.scrollRectToVisible(activeTable.getCellRect(j, 0, true)); |
| 569 | | continue outer; |
| | 570 | alreadyExists = true; |
| | 571 | break; |
| 570 | 572 | } |
| 571 | 573 | } |
| | 574 | |
| | 575 | if (alreadyExists) { |
| | 576 | continue; |
| | 577 | } |
| 572 | 578 | |
| 573 | | String eulaURL = info.getEulaAcceptanceRequired(); |
| | 579 | final String eulaURL = info.getEulaAcceptanceRequired(); |
| 574 | 580 | // If set and not already accepted, ask for EULA acceptance |
| 575 | 581 | if (eulaURL != null && !acceptedEulas.contains(eulaURL)) { |
| 576 | 582 | if (confirmEulaAcceptance(gui, eulaURL)) { |
| 577 | 583 | acceptedEulas.add(eulaURL); |
| 578 | 584 | } else { |
| 579 | | continue outer; |
| | 585 | continue; |
| 580 | 586 | } |
| 581 | 587 | } |
| 582 | 588 | |
| 583 | 589 | activeModel.addRow(new ImageryInfo(info)); |
| 584 | | int lastLine = activeModel.getRowCount() - 1; |
| | 590 | final int lastLine = activeModel.getRowCount() - 1; |
| 585 | 591 | activeTable.getSelectionModel().setSelectionInterval(lastLine, lastLine); |
| 586 | 592 | activeTable.scrollRectToVisible(activeTable.getCellRect(lastLine, 0, true)); |
| 587 | 593 | } |
| … |
… |
|
| 641 | 647 | */ |
| 642 | 648 | public void addRow(ImageryInfo i) { |
| 643 | 649 | layerInfo.add(i); |
| 644 | | int p = getRowCount() - 1; |
| | 650 | final int p = getRowCount() - 1; |
| 645 | 651 | fireTableRowsInserted(p, p); |
| 646 | 652 | } |
| 647 | 653 | |
| … |
… |
|
| 658 | 664 | |
| 659 | 665 | @Override |
| 660 | 666 | public Object getValueAt(int row, int column) { |
| 661 | | ImageryInfo info = layerInfo.getLayers().get(row); |
| | 667 | final ImageryInfo info = layerInfo.getLayers().get(row); |
| 662 | 668 | switch (column) { |
| 663 | 669 | case 0: |
| 664 | 670 | return info.getName(); |
| … |
… |
|
| 671 | 677 | |
| 672 | 678 | @Override |
| 673 | 679 | public void setValueAt(Object o, int row, int column) { |
| 674 | | if (layerInfo.getLayers().size() <= row) return; |
| 675 | | ImageryInfo info = layerInfo.getLayers().get(row); |
| | 680 | if (layerInfo.getLayers().size() <= row) { |
| | 681 | return; |
| | 682 | } |
| | 683 | final ImageryInfo info = layerInfo.getLayers().get(row); |
| 676 | 684 | switch (column) { |
| 677 | 685 | case 0: |
| 678 | 686 | info.setName((String) o); |
| … |
… |
|
| 731 | 739 | |
| 732 | 740 | @Override |
| 733 | 741 | public Object getValueAt(int row, int column) { |
| 734 | | ImageryInfo info = layerInfo.getAllDefaultLayers().get(row); |
| | 742 | final ImageryInfo info = layerInfo.getAllDefaultLayers().get(row); |
| 735 | 743 | switch (column) { |
| 736 | 744 | case 0: |
| 737 | 745 | return Optional.ofNullable(info.getImageryCategory()).orElse(ImageryCategory.OTHER); |
| … |
… |
|
| 755 | 763 | private static boolean confirmEulaAcceptance(PreferenceTabbedPane gui, String eulaUrl) { |
| 756 | 764 | URL url; |
| 757 | 765 | try { |
| 758 | | url = new URL(eulaUrl.replaceAll("\\{lang}", LanguageInfo.getWikiLanguagePrefix())); |
| | 766 | url = URI.create(eulaUrl.replaceAll("\\{lang}", LanguageInfo.getWikiLanguagePrefix())).toURL(); |
| 759 | 767 | JosmEditorPane htmlPane; |
| 760 | 768 | try { |
| 761 | 769 | htmlPane = new JosmEditorPane(url); |
| … |
… |
|
| 763 | 771 | Logging.trace(e1); |
| 764 | 772 | // give a second chance with a default Locale 'en' |
| 765 | 773 | try { |
| 766 | | url = new URL(eulaUrl.replaceAll("\\{lang}", "")); |
| | 774 | url = URI.create(eulaUrl.replaceAll("\\{lang}", "")).toURL(); |
| 767 | 775 | htmlPane = new JosmEditorPane(url); |
| 768 | 776 | } catch (IOException e2) { |
| 769 | 777 | Logging.debug(e2); |
| … |
… |
|
| 771 | 779 | return false; |
| 772 | 780 | } |
| 773 | 781 | } |
| 774 | | Box box = Box.createVerticalBox(); |
| | 782 | final Box box = Box.createVerticalBox(); |
| 775 | 783 | htmlPane.setEditable(false); |
| 776 | | JScrollPane scrollPane = new JScrollPane(htmlPane); |
| | 784 | final JScrollPane scrollPane = new JScrollPane(htmlPane); |
| 777 | 785 | scrollPane.setPreferredSize(new Dimension(400, 400)); |
| 778 | 786 | box.add(scrollPane); |
| 779 | | int option = JOptionPane.showConfirmDialog(MainApplication.getMainFrame(), box, tr("Please abort if you are not sure"), |
| | 787 | final int option = JOptionPane.showConfirmDialog(MainApplication.getMainFrame(), box, tr("Please abort if you are not sure"), |
| 780 | 788 | JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); |
| 781 | | if (option == JOptionPane.YES_OPTION) |
| 782 | | return true; |
| | 789 | if (option == JOptionPane.YES_OPTION) { |
| | 790 | return true; |
| | 791 | } |
| 783 | 792 | } catch (MalformedURLException e2) { |
| 784 | 793 | JOptionPane.showMessageDialog(gui, tr("Malformed URL for the EULA licence: {0}", eulaUrl)); |
| 785 | 794 | } |