Changeset 11797 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2017-03-31T22:11:31+02:00 (8 years ago)
Author:
bastiK
Message:

see #14495 - fix immutable class non-constant field (by removing it)

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/BoxTextElement.java

    r11452 r11797  
    108108
    109109    /**
    110      * A rectangle with size 0x0
    111      */
    112     public static final Rectangle ZERO_BOX = new Rectangle(0, 0, 0, 0);
    113 
    114     /**
    115110     * The default style a simple node should use for it's text
    116111     */
     
    138133     */
    139134    public TextLabel text;
    140     // Either boxProvider or box is not null. If boxProvider is different from
    141     // null, this means, that the box can still change in future, otherwise
    142     // it is fixed.
     135    /**
     136     * The {@link HorizontalTextAlignment} for this text.
     137     */
     138    public HorizontalTextAlignment hAlign;
     139    /**
     140     * The {@link VerticalTextAlignment} for this text.
     141     */
     142    public VerticalTextAlignment vAlign;
    143143    protected BoxProvider boxProvider;
    144     protected Rectangle box;
    145     /**
    146      * The {@link HorizontalTextAlignment} for this text.
    147      */
    148     public HorizontalTextAlignment hAlign;
    149     /**
    150      * The {@link VerticalTextAlignment} for this text.
    151      */
    152     public VerticalTextAlignment vAlign;
    153144
    154145    /**
     
    157148     * @param text The text to display
    158149     * @param boxProvider The box provider to use
    159      * @param box The initial box to use.
    160150     * @param hAlign The {@link HorizontalTextAlignment}
    161151     * @param vAlign The {@link VerticalTextAlignment}
    162152     */
    163     public BoxTextElement(Cascade c, TextLabel text, BoxProvider boxProvider, Rectangle box,
     153    public BoxTextElement(Cascade c, TextLabel text, BoxProvider boxProvider,
    164154            HorizontalTextAlignment hAlign, VerticalTextAlignment vAlign) {
    165155        super(c, 5f);
     
    169159        this.text = text;
    170160        this.boxProvider = boxProvider;
    171         this.box = box == null ? ZERO_BOX : box;
    172161        this.hAlign = hAlign;
    173162        this.vAlign = vAlign;
    174     }
    175 
    176     /**
    177      * Create a new {@link BoxTextElement} with a dynamic box
    178      * @param env The MapCSS environment
    179      * @param boxProvider The box provider that computes the box.
    180      * @return A new {@link BoxTextElement} or <code>null</code> if the creation failed.
    181      */
    182     public static BoxTextElement create(Environment env, BoxProvider boxProvider) {
    183         return create(env, boxProvider, null);
    184     }
    185 
    186     /**
    187      * Create a new {@link BoxTextElement} with a fixed box
    188      * @param env The MapCSS environment
    189      * @param box The box
    190      * @return A new {@link BoxTextElement} or <code>null</code> if the creation failed.
    191      */
    192     public static BoxTextElement create(Environment env, Rectangle box) {
    193         return create(env, null, box);
    194163    }
    195164
     
    198167     * @param env The MapCSS environment
    199168     * @param boxProvider The box provider.
    200      * @param box The box. Only considered if boxProvider is null.
    201169     * @return A new {@link BoxTextElement} or <code>null</code> if the creation failed.
    202170     */
    203     public static BoxTextElement create(Environment env, BoxProvider boxProvider, Rectangle box) {
     171    public static BoxTextElement create(Environment env, BoxProvider boxProvider) {
    204172        initDefaultParameters();
    205173
     
    244212        }
    245213
    246         return new BoxTextElement(c, text, boxProvider, box, hAlign, vAlign);
     214        return new BoxTextElement(c, text, boxProvider, hAlign, vAlign);
    247215    }
    248216
     
    252220     */
    253221    public Rectangle getBox() {
    254         if (boxProvider != null) {
    255             BoxProviderResult result = boxProvider.get();
    256             if (!result.isTemporary()) {
    257                 box = result.getBox();
    258                 boxProvider = null;
    259             }
    260             return result.getBox();
    261         }
    262         return box;
     222        return boxProvider.get().getBox();
    263223    }
    264224
     
    285245               vAlign == that.vAlign &&
    286246               Objects.equals(text, that.text) &&
    287                Objects.equals(boxProvider, that.boxProvider) &&
    288                Objects.equals(box, that.box);
     247               Objects.equals(boxProvider, that.boxProvider);
    289248    }
    290249
    291250    @Override
    292251    public int hashCode() {
    293         return Objects.hash(super.hashCode(), text, boxProvider, box, hAlign, vAlign);
     252        return Objects.hash(super.hashCode(), text, boxProvider, hAlign, vAlign);
    294253    }
    295254
    296255    @Override
    297256    public String toString() {
    298         return "BoxTextElemStyle{" + super.toString() + ' ' + text.toStringImpl()
    299                 + " box=" + box + " hAlign=" + hAlign + " vAlign=" + vAlign + '}';
     257        return "BoxTextElement{" + super.toString() + ' ' + text.toStringImpl()
     258                + " box=" + getBox() + " hAlign=" + hAlign + " vAlign=" + vAlign + '}';
    300259    }
    301260}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java

    r11763 r11797  
    376376    @Override
    377377    public String toString() {
    378         StringBuilder s = new StringBuilder(64).append("NodeElemStyle{").append(super.toString());
     378        StringBuilder s = new StringBuilder(64).append("NodeElement{").append(super.toString());
    379379        if (mapImage != null) {
    380380            s.append(" icon=[" + mapImage + ']');
Note: See TracChangeset for help on using the changeset viewer.