vito
10 months ago
14 changed files with 334 additions and 96 deletions
@ -0,0 +1,58 @@
|
||||
package com.fine.theme.icon; |
||||
|
||||
import com.formdev.flatlaf.util.Graphics2DProxy; |
||||
|
||||
import java.awt.Color; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.Paint; |
||||
import java.awt.image.RGBImageFilter; |
||||
|
||||
/** |
||||
* 颜色过滤器画板 |
||||
* |
||||
* @author vito |
||||
* @since 11.0 |
||||
* Created on 2023/11/21 |
||||
*/ |
||||
public class GraphicsFilter |
||||
extends Graphics2DProxy { |
||||
private final RGBImageFilter grayFilter; |
||||
|
||||
public GraphicsFilter(Graphics2D delegate, RGBImageFilter grayFilter) { |
||||
super(delegate); |
||||
this.grayFilter = grayFilter; |
||||
} |
||||
|
||||
@Override |
||||
public Graphics create() { |
||||
return new GraphicsFilter((Graphics2D) super.create(), grayFilter); |
||||
} |
||||
|
||||
@Override |
||||
public Graphics create(int x, int y, int width, int height) { |
||||
return new GraphicsFilter((Graphics2D) super.create(x, y, width, height), grayFilter); |
||||
} |
||||
|
||||
@Override |
||||
public void setColor(Color c) { |
||||
super.setColor(filterColor(c)); |
||||
} |
||||
|
||||
@Override |
||||
public void setPaint(Paint paint) { |
||||
if (paint instanceof Color) |
||||
paint = filterColor((Color) paint); |
||||
super.setPaint(paint); |
||||
} |
||||
|
||||
private Color filterColor(Color color) { |
||||
|
||||
if (grayFilter != null) { |
||||
int oldRGB = color.getRGB(); |
||||
int newRGB = grayFilter.filterRGB(0, 0, oldRGB); |
||||
color = (newRGB != oldRGB) ? new Color(newRGB, true) : color; |
||||
} |
||||
return color; |
||||
} |
||||
} |
@ -0,0 +1,22 @@
|
||||
package com.fine.theme.icon; |
||||
|
||||
import org.jetbrains.annotations.NotNull; |
||||
|
||||
import javax.swing.Icon; |
||||
|
||||
/** |
||||
* 白化图像 |
||||
* |
||||
* @author vito |
||||
* @since 11.0 |
||||
* Created on 2024/1/8 |
||||
*/ |
||||
public interface WhiteIcon { |
||||
/** |
||||
* 创建一份白化图标 |
||||
* |
||||
* @return 灰化图标 |
||||
*/ |
||||
@NotNull |
||||
Icon white(); |
||||
} |
@ -0,0 +1,50 @@
|
||||
package com.fine.theme.icon.svg; |
||||
|
||||
import com.github.weisj.jsvg.attributes.paint.AwtSVGPaint; |
||||
import com.github.weisj.jsvg.attributes.paint.PaintParser; |
||||
import com.github.weisj.jsvg.attributes.paint.SVGPaint; |
||||
import com.github.weisj.jsvg.parser.AttributeNode; |
||||
import com.github.weisj.jsvg.parser.DefaultParserProvider; |
||||
import org.jetbrains.annotations.NotNull; |
||||
import org.jetbrains.annotations.Nullable; |
||||
|
||||
import java.awt.Color; |
||||
|
||||
/** |
||||
* svg绘制白化转化器 |
||||
* |
||||
* @author vito |
||||
* @since 11.0 |
||||
* Created on 2024/1/8 |
||||
*/ |
||||
public class WhiteParser extends DefaultParserProvider { |
||||
@Override |
||||
public @NotNull PaintParser createPaintParser() { |
||||
return new WhitePaintParser(super.createPaintParser()); |
||||
} |
||||
|
||||
|
||||
static class WhitePaintParser implements PaintParser { |
||||
|
||||
private final PaintParser delegate; |
||||
|
||||
WhitePaintParser(PaintParser delegate) { |
||||
this.delegate = delegate; |
||||
} |
||||
|
||||
@Override |
||||
public @Nullable Color parseColor(@NotNull String value, @NotNull AttributeNode attributeNode) { |
||||
return delegate.parseColor(value, attributeNode); |
||||
} |
||||
|
||||
@Override |
||||
public @Nullable SVGPaint parsePaint(@Nullable String value, @NotNull AttributeNode attributeNode) { |
||||
SVGPaint paint = delegate.parsePaint(value, attributeNode); |
||||
if (!(paint instanceof AwtSVGPaint)) { |
||||
return paint; |
||||
} |
||||
return new AwtSVGPaint(Color.WHITE); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,60 @@
|
||||
package com.fr.design.gui.storybook.components; |
||||
|
||||
import com.fine.theme.icon.LazyIcon; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.storybook.Story; |
||||
import com.fr.design.gui.storybook.StoryBoard; |
||||
|
||||
import javax.swing.JLabel; |
||||
|
||||
import static com.fine.swing.ui.layout.Layouts.cell; |
||||
import static com.fine.swing.ui.layout.Layouts.fix; |
||||
import static com.fine.swing.ui.layout.Layouts.flex; |
||||
import static com.fine.swing.ui.layout.Layouts.row; |
||||
|
||||
/** |
||||
* @author vito |
||||
* @since 11.0 |
||||
* Created on 2024/1/8 |
||||
*/ |
||||
@Story |
||||
public class IconStoryBoard extends StoryBoard { |
||||
public IconStoryBoard() { |
||||
super("图标"); |
||||
add( |
||||
cell(new UILabel("普通图标")).with(this::h3), |
||||
row(10, |
||||
cell(new JLabel(new LazyIcon("cut"))), |
||||
cell(new JLabel(new LazyIcon("save"))), |
||||
cell(new JLabel(new LazyIcon("copy"))), |
||||
cell(new JLabel(new LazyIcon("formatBrush"))), |
||||
cell(new JLabel(new LazyIcon("paste"))), |
||||
cell(new JLabel(new LazyIcon("undo"))), |
||||
cell(new JLabel(new LazyIcon("redo"))) |
||||
), |
||||
fix(5), |
||||
cell(new UILabel("禁用图标")).with(this::h3), |
||||
row(10, |
||||
cell(new JLabel(new LazyIcon("cut").disabled())), |
||||
cell(new JLabel(new LazyIcon("save").disabled())), |
||||
cell(new JLabel(new LazyIcon("copy").disabled())), |
||||
cell(new JLabel(new LazyIcon("formatBrush").disabled())), |
||||
cell(new JLabel(new LazyIcon("paste").disabled())), |
||||
cell(new JLabel(new LazyIcon("undo").disabled())), |
||||
cell(new JLabel(new LazyIcon("redo").disabled())) |
||||
), |
||||
fix(5), |
||||
cell(new UILabel("白化图标")).with(this::h3), |
||||
row(10, |
||||
cell(new JLabel(new LazyIcon("cut").white())), |
||||
cell(new JLabel(new LazyIcon("save").white())), |
||||
cell(new JLabel(new LazyIcon("copy").white())), |
||||
cell(new JLabel(new LazyIcon("formatBrush").white())), |
||||
cell(new JLabel(new LazyIcon("paste").white())), |
||||
cell(new JLabel(new LazyIcon("undo").white())), |
||||
cell(new JLabel(new LazyIcon("redo").white())) |
||||
), |
||||
flex() |
||||
); |
||||
} |
||||
} |
Loading…
Reference in new issue