Browse Source
【问题原因】 1. 利用clone机制遍历搜索待查找对象 2. 在clone时应用主题色,从而得到同步主题色的大对象 3. 使用上述cloned大对象 【改动思路】 同上 【review建议】newui
Starryi
3 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