|
|
@ -3,6 +3,7 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package com.fr.design.gui.icombobox; |
|
|
|
package com.fr.design.gui.icombobox; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.fine.theme.utils.FineUIScale; |
|
|
|
import com.fr.base.GraphHelper; |
|
|
|
import com.fr.base.GraphHelper; |
|
|
|
import com.fr.stable.Constants; |
|
|
|
import com.fr.stable.Constants; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
@ -17,6 +18,9 @@ import java.awt.geom.Point2D; |
|
|
|
* Combobox for selecting line styles. |
|
|
|
* Combobox for selecting line styles. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class LineComboBox extends UIComboBox { |
|
|
|
public class LineComboBox extends UIComboBox { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final int LINE_HEIGHT = 16; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Constructor. |
|
|
|
* Constructor. |
|
|
|
* |
|
|
|
* |
|
|
@ -48,7 +52,7 @@ public class LineComboBox extends UIComboBox { |
|
|
|
* Set the selected line style. |
|
|
|
* Set the selected line style. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setSelectedLineStyle(int style) { |
|
|
|
public void setSelectedLineStyle(int style) { |
|
|
|
this.setSelectedItem(new Integer(style)); |
|
|
|
this.setSelectedItem(new Integer(style)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected String toStringFromStyle(int style) { |
|
|
|
protected String toStringFromStyle(int style) { |
|
|
@ -64,7 +68,7 @@ public class LineComboBox extends UIComboBox { |
|
|
|
class LineCellRenderer extends UIComboBoxRenderer { |
|
|
|
class LineCellRenderer extends UIComboBoxRenderer { |
|
|
|
public Component getListCellRendererComponent( |
|
|
|
public Component getListCellRendererComponent( |
|
|
|
JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
|
|
|
JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
|
|
|
JLabel comp= (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); |
|
|
|
JLabel comp = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); |
|
|
|
this.style = ((Integer) value).intValue(); |
|
|
|
this.style = ((Integer) value).intValue(); |
|
|
|
String displayString = toStringFromStyle(style); |
|
|
|
String displayString = toStringFromStyle(style); |
|
|
|
if (StringUtils.isNotEmpty(displayString)) { |
|
|
|
if (StringUtils.isNotEmpty(displayString)) { |
|
|
@ -76,56 +80,56 @@ public class LineComboBox extends UIComboBox { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void paint(Graphics g) { |
|
|
|
public void paint(Graphics g) { |
|
|
|
super.paint(g); |
|
|
|
super.paint(g); |
|
|
|
if (StringUtils.isEmpty(toStringFromStyle(style))) { |
|
|
|
if (StringUtils.isEmpty(toStringFromStyle(style))) { |
|
|
|
Graphics2D g2d = (Graphics2D) g; |
|
|
|
Graphics2D g2d = (Graphics2D) g; |
|
|
|
|
|
|
|
|
|
|
|
Dimension d = getSize(); |
|
|
|
Dimension d = getSize(); |
|
|
|
g2d.setColor(getForeground()); |
|
|
|
g2d.setColor(getForeground()); |
|
|
|
GraphHelper.drawLine(g2d, 4, d.height / 2D, d.width - 8D, d.height / 2D, style); |
|
|
|
GraphHelper.drawLine(g2d, 4, d.height / 2D, d.width - 8D, d.height / 2D, style); |
|
|
|
|
|
|
|
|
|
|
|
if(isShowAxisWithLineStyle()) { // 带有坐标轴箭头的样式.
|
|
|
|
if (isShowAxisWithLineStyle()) { // 带有坐标轴箭头的样式.
|
|
|
|
drawArrow(g2d, new Point2D.Double(4, d.height / 2D), new Point2D.Double(d.width - 8D, d.height / 2D)); |
|
|
|
drawArrow(g2d, new Point2D.Double(4, d.height / 2D), new Point2D.Double(d.width - 8D, d.height / 2D)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void drawArrow(Graphics2D g2d, Point2D p0, Point2D p1) { |
|
|
|
private void drawArrow(Graphics2D g2d, Point2D p0, Point2D p1) { |
|
|
|
Point2D s = new Point2D.Double(p1.getX() - p0.getX(), p1.getY() - p0.getY()); |
|
|
|
Point2D s = new Point2D.Double(p1.getX() - p0.getX(), p1.getY() - p0.getY()); |
|
|
|
Point2D t = new Point2D.Double(); |
|
|
|
Point2D t = new Point2D.Double(); |
|
|
|
double d1 = p0.distance(p1); |
|
|
|
double d1 = p0.distance(p1); |
|
|
|
//d2-d5设定箭头的大小,p1-p2为坐标轴的延长线,p2-p5-p3-p6为箭头4个点的具体位置
|
|
|
|
//d2-d5设定箭头的大小,p1-p2为坐标轴的延长线,p2-p5-p3-p6为箭头4个点的具体位置
|
|
|
|
double d2 = 9; |
|
|
|
double d2 = 9; |
|
|
|
double d3 = 15; |
|
|
|
double d3 = 15; |
|
|
|
double d4 = 7; |
|
|
|
double d4 = 7; |
|
|
|
double d5 = 3; |
|
|
|
double d5 = 3; |
|
|
|
t.setLocation(d2 * s.getX() / d1, d2 * s.getY() / d1); |
|
|
|
t.setLocation(d2 * s.getX() / d1, d2 * s.getY() / d1); |
|
|
|
Point2D p2 = new Point2D.Double(p1.getX() + t.getX(), p1.getY() + t.getY()); |
|
|
|
Point2D p2 = new Point2D.Double(p1.getX() + t.getX(), p1.getY() + t.getY()); |
|
|
|
t.setLocation(d3 * s.getX() / d1, d3 * s.getY() / d1); |
|
|
|
t.setLocation(d3 * s.getX() / d1, d3 * s.getY() / d1); |
|
|
|
Point2D p3 = new Point2D.Double(p1.getX() + t.getX(), p1.getY() + t.getY()); |
|
|
|
Point2D p3 = new Point2D.Double(p1.getX() + t.getX(), p1.getY() + t.getY()); |
|
|
|
t.setLocation(d4 * s.getX() / d1, d4 * s.getY() / d1); |
|
|
|
t.setLocation(d4 * s.getX() / d1, d4 * s.getY() / d1); |
|
|
|
Point2D p4 = new Point2D.Double(p1.getX() + t.getX(), p1.getY() + t.getY()); |
|
|
|
Point2D p4 = new Point2D.Double(p1.getX() + t.getX(), p1.getY() + t.getY()); |
|
|
|
Point2D p5 = new Point2D.Double(p4.getX() + s.getY() / d1 * d5, p4.getY() - s.getX() / d1 * d5); |
|
|
|
Point2D p5 = new Point2D.Double(p4.getX() + s.getY() / d1 * d5, p4.getY() - s.getX() / d1 * d5); |
|
|
|
Point2D p6 = new Point2D.Double(p4.getX() - s.getY() / d1 * d5, p4.getY() + s.getX() / d1 * d5); |
|
|
|
Point2D p6 = new Point2D.Double(p4.getX() - s.getY() / d1 * d5, p4.getY() + s.getX() / d1 * d5); |
|
|
|
|
|
|
|
|
|
|
|
GeneralPath arrow = new GeneralPath(); |
|
|
|
GeneralPath arrow = new GeneralPath(); |
|
|
|
arrow.moveTo((float) p2.getX() - 10, (float) p2.getY()); |
|
|
|
arrow.moveTo((float) p2.getX() - 10, (float) p2.getY()); |
|
|
|
arrow.lineTo((float) p5.getX() - 10, (float) p5.getY()); |
|
|
|
arrow.lineTo((float) p5.getX() - 10, (float) p5.getY()); |
|
|
|
arrow.lineTo((float) p3.getX() - 10, (float) p3.getY()); |
|
|
|
arrow.lineTo((float) p3.getX() - 10, (float) p3.getY()); |
|
|
|
arrow.lineTo((float) p6.getX() - 10, (float) p6.getY()); |
|
|
|
arrow.lineTo((float) p6.getX() - 10, (float) p6.getY()); |
|
|
|
arrow.closePath(); |
|
|
|
arrow.closePath(); |
|
|
|
|
|
|
|
|
|
|
|
g2d.draw(arrow); |
|
|
|
g2d.draw(arrow); |
|
|
|
g2d.fill(arrow); |
|
|
|
g2d.fill(arrow); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean isShowAxisWithLineStyle() { |
|
|
|
private boolean isShowAxisWithLineStyle() { |
|
|
|
return style == Constants.LINE_CHART_MED_ARROW |
|
|
|
return style == Constants.LINE_CHART_MED_ARROW |
|
|
|
|| style == Constants.LINE_CHART_THICK_ARROW || style == Constants.LINE_CHART_THIN_ARROW; |
|
|
|
|| style == Constants.LINE_CHART_THICK_ARROW || style == Constants.LINE_CHART_THIN_ARROW; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Dimension getPreferredSize() { |
|
|
|
public Dimension getPreferredSize() { |
|
|
|
return new Dimension(60, 16); |
|
|
|
return new Dimension(getWidth(), FineUIScale.scale(LINE_HEIGHT)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Dimension getMinimumSize() { |
|
|
|
public Dimension getMinimumSize() { |
|
|
|