Changeset 6789 in josm for trunk/src/org/openstreetmap/josm/gui/MapStatus.java
- Timestamp:
- 2014-01-31T01:07:05+01:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r6783 r6789 3 3 4 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 import static org.openstreetmap.josm.tools.I18n.marktr; 5 6 import static org.openstreetmap.josm.tools.I18n.tr; 6 7 7 8 import java.awt.AWTEvent; 9 import java.awt.Color; 8 10 import java.awt.Component; 9 11 import java.awt.Cursor; … … 47 49 48 50 import org.openstreetmap.josm.Main; 51 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 52 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 49 53 import org.openstreetmap.josm.data.coor.CoordinateFormat; 50 54 import org.openstreetmap.josm.data.coor.LatLon; … … 52 56 import org.openstreetmap.josm.data.osm.OsmPrimitive; 53 57 import org.openstreetmap.josm.data.osm.Way; 58 import org.openstreetmap.josm.data.preferences.ColorProperty; 54 59 import org.openstreetmap.josm.gui.NavigatableComponent.SoMChangeListener; 55 60 import org.openstreetmap.josm.gui.help.Helpful; … … 77 82 * @author imi 78 83 */ 79 public class MapStatus extends JPanel implements Helpful, Destroyable { 84 public class MapStatus extends JPanel implements Helpful, Destroyable, PreferenceChangedListener { 85 86 /** 87 * Property for map status background color. 88 * @since 6789 89 */ 90 public static final ColorProperty PROP_BACKGROUND_COLOR = new ColorProperty( 91 marktr("Status bar background"), Color.decode("#b8cfe5")); 92 93 /** 94 * Property for map status background color (active state). 95 * @since 6789 96 */ 97 public static final ColorProperty PROP_ACTIVE_BACKGROUND_COLOR = new ColorProperty( 98 marktr("Status bar background: active"), Color.decode("#aaff5e")); 99 100 /** 101 * Property for map status foreground color. 102 * @since 6789 103 */ 104 public static final ColorProperty PROP_FOREGROUND_COLOR = new ColorProperty( 105 marktr("Status bar foreground"), Color.black); 106 107 /** 108 * Property for map status foreground color (active state). 109 * @since 6789 110 */ 111 public static final ColorProperty PROP_ACTIVE_FOREGROUND_COLOR = new ColorProperty( 112 marktr("Status bar foreground: active"), Color.black); 80 113 81 114 /** … … 137 170 } 138 171 139 final ImageLabel lonText = new ImageLabel("lon", tr("The geographic longitude at the mouse pointer."), 11); 140 final ImageLabel nameText = new ImageLabel("name", tr("The name of the object at the mouse pointer."), 20); 172 final ImageLabel latText = new ImageLabel("lat", tr("The geographic latitude at the mouse pointer."), 11, PROP_BACKGROUND_COLOR.get()); 173 final ImageLabel lonText = new ImageLabel("lon", tr("The geographic longitude at the mouse pointer."), 11, PROP_BACKGROUND_COLOR.get()); 174 final ImageLabel headingText = new ImageLabel("heading", tr("The (compass) heading of the line segment being drawn."), 6, PROP_BACKGROUND_COLOR.get()); 175 final ImageLabel angleText = new ImageLabel("angle", tr("The angle between the previous and the current way segment."), 6, PROP_BACKGROUND_COLOR.get()); 176 final ImageLabel distText = new ImageLabel("dist", tr("The length of the new way segment being drawn."), 10, PROP_BACKGROUND_COLOR.get()); 177 final ImageLabel nameText = new ImageLabel("name", tr("The name of the object at the mouse pointer."), 20, PROP_BACKGROUND_COLOR.get()); 141 178 final JosmTextField helpText = new JosmTextField(); 142 final ImageLabel latText = new ImageLabel("lat", tr("The geographic latitude at the mouse pointer."), 11);143 final ImageLabel angleText = new ImageLabel("angle", tr("The angle between the previous and the current way segment."), 6);144 final ImageLabel headingText = new ImageLabel("heading", tr("The (compass) heading of the line segment being drawn."), 6);145 final ImageLabel distText = new ImageLabel("dist", tr("The length of the new way segment being drawn."), 10);146 179 final JProgressBar progressBar = new JProgressBar(); 147 180 public final BackgroundProgressMonitor progressMonitor = new BackgroundProgressMonitor(); … … 149 182 private final SoMChangeListener somListener; 150 183 151 private double distValue; // Distance value displayed in distText, stored if refresh needed after a change of system of measurement 184 // Distance value displayed in distText, stored if refresh needed after a change of system of measurement 185 private double distValue; 186 187 // Determines if angle panel is enabled or not 188 private boolean angleEnabled = false; 152 189 153 190 /** … … 771 808 772 809 NavigatableComponent.addSoMChangeListener(somListener = new SoMChangeListener() { 773 @Override public void systemOfMeasurementChanged(String oldSoM, String newSoM) { 810 @Override 811 public void systemOfMeasurementChanged(String oldSoM, String newSoM) { 774 812 setDist(distValue); 775 813 } … … 798 836 }); 799 837 838 Main.pref.addPreferenceChangeListener(this); 839 800 840 // The background thread 801 841 thread = new Thread(collector, "Map Status Collector"); … … 823 863 setHelpText(null, t); 824 864 } 865 825 866 public void setHelpText(Object id, final String text) { 826 867 … … 838 879 }); 839 880 } 881 840 882 public void resetHelpText(Object id) { 841 883 if (statusText.isEmpty()) … … 853 895 statusText.remove(entry); 854 896 } 897 855 898 public void setAngle(double a) { 856 899 angleText.setText(a < 0 ? "--" : Math.round(a*10)/10.0 + " \u00B0"); 857 900 } 901 858 902 public void setHeading(double h) { 859 903 headingText.setText(h < 0 ? "--" : Math.round(h*10)/10.0 + " \u00B0"); 860 904 } 905 861 906 /** 862 907 * Sets the distance text to the given value … … 867 912 distText.setText(dist < 0 ? "--" : NavigatableComponent.getDistText(dist)); 868 913 } 914 869 915 /** 870 916 * Sets the distance text to the total sum of given ways length … … 885 931 setDist(dist); 886 932 } 933 934 /** 935 * Activates the angle panel. 936 * @param activeFlag {@code true} to activate it, {@code false} to deactivate it 937 */ 887 938 public void activateAnglePanel(boolean activeFlag) { 888 angleText.setBackground(activeFlag ? ImageLabel.backColorActive : ImageLabel.backColor); 939 angleEnabled = activeFlag; 940 refreshAnglePanel(); 941 } 942 943 private void refreshAnglePanel() { 944 angleText.setBackground(angleEnabled ? PROP_ACTIVE_BACKGROUND_COLOR.get() : PROP_BACKGROUND_COLOR.get()); 945 angleText.setForeground(angleEnabled ? PROP_ACTIVE_FOREGROUND_COLOR.get() : PROP_FOREGROUND_COLOR.get()); 889 946 } 890 947 … … 892 949 public void destroy() { 893 950 NavigatableComponent.removeSoMChangeListener(somListener); 951 Main.pref.removePreferenceChangeListener(this); 894 952 895 953 // MapFrame gets destroyed when the last layer is removed, but the status line background … … 903 961 } 904 962 } 963 964 @Override 965 public void preferenceChanged(PreferenceChangeEvent e) { 966 String key = e.getKey(); 967 if (key.startsWith("color.")) { 968 key = key.substring("color.".length()); 969 if (PROP_BACKGROUND_COLOR.getKey().equals(key) || PROP_FOREGROUND_COLOR.getKey().equals(key)) { 970 for (ImageLabel il : new ImageLabel[]{latText, lonText, headingText, distText, nameText}) { 971 il.setBackground(PROP_BACKGROUND_COLOR.get()); 972 il.setForeground(PROP_FOREGROUND_COLOR.get()); 973 } 974 refreshAnglePanel(); 975 } else if (PROP_ACTIVE_BACKGROUND_COLOR.getKey().equals(key) || PROP_ACTIVE_FOREGROUND_COLOR.getKey().equals(key)) { 976 refreshAnglePanel(); 977 } 978 } 979 } 980 981 /** 982 * Loads all colors from preferences. 983 * @since 6789 984 */ 985 public static void getColors() { 986 PROP_BACKGROUND_COLOR.get(); 987 PROP_FOREGROUND_COLOR.get(); 988 PROP_ACTIVE_BACKGROUND_COLOR.get(); 989 PROP_ACTIVE_FOREGROUND_COLOR.get(); 990 } 905 991 }
Note:
See TracChangeset
for help on using the changeset viewer.
