Ignore:
Timestamp:
2014-10-19T01:27:04+02:00 (10 years ago)
Author:
donvip
Message:

[josm_plugins] fix java 7 warnings / global usage of try-with-resource

Location:
applications/editors/josm/plugins/routes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/routes/.settings/org.eclipse.jdt.ui.prefs

    r19532 r30738  
    1 #Fri Jan 15 16:11:57 CET 2010
    21eclipse.preferences.version=1
    32editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
     
    98sp_cleanup.add_missing_nls_tags=false
    109sp_cleanup.add_missing_override_annotations=false
     10sp_cleanup.add_missing_override_annotations_interface_methods=false
    1111sp_cleanup.add_serial_version_id=false
    1212sp_cleanup.always_use_blocks=true
     
    1414sp_cleanup.always_use_this_for_non_static_field_access=false
    1515sp_cleanup.always_use_this_for_non_static_method_access=false
     16sp_cleanup.convert_functional_interfaces=false
    1617sp_cleanup.convert_to_enhanced_for_loop=false
    17 sp_cleanup.correct_indentation=true
     18sp_cleanup.correct_indentation=false
    1819sp_cleanup.format_source_code=false
    1920sp_cleanup.format_source_code_changes_only=false
     21sp_cleanup.insert_inferred_type_arguments=false
    2022sp_cleanup.make_local_variable_final=false
    2123sp_cleanup.make_parameters_final=false
     
    3335sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
    3436sp_cleanup.remove_private_constructors=true
     37sp_cleanup.remove_redundant_type_arguments=false
    3538sp_cleanup.remove_trailing_whitespaces=true
    3639sp_cleanup.remove_trailing_whitespaces_all=true
     
    4649sp_cleanup.sort_members=false
    4750sp_cleanup.sort_members_all=false
     51sp_cleanup.use_anonymous_class_creation=false
    4852sp_cleanup.use_blocks=false
    4953sp_cleanup.use_blocks_only_for_return_and_throw=false
     54sp_cleanup.use_lambda=false
    5055sp_cleanup.use_parentheses_in_expressions=false
    5156sp_cleanup.use_this_for_non_static_field_access=false
     
    5358sp_cleanup.use_this_for_non_static_method_access=false
    5459sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
     60sp_cleanup.use_type_arguments=false
  • applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/RoutesPlugin.java

    r30737 r30738  
    1919import org.openstreetmap.josm.gui.layer.Layer;
    2020import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    21 
    2221import org.openstreetmap.josm.plugins.Plugin;
    2322import org.openstreetmap.josm.plugins.PluginInformation;
     
    3635        File routesFile = new File(getPluginDir() + File.separator + "routes.xml");
    3736        if (!routesFile.exists()) {
    38             System.out.println("File with route definitions doesn't exist, using default");
     37            Main.info("File with route definitions doesn't exist, using default");
    3938
    4039            try {
    4140                routesFile.getParentFile().mkdir();
    42                 OutputStream outputStream = new FileOutputStream(routesFile);
    43                 InputStream inputStream = Routes.class.getResourceAsStream("routes.xml");
    44 
    45                 byte[] b = new byte[512];
    46                 int read;
    47                 while ((read = inputStream.read(b)) != -1) {
    48                     outputStream.write(b, 0, read);
     41                try (
     42                    OutputStream outputStream = new FileOutputStream(routesFile);
     43                    InputStream inputStream = Routes.class.getResourceAsStream("routes.xml");
     44                ) {
     45                    byte[] b = new byte[512];
     46                    int read;
     47                    while ((read = inputStream.read(b)) != -1) {
     48                        outputStream.write(b, 0, read);
     49                    }
    4950                }
    50 
    51                 outputStream.close();
    52                 inputStream.close();
    53 
    5451            } catch (IOException e) {
    55                 e.printStackTrace();
     52                Main.error(e);
    5653            }
    5754        }
     
    6259            Unmarshaller unmarshaller = context.createUnmarshaller();
    6360            Routes routes = (Routes)unmarshaller.unmarshal(
    64                 new FileInputStream(getPluginDir() + File.separator + "routes.xml"));
     61                    new FileInputStream(getPluginDir() + File.separator + "routes.xml"));
    6562            for (RoutesXMLLayer layer:routes.getLayer()) {
    6663                if (layer.isEnabled()) {
     
    7774
    7875    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    79         // TODO Auto-generated method stub
     76        // Do nothing
    8077    }
    8178
     
    117114        checkLayers();
    118115    }
    119 
    120116}
  • applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/paint/AbstractLinePainter.java

    r23422 r30738  
    1717public abstract class AbstractLinePainter implements PathPainter {
    1818
    19         // Following two method copied from http://blog.persistent.info/2004/03/java-lineline-intersections.html
    20         protected boolean getLineLineIntersection(Line2D.Double l1,
    21                         Line2D.Double l2,
    22                         Point intersection)
    23         {
    24                 double  x1 = l1.getX1(), y1 = l1.getY1(),
    25                 x2 = l1.getX2(), y2 = l1.getY2(),
    26                 x3 = l2.getX1(), y3 = l2.getY1(),
    27                 x4 = l2.getX2(), y4 = l2.getY2();
    28                 double dx1 = x2 - x1;
    29                 double dx2 = x4 - x3;
    30                 double dy1 = y2 - y1;
    31                 double dy2 = y4 - y3;
     19    // Following two method copied from http://blog.persistent.info/2004/03/java-lineline-intersections.html
     20    protected boolean getLineLineIntersection(Line2D.Double l1,
     21            Line2D.Double l2,
     22            Point intersection)
     23    {
     24        double  x1 = l1.getX1(), y1 = l1.getY1(),
     25        x2 = l1.getX2(), y2 = l1.getY2(),
     26        x3 = l2.getX1(), y3 = l2.getY1(),
     27        x4 = l2.getX2(), y4 = l2.getY2();
     28        double dx1 = x2 - x1;
     29        double dx2 = x4 - x3;
     30        double dy1 = y2 - y1;
     31        double dy2 = y4 - y3;
    3232
    33                 double ua = (dx2 * (y1 - y3) - dy2 * (x1 - x3)) / (dy2 * dx1 - dx2 * dy1);
     33        double ua = (dx2 * (y1 - y3) - dy2 * (x1 - x3)) / (dy2 * dx1 - dx2 * dy1);
    3434
    35                 if (Math.abs(dy2 * dx1 - dx2 * dy1) < 0.0001) {
    36                         intersection.x = (int)l1.x2;
    37                         intersection.y = (int)l1.y2;
    38                         return false;
    39                 } else {
    40                         intersection.x = (int)(x1 + ua * (x2 - x1));
    41                         intersection.y = (int)(y1 + ua * (y2 - y1));
    42                 }
     35        if (Math.abs(dy2 * dx1 - dx2 * dy1) < 0.0001) {
     36            intersection.x = (int)l1.x2;
     37            intersection.y = (int)l1.y2;
     38            return false;
     39        } else {
     40            intersection.x = (int)(x1 + ua * (x2 - x1));
     41            intersection.y = (int)(y1 + ua * (y2 - y1));
     42        }
    4343
    44                 return true;
    45         }
     44        return true;
     45    }
    4646
    47         protected double det(double a, double b, double c, double d)
    48         {
    49                 return a * d - b * c;
    50         }
     47    protected double det(double a, double b, double c, double d)
     48    {
     49        return a * d - b * c;
     50    }
    5151
    52         protected Point shiftPoint(Point2D p1, Point2D p2, double shift) {
    53                 double dx = p2.getX() - p1.getX();
    54                 double dy = p2.getY() - p1.getY();
     52    protected Point shiftPoint(Point2D p1, Point2D p2, double shift) {
     53        double dx = p2.getX() - p1.getX();
     54        double dy = p2.getY() - p1.getY();
    5555
    56                 // Perpendicular vector
    57                 double ndx = -dy;
    58                 double ndy = dx;
     56        // Perpendicular vector
     57        double ndx = -dy;
     58        double ndy = dx;
    5959
    60                 // Normalize
    61                 double length = Math.sqrt(ndx * ndx + ndy * ndy);
    62                 ndx = ndx / length;
    63                 ndy = ndy / length;
     60        // Normalize
     61        double length = Math.sqrt(ndx * ndx + ndy * ndy);
     62        ndx = ndx / length;
     63        ndy = ndy / length;
    6464
    65                 return new Point((int)(p1.getX() + shift * ndx), (int)(p1.getY() + shift * ndy));
    66         }
     65        return new Point((int)(p1.getX() + shift * ndx), (int)(p1.getY() + shift * ndy));
     66    }
    6767
    68         protected Line2D.Double shiftLine(Point2D p1, Point2D p2, double shift) {
    69                 double dx = p2.getX() - p1.getX();
    70                 double dy = p2.getY() - p1.getY();
     68    protected Line2D.Double shiftLine(Point2D p1, Point2D p2, double shift) {
     69        double dx = p2.getX() - p1.getX();
     70        double dy = p2.getY() - p1.getY();
    7171
    72                 Point2D point1 = shiftPoint(p1, p2, shift);
    73                 Point2D point2 = new Point2D.Double(point1.getX() + dx, point1.getY() + dy);
     72        Point2D point1 = shiftPoint(p1, p2, shift);
     73        Point2D point2 = new Point2D.Double(point1.getX() + dx, point1.getY() + dy);
    7474
    75                 return new Line2D.Double(
    76                                 point1, point2);
    77         }
     75        return new Line2D.Double(
     76                point1, point2);
     77    }
    7878
    79         protected GeneralPath getPath(Graphics2D g, MapView mapView, List<Node> nodes, double shift) {
     79    protected GeneralPath getPath(Graphics2D g, MapView mapView, List<Node> nodes, double shift) {
    8080
    81                 GeneralPath path = new GeneralPath();
     81        GeneralPath path = new GeneralPath();
    8282
    83                 if (nodes.size() < 2) {
    84                         return path;
    85                 }
     83        if (nodes.size() < 2) {
     84            return path;
     85        }
    8686
    87                 Point p1 = null;
    88                 Point p2 = null;
    89                 Point p3 = null;
    90                 Point lastPoint = null;
     87        Point p1 = null;
     88        Point p2 = null;
     89        Point p3 = null;
     90        Point lastPoint = null;
    9191
    92                 for (Node n: nodes) {
    93                         Point p = mapView.getPoint(n);
     92        for (Node n: nodes) {
     93            Point p = mapView.getPoint(n);
    9494
    95                         if (!p.equals(p3)) {
    96                                 p1 = p2;
    97                                 p2 = p3;
    98                                 p3 = p;
    99                         } else {
    100                                 continue;
    101                         }
     95            if (!p.equals(p3)) {
     96                p1 = p2;
     97                p2 = p3;
     98                p3 = p;
     99            } else {
     100                continue;
     101            }
    102102
    103                         p = null;
    104                         if (p2 != null) {
    105                                 if (p1 == null) {
    106                                         p = shiftPoint(p2, p3, shift);
    107                                 } else {
    108                                         Line2D.Double line1 = shiftLine(p1, p2, shift);
    109                                         Line2D.Double line2 = shiftLine(p2, p3, shift);
     103            p = null;
     104            if (p2 != null) {
     105                if (p1 == null) {
     106                    p = shiftPoint(p2, p3, shift);
     107                } else {
     108                    Line2D.Double line1 = shiftLine(p1, p2, shift);
     109                    Line2D.Double line2 = shiftLine(p2, p3, shift);
    110110
    111                                         /*path.moveTo((float)line1.x1, (float)line1.y1);
     111                    /*path.moveTo((float)line1.x1, (float)line1.y1);
    112112                    path.lineTo((float)line1.x2, (float)line1.y2);
    113113                    path.moveTo((float)line2.x1, (float)line2.y1);
    114114                    path.lineTo((float)line2.x2, (float)line2.y2);*/
    115115
    116                                         p = new Point();
    117                                         if (!getLineLineIntersection(line1, line2, p)) {
    118                                                 p = null;
    119                                         } else {
    120                                                 int dx = p.x - p2.x;
    121                                                 int dy = p.y - p2.y;
    122                                                 int distance = (int)Math.sqrt(dx * dx + dy * dy);
    123                                                 if (distance > 10) {
    124                                                         p.x = p2.x + dx / (distance / 10);
    125                                                         p.y = p2.y + dy / (distance / 10);
    126                                                 }
    127                                         }
    128                                 }
    129                         }
     116                    p = new Point();
     117                    if (!getLineLineIntersection(line1, line2, p)) {
     118                        p = null;
     119                    } else {
     120                        int dx = p.x - p2.x;
     121                        int dy = p.y - p2.y;
     122                        int distance = (int)Math.sqrt(dx * dx + dy * dy);
     123                        if (distance > 10) {
     124                            p.x = p2.x + dx / (distance / 10);
     125                            p.y = p2.y + dy / (distance / 10);
     126                        }
     127                    }
     128                }
     129            }
    130130
    131                         if (p != null && lastPoint != null) {
    132                                 drawSegment(g, mapView, path, lastPoint, p);
    133                         }
    134                         if (p != null) {
    135                                 lastPoint = p;
    136                         }
    137                 }
     131            if (p != null && lastPoint != null) {
     132                drawSegment(g, mapView, path, lastPoint, p);
     133            }
     134            if (p != null) {
     135                lastPoint = p;
     136            }
     137        }
    138138
    139                 if (p2 != null && p3 != null && lastPoint != null) {
    140                         p3 = shiftPoint(p3, p2, -shift);
    141                         drawSegment(g, mapView, path, lastPoint, p3);
    142                 }
     139        if (p2 != null && p3 != null && lastPoint != null) {
     140            p3 = shiftPoint(p3, p2, -shift);
     141            drawSegment(g, mapView, path, lastPoint, p3);
     142        }
    143143
    144                 return path;
    145         }
     144        return path;
     145    }
    146146
    147         private void drawSegment(Graphics2D g, NavigatableComponent nc, GeneralPath path, Point p1, Point p2) {
    148                 boolean drawIt = false;
    149                 if (Main.isOpenjdk) {
    150                         /**
    151                         * Work around openjdk bug. It leads to drawing artefacts when zooming in a lot. (#4289, #4424)
    152                         * (It looks like int overflow when clipping.) We do custom clipping.
    153                         */
    154                         Rectangle bounds = g.getClipBounds();
    155                         bounds.grow(100, 100);                  // avoid arrow heads at the border
    156                         LineClip clip = new LineClip(p1, p2, bounds);
    157                         drawIt = clip.execute();
    158                         if (drawIt) {
    159                                 p1 = clip.getP1();
    160                                 p2 = clip.getP2();
    161                         }
    162                 } else {
    163                         drawIt = isSegmentVisible(nc, p1, p2);
    164                 }
    165                 if (drawIt) {
    166                         /* draw segment line */
    167                         path.moveTo(p1.x, p1.y);
    168                         path.lineTo(p2.x, p2.y);
    169                 }
    170         }
     147    private void drawSegment(Graphics2D g, NavigatableComponent nc, GeneralPath path, Point p1, Point p2) {
     148        boolean drawIt = false;
     149        if (Main.isOpenjdk) {
     150            /**
     151            * Work around openjdk bug. It leads to drawing artefacts when zooming in a lot. (#4289, #4424)
     152            * (It looks like int overflow when clipping.) We do custom clipping.
     153            */
     154            Rectangle bounds = g.getClipBounds();
     155            bounds.grow(100, 100);                  // avoid arrow heads at the border
     156            LineClip clip = new LineClip(p1, p2, bounds);
     157            drawIt = clip.execute();
     158            if (drawIt) {
     159                p1 = clip.getP1();
     160                p2 = clip.getP2();
     161            }
     162        } else {
     163            drawIt = isSegmentVisible(nc, p1, p2);
     164        }
     165        if (drawIt) {
     166            /* draw segment line */
     167            path.moveTo(p1.x, p1.y);
     168            path.lineTo(p2.x, p2.y);
     169        }
     170    }
    171171
    172         private boolean isSegmentVisible(NavigatableComponent nc, Point p1, Point p2) {
    173                 if ((p1.x < 0) && (p2.x < 0)) return false;
    174                 if ((p1.y < 0) && (p2.y < 0)) return false;
    175                 if ((p1.x > nc.getWidth()) && (p2.x > nc.getWidth())) return false;
    176                 if ((p1.y > nc.getHeight()) && (p2.y > nc.getHeight())) return false;
    177                 return true;
    178         }
     172    private boolean isSegmentVisible(NavigatableComponent nc, Point p1, Point p2) {
     173        if ((p1.x < 0) && (p2.x < 0)) return false;
     174        if ((p1.y < 0) && (p2.y < 0)) return false;
     175        if ((p1.x > nc.getWidth()) && (p2.x > nc.getWidth())) return false;
     176        if ((p1.y > nc.getHeight()) && (p2.y > nc.getHeight())) return false;
     177        return true;
     178    }
    179179
    180180
  • applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/xml/routes.xml

    r19345 r30738  
    22<routes xmlns="http://www.example.org/routes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/routes routes.xsd ">
    33<!-- pattern is the same pattern as used in SearchAction -->
    4         <layer name="Czech hiking trails">
    5                 <route color="#FF0000">
    6                         <pattern>
    7                         ((type:relation | type:way) kct_red=*) | (color=red type=route route=hiking network="cz:kct")
    8                         </pattern>
    9                 </route>
    10                 <route color="#FFFF00">
    11                         <pattern>
    12                         ((type:relation | type:way) kct_yellow=*) | (color=yellow type=route route=hiking network="cz:kct")
    13                         </pattern>                     
    14                 </route>
    15                 <route color="#0000FF">
    16                         <pattern>
    17                         ((type:relation | type:way) kct_blue=*) | (color=blue type=route route=hiking network="cz:kct")
    18                         </pattern>
    19                 </route>
    20                 <route color="#00FF00">
    21                         <pattern>
    22                         ((type:relation | type:way) kct_green=*) | (color=green type=route route=hiking network="cz:kct")
    23                         </pattern>             
    24                 </route>
    25         </layer>
    26         <layer name="Cycle routes">
    27                 <route color="#FF00FF">
    28                         <pattern>
    29                         (type:way (ncn=* | (lcn=* | rcn=* ))) | (type:relation type=route route=bicycle)
    30                         </pattern>
    31                 </route>
    32         </layer>
     4    <layer name="Czech hiking trails">
     5        <route color="#FF0000">
     6            <pattern>
     7            ((type:relation | type:way) kct_red=*) | (color=red type=route route=hiking network="cz:kct")
     8            </pattern>
     9        </route>
     10        <route color="#FFFF00">
     11            <pattern>
     12            ((type:relation | type:way) kct_yellow=*) | (color=yellow type=route route=hiking network="cz:kct")
     13            </pattern>           
     14        </route>
     15        <route color="#0000FF">
     16            <pattern>
     17            ((type:relation | type:way) kct_blue=*) | (color=blue type=route route=hiking network="cz:kct")
     18            </pattern>
     19        </route>
     20        <route color="#00FF00">
     21            <pattern>
     22            ((type:relation | type:way) kct_green=*) | (color=green type=route route=hiking network="cz:kct")
     23            </pattern>       
     24        </route>
     25    </layer>
     26    <layer name="Cycle routes">
     27        <route color="#FF00FF">
     28            <pattern>
     29            (type:way (ncn=* | (lcn=* | rcn=* ))) | (type:relation type=route route=bicycle)
     30            </pattern>
     31        </route>
     32    </layer>
    3333</routes>
  • applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/xml/routes.xsd

    r16593 r30738  
    1111
    1212<annotation>
    13         <appinfo>
    14                 <jxb:schemaBindings>   
    15                         <jxb:nameXmlTransform>
    16                                 <jxb:typeName prefix="RoutesXML"/>
    17                         </jxb:nameXmlTransform>
    18                 </jxb:schemaBindings>
    19         </appinfo>
     13    <appinfo>
     14        <jxb:schemaBindings>   
     15            <jxb:nameXmlTransform>
     16                <jxb:typeName prefix="RoutesXML"/>
     17            </jxb:nameXmlTransform>
     18        </jxb:schemaBindings>
     19    </appinfo>
    2020</annotation>
    2121
    2222<element name="routes">
    23         <complexType>
    24                 <sequence>
    25                         <element name="layer" type="tns:layer" minOccurs="0" maxOccurs="unbounded"/>
    26                 </sequence>
    27         </complexType>
     23    <complexType>
     24        <sequence>
     25            <element name="layer" type="tns:layer" minOccurs="0" maxOccurs="unbounded"/>
     26        </sequence>
     27    </complexType>
    2828</element>
    2929
    3030<complexType name="layer">
    31         <sequence>
    32                 <element name="route" type="tns:route" minOccurs="0" maxOccurs="unbounded"/>
    33         </sequence>
    34         <attribute name="name" type="string"/>
    35         <attribute name="enabled" type="boolean" default="true"/>
     31    <sequence>
     32        <element name="route" type="tns:route" minOccurs="0" maxOccurs="unbounded"/>
     33    </sequence>
     34    <attribute name="name" type="string"/>
     35    <attribute name="enabled" type="boolean" default="true"/>
    3636</complexType>
    3737
    3838<complexType name="route">
    39         <sequence>
    40                 <element name="pattern" type="string"/>         
    41         </sequence>
    42         <attribute name="color" type="string"/>
    43         <attribute name="enabled" type="boolean" default="true"/>
     39    <sequence>
     40        <element name="pattern" type="string"/>       
     41    </sequence>
     42    <attribute name="color" type="string"/>
     43    <attribute name="enabled" type="boolean" default="true"/>
    4444</complexType>
    4545
Note: See TracChangeset for help on using the changeset viewer.