Ignore:
Timestamp:
2013-12-10T00:35:06+01:00 (11 years ago)
Author:
donvip
Message:

[josm_openinghours] fix regressions

Location:
applications/editors/josm/plugins/OpeningHoursEditor
Files:
2 edited

Legend:

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

    r30112 r30122  
    1515    <import file="../build-common.xml"/>
    1616       
    17     <property name="javacc.home" location="../../core/tools"/>
     17    <property name="javacc.home" location="../00_core_tools"/>
    1818        <property name="parser.dir" location="${plugin.src.dir}/org/openstreetmap/josm/plugins/ohe/parser"/>
    1919       
  • applications/editors/josm/plugins/OpeningHoursEditor/src/org/openstreetmap/josm/plugins/ohe/gui/OheDialogPanel.java

    r30116 r30122  
    2424import org.openstreetmap.josm.plugins.ohe.parser.ParseException;
    2525import org.openstreetmap.josm.plugins.ohe.parser.SyntaxException;
     26import org.openstreetmap.josm.plugins.ohe.parser.TokenMgrError;
    2627import org.openstreetmap.josm.tools.GBC;
    2728
     
    99100        toolsPanel.add(Box.createGlue(), GBC.std().fill(GBC.HORIZONTAL));
    100101        toolsPanel.add(actualPostionLabel, GBC.eop());
    101 
     102       
    102103        editorPanel = new OheEditor(this);
    103104
     
    132133                time = OpeningTimeUtils.convert(compiler.startCompile());
    133134            } catch (Throwable t) {
     135                Main.warn(t);
     136               
    134137                int tColumns[] = null;
    135                 String info = null;
     138                String info = t.getMessage();
    136139
    137140                if (t instanceof ParseException) {
     
    141144                    SyntaxException syntaxError = (SyntaxException) t;
    142145                    tColumns = new int[] { syntaxError.getStartColumn(), syntaxError.getEndColumn() };
    143                     info = syntaxError.getMessage();
    144                 } else {
    145                     info = t.getMessage();
    146                     Main.warn(t);
     146                } else if (t instanceof TokenMgrError) {
     147                    try {
     148                        // With JavaCC 6 Message is: "Lexical error at line 1, column 20.  Encountered: "P" (80), after : ""
     149                        int idx = info.indexOf("column ");
     150                        if (idx > -1) {
     151                            int col = Integer.parseInt(info.substring(idx+"column ".length(), info.indexOf('.', idx)));
     152                            tColumns = new int[] { col - 1, col + 1 };
     153                        }
     154                    } catch (IndexOutOfBoundsException e) {
     155                        Main.warn(e);
     156                    } catch (NumberFormatException e) {
     157                        Main.warn(e);
     158                    }
    147159                }
    148160
    149161                // shows a Information Dialog, where the Error occurred
    150                 if (tColumns != null) {
    151                     int first = Math.max(0, tColumns[0]);
    152                     int last = Math.min(value.length(), tColumns[1]);
    153                     String begin = value.substring(0, first);
    154                     String middle = value.substring(first, last);
    155                     String end = value.substring(last);
    156                     valueField.setCaretPosition(first);
    157                     // TODO focus on the valueField
    158                     String message = "<html>" + tr("There is something wrong in the value near:") + "<br>" + begin
    159                             + "<span style='background-color:red;'>" + middle + "</span>" + end;
    160                     if (info != null)
    161                         message += "<br>" + tr("Info: {0}", tr(info));
    162                     message += "<br>" + tr("Correct the value manually and than press Enter.");
    163                     message += "</html>";
    164                     JOptionPane.showMessageDialog(this, message, tr("Error in timeformat"),
    165                             JOptionPane.INFORMATION_MESSAGE);
     162                if (tColumns != null || info != null) {
     163                    String message = "<html>";
     164                    if (tColumns != null) {
     165                        int first = Math.max(0, tColumns[0]);
     166                        int last = Math.min(value.length(), tColumns[1]);
     167                        String begin = value.substring(0, first);
     168                        String middle = value.substring(first, last);
     169                        String end = value.substring(last);
     170                        valueField.setCaretPosition(first);
     171                        // TODO focus on the valueField
     172                        message += tr("There is something wrong in the value near:") + "<br>" + begin
     173                                + "<span style='background-color:red;'>" + middle + "</span>" + end;
     174                    }
     175                    if (info != null) {
     176                        if (tColumns != null) {
     177                            message += "<br>";
     178                        }
     179                        message += tr("Info: {0}", tr(info));
     180                    }
     181                    message += "<br>" + tr("Correct the value manually and than press Enter.") + "</html>";
     182                    JOptionPane.showMessageDialog(this, message, tr("Error in timeformat"), JOptionPane.INFORMATION_MESSAGE);
    166183                }
    167184
Note: See TracChangeset for help on using the changeset viewer.