Browse Source

REPORT-107972 设计器样式翻新-UIComboBox翻新

newui
Levy.Xie-解安森 1 year ago
parent
commit
faff0f3959
  1. 41
      designer-base/src/main/java/com/fine/theme/light/ui/FineComboBoxUI.java
  2. 1
      designer-base/src/main/java/com/fine/theme/light/ui/FineLightIconSet.java
  3. 13
      designer-base/src/main/java/com/fr/design/event/HoverAware.java
  4. 4
      designer-base/src/main/java/com/fr/design/gui/icombobox/ExtendedComboBox.java
  5. 78
      designer-base/src/main/java/com/fr/design/gui/icombobox/FRTreeComboBox.java
  6. 47
      designer-base/src/main/java/com/fr/design/gui/icombobox/UIComboBox.java
  7. 5
      designer-base/src/main/resources/com/fine/theme/icon/down_arrow.svg
  8. 5
      designer-base/src/main/resources/com/fine/theme/icon/down_arrow_disable.svg
  9. 28
      designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLightLaf.properties

41
designer-base/src/main/java/com/fine/theme/light/ui/FineComboBoxUI.java

@ -0,0 +1,41 @@
package com.fine.theme.light.ui;
import com.formdev.flatlaf.ui.FlatComboBoxUI;
import javax.swing.JComponent;
import javax.swing.JButton;
import javax.swing.SwingConstants;
import javax.swing.plaf.ComponentUI;
import java.awt.Graphics2D;
/**
* 提供 {@link javax.swing.JComboBox} 的UI类
*
* @author Levy.Xie
* @since 11.0
* Created on 2023/12/07
*/
public class FineComboBoxUI extends FlatComboBoxUI {
public static ComponentUI createUI(JComponent c) {
return new FineComboBoxUI();
}
@Override
protected JButton createArrowButton() {
return new FineComboBoxButton();
}
protected class FineComboBoxButton extends FlatComboBoxButton {
@Override
protected void paintArrow(Graphics2D g) {
if (isPopupVisible(comboBox)) {
setDirection(SwingConstants.NORTH);
} else {
setDirection(SwingConstants.SOUTH);
}
super.paintArrow(g);
}
}
}

1
designer-base/src/main/java/com/fine/theme/light/ui/FineLightIconSet.java

@ -34,6 +34,7 @@ public class FineLightIconSet extends AbstractIconSet {
new SvgIconSource("add", "com/fine/theme/icon/add.svg", true),
new SvgIconSource("drag_left", "com/fine/theme/icon/drag_left.svg", true),
new SvgIconSource("drag_right", "com/fine/theme/icon/drag_right.svg", true),
new SvgIconSource("down_arrow", "com/fine/theme/icon/down_arrow.svg", true),
// 数据集相关Icon
new SvgIconSource("database", "com/fine/theme/icon/dataset/database.svg", true),

13
designer-base/src/main/java/com/fr/design/event/HoverAware.java

@ -0,0 +1,13 @@
package com.fr.design.event;
/**
* 组件判断是否被hover的能力接口
*
* @author Levy.Xie
* @since 11.0
* Created on 2023/12/07
*/
public interface HoverAware {
boolean isHovered();
}

4
designer-base/src/main/java/com/fr/design/gui/icombobox/ExtendedComboBox.java

@ -1,12 +1,12 @@
package com.fr.design.gui.icombobox;
import com.fine.theme.light.ui.FineComboBoxUI;
import com.fr.common.inputevent.InputEventBaseOnOS;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.util.Vector;
@ -54,7 +54,7 @@ public class ExtendedComboBox extends UIComboBox {
return dim;
}
static class ExtendedComboBoxUI extends UIBasicComboBoxUI {
static class ExtendedComboBoxUI extends FineComboBoxUI {
public static ComponentUI createUI(JComponent c) {
return new ExtendedComboBoxUI();
}

78
designer-base/src/main/java/com/fr/design/gui/icombobox/FRTreeComboBox.java

@ -1,5 +1,6 @@
package com.fr.design.gui.icombobox;
import com.fine.theme.light.ui.FineComboBoxUI;
import com.fr.design.constants.UIConstants;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilable.UILabel;
@ -248,8 +249,7 @@ public class FRTreeComboBox extends UIComboBox {
private static TreePopup treePopup;
protected static class FRTreeComboBoxUI extends BasicComboBoxUI implements MouseListener{
private boolean isRollover = false;
protected static class FRTreeComboBoxUI extends FineComboBoxUI {
public FRTreeComboBoxUI() {
super();
@ -258,81 +258,7 @@ public class FRTreeComboBox extends UIComboBox {
treePopup = new TreePopup(comboBox);
return treePopup;
}
@Override
protected UIButton createArrowButton() {
arrowButton = new UIButton(UIConstants.ARROW_DOWN_ICON){
/**
* 组件是否需要响应添加的观察者事件
*
* @return 如果需要响应观察者事件则返回true否则返回false
*/
@Override
public boolean shouldResponseChangeListener() {
return false;
}
};
((UIButton) arrowButton).setRoundBorder(true, Constants.LEFT);
arrowButton.addMouseListener(this);
comboBox.addMouseListener(this);
return (UIButton) arrowButton;
}
public void paint(Graphics g, JComponent c) {
super.paint(g, c);
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Color linecolor = null;
if (comboBox.isPopupVisible()) {
linecolor = UIConstants.LINE_COLOR;
arrowButton.setSelected(true);
} else if (isRollover) {
linecolor = UIConstants.LIGHT_BLUE;
} else {
linecolor = UIConstants.LINE_COLOR;
arrowButton.setSelected(false);
}
g2d.setColor(linecolor);
if (!comboBox.isPopupVisible()) {
g2d.drawRoundRect(0, 0, c.getWidth() - arrowButton.getWidth() + 3, c.getHeight() - 1, UIConstants.LARGEARC, UIConstants.LARGEARC);
} else {
g2d.drawRoundRect(0, 0, c.getWidth() , c.getHeight() + 3, UIConstants.LARGEARC, UIConstants.LARGEARC );
g2d.drawLine(0, c.getHeight()-1, c.getWidth(), c.getHeight()-1);
}
}
private void setRollover(boolean isRollover) {
if (this.isRollover != isRollover) {
this.isRollover = isRollover;
comboBox.repaint();
}
}
@Override
public void mouseEntered(MouseEvent e) {
setRollover(true);
}
@Override
public void mouseExited(MouseEvent e) {
setRollover(false);
}
@Override
public void mouseClicked(MouseEvent e) {
// do nothing
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
}
/**

47
designer-base/src/main/java/com/fr/design/gui/icombobox/UIComboBox.java

@ -1,13 +1,16 @@
package com.fr.design.gui.icombobox;
import com.fine.theme.light.ui.FineComboBoxUI;
import com.fr.design.event.GlobalNameListener;
import com.fr.design.event.GlobalNameObserver;
import com.fr.design.event.UIObserver;
import com.fr.design.event.UIObserverListener;
import com.fr.design.event.HoverAware;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.ListCellRenderer;
import javax.swing.UIManager;
import javax.swing.plaf.ComboBoxUI;
import javax.swing.plaf.basic.ComboPopup;
import java.awt.Dimension;
@ -15,6 +18,8 @@ import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.Vector;
@ -28,16 +33,13 @@ import java.util.Vector;
* @author zhou
* @since 2012-5-9下午3:18:58
*/
public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObserver {
public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObserver, HoverAware {
/**
*
*/
private static final long serialVersionUID = 1L;
private static final int SIZE = 20;
private static final int SIZE = UIManager.getInt("ComboBox.comboHeight");
private static final int SIZE5 = 5;
private static final int RENDER_FIX_SIZE = 5;
protected UIObserverListener uiObserverListener;
@ -45,6 +47,8 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser
private GlobalNameListener globalNameListener = null;
private boolean hovered;
public UIComboBox() {
super();
init();
@ -67,7 +71,6 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser
private void init() {
setOpaque(false);
// setUI(getUIComboBoxUI());
setRenderer(new UIComboBoxRenderer());
setEditor(new UIComboBoxEditor());
initListener();
@ -93,6 +96,18 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser
}
}
});
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
hovered = true;
repaint();
}
@Override
public void mouseExited(MouseEvent e) {
hovered = false;
repaint();
}
});
}
}
@ -104,7 +119,7 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser
protected ComboBoxUI getUIComboBoxUI() {
return new UIComboBoxUI();
return new FineComboBoxUI();
}
/**
@ -129,7 +144,7 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser
@Override
public Dimension getPreferredSize() {
//加5的原因在于:render里,每一个项前面了空了一格,要多几像素
return new Dimension(super.getPreferredSize().width + SIZE5, SIZE);
return new Dimension(super.getPreferredSize().width + RENDER_FIX_SIZE, SIZE);
}
public void refreshBoxItems(List list) {
@ -161,15 +176,6 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser
}
// /**
// *
// */
// @Override
// public void updateUI() {
// setUI(getUIComboBoxUI());
// }
/**
* @param listener 观察者监听事件
*/
@ -210,5 +216,8 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser
return true;
}
@Override
public boolean isHovered() {
return hovered;
}
}

5
designer-base/src/main/resources/com/fine/theme/icon/down_arrow.svg

@ -0,0 +1,5 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="&#231;&#174;&#173;&#229;&#164;&#180;">
<path id="Union" d="M3.75743 6.09835C3.56217 6.29361 3.56217 6.6102 3.75743 6.80546L8.00007 11.0481L12.2427 6.80546C12.438 6.61019 12.438 6.29362 12.2427 6.09835C12.0474 5.90308 11.7309 5.90309 11.5356 6.09835L8.00007 9.63388L4.46454 6.09835C4.26928 5.90309 3.95269 5.90309 3.75743 6.09835Z" fill="#0A1C38" fill-opacity="0.9"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 482 B

5
designer-base/src/main/resources/com/fine/theme/icon/down_arrow_disable.svg

@ -0,0 +1,5 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="&#231;&#174;&#173;&#229;&#164;&#180;">
<path id="Union" d="M3.75743 6.09835C3.56217 6.29361 3.56217 6.6102 3.75743 6.80546L8.00007 11.0481L12.2427 6.80546C12.438 6.61019 12.438 6.29362 12.2427 6.09835C12.0474 5.90308 11.7309 5.90309 11.5356 6.09835L8.00007 9.63388L4.46454 6.09835C4.26928 5.90309 3.95269 5.90309 3.75743 6.09835Z" fill="#0A1C38" fill-opacity="0.29"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 483 B

28
designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLightLaf.properties

@ -47,7 +47,7 @@ ButtonUI = com.formdev.flatlaf.ui.FlatButtonUI
CheckBoxUI = com.formdev.flatlaf.ui.FlatCheckBoxUI
CheckBoxMenuItemUI = com.formdev.flatlaf.ui.FlatCheckBoxMenuItemUI
ColorChooserUI = com.formdev.flatlaf.ui.FlatColorChooserUI
ComboBoxUI = com.formdev.flatlaf.ui.FlatComboBoxUI
ComboBoxUI = com.fine.theme.light.ui.FineComboBoxUI
DesktopIconUI = com.formdev.flatlaf.ui.FlatDesktopIconUI
DesktopPaneUI = com.formdev.flatlaf.ui.FlatDesktopPaneUI
EditorPaneUI = com.formdev.flatlaf.ui.FlatEditorPaneUI
@ -161,6 +161,10 @@ controlHighlight = lighten($controlShadow,12%)
controlLtHighlight = lighten($controlShadow,25%)
controlDkShadow = darken($controlShadow,15%)
DarkenedFontColor = #091E40
defaultBorderColor = #DADEE7
defaultHighlightBorderColor = #2576EF
defaultBorderFocusShadow = #2576ef19
defaultBorderFocusWidth = 1
#---- Button ----
@ -277,7 +281,7 @@ ColorChooser.swatchesDefaultRecentColor = $control
#---- ComboBox ----
ComboBox.border = com.formdev.flatlaf.ui.FlatRoundBorder
ComboBox.border = com.fine.theme.light.ui.FineRoundBorder
ComboBox.padding = @componentMargin
ComboBox.minimumWidth = 72
ComboBox.editorColumns = 0
@ -285,21 +289,21 @@ ComboBox.maximumRowCount = 15
[mac]ComboBox.showPopupOnNavigation = true
# allowed values: auto, button or none
ComboBox.buttonStyle = auto
ComboBox.background = @componentBackground
ComboBox.background = #FFF
ComboBox.buttonBackground = $ComboBox.background
ComboBox.buttonEditableBackground = darken($ComboBox.background,2%)
ComboBox.buttonSeparatorColor = $Component.borderColor
ComboBox.buttonSeparatorColor = $ComboBox.background
ComboBox.buttonDisabledSeparatorColor = $Component.disabledBorderColor
ComboBox.buttonArrowColor = @buttonArrowColor
ComboBox.buttonArrowColor = #0A1C38
ComboBox.buttonDisabledArrowColor = @buttonDisabledArrowColor
ComboBox.buttonHoverArrowColor = @buttonHoverArrowColor
ComboBox.buttonPressedArrowColor = @buttonPressedArrowColor
ComboBox.buttonHoverArrowColor = #0A1C38
ComboBox.buttonPressedArrowColor = #0A1C38
ComboBox.popupInsets = 0,0,0,0
ComboBox.selectionInsets = 0,0,0,0
ComboBox.selectionArc = 0
ComboBox.borderCornerRadius = $Popup.borderCornerRadius
ComboBox.borderCornerRadius = 3
ComboBox.comboHeight = 24
#---- Component ----
@ -1061,7 +1065,7 @@ Tree.icon.openColor = @icon
Tree.hash = darken($Tree.background,10%)
#---- West ----
West.border = #DADEE7
West.border = $defaultBorderColor
#---- ExpandablePane ----
ExpandablePane.HeaderPane.borderInsets=0, 6, 0, 6
ExpandablePane.HeaderPane.hGap=2
@ -1070,7 +1074,7 @@ HeaderPane.width=248
HeaderPane.height=24
#---- East ----
East.border = #DADEE7
East.border = $defaultBorderColor
East.TabSelectedColor = #B3CFF9
#---- South ----
@ -1086,7 +1090,7 @@ South.SheetSelectedColor = #FFF
North.userinfoLabel.borderMargins=2, 16, 2, 16
North.userinfoLabel.width=80
North.userinfoLabel.height=24
North.border = #DADEE7
North.border = $defaultBorderColor
North.coverPane.background = #0a1c38
North.coverPane.radius = 8

Loading…
Cancel
Save