Browse Source
Merge in DESIGN/design from ~STARRYI/design:KERNEL-11517 to release/11.0 * commit '44ca0f01134c44e950311e1852289d0d08e35dcb': KERNEL-11517 实现主题色时ClassHelper中遍历搜索对象存在性能问题newui
starryi
2 years ago
9 changed files with 38 additions and 164 deletions
@ -1,144 +0,0 @@
|
||||
package com.fr.design.mainframe.theme.edit.ui; |
||||
|
||||
import com.fr.base.theme.FineColorManager; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
|
||||
import javax.swing.JPanel; |
||||
import java.awt.Color; |
||||
import java.awt.Dimension; |
||||
import java.awt.Graphics; |
||||
import java.awt.event.MouseEvent; |
||||
import java.awt.event.MouseListener; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author Starryi |
||||
* @version 1.0 |
||||
* Created by Starryi on 2021/8/7 |
||||
*/ |
||||
public class ColorListExtendedPane extends JPanel implements MouseListener { |
||||
public static final int DEFAULT_COLOR_COUNT = 8; |
||||
public static final int DEFAULT_EXTENDED_COUNT = 5; |
||||
public static final int DEFAULT_COLOR_SIZE = 16; |
||||
public static final int DEFAULT_COLOR_GAP = 3; |
||||
|
||||
public static final ExtendedColorComputer DEFAULT_EXTENDED_COMPUTER = new ExtendedColorComputer() { |
||||
@Override |
||||
public Color computeExtendedColor(Color color, int index, int count) { |
||||
return FineColorManager.computeExtendedColor(color, index, count); |
||||
} |
||||
}; |
||||
|
||||
private final boolean selectable; |
||||
private final int colorCount; |
||||
private final int extendedCount; |
||||
private final int boxSize; |
||||
private final int boxGap; |
||||
|
||||
private final List<Color> colorList = new ArrayList<>(); |
||||
private ExtendedColorComputer extendedColorComputer = DEFAULT_EXTENDED_COMPUTER; |
||||
|
||||
private int selectedColorIndex = -1; |
||||
private int selectedExtendedIndex = -1; |
||||
|
||||
public ColorListExtendedPane() { |
||||
this(false, DEFAULT_COLOR_COUNT, DEFAULT_EXTENDED_COUNT, DEFAULT_COLOR_SIZE, DEFAULT_COLOR_GAP); |
||||
} |
||||
|
||||
public ColorListExtendedPane(boolean selectable, int colorCount, int extendedCount, int boxSize, int boxGap) { |
||||
setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
this.selectable = selectable; |
||||
this.colorCount = Math.max(1, colorCount); |
||||
this.extendedCount = extendedCount; |
||||
this.boxSize = boxSize; |
||||
this.boxGap = boxGap; |
||||
|
||||
for (int i = 0; i < colorCount; i++) { |
||||
colorList.add(Color.WHITE); |
||||
} |
||||
|
||||
int width = colorCount * boxSize + (colorCount - 1) * boxGap; |
||||
int height = extendedCount * boxSize + (extendedCount - 1) * boxGap; |
||||
setPreferredSize(new Dimension(width, height)); |
||||
} |
||||
|
||||
public void populate(List<Color> colors) { |
||||
if (colors.size() > 0) { |
||||
colorList.clear(); |
||||
colorList.addAll(colors); |
||||
repaint(); |
||||
} |
||||
} |
||||
|
||||
public List<Color> update() { |
||||
return new ArrayList<>(colorList); |
||||
} |
||||
|
||||
public void setExtendedColorComputer(ExtendedColorComputer extendedColorComputer) { |
||||
this.extendedColorComputer = extendedColorComputer; |
||||
} |
||||
|
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
int x = e.getX(); |
||||
int y = e.getY(); |
||||
|
||||
int colorIndex = x / (boxSize + boxGap); |
||||
int colorX = colorIndex * (boxSize + boxGap); |
||||
|
||||
int extendedIndex = y / boxSize; |
||||
int extendedY = extendedIndex * boxSize; |
||||
|
||||
if (colorX <= x && x <= colorX + boxSize && extendedY <= y && y <= extendedY + boxSize) { |
||||
selectedColorIndex = colorIndex; |
||||
selectedExtendedIndex = extendedIndex; |
||||
} else { |
||||
selectedColorIndex = -1; |
||||
selectedExtendedIndex = -1; |
||||
} |
||||
repaint(); |
||||
} |
||||
|
||||
@Override |
||||
public void mousePressed(MouseEvent e) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void mouseReleased(MouseEvent e) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void mouseEntered(MouseEvent e) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void mouseExited(MouseEvent e) { |
||||
|
||||
} |
||||
|
||||
public interface ExtendedColorComputer { |
||||
Color computeExtendedColor(Color color, int index, int count); |
||||
} |
||||
|
||||
@Override |
||||
public void paint(Graphics g) { |
||||
super.paint(g); |
||||
Color oldColor = g.getColor(); |
||||
|
||||
for (int i = 0; i < colorCount; i++) { |
||||
int x = i * (boxSize + boxGap); |
||||
for (int j = 0; j < extendedCount; j++) { |
||||
Color color = extendedColorComputer.computeExtendedColor(colorList.get(i), j, extendedCount); |
||||
g.setColor(color); |
||||
int y = j * (boxSize + boxGap); |
||||
g.fillRect(x, y, boxSize, boxSize); |
||||
} |
||||
} |
||||
|
||||
g.setColor(oldColor); |
||||
} |
||||
} |
Loading…
Reference in new issue