Changeset 6789 in josm for trunk/src/org
- Timestamp:
- 2014-01-31T01:07:05+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 3 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 } -
trunk/src/org/openstreetmap/josm/gui/preferences/display/ColorPreference.java
r6764 r6789 35 35 import org.openstreetmap.josm.data.validation.Severity; 36 36 import org.openstreetmap.josm.gui.MapScaler; 37 import org.openstreetmap.josm.gui.MapStatus; 37 38 import org.openstreetmap.josm.gui.conflict.ConflictColors; 38 39 import org.openstreetmap.josm.gui.dialogs.ConflictDialog; … … 269 270 ImageryLayer.getFadeColor(); 270 271 MapScaler.getColor(); 272 MapStatus.getColors(); 271 273 ConflictDialog.getColor(); 272 274 } -
trunk/src/org/openstreetmap/josm/gui/widgets/ImageLabel.java
r6101 r6789 5 5 import java.awt.Dimension; 6 6 import java.awt.GridBagLayout; 7 7 8 import javax.swing.JLabel; 8 9 import javax.swing.JPanel; 10 9 11 import org.openstreetmap.josm.tools.GBC; 10 12 import org.openstreetmap.josm.tools.ImageProvider; 11 12 13 13 14 /** 14 15 * A small user interface component that consists of an image label and 15 16 * a fixed text content to the right of the image. 16 * Moved from @link org.openstreetmap.josm.gui.MapStatus@since 596517 * @since 5965 17 18 */ 18 19 public class ImageLabel extends JPanel { 19 public static final Color backColor = Color.decode("#b8cfe5");20 public static final Color backColorActive = Color.decode("#aaff5e");21 22 20 private JLabel tf; 23 21 private int charCount; 24 25 public ImageLabel(String img, String tooltip, int charCount) { 26 super(); 22 23 /** 24 * Constructs a new {@code ImageLabel}. 25 * @param img Image name (without .png extension) to find in {@code statusline} directory 26 * @param tooltip Tooltip text to display 27 * @param charCount Character count used to compute min/preferred size 28 * @param background The background color 29 */ 30 public ImageLabel(String img, String tooltip, int charCount, Color background) { 27 31 setLayout(new GridBagLayout()); 28 setBackground(back Color);32 setBackground(background); 29 33 add(new JLabel(ImageProvider.get("statusline/"+img+".png")), GBC.std().anchor(GBC.WEST).insets(0,1,1,0)); 30 34 add(tf = new JLabel(), GBC.std().fill(GBC.BOTH).anchor(GBC.WEST).insets(2,1,1,0)); … … 32 36 this.charCount = charCount; 33 37 } 34 38 39 /** 40 * Sets the text to display. 41 * @param t text to display 42 */ 35 43 public void setText(String t) { 36 44 tf.setText(t); 37 45 } 38 @Override public Dimension getPreferredSize() { 46 47 @Override 48 public Dimension getPreferredSize() { 39 49 return new Dimension(25 + charCount*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getPreferredSize().height); 40 50 } 41 @Override public Dimension getMinimumSize() { 51 52 @Override 53 public Dimension getMinimumSize() { 42 54 return new Dimension(25 + charCount*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getMinimumSize().height); 43 55 }
Note:
See TracChangeset
for help on using the changeset viewer.