vito
12 months ago
6 changed files with 235 additions and 262 deletions
@ -0,0 +1,52 @@
|
||||
package com.fine.theme.light.ui; |
||||
|
||||
import com.formdev.flatlaf.ui.FlatUIUtils; |
||||
|
||||
import javax.swing.JComponent; |
||||
import javax.swing.plaf.ComponentUI; |
||||
import javax.swing.plaf.PanelUI; |
||||
import java.awt.Color; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.Insets; |
||||
import java.awt.geom.RoundRectangle2D; |
||||
|
||||
/** |
||||
* 模版列表菜单ui |
||||
* |
||||
* @author vito |
||||
* @since 11.0 |
||||
* Created on 2024/1/11 |
||||
*/ |
||||
public class FineTemplateListMenuItemUI extends PanelUI { |
||||
/** |
||||
* 创建UI |
||||
* |
||||
* @param c 组件 |
||||
* @return ComponentUI |
||||
*/ |
||||
public static ComponentUI createUI(JComponent c) { |
||||
return new FineTemplateListMenuItemUI(); |
||||
} |
||||
|
||||
@Override |
||||
public void update(Graphics g, JComponent c) { |
||||
Color color = g.getColor(); |
||||
g.setColor(c.getBackground()); |
||||
Insets insets = c.getInsets(); |
||||
Object[] old = FlatUIUtils.setRenderingHints(g); |
||||
((Graphics2D) g).fill(new RoundRectangle2D.Float( |
||||
insets.left, insets.top, |
||||
(float) c.getWidth() - insets.left - insets.right, |
||||
(float) c.getHeight() - insets.top - insets.bottom, |
||||
3, 3)); |
||||
g.setColor(color); |
||||
FlatUIUtils.resetRenderingHints(g, old); |
||||
super.paint(g, c); |
||||
} |
||||
|
||||
@Override |
||||
public void uninstallUI(JComponent c) { |
||||
super.uninstallUI(c); |
||||
} |
||||
} |
@ -0,0 +1,153 @@
|
||||
package com.fr.design.file; |
||||
|
||||
/** |
||||
* @author vito |
||||
* @since 11.0 |
||||
* Created on 2024/1/11 |
||||
*/ |
||||
|
||||
import com.fine.swing.ui.layout.Row; |
||||
import com.fine.theme.icon.LazyIcon; |
||||
import com.fine.theme.utils.FineUIScale; |
||||
import com.formdev.flatlaf.util.ScaledEmptyBorder; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.design.utils.TemplateUtils; |
||||
|
||||
import javax.swing.JPopupMenu; |
||||
import javax.swing.SwingConstants; |
||||
import javax.swing.UIManager; |
||||
import java.awt.Dimension; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
|
||||
import static com.fine.swing.ui.layout.Layouts.cell; |
||||
|
||||
/** |
||||
* menu的item由模板图标、模板名、模板关闭按钮组成 |
||||
* |
||||
* @author vito |
||||
* @since 9.0 |
||||
* Created on 2015.1 |
||||
*/ |
||||
public class TemplateListMenuItem extends Row { |
||||
private static final String UI_CLASS_ID = "TemplateListMenuItemUI"; |
||||
|
||||
private static final int WIDTH = 200; |
||||
|
||||
private final UIButton templateButton; |
||||
private final UIButton closeButton; |
||||
private final JPopupMenu menu; |
||||
|
||||
public TemplateListMenuItem(JPopupMenu menu, JTemplate<?, ?> template) { |
||||
this.menu = menu; |
||||
templateButton = createTemplateButton(template); |
||||
closeButton = createCloseButton(); |
||||
add( |
||||
cell(templateButton).weight(1), |
||||
cell(closeButton) |
||||
); |
||||
setBorder(new ScaledEmptyBorder(0, 4, 0, 4)); |
||||
setPreferredSize(new Dimension(FineUIScale.scale(WIDTH), templateButton.getPreferredSize().height)); |
||||
initListener(template); |
||||
} |
||||
|
||||
@Override |
||||
public String getUIClassID() { |
||||
return UI_CLASS_ID; |
||||
} |
||||
|
||||
/** |
||||
* item[1] 切换模板按钮初始化 |
||||
*/ |
||||
private UIButton createTemplateButton(JTemplate<?, ?> template) { |
||||
UIButton button = new UIButton( |
||||
TemplateUtils.createLockeTemplatedName(template, template.getTemplateName()), template.getIcon()); |
||||
button.setContentAreaFilled(false); |
||||
button.setHorizontalAlignment(SwingConstants.LEFT); |
||||
return button; |
||||
} |
||||
|
||||
/** |
||||
* item[2] 关闭模板图标按钮初始化 |
||||
*/ |
||||
private UIButton createCloseButton() { |
||||
UIButton button = new UIButton( |
||||
new LazyIcon("clear"), |
||||
new LazyIcon("clear_hover"), |
||||
new LazyIcon("clear_hover")); |
||||
button.setContentAreaFilled(false); |
||||
button.setVisible(false); |
||||
return button; |
||||
} |
||||
|
||||
private void initListener(JTemplate<?, ?> template) { |
||||
initTemplateButtonListener(template); |
||||
initCloseButtonListener(template); |
||||
} |
||||
|
||||
/** |
||||
* item[1] 切换模板按钮鼠标事件 |
||||
*/ |
||||
private void initTemplateButtonListener(JTemplate<?, ?> template) { |
||||
templateButton.addMouseListener(new MouseAdapter() { |
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
menu.setVisible(false); |
||||
MultiTemplateTabPane.getInstance().switchJTemplate(template); |
||||
} |
||||
|
||||
@Override |
||||
public void mouseEntered(MouseEvent e) { |
||||
fireMouseEnteredEvent(); |
||||
} |
||||
|
||||
@Override |
||||
public void mouseExited(MouseEvent e) { |
||||
fireMouseExitedEvent(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* item[2] 关闭模板按钮鼠标事件 |
||||
*/ |
||||
private void initCloseButtonListener(JTemplate<?, ?> template) { |
||||
closeButton.addMouseListener(new MouseAdapter() { |
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
menu.setVisible(false); |
||||
MultiTemplateTabPane.getInstance().setIsCloseCurrent(template == HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()); |
||||
MultiTemplateTabPane.getInstance().closeFormat(template); |
||||
MultiTemplateTabPane.getInstance().closeSpecifiedTemplate(template); |
||||
} |
||||
|
||||
@Override |
||||
public void mouseEntered(MouseEvent e) { |
||||
fireMouseEnteredEvent(); |
||||
} |
||||
|
||||
@Override |
||||
public void mouseExited(MouseEvent e) { |
||||
fireMouseExitedEvent(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* mouse移入item范围 |
||||
*/ |
||||
private void fireMouseEnteredEvent() { |
||||
TemplateListMenuItem.this.setBackground(UIManager.getColor("MenuItem.selectionBackground")); |
||||
closeButton.setVisible(true); |
||||
} |
||||
|
||||
/** |
||||
* mouse移出item范围 |
||||
*/ |
||||
private void fireMouseExitedEvent() { |
||||
TemplateListMenuItem.this.setBackground(TemplateListMenuItem.this.getParent().getBackground()); |
||||
closeButton.setVisible(false); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue