Changeset 6789 in josm


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

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

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
3 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}
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/ColorPreference.java

    r6764 r6789  
    3535import org.openstreetmap.josm.data.validation.Severity;
    3636import org.openstreetmap.josm.gui.MapScaler;
     37import org.openstreetmap.josm.gui.MapStatus;
    3738import org.openstreetmap.josm.gui.conflict.ConflictColors;
    3839import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
     
    269270        ImageryLayer.getFadeColor();
    270271        MapScaler.getColor();
     272        MapStatus.getColors();
    271273        ConflictDialog.getColor();
    272274    }
  • trunk/src/org/openstreetmap/josm/gui/widgets/ImageLabel.java

    r6101 r6789  
    55import java.awt.Dimension;
    66import java.awt.GridBagLayout;
     7
    78import javax.swing.JLabel;
    89import javax.swing.JPanel;
     10
    911import org.openstreetmap.josm.tools.GBC;
    1012import org.openstreetmap.josm.tools.ImageProvider;
    11 
    1213
    1314/**
    1415 * A small user interface component that consists of an image label and
    1516 * a fixed text content to the right of the image.
    16  * Moved from @link org.openstreetmap.josm.gui.MapStatus @since 5965
     17 * @since 5965
    1718 */
    1819public class ImageLabel extends JPanel {
    19     public static final Color backColor = Color.decode("#b8cfe5");
    20     public static final Color backColorActive = Color.decode("#aaff5e");
    21 
    2220    private JLabel tf;
    2321    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) {
    2731        setLayout(new GridBagLayout());
    28         setBackground(backColor);
     32        setBackground(background);
    2933        add(new JLabel(ImageProvider.get("statusline/"+img+".png")), GBC.std().anchor(GBC.WEST).insets(0,1,1,0));
    3034        add(tf = new JLabel(), GBC.std().fill(GBC.BOTH).anchor(GBC.WEST).insets(2,1,1,0));
     
    3236        this.charCount = charCount;
    3337    }
    34    
     38
     39    /**
     40     * Sets the text to display.
     41     * @param t text to display
     42     */
    3543    public void setText(String t) {
    3644        tf.setText(t);
    3745    }
    38     @Override public Dimension getPreferredSize() {
     46
     47    @Override
     48    public Dimension getPreferredSize() {
    3949        return new Dimension(25 + charCount*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getPreferredSize().height);
    4050    }
    41     @Override public Dimension getMinimumSize() {
     51
     52    @Override
     53    public Dimension getMinimumSize() {
    4254        return new Dimension(25 + charCount*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getMinimumSize().height);
    4355    }
Note: See TracChangeset for help on using the changeset viewer.