mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
Label and ToolTip: made inserting BASE_SIZE rule into HTML text more reliable
This commit is contained in:
@@ -110,14 +110,26 @@ public class FlatLabelUI
|
|||||||
c.getClientProperty( "html.disable" ) != Boolean.TRUE &&
|
c.getClientProperty( "html.disable" ) != Boolean.TRUE &&
|
||||||
needsFontBaseSize( text ) )
|
needsFontBaseSize( text ) )
|
||||||
{
|
{
|
||||||
int headIndex = text.indexOf( "<head>" );
|
|
||||||
|
|
||||||
// BASE_SIZE rule is parsed in javax.swing.text.html.StyleSheet.addRule()
|
// BASE_SIZE rule is parsed in javax.swing.text.html.StyleSheet.addRule()
|
||||||
String style = "<style>BASE_SIZE " + c.getFont().getSize() + "</style>";
|
String style = "<style>BASE_SIZE " + c.getFont().getSize() + "</style>";
|
||||||
if( headIndex < 0 )
|
|
||||||
style = "<head>" + style + "</head>";
|
|
||||||
|
|
||||||
int insertIndex = headIndex >= 0 ? (headIndex + "<head>".length()) : "<html>".length();
|
String lowerText = text.toLowerCase();
|
||||||
|
int headIndex;
|
||||||
|
int styleIndex;
|
||||||
|
|
||||||
|
int insertIndex;
|
||||||
|
if( (headIndex = lowerText.indexOf( "<head>" )) >= 0 ) {
|
||||||
|
// there is a <head> tag --> insert after <head> tag
|
||||||
|
insertIndex = headIndex + "<head>".length();
|
||||||
|
} else if( (styleIndex = lowerText.indexOf( "<style>" )) >= 0 ) {
|
||||||
|
// there is a <style> tag --> insert before <style> tag
|
||||||
|
insertIndex = styleIndex;
|
||||||
|
} else {
|
||||||
|
// no <head> or <style> tag --> insert <head> tag after <html> tag
|
||||||
|
style = "<head>" + style + "</head>";
|
||||||
|
insertIndex = "<html>".length();
|
||||||
|
}
|
||||||
|
|
||||||
text = text.substring( 0, insertIndex )
|
text = text.substring( 0, insertIndex )
|
||||||
+ style
|
+ style
|
||||||
+ text.substring( insertIndex );
|
+ text.substring( insertIndex );
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ public class FlatHtmlTest
|
|||||||
JLabel label48 = new JLabel();
|
JLabel label48 = new JLabel();
|
||||||
JLabel label54 = new JLabel();
|
JLabel label54 = new JLabel();
|
||||||
JLabel label56 = new JLabel();
|
JLabel label56 = new JLabel();
|
||||||
|
JLabel label57 = new JLabel();
|
||||||
|
|
||||||
//======== this ========
|
//======== this ========
|
||||||
setLayout(new MigLayout(
|
setLayout(new MigLayout(
|
||||||
@@ -443,6 +444,7 @@ public class FlatHtmlTest
|
|||||||
"[]para" +
|
"[]para" +
|
||||||
"[]para" +
|
"[]para" +
|
||||||
"[]" +
|
"[]" +
|
||||||
|
"[]" +
|
||||||
"[]"));
|
"[]"));
|
||||||
|
|
||||||
//---- label22 ----
|
//---- label22 ----
|
||||||
@@ -588,6 +590,10 @@ public class FlatHtmlTest
|
|||||||
//---- label56 ----
|
//---- label56 ----
|
||||||
label56.setText("<html><head><style>body { color: red }</style></head>leading <big>red</big> trailing</html>");
|
label56.setText("<html><head><style>body { color: red }</style></head>leading <big>red</big> trailing</html>");
|
||||||
panel2.add(label56, "cell 0 8 7 1");
|
panel2.add(label56, "cell 0 8 7 1");
|
||||||
|
|
||||||
|
//---- label57 ----
|
||||||
|
label57.setText("<html><style>body { color: red }</style><p>leading <big>red</big> trailing</p></html>");
|
||||||
|
panel2.add(label57, "cell 0 9 7 1");
|
||||||
}
|
}
|
||||||
add(panel2, "cell 4 2");
|
add(panel2, "cell 4 2");
|
||||||
// JFormDesigner - End of component initialization //GEN-END:initComponents
|
// JFormDesigner - End of component initialization //GEN-END:initComponents
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ new FormModel {
|
|||||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||||
"$layoutConstraints": "insets 0,hidemode 3"
|
"$layoutConstraints": "insets 0,hidemode 3"
|
||||||
"$columnConstraints": "[fill]para[fill][fill][fill][fill][fill][fill]"
|
"$columnConstraints": "[fill]para[fill][fill][fill][fill][fill][fill]"
|
||||||
"$rowConstraints": "[][][][][][]para[]para[][]"
|
"$rowConstraints": "[][][][][][]para[]para[][][]"
|
||||||
} ) {
|
} ) {
|
||||||
name: "panel2"
|
name: "panel2"
|
||||||
auxiliary() {
|
auxiliary() {
|
||||||
@@ -594,6 +594,12 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 8 7 1"
|
"value": "cell 0 8 7 1"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
|
name: "label57"
|
||||||
|
"text": "<html><style>body { color: red }</style><p>leading <big>red</big> trailing</p></html>"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 0 9 7 1"
|
||||||
|
} )
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 4 2"
|
"value": "cell 4 2"
|
||||||
} )
|
} )
|
||||||
|
|||||||
Reference in New Issue
Block a user