Leo.Qin
10 months ago
18 changed files with 375 additions and 70 deletions
@ -0,0 +1,50 @@
|
||||
package com.fine.theme.light.ui; |
||||
|
||||
import com.fine.theme.utils.FineClientProperties; |
||||
import com.fine.theme.utils.FineUIUtils; |
||||
import com.formdev.flatlaf.ui.FlatMenuItemUI; |
||||
import com.fr.design.editlock.EditLockUtils; |
||||
|
||||
import javax.swing.JComponent; |
||||
import javax.swing.plaf.ComponentUI; |
||||
import java.awt.Graphics; |
||||
|
||||
/** |
||||
* menuItem UI类 |
||||
* |
||||
* @author Leo.Qin |
||||
* @since 11.0 |
||||
* Created on 2024/1/8 |
||||
*/ |
||||
public class FineMenuItemUI extends FlatMenuItemUI { |
||||
int iconSize = 16; |
||||
int rightMargin = 10; |
||||
|
||||
/** |
||||
* 创建UI |
||||
* |
||||
* @param c |
||||
* @return |
||||
*/ |
||||
public static ComponentUI createUI(JComponent c) { |
||||
return new FineMenuItemUI(); |
||||
} |
||||
|
||||
@Override |
||||
public void paint(Graphics g, JComponent c) { |
||||
Object clientProperty = c.getClientProperty(FineClientProperties.POPUP_MENU_TYPE); |
||||
if (FineClientProperties.POPUP_MENU_TYPE_TOOL_BAR.equals(clientProperty)) { |
||||
selectionBackground = FineUIUtils.getUIColor("Menu.toolbar.selectionBackground", "Menu.selectionBackground"); |
||||
selectionForeground = FineUIUtils.getUIColor("Menu.toolbar.selectionForeground", "Menu.selectionForeground"); |
||||
acceleratorForeground = FineUIUtils.getUIColor("Menu.toolbar.acceleratorForeground", "Menu.acceleratorForeground"); |
||||
acceleratorSelectionForeground = FineUIUtils.getUIColor("Menu.toolbar.acceleratorSelectionForeground", "Menu.acceleratorSelectionForeground"); |
||||
} |
||||
|
||||
super.paint(g, c); |
||||
|
||||
Object itemType = c.getClientProperty(FineClientProperties.MENU_ITEM_TYPE); |
||||
if (FineClientProperties.MENU_ITEM_TYPE_LOCK.equals(itemType)) { |
||||
g.drawImage(EditLockUtils.LOCKED_IMAGE, c.getWidth() - rightMargin - iconSize, (c.getHeight() - iconSize) / 2, iconSize, iconSize, null); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,49 @@
|
||||
package com.fine.theme.light.ui; |
||||
|
||||
import com.fine.theme.icon.LazyIcon; |
||||
import com.fine.theme.utils.FineClientProperties; |
||||
import com.fine.theme.utils.FineUIUtils; |
||||
import com.formdev.flatlaf.ui.FlatMenuUI; |
||||
|
||||
import javax.swing.JComponent; |
||||
import javax.swing.plaf.ComponentUI; |
||||
import java.awt.Graphics; |
||||
|
||||
/** |
||||
* 弹窗菜单UI |
||||
* |
||||
* @author Leo.Qin |
||||
* @since 11.0 |
||||
* Created on 2024/1/8 |
||||
*/ |
||||
public class FineMenuUI extends FlatMenuUI { |
||||
|
||||
|
||||
/** |
||||
* 创建UI |
||||
* |
||||
* @param c |
||||
* @return |
||||
*/ |
||||
public static ComponentUI createUI(JComponent c) { |
||||
return new FineMenuUI(); |
||||
} |
||||
|
||||
@Override |
||||
protected void installDefaults() { |
||||
arrowIcon = new LazyIcon("triangle_right"); |
||||
super.installDefaults(); |
||||
} |
||||
|
||||
@Override |
||||
public void paint(Graphics g, JComponent c) { |
||||
Object clientProperty = c.getClientProperty(FineClientProperties.POPUP_MENU_TYPE); |
||||
if (FineClientProperties.POPUP_MENU_TYPE_TOOL_BAR.equals(clientProperty)) { |
||||
selectionBackground = FineUIUtils.getUIColor("MenuItem.toolbar.selectionBackground", "MenuItem.selectionBackground"); |
||||
selectionForeground = FineUIUtils.getUIColor("MenuItem.toolbar.selectionForeground", "MenuItem.selectionForeground"); |
||||
acceleratorForeground = FineUIUtils.getUIColor("MenuItem.toolbar.acceleratorForeground", "MenuItem.acceleratorForeground"); |
||||
acceleratorSelectionForeground = FineUIUtils.getUIColor("MenuItem.toolbar.acceleratorSelectionForeground", "MenuItem.acceleratorSelectionForeground"); |
||||
} |
||||
super.paint(g, c); |
||||
} |
||||
} |
@ -0,0 +1,70 @@
|
||||
package com.fine.theme.light.ui; |
||||
|
||||
import com.fine.theme.utils.FineUIUtils; |
||||
import com.formdev.flatlaf.ui.FlatPopupMenuSeparatorUI; |
||||
import com.formdev.flatlaf.ui.FlatUIUtils; |
||||
|
||||
import javax.swing.JComponent; |
||||
import javax.swing.JSeparator; |
||||
import javax.swing.plaf.ComponentUI; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.Insets; |
||||
import java.awt.geom.Rectangle2D; |
||||
|
||||
import static com.formdev.flatlaf.util.UIScale.scale; |
||||
|
||||
/** |
||||
* popup弹窗分割线UI |
||||
* |
||||
* @author Leo.Qin |
||||
* @since 11.0 |
||||
* Created on 2024/1/8 |
||||
*/ |
||||
public class FinePopupMenuSeparatorUI extends FlatPopupMenuSeparatorUI { |
||||
protected Insets insets; |
||||
|
||||
/** |
||||
* @param shared |
||||
* @since 2 |
||||
*/ |
||||
protected FinePopupMenuSeparatorUI(boolean shared) { |
||||
super(shared); |
||||
} |
||||
|
||||
/** |
||||
* 创建UI类 |
||||
* |
||||
* @param c |
||||
* @return |
||||
*/ |
||||
public static ComponentUI createUI(JComponent c) { |
||||
return new FinePopupMenuSeparatorUI(false); |
||||
} |
||||
|
||||
@Override |
||||
protected void installDefaults(JSeparator s) { |
||||
super.installDefaults(s); |
||||
insets = FineUIUtils.getAndScaleUIInsets("PopupMenuSeparator.Insets", new Insets(0, 10, 0, 10)); |
||||
} |
||||
|
||||
@Override |
||||
public void paint(Graphics g, JComponent c) { |
||||
Graphics2D g2 = (Graphics2D) g.create(); |
||||
try { |
||||
FlatUIUtils.setRenderingHints(g2); |
||||
g2.setColor(c.getForeground()); |
||||
|
||||
float width = scale((float) stripeWidth); |
||||
float indent = scale((float) stripeIndent); |
||||
|
||||
if (((JSeparator) c).getOrientation() == JSeparator.VERTICAL) { |
||||
g2.fill(new Rectangle2D.Float(indent, insets.left, width - (insets.left + insets.right), c.getHeight())); |
||||
} else { |
||||
g2.fill(new Rectangle2D.Float(insets.left, indent, c.getWidth() - (insets.left + insets.right), width)); |
||||
} |
||||
} finally { |
||||
g2.dispose(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,102 @@
|
||||
package com.fr.design.gui.storybook.components; |
||||
|
||||
import com.fine.theme.icon.LazyIcon; |
||||
import com.fine.theme.utils.FineClientProperties; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.imenu.UIMenuItem; |
||||
import com.fr.design.gui.imenu.UIPopupMenu; |
||||
import com.fr.design.gui.storybook.Story; |
||||
import com.fr.design.gui.storybook.StoryBoard; |
||||
import com.fr.design.menu.DottedSeparator; |
||||
import com.fr.design.menu.NameSeparator; |
||||
|
||||
import javax.swing.JMenu; |
||||
import javax.swing.JMenuItem; |
||||
import javax.swing.JPopupMenu; |
||||
import javax.swing.MenuElement; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
|
||||
import static com.fine.swing.ui.layout.Layouts.cell; |
||||
import static com.fine.swing.ui.layout.Layouts.column; |
||||
|
||||
/** |
||||
* 弹窗组件 |
||||
* |
||||
* @author Leo.Qin |
||||
* @since 11.0 |
||||
* Created on 2024/1/8 |
||||
*/ |
||||
@Story |
||||
public class PopupMenuStoryBoard extends StoryBoard { |
||||
public PopupMenuStoryBoard() { |
||||
super("弹窗"); |
||||
add( |
||||
column(70, |
||||
cell(new UIButton("点击展示弹窗")).with(it -> { |
||||
UIPopupMenu popupMenu = new UIPopupMenu(); |
||||
popupMenu.add(new UIMenuItem("test1", new LazyIcon("edit"))); |
||||
popupMenu.add(new UIMenuItem("test2", new LazyIcon("cellHyperLinkAttr"))); |
||||
popupMenu.addSeparator(); |
||||
popupMenu.add(new UIMenuItem("test3", new LazyIcon("cellClear"))); |
||||
popupMenu.add(new NameSeparator("分割线").createMenuItem()); |
||||
popupMenu.add(new UIMenuItem("test4", new LazyIcon("cellOtherAttr"))); |
||||
popupMenu.add(new DottedSeparator().createMenuItem()); |
||||
popupMenu.add(new UIMenuItem("test5", new LazyIcon("cellExpandAttr"))); |
||||
|
||||
it.addMouseListener(new MouseAdapter() { |
||||
|
||||
|
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
popupMenu.show(it, e.getX(), e.getY()); |
||||
} |
||||
}); |
||||
}), |
||||
|
||||
cell(new UIButton("点击展示菜单栏弹窗")).with(it -> { |
||||
UIPopupMenu popupMenu = new UIPopupMenu(); |
||||
popupMenu.add(new UIMenuItem("test1", new LazyIcon("edit"))); |
||||
popupMenu.add(new UIMenuItem("test2", new LazyIcon("cellHyperLinkAttr"))); |
||||
popupMenu.addSeparator(); |
||||
popupMenu.add(new UIMenuItem("test3", new LazyIcon("cellClear"))); |
||||
popupMenu.add(new NameSeparator("分割线").createMenuItem()); |
||||
popupMenu.add(new UIMenuItem("test4", new LazyIcon("cellOtherAttr"))); |
||||
popupMenu.add(new DottedSeparator().createMenuItem()); |
||||
popupMenu.add(new UIMenuItem("test5", new LazyIcon("cellExpandAttr"))); |
||||
|
||||
it.addMouseListener(new MouseAdapter() { |
||||
|
||||
|
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
popupMenu.show(it, e.getX(), e.getY()); |
||||
} |
||||
}); |
||||
|
||||
setToolBarClientProperty(popupMenu); |
||||
}) |
||||
) |
||||
); |
||||
|
||||
} |
||||
|
||||
|
||||
private void setToolBarClientProperty(JPopupMenu jPopupMenu) { |
||||
jPopupMenu.putClientProperty(FineClientProperties.POPUP_MENU_TYPE, FineClientProperties.POPUP_MENU_TYPE_TOOL_BAR); |
||||
|
||||
MenuElement[] subElements = jPopupMenu.getSubElements(); |
||||
for (MenuElement subElement : subElements) { |
||||
if (subElement instanceof JMenu) { |
||||
JMenu jMenu = (JMenu) subElement; |
||||
jMenu.putClientProperty(FineClientProperties.POPUP_MENU_TYPE, FineClientProperties.POPUP_MENU_TYPE_TOOL_BAR); |
||||
JPopupMenu childPopupMenu = jMenu.getPopupMenu(); |
||||
setToolBarClientProperty(childPopupMenu); |
||||
} else if (subElement instanceof JMenuItem) { |
||||
JMenuItem jMenuItem = (JMenuItem) subElement; |
||||
jMenuItem.putClientProperty(FineClientProperties.POPUP_MENU_TYPE, FineClientProperties.POPUP_MENU_TYPE_TOOL_BAR); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue