Leo.Qin
12 months ago
23 changed files with 499 additions and 310 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,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