Changeset 28394 in osm


Ignore:
Timestamp:
2012-05-17T11:05:51+02:00 (12 years ago)
Author:
bastik
Message:

update to josm core changes

Location:
applications/editors/josm/plugins/proj4j
Files:
1 added
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/proj4j/build.xml

    r27119 r28394  
    3636    <property name="commit.message" value="Commit message"/>
    3737    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    38     <property name="plugin.main.version" value="4549"/>
     38    <property name="plugin.main.version" value="5234"/>
    3939    <!--
    4040      ************************************************
  • applications/editors/josm/plugins/proj4j/src/org/openstreetmap/josm/plugins/proj4j/Proj4J.java

    r25450 r28394  
    33package org.openstreetmap.josm.plugins.proj4j;
    44
    5 import org.openstreetmap.josm.data.projection.Projections;
     5import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;
    66import org.openstreetmap.josm.plugins.Plugin;
    77import org.openstreetmap.josm.plugins.PluginInformation;
     
    1010    public Proj4J(PluginInformation info) {
    1111        super(info);
    12         Projections.addProjection(new ProjectionProj4J());
     12        ProjectionPreference.registerProjectionChoice(new Proj4JProjectionChoice());
    1313    }
    1414}
  • applications/editors/josm/plugins/proj4j/src/org/openstreetmap/josm/plugins/proj4j/Proj4JProjectionChoice.java

    r28393 r28394  
    22package org.openstreetmap.josm.plugins.proj4j;
    33
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
    46import java.awt.Dimension;
    57import java.awt.GridBagConstraints;
    6 import javax.swing.event.DocumentEvent;
    7 import static org.openstreetmap.josm.tools.I18n.tr;
    8 
    98import java.awt.GridBagLayout;
    109import java.awt.event.ActionEvent;
     
    1817import java.util.Collection;
    1918import java.util.Collections;
     19
    2020import javax.swing.JLabel;
    21 
    2221import javax.swing.JPanel;
    2322import javax.swing.JScrollPane;
     
    2726import javax.swing.RowFilter;
    2827import javax.swing.SwingConstants;
     28import javax.swing.event.DocumentEvent;
    2929import javax.swing.event.DocumentListener;
    3030import javax.swing.event.ListSelectionEvent;
     
    3333import javax.swing.table.TableRowSorter;
    3434
    35 import org.openstreetmap.josm.data.Bounds;
    36 import org.openstreetmap.josm.data.coor.EastNorth;
    37 import org.openstreetmap.josm.data.coor.LatLon;
     35import org.openstreetmap.josm.data.projection.Projection;
     36import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice;
    3837import org.openstreetmap.josm.tools.GBC;
    3938
     
    4443 *      * Allow user to input proj.4 settings explicitly, or load from a file
    4544 */
    46 public class ProjectionProj4J implements org.openstreetmap.josm.data.projection.Projection, org.openstreetmap.josm.data.projection.ProjectionSubPrefs {
     45public class Proj4JProjectionChoice implements ProjectionChoice {
    4746
    4847    private String crsCode = "EPSG:4326";
    4948    private String filterText = "";
    50     private org.osgeo.proj4j.CoordinateReferenceSystem proj4jCRS;
    51     private org.osgeo.proj4j.CoordinateReferenceSystem wgs84CRS;
    52     private org.osgeo.proj4j.CoordinateTransform transformToWGS84;
    53     private org.osgeo.proj4j.CoordinateTransform transformFromWGS84;
    5449    private JTable table;
    5550    private JTextField filterTextField;
     
    5954    private ActionListener actionListener;
    6055
    61     public ProjectionProj4J() {
    62         super();
    63 
     56    public Proj4JProjectionChoice() {
    6457        try {
    6558            model = new CRSTableModel();
     
    7063
    7164        sorter = new TableRowSorter<CRSTableModel>(model);
    72 
    73         setupTransformations();
    74     }
    75 
    76     @Override
    77     public void setupPreferencePanel(JPanel p, ActionListener actionListener) {
    78         GridBagConstraints c = new GridBagConstraints();
    79         p.setLayout(new GridBagLayout());
    80 
    81         JLabel filterLabel = new JLabel(tr("Filter"), SwingConstants.TRAILING);
    82         c.gridx = 0;
    83         c.gridy = 0;
    84         c.fill = GBC.NONE;
    85         p.add(filterLabel, c);
    86 
    87         c.gridx = 1;
    88         c.gridy = 0;
    89         c.fill = GBC.HORIZONTAL;
    90         filterTextField = new JTextField(filterText, 20);
    91         filterTextField.getDocument().addDocumentListener(
    92                 new DocumentListener() {
    93 
    94                     public void insertUpdate(DocumentEvent e) {
    95                         newFilter();
    96                     }
    97 
    98                     public void removeUpdate(DocumentEvent e) {
    99                         newFilter();
    100                     }
    101 
    102                     public void changedUpdate(DocumentEvent e) {
    103                         newFilter();
    104                     }
    105                 });
    106         p.add(filterTextField, c);
    107 
    108         selectedLabel = new JLabel(tr("Selected: {0}", crsCode), SwingConstants.TRAILING);
    109         c.gridx = 3;
    110         c.gridy = 0;
    111         c.fill = GBC.HORIZONTAL;
    112         p.add(selectedLabel);
    113 
    114         filterLabel.setLabelFor(filterTextField);
    115 
    116         table = new JTable(model);
    117         table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    118         table.setFillsViewportHeight(true);
    119         table.setRowSorter(sorter);
    120         table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    121 
    122         JScrollPane scrollPane = new JScrollPane(table);
    123         c.gridx = 0;
    124         c.gridy = 1;
    125         c.fill = GBC.BOTH;
    126         c.gridwidth = 3;
    127         p.add(scrollPane, c);
    128 
    129         // Update table using filterText
    130         newFilter();
    131 
    132         // Select and show row containing saved projection/CRS, if visible
    133         int index = model.findCode(crsCode);
    134         if (index >= 0) {
    135             index = table.convertRowIndexToView(index);
     65    }
     66   
     67    @Override
     68    public String getId() {
     69        return "proj4jplugin";
     70    }
     71
     72    @Override
     73    public JPanel getPreferencePanel(ActionListener actionListener) {
     74        return new Proj4JPanel(actionListener);
     75    }
     76   
     77    protected class Proj4JPanel extends JPanel {
     78       
     79        public Proj4JPanel(ActionListener actionListener) {
     80            GridBagConstraints c = new GridBagConstraints();
     81            this.setLayout(new GridBagLayout());
     82
     83            JLabel filterLabel = new JLabel(tr("Filter"), SwingConstants.TRAILING);
     84            c.gridx = 0;
     85            c.gridy = 0;
     86            c.fill = GBC.NONE;
     87            this.add(filterLabel, c);
     88
     89            c.gridx = 1;
     90            c.gridy = 0;
     91            c.fill = GBC.HORIZONTAL;
     92            filterTextField = new JTextField(filterText, 20);
     93            filterTextField.getDocument().addDocumentListener(
     94                    new DocumentListener() {
     95
     96                        public void insertUpdate(DocumentEvent e) {
     97                            newFilter();
     98                        }
     99
     100                        public void removeUpdate(DocumentEvent e) {
     101                            newFilter();
     102                        }
     103
     104                        public void changedUpdate(DocumentEvent e) {
     105                            newFilter();
     106                        }
     107                    });
     108            this.add(filterTextField, c);
     109
     110            selectedLabel = new JLabel(tr("Selected: {0}", crsCode), SwingConstants.TRAILING);
     111            c.gridx = 3;
     112            c.gridy = 0;
     113            c.fill = GBC.HORIZONTAL;
     114            this.add(selectedLabel);
     115
     116            filterLabel.setLabelFor(filterTextField);
     117
     118            table = new JTable(model);
     119            table.setPreferredScrollableViewportSize(new Dimension(500, 70));
     120            table.setFillsViewportHeight(true);
     121            table.setRowSorter(sorter);
     122            table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     123
     124            JScrollPane scrollPane = new JScrollPane(table);
     125            c.gridx = 0;
     126            c.gridy = 1;
     127            c.fill = GBC.BOTH;
     128            c.gridwidth = 3;
     129            this.add(scrollPane, c);
     130
     131            // Update table using filterText
     132            newFilter();
     133
     134            // Select and show row containing saved projection/CRS, if visible
     135            int index = model.findCode(crsCode);
    136136            if (index >= 0) {
    137                 table.addRowSelectionInterval(index, index);
    138                 table.scrollRectToVisible(table.getCellRect(index, 0, true));
    139             }
    140         }
    141 
    142         // add listener to react to table selections
    143         table.getSelectionModel().addListSelectionListener(
    144                 new SelectionListener(table));
    145 
    146         this.actionListener = actionListener;
     137                index = table.convertRowIndexToView(index);
     138                if (index >= 0) {
     139                    table.addRowSelectionInterval(index, index);
     140                    table.scrollRectToVisible(table.getCellRect(index, 0, true));
     141                }
     142            }
     143
     144            // add listener to react to table selections
     145            table.getSelectionModel().addListSelectionListener(
     146                    new SelectionListener(table));
     147
     148            Proj4JProjectionChoice.this.actionListener = actionListener;
     149        }
    147150    }
    148151
     
    168171                filterText = array[1];
    169172            }
    170             setupTransformations();
    171         }
    172     }
    173 
    174     @Override
    175     public double getDefaultZoomInPPD() {
    176         //TODO: this needs to be changed per projection
    177         return 1.01;
    178     }
    179 
    180     /**
    181      * @param LatLon WGS84 (in degree)
    182      * @return xy east/north (in whatever unit the projection uses, m/ft/deg/etc)
    183      */
    184     @Override
    185     public EastNorth latlon2eastNorth(LatLon p) {
    186         org.osgeo.proj4j.ProjCoordinate pc1 = new org.osgeo.proj4j.ProjCoordinate(p.lon(), p.lat());
    187         org.osgeo.proj4j.ProjCoordinate pc2 = new org.osgeo.proj4j.ProjCoordinate();
    188         //System.out.println("From " + pc1.x + " " + pc1.y);
    189         transformFromWGS84.transform(pc1, pc2);
    190         //System.out.println("To " + pc2.x + " " + pc2.y);
    191         return new EastNorth(pc2.x, pc2.y);
    192     }
    193 
    194     /**
    195      * @param xy east/north (in whatever unit the projection uses, m/ft/deg/etc)
    196      * @return LatLon WGS84 (in degree)
    197      */
    198     @Override
    199     public LatLon eastNorth2latlon(EastNorth p) {
    200         org.osgeo.proj4j.ProjCoordinate pc1 = new org.osgeo.proj4j.ProjCoordinate(p.east(), p.north());
    201         org.osgeo.proj4j.ProjCoordinate pc2 = new org.osgeo.proj4j.ProjCoordinate();
    202         //System.out.println("InvFrom " + pc1.x + " " + pc1.y);
    203         transformToWGS84.transform(pc1, pc2);
    204         //System.out.println("InvTo " + pc2.x + " " + pc2.y);
    205         return new LatLon(pc2.y, pc2.x);
     173        }
     174    }
     175
     176    @Override
     177    public Projection getProjection() {
     178        return new Proj4JProjection(crsCode);
    206179    }
    207180
    208181    @Override
    209182    public String toString() {
    210         // TODO: include description in string
    211         return tr("Proj4J: {0} selected", crsCode);
    212     }
    213 
    214     @Override
    215     public String toCode() {
    216         return crsCode;
    217     }
    218 
    219     @Override
    220     public String getCacheDirectoryName() {
    221         return "Proj4J";
    222     }
    223 
    224     @Override
    225     public Bounds getWorldBoundsLatLon() {
    226         org.osgeo.proj4j.proj.Projection proj = proj4jCRS.getProjection();
    227 
    228         // FIXME: Do we need to convert these coords because of possibly differing datums?
    229         LatLon min = new LatLon(proj.getMinLatitudeDegrees(), proj.getMinLongitudeDegrees());
    230         LatLon max = new LatLon(proj.getMaxLatitudeDegrees(), proj.getMaxLongitudeDegrees());
    231         return new Bounds(min, max);
     183        return tr("Proj4J Plugin");
    232184    }
    233185
     
    246198                crsCode = model.getCRSEntryAt(index).getName();
    247199                selectedLabel.setText(tr("Selected: {0}", crsCode));
    248                 setupTransformations();
    249200                if (actionListener != null) {
    250201                    actionListener.actionPerformed(new ActionEvent(selectedLabel, 0, "CRS changed"));
     
    265216            updateSelectedCode();
    266217        }
    267     }
    268 
    269     private void setupTransformations() {
    270         org.osgeo.proj4j.CRSFactory crsFactory =
    271                 new org.osgeo.proj4j.CRSFactory();
    272         org.osgeo.proj4j.CoordinateTransformFactory transFactory =
    273                 new org.osgeo.proj4j.CoordinateTransformFactory();
    274 
    275         // Create coordinate reference systems for source and target
    276         proj4jCRS = crsFactory.createFromName(crsCode);
    277         wgs84CRS = crsFactory.createFromName("EPSG:4326");
    278 
    279         // Create transformations between CRS
    280         transformToWGS84 = transFactory.createTransform(proj4jCRS, wgs84CRS);
    281         transformFromWGS84 = transFactory.createTransform(wgs84CRS, proj4jCRS);
    282218    }
    283219
Note: See TracChangeset for help on using the changeset viewer.