Changeset 13544 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2018-03-19T00:48:34+01:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/projection/CodeProjectionChoice.java
r13515 r13544 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Dimension;7 import java.awt.GridBagLayout;8 6 import java.awt.event.ActionListener; 9 7 import java.io.Serializable; 10 import java.util.ArrayList;11 8 import java.util.Collection; 12 9 import java.util.Collections; 13 10 import java.util.Comparator; 14 import java.util.List;15 import java.util.Locale;16 11 import java.util.regex.Matcher; 17 12 import java.util.regex.Pattern; 18 13 19 14 import javax.swing.JPanel; 20 import javax.swing.JScrollPane;21 import javax.swing.JTable;22 import javax.swing.event.DocumentEvent;23 import javax.swing.event.DocumentListener;24 import javax.swing.event.ListSelectionEvent;25 import javax.swing.event.ListSelectionListener;26 import javax.swing.table.AbstractTableModel;27 15 28 16 import org.openstreetmap.josm.data.projection.Projection; 29 17 import org.openstreetmap.josm.data.projection.Projections; 30 import org.openstreetmap.josm.gui.widgets.JosmTextField;31 import org.openstreetmap.josm.tools.GBC;32 18 33 19 /** … … 44 30 public CodeProjectionChoice() { 45 31 super(tr("By Code (EPSG)"), /* NO-ICON */ "core:code"); 46 }47 48 private static class CodeSelectionPanel extends JPanel implements ListSelectionListener, DocumentListener {49 50 private final JosmTextField filter = new JosmTextField(30);51 private final ProjectionCodeModel model = new ProjectionCodeModel();52 private JTable table;53 private final List<String> data;54 private final List<String> filteredData;55 private static final String DEFAULT_CODE = "EPSG:3857";56 private String lastCode = DEFAULT_CODE;57 private final transient ActionListener listener;58 59 CodeSelectionPanel(String initialCode, ActionListener listener) {60 this.listener = listener;61 data = new ArrayList<>(Projections.getAllProjectionCodes());62 data.sort(new CodeComparator());63 filteredData = new ArrayList<>(data);64 build();65 setCode(initialCode != null ? initialCode : DEFAULT_CODE);66 table.getSelectionModel().addListSelectionListener(this);67 }68 69 /**70 * List model for the filtered view on the list of all codes.71 */72 private class ProjectionCodeModel extends AbstractTableModel {73 @Override74 public int getRowCount() {75 return filteredData.size();76 }77 78 @Override79 public String getValueAt(int index, int column) {80 if (index >= 0 && index < filteredData.size()) {81 String code = filteredData.get(index);82 switch (column) {83 case 0: return code;84 case 1: return Projections.getProjectionByCode(code).toString();85 default: break;86 }87 }88 return null;89 }90 91 @Override92 public int getColumnCount() {93 return 2;94 }95 96 @Override97 public String getColumnName(int column) {98 switch (column) {99 case 0: return tr("Projection code");100 case 1: return tr("Projection name");101 default: return super.getColumnName(column);102 }103 }104 }105 106 private void build() {107 filter.setColumns(40);108 filter.getDocument().addDocumentListener(this);109 110 table = new JTable(model);111 table.setAutoCreateRowSorter(true);112 JScrollPane scroll = new JScrollPane(table);113 scroll.setPreferredSize(new Dimension(200, 214));114 115 this.setLayout(new GridBagLayout());116 this.add(filter, GBC.eol().weight(1.0, 0.0));117 this.add(scroll, GBC.eol().fill(GBC.HORIZONTAL));118 }119 120 public String getCode() {121 int idx = table.getSelectedRow();122 if (idx == -1)123 return lastCode;124 return filteredData.get(table.convertRowIndexToModel(table.getSelectedRow()));125 }126 127 public final void setCode(String code) {128 int idx = filteredData.indexOf(code);129 if (idx != -1) {130 selectRow(idx);131 }132 }133 134 private void selectRow(int idx) {135 table.setRowSelectionInterval(idx, idx);136 ensureRowIsVisible(idx);137 }138 139 private void ensureRowIsVisible(int idx) {140 table.scrollRectToVisible(table.getCellRect(idx, 0, true));141 }142 143 @Override144 public void valueChanged(ListSelectionEvent e) {145 listener.actionPerformed(null);146 lastCode = getCode();147 }148 149 @Override150 public void insertUpdate(DocumentEvent e) {151 updateFilter();152 }153 154 @Override155 public void removeUpdate(DocumentEvent e) {156 updateFilter();157 }158 159 @Override160 public void changedUpdate(DocumentEvent e) {161 updateFilter();162 }163 164 private void updateFilter() {165 filteredData.clear();166 String filterTxt = filter.getText().trim().toLowerCase(Locale.ENGLISH);167 for (String code : data) {168 if (code.toLowerCase(Locale.ENGLISH).contains(filterTxt)169 || Projections.getProjectionByCode(code).toString().toLowerCase(Locale.ENGLISH).contains(filterTxt)) {170 filteredData.add(code);171 }172 }173 model.fireTableDataChanged();174 int idx = filteredData.indexOf(lastCode);175 if (idx == -1) {176 table.clearSelection();177 if (table.getModel().getRowCount() > 0) {178 ensureRowIsVisible(0);179 }180 } else {181 selectRow(idx);182 }183 }184 32 } 185 33 -
trunk/src/org/openstreetmap/josm/tools/I18n.java
r13509 r13544 379 379 ZipFile zipFile = new ZipFile(source, StandardCharsets.UTF_8); 380 380 InputStream orig = zipFile.getInputStream(enfile); 381 InputStream trans = zipFile.getInputStream(langfile) ;381 InputStream trans = zipFile.getInputStream(langfile) 382 382 ) { 383 383 if (orig != null && trans != null) -
trunk/src/org/openstreetmap/josm/tools/TextTagParser.java
r13541 r13544 5 5 import static org.openstreetmap.josm.tools.I18n.trn; 6 6 7 import java.util.Arrays;8 7 import java.util.HashMap; 9 8 import java.util.Map; … … 27 26 private TextTagParser() { 28 27 // Hide default constructor for utils classes 29 }30 31 /**32 * A helper class that analyzes the text and attempts to parse tags from it33 */34 public static class TextAnalyzer {35 private boolean quotesStarted;36 private boolean esc;37 private final StringBuilder s = new StringBuilder(200);38 private String valueStops = "\n\r\t";39 private int pos;40 private final String data;41 private final int n;42 43 /**44 * Create a new {@link TextAnalyzer}45 * @param text The text to parse46 */47 public TextAnalyzer(String text) {48 pos = 0;49 data = Utils.strip(text);50 n = data.length();51 // fix #1604: allow space characters as value stops for single-line input only52 if (data.indexOf('\r') == -1 && data.indexOf('\n') == -1) {53 valueStops += " ";54 }55 }56 57 /**58 * Read tags from "Free format"59 * @return map of tags60 */61 private Map<String, String> getFreeParsedTags() {62 String k, v;63 Map<String, String> tags = new HashMap<>();64 65 while (true) {66 skipEmpty();67 if (pos == n) {68 break;69 }70 k = parseString("\n\r\t= ");71 if (pos == n) {72 tags.clear();73 break;74 }75 skipSign();76 if (pos == n) {77 tags.clear();78 break;79 }80 v = parseString(valueStops);81 tags.put(k, v);82 }83 return tags;84 }85 86 private String parseString(String stopChars) {87 char[] stop = stopChars.toCharArray();88 Arrays.sort(stop);89 char c;90 while (pos < n) {91 c = data.charAt(pos);92 if (esc) {93 esc = false;94 s.append(c); // \" \\95 } else if (c == '\\') {96 esc = true;97 } else if (c == '\"' && !quotesStarted) { // opening "98 if (!s.toString().trim().isEmpty()) { // we had ||some text"||99 s.append(c); // just add ", not open100 } else {101 s.delete(0, s.length()); // forget that empty characthers and start reading "....102 quotesStarted = true;103 }104 } else if (c == '\"' && quotesStarted) { // closing "105 quotesStarted = false;106 pos++;107 break;108 } else if (!quotesStarted && (Arrays.binarySearch(stop, c) >= 0)) {109 // stop-symbol found110 pos++;111 break;112 } else {113 // skip non-printable characters114 if (c >= 32) s.append(c);115 }116 pos++;117 }118 119 String res = s.toString();120 s.delete(0, s.length());121 return res.trim();122 }123 124 private void skipSign() {125 char c;126 boolean signFound = false;127 while (pos < n) {128 c = data.charAt(pos);129 if (c == '\t' || c == '\n' || c == ' ') {130 pos++;131 } else if (c == '=') {132 if (signFound) break; // a = =qwerty means "a"="=qwerty"133 signFound = true;134 pos++;135 } else {136 break;137 }138 }139 }140 141 private void skipEmpty() {142 char c;143 while (pos < n) {144 c = data.charAt(pos);145 if (c == '\t' || c == '\n' || c == '\r' || c == ' ') {146 pos++;147 } else {148 break;149 }150 }151 }152 28 } 153 29
Note:
See TracChangeset
for help on using the changeset viewer.