Changeset 9954 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-03-08T01:22:33+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapScaler.java
r8510 r9954 9 9 import java.awt.geom.Rectangle2D; 10 10 11 import javax.accessibility.Accessible; 12 import javax.accessibility.AccessibleContext; 13 import javax.accessibility.AccessibleValue; 11 14 import javax.swing.JComponent; 12 15 … … 14 17 import org.openstreetmap.josm.gui.help.Helpful; 15 18 16 public class MapScaler extends JComponent implements Helpful { 19 /** 20 * Map scale bar, displaying the distance in meter that correspond to 100 px on screen. 21 * @since 115 22 */ 23 public class MapScaler extends JComponent implements Helpful, Accessible { 17 24 18 25 private final NavigatableComponent mv; … … 20 27 private static final int PADDING_RIGHT = 100; 21 28 29 /** 30 * Constructs a new {@code MapScaler}. 31 * @param mv map view 32 */ 22 33 public MapScaler(NavigatableComponent mv) { 23 34 this.mv = mv; … … 41 52 } 42 53 54 /** 55 * Returns the color of map scaler. 56 * @return the color of map scaler 57 */ 43 58 public static Color getColor() { 44 59 return Main.pref.getColor(marktr("scale"), Color.white); … … 49 64 return ht("/MapView/Scaler"); 50 65 } 66 67 @Override 68 public AccessibleContext getAccessibleContext() { 69 if (accessibleContext == null) { 70 accessibleContext = new AccessibleMapScaler(); 71 } 72 return accessibleContext; 73 } 74 75 class AccessibleMapScaler extends AccessibleJComponent implements AccessibleValue { 76 77 @Override 78 public Number getCurrentAccessibleValue() { 79 return mv.getDist100Pixel(); 80 } 81 82 @Override 83 public boolean setCurrentAccessibleValue(Number n) { 84 return false; 85 } 86 87 @Override 88 public Number getMinimumAccessibleValue() { 89 return null; 90 } 91 92 @Override 93 public Number getMaximumAccessibleValue() { 94 return null; 95 } 96 } 51 97 } -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r9947 r9954 204 204 ScaleList scaleList = nativeScaleLayer.getNativeScales(); 205 205 if (scaleList != null) { 206 if ( 206 if (PROP_ZOOM_INTERMEDIATE_STEPS.get()) { 207 207 scaleList = scaleList.withIntermediateSteps(PROP_ZOOM_RATIO.get()); 208 208 } … … 323 323 } 324 324 325 /** 326 * Returns the text describing the distance in meter that correspond to 100 px on screen. 327 * @return the text describing the distance in meter that correspond to 100 px on screen 328 */ 325 329 public String getDist100PixelText() { 326 330 return getDistText(getDist100Pixel()); -
trunk/src/org/openstreetmap/josm/gui/bbox/SizeButton.java
r9078 r9954 6 6 import java.awt.Dimension; 7 7 import java.awt.Graphics; 8 import java.awt.Point;9 8 import java.awt.event.MouseAdapter; 10 9 import java.awt.event.MouseEvent; 11 10 11 import javax.accessibility.Accessible; 12 import javax.accessibility.AccessibleAction; 13 import javax.accessibility.AccessibleContext; 12 14 import javax.swing.ImageIcon; 13 15 import javax.swing.JComponent; … … 16 18 17 19 /** 20 * Button allowing to control the dimension of a slippy map between two states (normal/enlarged). 18 21 * @author Tim Haussmann 22 * @since 1390 19 23 */ 20 public class SizeButton extends JComponent { 21 22 private int x; 23 private int y; 24 public class SizeButton extends JComponent implements Accessible { 24 25 25 26 private final ImageIcon enlargeImage; … … 28 29 private final SlippyMapBBoxChooser slippyMapBBoxChooser; 29 30 31 private final transient MouseAdapter mouseAdapter = new MouseAdapter() { 32 @Override 33 public void mouseReleased(MouseEvent e) { 34 if (e.getButton() == MouseEvent.BUTTON1) { 35 toggle(); 36 } 37 } 38 }; 39 40 /** 41 * Constructs a new {@code SizeButton}. 42 * @param slippyMapBBoxChooser the associated slippy map 43 */ 30 44 public SizeButton(SlippyMapBBoxChooser slippyMapBBoxChooser) { 31 45 this.slippyMapBBoxChooser = slippyMapBBoxChooser; … … 33 47 shrinkImage = ImageProvider.get("view-fullscreen-revert"); 34 48 setPreferredSize(new Dimension(enlargeImage.getIconWidth(), enlargeImage.getIconHeight())); 35 addMouseListener(mouse Listener);49 addMouseListener(mouseAdapter); 36 50 setToolTipText(tr("Enlarge")); 37 51 } 38 39 private final transient MouseAdapter mouseListener = new MouseAdapter() {40 @Override41 public void mouseReleased(MouseEvent e) {42 if (e.getButton() == MouseEvent.BUTTON1) {43 toggle();44 slippyMapBBoxChooser.resizeSlippyMap();45 }46 }47 };48 52 49 53 @Override … … 51 55 if (isEnlarged) { 52 56 if (shrinkImage != null) 53 g.drawImage(shrinkImage.getImage(), x, y, null);57 g.drawImage(shrinkImage.getImage(), 0, 0, null); 54 58 } else { 55 59 if (enlargeImage != null) 56 g.drawImage(enlargeImage.getImage(), x, y, null);60 g.drawImage(enlargeImage.getImage(), 0, 0, null); 57 61 } 58 62 } 59 63 64 /** 65 * Toggles button state. 66 */ 60 67 public void toggle() { 61 68 isEnlarged = !isEnlarged; 62 69 setToolTipText(isEnlarged ? tr("Shrink") : tr("Enlarge")); 70 slippyMapBBoxChooser.resizeSlippyMap(); 63 71 } 64 72 73 /** 74 * Determines if the slippy map is enlarged. 75 * @return {@code true} if the slippy map is enlarged, {@code false} otherwise 76 */ 65 77 public boolean isEnlarged() { 66 78 return isEnlarged; 67 79 } 68 80 69 public boolean hit(Point point) { 70 if (x < point.x && point.x < x + enlargeImage.getIconWidth()) { 71 if (y < point.y && point.y < y + enlargeImage.getIconHeight()) { 72 return true; 73 } 81 @Override 82 public AccessibleContext getAccessibleContext() { 83 if (accessibleContext == null) { 84 accessibleContext = new AccessibleSizeButton(); 74 85 } 75 return false;86 return accessibleContext; 76 87 } 77 88 89 class AccessibleSizeButton extends AccessibleJComponent implements AccessibleAction { 90 91 @Override 92 public int getAccessibleActionCount() { 93 return 1; 94 } 95 96 @Override 97 public String getAccessibleActionDescription(int i) { 98 return "toggle"; 99 } 100 101 @Override 102 public boolean doAccessibleAction(int i) { 103 toggle(); 104 return true; 105 } 106 } 78 107 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r9916 r9954 92 92 private static final char[] DEFAULT_STRIP = {'\u200B', '\uFEFF'}; 93 93 94 private static final String[] SIZE_UNITS = {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}; 95 94 96 /** 95 97 * Tests whether {@code predicate} applies to at least one element from {@code collection}. … … 1042 1044 throw new IllegalArgumentException("bytes must be >= 0"); 1043 1045 } 1044 final String[] units = {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};1045 1046 int unitIndex = 0; 1046 1047 double value = bytes; 1047 while (value >= 1024 && unitIndex < units.length) {1048 while (value >= 1024 && unitIndex < SIZE_UNITS.length) { 1048 1049 value /= 1024; 1049 1050 unitIndex++; 1050 1051 } 1051 1052 if (value > 100 || unitIndex == 0) { 1052 return String.format(locale, "%.0f %s", value, units[unitIndex]);1053 return String.format(locale, "%.0f %s", value, SIZE_UNITS[unitIndex]); 1053 1054 } else if (value > 10) { 1054 return String.format(locale, "%.1f %s", value, units[unitIndex]);1055 return String.format(locale, "%.1f %s", value, SIZE_UNITS[unitIndex]); 1055 1056 } else { 1056 return String.format(locale, "%.2f %s", value, units[unitIndex]);1057 return String.format(locale, "%.2f %s", value, SIZE_UNITS[unitIndex]); 1057 1058 } 1058 1059 }
Note:
See TracChangeset
for help on using the changeset viewer.