Browse Source
Merge in DESIGN/design from ~LEO.QIN/design:newui to newui * commit 'af5775815287bd35b08fe7cf27303bebb2bfd563': REPORT-107973 回退透明按钮 REPORT-107973 翻新上下文菜单弹窗。透明按钮 REPORT-107973 翻新上下文菜单弹窗newui
Leo.Qin-覃宇攀
12 months ago
19 changed files with 362 additions and 70 deletions
@ -0,0 +1,41 @@
|
||||
package com.fine.theme.light.ui; |
||||
|
||||
import com.fine.theme.utils.FineClientProperties; |
||||
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) { |
||||
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,40 @@
|
||||
package com.fine.theme.light.ui; |
||||
|
||||
import com.fine.theme.icon.LazyIcon; |
||||
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) { |
||||
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,103 @@
|
||||
package com.fr.design.gui.storybook.components; |
||||
|
||||
import com.fine.theme.icon.LazyIcon; |
||||
import com.fine.theme.utils.FineUIStyle; |
||||
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; |
||||
import static com.fine.theme.utils.FineUIStyle.setStyle; |
||||
|
||||
/** |
||||
* 弹窗组件 |
||||
* |
||||
* @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) { |
||||
setStyle(jPopupMenu, FineUIStyle.POPUP_MENU_TOOL_BAR); |
||||
|
||||
MenuElement[] subElements = jPopupMenu.getSubElements(); |
||||
for (MenuElement subElement : subElements) { |
||||
if (subElement instanceof JMenu) { |
||||
JMenu jMenu = (JMenu) subElement; |
||||
JPopupMenu childPopupMenu = jMenu.getPopupMenu(); |
||||
setStyle(jMenu, FineUIStyle.MENU_TOOL_BAR); |
||||
setToolBarClientProperty(childPopupMenu); |
||||
} else if (subElement instanceof JMenuItem) { |
||||
JMenuItem jMenuItem = (JMenuItem) subElement; |
||||
setStyle(jMenuItem, FineUIStyle.MENU_ITEM_TOOL_BAR); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue