|
|
|
@ -7,7 +7,6 @@ import com.fr.design.event.UIObserverListener;
|
|
|
|
|
import com.fr.design.mainframe.DesignerContext; |
|
|
|
|
import com.fr.design.style.background.gradient.SelectColorPointBtn; |
|
|
|
|
import com.fr.design.style.color.ColorCell; |
|
|
|
|
import com.fr.design.style.color.ColorSelectConfigManager; |
|
|
|
|
import com.fr.design.style.color.ColorSelectDetailPane; |
|
|
|
|
import com.fr.design.style.color.ColorSelectDialog; |
|
|
|
|
import com.fr.design.style.color.ColorSelectable; |
|
|
|
@ -18,6 +17,9 @@ import com.fr.stable.AssistUtils;
|
|
|
|
|
import javax.swing.JComponent; |
|
|
|
|
import javax.swing.event.ChangeEvent; |
|
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.awt.Color; |
|
|
|
|
import java.awt.Cursor; |
|
|
|
|
import java.awt.Dimension; |
|
|
|
@ -27,9 +29,6 @@ import java.awt.LinearGradientPaint;
|
|
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
|
import java.awt.geom.Point2D; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
public class LegendGradientBar extends JComponent implements ColorSelectable, UIObserver { |
|
|
|
|
|
|
|
|
@ -75,11 +74,11 @@ public class LegendGradientBar extends JComponent implements ColorSelectable, UI
|
|
|
|
|
private List<ChangeListener> changeListenerList = new ArrayList<ChangeListener>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public LegendGradientBar(){ |
|
|
|
|
public LegendGradientBar() { |
|
|
|
|
startPos = 4; |
|
|
|
|
endPos = max; |
|
|
|
|
|
|
|
|
|
setSubColor(new Color(36,167,255)); |
|
|
|
|
setSubColor(new Color(36, 167, 255)); |
|
|
|
|
|
|
|
|
|
setColorSelectionBtnNum(2 + 1); |
|
|
|
|
|
|
|
|
@ -117,10 +116,10 @@ public class LegendGradientBar extends JComponent implements ColorSelectable, UI
|
|
|
|
|
private float[] initDist(int colorSelectionBtnNum) { |
|
|
|
|
float[] dist = new float[colorSelectionBtnNum]; |
|
|
|
|
dist[0] = 0f; |
|
|
|
|
for (int i = 0; i < colorSelectionBtnNum-2; i++) { |
|
|
|
|
dist[i+1] = (float) ((selectColorPointBtnList.get(i).getX() - 4) / (max - 4)); |
|
|
|
|
for (int i = 0; i < colorSelectionBtnNum - 2; i++) { |
|
|
|
|
dist[i + 1] = (float) ((selectColorPointBtnList.get(i).getX() - 4) / (max - 4)); |
|
|
|
|
} |
|
|
|
|
dist[colorSelectionBtnNum-1] = 1f; |
|
|
|
|
dist[colorSelectionBtnNum - 1] = 1f; |
|
|
|
|
return dist; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -141,8 +140,8 @@ public class LegendGradientBar extends JComponent implements ColorSelectable, UI
|
|
|
|
|
private Color[] initColors(Color subColor, int colorSelectionBtnNum) { |
|
|
|
|
Color[] converseColors = getColorArray(subColor, colorSelectionBtnNum); |
|
|
|
|
Color[] colors = new Color[colorSelectionBtnNum]; |
|
|
|
|
for (int i = 0; i < colorSelectionBtnNum; i++){ |
|
|
|
|
colors[i] = converseColors[colorSelectionBtnNum-1 - i]; |
|
|
|
|
for (int i = 0; i < colorSelectionBtnNum; i++) { |
|
|
|
|
colors[i] = converseColors[colorSelectionBtnNum - 1 - i]; |
|
|
|
|
} |
|
|
|
|
return colors; |
|
|
|
|
} |
|
|
|
@ -150,30 +149,32 @@ public class LegendGradientBar extends JComponent implements ColorSelectable, UI
|
|
|
|
|
private void initColorSelectBtn(Color[] colors, int colorSelectionBtnNum) { |
|
|
|
|
//获取按钮颜色数组
|
|
|
|
|
Color startSlotColor = colors[0]; |
|
|
|
|
Color endSlotColor = colors[colorSelectionBtnNum-1]; |
|
|
|
|
Color endSlotColor = colors[colorSelectionBtnNum - 1]; |
|
|
|
|
|
|
|
|
|
Color[] pColors = new Color[colorSelectionBtnNum - 2]; |
|
|
|
|
for (int i = 0; i < pColors.length; i++){ |
|
|
|
|
for (int i = 0; i < pColors.length; i++) { |
|
|
|
|
pColors[i] = colors[i + 1]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
selectColorSlotBtnStart = new SelectColorPointBtn(startPos, REC_HEIGHT, startSlotColor, new Color(138,138,138)); |
|
|
|
|
selectColorSlotBtnEnd = new SelectColorPointBtn(endPos, REC_HEIGHT, endSlotColor, new Color(138,138,138)); |
|
|
|
|
selectColorSlotBtnStart = new SelectColorPointBtn(startPos, REC_HEIGHT, startSlotColor, new Color(138, 138, 138)); |
|
|
|
|
selectColorSlotBtnEnd = new SelectColorPointBtn(endPos, REC_HEIGHT, endSlotColor, new Color(138, 138, 138)); |
|
|
|
|
|
|
|
|
|
//初始化list
|
|
|
|
|
selectColorPointBtnList = new ArrayList<SelectColorPointBtn>(); |
|
|
|
|
|
|
|
|
|
//加入可滑动颜色选择器
|
|
|
|
|
for (int i = 0; i < pColors.length; i++){ |
|
|
|
|
SelectColorPointBtn pi = new SelectColorPointBtn(((startPos+endPos)/(pColors.length+1))*(i+1), REC_HEIGHT, pColors[i]); |
|
|
|
|
for (int i = 0; i < pColors.length; i++) { |
|
|
|
|
SelectColorPointBtn pi = new SelectColorPointBtn(((startPos + endPos) / (pColors.length + 1)) * (i + 1), REC_HEIGHT, pColors[i]); |
|
|
|
|
selectColorPointBtnList.add(pi); |
|
|
|
|
} |
|
|
|
|
refreshColorsAndDist(selectColorPointBtnList); |
|
|
|
|
this.repaint(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 添加事件 |
|
|
|
|
* |
|
|
|
|
* @param changeListener 事件 |
|
|
|
|
*/ |
|
|
|
|
public void addChangeListener(ChangeListener changeListener) { |
|
|
|
@ -216,7 +217,7 @@ public class LegendGradientBar extends JComponent implements ColorSelectable, UI
|
|
|
|
|
//如果该位置已经有滑块占领,则做跨越偏移
|
|
|
|
|
selectColorPointBtnList.get(index).setX(LegendGradientBar.this.setOffset(e.getX(), index, OFFSETSTEP)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
refreshColorsAndDist(selectColorPointBtnList); |
|
|
|
|
LegendGradientBar.this.repaint(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
@ -224,25 +225,23 @@ public class LegendGradientBar extends JComponent implements ColorSelectable, UI
|
|
|
|
|
|
|
|
|
|
//防止位置重复,设置偏移
|
|
|
|
|
private int setOffset(int x, int index, int offset) { |
|
|
|
|
for (int i = 0; i < selectColorPointBtnList.size(); i++){ |
|
|
|
|
for (int i = 0; i < selectColorPointBtnList.size(); i++) { |
|
|
|
|
if (i != index && AssistUtils.equals(x, selectColorPointBtnList.get(i).getX())) { |
|
|
|
|
if (x >= (min+max)/2) { |
|
|
|
|
if (x >= (min + max) / 2) { |
|
|
|
|
x -= offset; |
|
|
|
|
x = setOffset(x, index, offset+OFFSETSTEP); |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
x = setOffset(x, index, offset + OFFSETSTEP); |
|
|
|
|
} else { |
|
|
|
|
x += offset; |
|
|
|
|
x = setOffset(x, index, offset+OFFSETSTEP); |
|
|
|
|
x = setOffset(x, index, offset + OFFSETSTEP); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//边界情况
|
|
|
|
|
if (x <= min){ |
|
|
|
|
x = min + (index+1)*OFFSETSTEP; |
|
|
|
|
} |
|
|
|
|
else if (x >= max){ |
|
|
|
|
x = max - (index+1)*OFFSETSTEP; |
|
|
|
|
if (x <= min) { |
|
|
|
|
x = min + (index + 1) * OFFSETSTEP; |
|
|
|
|
} else if (x >= max) { |
|
|
|
|
x = max - (index + 1) * OFFSETSTEP; |
|
|
|
|
} |
|
|
|
|
return x; |
|
|
|
|
} |
|
|
|
@ -259,50 +258,33 @@ public class LegendGradientBar extends JComponent implements ColorSelectable, UI
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (select >= 0) { |
|
|
|
|
ColorSelectDetailPane pane = new ColorSelectDetailPane(Color.WHITE); |
|
|
|
|
ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, Color.WHITE, LegendGradientBar.this); |
|
|
|
|
Color color = LegendGradientBar.this.getColor(); |
|
|
|
|
if (color != null) { |
|
|
|
|
DesignerEnvManager.getEnvManager().getColorConfigManager().addToColorQueue(color); |
|
|
|
|
selectColorPointBtnList.get(select).setColorInner(color); |
|
|
|
|
|
|
|
|
|
LegendGradientBar.this.repaint(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//是否选中颜色编辑槽
|
|
|
|
|
else if (selectColorSlotBtnStart.contains(e.getX(), e.getY())) { |
|
|
|
|
ColorSelectDetailPane pane = new ColorSelectDetailPane(Color.WHITE); |
|
|
|
|
ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, Color.WHITE, LegendGradientBar.this); |
|
|
|
|
Color color = LegendGradientBar.this.getColor(); |
|
|
|
|
if (color != null) { |
|
|
|
|
DesignerEnvManager.getEnvManager().getColorConfigManager().addToColorQueue(color); |
|
|
|
|
selectColorSlotBtnStart.setColorInner(color); |
|
|
|
|
//stateChanged();
|
|
|
|
|
LegendGradientBar.this.repaint(); |
|
|
|
|
} |
|
|
|
|
dealClick(selectColorPointBtnList.get(select)); |
|
|
|
|
} else if (selectColorSlotBtnStart.contains(e.getX(), e.getY())) { |
|
|
|
|
dealClick(selectColorSlotBtnStart); |
|
|
|
|
} else if (selectColorSlotBtnEnd.contains(e.getX(), e.getY())) { |
|
|
|
|
ColorSelectDetailPane pane = new ColorSelectDetailPane(Color.WHITE); |
|
|
|
|
ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, Color.WHITE, LegendGradientBar.this); |
|
|
|
|
Color color = LegendGradientBar.this.getColor(); |
|
|
|
|
if (color != null) { |
|
|
|
|
DesignerEnvManager.getEnvManager().getColorConfigManager().addToColorQueue(color); |
|
|
|
|
selectColorSlotBtnEnd.setColorInner(color); |
|
|
|
|
//stateChanged();
|
|
|
|
|
LegendGradientBar.this.repaint(); |
|
|
|
|
} |
|
|
|
|
dealClick(selectColorSlotBtnEnd); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LegendGradientBar.this.repaint(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void addMouseReleasedListener(){ |
|
|
|
|
private void dealClick(SelectColorPointBtn selectColorPointBtn) { |
|
|
|
|
ColorSelectDetailPane pane = new ColorSelectDetailPane(Color.WHITE); |
|
|
|
|
this.setColor(selectColorPointBtn.getColorInner()); |
|
|
|
|
ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, Color.WHITE, LegendGradientBar.this); |
|
|
|
|
Color color = this.getColor(); |
|
|
|
|
if (color != null) { |
|
|
|
|
DesignerEnvManager.getEnvManager().getColorConfigManager().addToColorQueue(color); |
|
|
|
|
selectColorPointBtn.setColorInner(color); |
|
|
|
|
refreshColorsAndDist(selectColorPointBtnList); |
|
|
|
|
LegendGradientBar.this.repaint(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void addMouseReleasedListener() { |
|
|
|
|
this.addMouseListener(new MouseAdapter() { |
|
|
|
|
@Override |
|
|
|
|
public void mouseReleased(MouseEvent e) { |
|
|
|
@ -318,14 +300,11 @@ public class LegendGradientBar extends JComponent implements ColorSelectable, UI
|
|
|
|
|
Point2D start = new Point2D.Float(4, 0); |
|
|
|
|
Point2D end = new Point2D.Float(max, 0); |
|
|
|
|
|
|
|
|
|
//获取排序后的颜色数组和位置数组
|
|
|
|
|
refreshColorsAndDist(selectColorPointBtnList); |
|
|
|
|
|
|
|
|
|
LinearGradientPaint paint = new LinearGradientPaint(start, end, dist, colors); |
|
|
|
|
g2.setPaint(paint); |
|
|
|
|
|
|
|
|
|
g2.fillRect(4, 0, max - 4, 30); |
|
|
|
|
g2.setColor(new Color(138,138,138)); |
|
|
|
|
g2.setColor(new Color(138, 138, 138)); |
|
|
|
|
g2.drawRect(4, 0, max - 4, 30); |
|
|
|
|
|
|
|
|
|
//开始和结束位置颜色选择槽位
|
|
|
|
@ -343,22 +322,22 @@ public class LegendGradientBar extends JComponent implements ColorSelectable, UI
|
|
|
|
|
Collections.sort(select); |
|
|
|
|
|
|
|
|
|
colors[0] = selectColorSlotBtnStart.getColorInner(); |
|
|
|
|
for (int i = 0; i < colorSelectionBtnNum-2; i++) { |
|
|
|
|
colors[i+1] = select.get(i).getColorInner(); |
|
|
|
|
for (int i = 0; i < colorSelectionBtnNum - 2; i++) { |
|
|
|
|
colors[i + 1] = select.get(i).getColorInner(); |
|
|
|
|
} |
|
|
|
|
colors[colorSelectionBtnNum-1] = selectColorSlotBtnEnd.getColorInner(); |
|
|
|
|
colors[colorSelectionBtnNum - 1] = selectColorSlotBtnEnd.getColorInner(); |
|
|
|
|
|
|
|
|
|
dist = new float[colorSelectionBtnNum]; |
|
|
|
|
dist[0] = 0f; |
|
|
|
|
for (int i = 0; i < colorSelectionBtnNum-2; i++) { |
|
|
|
|
dist[i+1] = (float) ((select.get(i).getX() - 4) / (max - 4)); |
|
|
|
|
for (int i = 0; i < colorSelectionBtnNum - 2; i++) { |
|
|
|
|
dist[i + 1] = (float) ((select.get(i).getX() - 4) / (max - 4)); |
|
|
|
|
} |
|
|
|
|
dist[colorSelectionBtnNum-1] = 1f; |
|
|
|
|
dist[colorSelectionBtnNum - 1] = 1f; |
|
|
|
|
|
|
|
|
|
fireColorAndDistChangeListener(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void refreshSubColor(Color subColor){ |
|
|
|
|
public void refreshSubColor(Color subColor) { |
|
|
|
|
|
|
|
|
|
//设置主题色
|
|
|
|
|
setSubColor(subColor); |
|
|
|
@ -370,9 +349,9 @@ public class LegendGradientBar extends JComponent implements ColorSelectable, UI
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void refreshColorSelectionBtnNum(int num){ |
|
|
|
|
public void refreshColorSelectionBtnNum(int num) { |
|
|
|
|
//设置主题色
|
|
|
|
|
colorSelectionBtnNum = num+1; |
|
|
|
|
colorSelectionBtnNum = num + 1; |
|
|
|
|
|
|
|
|
|
//计算colors数组
|
|
|
|
|
colors = initColors(subColor, colorSelectionBtnNum); |
|
|
|
@ -418,14 +397,14 @@ public class LegendGradientBar extends JComponent implements ColorSelectable, UI
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void populate(GradualIntervalConfig intervalConfig){ |
|
|
|
|
if(intervalConfig == null) { |
|
|
|
|
public void populate(GradualIntervalConfig intervalConfig) { |
|
|
|
|
if (intervalConfig == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setSubColor(intervalConfig.getSubColor()); |
|
|
|
|
|
|
|
|
|
setColorSelectionBtnNum((int)(intervalConfig.getDivStage() + 1)); |
|
|
|
|
setColorSelectionBtnNum((int) (intervalConfig.getDivStage() + 1)); |
|
|
|
|
|
|
|
|
|
populateColorAndDist(intervalConfig.getGradualColorDistList()); |
|
|
|
|
|
|
|
|
@ -436,15 +415,15 @@ public class LegendGradientBar extends JComponent implements ColorSelectable, UI
|
|
|
|
|
int num = gradualColorDistList.size(); |
|
|
|
|
this.colors = new Color[num]; |
|
|
|
|
this.dist = new float[num]; |
|
|
|
|
for (int i = 0; i < num; i++){ |
|
|
|
|
for (int i = 0; i < num; i++) { |
|
|
|
|
this.colors[i] = gradualColorDistList.get(i).getColor(); |
|
|
|
|
this.dist[i] = gradualColorDistList.get(i).getPosition(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void update(GradualIntervalConfig intervalConfig){ |
|
|
|
|
public void update(GradualIntervalConfig intervalConfig) { |
|
|
|
|
ArrayList<GradualColorDist> colorDistList = new ArrayList<GradualColorDist>(); |
|
|
|
|
for (int i = 0; i < getColorSelectionBtnNum(); i++){ |
|
|
|
|
for (int i = 0; i < getColorSelectionBtnNum(); i++) { |
|
|
|
|
colorDistList.add(new GradualColorDist(this.dist[i], this.colors[i])); |
|
|
|
|
} |
|
|
|
|
intervalConfig.setGradualColorDistList(colorDistList); |
|
|
|
@ -453,26 +432,26 @@ public class LegendGradientBar extends JComponent implements ColorSelectable, UI
|
|
|
|
|
private void refreshColorSelectBtn(Color[] colors, float[] dist) { |
|
|
|
|
//获取按钮颜色数组
|
|
|
|
|
Color startSlotColor = colors[0]; |
|
|
|
|
Color endSlotColor = colors[colors.length-1]; |
|
|
|
|
Color endSlotColor = colors[colors.length - 1]; |
|
|
|
|
|
|
|
|
|
Color[] pColors = new Color[colors.length - 2]; |
|
|
|
|
for (int i = 0; i < pColors.length; i++){ |
|
|
|
|
for (int i = 0; i < pColors.length; i++) { |
|
|
|
|
pColors[i] = colors[i + 1]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
float[] position = new float[dist.length - 2]; |
|
|
|
|
for (int i = 0; i < position.length; i++){ |
|
|
|
|
position[i] = dist[i+1]*(max-4) + 4; |
|
|
|
|
for (int i = 0; i < position.length; i++) { |
|
|
|
|
position[i] = dist[i + 1] * (max - 4) + 4; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
selectColorSlotBtnStart = new SelectColorPointBtn(startPos, REC_HEIGHT, startSlotColor, new Color(138,138,138)); |
|
|
|
|
selectColorSlotBtnEnd = new SelectColorPointBtn(endPos, REC_HEIGHT, endSlotColor, new Color(138,138,138)); |
|
|
|
|
selectColorSlotBtnStart = new SelectColorPointBtn(startPos, REC_HEIGHT, startSlotColor, new Color(138, 138, 138)); |
|
|
|
|
selectColorSlotBtnEnd = new SelectColorPointBtn(endPos, REC_HEIGHT, endSlotColor, new Color(138, 138, 138)); |
|
|
|
|
|
|
|
|
|
//刷新可移动按钮的位置
|
|
|
|
|
selectColorPointBtnList = new ArrayList<SelectColorPointBtn>(); |
|
|
|
|
|
|
|
|
|
//加入可滑动颜色选择器
|
|
|
|
|
for (int i = 0; i < pColors.length; i++){ |
|
|
|
|
for (int i = 0; i < pColors.length; i++) { |
|
|
|
|
SelectColorPointBtn pi = new SelectColorPointBtn(position[i], REC_HEIGHT, pColors[i]); |
|
|
|
|
selectColorPointBtnList.add(pi); |
|
|
|
|
} |
|
|
|
|