Browse Source

CHART-20229 图表控件修改

feature/10.0
白岳 3 years ago
parent
commit
39a0b0db0a
  1. 204
      designer-chart/src/main/java/com/fr/design/gui/xcombox/MarkerComboBox.java
  2. 17
      designer-chart/src/main/java/com/fr/van/chart/designer/component/LineTypeComboBox.java

204
designer-chart/src/main/java/com/fr/design/gui/xcombox/MarkerComboBox.java

@ -8,110 +8,122 @@ import com.fr.base.GraphHelper;
import com.fr.base.ScreenResolution; import com.fr.base.ScreenResolution;
import com.fr.base.background.ColorBackground; import com.fr.base.background.ColorBackground;
import com.fr.chart.chartglyph.Marker; import com.fr.chart.chartglyph.Marker;
import com.fr.general.ComparatorUtils;
import com.fr.plugin.chart.ConfigHelper;
import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.icombobox.UIComboBoxRenderer; import com.fr.design.gui.icombobox.UIComboBoxRenderer;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.general.ComparatorUtils;
import com.fr.general.FRFont; import com.fr.general.FRFont;
import com.fr.plugin.chart.ConfigHelper;
import javax.swing.DefaultComboBoxModel;
import javax.swing.*; import javax.swing.JLabel;
import java.awt.*; import javax.swing.JList;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
/** /**
* Combobox for selecting marker. * Combobox for selecting marker.
*/ */
public class MarkerComboBox extends UIComboBox { public class MarkerComboBox extends UIComboBox {
private static final double TEXT_X_COORDINATES = 12d; private static final double TEXT_X_COORDINATES = 12d;
/** /**
* Constructor. * Constructor.
* *
* @param markerArray the array of marker. * @param markerArray the array of marker.
*/ */
public MarkerComboBox(Marker[] markerArray) { public MarkerComboBox(Marker[] markerArray) {
this.setModel(new DefaultComboBoxModel(markerArray)); this.setModel(new DefaultComboBoxModel(markerArray));
this.setRenderer(new MarkerCellRenderer()); this.setRenderer(new MarkerCellRenderer());
} }
/** /**
* Get selected marker. * Get selected marker.
*/ */
public Marker getSelectedMarkder() { public Marker getSelectedMarkder() {
return (Marker) getSelectedItem(); return (Marker) getSelectedItem();
} }
/** /**
* Set the selected marker. * Set the selected marker.
*/ */
public void setSelectedMarker(Marker marker) { public void setSelectedMarker(Marker marker) {
setSelectedItem(marker); setSelectedItem(marker);
} }
/** /**
* CellRenderer. * CellRenderer.
*/ */
class MarkerCellRenderer extends UIComboBoxRenderer { class MarkerCellRenderer extends UIComboBoxRenderer {
public Component getListCellRendererComponent(JList list,
Object value, int index, boolean isSelected, boolean cellHasFocus) { private Marker marker = null;
this.marker = (Marker) value; private boolean isSelected = false;
this.isSelected = isSelected;
public Component getListCellRendererComponent(JList list,
return this; Object value, int index, boolean isSelected, boolean cellHasFocus) {
} this.marker = (Marker) value;
this.isSelected = isSelected;
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g; String text = null;
if (marker != null) {
Dimension d = getSize(); boolean isAutoMarker = ComparatorUtils.equals(marker.getMarkerType(), ConfigHelper.AUTO_M);
g2d.setColor(Color.black); boolean isNullMarker = ComparatorUtils.equals(marker.getMarkerType(), ConfigHelper.NULL_M);
g2d.setFont(FRContext.getDefaultValues().getFRFont()); if (isAutoMarker || isNullMarker) {
text = isNullMarker
if (marker != null) { ? Toolkit.i18nText("Fine-Design_Report_None")
boolean isAutoMarker = ComparatorUtils.equals(marker.getMarkerType(), ConfigHelper.AUTO_M); : Toolkit.i18nText("Fine-Design_Basic_ChartF_Auto");
boolean isNullMarker = ComparatorUtils.equals(marker.getMarkerType(), ConfigHelper.NULL_M); }
}
if (isAutoMarker || isNullMarker) { JLabel comp = (JLabel) super.getListCellRendererComponent(list, text, index, isSelected, cellHasFocus);
String text = isNullMarker return comp;
?Toolkit.i18nText("Fine-Design_Report_None") }
:Toolkit.i18nText("Fine-Design_Basic_ChartF_Auto");
public void paint(Graphics g) {
paintTextMarker(g2d, d, text); Graphics2D g2d = (Graphics2D) g;
} else { Dimension d = getSize();
if (marker.getBackground() == null) { if (marker != null) {
marker.setBackground(ColorBackground.getInstance(Color.black)); boolean isAutoMarker = ComparatorUtils.equals(marker.getMarkerType(), ConfigHelper.AUTO_M);
} boolean isNullMarker = ComparatorUtils.equals(marker.getMarkerType(), ConfigHelper.NULL_M);
marker.paint(g2d, d.width / 2, d.height / 2); if (isAutoMarker || isNullMarker) {
} super.paint(g);
} } else {
g2d.setColor(Color.black);
if (isSelected) { if (marker.getBackground() == null) {
g2d.setColor(Color.blue); marker.setBackground(ColorBackground.getInstance(Color.black));
GraphHelper.drawRect(g2d, 0, 0, d.width - 1, d.height - 1); }
} marker.paint(g2d, d.width / 2, d.height / 2);
} }
}
public Dimension getPreferredSize() {
return new Dimension(36, 16); if (isSelected) {
} g2d.setColor(Color.blue);
GraphHelper.drawRect(g2d, 0, 0, d.width - 1, d.height - 1);
public Dimension getMinimumSize() { }
return getPreferredSize(); }
}
public Dimension getPreferredSize() {
private Marker marker = null; return new Dimension(36, 16);
private boolean isSelected = false; }
private void paintTextMarker(Graphics2D g2d, Dimension d, String text) { public Dimension getMinimumSize() {
g2d.setColor(Color.black); return getPreferredSize();
FRFont font = FRContext.getDefaultValues().getFRFont(); }
int resolution = ScreenResolution.getScreenResolution();
Font rfont = font.applyResolutionNP(resolution);
g2d.setFont(rfont); private void paintTextMarker(Graphics2D g2d, Dimension d, String text) {
FontMetrics fm = GraphHelper.getFontMetrics(rfont); g2d.setColor(Color.black);
FRFont font = FRContext.getDefaultValues().getFRFont();
GraphHelper.drawString(g2d, text, TEXT_X_COORDINATES, (d.height - fm.getHeight()) / 2 + fm.getAscent()); int resolution = ScreenResolution.getScreenResolution();
} Font rfont = font.applyResolutionNP(resolution);
} g2d.setFont(rfont);
FontMetrics fm = GraphHelper.getFontMetrics(rfont);
GraphHelper.drawString(g2d, text, TEXT_X_COORDINATES, (d.height - fm.getHeight()) / 2 + fm.getAscent());
}
}
} }

