ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/java/SwingComponents/src/net/oni2/swingcomponents/HTMLLinkLabel.java
(Generate patch)

Comparing java/SwingComponents/src/net/oni2/swingcomponents/HTMLLinkLabel.java (file contents):
Revision 849 by alloc, Thu May 2 11:15:35 2013 UTC vs.
Revision 880 by alloc, Mon Jun 3 09:46:25 2013 UTC

# Line 14 | Line 14 | import javax.swing.border.Border;
14   import javax.swing.event.HyperlinkEvent;
15   import javax.swing.event.HyperlinkListener;
16   import javax.swing.text.DefaultCaret;
17 + import javax.swing.text.html.CSS;
18   import javax.swing.text.html.HTMLEditorKit;
19   import javax.swing.text.html.StyleSheet;
20  
# Line 38 | Line 39 | public class HTMLLinkLabel extends JEdit
39                                  .setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
40  
41                  setContentType("text/html");
42 <
42 <                HTMLEditorKit hek = (HTMLEditorKit) getEditorKit();
43 <                StyleSheet css = hek.getStyleSheet();
44 <                css.removeStyle("p");
45 <
42 >                
43                  Font font = new JLabel().getFont();
44  
45                  StringBuffer style = new StringBuffer("font-family:" + font.getFamily()
# Line 79 | Line 76 | public class HTMLLinkLabel extends JEdit
76          }
77  
78          /**
79 +         * Add or reset a CSS attribute for styling the text
80 +         *
81 +         * @param selector
82 +         *            CSS selector
83 +         * @param attribute
84 +         *            CSS attribute
85 +         * @param value
86 +         *            Value
87 +         */
88 +        public void setCssAttribute(String selector, CSS.Attribute attribute,
89 +                        String value) {
90 +                HTMLEditorKit hek = (HTMLEditorKit) getEditorKit();
91 +                StyleSheet css = hek.getStyleSheet();
92 +                css.addRule(String.format("%s {%s: %s}", selector, attribute.toString(), value));
93 +        }
94 +
95 +        /**
96           * Allow or forbid to set a non-null border
97           *
98           * @param enable
# Line 98 | Line 112 | public class HTMLLinkLabel extends JEdit
112  
113          @Override
114          public void setText(String t) {
115 +                if (t.startsWith("<p>"))
116 +                        t = t.replaceFirst("<p>", "<p style=\"margin-top: 0\">");
117                  super.setText(prefix + t + suffix);
118          }
119  

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)