帆软报表设计器源代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

120 lines
2.8 KiB

package com.fine.theme.icon;
import com.fr.third.errorprone.annotations.Immutable;
import org.jetbrains.annotations.NotNull;
import javax.swing.Icon;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.StringJoiner;
import static com.fine.theme.utils.FineUIScale.scale;
/**
* 懒加载图标
* 非常懒,宽高都不想算
*
* @author vito
* @since 11.0
* Created on 2023/11/6
*/
@Immutable
public class LazyIcon implements Identifiable, DisabledIcon, WhiteIcon, Icon {
@NotNull
private final String id;
private final Dimension dimension;
private final IconType type;
public LazyIcon(@NotNull final String id) {
this.id = id;
this.dimension = IconManager.DEFAULT_DIMENSION;
this.type = IconType.normal;
}
public LazyIcon(@NotNull final String id, int side) {
this.id = id;
this.dimension = new Dimension(side, side);
this.type = IconType.normal;
}
public LazyIcon(@NotNull final String id, @NotNull Dimension dimension) {
this.id = id;
this.dimension = dimension;
this.type = IconType.normal;
}
private LazyIcon(@NotNull final String id, @NotNull IconType type) {
this.id = id;
this.dimension = IconManager.DEFAULT_DIMENSION;
this.type = type;
}
public LazyIcon(@NotNull final String id, @NotNull Dimension dimension, @NotNull IconType type) {
this.id = id;
this.dimension = dimension;
this.type = type;
}
@NotNull
@Override
public String getId() {
return id;
}
@Override
public void paintIcon(@NotNull final Component c, @NotNull final Graphics g, final int x, final int y) {
getIcon().paintIcon(c, g, x, y);
}
@Override
public int getIconWidth() {
return scale(dimension.width);
}
@Override
public int getIconHeight() {
return scale(dimension.height);
}
@NotNull
public <I extends Icon> I getIcon() {
return IconManager.getIcon(getId(), dimension, type);
}
/**
* 创建一份灰化图标
*
* @return 灰化图标
*/
@NotNull
@Override
public Icon disabled() {
return new LazyIcon(getId(), dimension, IconType.disable);
}
/**
* 创建一份白化图标
*
* @return 白化图标
*/
@NotNull
@Override
public Icon white() {
return new LazyIcon(getId(), dimension, IconType.white);
}
@Override
public String toString() {
return new StringJoiner(", ", LazyIcon.class.getSimpleName() + "[", "]")
.add("id='" + id + "'")
.add("size=" + "[w=" + scale(dimension.width) + ",h=" + scale(dimension.height) + "]")
.add("type=" + type)
.toString();
}
}