Browse Source
Merge in DESIGN/design from ~LEO.QIN/design:newui to newui * commit '5c0b50211829dd2bfbd9c30d8dc0c44973173e16': 改一下代码质量 REPORT-107973 主页及组件视觉样式翻新 【问题原因】rt 【改动思路】翻新:数字步进、搜索框、BaseAccessibleEditor、popupTool面板,部分文本框组件高度 REPORT-107973 主页及组件视觉样式翻新 【问题原因】rt 【改动思路】tooltip翻新newui
Leo.Qin-覃宇攀
12 months ago
24 changed files with 631 additions and 316 deletions
@ -0,0 +1,80 @@
|
||||
package com.fine.theme.light.ui; |
||||
|
||||
import com.formdev.flatlaf.ui.FlatButtonUI; |
||||
import com.formdev.flatlaf.ui.FlatPanelUI; |
||||
|
||||
import javax.swing.AbstractButton; |
||||
import javax.swing.JComponent; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.UIManager; |
||||
import javax.swing.plaf.ComponentUI; |
||||
|
||||
/** |
||||
* Input输入框 UI类 |
||||
* |
||||
* @author Leo.Qin |
||||
* @since 11.0 |
||||
* Created on 2023/12/11 |
||||
*/ |
||||
public class FineInputUI extends FlatPanelUI { |
||||
|
||||
public FineInputUI(boolean shared) { |
||||
super(shared); |
||||
} |
||||
|
||||
/** |
||||
* 创建UI |
||||
*/ |
||||
public static ComponentUI createUI(JComponent c) { |
||||
return new FineInputUI(false); |
||||
} |
||||
|
||||
@Override |
||||
public void installUI(JComponent c) { |
||||
super.installUI(c); |
||||
c.setBackground(UIManager.getColor("Input.background")); |
||||
c.setBorder(UIManager.getBorder("Input.border")); |
||||
} |
||||
|
||||
@Override |
||||
protected void installDefaults(JPanel p) { |
||||
super.installDefaults(p); |
||||
arc = UIManager.getInt("Input.arc"); |
||||
} |
||||
|
||||
/** |
||||
* input输入框中的Button UI类 |
||||
* |
||||
* @author Leo.Qin |
||||
* @since 11.0 |
||||
* Created on 2023/12/12 |
||||
*/ |
||||
public static class FineInputButtonUI extends FlatButtonUI { |
||||
|
||||
public FineInputButtonUI(boolean shared) { |
||||
super(shared); |
||||
} |
||||
|
||||
/** |
||||
* 创建UI |
||||
*/ |
||||
public static ComponentUI createUI(JComponent c) { |
||||
return new FineInputButtonUI(false); |
||||
} |
||||
|
||||
@Override |
||||
public void installUI(JComponent c) { |
||||
super.installUI(c); |
||||
c.setBorder(null); |
||||
c.setOpaque(false); |
||||
} |
||||
|
||||
@Override |
||||
protected void installDefaults(AbstractButton b) { |
||||
super.installDefaults(b); |
||||
hoverBackground = UIManager.getColor("InputButton.hoverBackground"); |
||||
pressedBackground = UIManager.getColor("InputButton.pressedBackground"); |
||||
background = UIManager.getColor("InputButton.background"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,97 @@
|
||||
package com.fine.theme.light.ui; |
||||
|
||||
import com.formdev.flatlaf.ui.FlatToolTipUI; |
||||
import com.formdev.flatlaf.ui.FlatUIUtils; |
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.stable.Constants; |
||||
|
||||
import javax.swing.JComponent; |
||||
import javax.swing.JToolTip; |
||||
import javax.swing.SwingUtilities; |
||||
import javax.swing.UIManager; |
||||
import javax.swing.plaf.ComponentUI; |
||||
import java.awt.Dimension; |
||||
import java.awt.FontMetrics; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.Insets; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* ToolTip UI类 |
||||
* |
||||
* @author Leo.Qin |
||||
* @since 11.0 |
||||
* Created on 2023/12/8 |
||||
*/ |
||||
public class FineTooltipUI extends FlatToolTipUI { |
||||
private int maxWidth; |
||||
private int arc; |
||||
private List<String> lines; |
||||
|
||||
/** |
||||
* 创建UI |
||||
*/ |
||||
public static ComponentUI createUI(JComponent c) { |
||||
return FlatUIUtils.createSharedUI(FineTooltipUI.class, FineTooltipUI::new); |
||||
} |
||||
|
||||
@Override |
||||
public void paint(Graphics g, JComponent c) { |
||||
|
||||
g.setColor(c.getBackground()); |
||||
g.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), arc, arc); |
||||
|
||||
String text = ((JToolTip) c).getTipText(); |
||||
if (text == null || text.isEmpty()) { |
||||
return; |
||||
} |
||||
|
||||
Insets insets = c.getInsets(); |
||||
Graphics2D g2d = (Graphics2D) g; |
||||
FontMetrics fm = g2d.getFontMetrics(); |
||||
|
||||
int x = insets.left; |
||||
int y = insets.top + fm.getAscent(); |
||||
|
||||
g2d.setColor(c.getForeground()); |
||||
|
||||
for (String line : lines) { |
||||
g2d.drawString(line, x, y); |
||||
y += fm.getHeight(); |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void installDefaults(JComponent c) { |
||||
super.installDefaults(c); |
||||
c.setOpaque(false); |
||||
arc = UIManager.getInt("ToolTip.arc"); |
||||
maxWidth = UIManager.getInt("ToolTip.maxWidth"); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public Dimension getPreferredSize(JComponent c) { |
||||
String text = ((JToolTip) c).getTipText(); |
||||
if (text == null || text.isEmpty()) { |
||||
return new Dimension(); |
||||
} |
||||
|
||||
Insets insets = c.getInsets(); |
||||
int fontWidth = this.maxWidth - insets.left - insets.right; |
||||
lines = BaseUtils.getLineTextList(text, null, null, fontWidth, Constants.FR_PAINT_RESOLUTION); |
||||
|
||||
FontMetrics fm = c.getFontMetrics(c.getFont()); |
||||
|
||||
int width = 0; |
||||
int height = fm.getHeight() * Math.max(lines.size(), 1); |
||||
for (String line : lines) { |
||||
width = Math.max(width, SwingUtilities.computeStringWidth(fm, line)); |
||||
} |
||||
|
||||
return new Dimension(insets.left + width + insets.right, insets.top + height + insets.bottom); |
||||
} |
||||
} |
@ -0,0 +1,125 @@
|
||||
package com.fr.design.data.datapane.management.search.pane; |
||||
|
||||
import com.fine.theme.icon.LazyIcon; |
||||
import com.fine.theme.light.ui.FineInputUI; |
||||
import com.fr.design.event.HoverAware; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.UIManager; |
||||
import javax.swing.event.DocumentListener; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.Insets; |
||||
import java.awt.event.ActionListener; |
||||
import java.awt.event.KeyListener; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
|
||||
/** |
||||
* 搜索面板 |
||||
* |
||||
* @author Leo.Qin |
||||
* @since 11.0 |
||||
* Created on 2023/12/13 |
||||
*/ |
||||
public class FineSearchPane extends JPanel implements HoverAware { |
||||
|
||||
private static final Insets LABEL_INSETS = UIManager.getInsets("SearchPanel.labelBorderInsets"); |
||||
private static final Insets BUTTON_INSETS = UIManager.getInsets("SearchPanel.buttonBorderInsets"); |
||||
|
||||
private UITextField searchTextField; |
||||
private UIButton clearButton; |
||||
|
||||
private boolean hover; |
||||
|
||||
public FineSearchPane() { |
||||
this.setLayout(new BorderLayout()); |
||||
this.setUI(new FineInputUI(false)); |
||||
|
||||
initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
// 左侧搜索图标
|
||||
UILabel searchLabel = new UILabel(new LazyIcon("search")); |
||||
searchLabel.setBorder(BorderFactory.createEmptyBorder(LABEL_INSETS.top, LABEL_INSETS.left, LABEL_INSETS.bottom, LABEL_INSETS.right)); |
||||
|
||||
// 中间输入框
|
||||
searchTextField = new UITextField(); |
||||
searchTextField.setBorder(null); |
||||
searchTextField.setOpaque(false); |
||||
searchTextField.addMouseListener(new MouseAdapter() { |
||||
@Override |
||||
public void mouseEntered(MouseEvent e) { |
||||
hover = true; |
||||
repaint(); |
||||
} |
||||
|
||||
@Override |
||||
public void mouseExited(MouseEvent e) { |
||||
hover = false; |
||||
repaint(); |
||||
} |
||||
}); |
||||
|
||||
// 右侧返回图标
|
||||
clearButton = new UIButton(new LazyIcon("clear")); |
||||
clearButton.setUI(new FineInputUI.FineInputButtonUI(false)); |
||||
clearButton.setBorder(BorderFactory.createEmptyBorder(BUTTON_INSETS.top, BUTTON_INSETS.left, BUTTON_INSETS.bottom, BUTTON_INSETS.right)); |
||||
|
||||
this.add(searchLabel, BorderLayout.WEST); |
||||
this.add(searchTextField, BorderLayout.CENTER); |
||||
this.add(clearButton, BorderLayout.EAST); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isHovered() { |
||||
return hover; |
||||
} |
||||
|
||||
/** |
||||
* 添加KeyListener |
||||
* |
||||
* @param listener the key listener. |
||||
*/ |
||||
public void addKeyListener(KeyListener listener) { |
||||
searchTextField.addKeyListener(listener); |
||||
} |
||||
|
||||
public void setPlaceholder(String placeHolder) { |
||||
searchTextField.setPlaceholder(placeHolder); |
||||
} |
||||
|
||||
public void setClearToolTipText(String text) { |
||||
clearButton.setToolTipText(text); |
||||
} |
||||
|
||||
/** |
||||
* 添加DocumentListener |
||||
* |
||||
* @param listener |
||||
*/ |
||||
public void addDocumentListener(DocumentListener listener) { |
||||
searchTextField.getDocument().addDocumentListener(listener); |
||||
} |
||||
|
||||
/** |
||||
* 按钮添加监听器 |
||||
* |
||||
* @param listener |
||||
*/ |
||||
public void addClearActionListener(ActionListener listener) { |
||||
clearButton.addActionListener(listener); |
||||
} |
||||
|
||||
public String getText() { |
||||
return searchTextField.getText(); |
||||
} |
||||
|
||||
public void setText(String text) { |
||||
searchTextField.setText(text); |
||||
} |
||||
} |
After Width: | Height: | Size: 718 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 720 B |
After Width: | Height: | Size: 593 B |
After Width: | Height: | Size: 436 B |
Loading…
Reference in new issue