Ignore:
Timestamp:
2009-01-01T18:28:53+01:00 (16 years ago)
Author:
stoecker
Message:

removed tab stop usage

Location:
applications/editors/josm/plugins/slippy_map_chooser/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/slippy_map_chooser/src/OsmMapControl.java

    r9623 r12778  
    2323public class OsmMapControl extends MouseAdapter implements MouseMotionListener, MouseListener {
    2424
    25         // start and end point of selection rectangle
    26         private Point iStartSelectionPoint;
    27         private Point iEndSelectionPoint;
     25    // start and end point of selection rectangle
     26    private Point iStartSelectionPoint;
     27    private Point iEndSelectionPoint;
    2828
    29         // the SlippyMapChooserComponent
    30         private final SlippyMapChooser iSlippyMapChooser;
     29    // the SlippyMapChooserComponent
     30    private final SlippyMapChooser iSlippyMapChooser;
    3131
    32         private SizeButton iSizeButton = null;
    33         private SourceButton iSourceButton = null;
     32    private SizeButton iSizeButton = null;
     33    private SourceButton iSourceButton = null;
    3434
    35         /**
    36         * Create a new OsmMapControl
    37         */
    38         public OsmMapControl(SlippyMapChooser navComp, JPanel contentPane, SizeButton sizeButton, SourceButton sourceButton) {
    39                 this.iSlippyMapChooser = navComp;
    40                 iSlippyMapChooser.addMouseListener(this);
    41                 iSlippyMapChooser.addMouseMotionListener(this);
     35    /**
     36    * Create a new OsmMapControl
     37    */
     38    public OsmMapControl(SlippyMapChooser navComp, JPanel contentPane, SizeButton sizeButton, SourceButton sourceButton) {
     39        this.iSlippyMapChooser = navComp;
     40        iSlippyMapChooser.addMouseListener(this);
     41        iSlippyMapChooser.addMouseMotionListener(this);
    4242
    43                 String[] n = { ",", ".", "up", "right", "down", "left" };
    44                 int[] k =
    45                                 { KeyEvent.VK_COMMA, KeyEvent.VK_PERIOD, KeyEvent.VK_UP, KeyEvent.VK_RIGHT,
    46                                                 KeyEvent.VK_DOWN, KeyEvent.VK_LEFT };
     43        String[] n = { ",", ".", "up", "right", "down", "left" };
     44        int[] k =
     45                { KeyEvent.VK_COMMA, KeyEvent.VK_PERIOD, KeyEvent.VK_UP, KeyEvent.VK_RIGHT,
     46                        KeyEvent.VK_DOWN, KeyEvent.VK_LEFT };
    4747
    48                 if (contentPane != null) {
    49                         for (int i = 0; i < n.length; ++i) {
    50                                 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
    51                                                 KeyStroke.getKeyStroke(k[i], KeyEvent.CTRL_DOWN_MASK),
    52                                                 "MapMover.Zoomer." + n[i]);
    53                         }
    54                 }
    55                 iSizeButton = sizeButton;
    56                 iSourceButton = sourceButton;
    57         }
     48        if (contentPane != null) {
     49            for (int i = 0; i < n.length; ++i) {
     50                contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
     51                        KeyStroke.getKeyStroke(k[i], KeyEvent.CTRL_DOWN_MASK),
     52                        "MapMover.Zoomer." + n[i]);
     53            }
     54        }
     55        iSizeButton = sizeButton;
     56        iSourceButton = sourceButton;
     57    }
    5858
    59         /**
    60         * Start drawing the selection rectangle if it was the 1st button (left
    61         * button)
    62         */
    63         @Override
    64         public void mousePressed(MouseEvent e) {
    65                 if (e.getButton() == MouseEvent.BUTTON1) {
    66                         if (!iSizeButton.hit(e.getPoint())) {
    67                                 iStartSelectionPoint = e.getPoint();
    68                                 iEndSelectionPoint = e.getPoint();
    69                         }
    70                 }
    71                
    72         }
     59    /**
     60    * Start drawing the selection rectangle if it was the 1st button (left
     61    * button)
     62    */
     63    @Override
     64    public void mousePressed(MouseEvent e) {
     65        if (e.getButton() == MouseEvent.BUTTON1) {
     66            if (!iSizeButton.hit(e.getPoint())) {
     67                iStartSelectionPoint = e.getPoint();
     68                iEndSelectionPoint = e.getPoint();
     69            }
     70        }
     71       
     72    }
    7373
    74         public void mouseDragged(MouseEvent e) {               
    75                 if((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK){
    76                         if (iStartSelectionPoint != null) {                             
    77                                 iEndSelectionPoint = e.getPoint();
    78                                 iSlippyMapChooser.setSelection(iStartSelectionPoint, iEndSelectionPoint);
    79                         }
    80                 }
    81         }
     74    public void mouseDragged(MouseEvent e) {       
     75        if((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK){
     76            if (iStartSelectionPoint != null) {             
     77                iEndSelectionPoint = e.getPoint();
     78                iSlippyMapChooser.setSelection(iStartSelectionPoint, iEndSelectionPoint);
     79            }
     80        }
     81    }
    8282
    83         /**
    84         * When dragging the map change the cursor back to it's pre-move cursor. If
    85         * a double-click occurs center and zoom the map on the clicked location.
    86         */
    87         @Override
    88         public void mouseReleased(MouseEvent e) {
    89                 if (e.getButton() == MouseEvent.BUTTON1) {
    90                        
    91                         int sourceButton = iSourceButton.hit(e.getPoint());
    92                        
    93                         if (iSizeButton.hit(e.getPoint())) {
    94                                 iSizeButton.toggle();
    95                                 iSlippyMapChooser.resizeSlippyMap();
    96                         }
    97                         else if(sourceButton == SourceButton.HIDE_OR_SHOW) {
    98                                 iSourceButton.toggle();
    99                                 iSlippyMapChooser.repaint();
    100                                
    101                         }else if(sourceButton == SourceButton.MAPNIK || sourceButton == SourceButton.OSMARENDER) {
    102                                 iSlippyMapChooser.toggleMapSource(sourceButton);
    103                         }
    104                         else {
    105                                 if (e.getClickCount() == 1) {
    106                                         iSlippyMapChooser.setSelection(iStartSelectionPoint, e.getPoint());
     83    /**
     84    * When dragging the map change the cursor back to it's pre-move cursor. If
     85    * a double-click occurs center and zoom the map on the clicked location.
     86    */
     87    @Override
     88    public void mouseReleased(MouseEvent e) {
     89        if (e.getButton() == MouseEvent.BUTTON1) {
     90           
     91            int sourceButton = iSourceButton.hit(e.getPoint());
     92           
     93            if (iSizeButton.hit(e.getPoint())) {
     94                iSizeButton.toggle();
     95                iSlippyMapChooser.resizeSlippyMap();
     96            }
     97            else if(sourceButton == SourceButton.HIDE_OR_SHOW) {
     98                iSourceButton.toggle();
     99                iSlippyMapChooser.repaint();
     100               
     101            }else if(sourceButton == SourceButton.MAPNIK || sourceButton == SourceButton.OSMARENDER) {
     102                iSlippyMapChooser.toggleMapSource(sourceButton);
     103            }
     104            else {
     105                if (e.getClickCount() == 1) {
     106                    iSlippyMapChooser.setSelection(iStartSelectionPoint, e.getPoint());
    107107
    108                                         // reset the selections start and end
    109                                         iEndSelectionPoint = null;
    110                                         iStartSelectionPoint = null;
    111                                 }
    112                         }
    113                        
    114                 }
    115         }
     108                    // reset the selections start and end
     109                    iEndSelectionPoint = null;
     110                    iStartSelectionPoint = null;
     111                }
     112            }
     113           
     114        }
     115    }
    116116
    117         public void mouseMoved(MouseEvent e) {
    118         }
     117    public void mouseMoved(MouseEvent e) {
     118    }
    119119
    120120}
  • applications/editors/josm/plugins/slippy_map_chooser/src/SizeButton.java

    r7199 r12778  
    1515 */
    1616public class SizeButton{
    17        
    18         private int x = 0;
    19         private int y = 0;
    20        
    21         private ImageIcon enlargeImage;
    22         private ImageIcon shrinkImage;
    23         private boolean isEnlarged = false;
    24        
    25        
    26         public SizeButton(){
    27                 enlargeImage = ImageProvider.get("", "view-fullscreen.png");
    28                 shrinkImage = ImageProvider.get("", "view-fullscreen-revert.png");             
    29         }
    30        
    31         public void paint(Graphics g){
    32                 if(isEnlarged){
    33                         if(shrinkImage != null)
    34                                 g.drawImage(shrinkImage.getImage(),x,y, null);
    35                 }else{
    36                         if(enlargeImage != null)
    37                                 g.drawImage(enlargeImage.getImage(),x,y, null);
    38                 }
    39         }
    40        
    41         public void toggle(){
    42                 isEnlarged = !isEnlarged;
    43         }
    44        
    45         public boolean hit(Point point){
    46                 if(x < point.x && point.x < x + enlargeImage.getIconWidth()){
    47                         if(y < point.y && point.y < y + enlargeImage.getIconHeight() ){                         
    48                                 return true;
    49                         }
    50                 }
    51                 return false;
    52         }
     17   
     18    private int x = 0;
     19    private int y = 0;
     20   
     21    private ImageIcon enlargeImage;
     22    private ImageIcon shrinkImage;
     23    private boolean isEnlarged = false;
     24   
     25   
     26    public SizeButton(){
     27        enlargeImage = ImageProvider.get("", "view-fullscreen.png");
     28        shrinkImage = ImageProvider.get("", "view-fullscreen-revert.png");     
     29    }
     30   
     31    public void paint(Graphics g){
     32        if(isEnlarged){
     33            if(shrinkImage != null)
     34                g.drawImage(shrinkImage.getImage(),x,y, null);
     35        }else{
     36            if(enlargeImage != null)
     37                g.drawImage(enlargeImage.getImage(),x,y, null);
     38        }
     39    }
     40   
     41    public void toggle(){
     42        isEnlarged = !isEnlarged;
     43    }
     44   
     45    public boolean hit(Point point){
     46        if(x < point.x && point.x < x + enlargeImage.getIconWidth()){
     47            if(y < point.y && point.y < y + enlargeImage.getIconHeight() ){             
     48                return true;
     49            }
     50        }
     51        return false;
     52    }
    5353
    5454}
  • applications/editors/josm/plugins/slippy_map_chooser/src/SlippyMapChooser.java

    r10310 r12778  
    4040public class SlippyMapChooser extends JMapViewer implements DownloadSelection, ComponentListener {
    4141
    42         private DownloadDialog iGui;
    43 
    44         // upper left and lower right corners of the selection rectangle (x/y on
    45         // ZOOM_MAX)
    46         Point iSelectionRectStart;
    47         Point iSelectionRectEnd;
    48 
    49         private SizeButton iSizeButton = new SizeButton();
    50         private SourceButton iSourceButton = new SourceButton();
    51 
    52         // standard dimension
    53         private Dimension iDownloadDialogDimension;
    54         // screen size
    55         private Dimension iScreenSize;
    56 
    57         private TileSource[] sources = { new OsmTileSource.Mapnik(), new OsmTileSource.TilesAtHome() };
    58         TileLoader cachedLoader;
    59         TileLoader uncachedLoader;
    60         JPanel slipyyMapTabPanel;
    61         boolean firstShown = true;
    62 
    63         /**
    64         * Create the chooser component.
    65         */
    66         public SlippyMapChooser() {
    67                 super();
    68                 cachedLoader = new OsmFileCacheTileLoader(this);
    69                 uncachedLoader = new OsmTileLoader(this);
    70                 setZoomContolsVisible(false);
    71                 setMapMarkerVisible(false);
    72                 setMinimumSize(new Dimension(350, 350 / 2));
    73                 setFileCacheEnabled(SlippyMapChooserPlugin.ENABLE_FILE_CACHE);
    74                 setMaxTilesInmemory(SlippyMapChooserPlugin.MAX_TILES_IN_MEMORY);
    75                 addComponentListener(this);
    76         }
    77 
    78         public void setMaxTilesInmemory(int tiles) {
    79                 ((MemoryTileCache) getTileCache()).setCacheSize(tiles);
    80         }
    81 
    82         public void setFileCacheEnabled(boolean enabled) {
    83                 if (enabled)
    84                         setTileLoader(cachedLoader);
    85                 else
    86                         setTileLoader(uncachedLoader);
    87         }
    88 
    89         public void addGui(final DownloadDialog gui) {
    90                 iGui = gui;
    91                 slipyyMapTabPanel = new JPanel();
    92                 slipyyMapTabPanel.setLayout(new BorderLayout());
    93                 slipyyMapTabPanel.add(this, BorderLayout.CENTER);
    94                 slipyyMapTabPanel.add(new JLabel((tr("Zoom: Mousewheel or double click.   "
    95                                 + "Move map: Hold right mousebutton and move mouse.   Select: Click."))),
    96                                 BorderLayout.SOUTH);
    97                 iGui.tabpane.add(slipyyMapTabPanel, tr("Slippy map"));
    98                 iGui.tabpane.addComponentListener(this);
    99                 new OsmMapControl(this, slipyyMapTabPanel, iSizeButton, iSourceButton);
    100         }
    101 
    102         protected Point getTopLeftCoordinates() {
    103                 return new Point(center.x - (getWidth() / 2), center.y - (getHeight() / 2));
    104         }
    105 
    106         /**
    107         * Draw the map.
    108         */
    109         @Override
    110         public void paint(Graphics g) {
    111                 try {
    112                         super.paint(g);
    113 
    114                         // draw selection rectangle
    115                         if (iSelectionRectStart != null && iSelectionRectEnd != null) {
    116 
    117                                 int zoomDiff = MAX_ZOOM - zoom;
    118                                 Point tlc = getTopLeftCoordinates();
    119                                 int x_min = (iSelectionRectStart.x >> zoomDiff) - tlc.x;
    120                                 int y_min = (iSelectionRectStart.y >> zoomDiff) - tlc.y;
    121                                 int x_max = (iSelectionRectEnd.x >> zoomDiff) - tlc.x;
    122                                 int y_max = (iSelectionRectEnd.y >> zoomDiff) - tlc.y;
    123 
    124                                 int w = x_max - x_min;
    125                                 int h = y_max - y_min;
    126                                 g.setColor(new Color(0.9f, 0.7f, 0.7f, 0.6f));
    127                                 g.fillRect(x_min, y_min, w, h);
    128 
    129                                 g.setColor(Color.BLACK);
    130                                 g.drawRect(x_min, y_min, w, h);
    131 
    132                         }
    133 
    134                         iSizeButton.paint(g);
    135                         iSourceButton.paint(g);
    136                 } catch (Exception e) {
    137                         e.printStackTrace();
    138                 }
    139         }
    140 
    141         public void boundingBoxChanged(DownloadDialog gui) {
    142 
    143                 // test if a bounding box has been set set
    144                 if (gui.minlat == 0.0 && gui.minlon == 0.0 && gui.maxlat == 0.0 && gui.maxlon == 0.0)
    145                         return;
    146 
    147                 int y1 = OsmMercator.LatToY(gui.minlat, MAX_ZOOM);
    148                 int y2 = OsmMercator.LatToY(gui.maxlat, MAX_ZOOM);
    149                 int x1 = OsmMercator.LonToX(gui.minlon, MAX_ZOOM);
    150                 int x2 = OsmMercator.LonToX(gui.maxlon, MAX_ZOOM);
    151 
    152                 iSelectionRectStart = new Point(Math.min(x1, x2), Math.min(y1, y2));
    153                 iSelectionRectEnd = new Point(Math.max(x1, x2), Math.max(y1, y2));
    154 
    155                 // calc the screen coordinates for the new selection rectangle
    156                 MapMarkerDot xmin_ymin = new MapMarkerDot(gui.minlat, gui.minlon);
    157                 MapMarkerDot xmax_ymax = new MapMarkerDot(gui.maxlat, gui.maxlon);
    158 
    159                 Vector<MapMarker> marker = new Vector<MapMarker>(2);
    160                 marker.add(xmin_ymin);
    161                 marker.add(xmax_ymax);
    162                 setMapMarkerList(marker);
    163                 setDisplayToFitMapMarkers();
    164                 zoomOut();
    165         }
    166 
    167         /**
    168         * Callback for the OsmMapControl. (Re-)Sets the start and end point of the
    169         * selection rectangle.
    170         *
    171         * @param aStart
    172         * @param aEnd
    173         */
    174         public void setSelection(Point aStart, Point aEnd) {
    175                 if (aStart == null || aEnd == null)
    176                         return;
    177                 Point p_max = new Point(Math.max(aEnd.x, aStart.x), Math.max(aEnd.y, aStart.y));
    178                 Point p_min = new Point(Math.min(aEnd.x, aStart.x), Math.min(aEnd.y, aStart.y));
    179 
    180                 Point tlc = getTopLeftCoordinates();
    181                 int zoomDiff = MAX_ZOOM - zoom;
    182                 Point pEnd = new Point(p_max.x + tlc.x, p_max.y + tlc.y);
    183                 Point pStart = new Point(p_min.x + tlc.x, p_min.y + tlc.y);
    184 
    185                 pEnd.x <<= zoomDiff;
    186                 pEnd.y <<= zoomDiff;
    187                 pStart.x <<= zoomDiff;
    188                 pStart.y <<= zoomDiff;
    189 
    190                 iSelectionRectStart = pStart;
    191                 iSelectionRectEnd = pEnd;
    192 
    193                 Point2D.Double l1 = getPosition(p_max);
    194                 Point2D.Double l2 = getPosition(p_min);
    195                 iGui.minlat = Math.min(l2.x, l1.x);
    196                 iGui.minlon = Math.min(l1.y, l2.y);
    197                 iGui.maxlat = Math.max(l2.x, l1.x);
    198                 iGui.maxlon = Math.max(l1.y, l2.y);
    199 
    200                 iGui.boundingBoxChanged(this);
    201                 repaint();
    202         }
    203 
    204         /**
    205         * Performs resizing of the DownloadDialog in order to enlarge or shrink the
    206         * map.
    207         */
    208         public void resizeSlippyMap() {
    209                 if (iScreenSize == null) {
    210                         Component c =
    211                                         iGui.getParent().getParent().getParent().getParent().getParent().getParent()
    212                                                         .getParent().getParent().getParent();
    213                         // remember the initial set screen dimensions
    214                         iDownloadDialogDimension = c.getSize();
    215                         // retrive the size of the display
    216                         iScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
    217                 }
    218 
    219                 // resize
    220                 Component co =
    221                                 iGui.getParent().getParent().getParent().getParent().getParent().getParent()
    222                                                 .getParent().getParent().getParent();
    223                 Dimension currentDimension = co.getSize();
    224 
    225                 // enlarge
    226                 if (currentDimension.equals(iDownloadDialogDimension)) {
    227                         // make the each dimension 90% of the absolute display size and
    228                         // center the DownloadDialog
    229                         int w = iScreenSize.width * 90 / 100;
    230                         int h = iScreenSize.height * 90 / 100;
    231                         co.setBounds((iScreenSize.width - w) / 2, (iScreenSize.height - h) / 2, w, h);
    232 
    233                 }
    234                 // shrink
    235                 else {
    236                         // set the size back to the initial dimensions and center the
    237                         // DownloadDialog
    238                         int w = iDownloadDialogDimension.width;
    239                         int h = iDownloadDialogDimension.height;
    240                         co.setBounds((iScreenSize.width - w) / 2, (iScreenSize.height - h) / 2, w, h);
    241 
    242                 }
    243 
    244                 repaint();
    245         }
    246 
    247         public void toggleMapSource(int mapSource) {
    248                 this.tileCache = new MemoryTileCache();
    249                 if (mapSource == SourceButton.MAPNIK) {
    250                         this.setTileSource(sources[0]);
    251                 } else {
    252                         this.setTileSource(sources[1]);
    253                 }
    254         }
    255 
    256         public void componentHidden(ComponentEvent e) {
    257         }
    258 
    259         public void componentMoved(ComponentEvent e) {
    260         }
    261 
    262         public void componentShown(ComponentEvent e) {
    263         }
    264 
    265         public void componentResized(ComponentEvent e) {
    266                 if (!this.equals(e.getSource()) || getHeight() == 0 || getWidth() == 0)
    267                         return;
    268                 firstShown = false;
    269                 // The bounding box has to be set after SlippyMapChooser's size has been
    270                 // finally set - otherwise the zoom level will be totally wrong (too wide)
    271                 boundingBoxChanged(iGui);
    272         }
     42    private DownloadDialog iGui;
     43
     44    // upper left and lower right corners of the selection rectangle (x/y on
     45    // ZOOM_MAX)
     46    Point iSelectionRectStart;
     47    Point iSelectionRectEnd;
     48
     49    private SizeButton iSizeButton = new SizeButton();
     50    private SourceButton iSourceButton = new SourceButton();
     51
     52    // standard dimension
     53    private Dimension iDownloadDialogDimension;
     54    // screen size
     55    private Dimension iScreenSize;
     56
     57    private TileSource[] sources = { new OsmTileSource.Mapnik(), new OsmTileSource.TilesAtHome() };
     58    TileLoader cachedLoader;
     59    TileLoader uncachedLoader;
     60    JPanel slipyyMapTabPanel;
     61    boolean firstShown = true;
     62
     63    /**
     64    * Create the chooser component.
     65    */
     66    public SlippyMapChooser() {
     67        super();
     68        cachedLoader = new OsmFileCacheTileLoader(this);
     69        uncachedLoader = new OsmTileLoader(this);
     70        setZoomContolsVisible(false);
     71        setMapMarkerVisible(false);
     72        setMinimumSize(new Dimension(350, 350 / 2));
     73        setFileCacheEnabled(SlippyMapChooserPlugin.ENABLE_FILE_CACHE);
     74        setMaxTilesInmemory(SlippyMapChooserPlugin.MAX_TILES_IN_MEMORY);
     75        addComponentListener(this);
     76    }
     77
     78    public void setMaxTilesInmemory(int tiles) {
     79        ((MemoryTileCache) getTileCache()).setCacheSize(tiles);
     80    }
     81
     82    public void setFileCacheEnabled(boolean enabled) {
     83        if (enabled)
     84            setTileLoader(cachedLoader);
     85        else
     86            setTileLoader(uncachedLoader);
     87    }
     88
     89    public void addGui(final DownloadDialog gui) {
     90        iGui = gui;
     91        slipyyMapTabPanel = new JPanel();
     92        slipyyMapTabPanel.setLayout(new BorderLayout());
     93        slipyyMapTabPanel.add(this, BorderLayout.CENTER);
     94        slipyyMapTabPanel.add(new JLabel((tr("Zoom: Mousewheel or double click.   "
     95                + "Move map: Hold right mousebutton and move mouse.   Select: Click."))),
     96                BorderLayout.SOUTH);
     97        iGui.tabpane.add(slipyyMapTabPanel, tr("Slippy map"));
     98        iGui.tabpane.addComponentListener(this);
     99        new OsmMapControl(this, slipyyMapTabPanel, iSizeButton, iSourceButton);
     100    }
     101
     102    protected Point getTopLeftCoordinates() {
     103        return new Point(center.x - (getWidth() / 2), center.y - (getHeight() / 2));
     104    }
     105
     106    /**
     107    * Draw the map.
     108    */
     109    @Override
     110    public void paint(Graphics g) {
     111        try {
     112            super.paint(g);
     113
     114            // draw selection rectangle
     115            if (iSelectionRectStart != null && iSelectionRectEnd != null) {
     116
     117                int zoomDiff = MAX_ZOOM - zoom;
     118                Point tlc = getTopLeftCoordinates();
     119                int x_min = (iSelectionRectStart.x >> zoomDiff) - tlc.x;
     120                int y_min = (iSelectionRectStart.y >> zoomDiff) - tlc.y;
     121                int x_max = (iSelectionRectEnd.x >> zoomDiff) - tlc.x;
     122                int y_max = (iSelectionRectEnd.y >> zoomDiff) - tlc.y;
     123
     124                int w = x_max - x_min;
     125                int h = y_max - y_min;
     126                g.setColor(new Color(0.9f, 0.7f, 0.7f, 0.6f));
     127                g.fillRect(x_min, y_min, w, h);
     128
     129                g.setColor(Color.BLACK);
     130                g.drawRect(x_min, y_min, w, h);
     131
     132            }
     133
     134            iSizeButton.paint(g);
     135            iSourceButton.paint(g);
     136        } catch (Exception e) {
     137            e.printStackTrace();
     138        }
     139    }
     140
     141    public void boundingBoxChanged(DownloadDialog gui) {
     142
     143        // test if a bounding box has been set set
     144        if (gui.minlat == 0.0 && gui.minlon == 0.0 && gui.maxlat == 0.0 && gui.maxlon == 0.0)
     145            return;
     146
     147        int y1 = OsmMercator.LatToY(gui.minlat, MAX_ZOOM);
     148        int y2 = OsmMercator.LatToY(gui.maxlat, MAX_ZOOM);
     149        int x1 = OsmMercator.LonToX(gui.minlon, MAX_ZOOM);
     150        int x2 = OsmMercator.LonToX(gui.maxlon, MAX_ZOOM);
     151
     152        iSelectionRectStart = new Point(Math.min(x1, x2), Math.min(y1, y2));
     153        iSelectionRectEnd = new Point(Math.max(x1, x2), Math.max(y1, y2));
     154
     155        // calc the screen coordinates for the new selection rectangle
     156        MapMarkerDot xmin_ymin = new MapMarkerDot(gui.minlat, gui.minlon);
     157        MapMarkerDot xmax_ymax = new MapMarkerDot(gui.maxlat, gui.maxlon);
     158
     159        Vector<MapMarker> marker = new Vector<MapMarker>(2);
     160        marker.add(xmin_ymin);
     161        marker.add(xmax_ymax);
     162        setMapMarkerList(marker);
     163        setDisplayToFitMapMarkers();
     164        zoomOut();
     165    }
     166
     167    /**
     168    * Callback for the OsmMapControl. (Re-)Sets the start and end point of the
     169    * selection rectangle.
     170    *
     171    * @param aStart
     172    * @param aEnd
     173    */
     174    public void setSelection(Point aStart, Point aEnd) {
     175        if (aStart == null || aEnd == null)
     176            return;
     177        Point p_max = new Point(Math.max(aEnd.x, aStart.x), Math.max(aEnd.y, aStart.y));
     178        Point p_min = new Point(Math.min(aEnd.x, aStart.x), Math.min(aEnd.y, aStart.y));
     179
     180        Point tlc = getTopLeftCoordinates();
     181        int zoomDiff = MAX_ZOOM - zoom;
     182        Point pEnd = new Point(p_max.x + tlc.x, p_max.y + tlc.y);
     183        Point pStart = new Point(p_min.x + tlc.x, p_min.y + tlc.y);
     184
     185        pEnd.x <<= zoomDiff;
     186        pEnd.y <<= zoomDiff;
     187        pStart.x <<= zoomDiff;
     188        pStart.y <<= zoomDiff;
     189
     190        iSelectionRectStart = pStart;
     191        iSelectionRectEnd = pEnd;
     192
     193        Point2D.Double l1 = getPosition(p_max);
     194        Point2D.Double l2 = getPosition(p_min);
     195        iGui.minlat = Math.min(l2.x, l1.x);
     196        iGui.minlon = Math.min(l1.y, l2.y);
     197        iGui.maxlat = Math.max(l2.x, l1.x);
     198        iGui.maxlon = Math.max(l1.y, l2.y);
     199
     200        iGui.boundingBoxChanged(this);
     201        repaint();
     202    }
     203
     204    /**
     205    * Performs resizing of the DownloadDialog in order to enlarge or shrink the
     206    * map.
     207    */
     208    public void resizeSlippyMap() {
     209        if (iScreenSize == null) {
     210            Component c =
     211                    iGui.getParent().getParent().getParent().getParent().getParent().getParent()
     212                            .getParent().getParent().getParent();
     213            // remember the initial set screen dimensions
     214            iDownloadDialogDimension = c.getSize();
     215            // retrive the size of the display
     216            iScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
     217        }
     218
     219        // resize
     220        Component co =
     221                iGui.getParent().getParent().getParent().getParent().getParent().getParent()
     222                        .getParent().getParent().getParent();
     223        Dimension currentDimension = co.getSize();
     224
     225        // enlarge
     226        if (currentDimension.equals(iDownloadDialogDimension)) {
     227            // make the each dimension 90% of the absolute display size and
     228            // center the DownloadDialog
     229            int w = iScreenSize.width * 90 / 100;
     230            int h = iScreenSize.height * 90 / 100;
     231            co.setBounds((iScreenSize.width - w) / 2, (iScreenSize.height - h) / 2, w, h);
     232
     233        }
     234        // shrink
     235        else {
     236            // set the size back to the initial dimensions and center the
     237            // DownloadDialog
     238            int w = iDownloadDialogDimension.width;
     239            int h = iDownloadDialogDimension.height;
     240            co.setBounds((iScreenSize.width - w) / 2, (iScreenSize.height - h) / 2, w, h);
     241
     242        }
     243
     244        repaint();
     245    }
     246
     247    public void toggleMapSource(int mapSource) {
     248        this.tileCache = new MemoryTileCache();
     249        if (mapSource == SourceButton.MAPNIK) {
     250            this.setTileSource(sources[0]);
     251        } else {
     252            this.setTileSource(sources[1]);
     253        }
     254    }
     255
     256    public void componentHidden(ComponentEvent e) {
     257    }
     258
     259    public void componentMoved(ComponentEvent e) {
     260    }
     261
     262    public void componentShown(ComponentEvent e) {
     263    }
     264
     265    public void componentResized(ComponentEvent e) {
     266        if (!this.equals(e.getSource()) || getHeight() == 0 || getWidth() == 0)
     267            return;
     268        firstShown = false;
     269        // The bounding box has to be set after SlippyMapChooser's size has been
     270        // finally set - otherwise the zoom level will be totally wrong (too wide)
     271        boundingBoxChanged(iGui);
     272    }
    273273
    274274}
  • applications/editors/josm/plugins/slippy_map_chooser/src/SlippyMapChooserPlugin.java

    r9851 r12778  
    1414public class SlippyMapChooserPlugin extends Plugin implements PreferenceChangedListener {
    1515
    16         static String iPluginFolder = "";
     16    static String iPluginFolder = "";
    1717
    18         private static final String KEY_MAX_TILES_IN_MEMORY = "slippy_map_chooser.max_tiles";
    19         private static final String KEY_ENABLE_FILE_CACHE = "slippy_map_chooser.file_cache";
     18    private static final String KEY_MAX_TILES_IN_MEMORY = "slippy_map_chooser.max_tiles";
     19    private static final String KEY_ENABLE_FILE_CACHE = "slippy_map_chooser.file_cache";
    2020
    21         static int MAX_TILES_IN_MEMORY = 200;
    22         static boolean ENABLE_FILE_CACHE = true;
     21    static int MAX_TILES_IN_MEMORY = 200;
     22    static boolean ENABLE_FILE_CACHE = true;
    2323
    24         public SlippyMapChooserPlugin() {
    25                 // create the plugin folder
    26                 // iPluginFolder = getPluginDir();
    27                 // File pluginFolder = new File(iPluginFolder);
    28                 // if(!pluginFolder.exists())
    29                 // pluginFolder.mkdir();
    30                 //             
    31                 // //init the logger
    32                 // Logger.setLogFile(iPluginFolder+"\\slippy_map_chooser.log");
     24    public SlippyMapChooserPlugin() {
     25        // create the plugin folder
     26        // iPluginFolder = getPluginDir();
     27        // File pluginFolder = new File(iPluginFolder);
     28        // if(!pluginFolder.exists())
     29        // pluginFolder.mkdir();
     30        //     
     31        // //init the logger
     32        // Logger.setLogFile(iPluginFolder+"\\slippy_map_chooser.log");
    3333
    34                 // Add this plugin to the preference changed listener list
    35                 Main.pref.listener.add(this);
     34        // Add this plugin to the preference changed listener list
     35        Main.pref.listener.add(this);
    3636
    37                 // load prefs
    38                 String maxTiles = Main.pref.get(KEY_MAX_TILES_IN_MEMORY);
    39                 if (!maxTiles.equals("")) {
    40                         preferenceChanged(KEY_MAX_TILES_IN_MEMORY, maxTiles);
    41                 } else {
    42                         Main.pref.put(KEY_MAX_TILES_IN_MEMORY, Integer.toString(MAX_TILES_IN_MEMORY));
    43                 }
    44                 String enableFileCache = Main.pref.get(KEY_ENABLE_FILE_CACHE);
    45                 if (!enableFileCache.equals("")) {
    46                         preferenceChanged(KEY_ENABLE_FILE_CACHE, enableFileCache);
    47                 } else {
    48                         Main.pref.put(KEY_ENABLE_FILE_CACHE, Boolean.toString(ENABLE_FILE_CACHE));
    49                 }
    50         }
     37        // load prefs
     38        String maxTiles = Main.pref.get(KEY_MAX_TILES_IN_MEMORY);
     39        if (!maxTiles.equals("")) {
     40            preferenceChanged(KEY_MAX_TILES_IN_MEMORY, maxTiles);
     41        } else {
     42            Main.pref.put(KEY_MAX_TILES_IN_MEMORY, Integer.toString(MAX_TILES_IN_MEMORY));
     43        }
     44        String enableFileCache = Main.pref.get(KEY_ENABLE_FILE_CACHE);
     45        if (!enableFileCache.equals("")) {
     46            preferenceChanged(KEY_ENABLE_FILE_CACHE, enableFileCache);
     47        } else {
     48            Main.pref.put(KEY_ENABLE_FILE_CACHE, Boolean.toString(ENABLE_FILE_CACHE));
     49        }
     50    }
    5151
    52         public void addDownloadSelection(List<DownloadSelection> list) {
    53                 list.add(new SlippyMapChooser());
    54         }
     52    public void addDownloadSelection(List<DownloadSelection> list) {
     53        list.add(new SlippyMapChooser());
     54    }
    5555
    56         public void preferenceChanged(String key, String newValue) {
    57                 if (KEY_MAX_TILES_IN_MEMORY.equals(key)) {
    58                         try {
    59                                 MAX_TILES_IN_MEMORY = Integer.parseInt(newValue);
    60                         } catch (Exception e) {
    61                                 MAX_TILES_IN_MEMORY = 1000;
    62                         }
    63                 } else if (KEY_ENABLE_FILE_CACHE.equals(key)) {
    64                         try {
    65                                 ENABLE_FILE_CACHE = Boolean.parseBoolean(newValue);
    66                         } catch (Exception e) {
    67                                 MAX_TILES_IN_MEMORY = 1000;
    68                         }
    69                 }
    70         }
     56    public void preferenceChanged(String key, String newValue) {
     57        if (KEY_MAX_TILES_IN_MEMORY.equals(key)) {
     58            try {
     59                MAX_TILES_IN_MEMORY = Integer.parseInt(newValue);
     60            } catch (Exception e) {
     61                MAX_TILES_IN_MEMORY = 1000;
     62            }
     63        } else if (KEY_ENABLE_FILE_CACHE.equals(key)) {
     64            try {
     65                ENABLE_FILE_CACHE = Boolean.parseBoolean(newValue);
     66            } catch (Exception e) {
     67                MAX_TILES_IN_MEMORY = 1000;
     68            }
     69        }
     70    }
    7171
    7272}
  • applications/editors/josm/plugins/slippy_map_chooser/src/SourceButton.java

    r9819 r12778  
    88public class SourceButton {
    99
    10         private int x = 0;
    11         private int y = 30;
     10    private int x = 0;
     11    private int y = 30;
    1212
    13         private ImageIcon enlargeImage;
    14         private ImageIcon shrinkImage;
    15         private ImageIcon imageMapnik;
    16         private ImageIcon imageOsmarender;
     13    private ImageIcon enlargeImage;
     14    private ImageIcon shrinkImage;
     15    private ImageIcon imageMapnik;
     16    private ImageIcon imageOsmarender;
    1717
    18         private boolean isEnlarged = false;
     18    private boolean isEnlarged = false;
    1919
    20         private boolean isMapnik = true;
     20    private boolean isMapnik = true;
    2121
    22         public static final int HIDE_OR_SHOW = 1;
    23         public static final int MAPNIK = 2;
    24         public static final int OSMARENDER = 3;
     22    public static final int HIDE_OR_SHOW = 1;
     23    public static final int MAPNIK = 2;
     24    public static final int OSMARENDER = 3;
    2525
    26         public SourceButton() {
    27                 enlargeImage = ImageProvider.get("", "layer-switcher-maximize.png");
    28                 shrinkImage = ImageProvider.get("", "layer-switcher-minimize.png");
    29                 imageMapnik = ImageProvider.get("", "blue_Mapnik.png");
    30                 imageOsmarender = ImageProvider.get("", "blue_Osmarender.png");
    31         }
     26    public SourceButton() {
     27        enlargeImage = ImageProvider.get("", "layer-switcher-maximize.png");
     28        shrinkImage = ImageProvider.get("", "layer-switcher-minimize.png");
     29        imageMapnik = ImageProvider.get("", "blue_Mapnik.png");
     30        imageOsmarender = ImageProvider.get("", "blue_Osmarender.png");
     31    }
    3232
    33         public void paint(Graphics g) {
     33    public void paint(Graphics g) {
    3434
    35                 if (isEnlarged) {
    36                         if (isMapnik) {
    37                                 g.drawImage(imageMapnik.getImage(), g.getClipBounds().width
    38                                                 - imageMapnik.getIconWidth(), y, null);
    39                         } else {
    40                                 g.drawImage(imageOsmarender.getImage(), g.getClipBounds().width
    41                                                 - imageMapnik.getIconWidth(), y, null);
    42                         }
     35        if (isEnlarged) {
     36            if (isMapnik) {
     37                g.drawImage(imageMapnik.getImage(), g.getClipBounds().width
     38                        - imageMapnik.getIconWidth(), y, null);
     39            } else {
     40                g.drawImage(imageOsmarender.getImage(), g.getClipBounds().width
     41                        - imageMapnik.getIconWidth(), y, null);
     42            }
    4343
    44                         if (shrinkImage != null) {
    45                                 this.x = g.getClipBounds().width - shrinkImage.getIconWidth();
    46                                 g.drawImage(shrinkImage.getImage(), x, y, null);
    47                         }
     44            if (shrinkImage != null) {
     45                this.x = g.getClipBounds().width - shrinkImage.getIconWidth();
     46                g.drawImage(shrinkImage.getImage(), x, y, null);
     47            }
    4848
    49                 } else {
    50                         if (enlargeImage != null) {
    51                                 this.x = g.getClipBounds().width - enlargeImage.getIconWidth();
    52                                 g.drawImage(enlargeImage.getImage(), x, y, null);
    53                         }
    54                 }
    55         }
     49        } else {
     50            if (enlargeImage != null) {
     51                this.x = g.getClipBounds().width - enlargeImage.getIconWidth();
     52                g.drawImage(enlargeImage.getImage(), x, y, null);
     53            }
     54        }
     55    }
    5656
    57         public void toggle() {
    58                 this.isEnlarged = !this.isEnlarged;
     57    public void toggle() {
     58        this.isEnlarged = !this.isEnlarged;
    5959
    60         }
     60    }
    6161
    62         public int hit(Point point) {
    63                 if (isEnlarged) {
    64                         if (x < point.x && point.x < x + shrinkImage.getIconWidth()) {
    65                                 if (y < point.y && point.y < y + shrinkImage.getIconHeight()) {
    66                                         return HIDE_OR_SHOW;
    67                                 }
    68                         } else if (x - imageMapnik.getIconWidth() < point.x && point.x < x) {
    69                                 if (y < point.y && point.y < y + imageMapnik.getIconHeight() / 2) {
    70                                         isMapnik = false;
    71                                         return OSMARENDER;
    72                                 } else if (y + imageMapnik.getIconHeight() / 2 < point.y
    73                                                 && point.y < y + imageMapnik.getIconHeight()) {
    74                                         isMapnik = true;
    75                                         return MAPNIK;
    76                                 }
    77                         }
    78                 } else {
    79                         if (x < point.x && point.x < x + enlargeImage.getIconWidth()) {
    80                                 if (y < point.y && point.y < y + enlargeImage.getIconHeight()) {
    81                                         return HIDE_OR_SHOW;
    82                                 }
    83                         }
    84                 }
     62    public int hit(Point point) {
     63        if (isEnlarged) {
     64            if (x < point.x && point.x < x + shrinkImage.getIconWidth()) {
     65                if (y < point.y && point.y < y + shrinkImage.getIconHeight()) {
     66                    return HIDE_OR_SHOW;
     67                }
     68            } else if (x - imageMapnik.getIconWidth() < point.x && point.x < x) {
     69                if (y < point.y && point.y < y + imageMapnik.getIconHeight() / 2) {
     70                    isMapnik = false;
     71                    return OSMARENDER;
     72                } else if (y + imageMapnik.getIconHeight() / 2 < point.y
     73                        && point.y < y + imageMapnik.getIconHeight()) {
     74                    isMapnik = true;
     75                    return MAPNIK;
     76                }
     77            }
     78        } else {
     79            if (x < point.x && point.x < x + enlargeImage.getIconWidth()) {
     80                if (y < point.y && point.y < y + enlargeImage.getIconHeight()) {
     81                    return HIDE_OR_SHOW;
     82                }
     83            }
     84        }
    8585
    86                 return 0;
    87         }
     86        return 0;
     87    }
    8888}
Note: See TracChangeset for help on using the changeset viewer.