mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 15:27:16 -06:00
Menus: support HTML in new layout (issue #3)
This commit is contained in:
@@ -32,6 +32,8 @@ import javax.swing.JMenuItem;
|
|||||||
import javax.swing.KeyStroke;
|
import javax.swing.KeyStroke;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.plaf.basic.BasicHTML;
|
||||||
|
import javax.swing.text.View;
|
||||||
import com.formdev.flatlaf.FlatLaf;
|
import com.formdev.flatlaf.FlatLaf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,10 +87,16 @@ public class FlatMenuItemRenderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// text size
|
// text size
|
||||||
String text = menuItem.getText();
|
View htmlView = (View) menuItem.getClientProperty( BasicHTML.propertyKey );
|
||||||
FontMetrics fm = menuItem.getFontMetrics( menuItem.getFont() );
|
if( htmlView != null ) {
|
||||||
width += SwingUtilities.computeStringWidth( fm, text );
|
width += htmlView.getPreferredSpan( View.X_AXIS );
|
||||||
height = Math.max( fm.getHeight(), height );
|
height = Math.max( (int) htmlView.getPreferredSpan( View.Y_AXIS ), height );
|
||||||
|
} else {
|
||||||
|
String text = menuItem.getText();
|
||||||
|
FontMetrics fm = menuItem.getFontMetrics( menuItem.getFont() );
|
||||||
|
width += SwingUtilities.computeStringWidth( fm, text );
|
||||||
|
height = Math.max( fm.getHeight(), height );
|
||||||
|
}
|
||||||
|
|
||||||
// accelerator size
|
// accelerator size
|
||||||
String accelText = getAcceleratorText();
|
String accelText = getAcceleratorText();
|
||||||
@@ -226,6 +234,12 @@ debug*/
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void paintText( Graphics g, Rectangle textRect, String text, Color selectionForeground, Color disabledForeground ) {
|
protected void paintText( Graphics g, Rectangle textRect, String text, Color selectionForeground, Color disabledForeground ) {
|
||||||
|
View htmlView = (View) menuItem.getClientProperty( BasicHTML.propertyKey );
|
||||||
|
if( htmlView != null ) {
|
||||||
|
htmlView.paint( g, textRect );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int mnemonicIndex = FlatLaf.isShowMnemonics() ? menuItem.getDisplayedMnemonicIndex() : -1;
|
int mnemonicIndex = FlatLaf.isShowMnemonics() ? menuItem.getDisplayedMnemonicIndex() : -1;
|
||||||
|
|
||||||
paintText( g, menuItem, textRect, text, mnemonicIndex, menuItem.getFont(),
|
paintText( g, menuItem, textRect, text, mnemonicIndex, menuItem.getFont(),
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ public class FlatMenusTest
|
|||||||
panel1.add(checkBoxMenuItemLabel, "cell 0 2");
|
panel1.add(checkBoxMenuItemLabel, "cell 0 2");
|
||||||
|
|
||||||
//---- checkBoxMenuItem1 ----
|
//---- checkBoxMenuItem1 ----
|
||||||
checkBoxMenuItem1.setText("enabled");
|
checkBoxMenuItem1.setText("<html>en<b>abl</b>ed</html>");
|
||||||
checkBoxMenuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
|
checkBoxMenuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
|
||||||
checkBoxMenuItem1.setMnemonic('A');
|
checkBoxMenuItem1.setMnemonic('A');
|
||||||
panel1.add(checkBoxMenuItem1, "cell 1 2");
|
panel1.add(checkBoxMenuItem1, "cell 1 2");
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ new FormModel {
|
|||||||
} )
|
} )
|
||||||
add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) {
|
add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) {
|
||||||
name: "checkBoxMenuItem1"
|
name: "checkBoxMenuItem1"
|
||||||
"text": "enabled"
|
"text": "<html>en<b>abl</b>ed</html>"
|
||||||
"accelerator": &KeyStroke0 static javax.swing.KeyStroke getKeyStroke( 112, 0, false )
|
"accelerator": &KeyStroke0 static javax.swing.KeyStroke getKeyStroke( 112, 0, false )
|
||||||
"mnemonic": 65
|
"mnemonic": 65
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user