Changeset 7081 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2014-05-09T04:49:54+02:00 (10 years ago)
Author:
Don-vip
Message:

fixes for unit tests

Location:
trunk/src/org/openstreetmap/josm
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/JumpToAction.java

    r7025 r7081  
    3232 */
    3333public class JumpToAction extends JosmAction {
    34    
     34
    3535    /**
    3636     * Constructs a new {@code JumpToAction}.
    3737     */
    3838    public JumpToAction() {
    39         super(tr("Jump To Position"), (Icon) null, tr("Opens a dialog that allows to jump to a specific location"), 
     39        super(tr("Jump To Position"), (Icon) null, tr("Opens a dialog that allows to jump to a specific location"),
    4040                Shortcut.registerShortcut("tools:jumpto", tr("Tool: {0}", tr("Jump To Position")),
    4141                        KeyEvent.VK_J, Shortcut.CTRL), true, "action/jumpto", true);
     
    4646    private final JosmTextField lon = new JosmTextField();
    4747    private final JosmTextField zm = new JosmTextField();
     48
     49    class OsmURLListener implements DocumentListener {
     50        @Override public void changedUpdate(DocumentEvent e) { parseURL(); }
     51        @Override public void insertUpdate(DocumentEvent e) { parseURL(); }
     52        @Override public void removeUpdate(DocumentEvent e) { parseURL(); }
     53    }
     54
     55    class OsmLonLatListener implements DocumentListener {
     56        @Override public void changedUpdate(DocumentEvent e) { updateUrl(false); }
     57        @Override public void insertUpdate(DocumentEvent e) { updateUrl(false); }
     58        @Override public void removeUpdate(DocumentEvent e) { updateUrl(false); }
     59    }
    4860
    4961    /**
     
    7385                              + "</html>"),
    7486                  BorderLayout.NORTH);
    75 
    76         class OsmURLListener implements DocumentListener {
    77             @Override public void changedUpdate(DocumentEvent e) { parseURL(); }
    78             @Override public void insertUpdate(DocumentEvent e) { parseURL(); }
    79             @Override public void removeUpdate(DocumentEvent e) { parseURL(); }
    80         }
    81 
    82         class OsmLonLatListener implements DocumentListener {
    83             @Override public void changedUpdate(DocumentEvent e) { updateUrl(false); }
    84             @Override public void insertUpdate(DocumentEvent e) { updateUrl(false); }
    85             @Override public void removeUpdate(DocumentEvent e) { updateUrl(false); }
    86         }
    8787
    8888        OsmLonLatListener x = new OsmLonLatListener();
     
    150150                    int eq = arg.indexOf('=');
    151151                    if (eq == -1 || !"zoom".equalsIgnoreCase(arg.substring(0, eq))) continue;
    152    
     152
    153153                    zoomLvl = Integer.parseInt(arg.substring(eq + 1));
    154154                    break;
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r7080 r7081  
    8080    final public static int noThreads;
    8181    final public static ExecutorService styleCreatorPool;
    82    
     82
    8383    static {
    8484        noThreads = Main.pref.getInteger(
     
    330330    private boolean leftHandTraffic;
    331331
     332    /**
     333     * Constructs a new {@code StyledMapRenderer}.
     334     *
     335     * @param g the graphics context. Must not be null.
     336     * @param nc the map viewport. Must not be null.
     337     * @param isInactiveMode if true, the paint visitor shall render OSM objects such that they
     338     * look inactive. Example: rendering of data in an inactive layer using light gray as color only.
     339     * @throws IllegalArgumentException thrown if {@code g} is null
     340     * @throws IllegalArgumentException thrown if {@code nc} is null
     341     */
    332342    public StyledMapRenderer(Graphics2D g, NavigatableComponent nc, boolean isInactiveMode) {
    333343        super(g, nc, isInactiveMode);
     
    13291339        return null;
    13301340    }
    1331    
     1341
    13321342    @Override
    13331343    public void render(final DataSet data, boolean renderVirtualNodes, Bounds bounds) {
     
    13431353       
    13441354        highlightWaySegments = data.getHighlightedWaySegments();
    1345        
     1355
    13461356        long timeStart=0, timePhase1=0, timeFinished;
    13471357        if (Main.isTraceEnabled()) {
     
    13691379                this.output = output;
    13701380            }
    1371            
     1381
    13721382            @Override
    13731383            public List<StyleRecord> call() throws Exception {
     
    13801390                return output;
    13811391            }
    1382            
     1392
    13831393            @Override
    13841394            public void visit(Node n) {
     
    14561466       
    14571467        final List<StyleRecord> allStyleElems = new ArrayList<>(nodes.size()+ways.size()+relations.size());
    1458        
     1468
    14591469        class ConcurrentTasksHelper {
    1460            
     1470
    14611471            void process(List<? extends OsmPrimitive> prims) {
    14621472                final List<ComputeStyleListWorker> tasks = new ArrayList<>();
     
    14901500        }
    14911501        ConcurrentTasksHelper helper = new ConcurrentTasksHelper();
    1492        
     1502
    14931503        // Need to process all relations first.
    14941504        // Reason: Make sure, ElemStyles.getStyleCacheWithRange is
     
    15051515            System.err.print("phase 1 (calculate styles): " + (timePhase1 - timeStart) + " ms");
    15061516        }
    1507        
     1517
    15081518        Collections.sort(allStyleElems);
    1509        
     1519
    15101520        for (StyleRecord r : allStyleElems) {
    15111521            r.style.paintPrimitive(
  • trunk/src/org/openstreetmap/josm/gui/JosmUserIdentityManager.java

    r7048 r7081  
    242242        switch (evt.getKey()) {
    243243        case "osm-server.username":
    244             if (!(evt.getNewValue() instanceof StringSetting)) return;
    245             String newUserName = ((StringSetting) evt.getNewValue()).getValue();
     244            String newUserName = null;
     245            if (evt.getNewValue() instanceof StringSetting) {
     246                newUserName = ((StringSetting) evt.getNewValue()).getValue();
     247            }
    246248            if (newUserName == null || newUserName.trim().isEmpty()) {
    247249                setAnonymous();
    248250            } else {
    249                 if (! newUserName.equals(userName)) {
     251                if (!newUserName.equals(userName)) {
    250252                    setPartiallyIdentified(newUserName);
    251253                }
     
    254256
    255257        case "osm-server.url":
    256             if (!(evt.getNewValue() instanceof StringSetting)) return;
    257             String newUrl = ((StringSetting) evt.getNewValue()).getValue();
     258            String newUrl = null;
     259            if (evt.getNewValue() instanceof StringSetting) {
     260                newUrl = ((StringSetting) evt.getNewValue()).getValue();
     261            }
    258262            if (newUrl == null || newUrl.trim().isEmpty()) {
    259263                setAnonymous();
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java

    r7005 r7081  
    1818import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
    1919import org.openstreetmap.josm.gui.preferences.SourceEntry;
     20import org.openstreetmap.josm.io.MirroredInputStream;
    2021import org.openstreetmap.josm.tools.ImageProvider;
    2122import org.openstreetmap.josm.tools.Utils;
     
    6869    public abstract void apply(MultiCascade mc, OsmPrimitive osm, double scale, OsmPrimitive multipolyOuterWay, boolean pretendWayIsClosed);
    6970
     71    /**
     72     * Loads the style source.
     73     */
    7074    public abstract void loadStyleSource();
    7175
     
    7781     */
    7882    public abstract InputStream getSourceInputStream() throws IOException;
     83   
     84    /**
     85     * Returns a new {@code MirroredInputStream} to the local file containing style source (can be a text file or an archive).
     86     * @return A new {@code MirroredInputStream} to the local file containing style source
     87     * @throws IOException if any I/O error occurs.
     88     * @since 7081
     89     */
     90    public abstract MirroredInputStream getMirroredInputStream() throws IOException;
    7991
    8092    /**
     
    152164        this.lastMTime = lastMTime;
    153165    }
    154 
    155 
    156166}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java

    r7069 r7081  
    6565    }
    6666
    67     public static Condition createPseudoClassCondition(String id, boolean not, Context context) {
     67    public static PseudoClassCondition createPseudoClassCondition(String id, boolean not, Context context) {
    6868        return new PseudoClassCondition(id, not, context);
    6969    }
    7070
    71     public static Condition createClassCondition(String id, boolean not, Context context) {
     71    public static ClassCondition createClassCondition(String id, boolean not, Context context) {
    7272        return new ClassCondition(id, not);
    7373    }
    7474
    75     public static Condition createExpressionCondition(Expression e, Context context) {
     75    public static ExpressionCondition createExpressionCondition(Expression e, Context context) {
    7676        return new ExpressionCondition(e);
    7777    }
     
    153153    /**
    154154     * Most common case of a KeyValueCondition.
    155      * 
     155     *
    156156     * Extra class for performance reasons.
    157157     */
     
    169169            return v.equals(e.osm.get(k));
    170170        }
    171        
     171
    172172        public Tag asTag() {
    173173            return new Tag(k, v);
     
    178178            return '[' + k + '=' + v + ']';
    179179        }
    180        
     180
    181181    }
    182182
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r7074 r7081  
    151151        }
    152152    }
    153    
     153
    154154    @Override
    155155    public InputStream getSourceInputStream() throws IOException {
     
    157157            return new ByteArrayInputStream(css.getBytes(Utils.UTF_8));
    158158        }
    159         MirroredInputStream in = new MirroredInputStream(url, null, MAPCSS_STYLE_MIME_TYPES);
     159        MirroredInputStream in = getMirroredInputStream();
    160160        if (isZip) {
    161161            File file = in.getFile();
     
    170170            return in;
    171171        }
     172    }
     173
     174    @Override
     175    public MirroredInputStream getMirroredInputStream() throws IOException {
     176        return new MirroredInputStream(url, null, MAPCSS_STYLE_MIME_TYPES);
    172177    }
    173178
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java

    r7033 r7081  
    102102    @Override
    103103    public InputStream getSourceInputStream() throws IOException {
    104         MirroredInputStream in = new MirroredInputStream(url, null, XML_STYLE_MIME_TYPES);
     104        MirroredInputStream in = getMirroredInputStream();
    105105        InputStream zip = in.findZipEntryInputStream("xml", "style");
    106106        if (zip != null) {
     
    111111            return in;
    112112        }
     113    }
     114
     115    @Override
     116    public MirroredInputStream getMirroredInputStream() throws IOException {
     117        return new MirroredInputStream(url, null, XML_STYLE_MIME_TYPES);
    113118    }
    114119
  • trunk/src/org/openstreetmap/josm/io/MirroredInputStream.java

    r7058 r7081  
    228228    }
    229229
     230    /**
     231     * Replies the local file.
     232     * @return The local file on disk
     233     */
    230234    public File getFile() {
    231235        return file;
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r7037 r7081  
    615615                url = new URL(new URL(getBaseUrl()), urlSuffix);
    616616                Main.info(requestMethod + " " + url + "... ");
     617                Main.debug(requestBody);
    617618                // fix #5369, see http://www.tikalk.com/java/forums/httpurlconnection-disable-keep-alive
    618619                activeConnection = Utils.openHttpConnection(url, false);
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r7033 r7081  
    439439        }
    440440
    441         // user attribute added in 0.4 API
    442441        String user = parser.getAttributeValue(null, "user");
    443         // uid attribute added in 0.6 API
    444442        String uid = parser.getAttributeValue(null, "uid");
    445443        current.setUser(createUser(uid, user));
    446444
    447         // visible attribute added in 0.4 API
    448445        String visible = parser.getAttributeValue(null, "visible");
    449446        if (visible != null) {
     
    474471        } else {
    475472            // version expected for OSM primitives with an id assigned by the server (id > 0), since API 0.6
    476             //
    477473            if (!current.isNew() && ds.getVersion() != null && "0.6".equals(ds.getVersion())) {
    478474                throwException(tr("Missing attribute ''version'' on OSM primitive with ID {0}.", Long.toString(current.getUniqueId())));
     
    497493            try {
    498494                current.setChangesetId(Integer.parseInt(v));
    499             } catch(NumberFormatException e) {
     495            } catch (IllegalArgumentException e) {
     496                Main.debug(e.getMessage());
    500497                if (current.isNew()) {
    501498                    // for a new primitive we just log a warning
     
    506503                    throwException(tr("Illegal value for attribute ''changeset''. Got {0}.", v), e);
    507504                }
    508             }
    509             if (current.getChangesetId() <=0) {
     505            } catch (IllegalStateException e) {
     506                // thrown for positive changeset id on new primitives
     507                Main.info(e.getMessage());
     508                current.setChangesetId(0);
     509            }
     510            if (current.getChangesetId() <= 0) {
    510511                if (current.isNew()) {
    511512                    // for a new primitive we just log a warning
Note: See TracChangeset for help on using the changeset viewer.