Ignore:
Timestamp:
2014-01-31T01:07:05+01:00 (12 years ago)
Author:
Don-vip
Message:

fix #9637 - make status bar background/foregound colors configurable to allow manual look and feel adjustments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MapStatus.java

    r6783 r6789  
    33
    44import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
     5import static org.openstreetmap.josm.tools.I18n.marktr;
    56import static org.openstreetmap.josm.tools.I18n.tr;
    67
    78import java.awt.AWTEvent;
     9import java.awt.Color;
    810import java.awt.Component;
    911import java.awt.Cursor;
     
    4749
    4850import org.openstreetmap.josm.Main;
     51import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
     52import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
    4953import org.openstreetmap.josm.data.coor.CoordinateFormat;
    5054import org.openstreetmap.josm.data.coor.LatLon;
     
    5256import org.openstreetmap.josm.data.osm.OsmPrimitive;
    5357import org.openstreetmap.josm.data.osm.Way;
     58import org.openstreetmap.josm.data.preferences.ColorProperty;
    5459import org.openstreetmap.josm.gui.NavigatableComponent.SoMChangeListener;
    5560import org.openstreetmap.josm.gui.help.Helpful;
     
    7782 * @author imi
    7883 */
    79 public class MapStatus extends JPanel implements Helpful, Destroyable {
     84public 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);
    80113
    81114    /**
     
    137170    }
    138171
    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());
    141178    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);
    146179    final JProgressBar progressBar = new JProgressBar();
    147180    public final BackgroundProgressMonitor progressMonitor = new BackgroundProgressMonitor();
     
    149182    private final SoMChangeListener somListener;
    150183
    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;
    152189
    153190    /**
     
    771808
    772809        NavigatableComponent.addSoMChangeListener(somListener = new SoMChangeListener() {
    773             @Override public void systemOfMeasurementChanged(String oldSoM, String newSoM) {
     810            @Override
     811            public void systemOfMeasurementChanged(String oldSoM, String newSoM) {
    774812                setDist(distValue);
    775813            }
     
    798836        });
    799837
     838        Main.pref.addPreferenceChangeListener(this);
     839
    800840        // The background thread
    801841        thread = new Thread(collector, "Map Status Collector");
     
    823863        setHelpText(null, t);
    824864    }
     865
    825866    public void setHelpText(Object id, final String text)  {
    826867
     
    838879        });
    839880    }
     881
    840882    public void resetHelpText(Object id) {
    841883        if (statusText.isEmpty())
     
    853895        statusText.remove(entry);
    854896    }
     897
    855898    public void setAngle(double a) {
    856899        angleText.setText(a < 0 ? "--" : Math.round(a*10)/10.0 + " \u00B0");
    857900    }
     901
    858902    public void setHeading(double h) {
    859903        headingText.setText(h < 0 ? "--" : Math.round(h*10)/10.0 + " \u00B0");
    860904    }
     905
    861906    /**
    862907     * Sets the distance text to the given value
     
    867912        distText.setText(dist < 0 ? "--" : NavigatableComponent.getDistText(dist));
    868913    }
     914
    869915    /**
    870916     * Sets the distance text to the total sum of given ways length
     
    885931        setDist(dist);
    886932    }
     933
     934    /**
     935     * Activates the angle panel.
     936     * @param activeFlag {@code true} to activate it, {@code false} to deactivate it
     937     */
    887938    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());
    889946    }
    890947
     
    892949    public void destroy() {
    893950        NavigatableComponent.removeSoMChangeListener(somListener);
     951        Main.pref.removePreferenceChangeListener(this);
    894952
    895953        // MapFrame gets destroyed when the last layer is removed, but the status line background
     
    903961        }
    904962    }
     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    }
    905991}
Note: See TracChangeset for help on using the changeset viewer.