Ticket #3500: jmultiline.patch
| File jmultiline.patch, 3.0 KB (added by , 17 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/JMultilineLabel.java
42 42 43 43 public void setText(String text) { 44 44 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]+/?>", ""); 46 47 firePropertyChange("text", old, this.text); 47 if ((old == null) ? text!=null : !old.equals(text)) 48 if ((old == null) ? text!=null : !old.equals(text)) { 48 49 morph(); 50 } 49 51 } 50 52 51 53 public int getMaxWidth() { … … 58 60 int old = this.maxWidth; 59 61 this.maxWidth = maxWidth; 60 62 firePropertyChange("maxWidth", old, this.maxWidth); 61 if (old != this.maxWidth) 63 if (old != this.maxWidth) { 62 64 morph(); 65 } 63 66 } 64 67 65 68 public boolean isJustified() { … … 70 73 boolean old = this.justify; 71 74 this.justify = justify; 72 75 firePropertyChange("justified", old, this.justify); 73 if (old != this.justify) 76 if (old != this.justify) { 74 77 repaint(); 78 } 75 79 } 76 80 81 @Override 77 82 public Dimension getPreferredSize() { 78 83 return paintOrGetSize(null, getMaxWidth()); 79 84 } 80 85 86 @Override 81 87 public Dimension getMinimumSize() { 82 88 return getPreferredSize(); 83 89 } 84 90 91 @Override 85 92 protected void paintComponent(Graphics g) { 86 93 super.paintComponent(g); 87 94 paintOrGetSize((Graphics2D)g, getWidth()); … … 97 104 String[] lines = getText().split("\n"); 98 105 for(String line : lines) { 99 106 // Insert a space so new lines get rendered 100 if(line.length() == 0) line = " "; 107 if(line.length() == 0) { 108 line = " "; 109 } 101 110 AttributedString as = new AttributedString(line); 102 111 as.addAttribute(TextAttribute.FONT, getFont()); 103 112 AttributedCharacterIterator aci = as.getIterator(); … … 105 114 float max = 0; 106 115 while (lbm.getPosition() < aci.getEndIndex()) { 107 116 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) { 109 118 textLayout = textLayout.getJustifiedLayout(width); 110 if (g != null) 119 } 120 if (g != null) { 111 121 textLayout.draw(g, x, y + textLayout.getAscent()); 122 } 112 123 y += textLayout.getDescent() + textLayout.getLeading() + textLayout.getAscent(); 113 124 max = Math.max(max, textLayout.getVisibleAdvance()); 114 125 }
