Ticket #3500: jmultiline.patch

File jmultiline.patch, 3.0 KB (added by xeen, 17 years ago)

Patch is unnecessary large due to Eclipse reformatting the source code. I still do not get why we need braces around single statement blocks, but well.

  • src/org/openstreetmap/josm/gui/JMultilineLabel.java

     
    4242
    4343    public void setText(String text) {
    4444        String old = this.text;
    45         this.text = text;
     45        // Remove HTML tags but interpret <br> as intended
     46        this.text = text.replaceAll("<br/?>", "\n").replaceAll("</?[a-zA-Z]+/?>", "");
    4647        firePropertyChange("text", old, this.text);
    47         if ((old == null) ? text!=null : !old.equals(text))
     48        if ((old == null) ? text!=null : !old.equals(text)) {
    4849            morph();
     50        }
    4951    }
    5052
    5153    public int getMaxWidth() {
     
    5860        int old = this.maxWidth;
    5961        this.maxWidth = maxWidth;
    6062        firePropertyChange("maxWidth", old, this.maxWidth);
    61         if (old !=  this.maxWidth)
     63        if (old !=  this.maxWidth) {
    6264            morph();
     65        }
    6366    }
    6467
    6568    public boolean isJustified() {
     
    7073        boolean old = this.justify;
    7174        this.justify = justify;
    7275        firePropertyChange("justified", old, this.justify);
    73         if (old != this.justify)
     76        if (old != this.justify) {
    7477            repaint();
     78        }
    7579    }
    7680
     81    @Override
    7782    public Dimension getPreferredSize() {
    7883        return paintOrGetSize(null, getMaxWidth());
    7984    }
    8085
     86    @Override
    8187    public Dimension getMinimumSize() {
    8288        return getPreferredSize();
    8389    }
    8490
     91    @Override
    8592    protected void paintComponent(Graphics g) {
    8693        super.paintComponent(g);
    8794        paintOrGetSize((Graphics2D)g, getWidth());
     
    97104            String[] lines = getText().split("\n");
    98105            for(String line : lines) {
    99106                // Insert a space so new lines get rendered
    100                 if(line.length() == 0) line = " ";
     107                if(line.length() == 0) {
     108                    line = " ";
     109                }
    101110                AttributedString as = new AttributedString(line);
    102111                as.addAttribute(TextAttribute.FONT, getFont());
    103112                AttributedCharacterIterator aci = as.getIterator();
     
    105114                float max = 0;
    106115                while (lbm.getPosition() < aci.getEndIndex()) {
    107116                    TextLayout textLayout = lbm.nextLayout(width);
    108                     if (g != null && isJustified() && textLayout.getVisibleAdvance() > 0.80 * width)
     117                    if (g != null && isJustified() && textLayout.getVisibleAdvance() > 0.80 * width) {
    109118                        textLayout = textLayout.getJustifiedLayout(width);
    110                     if (g != null)
     119                    }
     120                    if (g != null) {
    111121                        textLayout.draw(g, x, y + textLayout.getAscent());
     122                    }
    112123                    y += textLayout.getDescent() + textLayout.getLeading() + textLayout.getAscent();
    113124                    max = Math.max(max, textLayout.getVisibleAdvance());
    114125                }