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