Mercurial > dive4elements > river
view flys-backend/src/main/java/de/intevation/flys/importer/parsers/MorphologicalWidthParser.java @ 4198:1cdbd8a0c994
Added two new tables ClickableQDTable and ClickableWTable and made Ws and Qs clickable in historical discharge calculation.
The new tables define listener interfaces (clicked lower or upper icon) to listen to user clicks.
In addition to this, there is an enum ClickMode with NONE, SINGLE and RANGE options, which allows to
specifiy, which icons are displayed in the tables. NONE means no icon for user clicks, SINGLE has 1
icon, RANGE 2 icons for lower and upper.
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 22 Oct 2012 13:31:25 +0200 |
parents | f63b39799d2d |
children | 255898799ed9 |
line wrap: on
line source
package de.intevation.flys.importer.parsers; import java.math.BigDecimal; import java.text.NumberFormat; import java.text.ParseException; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.log4j.Logger; import de.intevation.flys.importer.ImportMorphWidth; import de.intevation.flys.importer.ImportMorphWidthValue; import de.intevation.flys.importer.ImportUnit; public class MorphologicalWidthParser extends LineParser { private static final Logger log = Logger.getLogger(MorphologicalWidthParser.class); public static final NumberFormat nf = NumberFormat.getInstance(DEFAULT_LOCALE); public static final Pattern META_UNIT = Pattern.compile("^Einheit: \\[(.*)\\].*"); protected List<ImportMorphWidth> morphWidths; protected ImportMorphWidth current; public MorphologicalWidthParser() { morphWidths = new ArrayList<ImportMorphWidth>(); } @Override protected void reset() { current = new ImportMorphWidth(); } @Override protected void finish() { if (current != null) { morphWidths.add(current); } } @Override protected void handleLine(int lineNum, String line) { if (line.startsWith(START_META_CHAR)) { handleMetaLine(stripMetaLine(line)); } else { handleDataLine(line); } } protected void handleMetaLine(String line) { if (handleMetaUnit(line)) { return; } else { log.warn("MWP: Unknown meta line: '" + line + "'"); } } protected boolean handleMetaUnit(String line) { Matcher m = META_UNIT.matcher(line); if (m.matches()) { String unit = m.group(1); current.setUnit(new ImportUnit(unit)); return true; } return false; } protected void handleDataLine(String line) { String[] vals = line.split(SEPERATOR_CHAR); if (vals == null || vals.length < 2) { log.warn("MWP: skip invalid data line: '" + line + "'"); return; } try { BigDecimal km = new BigDecimal(nf.parse(vals[0]).doubleValue()); BigDecimal width = new BigDecimal(nf.parse(vals[1]).doubleValue()); String desc = vals.length > 2 ? vals[2] : null; current.addValue(new ImportMorphWidthValue( km, width, desc )); } catch (ParseException pe) { log.warn("MWP: Error while parsing numbers in '" + line + "'"); } } public List<ImportMorphWidth> getMorphologicalWidths() { return morphWidths; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :