@Override public CoordinateReferenceSystem getCRS(GeoPos referencePos) throws FactoryException { if (selectedCrsInfo != null) { return selectedCrsInfo.getCrs(referencePos); } else { return null; } }
private void updateFilter(String text) { filteredListModel.setFilter(crsInfo -> { String description = crsInfo.toString().toLowerCase(); return description.contains(text.trim().toLowerCase()); }); }
static List<CrsInfo> generateCRSList() { // todo - (mp/mz) this method takes time (2 sec.) try to speed up Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, true); Set<CRSAuthorityFactory> factories = ReferencingFactoryFinder.getCRSAuthorityFactories(hints); final List<CRSAuthorityFactory> filtered = new ArrayList<CRSAuthorityFactory>(); for (final CRSAuthorityFactory factory : factories) { if (Citations.identifierMatches(factory.getAuthority(), AUTHORITY)) { filtered.add(factory); } } CRSAuthorityFactory crsAuthorityFactory = FallbackAuthorityFactory.create(CRSAuthorityFactory.class, filtered); Set<String> codes = new HashSet<String>(); List<CrsInfo> crsList = new ArrayList<CrsInfo>(1024); retrieveCodes(codes, GeodeticCRS.class, crsAuthorityFactory); retrieveCodes(codes, ProjectedCRS.class, crsAuthorityFactory); for (String code : codes) { final String authCode = String.format("%s:%s", AUTHORITY, code); crsList.add(new CrsInfo(authCode, crsAuthorityFactory)); } codes.clear(); AutoCRSFactory autoCRSFactory = new AutoCRSFactory(); retrieveCodes(codes, ProjectedCRS.class, autoCRSFactory); for (String code : codes) { final String authCode = String.format("AUTO:%s", code); crsList.add(new AutoCrsInfo(authCode, autoCRSFactory)); } Collections.sort(crsList); return crsList; }
final JButton crsButton = new JButton("Select..."); final PredefinedCrsPanel predefinedCrsForm = new PredefinedCrsPanel( new CrsInfoListModel(CrsInfo.generateCRSList())); crsButton.addActionListener(e -> { final ModalDialog dialog = new ModalDialog(null, selectedCrsInfo = predefinedCrsForm.getSelectedCrsInfo(); if (selectedCrsInfo != null) { crsCodeField.setText(selectedCrsInfo.toString()); fireCrsChanged();
@Override public void valueChanged(ListSelectionEvent e) { final JList list = (JList) e.getSource(); selectedCrsInfo = (CrsInfo) list.getSelectedValue(); if (selectedCrsInfo != null) { try { setInfoText(selectedCrsInfo.getDescription()); } catch (Exception e1) { String message = e1.getMessage(); if (message != null) { setInfoText("Error while creating CRS:\n\n" + message); } } } }
public static void main(String[] args) { final JFrame frame = new JFrame("CRS Selection Panel"); Container contentPane = frame.getContentPane(); final CrsInfoListModel listModel = new CrsInfoListModel(CrsInfo.generateCRSList()); PredefinedCrsPanel predefinedCrsForm = new PredefinedCrsPanel(listModel); contentPane.add(predefinedCrsForm); frame.setSize(600, 400); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); SwingUtilities.invokeLater(() -> frame.setVisible(true)); }
public String getDescription() { try { return getCrs(null).toString(); } catch (FactoryException e) { return e.getMessage(); } }