diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/Chart.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/Chart.java index 38e32b0e..050c7a8f 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/Chart.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/Chart.java @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; import org.meteoinfo.chart.jogl.GLPlot; -import org.meteoinfo.chart.plot.MapPlot; +import org.meteoinfo.chart.geo.MapPlot; import org.meteoinfo.chart.plot.Plot; import org.meteoinfo.common.PointF; diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartColorBar.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartColorBar.java index 5b4fd20a..048fb289 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartColorBar.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartColorBar.java @@ -5,11 +5,7 @@ */ package org.meteoinfo.chart; -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics2D; -import java.awt.Rectangle; +import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.geom.Line2D; import java.awt.geom.Path2D; @@ -460,6 +456,19 @@ public class ChartColorBar extends ChartLegend { */ @Override public void draw(Graphics2D g, PointF point) { + if (this.antiAlias) { + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); + } else { + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); + g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT); + g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT); + } AffineTransform oldMatrix = g.getTransform(); g.translate(point.X + this.xshift, point.Y + this.yshift); diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartElement.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartElement.java index fded4d2e..3719960c 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartElement.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartElement.java @@ -14,6 +14,7 @@ package org.meteoinfo.chart; import org.meteoinfo.common.PointF; +import org.meteoinfo.geometry.graphic.Artist; import org.meteoinfo.ui.event.ILocationChangedListener; import org.meteoinfo.ui.event.ISizeChangedListener; import org.meteoinfo.ui.event.LocationChangedEvent; @@ -28,7 +29,7 @@ import org.meteoinfo.geometry.graphic.ResizeAbility; * * @author yaqiang */ -public abstract class ChartElement { +public abstract class ChartElement extends Artist { // public void addLocationChangedListener(ILocationChangedListener listener) { diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartLegend.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartLegend.java index 5592c50d..79262e7c 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartLegend.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartLegend.java @@ -18,23 +18,19 @@ import org.meteoinfo.geo.drawing.Draw; import com.l2fprod.common.beans.BaseBeanInfo; import com.l2fprod.common.beans.ExtendedPropertyDescriptor; import com.l2fprod.common.beans.editor.ComboBoxPropertyEditor; -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics2D; -import java.awt.Rectangle; + +import java.awt.*; import java.awt.geom.AffineTransform; import java.util.List; import org.meteoinfo.chart.plot.PlotOrientation; +import org.meteoinfo.geometry.graphic.Artist; import org.meteoinfo.geometry.legend.*; /** * * @author Yaqiang Wang */ -public class ChartLegend { +public class ChartLegend extends Artist { // //private final XY1DPlot plot; @@ -774,6 +770,19 @@ public class ChartLegend { * @param point Start point */ public void draw(Graphics2D g, PointF point) { + if (this.antiAlias) { + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); + } else { + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); + g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT); + g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT); + } AffineTransform oldMatrix = g.getTransform(); g.translate(point.X + this.xshift, point.Y + this.yshift); diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartNorthArrow.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartNorthArrow.java index 5a3b76e8..ba664de9 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartNorthArrow.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartNorthArrow.java @@ -22,7 +22,7 @@ import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.geom.AffineTransform; -import org.meteoinfo.chart.plot.MapPlot; +import org.meteoinfo.chart.geo.MapPlot; /** * @@ -38,7 +38,6 @@ public class ChartNorthArrow extends ChartElement { // private final MapPlot mapPlot; - private final boolean antiAlias; private float lineWidth; private boolean drawNeatLine; private Color neatLineColor; diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartPanel.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartPanel.java index 4d9b7b66..fe1336a3 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartPanel.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartPanel.java @@ -22,8 +22,6 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.awt.image.AffineTransformOp; @@ -36,7 +34,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.time.Duration; import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import java.util.Iterator; import java.util.List; import java.util.Properties; @@ -61,7 +58,6 @@ import javax.print.StreamPrintServiceFactory; import javax.print.attribute.HashPrintRequestAttributeSet; import javax.print.attribute.PrintRequestAttributeSet; import javax.swing.JFileChooser; -import javax.swing.JFrame; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -69,9 +65,7 @@ import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; import javax.swing.Timer; import javax.swing.event.EventListenerList; -import javax.swing.table.DefaultTableModel; -import com.jogamp.opengl.awt.GLJPanel; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.ImageWriteException; import org.freehep.graphics2d.VectorGraphics; @@ -80,28 +74,17 @@ import org.freehep.graphicsio.pdf.PDFGraphics2D; import org.freehep.graphicsio.ps.PSGraphics2D; import org.meteoinfo.chart.jogl.EarthGLPlot; import org.meteoinfo.chart.jogl.GLPlot; -import org.meteoinfo.chart.plot.MapPlot; +import org.meteoinfo.chart.geo.MapPlot; import org.meteoinfo.chart.plot.Plot; import org.meteoinfo.chart.plot.XY1DPlot; import org.meteoinfo.chart.plot.AbstractPlot2D; import org.meteoinfo.chart.plot.Plot3D; -import org.meteoinfo.chart.plot.PlotType; import org.meteoinfo.chart.plot3d.Projector; import org.meteoinfo.common.Extent; import org.meteoinfo.common.Extent3D; import org.meteoinfo.common.GenericFileFilter; -import org.meteoinfo.common.PointF; import org.meteoinfo.data.mapdata.webmap.TileLoadListener; -import org.meteoinfo.geo.layer.LayerTypes; -import org.meteoinfo.geo.layer.MapLayer; -import org.meteoinfo.geo.layer.RasterLayer; -import org.meteoinfo.geo.layer.VectorLayer; -import org.meteoinfo.ndarray.DataType; import org.meteoinfo.image.ImageUtil; -import org.meteoinfo.geo.mapview.FrmIdentifer; -import org.meteoinfo.geo.mapview.FrmIdentiferGrid; -import org.meteoinfo.geo.mapview.MapView; -import org.meteoinfo.table.Field; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartScaleBar.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartScaleBar.java index a6e821ad..f8153399 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartScaleBar.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartScaleBar.java @@ -14,7 +14,7 @@ import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.geom.AffineTransform; import java.awt.geom.Line2D; -import org.meteoinfo.chart.plot.MapPlot; +import org.meteoinfo.chart.geo.MapPlot; import org.meteoinfo.common.PointF; /** @@ -44,7 +44,6 @@ public class ChartScaleBar extends ChartElement { // private MapPlot mapPlot; - private boolean antiAlias; private float lineWidth; private Font font; private ScaleBarType scaleBarType; diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/GLChart.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/GLChart.java index 03d33779..b4e09639 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/GLChart.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/GLChart.java @@ -8,7 +8,7 @@ import com.jogamp.opengl.util.awt.AWTGLReadBufferUtil; import com.jogamp.opengl.util.gl2.GLUT; import org.meteoinfo.chart.jogl.GLPlot; import org.meteoinfo.chart.jogl.Program; -import org.meteoinfo.chart.plot.MapPlot; +import org.meteoinfo.chart.geo.MapPlot; import org.meteoinfo.chart.plot.Plot; import org.meteoinfo.common.PointF; diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/GLChartPanel.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/GLChartPanel.java index 6a94b700..d97ad5f4 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/GLChartPanel.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/GLChartPanel.java @@ -18,43 +18,29 @@ import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.ImageWriteException; import org.freehep.graphics2d.VectorGraphics; import org.freehep.graphicsio.emf.EMFGraphics2D; -import org.freehep.graphicsio.pdf.PDFGraphics2D; import org.freehep.graphicsio.ps.PSGraphics2D; +import org.meteoinfo.chart.geo.MapPlot; import org.meteoinfo.chart.jogl.*; import org.meteoinfo.chart.plot.*; import org.meteoinfo.chart.plot3d.Projector; import org.meteoinfo.common.Extent; import org.meteoinfo.common.Extent3D; import org.meteoinfo.common.GenericFileFilter; -import org.meteoinfo.common.PointF; import org.meteoinfo.data.mapdata.webmap.TileLoadListener; -import org.meteoinfo.geo.layer.LayerTypes; -import org.meteoinfo.geo.layer.MapLayer; -import org.meteoinfo.geo.layer.RasterLayer; -import org.meteoinfo.geo.layer.VectorLayer; -import org.meteoinfo.geo.mapview.FrmIdentifer; -import org.meteoinfo.geo.mapview.FrmIdentiferGrid; -import org.meteoinfo.geo.mapview.MapView; import org.meteoinfo.image.ImageUtil; -import org.meteoinfo.ndarray.DataType; -import org.meteoinfo.table.Field; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; -import org.w3c.dom.NodeList; import javax.imageio.*; -import javax.imageio.metadata.IIOInvalidTreeException; import javax.imageio.metadata.IIOMetadata; import javax.imageio.plugins.jpeg.JPEGImageWriteParam; -import javax.imageio.stream.FileImageOutputStream; import javax.imageio.stream.ImageOutputStream; import javax.print.*; import javax.print.attribute.HashPrintRequestAttributeSet; import javax.print.attribute.PrintRequestAttributeSet; import javax.swing.*; import javax.swing.event.EventListenerList; -import javax.swing.table.DefaultTableModel; import java.awt.*; import java.awt.event.*; import java.awt.geom.AffineTransform; @@ -69,8 +55,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.time.Duration; import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Iterator; import java.util.List; import java.util.Properties; import java.util.logging.Level; diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/Axis.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/Axis.java index 5418e026..0034755c 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/Axis.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/Axis.java @@ -14,6 +14,7 @@ import org.meteoinfo.common.XAlign; import org.meteoinfo.common.YAlign; import org.meteoinfo.common.util.JDateUtil; import org.meteoinfo.geo.drawing.Draw; +import org.meteoinfo.geometry.graphic.Artist; import org.meteoinfo.geometry.legend.LineStyles; import org.meteoinfo.ndarray.util.BigDecimalUtil; @@ -29,7 +30,7 @@ import java.util.List; * * @author yaqiang */ -public class Axis implements Cloneable { +public class Axis extends Artist implements Cloneable { // protected boolean xAxis; @@ -767,54 +768,6 @@ public class Axis implements Cloneable { } } -// /** -// * Get if is time axis -// * -// * @return Boolean -// */ -// public boolean isTimeAxis() { -// return this.timeAxis; -// } -// -// /** -// * Set if is time axis -// * -// * @param value Boolean -// */ -// public void setTimeAxis(boolean value) { -// this.timeAxis = value; -// } -// /** -// * Get time format -// * @return Time format -// */ -// public String getTimeFormat(){ -// return this.timeFormat; -// } -// -// /** -// * Set time format -// * @param value -// */ -// public void setTimeFormat(String value){ -// this.timeFormat = value; -// } -// -// /** -// * Get time unit -// * @return Time unit -// */ -// public TimeUnit getTimeUnit(){ -// return this.timeUnit; -// } -// -// /** -// * Set time unit -// * @param value Time unit -// */ -// public void setTimeUnit(TimeUnit value){ -// this.timeUnit = value; -// } /** * Get if is inverse * @@ -833,24 +786,6 @@ public class Axis implements Cloneable { this.inverse = value; } -// /** -// * Get shift -// * -// * @return Shift -// */ -// public float getShift() { -// return this.shift; -// } -// -// /** -// * Set shift -// * -// * @param value Shift -// */ -// public void setShift(float value) { -// this.shift = value; -// } - /** * Tick locations * @@ -1485,6 +1420,21 @@ public class Axis implements Cloneable { if (plot.getDrawExtent() == null) { return; } + + if (this.antiAlias) { + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); + } else { + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); + g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT); + g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT); + } + if (this.xAxis) { this.drawXAxis(g, area, plot); } else { diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/LonLatAxis.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/LonLatAxis.java index 1d456e6e..be298ea2 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/LonLatAxis.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/LonLatAxis.java @@ -6,7 +6,7 @@ package org.meteoinfo.chart.axis; import org.meteoinfo.chart.ChartText; -import org.meteoinfo.chart.plot.MapGridLine; +import org.meteoinfo.chart.geo.MapGridLine; import org.meteoinfo.common.DataConvert; import java.util.ArrayList; diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/ProjLonLatAxis.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/ProjLonLatAxis.java index 06731ca9..6b79d24f 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/ProjLonLatAxis.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/ProjLonLatAxis.java @@ -5,20 +5,16 @@ */ package org.meteoinfo.chart.axis; -import org.meteoinfo.chart.ChartText; import org.meteoinfo.chart.Location; import org.meteoinfo.chart.plot.AbstractPlot2D; -import org.meteoinfo.chart.plot.MapGridLine; +import org.meteoinfo.chart.geo.MapGridLine; import org.meteoinfo.common.*; import org.meteoinfo.geo.drawing.Draw; -import org.meteoinfo.projection.KnownCoordinateSystems; import org.meteoinfo.projection.ProjectionInfo; -import org.meteoinfo.projection.Reproject; import java.awt.*; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; -import java.util.ArrayList; import java.util.List; /** diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/MapGridLine.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/geo/MapGridLine.java similarity index 99% rename from meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/MapGridLine.java rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/geo/MapGridLine.java index 343286c7..f01bafb1 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/MapGridLine.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/geo/MapGridLine.java @@ -1,6 +1,8 @@ -package org.meteoinfo.chart.plot; +package org.meteoinfo.chart.geo; import org.meteoinfo.chart.axis.PositionType; +import org.meteoinfo.chart.plot.GridLabelPosition; +import org.meteoinfo.chart.plot.GridLine; import org.meteoinfo.common.*; import org.meteoinfo.geometry.geoprocess.GeoComputation; import org.meteoinfo.geometry.graphic.Graphic; diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/MapGridLine3D.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/geo/MapGridLine3D.java similarity index 97% rename from meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/MapGridLine3D.java rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/geo/MapGridLine3D.java index 51f32a7c..ad12d1a3 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/MapGridLine3D.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/geo/MapGridLine3D.java @@ -1,5 +1,6 @@ -package org.meteoinfo.chart.plot; +package org.meteoinfo.chart.geo; +import org.meteoinfo.chart.geo.MapGridLine; import org.meteoinfo.geometry.graphic.GraphicCollection3D; import org.meteoinfo.common.Extent; import org.meteoinfo.common.Extent3D; diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/MapPlot.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/geo/MapPlot.java similarity index 93% rename from meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/MapPlot.java rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/geo/MapPlot.java index 240d57b6..642da64e 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/MapPlot.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/geo/MapPlot.java @@ -3,34 +3,33 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package org.meteoinfo.chart.plot; +package org.meteoinfo.chart.geo; import org.meteoinfo.chart.*; import org.meteoinfo.chart.axis.Axis; import org.meteoinfo.chart.axis.LonLatAxis; import org.meteoinfo.chart.axis.ProjLonLatAxis; +import org.meteoinfo.chart.geo.MapGridLine; import org.meteoinfo.chart.graphic.WebMapImage; -import org.meteoinfo.chart.shape.PolylineErrorShape; +import org.meteoinfo.chart.plot.Plot2D; +import org.meteoinfo.chart.plot.PlotType; import org.meteoinfo.common.*; import org.meteoinfo.data.Dataset; import org.meteoinfo.data.mapdata.webmap.IWebMapPanel; import org.meteoinfo.data.mapdata.webmap.TileLoadListener; import org.meteoinfo.geo.drawing.Draw; +import org.meteoinfo.geo.graphic.GeoGraphicCollection; +import org.meteoinfo.geo.util.GeoProjectionUtil; import org.meteoinfo.geometry.graphic.Graphic; import org.meteoinfo.geometry.graphic.GraphicCollection; -import org.meteoinfo.geometry.graphic.Line2DGraphic; import org.meteoinfo.geometry.legend.*; import org.meteoinfo.geometry.shape.*; -import org.meteoinfo.geometry.shape.Polygon; -import org.meteoinfo.geometry.shape.Shape; import org.meteoinfo.projection.KnownCoordinateSystems; import org.meteoinfo.projection.ProjectionInfo; import org.meteoinfo.projection.ProjectionUtil; import org.meteoinfo.projection.Reproject; import org.w3c.dom.Document; import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; @@ -44,9 +43,6 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; /** * @@ -436,7 +432,7 @@ public class MapPlot extends Plot2D implements IWebMapPanel { } @Override - void drawGraph(Graphics2D g, Rectangle2D area) { + protected void drawGraph(Graphics2D g, Rectangle2D area) { //fill boundary polygon java.awt.Shape oldRegion = g.getClip(); if (this.clip) { @@ -474,7 +470,7 @@ public class MapPlot extends Plot2D implements IWebMapPanel { } @Override - void plotGraphics(Graphics2D g, Rectangle2D area) { + protected void plotGraphics(Graphics2D g, Rectangle2D area) { int barIdx = 0; for (int m = 0; m < this.graphics.getNumGraphics(); m++) { Graphic graphic = this.graphics.get(m); @@ -493,6 +489,12 @@ public class MapPlot extends Plot2D implements IWebMapPanel { if (graphic.getExtent().intersects(this.drawExtent)) { drawGraphics(g, graphic, area); } + + if (this.isLonLatMap() && graphic instanceof GeoGraphicCollection) { + if (this.drawExtent.maxX > 180) { + drawGraphics(g, ((GeoGraphicCollection) graphic).xShiftCopy(360), area); + } + } } } @@ -565,7 +567,7 @@ public class MapPlot extends Plot2D implements IWebMapPanel { this.addGraphic(graphic); return graphic; } else { - Graphic nGraphic = ProjectionUtil.projectClipGraphic(graphic, proj, toProj); + Graphic nGraphic = GeoProjectionUtil.projectClipGraphic(graphic, proj, toProj); this.addGraphic(nGraphic); return nGraphic; } @@ -585,61 +587,12 @@ public class MapPlot extends Plot2D implements IWebMapPanel { this.addGraphic(index, graphic); return graphic; } else { - Graphic nGraphic = ProjectionUtil.projectClipGraphic(graphic, proj, toProj); + Graphic nGraphic = GeoProjectionUtil.projectClipGraphic(graphic, proj, toProj); this.addGraphic(index, nGraphic); return nGraphic; } } - /** - * Add graphics - * - * @param graphics The graphics - * @param proj The graphic projection - * @return Added graphics - */ - public GraphicCollection addGraphics(GraphicCollection graphics, ProjectionInfo proj) { - - ProjectionInfo toProj = this.projInfo; - if (proj.equals(toProj)) { - for (int i = 0; i < graphics.getNumGraphics(); i++) - this.addGraphic(graphics.getGraphicN(i)); - return graphics; - } else { - GraphicCollection nGraphics = new GraphicCollection(); - for (int i = 0; i < graphics.getNumGraphics(); i++) { - Graphic nGraphic = ProjectionUtil.projectClipGraphic(graphics.getGraphicN(i), proj, toProj); - nGraphics.add(nGraphic); - this.addGraphic(nGraphic); - } - return nGraphics; - } - } - - /** - * Add graphics - * - * @param index The graphics index - * @param graphics The graphics - * @param proj The graphic projection - * @return Added graphics - */ - public GraphicCollection addGraphics(int index, GraphicCollection graphics, ProjectionInfo proj) { - ProjectionInfo toProj = this.projInfo; - if (proj.equals(toProj)) { - this.addGraphic(index, graphics); - return graphics; - } else { - GraphicCollection nGraphics = new GraphicCollection(); - for (int i = 0; i < graphics.getNumGraphics(); i++) { - Graphic nGraphic = ProjectionUtil.projectClipGraphic(graphics.getGraphicN(i), proj, toProj); - this.addGraphic(nGraphic); - } - this.addGraphic(nGraphics); - return nGraphics; - } - } - @Override public void addText(ChartText text) { addText(text, true); @@ -932,10 +885,25 @@ public class MapPlot extends Plot2D implements IWebMapPanel { return graphic; } - void drawGridLine(Graphics2D g, Rectangle2D area) { + @Override + protected void drawGridLine(Graphics2D g, Rectangle2D area) { if (this.projInfo.isLonLat()) { super.drawGridLine(g, area); } else { + if (this.antiAlias) { + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); + } else { + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); + g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT); + g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT); + } + AffineTransform oldMatrix = g.getTransform(); java.awt.Shape oldRegion = g.getClip(); if (this.clip) { diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/MapGLPlot.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/MapGLPlot.java index 95def7a6..25724fbc 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/MapGLPlot.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/MapGLPlot.java @@ -6,8 +6,8 @@ import org.joml.Vector3f; import org.meteoinfo.chart.ChartText; import org.meteoinfo.geometry.graphic.GraphicCollection3D; import org.meteoinfo.chart.graphic.GraphicProjectionUtil; -import org.meteoinfo.chart.plot.MapGridLine; -import org.meteoinfo.chart.plot.MapGridLine3D; +import org.meteoinfo.chart.geo.MapGridLine; +import org.meteoinfo.chart.geo.MapGridLine3D; import org.meteoinfo.common.*; import org.meteoinfo.geometry.graphic.Graphic; import org.meteoinfo.projection.ProjectionInfo; diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/AbstractPlot2D.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/AbstractPlot2D.java index 9d1af40e..c3fc15be 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/AbstractPlot2D.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/AbstractPlot2D.java @@ -55,6 +55,7 @@ public abstract class AbstractPlot2D extends Plot { protected double aspect = 1; protected boolean clip = true; protected boolean fixDrawExtent = false; + protected boolean antiAlias = false; // // @@ -719,6 +720,22 @@ public abstract class AbstractPlot2D extends Plot { this.fixDrawExtent = value; } + /** + * Return antiAlias + * @return AntiAlias + */ + public boolean isAntiAlias() { + return this.antiAlias; + } + + /** + * Set antiAlias + * @param value Set antiAlias + */ + public void setAntiAlias(boolean value) { + this.antiAlias = value; + } + // // /** @@ -1178,11 +1195,25 @@ public abstract class AbstractPlot2D extends Plot { } } - void drawGridLine(Graphics2D g, Rectangle2D area) { + protected void drawGridLine(Graphics2D g, Rectangle2D area) { if (!this.gridLine.isDrawXLine() && !this.gridLine.isDrawYLine()) { return; } + if (this.gridLine.isAntiAlias()) { + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); + } else { + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); + g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT); + g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT); + } + double[] xy; double x, y; double miny = area.getY(); @@ -1247,6 +1278,20 @@ public abstract class AbstractPlot2D extends Plot { abstract void drawGraph(Graphics2D g, Rectangle2D area); void drawAxis(Graphics2D g, Rectangle2D area) { + if (this.antiAlias) { + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); + } else { + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); + g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT); + g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT); + } + for (Location loc : this.axis.keySet()) { Axis ax = this.axis.get(loc); if (ax.isVisible()) { diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/GridLine.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/GridLine.java index 29592731..a77f4fad 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/GridLine.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/GridLine.java @@ -6,6 +6,7 @@ package org.meteoinfo.chart.plot; import org.meteoinfo.common.colors.ColorUtil; +import org.meteoinfo.geometry.graphic.Artist; import org.meteoinfo.geometry.legend.LineStyles; import org.meteoinfo.geometry.legend.PolylineBreak; @@ -15,7 +16,7 @@ import java.awt.*; * * @author yaqiang */ -public class GridLine { +public class GridLine extends Artist { // protected PolylineBreak lineBreak; protected boolean drawXLine; diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/MapPlotBackup.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/MapPlotBackup.java deleted file mode 100644 index d9a41094..00000000 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/MapPlotBackup.java +++ /dev/null @@ -1,1307 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.meteoinfo.chart.plot; - -import org.meteoinfo.chart.*; -import org.meteoinfo.chart.axis.LonLatAxis; -import org.meteoinfo.common.*; -import org.meteoinfo.data.Dataset; -import org.meteoinfo.data.mapdata.webmap.IWebMapPanel; -import org.meteoinfo.data.mapdata.webmap.TileLoadListener; -import org.meteoinfo.geo.drawing.Draw; -import org.meteoinfo.geo.layer.LayerCollection; -import org.meteoinfo.geo.layer.MapLayer; -import org.meteoinfo.geo.legend.MapFrame; -import org.meteoinfo.geo.mapview.MapView; -import org.meteoinfo.geometry.graphic.Graphic; -import org.meteoinfo.geometry.graphic.GraphicCollection; -import org.meteoinfo.geometry.legend.LegendScheme; -import org.meteoinfo.geometry.legend.PointBreak; -import org.meteoinfo.geometry.legend.PolygonBreak; -import org.meteoinfo.geometry.legend.PolylineBreak; -import org.meteoinfo.geometry.shape.*; -import org.meteoinfo.projection.KnownCoordinateSystems; -import org.meteoinfo.projection.ProjectionInfo; -import org.meteoinfo.projection.ProjectionUtil; -import org.meteoinfo.projection.Reproject; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import java.awt.*; -import java.awt.geom.Line2D; -import java.awt.geom.Rectangle2D; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - * @author wyq - */ -public class MapPlotBackup extends AbstractPlot2D implements IWebMapPanel { - - // - private MapFrame mapFrame; - private MapView mapView; - private ProjectionInfo projInfo; - private boolean antialias; - private MapLayer selectedLayer; - protected TileLoadListener tileLoadListener = new TileLoadListener(this); - private IChartPanel parent; - private float[] lonLim; - private float[] latLim; - private Graphic boundary; - private ChartScaleBar scaleBar; - private ChartNorthArrow northArrow; - private boolean degreeSpace = false; - - // - // - /** - * Constructor - */ - public MapPlotBackup() { - this(KnownCoordinateSystems.geographic.world.WGS1984); - } - - /** - * Constructor - * @param projInfo The projection info - */ - public MapPlotBackup(ProjectionInfo projInfo) { - super(); - - this.projInfo = projInfo; - this.antialias = false; - this.aspectType = AspectType.EQUAL; - this.setXAxis(new LonLatAxis("Longitude", true)); - this.setYAxis(new LonLatAxis("Latitude", false)); - this.getAxis(Location.TOP).setDrawTickLine(false); - this.getAxis(Location.TOP).setDrawTickLabel(false); - this.getAxis(Location.RIGHT).setDrawTickLine(false); - this.getAxis(Location.RIGHT).setDrawTickLabel(false); - this.setDrawNeatLine(true); - this.getGridLine().setTop(true); - } - - /** - * Constructor - * - * @param mapView MapView - */ - public MapPlotBackup(MapView mapView) { - this(); - - this.projInfo = mapView.getProjection().getProjInfo(); - this.setMapView(mapView, true); - this.mapFrame = new MapFrame(); - this.mapFrame.setMapView(mapView); - } - - /** - * Constructor - * - * @param mapFrame MapFrame - */ - public MapPlotBackup(MapFrame mapFrame) { - this(); - - this.projInfo = mapFrame.getMapView().getProjection().getProjInfo(); - this.mapFrame = mapFrame; - this.setMapView(mapFrame.getMapView(), true); - } - - // - // - - /** - * Get tile load listener - * - * @return Tile load listener - */ - public TileLoadListener getTileLoadListener() { - return this.tileLoadListener; - } - - /** - * ChartPanel parent - * - * @param value ChartPanel - */ - public void setParent(IChartPanel value) { - this.parent = value; - } - - @Override - public Dataset getDataset() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void setDataset(Dataset dataset) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - /** - * Get map view - * - * @return Map view - */ - public MapView getMapView() { - return this.mapView; - } - - /** - * Set map view - * - * @param value Map view - * @param isGeoMap If is geo map - */ - public void setMapView(MapView value, boolean isGeoMap) { - this.mapView = value; - this.mapView.setLockViewUpdate(true); - this.mapView.setGeoMap(isGeoMap); - this.mapView.setMultiGlobalDraw(isGeoMap); - Extent extent = this.getAutoExtent(); - this.setDrawExtent(extent); - PolygonShape bvs = this.getProjInfo().getBoundary(); - if (bvs != null) { - this.setBoundary(bvs); - } - } - - /** - * Get view extent - * @return View extent - */ - public Extent getViewExtent() { - return this.mapView.getViewExtent(); - } - - /** - * Get x scale - * @return X scale - */ - @Override - public double getXScale() { - return this.mapView.getXScale(); - } - - /** - * Get y scale - * @return Y scale - */ - @Override - public double getYScale() { - return this.mapView.getYScale(); - } - - @Override - public PlotType getPlotType() { - return PlotType.XY2D; - } - - /** - * Get if is antialias - * - * @return Boolean - */ - public boolean isAntialias() { - return this.antialias; - } - - /** - * Set if is antialias - * - * @param value Boolean - */ - public void setAntialias(boolean value) { - this.antialias = value; - } - - /** - * Get background color - * - * @return Background color - */ - @Override - public Color getBackground() { - return this.mapView.getBackground(); - } - - /** - * Set background color - * - * @param value Background color - */ - @Override - public void setBackground(Color value) { - this.mapView.setBackground(value); - } - - /** - * Get map frame - * - * @return Map frame - */ - public MapFrame getMapFrame() { - return this.mapFrame; - } - - /** - * Set map frame - * - * @param value Map frame - */ - public void setMapFrame(MapFrame value) { - this.mapFrame = value; - this.setMapView(mapFrame.getMapView(), true); - } - - /** - * Get projection info - * - * @return Projection info - */ - public ProjectionInfo getProjInfo() { - return this.projInfo; - } - - /** - * Set projection info - * @param proj Projection info - */ - public void setProjInfo(ProjectionInfo proj) { - this.projInfo = proj; - this.getMapView().getProjection().setProjInfo(proj); - if (proj.getBoundary() != null) { - this.setBoundary(proj.getBoundary()); - } - } - - /** - * Is lon/lat map or not - * - * @return Boolean - */ - public boolean isLonLatMap() { - return this.projInfo.isLonLat(); - } - - /** - * Get selected layer - * - * @return Selected layer - */ - public MapLayer getSelectedLayer() { - if (this.selectedLayer != null) { - return this.selectedLayer; - } else if (this.mapView.getLastAddedLayer() != null) { - return this.mapView.getLastAddedLayer(); - } else { - return null; - } - } - - /** - * Set selected layer - * - * @param value Selected layer - */ - public void setSelectedLayer(MapLayer value) { - this.selectedLayer = value; - } - - /** - * Get longitude limitations - * - * @return Longitude limitations - */ - public float[] getLonLim() { - return this.lonLim; - } - - /** - * Set longitude limitations - * - * @param value Longitude limitations - */ - public void setLonLim(float[] value) { - this.lonLim = value; - } - - /** - * Set longitude limitations - * - * @param lon1 Minimum longitude - * @param lon2 Maximum longitude - */ - public void setLonLim(float lon1, float lon2) { - this.lonLim = new float[]{lon1, lon2}; - } - - /** - * Get latitude limitations - * - * @return latitude limitations - */ - public float[] getLatLim() { - return this.latLim; - } - - /** - * Set latitude limitations - * - * @param value latitude limitations - */ - public void setLatLim(float[] value) { - this.latLim = value; - } - - /** - * Set latitude limitations - * - * @param lat1 Minimum latitude - * @param lat2 Maximum latitude - */ - public void setLatLim(float lat1, float lat2) { - this.latLim = new float[]{lat1, lat2}; - } - - /** - * Get map boundary - * - * @return Map boundary - */ - public Graphic getBoundary() { - return this.boundary; - } - - /** - * Set map boundary - * - * @param value Map boundary - */ - public void setBoundary(Graphic value) { - this.boundary = value; - } - - /** - * Set map boundary - * - * @param value Map boundary - */ - public void setBoundary(PolygonShape value) { - PolygonBreak pb = new PolygonBreak(); - pb.setOutlineSize(1.5f); - pb.setDrawFill(false); - this.boundary = new Graphic(value, pb); - } - - /** - * Set boundary property - * @param pb Boundary property - */ - public void setBoundaryProp(PolygonBreak pb) { - if (this.boundary != null) { - this.boundary = new Graphic(this.boundary.getShape(), pb); - } - } - - /** - * Get scale bar - * @return Scale bar - */ - public ChartScaleBar getScaleBar() { - return this.scaleBar; - } - - /** - * Set scale bar - * @param value Scale bar - */ - public void setScaleBar(ChartScaleBar value) { - this.scaleBar = value; - } - - /** - * Get north arrow - * @return North arrow - */ - public ChartNorthArrow getNorthArrow() { - return this.northArrow; - } - - /** - * Set north arrow - * @param value North arrow - */ - public void setNorthArrow(ChartNorthArrow value) { - this.northArrow = value; - } - - /** - * Get if using space between degree and E/W/S/N - * @return Boolean - */ - public boolean isDegreeSpace() { - return this.degreeSpace; - } - - /** - * Set if using space between degree and E/W/S/N - * @param value Boolean - */ - public void setDegreeSpace(boolean value) { - this.degreeSpace = value; - } - // - // - /** - * Check if the plot has web map layer - * - * @return Boolean - */ - public boolean hasWebMapLayer() { - return this.mapView.hasWebMapLayer(); - } - - /** - * Get web map zoom - * - * @return Web map zoom - */ - @Override - public int getWebMapZoom() { - return this.mapView.getWebMapZoom(); - } - - @Override - public void reDraw() { - if (this.parent != null) { - this.parent.paintGraphics(); - } - } - - /** - * Re draw function - * @param graphics2D Graphics2D object - * @param width Width - * @param height Height - */ - @Override - public void reDraw(Graphics2D graphics2D, int width, int height) { - if (this.parent != null) { - this.parent.paintGraphics(graphics2D, width, height); - } - } - - /** - * Draw plot - * - * @param g Graphics2D - * @param area Drawing area - */ - @Override - public void draw(Graphics2D g, Rectangle2D area) { - super.draw(g, area); - if (this.scaleBar != null) { - float x = (float) (area.getWidth() * this.scaleBar.getX()); - float y = (float) (area.getHeight() * (1 - this.scaleBar.getY())); - this.scaleBar.draw(g, x, y); - } - - if (this.northArrow != null) { - float x = (float) (area.getWidth() * this.northArrow.getX()); - float y = (float) (area.getHeight() * (1 - this.northArrow.getY())); - this.northArrow.draw(g, x, y); - } - } - - @Override - void drawGraph(Graphics2D g, Rectangle2D area) { - this.mapView.setLockViewUpdate(false); - this.mapView.setAntiAlias(this.antialias); - //this.mapView.setViewExtent((Extent) this.getDrawExtent().clone()); - if (this.mapView.hasWebMapLayer()) { - this.mapView.setViewExtent((Extent) this.getDrawExtent().clone()); - this.mapView.refreshXYScaleWebMap((Extent) this.getDrawExtent().clone(), area.getWidth(), - area.getHeight()); - /*this.mapView.zoomToExtent((Extent) this.getDrawExtent().clone(), - (int) area.getWidth(), (int) area.getHeight());*/ - } - if (this.boundary != null) { - PolygonBreak pb = (PolygonBreak)this.boundary.getLegend().clone(); - if (pb.isDrawFill()) { - pb.setDrawOutline(false); - this.mapView.drawGraphic(g, new Graphic(this.boundary.getShape(), pb), area.getBounds()); - //pb.setDrawOutline(true); - } - } - this.mapView.paintGraphics(g, area, this.tileLoadListener); - if (this.boundary != null) { - PolygonBreak pb = (PolygonBreak)this.boundary.getLegend().clone(); - pb.setDrawFill(false); - this.mapView.drawGraphic(g, new Graphic(this.boundary.getShape(), pb), area.getBounds()); - //pb.setDrawFill(true); - } - this.mapView.setLockViewUpdate(true); - } - - /** - * Get auto extent - * - * @return Auto extent - */ - @Override - public Extent getAutoExtent() { - return this.mapView.getLayersWholeExtent(); - } - - @Override - public void setAutoExtent() { - - } - - @Override - public void updateLegendScheme() { - - } - - /** - * Add a graphic - * - * @param graphic The graphic - */ - public void addGraphic(Graphic graphic) { - this.getMapView().addGraphic(graphic); - } - - /** - * Add graphics - * @param graphics The graphics - */ - public void addGraphics(GraphicCollection graphics) { - for (int i = 0; i < graphics.getNumGraphics(); i++) { - this.getMapView().addGraphic(graphics.getGraphicN(i)); - } - } - - /** - * Add a graphic - * - * @param graphic The graphic - * @param proj The graphic projection - * @return Added graphic - */ - public Graphic addGraphic(Graphic graphic, ProjectionInfo proj) { - ProjectionInfo toProj = this.getProjInfo(); - if (proj.equals(toProj)) { - this.getMapView().addGraphic(graphic); - return graphic; - } else { - Graphic nGraphic = ProjectionUtil.projectGraphic(graphic, proj, toProj); - this.getMapView().addGraphic(nGraphic); - return nGraphic; - } - } - - /** - * Add graphics - * - * @param graphics The graphics - * @param proj The graphic projection - * @return Added graphics - */ - public GraphicCollection addGraphics(GraphicCollection graphics, ProjectionInfo proj) { - - ProjectionInfo toProj = this.getMapView().getProjection().getProjInfo(); - if (proj.equals(toProj)) { - for (int i = 0; i < graphics.getNumGraphics(); i++) - this.getMapView().addGraphic(graphics.getGraphicN(i)); - return graphics; - } else { - GraphicCollection nGraphics = new GraphicCollection(); - for (int i = 0; i < graphics.getNumGraphics(); i++) { - Graphic nGraphic = ProjectionUtil.projectGraphic(graphics.getGraphicN(i), proj, toProj); - nGraphics.add(nGraphic); - this.getMapView().addGraphic(nGraphic); - } - return nGraphics; - } - } - - /** - * Add a layer - * - * @param layer The layer - */ - public void addLayer(MapLayer layer) { - this.mapView.addLayer(layer); - this.setDrawExtent(layer.getExtent()); - } - - /** - * Add a layer - * - * @param idx Index - * @param layer Layer - */ - public void addLayer(int idx, MapLayer layer) { - this.mapView.addLayer(idx, layer); - this.setDrawExtent(layer.getExtent()); - } - - /** - * Remove last added layer - */ - public void removeLastLayer() { - this.mapView.removeLayer(this.mapView.getLastAddedLayer()); - } - - /** - * Set all axis visible or not - * - * @param value Boolean - */ - @Override - public void setAxisOn(boolean value) { - super.setAxisOn(value); - this.mapFrame.setDrawGridTickLine(value); - this.mapFrame.setDrawGridLabel(value); - } - - /** - * Get full extent - * - * @return Full extent - */ - public Extent getFullExtent() { - Extent ext = this.mapView.getExtent(); - if (this.boundary != null) { - ext = ext.union(this.boundary.getExtent().extend(0.01)); - } - - return ext; - } - - /** - * Set longitude/latitude extent - * - * @param extent Extent - */ - public void setLonLatExtent(Extent extent) { - if (this.getMapView().getProjection().isLonLatMap()) { - super.setDrawExtent(extent); - } else { - this.getMapView().zoomToExtentLonLatEx(extent); - super.setDrawExtent1(this.getMapView().getViewExtent()); - this.setAxisExtent(extent); - } - } - - /** - * Set axis extent - * - * @param extent Extent - */ - public void setAxisExtent(Extent extent) { - this.getAxis(Location.BOTTOM).setMinMaxValue(extent.minX, extent.maxX); - this.getAxis(Location.TOP).setMinMaxValue(extent.minX, extent.maxX); - this.getAxis(Location.LEFT).setMinMaxValue(extent.minY, extent.maxY); - this.getAxis(Location.RIGHT).setMinMaxValue(extent.minY, extent.maxY); - } - - @Override - public void addText(ChartText text) { - addText(text, true); - } - - public void addText(ChartText text, boolean isLonLat) { - if (isLonLat) { - if (!this.getMapView().getProjection().isLonLatMap()) { - PointD xyp = Reproject.reprojectPoint(text.getX(), text.getY(), KnownCoordinateSystems.geographic.world.WGS1984, - this.getMapView().getProjection().getProjInfo()); - text.setX(xyp.X); - text.setY(xyp.Y); - } - } - super.addText(text); - } - - /** - * Add point graphic - * - * @param lat Latitude - * @param lon Longitude - * @param pb Point break - */ - public void addPoint(double lat, double lon, PointBreak pb) { - PointShape ps = new PointShape(); - PointD lonlatp = new PointD(lon, lat); - if (this.isLonLatMap()) { - ps.setPoint(lonlatp); - } else { - PointD xyp = Reproject.reprojectPoint(lonlatp, KnownCoordinateSystems.geographic.world.WGS1984, - this.getProjInfo()); - ps.setPoint(xyp); - } - Graphic aGraphic = new Graphic(ps, pb); - this.getMapView().addGraphic(aGraphic); - } - - /** - * Add point graphic - * - * @param lat Latitude - * @param lon Lontitude - * @param pb Point break - * @return Graphic - */ - public Graphic addPoint(List lat, List lon, PointBreak pb) { - double x, y; - PointShape ps; - PointD lonlatp, xyp; - for (int i = 0; i < lat.size(); i++) { - ps = new PointShape(); - x = lon.get(i).doubleValue(); - y = lat.get(i).doubleValue(); - lonlatp = new PointD(x, y); - if (this.isLonLatMap()) { - ps.setPoint(lonlatp); - } else { - xyp = Reproject.reprojectPoint(lonlatp, KnownCoordinateSystems.geographic.world.WGS1984, - this.getProjInfo()); - ps.setPoint(xyp); - } - Graphic aGraphic = new Graphic(ps, pb); - this.getMapView().addGraphic(aGraphic); - return aGraphic; - } - return null; - } - - /** - * Add polyline - * - * @param lat Latitude - * @param lon Longitude - * @param plb PolylineBreak - * @return Graphic - */ - public Graphic addPolyline(List lat, List lon, PolylineBreak plb) { - double x, y; - PolylineShape pls; - PointD lonlatp; - List points = new ArrayList<>(); - for (int i = 0; i < lat.size(); i++) { - x = lon.get(i).doubleValue(); - y = lat.get(i).doubleValue(); - if (Double.isNaN(x)) { - if (points.size() >= 2) { - pls = new PolylineShape(); - pls.setPoints(points); - Graphic aGraphic = new Graphic(pls, plb); - this.getMapView().addGraphic(aGraphic); - } - points = new ArrayList<>(); - } else { - lonlatp = new PointD(x, y); - if (!this.isLonLatMap()) { - lonlatp = Reproject.reprojectPoint(lonlatp, KnownCoordinateSystems.geographic.world.WGS1984, - this.getMapView().getProjection().getProjInfo()); - } - points.add(lonlatp); - } - } - if (points.size() >= 2) { - pls = new PolylineShape(); - pls.setPoints(points); - Graphic aGraphic = new Graphic(pls, plb); - this.getMapView().addGraphic(aGraphic); - return aGraphic; - } - return null; - } - - /** - * Add polyline - * - * @param lat Latitude - * @param lon Longitude - * @param plb PolylineBreak - * @param iscurve Is curve line or not - * @return Graphic - */ - public Graphic addPolyline(List lat, List lon, PolylineBreak plb, boolean iscurve) { - double x, y; - PolylineShape pls; - PointD lonlatp; - List points = new ArrayList<>(); - for (int i = 0; i < lat.size(); i++) { - x = lon.get(i).doubleValue(); - y = lat.get(i).doubleValue(); - if (Double.isNaN(x)) { - if (points.size() >= 2) { - if (iscurve) { - pls = new CurveLineShape(); - } else { - pls = new PolylineShape(); - } - pls.setPoints(points); - Graphic aGraphic = new Graphic(pls, plb); - this.getMapView().addGraphic(aGraphic); - } - points = new ArrayList<>(); - } else { - lonlatp = new PointD(x, y); - if (!this.getMapView().getProjection().isLonLatMap()) { - lonlatp = Reproject.reprojectPoint(lonlatp, KnownCoordinateSystems.geographic.world.WGS1984, - this.getMapView().getProjection().getProjInfo()); - } - points.add(lonlatp); - } - } - if (points.size() >= 2) { - if (iscurve) { - pls = new CurveLineShape(); - } else { - pls = new PolylineShape(); - } - pls.setPoints(points); - Graphic aGraphic = new Graphic(pls, plb); - this.getMapView().addGraphic(aGraphic); - return aGraphic; - } - return null; - } - - /** - * Add polygon - * - * @param lat Latitude - * @param lon Longitude - * @param pgb PolygonBreak - * @return Graphic - */ - public Graphic addPolygon(List lat, List lon, PolygonBreak pgb) { - double x, y; - PolygonShape pgs; - PointD lonlatp; - List points = new ArrayList<>(); - for (int i = 0; i < lat.size(); i++) { - x = lon.get(i).doubleValue(); - y = lat.get(i).doubleValue(); - if (Double.isNaN(x)) { - if (points.size() > 2) { - pgs = new PolygonShape(); - pgs.setPoints(points); - Graphic aGraphic = new Graphic(pgs, pgb); - this.getMapView().addGraphic(aGraphic); - } - points = new ArrayList<>(); - } else { - lonlatp = new PointD(x, y); - if (!this.getMapView().getProjection().isLonLatMap()) { - lonlatp = Reproject.reprojectPoint(lonlatp, KnownCoordinateSystems.geographic.world.WGS1984, - this.getMapView().getProjection().getProjInfo()); - } - points.add(lonlatp); - } - } - if (points.size() > 2) { - pgs = new PolygonShape(); - pgs.setPoints(points); - Graphic aGraphic = new Graphic(pgs, pgb); - this.getMapView().addGraphic(aGraphic); - return aGraphic; - } - return null; - } - - /** - * Add a circle - * - * @param x Center x - * @param y Center y - * @param radius - * @param pgb PolygonBreak - * @return Graphic - */ - public Graphic addCircle(float x, float y, float radius, PolygonBreak pgb) { - CircleShape aPGS = ShapeUtil.createCircleShape(x, y, radius); - Graphic graphic = new Graphic(aPGS, pgb); - this.addGraphic(graphic); - - return graphic; - } - - /** - * Get position area - * - * @param area Whole area - * @return Graphic area - */ - @Override - public Rectangle2D getPositionArea(Rectangle2D area) { - Rectangle2D plotArea = super.getPositionArea(area); - if (this.aspectType != AspectType.AUTO) { - MapView mv = this.mapFrame.getMapView(); - mv.setViewExtent((Extent) this.getDrawExtent().clone()); - Extent extent = mv.getViewExtent(); - double width = extent.getWidth(); - double height = extent.getHeight(); - double scaleFactor = mv.getXYScaleFactor(); - if (width / height / scaleFactor > plotArea.getWidth() / plotArea.getHeight()) { - double h = plotArea.getWidth() * height * scaleFactor / width; - double delta = plotArea.getHeight() - h; - plotArea.setRect(plotArea.getX(), plotArea.getY() + delta / 2, plotArea.getWidth(), h); - } else { - double w = width * plotArea.getHeight() / height / scaleFactor; - double delta = plotArea.getWidth() - w; - plotArea.setRect(plotArea.getX() + delta / 2, plotArea.getY(), w, plotArea.getHeight()); - } - } - return plotArea; - } - - @Override - void drawAxis(Graphics2D g, Rectangle2D area) { - if (this.mapFrame.getMapView().getProjection().isLonLatMap()) { - super.drawAxis(g, area); - return; - } - - //Draw lon/lat grid labels - if (this.mapFrame.isDrawGridLabel()) { - final float shift = 5.0F; - List extentList = new ArrayList<>(); - Extent maxExtent = new Extent(); - Extent aExtent; - Dimension aSF; - g.setColor(this.mapFrame.getGridLineColor()); - g.setStroke(new BasicStroke(this.mapFrame.getGridLineSize())); - String drawStr; - PointF sP = new PointF(0, 0); - PointF eP = new PointF(0, 0); - Font font = this.getXAxis().getTickLabelFont(); - //Font font = new Font(this.mapFrame.getGridFont().getFontName(), this.mapFrame.getGridFont().getStyle(), (int) (this.mapFrame.getGridFont().getSize())); - g.setFont(font); - float labX, labY; - int len = mapFrame.getTickLineLength(); - int space = mapFrame.getGridLabelShift(); - - Object[] objs; - float xShift, yShift; - XAlign xAlign = XAlign.CENTER; - YAlign yAlign = YAlign.CENTER; - for (int i = 0; i < mapFrame.getMapView().getGridLabels().size(); i++) { - GridLabel aGL = mapFrame.getMapView().getGridLabels().get(i); - switch (mapFrame.getGridLabelPosition()) { - case LEFT_BOTTOM: - switch (aGL.getLabDirection()) { - case East: - case North: - continue; - } - break; - case LEFT_UP: - switch (aGL.getLabDirection()) { - case East: - case South: - continue; - } - break; - case RIGHT_BOTTOM: - switch (aGL.getLabDirection()) { - case Weast: - case North: - continue; - } - break; - case RIGHT_UP: - switch (aGL.getLabDirection()) { - case Weast: - case South: - continue; - } - break; - } - - labX = (float) aGL.getLabPoint().X; - labY = (float) aGL.getLabPoint().Y; - labX = labX + (float) area.getX(); - labY = labY + (float) area.getY(); - sP.X = labX; - sP.Y = labY; - if (aGL.isBorder()) { - switch (aGL.getLabDirection()) { - case South: - sP.Y = (float) area.getMaxY(); - break; - } - } - - drawStr = aGL.getLabString(); - //if (this.drawDegreeSymbol) { - if (drawStr.endsWith("E") || drawStr.endsWith("W") || drawStr.endsWith("N") || drawStr.endsWith("S")) { - if (this.degreeSpace) { - drawStr = drawStr.substring(0, drawStr.length() - 1) + String.valueOf((char) 186) + - " " + drawStr.substring(drawStr.length() - 1); - } else { - drawStr = drawStr.substring(0, drawStr.length() - 1) + String.valueOf((char) 186) + - drawStr.substring(drawStr.length() - 1); - } - } else { - drawStr = drawStr + String.valueOf((char) 186); - } - //} - aSF = Draw.getStringDimension(drawStr, g); - boolean ifDraw = true; - aExtent = new Extent(); - aExtent.minX = labX; - aExtent.maxX = labX + aSF.width; - aExtent.minY = labY - aSF.height; - aExtent.maxY = labY; - - //Judge extent - if (extentList.isEmpty()) { - maxExtent = (Extent) aExtent.clone(); - extentList.add((Extent) aExtent.clone()); - } else if (!MIMath.isExtentCross(aExtent, maxExtent)) { - extentList.add((Extent) aExtent.clone()); - maxExtent = MIMath.getLagerExtent(maxExtent, aExtent); - } else { - for (int j = 0; j < extentList.size(); j++) { - if (MIMath.isExtentCross(aExtent, extentList.get(j))) { - ifDraw = false; - break; - } - } - if (ifDraw) { - extentList.add(aExtent); - maxExtent = MIMath.getLagerExtent(maxExtent, aExtent); - } - } - if (ifDraw) { - if (aGL.isBorder()) { - switch (aGL.getLabDirection()) { - case South: - eP.X = sP.X; - if (mapFrame.isInsideTickLine()) { - eP.Y = sP.Y - len; - labY = sP.Y + space; - } else { - eP.Y = sP.Y + len; - labY = eP.Y + space; - } - xAlign = XAlign.CENTER; - yAlign = YAlign.TOP; - break; - case Weast: - eP.Y = sP.Y; - if (mapFrame.isInsideTickLine()) { - eP.X = sP.X + len; - labX = sP.X - space; - } else { - eP.X = sP.X - len; - labX = eP.X - space; - } - xAlign = XAlign.RIGHT; - yAlign = YAlign.CENTER; - break; - case North: - eP.X = sP.X; - if (mapFrame.isInsideTickLine()) { - eP.Y = sP.Y + len; - labY = sP.Y - space; - } else { - eP.Y = sP.Y - len; - labY = eP.Y - space; - } - xAlign = XAlign.CENTER; - yAlign = YAlign.BOTTOM; - break; - case East: - eP.Y = sP.Y; - if (mapFrame.isInsideTickLine()) { - eP.X = sP.X - len; - labX = sP.X + space; - } else { - eP.X = sP.X + len; - labX = eP.X + space; - } - xAlign = XAlign.LEFT; - yAlign = YAlign.CENTER; - break; - } - g.setColor(mapFrame.getTickLineColor()); - g.setStroke(new BasicStroke(mapFrame.getTickLineWidth())); - g.draw(new Line2D.Float(sP.X, sP.Y, eP.X, eP.Y)); - g.setColor(this.getXAxis().getTickLabelColor()); - //g.drawString(drawStr, labX, labY); - Draw.drawString(g, labX, labY, drawStr, xAlign, yAlign, false); - } else { - g.setColor(this.getXAxis().getTickLabelColor()); - objs = this.getProjInfo().checkGridLabel(aGL, shift); - xShift = (float)objs[0]; - yShift = (float)objs[1]; - xAlign = (XAlign)objs[2]; - yAlign = (YAlign)objs[3]; - Draw.drawString(g, labX+xShift, labY+yShift, drawStr, xAlign, yAlign, false); - } - } - } - } - } - - @Override - int getXAxisHeight(Graphics2D g) { - if (this.isLonLatMap()) { - return super.getXAxisHeight(g); - } - - int space = 4; - if (this.mapFrame.isDrawGridLabel()) { - int height = space; - height += mapFrame.getTickLineLength() + mapFrame.getGridLabelShift(); - FontMetrics m = g.getFontMetrics(mapFrame.getGridFont()); - height += m.getHeight(); - return height; - } - - return 0; - } - - @Override - int getYAxisWidth(Graphics2D g) { - if (this.isLonLatMap()) { - return super.getYAxisWidth(g); - } - - int space = 4; - if (this.mapFrame.isDrawGridLabel()) { - int width = space; - width += mapFrame.getTickLineLength() + mapFrame.getGridLabelShift(); - FontMetrics m = g.getFontMetrics(mapFrame.getGridFont()); - List labels = mapFrame.getMapView().getGridLabels(); - int labWidth = 0, w; - for (int i = 0; i < labels.size(); i++) { - w = m.stringWidth(labels.get(i).getLabString()); - if (w > labWidth) { - labWidth = w; - } - } - width += labWidth; - return width; - } - - return 0; - } - - /** - * Get layer number - * - * @return Layer number - */ - public int getLayerNum() { - return this.mapView.getLayerNum(); - } - - /** - * Get layers - * - * @return Layers - */ - public LayerCollection getLayers() { - return this.mapView.getLayers(); - } - - /** - * Get layer by index - * - * @param i The layer index - * @return The layer - */ - public MapLayer getLayer(int i) { - return this.mapView.getLayers().get(i); - } - - /** - * Get layer by name - * - * @param name The layer name - * @return The layer - */ - public MapLayer getLayer(String name) { - return this.mapView.getLayer(name); - } - - /** - * Get legend scheme - * - * @return Legend scheme - */ - public LegendScheme getLegendScheme() { - MapLayer layer = this.mapView.getLastAddedLayer(); - return layer == null ? null : layer.getLegendScheme(); - } - - /** - * Load MeteoInfo project file - * - * @param fn MeteoInfo project file name - * @param mfidx Map frame index - * @throws SAXException - * @throws IOException - * @throws ParserConfigurationException - */ - public void loadMIProjectFile(String fn, int mfidx) throws SAXException, IOException, ParserConfigurationException { - File file = new File(fn); - String userDir = System.getProperty("user.dir"); - System.setProperty("user.dir", file.getParent()); - String pPath = file.getParent(); - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse(new File(fn)); - - Element root = doc.getDocumentElement(); - - Element mapFrames = (Element) root.getElementsByTagName("MapFrames").item(0); - if (mapFrames == null) { - this.mapFrame.importProjectXML(pPath, root); - } else { - NodeList mfNodes = mapFrames.getElementsByTagName("MapFrame"); - Node mfNode = mfNodes.item(mfidx); - this.mapFrame.importProjectXML(pPath, (Element) mfNode); - } - this.setDrawExtent(this.mapView.getViewExtent()); - this.setExtent(this.mapView.getViewExtent()); - System.setProperty("user.dir", userDir); - } - - /** - * Load MeteoInfo project file - * - * @param fn MeteoInfo project file name - * @throws SAXException - * @throws IOException - * @throws ParserConfigurationException - */ - public void loadMIProjectFile(String fn) throws SAXException, IOException, ParserConfigurationException { - this.loadMIProjectFile(fn, 0); - } - // -} diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/PiePlot.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/PiePlot.java index 9a76aff9..bf7499ec 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/PiePlot.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/PiePlot.java @@ -40,7 +40,7 @@ public class PiePlot extends Plot2D { // // @Override - void drawGraph(Graphics2D g, Rectangle2D area) { + protected void drawGraph(Graphics2D g, Rectangle2D area) { AffineTransform oldMatrix = g.getTransform(); //Rectangle oldRegion = g.getClipBounds(); //g.setClip(area); diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/Plot2D.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/Plot2D.java index 3b81be87..c4186475 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/Plot2D.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/Plot2D.java @@ -168,7 +168,7 @@ public class Plot2D extends AbstractPlot2D { } @Override - void drawGraph(Graphics2D g, Rectangle2D area) { + protected void drawGraph(Graphics2D g, Rectangle2D area) { AffineTransform oldMatrix = g.getTransform(); java.awt.Shape oldRegion = g.getClip(); if (this.clip) { @@ -271,7 +271,7 @@ public class Plot2D extends AbstractPlot2D { g.setTransform(oldMatrix); } - void plotGraphics(Graphics2D g, Rectangle2D area) { + protected void plotGraphics(Graphics2D g, Rectangle2D area) { int barIdx = 0; for (int m = 0; m < this.graphics.getNumGraphics(); m++) { Graphic graphic = this.graphics.get(m); @@ -290,7 +290,21 @@ public class Plot2D extends AbstractPlot2D { } } - void drawGraphics(Graphics2D g, Graphic graphic, Rectangle2D area) { + protected void drawGraphics(Graphics2D g, Graphic graphic, Rectangle2D area) { + if (graphic.isAntiAlias()) { + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); + } else { + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); + g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT); + g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT); + } + java.awt.Shape oldClip = g.getClip(); if (graphic.isClip()) { GeneralPath clipPath = getClipPath(graphic.getClipGraphic(), area); @@ -324,7 +338,7 @@ public class Plot2D extends AbstractPlot2D { drawGraphic(g, graphic, cb, area); } - void drawGraphic(Graphics2D g, Graphic graphic, ColorBreak cb, Rectangle2D area) { + protected void drawGraphic(Graphics2D g, Graphic graphic, ColorBreak cb, Rectangle2D area) { if (graphic instanceof Line2DGraphic) { this.drawLine2D(g, (Line2DGraphic) graphic, area); return; @@ -1189,7 +1203,7 @@ public class Plot2D extends AbstractPlot2D { return n; } - void drawBars(Graphics2D g, GraphicCollection bars, int barIdx, Rectangle2D area) { + protected void drawBars(Graphics2D g, GraphicCollection bars, int barIdx, Rectangle2D area) { double[] xy; xy = this.projToScreen(0, 0, area); float y0 = (float) xy[1]; @@ -1336,7 +1350,7 @@ public class Plot2D extends AbstractPlot2D { } @Override - Extent getAutoExtent() { + protected Extent getAutoExtent() { this.graphics.updateExtent(); Extent extent = (Extent)this.graphics.getExtent().clone(); if (extent.minX == extent.maxX) { diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/PolarPlot.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/PolarPlot.java index bf3eeea0..b81b8deb 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/PolarPlot.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/PolarPlot.java @@ -292,7 +292,7 @@ public class PolarPlot extends Plot2D { } @Override - Extent getAutoExtent() { + protected Extent getAutoExtent() { Extent extent = this.getGraphics().getExtent(); if (extent.minX == extent.maxX) { extent.minX = extent.minX - Math.abs(extent.minX); @@ -489,12 +489,12 @@ public class PolarPlot extends Plot2D { } @Override - void drawGraph(Graphics2D g, Rectangle2D area) { + protected void drawGraph(Graphics2D g, Rectangle2D area) { super.drawGraph(g, area); } @Override - void drawGridLine(Graphics2D g, Rectangle2D area) { + protected void drawGridLine(Graphics2D g, Rectangle2D area) { GridLine gridLine = this.getGridLine(); if (!gridLine.isDrawXLine() && !gridLine.isDrawYLine()) { return; diff --git a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPS11DataInfo.java b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPS11DataInfo.java index 9abb205e..76bfa28c 100644 --- a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPS11DataInfo.java +++ b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPS11DataInfo.java @@ -163,6 +163,7 @@ public class MICAPS11DataInfo extends DataInfo implements IGridDataInfo { _yArray[i] = YMin + i * YDelt; } + this.addAttribute(new Attribute("data_format", "MICAPS 11")); Dimension tdim = new Dimension(DimensionType.T); tdim.setShortName("time"); double[] values = new double[1]; diff --git a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPS4DataInfo.java b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPS4DataInfo.java index 1c454081..889f8f24 100644 --- a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPS4DataInfo.java +++ b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPS4DataInfo.java @@ -27,6 +27,7 @@ import java.io.*; import java.text.NumberFormat; import java.text.ParseException; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -170,6 +171,7 @@ public class MICAPS4DataInfo extends DataInfo implements IGridDataInfo { _yArray[i] = YMin + i * YDelt; } + this.addAttribute(new Attribute("data_format", "MICAPS 4")); Dimension tdim = new Dimension(DimensionType.T); double[] values = new double[1]; values[0] = JDateUtil.toOADate(time); @@ -212,6 +214,17 @@ public class MICAPS4DataInfo extends DataInfo implements IGridDataInfo { return new ArrayList<>(); } + @Override + public String generateInfoText() { + String dataInfo; + dataInfo = "Description: " + _description; + DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:00"); + dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().get(0)); + dataInfo += System.getProperty("line.separator") + super.generateInfoText(); + + return dataInfo; + } + /** * Read array data of a variable * diff --git a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPSDataInfo.java b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPSDataInfo.java index 876aac8f..40ea6069 100644 --- a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPSDataInfo.java +++ b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPSDataInfo.java @@ -59,6 +59,18 @@ public class MICAPSDataInfo { dataArray = aLine.split("\\s+"); dataType = dataArray[0] + " " + dataArray[1]; dataType = dataType.trim().toLowerCase(); + if (dataType.equals("diamond 11")) { + mdType = MeteoDataType.MICAPS_11; + } + if (dataType.equals("diamond 13")) { + mdType = MeteoDataType.MICAPS_13; + } + if (dataType.contains("iamond 120")) { + mdType = MeteoDataType.MICAPS_120; + } + if (dataType.contains("diamond 131")) { + mdType = MeteoDataType.MICAPS_131; + } if (dataType.contains("diamond 1")) { mdType = MeteoDataType.MICAPS_1; } @@ -74,18 +86,6 @@ public class MICAPSDataInfo { if (dataType.equals("diamond 7")) { mdType = MeteoDataType.MICAPS_7; } - if (dataType.equals("diamond 11")) { - mdType = MeteoDataType.MICAPS_11; - } - if (dataType.equals("diamond 13")) { - mdType = MeteoDataType.MICAPS_13; - } - if (dataType.contains("iamond 120")) { - mdType = MeteoDataType.MICAPS_120; - } - if (dataType.contains("diamond 131")) { - mdType = MeteoDataType.MICAPS_131; - } if (mdType == null) { System.out.println(String.format("Unknown MICAPS data file type: %s", dataType)); } @@ -126,7 +126,15 @@ public class MICAPSDataInfo { StringTokenizer stoker = new StringTokenizer(line); if (stoker.countTokens() >= 2) { String dataType = stoker.nextToken() + " " + stoker.nextToken(); - if (dataType.contains("diamond 1")) { + if (dataType.equals("diamond 11")) { + dataInfo = new MICAPS11DataInfo(); + } else if (dataType.equals("diamond 13")) { + dataInfo = new MICAPS13DataInfo(); + } else if (dataType.contains("iamond 120")) { + dataInfo = new MICAPS120DataInfo(); + } else if (dataType.contains("diamond 131")) { + dataInfo = new MICAPS131DataInfo(); + } else if (dataType.contains("diamond 1")) { dataInfo = new MICAPS1DataInfo(); } else if (dataType.equals("diamond 2")) { dataInfo = new MICAPS2DataInfo(); @@ -136,14 +144,6 @@ public class MICAPSDataInfo { dataInfo = new MICAPS4DataInfo(); } else if (dataType.equals("diamond 7")) { dataInfo = new MICAPS7DataInfo(); - } else if (dataType.equals("diamond 11")) { - dataInfo = new MICAPS11DataInfo(); - } else if (dataType.equals("diamond 13")) { - dataInfo = new MICAPS13DataInfo(); - } else if (dataType.contains("iamond 120")) { - dataInfo = new MICAPS120DataInfo(); - } else if (dataType.contains("diamond 131")) { - dataInfo = new MICAPS131DataInfo(); } } } diff --git a/meteoinfo-geo/src/main/java/org/meteoinfo/geo/graphic/GeoGraphicCollection.java b/meteoinfo-geo/src/main/java/org/meteoinfo/geo/graphic/GeoGraphicCollection.java new file mode 100644 index 00000000..e29243a7 --- /dev/null +++ b/meteoinfo-geo/src/main/java/org/meteoinfo/geo/graphic/GeoGraphicCollection.java @@ -0,0 +1,184 @@ +package org.meteoinfo.geo.graphic; + +import org.meteoinfo.common.DataConvert; +import org.meteoinfo.common.Extent; +import org.meteoinfo.common.MIMath; +import org.meteoinfo.common.PointD; +import org.meteoinfo.geometry.graphic.Graphic; +import org.meteoinfo.geometry.graphic.GraphicCollection; +import org.meteoinfo.geometry.legend.ColorBreak; +import org.meteoinfo.geometry.legend.LabelBreak; +import org.meteoinfo.geometry.legend.LegendType; +import org.meteoinfo.geometry.shape.PointShape; +import org.meteoinfo.geometry.shape.PolylineShape; +import org.meteoinfo.geometry.shape.Shape; +import org.meteoinfo.projection.ProjectionInfo; +import org.meteoinfo.table.AttributeTable; +import org.meteoinfo.table.Field; + +import java.util.List; + +public class GeoGraphicCollection extends GraphicCollection { + + protected AttributeTable attributeTable; + protected ProjectionInfo projInfo; + + /** + * Constructor + */ + public GeoGraphicCollection() { + super(); + + this.attributeTable = new AttributeTable(); + this.projInfo = ProjectionInfo.LONG_LAT; + } + + /** + * Get attribute table + * @return Attribute table + */ + public AttributeTable getAttributeTable() { + return this.attributeTable; + } + + /** + * Set attribute table + * @param value Attribute table + */ + public void setAttributeTable(AttributeTable value) { + this.attributeTable = value; + } + + /** + * Get projection info + * @return Projection info + */ + public ProjectionInfo getProjInfo() { + return this.projInfo; + } + + /** + * Set projection info + * @param value Projection info + */ + public void setProjInfo(ProjectionInfo value) { + this.projInfo = value; + } + + /** + * Get cell value + * + * @param fieldName Field name + * @param shapeIndex Shape index + * @return Cell value + */ + public Object getCellValue(String fieldName, int shapeIndex) { + return attributeTable.getTable().getValue(shapeIndex, fieldName); + } + + /** + * Get minimum data value of a field + * + * @param fieldName Field name + * @return Minimum data + */ + public double getMinValue(String fieldName) { + if (((Field) attributeTable.getTable().getColumns().get(fieldName)).isNumeric()) { + double min = 0; + int dNum = 0; + for (int i = 0; i < this.getNumGraphics(); i++) { + double aValue = Double.parseDouble(getCellValue(fieldName, i).toString()); + if (Math.abs(aValue / this.getLegendScheme().getUndefValue() - 1) < 0.01) { + continue; + } + + if (dNum == 0) { + min = aValue; + } else if (min > aValue) { + min = aValue; + } + dNum += 1; + } + return min; + } else { + return 0; + } + } + + /** + * Add labels + */ + protected void addLabelsByColor() { + int shapeIdx = -1; + PointD aPoint; + + String dFormat = "%1$.1f"; + boolean isData = false; + if (((Field) attributeTable.getTable().getColumns().get(labelSet.getFieldName())).isNumeric()) { + if (labelSet.isAutoDecimal()) { + double min = getMinValue(labelSet.getFieldName()); + labelSet.setDecimalDigits(MIMath.getDecimalNum(min)); + } + + dFormat = "%1$." + String.valueOf(labelSet.getDecimalDigits()) + "f"; + isData = true; + } + + for (Graphic graphic : this.graphics) { + Shape shape = graphic.getShape(); + shapeIdx += 1; + ColorBreak aCB = graphic.getLegend(); + if (!aCB.isDrawShape()) { + continue; + } + + PointShape aPS = new PointShape(); + switch (this.getShapeType()) { + case POINT: + case POINT_M: + case POINT_Z: + aPS.setPoint((PointD) ((PointShape) shape).getPoint().clone()); + break; + case POLYLINE: + case POLYLINE_M: + case POLYLINE_Z: + int pIdx = ((PolylineShape) shape).getPoints().size() / 2; + aPS.setPoint((PointD) ((PolylineShape) shape).getPoints().get(pIdx - 1).clone()); + break; + case POLYGON: + case POLYGON_M: + case POLYGON_Z: + Extent aExtent = shape.getExtent(); + aPoint = new PointD(); + aPoint.X = ((aExtent.minX + aExtent.maxX) / 2); + aPoint.Y = ((aExtent.minY + aExtent.maxY) / 2); + aPS.setPoint(aPoint); + break; + } + + LabelBreak aLP = new LabelBreak(); + if (isData) { + if (this.labelSet.isAutoDecimal()) { + aLP.setText(DataConvert.removeTailingZeros(getCellValue(labelSet.getFieldName(), shapeIdx).toString())); + } else { + aLP.setText(String.format(dFormat, Double.parseDouble(getCellValue(labelSet.getFieldName(), shapeIdx).toString()))); + } + } else { + aLP.setText(getCellValue(labelSet.getFieldName(), shapeIdx).toString()); + } + + if (labelSet.isColorByLegend()) { + aLP.setColor(aCB.getColor()); + } else { + aLP.setColor(labelSet.getLabelColor()); + } + aLP.setFont(labelSet.getLabelFont()); + aLP.setAlignType(labelSet.getLabelAlignType()); + aLP.setYShift(labelSet.getYOffset()); + aLP.setXShift(labelSet.getXOffset()); + Graphic aGraphic = new Graphic(aPS, aLP); + addLabel(aGraphic); + } + } + +} diff --git a/meteoinfo-geo/src/main/java/org/meteoinfo/geo/layer/VectorLayer.java b/meteoinfo-geo/src/main/java/org/meteoinfo/geo/layer/VectorLayer.java index de24427c..34a7b72f 100644 --- a/meteoinfo-geo/src/main/java/org/meteoinfo/geo/layer/VectorLayer.java +++ b/meteoinfo-geo/src/main/java/org/meteoinfo/geo/layer/VectorLayer.java @@ -14,6 +14,7 @@ package org.meteoinfo.geo.layer; import org.meteoinfo.common.*; +import org.meteoinfo.geo.graphic.GeoGraphicCollection; import org.meteoinfo.geo.mapdata.ShapeFileManage; import org.meteoinfo.geometry.graphic.GraphicCollection; import org.meteoinfo.geometry.legend.*; @@ -2830,7 +2831,7 @@ public class VectorLayer extends MapLayer { * * @return Graphics */ - public GraphicCollection getGraphics() { + public GeoGraphicCollection getGraphics() { return getGraphics(0); } @@ -2840,8 +2841,10 @@ public class VectorLayer extends MapLayer { * @param xShift X shift * @return Graphics */ - public GraphicCollection getGraphics(double xShift) { - GraphicCollection graphics = new GraphicCollection(); + public GeoGraphicCollection getGraphics(double xShift) { + GeoGraphicCollection graphics = new GeoGraphicCollection(); + graphics.setAttributeTable(this._attributeTable); + graphics.setProjInfo(this._projInfo); ColorBreak cb; if (xShift == 0) { for (Shape shape : this.shapes) { diff --git a/meteoinfo-geo/src/main/java/org/meteoinfo/geo/util/GeoProjectionUtil.java b/meteoinfo-geo/src/main/java/org/meteoinfo/geo/util/GeoProjectionUtil.java index 82f4067b..7ab856b1 100644 --- a/meteoinfo-geo/src/main/java/org/meteoinfo/geo/util/GeoProjectionUtil.java +++ b/meteoinfo-geo/src/main/java/org/meteoinfo/geo/util/GeoProjectionUtil.java @@ -17,8 +17,11 @@ import org.meteoinfo.common.Extent; import org.meteoinfo.common.MIMath; import org.meteoinfo.common.PointD; import org.meteoinfo.data.GridArray; +import org.meteoinfo.geo.graphic.GeoGraphicCollection; import org.meteoinfo.geo.layer.RasterLayer; import org.meteoinfo.geo.layer.VectorLayer; +import org.meteoinfo.geometry.graphic.Graphic; +import org.meteoinfo.geometry.graphic.GraphicCollection; import org.meteoinfo.geometry.shape.*; import org.meteoinfo.geometry.geoprocess.GeoComputation; import org.meteoinfo.geometry.geoprocess.GeometryUtil; @@ -643,4 +646,52 @@ public class GeoProjectionUtil { } } + /** + * Project graphic + * + * @param graphic The graphic + * @param fromProj From projection + * @param toProj To projection + * @return Projected graphic + */ + public static Graphic projectClipGraphic(Graphic graphic, ProjectionInfo fromProj, ProjectionInfo toProj) { + if (graphic instanceof GeoGraphicCollection) { + GeoGraphicCollection geoGraphic = (GeoGraphicCollection) graphic; + try { + GeoGraphicCollection newGCollection = new GeoGraphicCollection(); + DataTable dataTable = new DataTable(); + for (DataColumn aDC : geoGraphic.getAttributeTable().getTable().getColumns()) { + Field bDC = new Field(aDC.getColumnName(), aDC.getDataType()); + dataTable.getColumns().add(bDC); + } + int idx = 0; + for (Graphic aGraphic : geoGraphic.getGraphics()) { + List shapes = ProjectionUtil.projectClipShape(aGraphic.getShape(), fromProj, toProj); + if (shapes != null && shapes.size() > 0) { + aGraphic.setShape(shapes.get(0)); + newGCollection.add(aGraphic); + DataRow aDR = geoGraphic.getAttributeTable().getTable().getRows().get(idx); + try { + dataTable.addRow(aDR); + } catch (Exception ex) { + Logger.getLogger(GeoProjectionUtil.class.getName()).log(Level.SEVERE, null, ex); + } + } + idx += 1; + } + newGCollection.setLegendScheme(geoGraphic.getLegendScheme()); + newGCollection.setSingleLegend(geoGraphic.isSingleLegend()); + newGCollection.getAttributeTable().setTable(dataTable); + newGCollection.setProjInfo(toProj); + + return newGCollection; + } catch (Exception ex) { + ex.printStackTrace(); + return null; + } + } else { + return ProjectionUtil.projectClipGraphic(graphic, fromProj, toProj); + } + } + } diff --git a/meteoinfo-geometry/src/main/java/org/meteoinfo/geometry/graphic/Artist.java b/meteoinfo-geometry/src/main/java/org/meteoinfo/geometry/graphic/Artist.java new file mode 100644 index 00000000..039e1ec1 --- /dev/null +++ b/meteoinfo-geometry/src/main/java/org/meteoinfo/geometry/graphic/Artist.java @@ -0,0 +1,22 @@ +package org.meteoinfo.geometry.graphic; + +public class Artist { + + protected boolean antiAlias = false; + + /** + * Return antiAlias + * @return AntiAlias + */ + public boolean isAntiAlias() { + return this.antiAlias; + } + + /** + * Set antiAlias + * @param value Set antiAlias + */ + public void setAntiAlias(boolean value) { + this.antiAlias = value; + } +} diff --git a/meteoinfo-geometry/src/main/java/org/meteoinfo/geometry/graphic/Graphic.java b/meteoinfo-geometry/src/main/java/org/meteoinfo/geometry/graphic/Graphic.java index 19f56da2..458ff7d2 100644 --- a/meteoinfo-geometry/src/main/java/org/meteoinfo/geometry/graphic/Graphic.java +++ b/meteoinfo-geometry/src/main/java/org/meteoinfo/geometry/graphic/Graphic.java @@ -32,7 +32,7 @@ package org.meteoinfo.geometry.graphic; * * @author Yaqiang Wang */ - public class Graphic { + public class Graphic extends Artist { // protected Shape shape; diff --git a/meteoinfo-geometry/src/main/java/org/meteoinfo/geometry/graphic/GraphicCollection.java b/meteoinfo-geometry/src/main/java/org/meteoinfo/geometry/graphic/GraphicCollection.java index fa45e7fc..909f0e32 100644 --- a/meteoinfo-geometry/src/main/java/org/meteoinfo/geometry/graphic/GraphicCollection.java +++ b/meteoinfo-geometry/src/main/java/org/meteoinfo/geometry/graphic/GraphicCollection.java @@ -582,7 +582,7 @@ public class GraphicCollection extends Graphic implements Iterator { /** * Add labels */ - private void addLabelsByColor() { + protected void addLabelsByColor() { if (labelSet.isAutoDecimal()) { double min = getMinValue(); labelSet.setDecimalDigits(MIMath.getDecimalNum(min)); @@ -684,6 +684,56 @@ public class GraphicCollection extends Graphic implements Iterator { labelSet.setDrawLabels(true); } + /** + * Get a label by text + * + * @param text Text + * @return Label + */ + public Graphic getLabel(String text) { + for (Graphic lb : labelPoints) { + if (((LabelBreak) lb.getLegend()).getText().equals(text)) { + return lb; + } + } + return null; + } + + /** + * Move label + * + * @param text Label text + * @param x X + * @param y Y + */ + public void moveLabel(String text, float x, float y) { + Graphic lb = this.getLabel(text); + if (lb != null) { + this.moveLabel(lb, x, y); + } + } + + /** + * Move label + * + * @param lb Label + * @param x X + * @param y Y + */ + public void moveLabel(Graphic lb, float x, float y) { + LabelBreak lbb = (LabelBreak) lb.getLegend(); + lbb.setXShift(lbb.getXShift() + x); + lbb.setYShift(lbb.getYShift() + y); + } + + /** + * Remove all labels + */ + public void removeLabels() { + labelPoints.clear(); + labelSet.setDrawLabels(false); + } + /** * Get arrow zoom * @@ -736,5 +786,24 @@ public class GraphicCollection extends Graphic implements Iterator { return this; } + + /** + * X coordinate shift as a new GraphicCollection object + * @param xs X shift value + */ + public GraphicCollection xShiftCopy(double xs) { + GraphicCollection graphicCollection = new GraphicCollection(); + for (Graphic g : this.graphics) { + Shape shape = (Shape) g.getShape().clone(); + for (PointD p : shape.getPoints()) { + p.X += xs; + } + Graphic graphic = new Graphic(shape, g.legend); + graphic.setExtent(graphic.getExtent().shift(xs, 0)); + graphicCollection.add(graphic); + } + + return graphicCollection; + } // } diff --git a/meteoinfo-geometry/src/main/java/org/meteoinfo/geometry/shape/Shape.java b/meteoinfo-geometry/src/main/java/org/meteoinfo/geometry/shape/Shape.java index 5299bade..4b95a568 100644 --- a/meteoinfo-geometry/src/main/java/org/meteoinfo/geometry/shape/Shape.java +++ b/meteoinfo-geometry/src/main/java/org/meteoinfo/geometry/shape/Shape.java @@ -61,6 +61,30 @@ public abstract class Shape implements Cloneable{ */ public Shape(Geometry geometry) {}; + /** + * Create a new Shape object + * @param shapeType Shape type + * @return Shape object + */ + public static Shape factory(ShapeTypes shapeType) { + switch (shapeType) { + case POINT: + return new PointShape(); + case POINT_Z: + return new PointZShape(); + case POLYLINE: + return new PolylineShape(); + case POLYLINE_Z: + return new PolylineZShape(); + case POLYGON: + return new PolygonShape(); + case POLYGON_Z: + return new PolygonZShape(); + default: + throw new IllegalArgumentException("Shape type not supported"); + } + } + // // /** diff --git a/meteoinfo-lab/milconfig.xml b/meteoinfo-lab/milconfig.xml index 02c123cd..fefb366f 100644 --- a/meteoinfo-lab/milconfig.xml +++ b/meteoinfo-lab/milconfig.xml @@ -1,30 +1,34 @@ - - + + - + + + - + + + @@ -32,5 +36,5 @@
- + diff --git a/meteoinfo-lab/pylib/mipylib/geolib/_graphic.py b/meteoinfo-lab/pylib/mipylib/geolib/_graphic.py new file mode 100644 index 00000000..d6c79538 --- /dev/null +++ b/meteoinfo-lab/pylib/mipylib/geolib/_graphic.py @@ -0,0 +1,72 @@ +from org.meteoinfo.geo.graphic import GeoGraphicCollection as JGeoGraphicCollection +from java.awt import Font + +import mipylib.miutil as miutil + +class GeoGraphicCollection(object): + + def __init__(self, geographic=None): + """ + Class init. + + :param geographic: (*JGeoGraphicCollection*) Java GeoGraphicCollection object. + """ + self._geographic = geographic + + def addlabels(self, fieldname, **kwargs): + """ + Add labels + + :param fieldname: (*string*) Field name. + :param fontname: (*string*) Font name. Default is ``Arial``. + :param fontsize: (*string*) Font size. Default is ``14``. + :param bold: (*boolean*) Font bold or not. Default is ``False``. + :param color: (*color*) Label color. Default is ``None`` with black color. + :param xoffset: (*int*) X coordinate offset. Default is ``0``. + :param yoffset: (*int*) Y coordinate offset. Default is ``0``. + :param avoidcoll: (*boolean*) Avoid labels collision or not. Default is ``True``. + :param decimals: (*int*) Number of decimals of labels. + """ + labelset = self._geographic.getLabelSet() + labelset.setFieldName(fieldname) + fontname = kwargs.pop('fontname', 'Arial') + fontsize = kwargs.pop('fontsize', 14) + bold = kwargs.pop('bold', False) + if bold: + font = Font(fontname, Font.BOLD, fontsize) + else: + font = Font(fontname, Font.PLAIN, fontsize) + labelset.setLabelFont(font) + color = kwargs.pop('color', None) + if not color is None: + color = miutil.getcolor(color) + labelset.setLabelColor(color) + xoffset = kwargs.pop('xoffset', 0) + labelset.setXOffset(xoffset) + yoffset = kwargs.pop('yoffset', 0) + labelset.setYOffset(yoffset) + avoidcoll = kwargs.pop('avoidcoll', True) + labelset.setAvoidCollision(avoidcoll) + decimals = kwargs.pop('decimals', None) + if not decimals is None: + labelset.setAutoDecimal(False) + labelset.setDecimalDigits(decimals) + self._geographic.addLabels() + + def getlabel(self, text): + """ + Get a label. + + :param text: (*string*) The label text. + """ + return self._geographic.getLabel(text) + + def movelabel(self, label, x=0, y=0): + """ + Move a label. + + :param label: (*string*) The label text. + :param x: (*float*) X shift for moving in pixel unit. + :param y: (*float*) Y shift for moving in pixel unit. + """ + self._geographic.moveLabel(label, x, y) \ No newline at end of file diff --git a/meteoinfo-lab/pylib/mipylib/geolib/migeo$py.class b/meteoinfo-lab/pylib/mipylib/geolib/migeo$py.class index 74783059..fc2ce2a3 100644 Binary files a/meteoinfo-lab/pylib/mipylib/geolib/migeo$py.class and b/meteoinfo-lab/pylib/mipylib/geolib/migeo$py.class differ diff --git a/meteoinfo-lab/pylib/mipylib/geolib/milayer$py.class b/meteoinfo-lab/pylib/mipylib/geolib/milayer$py.class index 764c5711..2dccecd5 100644 Binary files a/meteoinfo-lab/pylib/mipylib/geolib/milayer$py.class and b/meteoinfo-lab/pylib/mipylib/geolib/milayer$py.class differ diff --git a/meteoinfo-lab/pylib/mipylib/plotlib/_axes$py.class b/meteoinfo-lab/pylib/mipylib/plotlib/_axes$py.class index 7bae7b2e..3e0281f3 100644 Binary files a/meteoinfo-lab/pylib/mipylib/plotlib/_axes$py.class and b/meteoinfo-lab/pylib/mipylib/plotlib/_axes$py.class differ diff --git a/meteoinfo-lab/pylib/mipylib/plotlib/_axes3d$py.class b/meteoinfo-lab/pylib/mipylib/plotlib/_axes3d$py.class index fad96529..ebef40d9 100644 Binary files a/meteoinfo-lab/pylib/mipylib/plotlib/_axes3d$py.class and b/meteoinfo-lab/pylib/mipylib/plotlib/_axes3d$py.class differ diff --git a/meteoinfo-lab/pylib/mipylib/plotlib/_axes3dgl$py.class b/meteoinfo-lab/pylib/mipylib/plotlib/_axes3dgl$py.class index f6fefdda..745f2df1 100644 Binary files a/meteoinfo-lab/pylib/mipylib/plotlib/_axes3dgl$py.class and b/meteoinfo-lab/pylib/mipylib/plotlib/_axes3dgl$py.class differ diff --git a/meteoinfo-lab/pylib/mipylib/plotlib/_glfigure$py.class b/meteoinfo-lab/pylib/mipylib/plotlib/_glfigure$py.class index b7fd1e86..0d032bea 100644 Binary files a/meteoinfo-lab/pylib/mipylib/plotlib/_glfigure$py.class and b/meteoinfo-lab/pylib/mipylib/plotlib/_glfigure$py.class differ diff --git a/meteoinfo-lab/pylib/mipylib/plotlib/_mapaxes$py.class b/meteoinfo-lab/pylib/mipylib/plotlib/_mapaxes$py.class index 5267ee4f..707aadb9 100644 Binary files a/meteoinfo-lab/pylib/mipylib/plotlib/_mapaxes$py.class and b/meteoinfo-lab/pylib/mipylib/plotlib/_mapaxes$py.class differ diff --git a/meteoinfo-lab/pylib/mipylib/plotlib/_mapaxes.py b/meteoinfo-lab/pylib/mipylib/plotlib/_mapaxes.py index 8cbb7a00..b53b018d 100644 --- a/meteoinfo-lab/pylib/mipylib/plotlib/_mapaxes.py +++ b/meteoinfo-lab/pylib/mipylib/plotlib/_mapaxes.py @@ -10,13 +10,13 @@ import os import numbers from org.meteoinfo.chart import ChartScaleBar, ChartNorthArrow -from org.meteoinfo.chart.plot import MapPlot, GridLabelPosition +from org.meteoinfo.chart.plot import GridLabelPosition +from org.meteoinfo.chart.geo import MapPlot from org.meteoinfo.chart.graphic import GraphicFactory from org.meteoinfo.geo.meteodata import DrawMeteoData from org.meteoinfo.geo.mapview import MapView from org.meteoinfo.geo.io import GraphicUtil from org.meteoinfo.geometry.legend import BreakTypes, LegendScheme, LegendType, LegendManage -#from org.meteoinfo.geo.legend import LegendManage from org.meteoinfo.geometry.shape import Shape, PolylineShape, PolygonShape, ShapeTypes from org.meteoinfo.geometry.graphic import Graphic from org.meteoinfo.projection import ProjectionInfo @@ -30,6 +30,7 @@ from ._axes import Axes import mipylib.numeric as np from mipylib.numeric.core import NDArray, DimArray from mipylib.geolib.milayer import MILayer +from mipylib.geolib._graphic import GeoGraphicCollection import mipylib.geolib.migeo as migeo import plotutil import colors @@ -553,7 +554,7 @@ class MapAxes(Axes): self._axes.setDrawExtent(graphics.getExtent().clone()) self._axes.setExtent(graphics.getExtent().clone()) - return graphics + return GeoGraphicCollection(graphics) else: if isinstance(args[0], Graphic): graphic = args[0] @@ -1311,6 +1312,7 @@ class MapAxes(Axes): ls = LegendManage.createLegendScheme(cdata.min(), cdata.max(), cn, cmap) else: levs = kwargs.pop('levs', None) + levs = kwargs.pop('levels', levs) if levs is None: ls = LegendManage.createLegendScheme(cdata.min(), cdata.max(), cmap) else: @@ -1333,6 +1335,10 @@ class MapAxes(Axes): graphics = GraphicFactory.createArrows(x._array, y._array, u._array, v._array, cdata, ls, isuv) # Add graphics + antialias = kwargs.pop('antialias', None) + if antialias is not None: + graphics.setAntiAlias(antialias) + visible = kwargs.pop('visible', True) if visible: zorder = kwargs.pop('zorder', None) @@ -1401,6 +1407,7 @@ class MapAxes(Axes): ls = LegendManage.createLegendScheme(cdata.min(), cdata.max(), cn, cmap) else: levs = kwargs.pop('levs', None) + levs = kwargs.pop('levels', levs) if levs is None: ls = LegendManage.createLegendScheme(cdata.min(), cdata.max(), cmap) else: @@ -1420,6 +1427,10 @@ class MapAxes(Axes): graphics = GraphicFactory.createBarbs(x._array, y._array, u._array, v._array, cdata, ls, isuv) # Add graphics + antialias = kwargs.pop('antialias', None) + if antialias is not None: + graphics.setAntiAlias(antialias) + proj = kwargs.pop('proj', migeo.projinfo()) visible = kwargs.pop('visible', True) if visible: diff --git a/meteoinfo-lab/pylib/mipylib/plotlib/miplot$py.class b/meteoinfo-lab/pylib/mipylib/plotlib/miplot$py.class index 684c1f24..5cfac5eb 100644 Binary files a/meteoinfo-lab/pylib/mipylib/plotlib/miplot$py.class and b/meteoinfo-lab/pylib/mipylib/plotlib/miplot$py.class differ diff --git a/meteoinfo-lab/pylib/mipylib/plotlib/miplot.py b/meteoinfo-lab/pylib/mipylib/plotlib/miplot.py index dd9cd126..b20cfd11 100644 --- a/meteoinfo-lab/pylib/mipylib/plotlib/miplot.py +++ b/meteoinfo-lab/pylib/mipylib/plotlib/miplot.py @@ -10,7 +10,8 @@ from javax.swing import WindowConstants from org.meteoinfo.chart import Location from org.meteoinfo.chart.form import ChartForm from org.meteoinfo.chart.jogl import JOGLUtil -from org.meteoinfo.chart.plot import Plot2D, MapPlot, Plot3D +from org.meteoinfo.chart.plot import Plot2D, Plot3D +from org.meteoinfo.chart.geo import MapPlot from org.meteoinfo.geo.legend import LegendManage from org.meteoinfo.geo.meteodata import DrawMeteoData from org.meteoinfo.geometry.legend import LegendScheme, LegendType diff --git a/meteoinfo-lab/pylib/mipylib/plotlib/plotutil$py.class b/meteoinfo-lab/pylib/mipylib/plotlib/plotutil$py.class index ffd5c807..81ae2251 100644 Binary files a/meteoinfo-lab/pylib/mipylib/plotlib/plotutil$py.class and b/meteoinfo-lab/pylib/mipylib/plotlib/plotutil$py.class differ diff --git a/meteoinfo-projection/src/main/java/org/meteoinfo/projection/ProjectionUtil.java b/meteoinfo-projection/src/main/java/org/meteoinfo/projection/ProjectionUtil.java index e96dc0ae..70e682ed 100644 --- a/meteoinfo-projection/src/main/java/org/meteoinfo/projection/ProjectionUtil.java +++ b/meteoinfo-projection/src/main/java/org/meteoinfo/projection/ProjectionUtil.java @@ -993,7 +993,7 @@ public class ProjectionUtil { return newGraphics; } - private static Shape projectShape(Shape aShape, ProjectionInfo fromProj, ProjectionInfo toProj) { + public static Shape projectShape(Shape aShape, ProjectionInfo fromProj, ProjectionInfo toProj) { Shape newShape; switch (aShape.getShapeType()) { case POINT: @@ -1030,7 +1030,7 @@ public class ProjectionUtil { return newShape; } - private static List projectClipShape(Shape shape, ProjectionInfo fromProj, ProjectionInfo toProj) { + public static List projectClipShape(Shape shape, ProjectionInfo fromProj, ProjectionInfo toProj) { List shapes = null; switch (shape.getShapeType()) { case POINT: