Browse Source

REPORT-107973 修改渐变色滑块UI实现

newui
Leo.Qin 11 months ago
parent
commit
0a4d5aad4e
  1. 35
      designer-base/src/main/java/com/fine/theme/light/ui/FineGradientBarUI.java
  2. 13
      designer-base/src/main/java/com/fr/design/style/background/gradient/AbstractComponentPopBox.java
  3. 2
      designer-base/src/main/java/com/fr/design/style/background/gradient/GradientBar.java

35
designer-base/src/main/java/com/fine/theme/light/ui/FineGradientBarUI.java

@ -1,6 +1,7 @@
package com.fine.theme.light.ui;
import com.fine.theme.utils.FineUIUtils;
import com.formdev.flatlaf.ui.FlatPanelUI;
import com.fr.design.style.background.gradient.GradientBar;
import com.fr.design.style.background.gradient.SelectColorPointBtn;
import com.fr.stable.AssistUtils;
@ -31,7 +32,7 @@ import java.util.List;
* @since 11.0
* Created on 2023/12/19
*/
public class FineGradientBarUI extends ComponentUI {
public class FineGradientBarUI extends FlatPanelUI {
private int directionalShapeSize;
private int recHeight;
@ -54,6 +55,10 @@ public class FineGradientBarUI extends ComponentUI {
boolean[] hoverStatus;
protected FineGradientBarUI(boolean shared) {
super(shared);
}
/**
* 创建UI
@ -62,7 +67,7 @@ public class FineGradientBarUI extends ComponentUI {
* @return UI
*/
public static ComponentUI createUI(JComponent c) {
return new FineGradientBarUI();
return new FineGradientBarUI(false);
}
@Override
@ -71,10 +76,6 @@ public class FineGradientBarUI extends ComponentUI {
installDefaults(c);
gradientBar = (GradientBar) c;
list = gradientBar.getList();
p1 = gradientBar.getSelectColorPointBtnP1();
p2 = gradientBar.getSelectColorPointBtnP2();
hoverStatus = new boolean[list.size()];
mouseMotionListener = new TrackMotionListener();
mouseListener = new TrackMouseListener();
gradientBar.addMouseMotionListener(mouseMotionListener);
@ -143,7 +144,6 @@ public class FineGradientBarUI extends ComponentUI {
int halfSize = directionalShapeSize / 2;
boolean x = e.getX() <= gradientBar.getWidth() - halfSize && e.getX() >= halfSize;
if (x) {
list.get(index).setX(e.getX());
list.get(index).setStartPosition((double) (e.getX() - halfSize) / (gradientBar.getWidth() - directionalShapeSize));
gradientBar.repaint();
}
@ -201,6 +201,15 @@ public class FineGradientBarUI extends ComponentUI {
public void paint(Graphics g, JComponent c) {
Graphics2D g2 = (Graphics2D) g;
gradientBar = (GradientBar) c;
list = gradientBar.getList();
p1 = gradientBar.getSelectColorPointBtnP1();
p2 = gradientBar.getSelectColorPointBtnP2();
if (hoverStatus == null) {
hoverStatus = new boolean[list.size()];
}
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
@ -232,6 +241,13 @@ public class FineGradientBarUI extends ComponentUI {
colors[i] = btnList.get(i).getColorInner();
}
float[] dist = getColorFloats(c, btnList);
LinearGradientPaint paint = new LinearGradientPaint(start, end, dist, colors);
g2d.setPaint(paint);
g2d.fillRect(halfSize + borderWidth, borderWidth, c.getWidth() - directionalShapeSize - borderWidth * 2, recHeight - borderWidth * 2);
}
private float[] getColorFloats(GradientBar c, List<SelectColorPointBtn> btnList) {
float[] dist = new float[btnList.size()];
for (int i = 0; i < btnList.size(); i++) {
if (btnList.get(i).getStartPosition() < 0) {
@ -243,6 +259,7 @@ public class FineGradientBarUI extends ComponentUI {
}
btnList.get(i).setX(dist[i] * (c.getWidth() - directionalShapeSize) + (double) directionalShapeSize / 2);
btnList.get(i).setY(recHeight);
}
float dist1 = dist[btnList.size() - 1];
@ -250,9 +267,7 @@ public class FineGradientBarUI extends ComponentUI {
if (AssistUtils.equals(dist1, dist2)) {
dist[btnList.size() - 1] = (float) (dist2 + offset);
}
LinearGradientPaint paint = new LinearGradientPaint(start, end, dist, colors);
g2d.setPaint(paint);
g2d.fillRect(halfSize + borderWidth, borderWidth, c.getWidth() - directionalShapeSize - borderWidth * 2, recHeight - borderWidth * 2);
return dist;
}
private void paintBorder(Graphics2D g2d, GradientBar c) {

13
designer-base/src/main/java/com/fr/design/style/background/gradient/AbstractComponentPopBox.java

@ -4,14 +4,11 @@ import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.style.background.BackgroundJComponent;
import com.fr.general.Background;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.util.ArrayList;
import java.util.List;
import java.awt.AWTEvent;
import java.awt.Dimension;
import java.awt.Point;
@ -21,13 +18,17 @@ import java.awt.Window;
import java.awt.event.AWTEventListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
/**
* 渐变色弹出窗口
*
* @author Bjorn
* @version 10.0
* Created by Bjorn on 2021-08-24
* @since 10.0
* Created on 2021-08-24
*/
public abstract class AbstractComponentPopBox extends JComponent {
public abstract class AbstractComponentPopBox extends JPanel {
protected BackgroundJComponent displayComponent;

2
designer-base/src/main/java/com/fr/design/style/background/gradient/GradientBar.java

@ -1,6 +1,5 @@
package com.fr.design.style.background.gradient;
import com.fine.theme.light.ui.FineGradientBarUI;
import com.fine.theme.utils.FineUIUtils;
import com.fr.base.background.ColorBackground;
import com.fr.design.event.UIObserver;
@ -86,7 +85,6 @@ public class GradientBar extends AbstractComponentPopBox implements UIObserver,
p2.setStartPosition(1);
addMouseClickListener();
iniListener();
setUI(new FineGradientBarUI());
}
public List<SelectColorPointBtn> getList() {

Loading…
Cancel
Save