17
designer-chart/src/main/java/com/fr/van/chart/designer/component/LineTypeComboBox.java

@ -1,12 +1,9 @@
package com.fr.van.chart.designer.component; package com.fr.van.chart.designer.component;
import com.fr.base.FRContext;
import com.fr.base.GraphHelper; import com.fr.base.GraphHelper;
import com.fr.base.ScreenResolution;
import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.icombobox.UIComboBoxRenderer; import com.fr.design.gui.icombobox.UIComboBoxRenderer;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.general.FRFont;
import com.fr.plugin.chart.type.LineType; import com.fr.plugin.chart.type.LineType;
import com.fr.stable.Constants; import com.fr.stable.Constants;
@ -14,8 +11,6 @@ import javax.swing.JLabel;
import javax.swing.JList; import javax.swing.JList;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
@ -37,9 +32,9 @@ public class LineTypeComboBox extends UIComboBox {
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);
this.lineType = (LineType) value; this.lineType = (LineType) value;
comp.setText(null); value = lineType == LineType.NONE ? Toolkit.i18nText("Fine-Design_Report_None") : null;
JLabel comp = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
return comp; return comp;
} }
@ -51,14 +46,6 @@ public class LineTypeComboBox extends UIComboBox {
g2d.setColor(getForeground()); g2d.setColor(getForeground());
switch (this.lineType) { switch (this.lineType) {
case NONE:
FRFont font = FRContext.getDefaultValues().getFRFont();
int resolution = ScreenResolution.getScreenResolution();
Font rfont = font.applyResolutionNP(resolution);
g2d.setFont(rfont);
FontMetrics fm = GraphHelper.getFontMetrics(rfont);
GraphHelper.drawString(g2d, Toolkit.i18nText("Fine-Design_Report_None"), 4, (d.height - fm.getHeight()) / 2 + fm.getAscent());
break;
case SOLID: case SOLID:
GraphHelper.drawLine(g2d, 4, d.height / 2, d.width - 8, d.height / 2); GraphHelper.drawLine(g2d, 4, d.height / 2, d.width - 8, d.height / 2);
break; break;

Loading…
Cancel
Save