Browse Source

REPORT-107973 修改西区搜索面板以及toolbar间距

newui
Leo.Qin 11 months ago
parent
commit
bc891be86a
  1. 30
      designer-base/src/main/java/com/fr/design/data/datapane/management/search/pane/FineSearchPane.java
  2. 31
      designer-base/src/main/java/com/fr/design/gui/itextfield/UITextField.java
  3. 5
      designer-base/src/main/java/com/fr/design/gui/itoolbar/UIToolbar.java
  4. 91
      designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateTreeSearchToolbarPane.java
  5. 14
      designer-base/src/main/java/com/fr/design/menu/ToolBarDef.java

30
designer-base/src/main/java/com/fr/design/data/datapane/management/search/pane/FineSearchPane.java

@ -8,6 +8,7 @@ import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.itextfield.UITextField;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import java.awt.BorderLayout; import java.awt.BorderLayout;
@ -60,7 +61,24 @@ public class FineSearchPane extends JPanel implements HoverAware {
// 中间输入框 // 中间输入框
searchTextField = new UITextField(); searchTextField = new UITextField();
setStyle(searchTextField, TRANSPARENT_TEXT_FIELD); setStyle(searchTextField, TRANSPARENT_TEXT_FIELD);
searchTextField.addMouseListener(new MouseAdapter() {
// 右侧返回图标
clearButton = new UIButton(new LazyIcon("clear"));
setStyle(clearButton, STYLE_TEXT);
Insets buttonInsets = FineUIUtils.getAndScaleUIInsets("SearchPanel.buttonBorderInsets", defaultButtonInsets);
clearButton.setBorder(BorderFactory.createEmptyBorder(buttonInsets.top, buttonInsets.left, buttonInsets.bottom, buttonInsets.right));
this.add(searchLabel, BorderLayout.WEST);
this.add(searchTextField, BorderLayout.CENTER);
this.add(clearButton, BorderLayout.EAST);
addHoverStatusListener(searchLabel);
addHoverStatusListener(searchTextField);
addHoverStatusListener(clearButton);
}
private void addHoverStatusListener(JComponent component) {
component.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
hover = true; hover = true;
@ -73,16 +91,6 @@ public class FineSearchPane extends JPanel implements HoverAware {
repaint(); repaint();
} }
}); });
// 右侧返回图标
clearButton = new UIButton(new LazyIcon("clear"));
setStyle(clearButton, STYLE_TEXT);
Insets buttonInsets = FineUIUtils.getAndScaleUIInsets("SearchPanel.buttonBorderInsets", defaultButtonInsets);
clearButton.setBorder(BorderFactory.createEmptyBorder(buttonInsets.top, buttonInsets.left, buttonInsets.bottom, buttonInsets.right));
this.add(searchLabel, BorderLayout.WEST);
this.add(searchTextField, BorderLayout.CENTER);
this.add(clearButton, BorderLayout.EAST);
} }
@Override @Override

31
designer-base/src/main/java/com/fr/design/gui/itextfield/UITextField.java

@ -7,22 +7,20 @@ import com.fr.design.event.GlobalNameObserver;
import com.fr.design.event.HoverAware; import com.fr.design.event.HoverAware;
import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserver;
import com.fr.design.event.UIObserverListener; import com.fr.design.event.UIObserverListener;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.stable.Constants; import com.fr.stable.Constants;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import javax.swing.text.Document; import javax.swing.text.Document;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.LayoutManager;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import static com.formdev.flatlaf.FlatClientProperties.PLACEHOLDER_TEXT;
/** /**
* 文本框 * 文本框
@ -40,7 +38,6 @@ public class UITextField extends JTextField implements UIObserver, GlobalNameObs
private String textFieldName = StringUtils.EMPTY; private String textFieldName = StringUtils.EMPTY;
private GlobalNameListener globalNameListener = null; private GlobalNameListener globalNameListener = null;
private Dimension preferredSize = null; private Dimension preferredSize = null;
private String placeholder = StringUtils.EMPTY;
//有些情况下setText的时候不希望触发attributeChange,添加一个属性标识 //有些情况下setText的时候不希望触发attributeChange,添加一个属性标识
private boolean isSetting = false; private boolean isSetting = false;
@ -121,11 +118,11 @@ public class UITextField extends JTextField implements UIObserver, GlobalNameObs
} }
public String getPlaceholder() { public String getPlaceholder() {
return placeholder; return (String) this.getClientProperty(PLACEHOLDER_TEXT);
} }
public void setPlaceholder(String placeholder) { public void setPlaceholder(String placeholder) {
this.placeholder = placeholder; this.putClientProperty(PLACEHOLDER_TEXT, placeholder);
} }
@ -212,26 +209,6 @@ public class UITextField extends JTextField implements UIObserver, GlobalNameObs
return true; return true;
} }
/**
* 主函数
*
* @param args 参数
*/
public static void main(String... args) {
LayoutManager layoutManager = null;
JFrame jf = new JFrame("test");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel content = (JPanel) jf.getContentPane();
content.setLayout(layoutManager);
UITextField bb = new UITextField(5);
bb.setBounds(20, 20, bb.getPreferredSize().width, bb.getPreferredSize().height);
content.add(bb);
GUICoreUtils.centerWindow(jf);
jf.setSize(400, 400);
jf.setVisible(true);
}
public void setBorderPainted(boolean isBorderPainted) { public void setBorderPainted(boolean isBorderPainted) {
this.isBorderPainted = isBorderPainted; this.isBorderPainted = isBorderPainted;
} }

5
designer-base/src/main/java/com/fr/design/gui/itoolbar/UIToolbar.java

@ -1,5 +1,7 @@
package com.fr.design.gui.itoolbar; package com.fr.design.gui.itoolbar;
import com.fine.theme.utils.FineUIScale;
import javax.swing.JToolBar; import javax.swing.JToolBar;
import java.awt.Component; import java.awt.Component;
import java.awt.FlowLayout; import java.awt.FlowLayout;
@ -8,6 +10,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class UIToolbar extends JToolBar { public class UIToolbar extends JToolBar {
int hgap = 2;
public UIToolbar() { public UIToolbar() {
this(FlowLayout.LEFT); this(FlowLayout.LEFT);
@ -17,7 +20,7 @@ public class UIToolbar extends JToolBar {
super(); super();
setFloatable(false); setFloatable(false);
setRollover(true); setRollover(true);
setLayout(new FlowLayout(align, 4, 0)); setLayout(new FlowLayout(align, FineUIScale.scale(hgap), 0));
setBorderPainted(false); setBorderPainted(false);
} }

91
designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateTreeSearchToolbarPane.java

@ -1,13 +1,9 @@
package com.fr.design.mainframe.manager.search.searcher.control.pane; package com.fr.design.mainframe.manager.search.searcher.control.pane;
import com.fine.theme.icon.LazyIcon; import com.formdev.flatlaf.util.ScaledEmptyBorder;
import com.fr.base.svg.IconUtils; import com.fr.design.data.datapane.management.search.pane.FineSearchPane;
import com.fr.design.constants.UIConstants;
import com.fr.design.file.TemplateTreePane; import com.fr.design.file.TemplateTreePane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.gui.itoolbar.UIToolbar;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.manager.search.TemplateTreeSearchManager; import com.fr.design.mainframe.manager.search.TemplateTreeSearchManager;
import com.fr.design.search.TreeSearchStatus; import com.fr.design.search.TreeSearchStatus;
@ -15,20 +11,13 @@ import com.fr.design.search.event.TreeSearchStatusChangeEvent;
import com.fr.design.search.event.TreeSearchStatusChangeListener; import com.fr.design.search.event.TreeSearchStatusChangeListener;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.CardLayout; import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Insets;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
/** /**
* 模板搜索工具栏 * 模板搜索工具栏
@ -57,12 +46,7 @@ public class TemplateTreeSearchToolbarPane extends JPanel implements TreeSearchS
/** /**
* 搜索面板 * 搜索面板
*/ */
private JPanel searchPane; private FineSearchPane searchPane;
/**
* 搜索输入框
*/
private UITextField searchTextField;
/** /**
* 内容面板 * 内容面板
@ -78,7 +62,7 @@ public class TemplateTreeSearchToolbarPane extends JPanel implements TreeSearchS
@Override @Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) { if (e.getKeyCode() == KeyEvent.VK_ENTER) {
TemplateTreeSearchManager.getInstance().startSearch(searchTextField.getText()); TemplateTreeSearchManager.getInstance().startSearch(searchPane.getText());
} }
} }
}; };
@ -99,63 +83,24 @@ public class TemplateTreeSearchToolbarPane extends JPanel implements TreeSearchS
contentPane.add(searchPane, SEARCH_PANE); contentPane.add(searchPane, SEARCH_PANE);
contentPane.add(toolbarPane, TOOLBAR_PANE); contentPane.add(toolbarPane, TOOLBAR_PANE);
cardLayout.show(contentPane, TOOLBAR_PANE); cardLayout.show(contentPane, TOOLBAR_PANE);
contentPane.setBorder(new ScaledEmptyBorder(6, 8, 6, 8));
} }
private void initSearchPane() { private void initSearchPane() {
searchPane = new JPanel(FRGUIPaneFactory.createBorderLayout());
searchPane.setBorder(BorderFactory.createLineBorder(UIConstants.TOOLBAR_BORDER_COLOR)); searchPane = new FineSearchPane();
searchPane.setBackground(Color.WHITE); searchPane.setPlaceholder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Template_Search_Press_Enter_For_Search"));
// 左侧搜索图标
UILabel searchLabel = new UILabel(new LazyIcon("search")); initSearchTextFieldListener();
searchLabel.setBorder(BorderFactory.createEmptyBorder(0, 12, 0, 0));
searchLabel.addMouseListener(new MouseAdapter() { searchPane.addClearActionListener(e -> {
@Override
public void mouseClicked(MouseEvent e) {
// do nothing
}
});
// 中间输入框
initSearchTextField();
// 右侧返回图标
UILabel returnLabel = new UILabel(IconUtils.readIcon("/com/fr/design/standard/clear"));
returnLabel.setToolTipText(Toolkit.i18nText("Fine-Design_Tree_Search_Return"));
returnLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 11));
returnLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
TemplateTreeSearchManager.getInstance().outOfSearchMode(); TemplateTreeSearchManager.getInstance().outOfSearchMode();
TemplateTreePane.getInstance().refreshDockingView(); TemplateTreePane.getInstance().refreshDockingView();
}
}); });
searchPane.add(searchLabel, BorderLayout.WEST);
searchPane.add(searchTextField, BorderLayout.CENTER);
searchPane.add(returnLabel, BorderLayout.EAST);
}
private void initSearchTextField() {
searchTextField = new UITextField(){
@Override
public Insets getInsets() {
return new Insets(2, 4, 0, 4);
}
};
searchTextField.setBorderPainted(false);
searchTextField.setPlaceholder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Template_Search_Press_Enter_For_Search"));
searchTextField.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
searchPane.setBorder(BorderFactory.createLineBorder(UIConstants.NORMAL_BLUE));
searchPane.repaint();
} }
@Override private void initSearchTextFieldListener() {
public void focusLost(FocusEvent e) { searchPane.addDocumentListener(new DocumentListener() {
searchPane.setBorder(BorderFactory.createLineBorder(UIConstants.TOOLBAR_BORDER_COLOR));
searchPane.repaint();
}
});
this.searchTextField.getDocument().addDocumentListener(new DocumentListener() {
@Override @Override
public void insertUpdate(DocumentEvent e) { public void insertUpdate(DocumentEvent e) {
} }
@ -169,11 +114,11 @@ public class TemplateTreeSearchToolbarPane extends JPanel implements TreeSearchS
public void changedUpdate(DocumentEvent e) { public void changedUpdate(DocumentEvent e) {
} }
}); });
this.searchTextField.addKeyListener(enterPressed); searchPane.addKeyListener(enterPressed);
} }
private void dealWithTextChange() { private void dealWithTextChange() {
if (StringUtils.isEmpty(searchTextField.getText()) && TemplateTreeSearchManager.getInstance().isInSearchMode()) { if (StringUtils.isEmpty(searchPane.getText()) && TemplateTreeSearchManager.getInstance().isInSearchMode()) {
// 如果是搜索模式下,看作是用户删除输入框文字,仅复原TemplateTreePane // 如果是搜索模式下,看作是用户删除输入框文字,仅复原TemplateTreePane
TemplateTreeSearchManager.getInstance().restoreTreePane(); TemplateTreeSearchManager.getInstance().restoreTreePane();
TemplateTreePane.getInstance().refreshDockingView(); TemplateTreePane.getInstance().refreshDockingView();
@ -195,7 +140,7 @@ public class TemplateTreeSearchToolbarPane extends JPanel implements TreeSearchS
} }
public void setPlaceHolder(String placeHolder) { public void setPlaceHolder(String placeHolder) {
this.searchTextField.setPlaceholder(placeHolder); this.searchPane.setPlaceholder(placeHolder);
} }
/** /**
@ -207,7 +152,7 @@ public class TemplateTreeSearchToolbarPane extends JPanel implements TreeSearchS
public void updateTreeSearchChange(TreeSearchStatusChangeEvent event) { public void updateTreeSearchChange(TreeSearchStatusChangeEvent event) {
TreeSearchStatus treeSearchStatus = event.getTreeSearchStatus(); TreeSearchStatus treeSearchStatus = event.getTreeSearchStatus();
if (treeSearchStatus == TreeSearchStatus.NOT_IN_SEARCH_MODE) { if (treeSearchStatus == TreeSearchStatus.NOT_IN_SEARCH_MODE) {
this.searchTextField.setText(StringUtils.EMPTY); searchPane.setText(StringUtils.EMPTY);
switchPane(TOOLBAR_PANE); switchPane(TOOLBAR_PANE);
} else { } else {
switchPane(SEARCH_PANE); switchPane(SEARCH_PANE);

14
designer-base/src/main/java/com/fr/design/menu/ToolBarDef.java

@ -5,14 +5,18 @@ import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.gui.itoolbar.UIToolBarUI; import com.fr.design.gui.itoolbar.UIToolBarUI;
import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.gui.itoolbar.UIToolbar;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import java.util.Set;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import javax.swing.*; import javax.swing.BorderFactory;
import java.awt.*; import javax.swing.JComponent;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* Define toolbar.. * Define toolbar..
@ -43,9 +47,7 @@ public class ToolBarDef {
* 一个static的方法生成一个JToolBar * 一个static的方法生成一个JToolBar
*/ */
public static UIToolbar createJToolBar() { public static UIToolbar createJToolBar() {
UIToolbar toolbar = new UIToolbar(FlowLayout.LEFT); return new UIToolbar(FlowLayout.LEFT);
toolbar.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
return toolbar;
} }
public ToolBarDef() { public ToolBarDef() {

Loading…
Cancel
Save