diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 00000000..569c3f52
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+MeteoInfoMap
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 247fc3f6..91669d7a 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -8,8 +8,8 @@
+
-
@@ -18,9 +18,9 @@
+
-
@@ -34,15 +34,15 @@
+
+
-
-
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index f0b5b0f4..a5d679c2 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -2,15 +2,9 @@
-
-
-
-
-
-
@@ -27,6 +21,12 @@
+
+
+
+
+
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index ab319e6a..728bc997 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -4,15 +4,11 @@
-
-
-
-
-
-
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
index 3b4d4bfb..31d41915 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -3,9 +3,7 @@
-
-
@@ -14,6 +12,8 @@
+
+
diff --git a/MeteoInfoLib/MeteoInfoLib.iml b/MeteoInfoLib/MeteoInfoLib.iml
index 7d788611..363f687d 100644
--- a/MeteoInfoLib/MeteoInfoLib.iml
+++ b/MeteoInfoLib/MeteoInfoLib.iml
@@ -39,6 +39,8 @@
+
+
diff --git a/MeteoInfoLib/pom.xml b/MeteoInfoLib/pom.xml
index f7dd09ef..17c3804e 100644
--- a/MeteoInfoLib/pom.xml
+++ b/MeteoInfoLib/pom.xml
@@ -92,6 +92,16 @@
meteoinfo-data
${project.version}
+
+ ${project.groupId}
+ meteoinfo-geo
+ ${project.version}
+
+
+ ${project.groupId}
+ meteoinfo-chart
+ ${project.version}
+
edu.ucar
netcdfAll
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/Chart.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/Chart.java
deleted file mode 100644
index 1b99e49c..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/Chart.java
+++ /dev/null
@@ -1,902 +0,0 @@
-/* This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-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.RenderingHints;
-import java.awt.Stroke;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
-import java.util.ArrayList;
-import java.util.List;
-import org.meteoinfo.chart.plot.MapPlot;
-import org.meteoinfo.chart.plot.Plot;
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.drawing.Draw;
-
-/**
- *
- * @author Yaqiang Wang
- * yaqiang.wang@gmail.com
- */
-public class Chart {
-
- //
- private List plots;
- private int currentPlot;
- private int rowNum;
- private int columnNum;
- private ChartText title;
- private ChartText subTitle;
- private List texts;
- private ChartLegend legend;
- private Color background;
- //private boolean drawBackground;
- private boolean drawLegend;
- private Rectangle2D plotArea;
- private boolean antiAlias;
- private boolean symbolAntialias;
- private ChartPanel parent;
-
- //
- //
- /**
- * Constructor
- */
- public Chart() {
- this.drawLegend = false;
- this.background = Color.white;
- //this.drawBackground = true;
- this.antiAlias = false;
- this.symbolAntialias = true;
- this.rowNum = 1;
- this.columnNum = 1;
- this.plots = new ArrayList<>();
- this.currentPlot = -1;
- this.texts = new ArrayList<>();
- }
-
- /**
- * Constructor
- *
- * @param parent ChartPanel parent
- */
- public Chart(ChartPanel parent) {
- this();
- this.parent = parent;
- }
-
- /**
- * Constructor
- *
- * @param plot Plot
- * @param parent ChartPanel
- */
- public Chart(Plot plot, ChartPanel parent) {
- this(parent);
- this.plots.add(plot);
- }
-
- /**
- * Constructor
- *
- * @param plot Plot
- */
- public Chart(Plot plot) {
- this(plot, null);
- }
-
- /**
- * Constructor
- *
- * @param title Title
- * @param plot Plot
- * @param parent ChartPanel
- */
- public Chart(String title, Plot plot, ChartPanel parent) {
- this(plot, parent);
- if (title == null) {
- this.title = null;
- } else {
- this.title = new ChartText(title);
- }
- }
-
- /**
- * Constructor
- *
- * @param title Title
- * @param plot Plot
- */
- public Chart(String title, Plot plot) {
- this(title, plot, null);
- }
-
- //
- //
- /**
- * Set ChartPanel parent
- *
- * @param value ChartPanel
- */
- public void setParent(ChartPanel value) {
- this.parent = value;
- for (Plot plot : this.plots) {
- if (plot instanceof MapPlot) {
- ((MapPlot) plot).setParent(value);
- }
- }
- }
-
- /**
- * Get plot
- *
- * @return Plot
- */
- public List getPlots() {
- return plots;
- }
-
- /**
- * Get current plot
- *
- * @return Current plot
- */
- public Plot getCurrentPlot() {
- if (this.plots.isEmpty()) {
- return null;
- }
-
- if (this.currentPlot < 0 || this.currentPlot >= this.plots.size()) {
- this.currentPlot = this.plots.size() - 1;
- }
- return this.plots.get(this.currentPlot);
- }
-
- /**
- * Set current plot
- *
- * @param value Current plot
- */
- public void setCurrentPlot(Plot value) {
- if (this.plots.isEmpty()) {
- this.addPlot(value);
- //this.currentPlot = 0;
- } else if (this.currentPlot == -1) {
- this.plots.add(value);
- } else {
- if (this.currentPlot >= this.plots.size()) {
- this.currentPlot = this.plots.size() - 1;
- }
- Plot plot = this.plots.get(this.currentPlot);
- value.isSubPlot = plot.isSubPlot;
- value.columnIndex = plot.columnIndex;
- value.rowIndex = plot.rowIndex;
- this.plots.set(this.currentPlot, value);
- }
- }
-
- /**
- * Set current plot index
- *
- * @param value Current plot index
- */
- public void setCurrentPlot(int value) {
- this.currentPlot = value;
- }
-
- /**
- * Get the first plot
- *
- * @return Plot
- */
- public Plot getPlot() {
- if (this.plots.isEmpty()) {
- return null;
- }
-
- return this.plots.get(0);
- }
-
- /**
- * Get row number of sub plots
- *
- * @return Row number of sub plots
- */
- public int getRowNum() {
- return this.rowNum;
- }
-
- /**
- * Set row number of sub plots
- *
- * @param value Row number of sub plots
- */
- public void setRowNum(int value) {
- this.rowNum = value;
- }
-
- /**
- * Get column number of sub plots
- *
- * @return Column number of sub plots
- */
- public int getColumnNum() {
- return this.columnNum;
- }
-
- /**
- * Set column number of sub plots
- *
- * @param value Column number of sub plots
- */
- public void setColumnNum(int value) {
- this.columnNum = value;
- }
-
- /**
- * Get title
- *
- * @return Title
- */
- public ChartText getTitle() {
- return title;
- }
-
- /**
- * Set title
- *
- * @param value Title
- */
- public void setTitle(ChartText value) {
- title = value;
- }
-
- /**
- * Get sub title
- *
- * @return Sub title
- */
- public ChartText getSubTitle() {
- return subTitle;
- }
-
- /**
- * Set sub title
- *
- * @param value Sub title
- */
- public void setSubTitle(ChartText value) {
- subTitle = value;
- }
-
- /**
- * Get background
- *
- * @return Background
- */
- public Color getBackground() {
- return this.background;
- }
-
- /**
- * Set background
- *
- * @param value Background
- */
- public void setBackground(Color value) {
- this.background = value;
- }
-
-// /**
-// * Get if draw background
-// *
-// * @return Boolean
-// */
-// public boolean isDrawBackground() {
-// return this.drawBackground;
-// }
-
-// /**
-// * Set if draw background
-// *
-// * @param value Boolean
-// */
-// public void setDrawBackground(boolean value) {
-// this.drawBackground = value;
-// }
-
- /**
- * Get chart legend
- *
- * @return Chart legend
- */
- public ChartLegend getLegend() {
- return this.legend;
- }
-
- /**
- * Get if draw legend
- *
- * @return If draw legend
- */
- public boolean isDrawLegend() {
- return this.drawLegend;
- }
-
- /**
- * Set if draw legend
- *
- * @param value Boolean
- */
- public void setDrawLegend(boolean value) {
- this.drawLegend = value;
- }
-
- /**
- * Get plot area
- *
- * @return Plot area
- */
- public Rectangle2D getPlotArea() {
- return this.plotArea;
- }
-
- /**
- * Get if is anti-alias
- *
- * @return Boolean
- */
- public boolean isAntiAlias() {
- return this.antiAlias;
- }
-
- /**
- * Set if is anti-alias
- *
- * @param value Boolean
- */
- public void setAntiAlias(boolean value) {
- this.antiAlias = value;
- }
-
- /**
- * Get symbol antialias
- * @return Boolean
- */
- public boolean isSymbolAntialias() {
- return this.symbolAntialias;
- }
-
- /**
- * Set symbol antialias
- * @param value Boolean
- */
- public void setSymbolAntialias(boolean value) {
- this.symbolAntialias = value;
- }
-
- //
- //
- /**
- * Draw plot
- *
- * @param g Graphics2D
- * @param area Drawing area
- */
- public void draw(Graphics2D g, Rectangle2D area) {
- g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
- if (antiAlias) {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- //g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_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_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
- 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_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_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_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
- g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT);
- }
-
- AffineTransform oldMatrix = g.getTransform();
- Rectangle oldRegion = g.getClipBounds();
- g.setClip(area);
- g.translate(area.getX(), area.getY());
-
- //Draw background
- if (this.background != null) {
- g.setColor(background);
- g.fill(new Rectangle2D.Double(0, 0, area.getWidth(), area.getHeight()));
- }
-
- //Draw title
- float y = 5;
- if (title != null) {
- g.setColor(title.getColor());
- g.setFont(title.getFont());
- float x = (float) area.getWidth() / 2;
- //y -= this.title.getHeight(g) - 5;
- //FontMetrics metrics = g.getFontMetrics(title.getFont());
- //x -= metrics.stringWidth(title.getText()) / 2;
- //y += metrics.getHeight();
- int i = 0;
- for (String text : title.getTexts()) {
- Dimension dim = Draw.getStringDimension(text, g);
- if (i == 0) {
- y += dim.getHeight();
- }
- Draw.drawString(g, text, x - dim.width / 2, y);
- g.setFont(title.getFont());
- y += dim.height + title.getLineSpace();
- i += 1;
- }
- y += 5;
- }
-
- //Draw plot
- plotArea = this.getPlotArea(g, area);
- //plotArea = area;
- if (plotArea.getWidth() < 20 || plotArea.getHeight() < 20) {
- g.setTransform(oldMatrix);
- g.setClip(oldRegion);
- return;
- }
-
- if (this.plots.size() > 0) {
- //double zoom = this.getPositionAreaZoom(g, plotArea);
- //Margin tightInset = this.getPlotsTightInset(g, plotArea);
- Margin shrink = this.getPlotsShrink(g, plotArea);
- for (int i = 0; i < this.plots.size(); i++) {
- Plot plot = this.plots.get(i);
- plot.setSymbolAntialias(this.symbolAntialias);
- if (plot.isOuterPosActive()){
- if (plot.isSubPlot || plot.isSameShrink()) {
- plot.setPlotShrink(shrink);
- } else {
- //plot.setPlotShrink(this.getPlotShrink(g, area, plot));
- plot.setPlotShrink(this.getPlotShrink(g, plotArea, plot));
- }
- }
- if (plot instanceof MapPlot) {
- ((MapPlot) plot).setAntialias(this.antiAlias);
- }
- plot.draw(g, plotArea);
- }
- }
-
- //Draw text
- drawText(g, area);
-
- //Draw legend
- if (this.drawLegend) {
- Dimension dim = this.legend.getLegendDimension(g, new Dimension((int) area.getWidth(), (int) area.getHeight()));
- float x = 0;
- switch (this.legend.getPosition()) {
- case UPPER_CENTER_OUTSIDE:
- x = (float) area.getWidth() / 2 - dim.width / 2;
- y += 5;
- break;
- case LOWER_CENTER_OUTSIDE:
- x = (float) area.getWidth() / 2 - dim.width / 2;
- y += plotArea.getHeight() + 5;
- break;
- case LEFT_OUTSIDE:
- x = 10;
- y = (float) area.getHeight() / 2 - dim.height / 2;
- break;
- case RIGHT_OUTSIDE:
- x = (float) plotArea.getWidth() + 10;
- y = (float) area.getHeight() / 2 - dim.height / 2;
- break;
- }
- this.legend.draw(g, new PointF(x, y));
- }
-
- g.setTransform(oldMatrix);
- g.setClip(oldRegion);
- }
-
- void drawText(Graphics2D g, Rectangle2D area) {
- float x, y;
- for (ChartText text : this.texts) {
- x = (float) (area.getWidth() * text.getX());
- y = (float) (area.getHeight() * (1 - text.getY()));
- Dimension dim = Draw.getStringDimension(text.getText(), g);
- Rectangle.Double rect = new Rectangle.Double(x, y, dim.getWidth(), dim.getHeight());
- if (text.isFill()) {
- g.setColor(text.getBackground());
- g.fill(rect);
- }
- if (text.isDrawNeatline()) {
- g.setColor(text.getNeatlineColor());
- Stroke oldStroke = g.getStroke();
- g.setStroke(new BasicStroke(text.getNeatlineSize()));
- g.draw(rect);
- g.setStroke(oldStroke);
- }
- g.setFont(text.getFont());
- g.setColor(text.getColor());
- Draw.drawString(g, text.getText(), x, y);
- }
- }
-
- private Rectangle2D getPlotArea(Graphics2D g, Rectangle2D area) {
- Rectangle2D pArea = new Rectangle2D.Double();
- int edge = 0;
- int top = edge;
- int left = edge;
- int right = edge;
- int bottom = edge;
- if (this.title != null) {
- top += this.title.getTrueDimension(g).height + 12;
- }
- pArea.setRect(left, top, area.getWidth() - left - right, area.getHeight() - top - bottom);
-
- return pArea;
- }
-
- private Rectangle2D getPlotArea_bak(Graphics2D g, Rectangle2D area) {
- Rectangle2D pArea = new Rectangle2D.Double();
- int edge = 2;
- int top = edge;
- int left = edge;
- int right = edge;
- int bottom = edge;
- if (this.title != null) {
- top += this.title.getTrueDimension(g).height + 10;
- }
- if (this.drawLegend) {
- Dimension dim = this.legend.getLegendDimension(g, new Dimension((int) area.getWidth(), (int) area.getHeight()));
- switch (this.legend.getPosition()) {
- case UPPER_CENTER_OUTSIDE:
- top += dim.height + 10;
- break;
- case LOWER_CENTER_OUTSIDE:
- bottom += dim.height + 10;
- break;
- case LEFT_OUTSIDE:
- left += dim.width + 10;
- break;
- case RIGHT_OUTSIDE:
- right += dim.width + 10;
- break;
- }
- }
- pArea.setRect(left, top, area.getWidth() - left - right, area.getHeight() - top - bottom);
-
- return pArea;
- }
-
- private Margin getPlotShrink(Graphics2D g, Rectangle2D area, Plot plot) {
- Margin shrink;
- if (plot.isSubPlot) {
- double rowHeight = area.getHeight() / this.rowNum;
- double colWidth = area.getWidth() / this.columnNum;
- double x = area.getX() + plot.columnIndex * colWidth;
- double y = area.getY() + plot.rowIndex * rowHeight;
- Rectangle2D subPlotArea = new Rectangle2D.Double(x, y, colWidth, rowHeight);
- plot.setOuterPositionArea(subPlotArea);
- plot.updatePosition(area, subPlotArea);
- Rectangle2D positionArea = plot.getPositionArea(area);
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- shrink = plot.getPlotShrink();
- } else {
- plot.setOuterPositionArea(area);
- Rectangle2D positionArea = plot.getPositionArea(area);
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- shrink = plot.getPlotShrink();
- //shrink = tightInset;
- }
-
- return shrink;
- }
-
- private Margin getPlotsShrink(Graphics2D g, Rectangle2D area) {
- Margin pshrink = null, shrink;
- for (int i = 0; i < this.plots.size(); i++) {
- Plot plot = this.plots.get(i);
- plot.setOuterPositionArea(plot.getOuterPositionArea(area));
- Rectangle2D positionArea = plot.getPositionArea(area);
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- shrink = plot.getPlotShrink();
- if (i == 0) {
- pshrink = shrink;
- } else if (pshrink != null) {
- pshrink = pshrink.extend(shrink);
- }
- }
-
- return pshrink;
- }
-
- private Margin getPlotsShrink_bak(Graphics2D g, Rectangle2D area) {
- Margin pshrink = null, shrink;
- for (int i = 0; i < this.plots.size(); i++) {
- Plot plot = this.plots.get(i);
- if (plot.isSubPlot) {
- double rowHeight = area.getHeight() / this.rowNum;
- double colWidth = area.getWidth() / this.columnNum;
- double x = area.getX() + plot.columnIndex * colWidth;
- double y = area.getY() + plot.rowIndex * rowHeight;
- Rectangle2D subPlotArea = new Rectangle2D.Double(x, y, colWidth, rowHeight);
- plot.setOuterPositionArea(subPlotArea);
- plot.updatePosition(area, subPlotArea);
- Rectangle2D positionArea = plot.getPositionArea(area);
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- shrink = plot.getPlotShrink();
- } else {
- plot.setOuterPositionArea(area);
- Rectangle2D positionArea = plot.getPositionArea(area);
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- shrink = plot.getPlotShrink();
- }
- if (i == 0) {
- pshrink = shrink;
- } else if (pshrink != null) {
- pshrink = pshrink.extend(shrink);
- }
- }
-
- return pshrink;
- }
-
- private Margin getPlotsTightInset(Graphics2D g, Rectangle2D area) {
- int i = 0;
- Margin pti = null, tightInset;
- for (Plot plot : this.plots) {
- if (plot.isSubPlot) {
- double rowHeight = area.getHeight() / this.rowNum;
- double colWidth = area.getWidth() / this.columnNum;
- double x = area.getX() + plot.columnIndex * colWidth;
- double y = area.getY() + plot.rowIndex * rowHeight;
- Rectangle2D subPlotArea = new Rectangle2D.Double(x, y, colWidth, rowHeight);
- plot.setOuterPositionArea(subPlotArea);
- plot.updatePosition(area, subPlotArea);
- Rectangle2D positionArea = plot.getPositionArea();
- plot.setPositionArea(positionArea);
- tightInset = plot.getTightInset(g, positionArea);
- } else {
- plot.setOuterPositionArea(area);
- Rectangle2D positionArea = plot.getPositionArea();
- plot.setPositionArea(positionArea);
- tightInset = plot.getTightInset(g, positionArea);
- }
- if (i == 0) {
- pti = tightInset;
- } else if (pti != null) {
- pti = pti.extend(tightInset);
- }
- i += 1;
- }
-
- return pti;
- }
-
- private double getPositionAreaZoom(Graphics2D g, Rectangle2D area) {
- double zoom = 1.0;
- for (Plot plot : this.plots) {
- if (plot.isSubPlot) {
- double rowHeight = area.getHeight() / this.rowNum;
- double colWidth = area.getWidth() / this.columnNum;
- double x = area.getX() + plot.columnIndex * colWidth;
- double y = area.getY() + plot.rowIndex * rowHeight;
- Rectangle2D subPlotArea = new Rectangle2D.Double(x, y, colWidth, rowHeight);
- plot.setOuterPositionArea(subPlotArea);
- plot.updatePosition(area, subPlotArea);
- Rectangle2D positionArea = plot.getPositionArea();
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- double zoom1 = plot.updatePostionAreaZoom();
- if (zoom1 < zoom) {
- zoom = zoom1;
- }
- } else {
- plot.setOuterPositionArea(area);
- Rectangle2D positionArea = plot.getPositionArea();
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- double zoom1 = plot.updatePostionAreaZoom();
- if (zoom1 < zoom) {
- zoom = zoom1;
- }
- }
- }
-
- return zoom;
- }
-
- private Rectangle2D getSubPlotArea(Graphics2D g, Plot plot, Rectangle2D area) {
- if (plot.isSubPlot) {
- double rowHeight = area.getHeight() / this.rowNum;
- double colWidth = area.getWidth() / this.columnNum;
- double x = area.getX() + plot.columnIndex * colWidth;
- double y = area.getY() + plot.rowIndex * rowHeight;
- Rectangle2D subPlotArea = new Rectangle2D.Double(x, y, colWidth, rowHeight);
- plot.setOuterPositionArea(subPlotArea);
- plot.updatePosition(area, subPlotArea);
- Rectangle2D positionArea = plot.getPositionArea();
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- double zoom = plot.updatePostionAreaZoom();
- plot.setPositionAreaZoom(zoom);
- return subPlotArea;
- } else {
- plot.setOuterPositionArea(area);
- Rectangle2D positionArea = plot.getPositionArea();
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- double zoom = plot.updatePostionAreaZoom();
- plot.setPositionAreaZoom(zoom);
- //return tightInset.getArea(positionArea);
- return area;
- }
- }
-
- /**
- * Get graph area
- *
- * @return Get graph area
- */
- public Rectangle2D getGraphArea() {
- Rectangle2D rect = this.plots.get(0).getPositionArea();
- double left = rect.getX() + this.plotArea.getX();
- double top = rect.getY() + this.plotArea.getY();
- return new Rectangle2D.Double(left, top, rect.getWidth(), rect.getHeight());
- }
-
- /**
- * Find a plot by point
- *
- * @param x X
- * @param y Y
- * @return Plot
- */
- public Plot findPlot(int x, int y) {
- for (Plot plot : this.plots) {
- Rectangle2D area = plot.getPositionArea();
- if (area.contains(x, y)) {
- return plot;
- }
- }
-
- return null;
- }
-
- /**
- * Clear plots
- */
- public void clearPlots() {
- this.plots.clear();
- }
-
- /**
- * Clear texts
- */
- public void clearTexts() {
- this.texts.clear();
- }
-
- /**
- * Remove a plot
- *
- * @param plot The plot
- */
- public void removePlot(Plot plot) {
- this.plots.remove(plot);
- }
-
- /**
- * Add a plot
- *
- * @param plot Plot
- */
- public void addPlot(Plot plot) {
- if (plot instanceof MapPlot) {
- ((MapPlot) plot).setParent(parent);
- }
- this.plots.add(plot);
- }
-
- /**
- * Set plot
- *
- * @param plot Plot
- */
- public void setPlot(Plot plot) {
- if (plot instanceof MapPlot) {
- ((MapPlot) plot).setParent(parent);
- }
- this.plots.clear();
- this.plots.add(plot);
- }
-
- /**
- * Get plot by plot index
- *
- * @param plotIdx Plot index - begin with 1
- * @return Plot index
- */
- public Plot getPlot(int plotIdx) {
- for (Plot plot : this.plots) {
- int pIdx = plot.rowIndex * this.columnNum + plot.columnIndex + 1;
- if (pIdx == plotIdx) {
- return plot;
- }
- }
-
- if (plotIdx > 0 && plotIdx <= this.plots.size())
- return this.plots.get(plotIdx - 1);
- else
- return null;
- }
-
- /**
- * Get plot index
- * @param plot The plot
- * @return Plot index
- */
- public int getPlotIndex(Plot plot){
- return this.plots.indexOf(plot);
- }
-
- /**
- * Check if has web map layer
- *
- * @return Boolean
- */
- public boolean hasWebMap() {
- for (Plot plot : this.plots) {
- if (plot instanceof MapPlot) {
- MapPlot mp = (MapPlot) plot;
- if (mp.hasWebMapLayer()) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- /**
- * Add text
- *
- * @param text Text
- */
- public void addText(ChartText text) {
- this.texts.add(text);
- }
- //
-
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartColorBar.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartColorBar.java
deleted file mode 100644
index b949340c..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartColorBar.java
+++ /dev/null
@@ -1,1038 +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;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Line2D;
-import java.awt.geom.Path2D;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.meteoinfo.common.*;
-import org.meteoinfo.drawing.Draw;
-import org.meteoinfo.geometry.legend.*;
-import org.meteoinfo.geometry.shape.ShapeTypes;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class ChartColorBar extends ChartLegend {
-
- //
- private List tickLocations;
- private List tickLabels;
- private boolean autoTick;
- private boolean insideTick;
- private float tickLength;
- private boolean tickVisible;
- private float tickWidth;
- private Color tickColor;
- private boolean drawMinLabel;
- private boolean drawMaxLabel;
-
- //
- //
- /**
- * Constructor
- *
- * @param ls LegendScheme
- */
- public ChartColorBar(LegendScheme ls) {
- super(ls);
-
- this.tickLocations = new ArrayList<>();
- this.tickLabels = new ArrayList<>();
- this.autoTick = true;
- this.insideTick = true;
- this.tickLength = 5;
- this.tickVisible = true;
- this.tickWidth = 1;
- this.tickColor = Color.black;
- this.drawMinLabel = false;
- this.drawMaxLabel = false;
- }
-
- //
- //
- /**
- * Tick locations
- *
- * @return Tick locations
- */
- public List getTickLocations() {
- return this.tickLocations;
- }
-
- /**
- * Set tick locations
- *
- * @param value Tick locations
- */
- public void setTickLocations(List value) {
- this.tickLocations.clear();
- this.tickLabels.clear();
- for (Number v : value) {
- this.tickLocations.add(v.doubleValue());
- this.tickLabels.add(new ChartText(DataConvert.removeTailingZeros(String.valueOf(v))));
- }
- this.autoTick = false;
- }
-
- /**
- * Set tick locations
- *
- * @param value Tick locations
- */
- public void setTickLocations(double[] value) {
- this.tickLocations.clear();
- this.tickLabels.clear();
- for (double v : value) {
- this.tickLocations.add(v);
- this.tickLabels.add(new ChartText(DataConvert.removeTailingZeros(String.valueOf(v))));
- }
- this.autoTick = false;
- }
-
- /**
- * Get tick labels
- *
- * @return Tick labels
- */
- public List getTickLabels() {
- return this.tickLabels;
- }
-
- /**
- * Get tick label text
- *
- * @return Tick label text
- */
- public List getTickLabelText() {
- List strs = new ArrayList<>();
- for (ChartText ct : this.tickLabels) {
- strs.add(ct.toString());
- }
-
- return strs;
- }
-
- /**
- * Set tick label text
- *
- * @param value Tick label text
- */
- public void setTickLabelText(List value) {
- this.tickLabels = new ArrayList<>();
- for (String v : value) {
- this.tickLabels.add(new ChartText(v));
- }
- this.autoTick = false;
- }
-
- /**
- * Set tick labels.
- *
- * @param value Tick labels
- */
- public void setTickLabels(List value) {
- this.tickLabels = value;
- }
-
- /**
- * Set tick labels
- *
- * @param value Tick labels
- */
- public void setTickLabels_Number(List value) {
- this.tickLabels = new ArrayList<>();
- for (Number v : value) {
- this.tickLabels.add(new ChartText(v.toString()));
- }
- this.autoTick = false;
- }
-
- /**
- * Get if is auto tick labels
- *
- * @return Boolean
- */
- public boolean isAutoTick() {
- return this.autoTick;
- }
-
- /**
- * Set if auto tick labels
- *
- * @param value Boolean
- */
- public void setAutoTick(boolean value) {
- this.autoTick = value;
- }
-
- /**
- * Get tick length
- *
- * @return Tick length
- */
- public float getTickLength() {
- return this.tickLength;
- }
-
- /**
- * Set tick length
- *
- * @param value Tick length
- */
- public void setTickLength(int value) {
- this.tickLength = value;
- }
-
- /**
- * Get if is inside tick
- *
- * @return Boolean
- */
- public boolean isInsideTick() {
- return this.insideTick;
- }
-
- /**
- * Set if is inside tick
- *
- * @param value Boolean
- */
- public void setInsideTick(boolean value) {
- this.insideTick = value;
- }
-
- /**
- * Get if is tick visible
- * @return Boolean
- */
- public boolean isTickVisible() {
- return this.tickVisible;
- }
-
- /**
- * Set if is tick visible
- * @param value Boolean
- */
- public void setTickVisible(boolean value) {
- this.tickVisible = value;
- }
-
- /**
- * Get tick line width
- * @return Tick line width
- */
- public float getTickWidth() {
- return this.tickWidth;
- }
-
- /**
- * Set tick line width
- * @param value Tick line width
- */
- public void setTickWidth(float value) {
- this.tickWidth = value;
- }
-
- /**
- * Get tick color
- * @return Tick color
- */
- public Color getTickColor() {
- return this.tickColor;
- }
-
- /**
- * Set tick color
- * @param value Tick color
- */
- public void setTickColor(Color value) {
- this.tickColor = value;
- }
-
- /**
- * Get if draw minimum value label
- *
- * @return Boolean
- */
- public boolean isDrawMinLabel() {
- return this.drawMinLabel;
- }
-
- /**
- * Set if draw minimum value label
- *
- * @param value Boolean
- */
- public void setDrawMinLabel(boolean value) {
- this.drawMinLabel = value;
- }
-
- /**
- * Get if draw maximum value label
- *
- * @return Boolean
- */
- public boolean isDrawMaxLabel() {
- return this.drawMaxLabel;
- }
-
- /**
- * Set if draw maximum value label
- *
- * @param value Boolean
- */
- public void setDrawMaxLabel(boolean value) {
- this.drawMaxLabel = value;
- }
-
- //
- //
- /**
- * Draw legend
- *
- * @param g Graphics2D
- * @param point Start point
- */
- @Override
- public void draw(Graphics2D g, PointF point) {
-
- AffineTransform oldMatrix = g.getTransform();
- g.translate(point.X + this.xshift, point.Y + this.yshift);
-
- //Draw background color
- if (this.drawBackground) {
- g.setColor(this.background);
- g.fill(new Rectangle.Float(0, 0, this.width, this.height));
- }
-
- //Draw legend
- g.setStroke(new BasicStroke(1));
- switch (this.orientation) {
- case HORIZONTAL:
- this.drawHorizontalBarLegend(g, legendScheme);
- break;
- case VERTICAL:
- this.drawVerticalBarLegend(g, legendScheme);
- break;
- }
-
- //Draw neatline
- if (drawNeatLine) {
- Rectangle.Float mapRect = new Rectangle.Float(0, 0, this.width, this.height);
- g.setColor(neatLineColor);
- g.setStroke(new BasicStroke(neatLineSize));
- g.draw(mapRect);
- }
-
- g.setTransform(oldMatrix);
- }
-
- private void drawTickLine(Graphics2D g, PointF sP, float tickLen, boolean vertical, float shift) {
- if (vertical) {
- if (this.insideTick) {
- g.draw(new Line2D.Float(sP.X + shift, sP.Y, sP.X + shift, sP.Y - tickLen));
- } else {
- g.draw(new Line2D.Float(sP.X + shift, sP.Y, sP.X + shift, sP.Y + tickLen));
- sP.Y += tickLen;
- }
- sP.Y += 5;
- } else {
- if (this.insideTick) {
- g.draw(new Line2D.Float(sP.X - tickLen, sP.Y + shift, sP.X, sP.Y + shift));
- } else {
- g.draw(new Line2D.Float(sP.X, sP.Y + shift, sP.X + tickLen, sP.Y + shift));
- sP.X += tickLen;
- }
- sP.X += 5;
- }
- }
-
- private void drawTickLine(Graphics2D g, PointD sP, float tickLen, boolean vertical, double shift) {
- if (vertical) {
- if (this.insideTick) {
- g.draw(new Line2D.Double(sP.X + shift, sP.Y, sP.X + shift, sP.Y - tickLen));
- } else {
- g.draw(new Line2D.Double(sP.X + shift, sP.Y, sP.X + shift, sP.Y + tickLen));
- sP.Y += tickLen;
- }
- sP.Y += 5;
- } else {
- if (this.insideTick) {
- g.draw(new Line2D.Double(sP.X - tickLen, sP.Y + shift, sP.X, sP.Y + shift));
- } else {
- g.draw(new Line2D.Double(sP.X, sP.Y + shift, sP.X + tickLen, sP.Y + shift));
- sP.X += tickLen;
- }
- sP.X += 5;
- }
- }
-
- private void drawHorizontalBarLegend(Graphics2D g, LegendScheme aLS) {
- PointD aP = new PointD(0, 0);
- PointD sP = new PointD(0, 0);
- boolean DrawShape = true, DrawFill = true, DrawOutline = false;
- Color FillColor = Color.red, OutlineColor = Color.black;
- String caption;
-
- int bNum = aLS.getBreakNum();
- if (aLS.getLegendBreaks().get(bNum - 1).isNoData()) {
- bNum -= 1;
- }
-
- List labelIdxs = new ArrayList<>();
- List tLabels = new ArrayList<>();
- if (this.autoTick) {
- int tickGap = this.getTickGap(g);
- int sIdx = (bNum % tickGap) / 2;
- int labNum = bNum - 1;
- if (aLS.getLegendType() == LegendType.UniqueValue) {
- labNum += 1;
- } else if (this.drawMinLabel) {
- sIdx = 0;
- labNum = bNum;
- }
- while (sIdx < labNum) {
- labelIdxs.add(sIdx);
- sIdx += tickGap;
- }
- } else {
- int tickIdx;
- for (int i = 0; i < bNum; i++) {
- ColorBreak cb = aLS.getLegendBreaks().get(i);
- if (i == bNum - 1) {
- if (cb.getStartValue().equals(cb.getEndValue()))
- continue;
- }
- double v = Double.parseDouble(cb.getEndValue().toString());
- if (this.tickLocations.contains(v)) {
- labelIdxs.add(i);
- tickIdx = this.tickLocations.indexOf(v);
- tLabels.add(this.tickLabels.get(tickIdx).getText());
- }
- }
- }
-
- this._hBarHeight = (double) this.legendWidth / this.aspect;
- _vBarWidth = (double) this.legendWidth / bNum;
- float y_shift = 0;
- if (this.label != null){
- switch (this.labelLocation){
- case "top":
- case "in":
- y_shift = this.label.getDimension(g).height + 5;
- break;
- }
- }
- int idx;
- aP.Y = y_shift;
- for (int i = 0; i < bNum; i++) {
- idx = i;
- switch (aLS.getShapeType()) {
- case Point:
- PointBreak aPB = (PointBreak) aLS.getLegendBreaks().get(idx);
- DrawShape = aPB.isDrawShape();
- DrawFill = aPB.isDrawFill();
- FillColor = aPB.getColor();
- break;
- case Polyline:
- PolylineBreak aPLB = (PolylineBreak) aLS.getLegendBreaks().get(idx);
- DrawShape = aPLB.getDrawPolyline();
- FillColor = aPLB.getColor();
- break;
- case Polygon:
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx);
- DrawShape = aPGB.isDrawShape();
- DrawFill = aPGB.isDrawFill();
- FillColor = aPGB.getColor();
- break;
- case Image:
- ColorBreak aCB = aLS.getLegendBreaks().get(idx);
- DrawShape = true;
- DrawFill = true;
- FillColor = aCB.getColor();
- break;
- }
-
- if (DrawShape) {
- if (this.extendRect) {
- if (aLS.getShapeType() == ShapeTypes.Polygon) {
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx).clone();
- aPGB.setDrawOutline(false);
- Draw.drawPolygonSymbol(aP.X, aP.Y, _vBarWidth, _hBarHeight, aPGB, g);
- } else {
- Draw.drawPolygonSymbol(aP.X, aP.Y, FillColor, OutlineColor, _vBarWidth,
- _hBarHeight, DrawFill, DrawOutline, g);
- }
- } else {
- double extendw = _vBarWidth;
- if (this.autoExtendFrac) {
- extendw = _hBarHeight;
- }
- if (i == 0) {
- PointD[] Points = new PointD[4];
- Points[0] = new PointD();
- Points[0].X = _vBarWidth - extendw;
- Points[0].Y = aP.Y + _hBarHeight * 0.5;
- Points[1] = new PointD();
- Points[1].X = _vBarWidth;
- Points[1].Y = aP.Y;
- Points[2] = new PointD();
- Points[2].X = _vBarWidth;
- Points[2].Y = aP.Y + _hBarHeight;
- Points[3] = new PointD();
- Points[3].X = _vBarWidth - extendw;
- Points[3].Y = aP.Y + _hBarHeight * 0.5;
- if (aLS.getShapeType() == ShapeTypes.Polygon) {
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx).clone();
- aPGB.setDrawOutline(false);
- Draw.drawPolygon(Points, aPGB, g);
- } else {
- Draw.drawPolygon(Points, FillColor, OutlineColor, DrawFill, DrawOutline, g);
- }
- } else if (i == bNum - 1) {
- PointD[] Points = new PointD[4];
- Points[0] = new PointD();
- Points[0].X = i * _vBarWidth - 1.0f;
- Points[0].Y = aP.Y + _hBarHeight;
- Points[1] = new PointD();
- Points[1].X = i * _vBarWidth - 1.0f;
- Points[1].Y = aP.Y;
- Points[2] = new PointD();
- Points[2].X = i * _vBarWidth + extendw;
- Points[2].Y = aP.Y + _hBarHeight * 0.5;
- Points[3] = new PointD();
- Points[3].X = i * _vBarWidth - 1.0f;
- Points[3].Y = aP.Y + _hBarHeight;
- if (aLS.getShapeType() == ShapeTypes.Polygon) {
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx).clone();
- aPGB.setDrawOutline(false);
- Draw.drawPolygon(Points, aPGB, g);
- } else {
- Draw.drawPolygon(Points, FillColor, OutlineColor, DrawFill, DrawOutline, g);
- }
- } else if (aLS.getShapeType() == ShapeTypes.Polygon) {
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx).clone();
- aPGB.setDrawOutline(false);
- Draw.drawPolygonSymbol(aP.X, aP.Y, _vBarWidth, _hBarHeight, aPGB, g);
- } else {
- Draw.drawPolygonSymbol(aP.X, aP.Y, FillColor, OutlineColor, _vBarWidth,
- _hBarHeight, DrawFill, DrawOutline, g);
- }
- }
- }
- aP.X += _vBarWidth;
- }
- //Draw neatline
- g.setStroke(new BasicStroke(this.neatLineSize));
- g.setColor(this.neatLineColor);
- if (this.extendRect) {
- g.draw(new Rectangle.Double(0, y_shift, this._vBarWidth * bNum, this._hBarHeight));
- } else {
- double extendw = _vBarWidth;
- if (this.autoExtendFrac) {
- extendw = _hBarHeight;
- }
- Path2D p = new Path2D.Double();
- p.moveTo(_vBarWidth - extendw, this._hBarHeight / 2 + y_shift);
- p.lineTo(this._vBarWidth, y_shift);
- p.lineTo(this._vBarWidth * (bNum - 1), y_shift);
- p.lineTo(this._vBarWidth * (bNum - 1) + extendw, this._hBarHeight / 2 + y_shift);
- p.lineTo(this._vBarWidth * (bNum - 1), this._hBarHeight + y_shift);
- p.lineTo(this._vBarWidth, this._hBarHeight + y_shift);
- p.closePath();
- g.draw(p);
- }
- //Draw tick and label
- aP.X = -_vBarWidth / 2;
- float tickLen = this.tickLength;
- if (this.insideTick) {
- if (this._hBarHeight < tickLen) {
- tickLen = (int) this._hBarHeight;
- }
- }
- g.setStroke(new BasicStroke(this.tickWidth));
- g.setFont(tickLabelFont);
- g.setColor(this.tickColor);
- idx = 0;
- for (int i = 0; i < bNum; i++) {
- aP.X += _vBarWidth;
- aP.Y = _hBarHeight / 2 + y_shift;
- if (labelIdxs.contains(i)) {
- ColorBreak cb = aLS.getLegendBreaks().get(i);
- if (this.autoTick) {
- if (aLS.getLegendType() == LegendType.UniqueValue) {
- caption = cb.getCaption();
- } else {
- caption = DataConvert.removeTailingZeros(cb.getEndValue().toString());
- }
- } else {
- caption = tLabels.get(idx);
- }
-
- if (aLS.getLegendType() == LegendType.UniqueValue) {
- sP.X = aP.X;
- sP.Y = aP.Y + _hBarHeight / 2 + 5;
- g.setColor(this.tickLabelColor);
- if (this.tickLabelAngle == 0) {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.CENTER, YAlign.TOP, this.tickLabelAngle, true);
- } else if (this.tickLabelAngle < 45) {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.RIGHT, YAlign.TOP, this.tickLabelAngle, true);
- } else {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.RIGHT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- } else {
- sP.X = aP.X + _vBarWidth / 2;
- sP.Y = aP.Y + _hBarHeight / 2;
- PointD ssP = (PointD)sP.clone();
- if (this.autoTick) {
- if (i < bNum - 1) {
- g.setColor(this.tickColor);
- this.drawTickLine(g, sP, tickLen, true, 0);
- g.setColor(this.tickLabelColor);
- if (this.tickLabelAngle == 0) {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.CENTER, YAlign.TOP, this.tickLabelAngle, true);
- } else if (this.tickLabelAngle < 45) {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.RIGHT, YAlign.TOP, this.tickLabelAngle, true);
- } else {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.RIGHT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- if (this.drawMinLabel && i == 0) {
- g.setColor(this.tickColor);
- this.drawTickLine(g, ssP, tickLen, true, -this._vBarWidth);
- caption = DataConvert.removeTailingZeros(cb.getStartValue().toString());
- g.setColor(this.tickLabelColor);
- //Draw.drawString(g, ssP.X - this._vBarWidth, ssP.Y, caption, XAlign.CENTER, YAlign.TOP, this.tickLabelAngle, true);
- if (this.tickLabelAngle == 0) {
- Draw.drawString(g, ssP.X - this._vBarWidth, ssP.Y, caption, XAlign.CENTER, YAlign.TOP, this.tickLabelAngle, true);
- } else if (this.tickLabelAngle < 45) {
- Draw.drawString(g, ssP.X - this._vBarWidth, ssP.Y, caption, XAlign.RIGHT, YAlign.TOP, this.tickLabelAngle, true);
- } else {
- Draw.drawString(g, ssP.X - this._vBarWidth, ssP.Y, caption, XAlign.RIGHT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- }
- } else if (this.drawMaxLabel) {
- g.setColor(this.tickColor);
- this.drawTickLine(g, sP, tickLen, true, 0);
- g.setColor(this.tickLabelColor);
- if (this.tickLabelAngle == 0) {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.CENTER, YAlign.TOP, this.tickLabelAngle, true);
- } else if (this.tickLabelAngle < 45) {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.RIGHT, YAlign.TOP, this.tickLabelAngle, true);
- } else {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.RIGHT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- }
- } else {
- if (i == 0 && this.tickLocations.get(idx) == Double.parseDouble(cb.getStartValue().toString())) {
- g.setColor(this.tickColor);
- this.drawTickLine(g, sP, tickLen, true, -this._vBarWidth);
- g.setColor(this.tickLabelColor);
- //Draw.drawString(g, sP.X - this._vBarWidth, sP.Y, caption, XAlign.CENTER, YAlign.TOP, this.tickLabelAngle, true);
- if (this.tickLabelAngle == 0) {
- Draw.drawString(g, sP.X - this._vBarWidth, sP.Y, caption, XAlign.CENTER, YAlign.TOP, this.tickLabelAngle, true);
- } else if (this.tickLabelAngle < 45) {
- Draw.drawString(g, sP.X - this._vBarWidth, sP.Y, caption, XAlign.RIGHT, YAlign.TOP, this.tickLabelAngle, true);
- } else {
- Draw.drawString(g, sP.X - this._vBarWidth, sP.Y, caption, XAlign.RIGHT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- } else {
- g.setColor(this.tickColor);
- this.drawTickLine(g, sP, tickLen, true, 0);
- g.setColor(this.tickLabelColor);
- if (this.tickLabelAngle == 0) {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.CENTER, YAlign.TOP, this.tickLabelAngle, true);
- } else if (this.tickLabelAngle < 45) {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.RIGHT, YAlign.TOP, this.tickLabelAngle, true);
- } else {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.RIGHT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- }
- }
- }
- idx += 1;
- }
- }
-
- //Draw label
- double sx, sy;
- if (this.label != null) {
- g.setFont(this.label.getFont());
- g.setColor(this.label.getColor());
- switch (this.labelLocation) {
- case "top":
- case "in":
- sx = this.legendWidth * 0.5;
- sy = 2;
- Draw.drawString(g, sx, sy, label.getText(), XAlign.CENTER, YAlign.TOP, label.isUseExternalFont());
- break;
- case "right":
- sx = this.legendWidth + 5;
- sy = this._hBarHeight * 0.5;
- Draw.drawString(g, sx, sy, label.getText(), XAlign.LEFT, YAlign.CENTER, label.isUseExternalFont());
- break;
- case "left":
- sx = -5;
- sy = this._hBarHeight * 0.5;
- Draw.drawString(g, sx, sy, label.getText(), XAlign.RIGHT, YAlign.CENTER, label.isUseExternalFont());
- break;
- default:
- sx = this.legendWidth * 0.5;
- sy = this.height - 2;
- Draw.drawString(g, sx, sy, label.getText(), XAlign.CENTER, YAlign.BOTTOM, label.isUseExternalFont());
- break;
- }
- }
- }
-
- private void drawVerticalBarLegend(Graphics2D g, LegendScheme aLS) {
- PointD aP = new PointD(0, 0);
- PointD sP = new PointD(0, 0);
- boolean DrawShape = true, DrawFill = true, DrawOutline = false;
- Color FillColor = Color.red, OutlineColor = Color.black;
- String caption;
-
- int bNum = aLS.getBreakNum();
- if (aLS.getLegendBreaks().get(bNum - 1).isNoData()) {
- bNum -= 1;
- }
-
- List labelIdxs = new ArrayList<>();
- List tLabels = new ArrayList<>();
- if (this.autoTick) {
- int tickGap = this.getTickGap(g);
- int sIdx = (bNum % tickGap) / 2;
- int labNum = bNum - 1;
- if (aLS.getLegendType() == LegendType.UniqueValue) {
- labNum += 1;
- } else if (this.drawMinLabel) {
- sIdx = 0;
- labNum = bNum;
- }
- while (sIdx < labNum) {
- labelIdxs.add(sIdx);
- sIdx += tickGap;
- }
- } else {
- int tickIdx;
- for (int i = 0; i < bNum; i++) {
- ColorBreak cb = aLS.getLegendBreaks().get(i);
- if (i == bNum - 1) {
- if (cb.getStartValue().equals(cb.getEndValue()))
- continue;
- }
- double v = Double.parseDouble(cb.getEndValue().toString());
- if (this.tickLocations.contains(v)) {
- labelIdxs.add(i);
- tickIdx = this.tickLocations.indexOf(v);
- tLabels.add(this.tickLabels.get(tickIdx).getText());
- }
- if (i == 0) {
- v = Double.parseDouble(cb.getStartValue().toString());
- if (this.tickLocations.contains(v)) {
- labelIdxs.add(i);
- tickIdx = this.tickLocations.indexOf(v);
- tLabels.add(this.tickLabels.get(tickIdx).getText());
- }
- }
- }
- }
-
- this._vBarWidth = (double) this.legendHeight / this.aspect;
- _hBarHeight = (double) this.legendHeight / bNum;
- aP.Y = this.legendHeight;
- float x_shift = 0;
- if (this.label != null){
- switch (this.labelLocation){
- case "left":
- case "in":
- x_shift = this.label.getDimension(g).height + 5;
- break;
- }
- }
- int idx;
- aP.X = x_shift;
- for (int i = 0; i < bNum; i++) {
- idx = i;
- switch (aLS.getShapeType()) {
- case Point:
- PointBreak aPB = (PointBreak) aLS.getLegendBreaks().get(idx);
- DrawShape = aPB.isDrawShape();
- DrawFill = aPB.isDrawFill();
- FillColor = aPB.getColor();
- break;
- case Polyline:
- PolylineBreak aPLB = (PolylineBreak) aLS.getLegendBreaks().get(idx);
- DrawShape = aPLB.getDrawPolyline();
- FillColor = aPLB.getColor();
- break;
- case Polygon:
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx);
- DrawShape = aPGB.isDrawShape();
- DrawFill = aPGB.isDrawFill();
- FillColor = aPGB.getColor();
- break;
- case Image:
- ColorBreak aCB = aLS.getLegendBreaks().get(idx);
- DrawShape = true;
- DrawFill = true;
- FillColor = aCB.getColor();
- break;
- }
-
- aP.Y = aP.Y - _hBarHeight;
-
- if (DrawShape) {
- if (this.extendRect) {
- if (aLS.getShapeType() == ShapeTypes.Polygon) {
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx).clone();
- aPGB.setDrawOutline(false);
- Draw.drawPolygonSymbol(aP.X, aP.Y, _vBarWidth, _hBarHeight, aPGB, g);
- } else {
- Draw.drawPolygonSymbol(aP.X, aP.Y, FillColor, OutlineColor, _vBarWidth,
- _hBarHeight, DrawFill, DrawOutline, g);
- }
- } else if (i == 0) {
- PointD[] Points = new PointD[4];
- Points[0] = new PointD();
- Points[0].X = aP.X + _vBarWidth * 0.5;
- Points[0].Y = this.legendHeight;
- Points[1] = new PointD();
- Points[1].X = aP.X;
- Points[1].Y = aP.Y;
- Points[2] = new PointD();
- Points[2].X = aP.X + _vBarWidth;
- Points[2].Y = aP.Y;
- Points[3] = new PointD();
- Points[3].X = aP.X + _vBarWidth * 0.5;
- Points[3].Y = this.legendHeight;
- if (aLS.getShapeType() == ShapeTypes.Polygon) {
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx).clone();
- aPGB.setDrawOutline(false);
- Draw.drawPolygon(Points, aPGB, g);
- } else {
- Draw.drawPolygon(Points, FillColor, OutlineColor, DrawFill, DrawOutline, g);
- }
- } else if (i == bNum - 1) {
- PointD[] Points = new PointD[4];
- Points[0] = new PointD();
- Points[0].X = aP.X;
- Points[0].Y = _hBarHeight;
- Points[1] = new PointD();
- Points[1].X = aP.X + _vBarWidth;
- Points[1].Y = _hBarHeight;
- Points[2] = new PointD();
- Points[2].X = aP.X + _vBarWidth * 0.5;
- Points[2].Y = 0;
- Points[3] = new PointD();
- Points[3].X = aP.X;
- Points[3].Y = _hBarHeight;
- if (aLS.getShapeType() == ShapeTypes.Polygon) {
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx).clone();
- aPGB.setDrawOutline(false);
- Draw.drawPolygon(Points, aPGB, g);
- } else {
- Draw.drawPolygon(Points, FillColor, OutlineColor, DrawFill, DrawOutline, g);
- }
- } else if (aLS.getShapeType() == ShapeTypes.Polygon) {
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx).clone();
- aPGB.setDrawOutline(false);
- Draw.drawPolygonSymbol(aP.X, aP.Y, _vBarWidth, _hBarHeight, aPGB, g);
- } else {
- Draw.drawPolygonSymbol(aP.X, aP.Y, FillColor, OutlineColor, _vBarWidth,
- _hBarHeight, DrawFill, DrawOutline, g);
- }
- }
- }
- //Draw neatline
- g.setStroke(new BasicStroke(this.neatLineSize));
- g.setColor(this.neatLineColor);
- if (this.extendRect) {
- g.draw(new Rectangle.Double(x_shift, 0, this._vBarWidth, this._hBarHeight * bNum));
- } else {
- Path2D p = new Path2D.Double();
- p.moveTo(this._vBarWidth / 2 + x_shift, 0);
- p.lineTo(x_shift, this._hBarHeight);
- p.lineTo(x_shift, (this._hBarHeight * (bNum - 1)));
- p.lineTo(this._vBarWidth / 2 + x_shift, this._hBarHeight * bNum);
- p.lineTo(this._vBarWidth + x_shift, this._hBarHeight * (bNum - 1));
- p.lineTo(this._vBarWidth + x_shift, this._hBarHeight);
- p.closePath();
- g.draw(p);
- }
- //Draw ticks
- g.setStroke(new BasicStroke(this.tickWidth));
- aP.Y = this.legendHeight + _hBarHeight / 2;
- float tickLen = this.tickLength;
- if (this.insideTick) {
- if (this._vBarWidth < tickLen) {
- tickLen = (int) this._vBarWidth;
- }
- }
- g.setFont(tickLabelFont);
- idx = 0;
- for (int i = 0; i < bNum; i++) {
- aP.X = _vBarWidth / 2 + x_shift;
- aP.Y = aP.Y - _hBarHeight;
- if (labelIdxs.contains(i)) {
- ColorBreak cb = aLS.getLegendBreaks().get(i);
- if (this.autoTick) {
- if (aLS.getLegendType() == LegendType.UniqueValue) {
- caption = cb.getCaption();
- } else {
- caption = DataConvert.removeTailingZeros(cb.getEndValue().toString());
- }
- } else {
- caption = tLabels.get(idx);
- }
-
- if (aLS.getLegendType() == LegendType.UniqueValue) {
- sP.X = aP.X + _vBarWidth / 2 + 5;
- sP.Y = aP.Y;
- g.setColor(this.tickLabelColor);
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.LEFT, YAlign.CENTER, this.tickLabelAngle, true);
- } else {
- sP.X = aP.X + _vBarWidth / 2;
- sP.Y = aP.Y - _hBarHeight / 2;
- PointD ssP = (PointD)sP.clone();
- if (this.autoTick) {
- if (i < bNum - 1) {
- g.setColor(this.tickColor);
- this.drawTickLine(g, sP, tickLen, false, 0);
- g.setColor(this.tickLabelColor);
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.LEFT, YAlign.CENTER, this.tickLabelAngle, true);
- if (this.drawMinLabel && i == 0) {
- g.setColor(this.tickColor);
- this.drawTickLine(g, ssP, tickLen, false, this._hBarHeight);
- caption = DataConvert.removeTailingZeros(cb.getStartValue().toString());
- g.setColor(this.tickLabelColor);
- Draw.drawString(g, ssP.X, ssP.Y + this._hBarHeight, caption, XAlign.LEFT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- } else if (this.drawMaxLabel) {
- g.setColor(this.tickColor);
- this.drawTickLine(g, sP, tickLen, false, 0);
- g.setColor(this.tickLabelColor);
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.LEFT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- } else {
- if (i == 0 && this.tickLocations.get(idx) == Double.parseDouble(cb.getStartValue().toString())) {
- g.setColor(this.tickColor);
- this.drawTickLine(g, sP, tickLen, false, this._hBarHeight);
- g.setColor(this.tickLabelColor);
- Draw.drawString(g, sP.X, sP.Y + this._hBarHeight, caption, XAlign.LEFT, YAlign.CENTER, this.tickLabelAngle, true);
- } else {
- g.setColor(this.tickColor);
- this.drawTickLine(g, sP, tickLen, false, 0);
- g.setColor(this.tickLabelColor);
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.LEFT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- }
- }
- idx += 1;
- }
- }
- //Draw label
- double sx, sy;
- if (this.label != null) {
- g.setFont(this.label.getFont());
- g.setColor(this.label.getColor());
- Dimension dim = Draw.getStringDimension(this.label.getText(), g);
- switch (this.labelLocation) {
- case "top":
- sx = 0;
- sy = -5;
- Draw.drawString(g, sx, sy, label.getText(), XAlign.LEFT, YAlign.BOTTOM, label.isUseExternalFont());
- break;
- case "bottom":
- sx = 0;
- sy = this.legendHeight + 5;
- Draw.drawString(g, sx, sy, label.getText(), XAlign.LEFT, YAlign.TOP, label.isUseExternalFont());
- break;
- case "left":
- case "in":
- sx = 0;
- sy = this.legendHeight * 0.5;
- Draw.drawString(g, sx, sy, label.getText(), XAlign.CENTER, YAlign.TOP, 90, label.isUseExternalFont());
- break;
- default:
- sx = this.width - dim.height;
- sy = this.legendHeight * 0.5;
- Draw.drawString(g, sx, sy, label.getText(), XAlign.CENTER, YAlign.TOP, 90, label.isUseExternalFont());
- break;
- }
- }
- }
-
- /**
- * Get legend dimension
- *
- * @param g Graphics2D
- * @param limitDim Limit dimension
- * @return Legend dimension
- */
- @Override
- public Dimension getLegendDimension(Graphics2D g, Dimension limitDim) {
- if (legendScheme != null) {
- switch (this.orientation) {
- case VERTICAL:
- this.width = (int) (this.getTickWidth(g) + limitDim.height * this.shrink / this.aspect + 5);
- if (!this.insideTick){
- this.width += this.tickLength;
- }
- this.legendWidth = this.width;
- this.legendHeight = this.height;
- if (this.label != null) {
- g.setFont(this.label.getFont());
- Dimension dim = Draw.getStringDimension(label.getText(), g);
- switch (this.labelLocation) {
- case "top":
- case "bottom":
- //this.height += dim.height + 10;
- this.width = Math.max(this.width, dim.width);
- break;
- default:
- this.width += dim.height + 5;
- break;
- }
- }
- break;
- default:
- g.setFont(this.tickLabelFont);
- this.height = (int) (this.getTickHeight(g) + limitDim.width * this.shrink / this.aspect + 5);
- if (!this.insideTick){
- this.height += this.tickLength;
- }
- this.legendWidth = this.width;
- this.legendHeight = this.height;
- if (this.label != null) {
- g.setFont(this.label.getFont());
- Dimension dim = Draw.getStringDimension(label.getText(), g);
- switch (this.labelLocation) {
- case "right":
- case "left":
- //this.width += dim.width + 10;
- break;
- default:
- this.height += dim.height + 5;
- break;
- }
- }
- }
- }
-
- return new Dimension(this.width, this.height);
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartElement.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartElement.java
deleted file mode 100644
index 145db3e7..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartElement.java
+++ /dev/null
@@ -1,336 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.chart;
-
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.ui.event.ILocationChangedListener;
-import org.meteoinfo.ui.event.ISizeChangedListener;
-import org.meteoinfo.ui.event.LocationChangedEvent;
-import org.meteoinfo.ui.event.SizeChangedEvent;
-
-import java.awt.Color;
-import java.awt.Rectangle;
-import javax.swing.event.EventListenerList;
-import org.meteoinfo.layout.ResizeAbility;
-
-/**
- *
- * @author yaqiang
- */
-public abstract class ChartElement {
- //
-
- public void addLocationChangedListener(ILocationChangedListener listener) {
- this._listeners.add(ILocationChangedListener.class, listener);
- }
-
- public void removeLocationChangedListener(ILocationChangedListener listener) {
- this._listeners.remove(ILocationChangedListener.class, listener);
- }
-
- public void fireLocationChangedEvent() {
- fireLocationChangedEvent(new LocationChangedEvent(this));
- }
-
- private void fireLocationChangedEvent(LocationChangedEvent event) {
- Object[] listeners = _listeners.getListenerList();
- for (int i = 0; i < listeners.length; i = i + 2) {
- if (listeners[i] == ILocationChangedListener.class) {
- ((ILocationChangedListener) listeners[i + 1]).locationChangedEvent(event);
- }
- }
- }
-
- public void addSizeChangedListener(ISizeChangedListener listener) {
- this._listeners.add(ISizeChangedListener.class, listener);
- }
-
- public void removeSizeChangedListener(ISizeChangedListener listener) {
- this._listeners.remove(ISizeChangedListener.class, listener);
- }
-
- public void fireSizeChangedEvent() {
- fireSizeChangedEvent(new SizeChangedEvent(this));
- }
-
- private void fireSizeChangedEvent(SizeChangedEvent event) {
- Object[] listeners = _listeners.getListenerList();
- for (int i = 0; i < listeners.length; i = i + 2) {
- if (listeners[i] == ISizeChangedListener.class) {
- ((ISizeChangedListener) listeners[i + 1]).sizeChangedEvent(event);
- }
- }
- }
- //
- //
- private final EventListenerList _listeners = new EventListenerList();
- protected float x;
- protected float y;
- protected float width;
- protected float height;
- protected Color _foreColor;
- protected Color _backColor;
- private boolean _selected;
- private ResizeAbility _resizeAbility;
- private boolean _visible = true;
- private boolean drawBackColor = false;
- //
- //
-
- public ChartElement() {
- _foreColor = Color.black;
- _backColor = Color.white;
- _selected = false;
- _resizeAbility = ResizeAbility.None;
- }
- //
- //
-
- /**
- * Get if visible
- *
- * @return Boolean
- */
- public boolean isVisible() {
- return _visible;
- }
-
- /**
- * Set if visible
- *
- * @param istrue Boolean
- */
- public void setVisible(boolean istrue) {
- _visible = istrue;
- }
-
- /**
- * Get x
- *
- * @return x
- */
- public float getX() {
- return x;
- }
-
- /**
- * Set left
- *
- * @param left
- */
- public void setX(float left) {
- x = left;
- this.fireLocationChangedEvent();
- }
-
- /**
- * Get y
- *
- * @return Y
- */
- public float getY() {
- return y;
- }
-
- /**
- * Set y
- *
- * @param top Y
- */
- public void setY(float top) {
- y = top;
- this.fireLocationChangedEvent();
- }
-
- /**
- * Get width
- *
- * @return Width
- */
- public float getWidth() {
- return width;
- }
-
- /**
- * Set width
- *
- * @param width Width
- */
- public void setWidth(float width) {
- this.width = width;
- this.fireSizeChangedEvent();
- }
-
- /**
- * Get height
- *
- * @return Height
- */
- public float getHeight() {
- return height;
- }
-
- /**
- * Set height
- *
- * @param height Height
- */
- public void setHeight(float height) {
- this.height = height;
- this.fireSizeChangedEvent();
- }
-
- /**
- * Get right
- *
- * @return Right
- */
- public float getRight() {
- return x + width;
- }
-
- /**
- * Get bottom
- *
- * @return Bottom
- */
- public float getBottom() {
- return y + height;
- }
-
- /**
- * Get bounds rectangle
- *
- * @return Bounds rectangle
- */
- public Rectangle.Float getBounds() {
- return new Rectangle.Float(x, y, width, height);
- }
-
- /**
- * Get foreground color
- *
- * @return Foreground color
- */
- public Color getForeground() {
- return _foreColor;
- }
-
- /**
- * Set foreground color
- *
- * @param color Foreground color
- */
- public void setForeground(Color color) {
- _foreColor = color;
- }
-
- /**
- * Get background color
- *
- * @return Background color
- */
- public Color getBackground() {
- return _backColor;
- }
-
- /**
- * Set background color
- *
- * @param color Background color
- */
- public void setBackground(Color color) {
- _backColor = color;
- }
-
- /**
- * Get if is selected
- *
- * @return Boolean
- */
- public boolean isSelected() {
- return _selected;
- }
-
- /**
- * Set if is selected
- *
- * @param istrue Boolean
- */
- public void setSelected(boolean istrue) {
- _selected = istrue;
- }
-
- /**
- * Get resize ability
- *
- * @return Resize ability
- */
- public ResizeAbility getResizeAbility() {
- return _resizeAbility;
- }
-
- /**
- * Set resize ability
- *
- * @param ra Resize ability
- */
- public void setResizeAbility(ResizeAbility ra) {
- _resizeAbility = ra;
- }
-
- /**
- * Get is draw backcolor
- * @return Boolean
- */
- public boolean isDrawBackColor(){
- return drawBackColor;
- }
-
- /**
- * Set is draw backcolor
- * @param value Boolean
- */
- public void setDrawBackColor(boolean value){
- drawBackColor = value;
- }
- //
- //
-
- /**
- * Move update method
- */
- public abstract void moveUpdate();
-
- /**
- * Resize update method
- */
- public abstract void resizeUpdate();
-
- /**
- * Page to screen
- *
- * @param pageX Page X
- * @param pageY Page Y
- * @param pageLocation Page location
- * @param zoom Zoom
- * @return Screen point
- */
- public PointF pageToScreen(float pageX, float pageY, PointF pageLocation, float zoom) {
- float x = pageX * zoom + pageLocation.X;
- float y = pageY * zoom + pageLocation.Y;
- return (new PointF(x, y));
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartLegend.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartLegend.java
deleted file mode 100644
index d2b638b3..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartLegend.java
+++ /dev/null
@@ -1,1436 +0,0 @@
-/* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.chart;
-
-import org.meteoinfo.common.DataConvert;
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.common.XAlign;
-import org.meteoinfo.common.YAlign;
-import org.meteoinfo.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.geom.AffineTransform;
-import java.util.List;
-import org.meteoinfo.chart.plot.PlotOrientation;
-import org.meteoinfo.geometry.legend.*;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class ChartLegend {
- //
-
- //private final XY1DPlot plot;
- protected LegendScheme legendScheme;
- private LegendPosition position;
- protected float shrink;
- protected int aspect;
- private boolean colorBar;
- protected float x;
- protected float y;
- protected PlotOrientation orientation;
- protected Color background;
- protected boolean drawBackground;
- protected int width;
- protected int height;
- protected int legendWidth;
- protected int legendHeight;
- protected ChartText label;
- protected String labelLocation;
- protected Font tickLabelFont;
- protected Color tickLabelColor;
- protected float tickLabelAngle;
- protected boolean drawNeatLine;
- protected Color neatLineColor;
- protected float neatLineSize;
- private float breakSpace;
- private float topSpace;
- private float leftSpace;
- protected double _vBarWidth;
- protected double _hBarHeight;
- private int rowColNum = 1;
- private boolean autoRowColNum = true;
- private Dimension symbolDimension;
- protected boolean extendRect;
- protected boolean autoExtendFrac;
- protected float xshift;
- protected float yshift;
- //
- //
-
- /**
- * Constructor
- *
- * @param ls LegendScheme
- */
- public ChartLegend(LegendScheme ls) {
- //this.plot = plot;
- this.legendScheme = ls;
- this.colorBar = false;
- this.position = LegendPosition.LOWER_CENTER_OUTSIDE;
- this.orientation = PlotOrientation.HORIZONTAL;
- this.shrink = 1.0f;
- this.aspect = 20;
- this.background = Color.white;
- this.drawBackground = false;
- drawNeatLine = true;
- neatLineColor = Color.black;
- neatLineSize = 1;
- breakSpace = 3;
- topSpace = 5;
- leftSpace = 5;
- _vBarWidth = 10;
- _hBarHeight = 10;
- this.labelLocation = "out";
- tickLabelFont = new Font("Arial", Font.PLAIN, 14);
- this.tickLabelColor = Color.black;
- this.tickLabelAngle = 0;
- this.symbolDimension = new Dimension(16, 10);
- this.extendRect = true;
- this.autoExtendFrac = false;
- this.xshift = 0;
- this.yshift = 0;
- }
-
- //
- //
- //
- //
- /**
- * Get legend scheme
- *
- * @return Legend scheme
- */
- public LegendScheme getLegendScheme() {
- return this.legendScheme;
- }
-
- /**
- * Set legend scheme
- *
- * @param value Legend scheme
- */
- public void setLegendScheme(LegendScheme value) {
- this.legendScheme = value;
- }
-
- /**
- * Get if is color bar
- *
- * @return Boolean
- */
- public boolean isColorbar() {
- return this.colorBar;
- }
-
- /**
- * Set if is color bar
- *
- * @param value Boolean
- */
- public void setColorbar(boolean value) {
- this.colorBar = value;
- }
-
- /**
- * Get legend position
- *
- * @return Legend position
- */
- public LegendPosition getPosition() {
- return this.position;
- }
-
- /**
- * Set legend position
- *
- * @param value Legend position
- */
- public void setPosition(LegendPosition value) {
- this.position = value;
- }
-
- /**
- * Get shrink
- *
- * @return Shrink
- */
- public float getShrink() {
- return this.shrink;
- }
-
- /**
- * Set shrink
- *
- * @param value Shrink
- */
- public void setShrink(float value) {
- this.shrink = value;
- }
-
- /**
- * Get aspect
- *
- * @return Aspect
- */
- public int getAspect() {
- return this.aspect;
- }
-
- /**
- * Set aspect
- *
- * @param value Aspect
- */
- public void setAspect(int value) {
- this.aspect = value;
- }
-
- /**
- * Get X
- *
- * @return X value
- */
- public float getX() {
- return this.x;
- }
-
- /**
- * Set X
- *
- * @param value X value
- */
- public void setX(float value) {
- x = value;
- }
-
- /**
- * Get Y
- *
- * @return Y value
- */
- public float getY() {
- return this.y;
- }
-
- /**
- * Set Y
- *
- * @param value Y value
- */
- public void setY(float value) {
- y = value;
- }
-
- /**
- * Get width
- *
- * @return Width
- */
- public int getWidth() {
- return this.width;
- }
-
- /**
- * Set width
- *
- * @param value Width
- */
- public void setWidth(int value) {
- this.width = value;
- }
-
- /**
- * Get height
- *
- * @return Height
- */
- public int getHeight() {
- return this.height;
- }
-
- /**
- * Set height
- *
- * @param value Height
- */
- public void setHeight(int value) {
- this.height = value;
- }
-
- /**
- * Get legend width
- *
- * @return Legend width
- */
- public int getLegendWidth() {
- return this.legendWidth;
- }
-
- /**
- * Set legend width
- *
- * @param value Legend width
- */
- public void setLegendWidth(int value) {
- this.legendWidth = value;
- }
-
- /**
- * Get legend height
- *
- * @return Legend height
- */
- public int getLegendHeight() {
- return this.legendHeight;
- }
-
- /**
- * Set legend height
- *
- * @param value Legend height
- */
- public void setLegendHeight(int value) {
- this.legendHeight = value;
- }
-
- /**
- * Get plot orientation
- *
- * @return Plot orientation
- */
- public PlotOrientation getPlotOrientation() {
- return this.orientation;
- }
-
- /**
- * Set plot orientation
- *
- * @param value Plot orientation
- */
- public void setPlotOrientation(PlotOrientation value) {
- this.orientation = value;
- }
-
- /**
- * Get background
- *
- * @return Background
- */
- public Color getBackground() {
- return this.background;
- }
-
- /**
- * Set background
- *
- * @param value Background
- */
- public void setBackground(Color value) {
- this.background = value;
- }
-
- /**
- * Get if draw background
- *
- * @return Boolean
- */
- public boolean isDrawBackground() {
- return this.drawBackground;
- }
-
- /**
- * Set if draw background
- *
- * @param value Boolean
- */
- public void setDrawBackground(boolean value) {
- this.drawBackground = value;
- }
-
- /**
- * Get if draw neat line
- *
- * @return If draw neat line
- */
- public boolean isDrawNeatLine() {
- return drawNeatLine;
- }
-
- /**
- * Set if draw neat line
- *
- * @param istrue If draw neat line
- */
- public void setDrawNeatLine(boolean istrue) {
- drawNeatLine = istrue;
- }
-
- /**
- * Get neat line color
- *
- * @return Neat line color
- */
- public Color getNeatLineColor() {
- return neatLineColor;
- }
-
- /**
- * Set neat line color
- *
- * @param color Neat line color
- */
- public void setNeatLineColor(Color color) {
- neatLineColor = color;
- }
-
- /**
- * Get neat line size
- *
- * @return Neat line size
- */
- public float getNeatLineSize() {
- return neatLineSize;
- }
-
- /**
- * Set neat line size
- *
- * @param size Neat line size
- */
- public void setNeatLineSize(float size) {
- neatLineSize = size;
- }
-
- /**
- * Get break space
- * @return Break space
- */
- public float getBreakSpace() {
- return this.breakSpace;
- }
-
- /**
- * Set break space
- * @param value Break space
- */
- public void setBreakSpace(float value) {
- this.breakSpace = value;
- }
-
- /**
- * Get label
- *
- * @return Label
- */
- public ChartText getLabel() {
- return this.label;
- }
-
- /**
- * Set label
- *
- * @param value Label
- */
- public void setLabel(ChartText value) {
- this.label = value;
- }
-
- /**
- * Get label font
- *
- * @return Label font
- */
- public Font getLabelFont() {
- return this.label.getFont();
- }
-
- /**
- * Set label font
- *
- * @param value Label font
- */
- public void setLabelFont(Font value) {
- this.label.setFont(value);
- }
-
- /**
- * Get label color
- *
- * @return Label color
- */
- public Color getLabelColor() {
- return this.label.getColor();
- }
-
- /**
- * Set label color
- *
- * @param value Label color
- */
- public void setLabelColor(Color value) {
- this.label.setColor(value);
- }
-
- /**
- * Get label location (in, out, top, bottom, left, right)
- *
- * @return Label location
- */
- public String getLabelLocation() {
- return this.labelLocation;
- }
-
- /**
- * Set label location
- *
- * @param value Label location
- */
- public void setLabelLocation(String value) {
- this.labelLocation = value;
- }
-
- /**
- * Get Tick label font
- *
- * @return The Tick label font
- */
- public Font getTickLabelFont() {
- return tickLabelFont;
- }
-
- /**
- * Set Tick label font
- *
- * @param font The Tick label font
- */
- public void setTickLabelFont(Font font) {
- tickLabelFont = font;
- }
-
- /**
- * Get tick label color
- *
- * @return Tick label color
- */
- public Color getTickLabelColor() {
- return this.tickLabelColor;
- }
-
- /**
- * Set tick label color
- *
- * @param value Tick label color
- */
- public void setTickLabelColor(Color value) {
- this.tickLabelColor = value;
- }
-
- /**
- * Get tick lable angle
- *
- * @return Tick label angle
- */
- public float getTickLabelAngle() {
- return this.tickLabelAngle;
- }
-
- /**
- * Set tick label angle
- *
- * @param value Tick label angle
- */
- public void setTickLabelAngle(float value) {
- this.tickLabelAngle = value;
- }
-
- /**
- * Get column number
- *
- * @return Column number
- */
- public int getColumnNumber() {
- return rowColNum;
- }
-
- /**
- * Set column number
- *
- * @param value Column number
- */
- public void setColumnNumber(int value) {
- rowColNum = value;
- }
-
- /**
- * Get if automatic set row/col number
- *
- * @return Boolean
- */
- public boolean isAutoRowColNum() {
- return this.autoRowColNum;
- }
-
- /**
- * Set if automatic set row/col number
- *
- * @param value Boolean
- */
- public void setAutoRowColNum(boolean value) {
- this.autoRowColNum = value;
- }
-
- /**
- * Get symbol dimension
- *
- * @return Symbol dimension
- */
- public Dimension getSymbolDimension() {
- return this.symbolDimension;
- }
-
- /**
- * Set symbol dimension
- *
- * @param value Symbol dimension
- */
- public void setSymbolDimension(Dimension value) {
- this.symbolDimension = value;
- }
-
- /**
- * Set symbol width
- *
- * @param value Width
- */
- public void setSymbolWidth(int value) {
- this.symbolDimension.width = value;
- }
-
- /**
- * Set symbol height
- *
- * @param value height
- */
- public void setSymbolHeight(int value) {
- this.symbolDimension.height = value;
- }
-
- /**
- * Set symbol scale
- *
- * @param value Symble scale
- */
- public void setSymbolScale(float value) {
- double w = this.symbolDimension.getWidth() * value;
- double h = this.symbolDimension.getHeight() * value;
- this.symbolDimension.setSize(w, h);
- }
-
- /**
- * Get if extend rectangle - or triangle
- *
- * @return Boolean
- */
- public boolean isExtendRect() {
- return this.extendRect;
- }
-
- /**
- * Set if extend rectangle - or triangle
- *
- * @param value Boolean
- */
- public void setExtendRect(boolean value) {
- this.extendRect = value;
- }
-
- /**
- * Get if auto set extend fraction - extend has save width and height Only
- * valid for colorbar
- *
- * @return Boolean
- */
- public boolean isAutoExtendFrac() {
- return this.autoExtendFrac;
- }
-
- /**
- * Set if auto set extend fraction - extend has save width and height Only
- * valid for colorbar
- *
- * @param value
- */
- public void setAutoExtendFrac(boolean value) {
- this.autoExtendFrac = value;
- }
-
- /**
- * Set tick labels
- *
- * @param value Tick labels
- */
- public void setTickCaptions(List value) {
- for (int i = 0; i < this.legendScheme.getBreakNum(); i++) {
- if (i < value.size()) {
- this.legendScheme.getLegendBreaks().get(i).setCaption(value.get(i));
- } else {
- break;
- }
- }
- }
-
- /**
- * Get x shift - pixel unit
- *
- * @return X shift
- */
- public float getXShift() {
- return this.xshift;
- }
-
- /**
- * Set x shift
- *
- * @param value X shift
- */
- public void setXShift(float value) {
- this.xshift = value;
- }
-
- /**
- * Get y shift - pixel unit
- *
- * @return Y shift
- */
- public float getYShift() {
- return this.yshift;
- }
-
- /**
- * Set y shift
- *
- * @param value Y shift
- */
- public void setYShift(float value) {
- this.yshift = value;
- }
-
- //
- //
- /**
- * Draw legend
- *
- * @param g Graphics2D
- * @param point Start point
- */
- public void draw(Graphics2D g, PointF point) {
-
- AffineTransform oldMatrix = g.getTransform();
- g.translate(point.X + this.xshift, point.Y + this.yshift);
-
- //Draw background color
- if (this.drawBackground) {
- g.setColor(this.background);
- g.fill(new Rectangle.Float(0, 0, this.width, this.height));
- }
-
- //Draw legend
- g.setStroke(new BasicStroke(1));
- switch (this.orientation) {
- case HORIZONTAL:
- drawHorizontalLegend(g, legendScheme);
- break;
- case VERTICAL:
- this.drawVerticalLegend(g, legendScheme);
- break;
- }
-
- //Draw neatline
- if (drawNeatLine) {
- Rectangle.Float mapRect = new Rectangle.Float(0, 0, this.width, this.height);
- g.setColor(neatLineColor);
- g.setStroke(new BasicStroke(neatLineSize));
- g.draw(mapRect);
- }
-
- g.setTransform(oldMatrix);
- }
-
- private void drawVerticalLegend(Graphics2D g, LegendScheme aLS) {
- String caption;
- float breakHeight = this.getBreakHeight(g);
- float symbolHeight = this.symbolDimension.height;
- float symbolWidth = this.symbolDimension.width;
- float colWidth = symbolWidth + getMaxLabelWidth(g) + 10;
-
- //Set columns
- int[] rowNums = new int[rowColNum];
- int ave = aLS.getVisibleBreakNum() / rowColNum;
- if (ave * rowColNum < aLS.getBreakNum()) {
- ave += 1;
- }
- int num = 0;
- int i;
- for (i = 1; i < rowColNum; i++) {
- rowNums[i] = ave;
- num += ave;
- }
- rowNums[0] = aLS.getVisibleBreakNum() - num;
-
- //Draw title
- float y0 = 0;
- if (this.label != null) {
- float x0 = (float) (this.width / 2.);
- y0 += this.breakSpace * 2;
- this.label.draw(g, x0, y0);
- y0 += this.label.getDimension(g).height + this.breakSpace * 2;
- }
-
- //Draw legend
- float x, y;
- i = 0;
- for (int col = 0; col < rowColNum; col++) {
- x = symbolWidth / 2 + leftSpace + col * colWidth;
- y = y0 + breakHeight / 2 + breakSpace * 2;
- for (int row = 0; row < rowNums[col]; row++) {
- if (!aLS.getLegendBreaks().get(i).isDrawShape()) {
- continue;
- }
-
- //y += breakHeight + breakSpace;
- ColorBreak cb = aLS.getLegendBreaks().get(i);
- if (!cb.isDrawShape()) {
- continue;
- }
- caption = aLS.getLegendBreaks().get(i).getCaption();
- if (cb instanceof PointBreak) {
- PointBreak aPB = (PointBreak) cb.clone();
- ((PointBreak) aPB).setSize(((PointBreak) cb).getSize() * (symbolHeight / 10.f));
- Draw.drawPoint(new PointF(x, y), aPB, g);
- } else if (cb instanceof PolylineBreak) {
- PolylineBreak aPLB = (PolylineBreak) cb;
- Draw.drawPolylineSymbol_S(new PointF(x, y), symbolWidth, symbolHeight, aPLB, g);
- } else if (cb instanceof PolygonBreak) {
- Draw.drawPolygonSymbol(new PointF(x, y), symbolWidth, symbolHeight, (PolygonBreak) cb, g);
- } else {
- PolygonBreak pgb = new PolygonBreak();
- pgb.setColor(cb.getColor());
- pgb.setOutlineColor(Color.black);
- Draw.drawPolygonSymbol(new PointF(x, y), symbolWidth, symbolHeight, pgb, g);
- }
-
- PointF sP = new PointF(0, 0);
- sP.X = x + symbolWidth / 2;
- sP.Y = y;
- g.setColor(this.tickLabelColor);
- g.setFont(this.tickLabelFont);
- Draw.drawString(g, sP.X + 5, sP.Y, caption, XAlign.LEFT, YAlign.CENTER, true);
- y += breakHeight + breakSpace;
-
- i += 1;
- }
- }
- }
-
- private void drawHorizontalLegend(Graphics2D g, LegendScheme aLS) {
- String caption;
- float breakHeight = this.getBreakHeight(g);
- float symbolHeight = this.symbolDimension.height;
- float symbolWidth = this.symbolDimension.width;
-
- //Set columns
- int[] colNums = new int[rowColNum];
- int ave = aLS.getVisibleBreakNum() / rowColNum;
- if (ave * rowColNum < aLS.getBreakNum()) {
- ave += 1;
- }
- int num = 0;
- int i;
- for (i = 0; i < rowColNum - 1; i++) {
- colNums[i] = ave;
- num += ave;
- }
- colNums[rowColNum - 1] = aLS.getVisibleBreakNum() - num;
-
- //Draw legend
- float x, y;
- y = this.breakSpace + breakHeight / 2;
- i = 0;
- for (int row = 0; row < rowColNum; row++) {
- x = this.symbolDimension.width / 2 + 5;
- for (int col = 0; col < colNums[row]; col++) {
- if (i >= aLS.getBreakNum()) {
- break;
- }
-
- ColorBreak cb = aLS.getLegendBreaks().get(i);
- if (!cb.isDrawShape()) {
- continue;
- }
- caption = aLS.getLegendBreaks().get(i).getCaption();
- if (cb instanceof PointBreak) {
- PointBreak aPB = (PointBreak) cb;
- Draw.drawPoint(new PointF(x, y), aPB, g);
- } else if (cb instanceof PolylineBreak) {
- PolylineBreak aPLB = (PolylineBreak) cb;
- Draw.drawPolylineSymbol_S(new PointF(x, y), symbolWidth, symbolHeight, aPLB, g);
- } else if (cb instanceof PolygonBreak) {
- Draw.drawPolygonSymbol(new PointF(x, y), symbolWidth, symbolHeight, (PolygonBreak) cb, g);
- }
-
- PointF sP = new PointF(0, 0);
- sP.X = x + symbolWidth / 2;
- sP.Y = y;
- g.setColor(this.tickLabelColor);
- g.setFont(this.tickLabelFont);
- Draw.drawString(g, sP.X + 5, sP.Y, caption, XAlign.LEFT, YAlign.CENTER, true);
- Dimension dim = Draw.getStringDimension(caption, g);
- x += this.symbolDimension.width + dim.width + 15;
- i += 1;
- }
- y += breakHeight + this.breakSpace * 2;
- }
- }
-
- private int getMaxLabelWidth(Graphics2D g) {
- String caption;
- Dimension aSF;
- int bNum = legendScheme.getBreakNum();
- int labWidth = 0;
- g.setFont(this.tickLabelFont);
- for (int i = 0; i < bNum; i++) {
- caption = legendScheme.getLegendBreaks().get(i).getCaption();
- boolean isValid = true;
- if (isValid) {
- aSF = Draw.getStringDimension(caption, this.tickLabelAngle, g);
- int labwidth = aSF.width;
- if (labWidth < labwidth) {
- labWidth = labwidth;
- }
- }
- }
-
- return labWidth;
- }
-
- private int getBreakHeight(Graphics2D g) {
- g.setFont(tickLabelFont);
- Dimension dim = Draw.getStringDimension(this.legendScheme.getLegendBreak(0).getCaption(), g);
- return Math.max(dim.height, this.symbolDimension.height);
- }
-
- /**
- * Get legend dimension
- *
- * @param g Graphics2D
- * @param limitDim Limit dimension
- * @return Legend dimension
- */
- public Dimension getLegendDimension(Graphics2D g, Dimension limitDim) {
- if (legendScheme != null) {
- if (this.colorBar) {
- switch (this.orientation) {
- case VERTICAL:
- this.width = (int) (this.getTickWidth(g) + limitDim.height * this.shrink / this.aspect + 5);
- if (this.label != null) {
- g.setFont(this.label.getFont());
- this.width += (int) Draw.getStringDimension(label.getText(), g).height + 5;
- }
- break;
- default:
- g.setFont(this.tickLabelFont);
- this.height = (int) (Draw.getStringDimension("test", g).height + limitDim.width * this.shrink / this.aspect + 5);
- if (this.label != null) {
- g.setFont(this.label.getFont());
- Dimension dim = Draw.getStringDimension(label.getText(), g);
- switch (this.labelLocation) {
- case "top":
- case "right":
- this.width += dim.width + 10;
- break;
- default:
- this.height += (int) Draw.getStringDimension(label.getText(), g).height + 5;
- break;
- }
- }
- }
- } else {
- int breakHeight = getBreakHeight(g);
- int titleHeight = 0;
- int titleWidth = 0;
- if (this.label != null) {
- Dimension dim = this.label.getDimension(g);
- titleHeight = dim.height + (int) (this.breakSpace * 4);
- titleWidth = dim.width;
- }
- switch (this.orientation) {
- case VERTICAL:
- //Get column number
- if (this.autoRowColNum) {
- int tHeight = (int) (legendScheme.getBreakNum() * (breakHeight + breakSpace)
- + breakSpace * 2 + breakHeight / 2 + 5);
- rowColNum = 1;
- if (tHeight > limitDim.height * 10 / 8) {
- rowColNum = tHeight / (limitDim.height * 10 / 8) + 1;
- if (rowColNum == 1) {
- rowColNum = 2;
- } else {
- int n = legendScheme.getBreakNum() / rowColNum;
- int m = legendScheme.getBreakNum() % rowColNum;
- if (m != 0) {
- if (m <= n) {
- rowColNum += 1;
- } else {
- rowColNum += 2;
- }
- } else if (rowColNum * (limitDim.width * 8 / 10) < tHeight) {
- rowColNum += 1;
- }
- }
- }
- }
-
- //Get width
- int colWidth = this.symbolDimension.width + getMaxLabelWidth(g) + 15;
- this.width = colWidth * rowColNum;
-
- //Get height
- int[] rowNums = new int[rowColNum];
- int ave = legendScheme.getBreakNum() / rowColNum;
- if (ave * rowColNum < legendScheme.getBreakNum()) {
- ave += 1;
- }
- int num = 0;
- int i;
- for (i = 0; i < rowColNum - 1; i++) {
- rowNums[i] = ave;
- num += ave;
- }
- rowNums[rowColNum - 1] = legendScheme.getBreakNum() - num;
-
-// this.height = (int) (rowNums[0] * (breakHeight + _breakSpace)
-// + _breakSpace * 2 + breakHeight / 2 + 5);
- this.height = (int) (rowNums[0] * (breakHeight + breakSpace)
- + breakSpace * 3);
- break;
- case HORIZONTAL:
- //Get row number
- if (this.autoRowColNum) {
- int breakWidth = this.symbolDimension.width + this.getMaxLabelWidth(g) + 15;
- int tWidth = breakWidth * legendScheme.getBreakNum();
- rowColNum = 1;
- if (tWidth > limitDim.width * 8 / 10) {
- rowColNum = tWidth / (limitDim.width * 8 / 10);
- if (rowColNum == 1) {
- rowColNum = 2;
- } else {
- int n = legendScheme.getBreakNum() / rowColNum;
- int m = legendScheme.getBreakNum() % rowColNum;
- if (m != 0) {
- if (m <= n) {
- rowColNum += 1;
- } else {
- rowColNum += 2;
- }
- } else if (rowColNum * (limitDim.width * 8 / 10) < tWidth) {
- rowColNum += 1;
- }
- }
- }
- }
-
- //Get height
- this.height = (int) (breakHeight + this.breakSpace * 2) * this.rowColNum;
-
- //Get width
- //FontMetrics metrics = g.getFontMetrics(tickFont);
- ave = legendScheme.getBreakNum() / rowColNum;
- if (ave * rowColNum < legendScheme.getBreakNum()) {
- ave += 1;
- }
- num = 0;
- int maxWidth = 0;
- int tempWidth = 0;
- for (i = 0; i < legendScheme.getBreakNum(); i++) {
- if (num < ave) {
- //tempWidth += this.symbolDimension.width + 15
- // + metrics.stringWidth(legendScheme.getLegendBreaks().get(i).getCaption());
- tempWidth += this.symbolDimension.width + 15
- + Draw.getStringDimension(legendScheme.getLegendBreaks().get(i).getCaption(), g).width;
- num += 1;
- } else {
- if (maxWidth < tempWidth) {
- maxWidth = tempWidth;
- }
- //tempWidth = metrics.stringWidth(legendScheme.getLegendBreaks().get(i).getCaption()) + 15;
- tempWidth = Draw.getStringDimension(legendScheme.getLegendBreaks().get(i).getCaption(), g).width;
- num = 1;
- }
- }
- if (maxWidth < tempWidth) {
- maxWidth = tempWidth;
- }
- if (maxWidth > limitDim.width) {
- maxWidth = limitDim.width * 8 / 10;
- }
- this.width = maxWidth;
- break;
- }
- this.height += titleHeight;
- this.width = Math.max(this.width, titleWidth);
- }
- }
-
- return new Dimension(this.width, this.height);
- }
-
- protected int getTickWidth(Graphics2D g) {
- float rwidth = 0;
- String caption = "";
- int bNum = this.legendScheme.getBreakNum();
- //FontMetrics metrics = g.getFontMetrics(this.tickFont);
- g.setFont(this.tickLabelFont);
- if (this.legendScheme.getLegendBreaks().get(bNum - 1).isNoData()) {
- bNum -= 1;
- }
- for (int i = 0; i < bNum; i++) {
- switch (this.legendScheme.getShapeType()) {
- case Point:
- PointBreak aPB = (PointBreak) legendScheme.getLegendBreaks().get(i);
- if (legendScheme.getLegendType() == LegendType.GraduatedColor) {
- caption = DataConvert.removeTailingZeros(aPB.getEndValue().toString());
- } else {
- caption = aPB.getCaption();
- }
- break;
- case Polyline:
- PolylineBreak aPLB = (PolylineBreak) legendScheme.getLegendBreaks().get(i);
- if (legendScheme.getLegendType() == LegendType.GraduatedColor) {
- caption = DataConvert.removeTailingZeros(aPLB.getEndValue().toString());
- } else {
- caption = aPLB.getCaption();
- }
- break;
- case Polygon:
- PolygonBreak aPGB = (PolygonBreak) legendScheme.getLegendBreaks().get(i);
- if (legendScheme.getLegendType() == LegendType.GraduatedColor) {
- caption = DataConvert.removeTailingZeros(aPGB.getEndValue().toString());
- } else {
- caption = aPGB.getCaption();
- }
- break;
- case Image:
- ColorBreak aCB = legendScheme.getLegendBreaks().get(i);
- if (legendScheme.getLegendType() == LegendType.GraduatedColor) {
- caption = DataConvert.removeTailingZeros(aCB.getEndValue().toString());
- } else {
- caption = aCB.getCaption();
- }
- break;
- }
-
- boolean isValid = true;
- switch (legendScheme.getLegendType()) {
- case GraduatedColor:
- if (i == bNum - 1) {
- isValid = false;
- }
- break;
- }
- if (isValid) {
- //float labwidth = metrics.stringWidth(caption);
- float labwidth = (float) Draw.getStringDimension(caption, this.tickLabelAngle, g).getWidth();
- if (rwidth < labwidth) {
- rwidth = labwidth;
- }
- }
- }
-
- return (int) rwidth;
- }
-
- protected int getTickHeight(Graphics2D g) {
- float rheight = 0;
- String caption = "";
- int bNum = this.legendScheme.getBreakNum();
- //FontMetrics metrics = g.getFontMetrics(this.tickFont);
- g.setFont(this.tickLabelFont);
- if (this.legendScheme.getLegendBreaks().get(bNum - 1).isNoData()) {
- bNum -= 1;
- }
- for (int i = 0; i < bNum; i++) {
- switch (this.legendScheme.getShapeType()) {
- case Point:
- PointBreak aPB = (PointBreak) legendScheme.getLegendBreaks().get(i);
- if (legendScheme.getLegendType() == LegendType.GraduatedColor) {
- caption = DataConvert.removeTailingZeros(aPB.getEndValue().toString());
- } else {
- caption = aPB.getCaption();
- }
- break;
- case Polyline:
- PolylineBreak aPLB = (PolylineBreak) legendScheme.getLegendBreaks().get(i);
- if (legendScheme.getLegendType() == LegendType.GraduatedColor) {
- caption = DataConvert.removeTailingZeros(aPLB.getEndValue().toString());
- } else {
- caption = aPLB.getCaption();
- }
- break;
- case Polygon:
- PolygonBreak aPGB = (PolygonBreak) legendScheme.getLegendBreaks().get(i);
- if (legendScheme.getLegendType() == LegendType.GraduatedColor) {
- caption = DataConvert.removeTailingZeros(aPGB.getEndValue().toString());
- } else {
- caption = aPGB.getCaption();
- }
- break;
- case Image:
- ColorBreak aCB = legendScheme.getLegendBreaks().get(i);
- if (legendScheme.getLegendType() == LegendType.GraduatedColor) {
- caption = DataConvert.removeTailingZeros(aCB.getEndValue().toString());
- } else {
- caption = aCB.getCaption();
- }
- break;
- }
-
- boolean isValid = true;
- switch (legendScheme.getLegendType()) {
- case GraduatedColor:
- if (i == bNum - 1) {
- isValid = false;
- }
- break;
- }
- if (isValid) {
- float labheight = (float) Draw.getStringDimension(caption, 90 - Math.abs(this.tickLabelAngle), g).getWidth();
- if (rheight < labheight) {
- rheight = labheight;
- }
- }
- }
-
- return (int) rheight;
- }
-
- /**
- * Update tick gap
- *
- * @param g Graphics2D
- * @return Ticks gap
- */
- protected int getTickGap(Graphics2D g) {
- if (this.tickLabelAngle != 0) {
- return 1;
- }
-
- double len;
- int n = this.legendScheme.getBreakNum();
- int nn;
- if (this.orientation == PlotOrientation.HORIZONTAL) {
- len = this.width;
- int labLen = this.getTickWidth(g);
- nn = (int) ((len * 0.8) / labLen);
- } else {
- len = this.height;
- FontMetrics metrics = g.getFontMetrics(tickLabelFont);
- nn = (int) (len / metrics.getHeight());
- }
- if (nn == 0) {
- nn = 1;
- }
- return n / nn + 1;
- }
-
- //
- //
- public class LayoutLegendBean {
-
- LayoutLegendBean() {
- }
-
- //
- /**
- * Get if draw neat line
- *
- * @return If draw neat line
- */
- public boolean isDrawNeatLine() {
- return drawNeatLine;
- }
-
- /**
- * Set if draw neat line
- *
- * @param istrue If draw neat line
- */
- public void setDrawNeatLine(boolean istrue) {
- drawNeatLine = istrue;
- }
-
- /**
- * Get neat line color
- *
- * @return Neat line color
- */
- public Color getNeatLineColor() {
- return neatLineColor;
- }
-
- /**
- * Set neat line color
- *
- * @param color Neat line color
- */
- public void setNeatLineColor(Color color) {
- neatLineColor = color;
- }
-
- /**
- * Get neat line size
- *
- * @return Neat line size
- */
- public float getNeatLineSize() {
- return neatLineSize;
- }
-
- /**
- * Set neat line size
- *
- * @param size Neat line size
- */
- public void setNeatLineSize(float size) {
- neatLineSize = size;
- }
-
- /**
- * Get tick label font
- *
- * @return The tick label font
- */
- public Font getTickLabelFont() {
- return tickLabelFont;
- }
-
- /**
- * Set tick label font
- *
- * @param font The tick label font
- */
- public void setTickLabelFont(Font font) {
- tickLabelFont = font;
- }
-
- /**
- * Get column number
- *
- * @return Column number
- */
- public int getColumnNumber() {
- return rowColNum;
- }
-
- /**
- * Set column number
- *
- * @param value Column number
- */
- public void setColumnNumber(int value) {
- rowColNum = value;
- }
-
- /**
- * Get is draw background
- *
- * @return Boolean
- */
- public boolean isDrawBackground() {
- return drawBackground;
- }
-
- /**
- * Set is draw background
- *
- * @param value Boolean
- */
- public void setDrawBackground(boolean value) {
- drawBackground = value;
- }
-
- /**
- * Get background color
- *
- * @return Background color
- */
- public Color getBackground() {
- return background;
- }
-
- /**
- * Set background color
- *
- * @param c Background color
- */
- public void setBackground(Color c) {
- background = c;
- }
-
- //
- }
-
- public static class LayoutLegendBeanBeanInfo extends BaseBeanInfo {
-
- public LayoutLegendBeanBeanInfo() {
- super(LayoutLegendBean.class);
- ExtendedPropertyDescriptor e = addProperty("plotOrientation");
- e.setCategory("General").setDisplayName("Plot orientation");
- e.setPropertyEditorClass(PlotOrientationEditor.class);
- addProperty("tickFont").setCategory("General").setDisplayName("Tick Font");
- addProperty("drawBackground").setCategory("General").setDisplayName("Draw Background");
- addProperty("background").setCategory("General").setDisplayName("Background");
- addProperty("columnNumber").setCategory("General").setDisplayName("Column Number");
- addProperty("drawNeatLine").setCategory("Neat Line").setDisplayName("Draw Neat Line");
- addProperty("neatLineColor").setCategory("Neat Line").setDisplayName("Neat Line Color");
- addProperty("neatLineSize").setCategory("Neat Line").setDisplayName("Neat Line Size");
- }
- }
-
- public static class PlotOrientationEditor extends ComboBoxPropertyEditor {
-
- public PlotOrientationEditor() {
- super();
- PlotOrientation[] orientations = PlotOrientation.values();
- String[] types = new String[orientations.length];
- int i = 0;
- for (PlotOrientation type : orientations) {
- types[i] = type.toString();
- i += 1;
- }
- setAvailableValues(types);
- }
- }
-
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartNorthArrow.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartNorthArrow.java
deleted file mode 100644
index a6e9813f..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartNorthArrow.java
+++ /dev/null
@@ -1,298 +0,0 @@
-/* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.chart;
-
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.drawing.Draw;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-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.layout.NorthArrowType;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class ChartNorthArrow extends ChartElement {
-//
-
- private MapPlot mapPlot;
- private boolean _antiAlias;
- private float lineWidth;
- private boolean _drawNeatLine;
- private Color _neatLineColor;
- private float _neatLineSize;
- private NorthArrowType _northArrowType;
- private float _angle;
- //
- //
-
- /**
- * Constructor
- *
- * @param mapPlot The map plot
- */
- public ChartNorthArrow(MapPlot mapPlot) {
- super();
-
- this.setWidth(50);
- this.setHeight(50);
-
- this.mapPlot = mapPlot;
- this.lineWidth = 1;
- _antiAlias = true;
- _drawNeatLine = false;
- _neatLineColor = Color.black;
- _neatLineSize = 1;
- _northArrowType = NorthArrowType.NORTHARROW_1;
- _angle = 0;
- }
- //
- //
-
- /**
- * Get map plot
- *
- * @return The map plot
- */
- public MapPlot getMapPlot() {
- return this.mapPlot;
- }
-
- /**
- * Get line widht
- * @return Line width
- */
- public float getLineWidth() {
- return this.lineWidth;
- }
-
- /**
- * Set line width
- * @param value Line width
- */
- public void setLineWidth(float value) {
- this.lineWidth = value;
- }
-
- /**
- * Get if draw neat line
- *
- * @return If draw neat line
- */
- public boolean isDrawNeatLine() {
- return _drawNeatLine;
- }
-
- /**
- * Set if draw neat line
- *
- * @param istrue If draw neat line
- */
- public void setDrawNeatLine(boolean istrue) {
- _drawNeatLine = istrue;
- }
-
- /**
- * Get neat line color
- *
- * @return Neat line color
- */
- public Color getNeatLineColor() {
- return _neatLineColor;
- }
-
- /**
- * Set neat line color
- *
- * @param color Neat line color
- */
- public void setNeatLineColor(Color color) {
- _neatLineColor = color;
- }
-
- /**
- * Get neat line size
- *
- * @return Neat line size
- */
- public float getNeatLineSize() {
- return _neatLineSize;
- }
-
- /**
- * Set neat line size
- *
- * @param size Neat line size
- */
- public void setNeatLineSize(float size) {
- _neatLineSize = size;
- }
-
- /**
- * Get angle
- *
- * @return Angle
- */
- public float getAngle() {
- return _angle;
- }
-
- /**
- * Set angle
- *
- * @param angle The angle
- */
- public void setAngle(float angle) {
- _angle = angle;
- }
-
- //
- //
- /**
- * Draw text
- *
- * @param g Graphics2D
- * @param x X
- * @param y Y
- */
- public void draw(Graphics2D g, float x, float y) {
- AffineTransform oldMatrix = g.getTransform();
- g.translate(x, y);
- if (_angle != 0) {
- g.rotate(_angle);
- }
- if (_antiAlias) {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- } else {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
- }
-
- //Draw background color
- if (this.isDrawBackColor()){
- g.setColor(this.getBackground());
- g.fill(new Rectangle.Float(0, 0, this.getWidth(), this.getHeight()));
- }
-
- drawNorthArrow(g);
-
- //Draw neatline
- if (_drawNeatLine) {
- Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
- (this.getWidth() - _neatLineSize), (this.getHeight() - _neatLineSize));
- g.setColor(_neatLineColor);
- g.setStroke(new BasicStroke(_neatLineSize));
- g.draw(mapRect);
- }
-
- g.setTransform(oldMatrix);
- }
-
- /**
- * Paint graphics
- *
- * @param g Graphics
- * @param pageLocation Page location
- * @param zoom Zoom
- */
- public void paintGraphics(Graphics2D g, PointF pageLocation, float zoom) {
- AffineTransform oldMatrix = g.getTransform();
- PointF aP = pageToScreen(this.getX(), this.getY(), pageLocation, zoom);
- g.translate(aP.X, aP.Y);
- g.scale(zoom, zoom);
- if (_angle != 0) {
- g.rotate(_angle);
- }
- if (_antiAlias) {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- } else {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
- }
-
- //Draw background color
- if (this.isDrawBackColor()){
- g.setColor(this.getBackground());
- g.fill(new Rectangle.Float(0, 0, this.getWidth() * zoom, this.getHeight() * zoom));
- }
-
- drawNorthArrow(g);
-
- //Draw neatline
- if (_drawNeatLine) {
- Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
- (this.getWidth() - _neatLineSize) * zoom, (this.getHeight() - _neatLineSize) * zoom);
- g.setColor(_neatLineColor);
- g.setStroke(new BasicStroke(_neatLineSize));
- g.draw(mapRect);
- }
-
- g.setTransform(oldMatrix);
- }
-
- private void drawNorthArrow(Graphics2D g) {
- switch (_northArrowType) {
- case NORTHARROW_1:
- drawNorthArrow1(g);
- break;
- }
- }
-
- private void drawNorthArrow1(Graphics2D g) {
- g.setColor(this.getForeground());
- g.setStroke(new BasicStroke(this.lineWidth));
-
- //Draw N symbol
- PointF[] points = new PointF[4];
- float x = this.getWidth() / 2;
- float y = this.getHeight() / 6;
- float w = this.getWidth() / 6;
- float h = this.getHeight() / 4;
- points[0] = new PointF(x - w / 2, y + h / 2);
- points[1] = new PointF(x - w / 2, y - h / 2);
- points[2] = new PointF(x + w / 2, y + h / 2);
- points[3] = new PointF(x + w / 2, y - h / 2);
- Draw.drawPolyline(points, g);
-
- //Draw arrow
- w = this.getWidth() / 2;
- h = this.getHeight() * 2 / 3;
- points = new PointF[3];
- points[0] = new PointF(x - w / 2, this.getHeight());
- points[1] = new PointF(x, this.getHeight() - h / 2);
- points[2] = new PointF(x, this.getHeight() - h);
- Draw.fillPolygon(points, g, null);
- Draw.drawPolyline(points, g);
-
- points = new PointF[4];
- points[0] = new PointF(x + w / 2, this.getHeight());
- points[1] = new PointF(x, this.getHeight() - h / 2);
- points[2] = new PointF(x, this.getHeight() - h);
- points[3] = points[0];
- Draw.drawPolyline(points, g);
- }
-
- @Override
- public void moveUpdate() {
- }
-
- @Override
- public void resizeUpdate() {
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartPanel.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartPanel.java
deleted file mode 100644
index fc59e77f..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartPanel.java
+++ /dev/null
@@ -1,1689 +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;
-
-import com.itextpdf.awt.PdfGraphics2D;
-import com.itextpdf.text.Document;
-import com.itextpdf.text.DocumentException;
-import com.itextpdf.text.pdf.PdfContentByte;
-import com.itextpdf.text.pdf.PdfTemplate;
-import com.itextpdf.text.pdf.PdfWriter;
-
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.ComponentEvent;
-import java.awt.event.MouseAdapter;
-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;
-import java.awt.image.BufferedImage;
-import java.awt.print.PageFormat;
-import java.awt.print.Printable;
-import java.io.File;
-import java.io.FileNotFoundException;
-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;
-import java.util.logging.Logger;
-import javax.imageio.IIOImage;
-import javax.imageio.ImageIO;
-import javax.imageio.ImageTypeSpecifier;
-import javax.imageio.ImageWriteParam;
-import javax.imageio.ImageWriter;
-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.DocFlavor;
-import javax.print.DocPrintJob;
-import javax.print.PrintException;
-import javax.print.PrintService;
-import javax.print.SimpleDoc;
-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;
-import javax.swing.JPopupMenu;
-import javax.swing.SwingUtilities;
-import javax.swing.Timer;
-import javax.swing.event.EventListenerList;
-import javax.swing.table.DefaultTableModel;
-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.plot.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.GenericFileFilter;
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.ndarray.DataType;
-import org.meteoinfo.image.ImageUtil;
-import org.meteoinfo.layer.LayerTypes;
-import org.meteoinfo.layer.MapLayer;
-import org.meteoinfo.layer.RasterLayer;
-import org.meteoinfo.layer.VectorLayer;
-import org.meteoinfo.map.FrmIdentifer;
-import org.meteoinfo.map.FrmIdentiferGrid;
-import org.meteoinfo.map.MapView;
-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;
-
-/**
- *
- * @author yaqiang
- */
-public class ChartPanel extends JPanel implements IChartPanel{
-
- //
- private final EventListenerList listeners = new EventListenerList();
- private BufferedImage mapBitmap = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
- private BufferedImage tempImage = null;
- private boolean newPaint = false;
- private boolean doubleBuffer = true;
- private Chart chart;
- private Plot currentPlot;
- private Dimension chartSize;
- private Point mouseDownPoint = new Point(0, 0);
- private Point mouseLastPos = new Point(0, 0);
- private boolean dragMode = false;
- private JPopupMenu popupMenu;
- private MouseMode mouseMode;
- private List selectedPoints;
- private int xShift = 0;
- private int yShift = 0;
- private double paintScale = 1.0;
- private LocalDateTime lastMouseWheelTime;
- private Timer mouseWheelDetctionTimer;
- //
-
- //
- /**
- * Constructor
- */
- public ChartPanel() {
- super();
- //this.setBackground(Color.white);
- this.setBackground(Color.lightGray);
- this.setSize(200, 200);
- this.addComponentListener(new ComponentAdapter() {
- @Override
- public void componentResized(ComponentEvent e) {
- onComponentResized(e);
- }
- });
- this.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- onMouseClicked(e);
- }
-
- @Override
- public void mousePressed(MouseEvent e) {
- onMousePressed(e);
- }
-
- @Override
- public void mouseReleased(MouseEvent e) {
- onMouseReleased(e);
- }
- });
- this.addMouseMotionListener(new MouseMotionAdapter() {
- @Override
- public void mouseMoved(MouseEvent e) {
- onMouseMoved(e);
- }
-
- @Override
- public void mouseDragged(MouseEvent e) {
- onMouseDragged(e);
- }
- });
- this.addMouseWheelListener(new MouseWheelListener() {
- @Override
- public void mouseWheelMoved(MouseWheelEvent e) {
- onMouseWheelMoved(e);
- }
- });
-
- this.mouseWheelDetctionTimer = new Timer(100, new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- LocalDateTime now = LocalDateTime.now();
- if (Duration.between(lastMouseWheelTime, now).toMillis() > 200) {
- xShift = 0;
- yShift = 0;
- paintScale = 1.0;
- //paintGraphics();
- repaintNew();
- mouseWheelDetctionTimer.stop();
- }
- }
- });
-
- popupMenu = new JPopupMenu();
- JMenuItem undoZoom = new JMenuItem("Undo zoom");
- undoZoom.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- onUndoZoomClick();
- }
- });
- popupMenu.add(undoZoom);
- popupMenu.addSeparator();
-
- JMenuItem saveFigure = new JMenuItem("Save figure");
- saveFigure.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- onSaveFigureClick(e);
- }
- });
- popupMenu.add(saveFigure);
-
- this.chart = null;
- this.mouseMode = MouseMode.DEFAULT;
- //this.setMouseMode(mouseMode.ZOOM_IN);
- }
-
- /**
- * Constructor
- *
- * @param chart Chart
- */
- public ChartPanel(Chart chart) {
- this();
- this.chart = chart;
- if (this.chart != null) {
- this.chart.setParent(this);
- }
- }
-
- /**
- * Constructor
- *
- * @param chart Chart
- * @param width Chart width
- * @param height Chart height
- */
- public ChartPanel(Chart chart, int width, int height) {
- this(chart);
- this.chartSize = new Dimension(width, height);
- this.setPreferredSize(chartSize);
- }
-
- //
- //
- /**
- * Get chart
- *
- * @return Chart
- */
- public Chart getChart() {
- return chart;
- }
-
- /**
- * Set chart
- *
- * @param value
- */
- public void setChart(Chart value) {
- chart = value;
- if (this.chart != null) {
- chart.setParent(this);
- }
- }
-
- /**
- * Get if using off screen image double buffering.
- * Using double buffering will be faster but lower view quality in
- * high dpi screen computer.
- *
- * @return Boolean
- */
- public boolean isDoubleBuffer() {
- return this.doubleBuffer;
- }
-
- /**
- * Set using off screen image double buffering or not.
- * @param value Boolean
- */
- public void setDoubleBuffer(boolean value) {
- this.doubleBuffer = value;
- }
-
- /**
- * Get popup menu
- *
- * @return Popup menu
- */
- public JPopupMenu getPopupMenu() {
- return this.popupMenu;
- }
-
- /**
- * Get mouse mode
- *
- * @return Mouse mode
- */
- public MouseMode getMouseMode() {
- return this.mouseMode;
- }
-
- /**
- * Set mouse mode
- *
- * @param value Mouse mode
- */
- @Override
- public void setMouseMode(MouseMode value) {
- this.mouseMode = value;
- Image image;
- Toolkit toolkit = Toolkit.getDefaultToolkit();
- Cursor customCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
- switch (this.mouseMode) {
- case SELECT:
- customCursor = Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
- break;
- case ZOOM_IN:
- image = toolkit.getImage(this.getClass().getResource("/images/zoom_in_32x32x32.png"));
- customCursor = toolkit.createCustomCursor(image, new Point(8, 8), "Zoom In");
- break;
- case ZOOM_OUT:
- image = toolkit.getImage(this.getClass().getResource("/images/zoom_out_32x32x32.png"));
- customCursor = toolkit.createCustomCursor(image, new Point(8, 8), "Zoom In");
- break;
- case PAN:
- image = toolkit.getImage(this.getClass().getResource("/images/Pan_Open_32x32x32.png"));
- customCursor = toolkit.createCustomCursor(image, new Point(8, 8), "Pan");
- break;
- case IDENTIFER:
- image = toolkit.getImage(this.getClass().getResource("/images/identifer_32x32x32.png"));
- customCursor = toolkit.createCustomCursor(image, new Point(8, 8), "Identifer");
- break;
- case ROTATE:
- image = toolkit.getImage(this.getClass().getResource("/images/rotate.png"));
- customCursor = toolkit.createCustomCursor(image, new Point(8, 8), "Identifer");
- break;
- }
- this.setCursor(customCursor);
- }
-
- /**
- * Get selected chart points
- *
- * @return Selected chart points
- */
- public List getSelectedPoints() {
- return this.selectedPoints;
- }
- //
-
- //
- public void addPointSelectedListener(IPointSelectedListener listener) {
- this.listeners.add(IPointSelectedListener.class, listener);
- }
-
- public void removePointSelectedListener(IPointSelectedListener listener) {
- this.listeners.remove(IPointSelectedListener.class, listener);
- }
-
- public void firePointSelectedEvent() {
- firePointSelectedEvent(new PointSelectedEvent(this));
- }
-
- private void firePointSelectedEvent(PointSelectedEvent event) {
- Object[] listeners = this.listeners.getListenerList();
- for (int i = 0; i < listeners.length; i = i + 2) {
- if (listeners[i] == IPointSelectedListener.class) {
- ((IPointSelectedListener) listeners[i + 1]).pointSelectedEvent(event);
- }
- }
- }
- //
-
- //
- /**
- * Get figure width
- *
- * @return Figure width
- */
- public int getFigureWidth() {
- int width;
- if (this.chartSize != null) {
- width = this.chartSize.width;
- } else {
- width = this.getWidth();
- }
-
- return width;
- }
-
- /**
- * Get Figure height
- *
- * @return Figure height
- */
- public int getFigureHeight() {
- int height;
- if (this.chartSize != null) {
- height = this.chartSize.height;
- } else {
- height = this.getHeight();
- }
-
- return height;
- }
-
- /**
- * Select a plot by point
- *
- * @param x X
- * @param y Y
- * @return Selected plot
- */
- public Plot selPlot(int x, int y) {
- if (this.chart == null) {
- return null;
- }
-
- int n = this.chart.getPlots().size();
- for (int i = n - 1; i >= 0; i--) {
- Plot plot = this.chart.getPlots().get(i);
- Rectangle2D rect = plot.getGraphArea();
- if (rect.contains(x, y)) {
- return plot;
- }
- }
- return null;
- }
-
- /**
- * Paint component
- *
- * @param g Graphics
- */
- @Override
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
-
- if (this.getWidth() < 5 || this.getHeight() < 5) {
- return;
- }
-
- //this.setBackground(Color.white);
- Graphics2D g2 = (Graphics2D) g;
-
- if (this.newPaint) {
- this.paintGraphics(g2);
- } else {
- AffineTransform mx = new AffineTransform();
- AffineTransformOp aop = new AffineTransformOp(mx, AffineTransformOp.TYPE_BICUBIC);
- g2.drawImage(mapBitmap, aop, 0, 0);
- }
-
- //Draw dynamic graphics
- if (this.dragMode) {
- switch (this.mouseMode) {
- case ZOOM_IN:
- case SELECT:
- int aWidth = Math.abs(mouseLastPos.x - mouseDownPoint.x);
- int aHeight = Math.abs(mouseLastPos.y - mouseDownPoint.y);
- int aX = Math.min(mouseLastPos.x, mouseDownPoint.x);
- int aY = Math.min(mouseLastPos.y, mouseDownPoint.y);
- g2.setColor(this.getForeground());
- float dash1[] = {2.0f};
- g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f));
- g2.draw(new Rectangle(aX, aY, aWidth, aHeight));
- break;
- }
- }
-
- //Draw identifer shape
- if (this.currentPlot != null) {
- if (this.currentPlot instanceof MapPlot) {
- MapPlot plot = (MapPlot) this.currentPlot;
- if (plot.getMapView().isDrawIdentiferShape()) {
- if (plot.getSelectedLayer() != null) {
- if (plot.getSelectedLayer().getLayerType() == LayerTypes.VectorLayer) {
- VectorLayer layer = (VectorLayer) plot.getSelectedLayer();
- Rectangle2D rect = plot.getGraphArea();
- Rectangle rr = new Rectangle((int) rect.getX(), (int) rect.getY(),
- (int) rect.getWidth(), (int) rect.getHeight());
- plot.getMapView().drawIdShape(g2, layer.getShapes().get(layer.getIdentiferShape()), rr);
- }
- }
- }
- }
- }
-
- g2.dispose();
- }
-
- /**
- * New paint
- */
- public void repaintNew() {
- if (this.doubleBuffer) {
- this.paintGraphics();
- } else {
- this.newPaint = true;
- this.repaint();
- this.updateViewImage();
- }
- }
-
- private void repaintOld() {
- if (this.doubleBuffer) {
- this.repaint();
- } else {
- this.newPaint = false;
- this.repaint();
- }
- }
-
- private void updateViewImage() {
- if (this.getWidth() < 5 || this.getHeight() < 5) {
- return;
- }
-
- int width, height;
- if (this.chartSize != null) {
- height = this.chartSize.height;
- width = this.chartSize.width;
- } else {
- width = this.getWidth();
- height = this.getHeight();
- }
-
- this.mapBitmap = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = this.mapBitmap.createGraphics();
- this.print(g);
- g.dispose();
- }
-
- /**
- * Paint graphics
- */
- @Override
- public void paintGraphics() {
- if (this.getWidth() < 5 || this.getHeight() < 5) {
- return;
- }
-
- int width, height;
- if (this.chartSize != null) {
- height = this.chartSize.height;
- width = this.chartSize.width;
- } else {
- width = this.getWidth();
- height = this.getHeight();
- }
-
- this.mapBitmap = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
-
- if (this.chart != null) {
- Graphics2D g = this.mapBitmap.createGraphics();
- Rectangle2D chartArea;
- if (this.chartSize == null) {
- chartArea = new Rectangle2D.Double(0.0, 0.0, this.mapBitmap.getWidth(), this.mapBitmap.getHeight());
- } else {
- chartArea = new Rectangle2D.Double(0.0, 0.0, this.chartSize.width, this.chartSize.height);
- }
- this.chart.draw(g, chartArea);
- }
- this.repaint();
- }
-
- public void paintGraphics(Graphics2D g) {
- if (this.chart != null) {
- Rectangle2D chartArea;
- if (this.chartSize == null) {
- chartArea = new Rectangle2D.Double(0.0, 0.0, this.getWidth(), this.getHeight());
- } else {
- chartArea = new Rectangle2D.Double(0.0, 0.0, this.chartSize.width, this.chartSize.height);
- }
- this.chart.draw(g, chartArea);
- }
- }
-
- public void paintGraphics(Graphics2D g, int width, int height) {
- if (this.chart != null) {
- Rectangle2D chartArea;
- chartArea = new Rectangle2D.Double(0.0, 0.0, width, height);
- this.chart.draw(g, chartArea);
- }
- }
-
- void onComponentResized(ComponentEvent e) {
- if (this.getWidth() > 0 && this.getHeight() > 0) {
- if (this.chart != null) {
- //this.paintGraphics();
- this.repaintNew();
- }
- }
- }
-
- void onMousePressed(MouseEvent e) {
- mouseDownPoint.x = e.getX();
- mouseDownPoint.y = e.getY();
- mouseLastPos = (Point) mouseDownPoint.clone();
- switch (this.mouseMode) {
- case PAN:
- Plot plot = selPlot(e.getX(), e.getY());
- if (plot != null) {
- Rectangle2D mapRect = plot.getGraphArea();
- tempImage = new BufferedImage((int) mapRect.getWidth() - 2,
- (int) mapRect.getHeight() - 2, BufferedImage.TYPE_INT_ARGB);
- Graphics2D tg = tempImage.createGraphics();
- tg.setColor(Color.white);
- tg.fill(mapRect);
- tg.drawImage(this.mapBitmap, -(int) mapRect.getX() - 1, -(int) mapRect.getY() - 1, this);
- tg.dispose();
- }
- break;
- }
- }
-
- void onMouseMoved(MouseEvent e) {
- this.dragMode = false;
-// switch (this.mouseMode) {
-// case PAN:
-// Plot plot = selPlot(e.getX(), e.getY());
-// if (plot != null) {
-// Rectangle2D mapRect = plot.getGraphArea();
-// tempImage = new BufferedImage((int) mapRect.getWidth() - 2,
-// (int) mapRect.getHeight() - 2, BufferedImage.TYPE_INT_ARGB);
-// Graphics2D tg = tempImage.createGraphics();
-// tg.setColor(Color.white);
-// tg.fill(mapRect);
-// tg.drawImage(this.mapBitmap, -(int) mapRect.getX() - 1, -(int) mapRect.getY() - 1, this);
-// tg.dispose();
-// }
-// break;
-// }
- }
-
- void onMouseReleased(MouseEvent e) {
- this.dragMode = false;
- Plot plt = this.chart.findPlot(mouseDownPoint.x, mouseDownPoint.y);
- if (!(plt instanceof AbstractPlot2D)) {
- return;
- }
-
- AbstractPlot2D xyplot = (AbstractPlot2D) plt;
- this.currentPlot = xyplot;
- switch (this.mouseMode) {
- case ZOOM_IN:
- if (Math.abs(mouseLastPos.x - mouseDownPoint.x) > 5) {
- if (xyplot instanceof MapPlot) {
- MapPlot plot = (MapPlot) xyplot;
- Rectangle2D graphArea = xyplot.getGraphArea();
- double[] xy1 = plot.screenToProj(mouseDownPoint.x - graphArea.getX(), mouseDownPoint.y - graphArea.getY(), graphArea);
- double[] xy2 = plot.screenToProj(mouseLastPos.x - graphArea.getX(), mouseLastPos.y - graphArea.getY(), graphArea);
- Extent extent = new Extent();
- extent.minX = Math.min(xy1[0], xy2[0]);
- extent.maxX = Math.max(xy1[0], xy2[0]);
- extent.minY = Math.min(xy1[1], xy2[1]);
- extent.maxY = Math.max(xy1[1], xy2[1]);
- plot.setDrawExtent(extent);
- //this.paintGraphics();
- this.repaintNew();
- } else {
- Rectangle2D graphArea = xyplot.getGraphArea();
- double[] xy1 = xyplot.screenToProj(mouseDownPoint.x - graphArea.getX(), mouseDownPoint.y - graphArea.getY(), graphArea);
- double[] xy2 = xyplot.screenToProj(mouseLastPos.x - graphArea.getX(), mouseLastPos.y - graphArea.getY(), graphArea);
- Extent extent = new Extent();
- extent.minX = Math.min(xy1[0], xy2[0]);
- extent.maxX = Math.max(xy1[0], xy2[0]);
- extent.minY = Math.min(xy1[1], xy2[1]);
- extent.maxY = Math.max(xy1[1], xy2[1]);
- if (xyplot.getXAxis().isInverse()) {
- Extent drawExtent = xyplot.getDrawExtent();
- double minx, maxx;
- minx = drawExtent.getWidth() - (extent.maxX - drawExtent.minX) + drawExtent.minX;
- maxx = drawExtent.getWidth() - (extent.minX - drawExtent.minX) + drawExtent.minX;
- extent.minX = minx;
- extent.maxX = maxx;
- }
- if (xyplot.getYAxis().isInverse()) {
- Extent drawExtent = xyplot.getDrawExtent();
- double miny, maxy;
- miny = drawExtent.getHeight() - (extent.maxY - drawExtent.minY) + drawExtent.minY;
- maxy = drawExtent.getHeight() - (extent.minY - drawExtent.minY) + drawExtent.minY;
- extent.minY = miny;
- extent.maxY = maxy;
- }
- xyplot.setDrawExtent(extent);
- //this.paintGraphics();
- this.repaintNew();
- }
- }
- break;
- case ZOOM_OUT:
- if (e.getButton() == MouseEvent.BUTTON1) {
- double zoom = 1.5;
- Extent extent = xyplot.getDrawExtent();
- double owidth = extent.getWidth();
- double oheight = extent.getHeight();
- double width = owidth * zoom;
- double height = oheight * zoom;
- double xshift = (owidth - width) * 0.5;
- double yshift = (oheight - height) * 0.5;
- extent.minX += xshift;
- extent.maxX -= xshift;
- extent.minY += yshift;
- extent.maxY -= yshift;
- xyplot.setDrawExtent(extent);
- //this.paintGraphics();
- this.repaintNew();
- }
- break;
- case SELECT:
- if (Math.abs(mouseLastPos.x - mouseDownPoint.x) > 5) {
- if (xyplot instanceof XY1DPlot) {
- XY1DPlot plot = (XY1DPlot) xyplot;
- Rectangle2D graphArea = plot.getGraphArea();
- if (graphArea.contains(mouseDownPoint.x, mouseDownPoint.y) || graphArea.contains(mouseLastPos.x, mouseLastPos.y)) {
- double[] xy1 = plot.screenToProj(mouseDownPoint.x - graphArea.getX(), mouseDownPoint.y - graphArea.getY(), graphArea);
- double[] xy2 = plot.screenToProj(mouseLastPos.x - graphArea.getX(), mouseLastPos.y - graphArea.getY(), graphArea);
- Extent extent = new Extent();
- extent.minX = Math.min(xy1[0], xy2[0]);
- extent.maxX = Math.max(xy1[0], xy2[0]);
- extent.minY = Math.min(xy1[1], xy2[1]);
- extent.maxY = Math.max(xy1[1], xy2[1]);
- this.selectedPoints = plot.getDataset().selectPoints(extent);
- this.firePointSelectedEvent();
- //this.paintGraphics();
- this.repaintNew();
- }
- }
- }
- break;
- case PAN:
- if (e.getButton() == MouseEvent.BUTTON1) {
- int deltaX = e.getX() - mouseDownPoint.x;
- int deltaY = e.getY() - mouseDownPoint.y;
- double minX = -deltaX;
- double minY = -deltaY;
- double maxX = xyplot.getGraphArea().getWidth() - deltaX;
- double maxY = xyplot.getGraphArea().getHeight() - deltaY;
- xyplot.zoomToExtentScreen(minX, maxX, minY, maxY);
- //this.paintGraphics();
- this.repaintNew();
- }
- break;
- }
- }
-
- void onMouseDragged(MouseEvent e) {
- this.dragMode = true;
- int x = e.getX();
- int y = e.getY();
- switch (this.mouseMode) {
- case ZOOM_IN:
- case SELECT:
- this.repaintOld();
- break;
- case PAN:
- Plot plot = selPlot(e.getX(), e.getY());
- if (plot != null) {
- Graphics2D g = (Graphics2D) this.getGraphics();
- Rectangle2D mapRect = plot.getGraphArea();
- g.setClip(mapRect);
- g.setColor(Color.white);
- int aX = e.getX() - mouseDownPoint.x;
- int aY = e.getY() - mouseDownPoint.y;
- if (aX > 0) {
- if (mapRect.getX() >= 0) {
- g.fillRect((int) mapRect.getX(), (int) mapRect.getY(), aX, (int) mapRect.getHeight());
- } else {
- g.fillRect(0, (int) mapRect.getY(), aX, (int) mapRect.getHeight());
- }
- } else if (mapRect.getX() <= this.getWidth()) {
- g.fillRect((int) (mapRect.getX() + mapRect.getWidth() + aX), (int) mapRect.getY(), Math.abs(aX), (int) mapRect.getHeight());
- } else {
- g.fillRect(this.getWidth() + aX, (int) mapRect.getY(), Math.abs(aX), (int) mapRect.getHeight());
- }
- if (aY > 0) {
- if (mapRect.getY() >= 0) {
- g.fillRect((int) mapRect.getX(), (int) mapRect.getY(), (int) mapRect.getWidth(), aY);
- } else {
- g.fillRect((int) mapRect.getX(), 0, (int) mapRect.getWidth(), aY);
- }
- } else if (mapRect.getY() + mapRect.getHeight() <= this.getX() + this.getHeight()) {
- g.fillRect((int) mapRect.getX(), (int) mapRect.getY() + (int) mapRect.getHeight() + aY, (int) mapRect.getWidth(), Math.abs(aY));
- } else {
- g.fillRect((int) mapRect.getX(), this.getY() + this.getHeight() + aY, (int) mapRect.getWidth(), Math.abs(aY));
- }
- int startX = (int) mapRect.getX() + aX;
- int startY = (int) mapRect.getY() + aY;
- g.drawImage(tempImage, startX, startY, this);
- g.setColor(this.getForeground());
- g.draw(mapRect);
- }
- break;
- case ROTATE:
- plot = selPlot(this.mouseDownPoint.x, this.mouseDownPoint.y);
- if (plot != null && plot.getPlotType() == PlotType.XYZ) {
- Plot3D plot3d = (Plot3D) plot;
- Projector projector = plot3d.getProjector();
- float new_value = 0.0f;
- // if (!thread.isAlive() || !data_available) {
- if (e.isControlDown()) {
- projector.set2D_xTranslation(projector.get2D_xTranslation() + (x - this.mouseLastPos.x));
- projector.set2D_yTranslation(projector.get2D_yTranslation() + (y - this.mouseLastPos.y));
- } else if (e.isShiftDown()) {
- new_value = projector.getY2DScaling() + (y - this.mouseLastPos.y) * 0.5f;
- if (new_value > 60.0f) {
- new_value = 60.0f;
- }
- if (new_value < 2.0f) {
- new_value = 2.0f;
- }
- projector.set2DScaling(new_value);
- } else {
- new_value = projector.getRotationAngle() + (x - this.mouseLastPos.x);
- while (new_value > 360) {
- new_value -= 360;
- }
- while (new_value < 0) {
- new_value += 360;
- }
- projector.setRotationAngle(new_value);
- new_value = projector.getElevationAngle() + (y - this.mouseLastPos.y);
- if (new_value > 90) {
- new_value = 90;
- } else if (new_value < 0) {
- new_value = 0;
- }
- projector.setElevationAngle(new_value);
- }
- this.repaintNew();
- //this.paintGraphics();
-// if (!model.isExpectDelay()) {
-// repaint();
-// } else {
-// if (!dragged) {
-// is_data_available = data_available;
-// dragged = true;
-// }
-// data_available = false;
-// repaint();
-// }
- }
- break;
- }
- mouseLastPos.x = x;
- mouseLastPos.y = y;
- }
-
- void onMouseClicked(MouseEvent e) {
- int clickTimes = e.getClickCount();
- if (clickTimes == 1) {
- if (e.getButton() == MouseEvent.BUTTON1) {
- switch (this.mouseMode) {
- case IDENTIFER:
- Plot plot = selPlot(e.getX(), e.getY());
- if (plot == null) {
- return;
- }
-
- if (!(plot instanceof MapPlot)) {
- return;
- }
-
- this.currentPlot = plot;
- MapPlot mplot = (MapPlot) plot;
- final MapView mapView = mplot.getMapView();
- MapLayer aMLayer = mplot.getSelectedLayer();
- if (aMLayer == null) {
- return;
- }
- if (aMLayer.getLayerType() == LayerTypes.ImageLayer) {
- return;
- }
-
- Rectangle2D rect = mplot.getGraphArea();
- PointF aPoint = new PointF(e.getX() - (float) rect.getX(), e.getY() - (float) rect.getY());
- if (aMLayer.getLayerType() == LayerTypes.VectorLayer) {
- VectorLayer aLayer = (VectorLayer) aMLayer;
- List selectedShapes = mapView.selectShapes(aLayer, aPoint, true, false);
- if (selectedShapes.size() > 0) {
- if (mapView.frmIdentifer == null) {
- mapView.frmIdentifer = new FrmIdentifer((JFrame) SwingUtilities.getWindowAncestor(this), false, mapView);
- mapView.frmIdentifer.addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosed(WindowEvent e) {
- mapView.setDrawIdentiferShape(false);
- ChartPanel.this.repaintOld();
- }
- });
- }
- String[] colNames = {"Field", "Value"};
- String fieldStr, valueStr;
- int shapeIdx = selectedShapes.get(0);
- aLayer.setIdentiferShape(shapeIdx);
- mapView._drawIdentiferShape = true;
-
- Object[][] tData = new Object[aLayer.getFieldNumber() + 1][2];
- fieldStr = "Index";
- valueStr = String.valueOf(shapeIdx);
- tData[0][0] = fieldStr;
- tData[0][1] = valueStr;
- Object value;
- if (aLayer.getShapeNum() > 0) {
- for (int i = 0; i < aLayer.getFieldNumber(); i++) {
- Field field = aLayer.getField(i);
- fieldStr = field.getColumnName();
- value = aLayer.getCellValue(i, shapeIdx);
- if (value == null) {
- valueStr = "";
- } else if (field.getDataType() == DataType.DATE) {
- DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd");
- valueStr = format.format((LocalDateTime) value);
- } else {
- valueStr = value.toString();
- }
- tData[i + 1][0] = fieldStr;
- tData[i + 1][1] = valueStr;
- }
- }
- DefaultTableModel dtm = new javax.swing.table.DefaultTableModel(tData, colNames) {
- @Override
- public boolean isCellEditable(int row, int column) {
- return false;
- }
- };
- mapView.frmIdentifer.getTable().setModel(dtm);
- mapView.frmIdentifer.repaint();
- if (!mapView.frmIdentifer.isVisible()) {
- //this._frmIdentifer.setLocation(e.getX(), e.getY());
- mapView.frmIdentifer.setLocationRelativeTo(this);
- mapView.frmIdentifer.setVisible(true);
- }
-
- mapView.setDrawIdentiferShape(true);
- this.repaintOld();
- }
- } else if (aMLayer.getLayerType() == LayerTypes.RasterLayer) {
- RasterLayer aRLayer = (RasterLayer) aMLayer;
- int[] ijIdx = mapView.selectGridCell(aRLayer, aPoint);
- if (ijIdx != null) {
- int iIdx = ijIdx[0];
- int jIdx = ijIdx[1];
- double aValue = aRLayer.getCellValue(iIdx, jIdx);
- if (mapView._frmIdentiferGrid == null) {
- mapView._frmIdentiferGrid = new FrmIdentiferGrid((JFrame) SwingUtilities.getWindowAncestor(this), false);
- }
-
- mapView._frmIdentiferGrid.setIIndex(iIdx);
- mapView._frmIdentiferGrid.setJIndex(jIdx);
- mapView._frmIdentiferGrid.setCellValue(aValue);
- if (!mapView._frmIdentiferGrid.isVisible()) {
- //this._frmIdentiferGrid.setLocation(e.getX(), e.getY());
- mapView._frmIdentiferGrid.setLocationRelativeTo(this);
- mapView._frmIdentiferGrid.setVisible(true);
- }
- }
- }
- break;
- }
- } else if (e.getButton() == MouseEvent.BUTTON3) {
- popupMenu.show(this, e.getX(), e.getY());
- }
- }
- }
-
- void onMouseWheelMoved(MouseWheelEvent e) {
- Plot plt = selPlot(e.getX(), e.getY());
- if (!(plt instanceof AbstractPlot2D)) {
- return;
- }
-
- double minX, maxX, minY, maxY, lonRan, latRan, zoomF;
- double mouseLon, mouseLat;
- Extent drawExtent = ((AbstractPlot2D) plt).getDrawExtent();
- lonRan = drawExtent.maxX - drawExtent.minX;
- latRan = drawExtent.maxY - drawExtent.minY;
- mouseLon = drawExtent.minX + lonRan / 2;
- mouseLat = drawExtent.minY + latRan / 2;
-
- zoomF = 1 + e.getWheelRotation() / 10.0f;
-
- minX = mouseLon - (lonRan / 2 * zoomF);
- maxX = mouseLon + (lonRan / 2 * zoomF);
- minY = mouseLat - (latRan / 2 * zoomF);
- maxY = mouseLat + (latRan / 2 * zoomF);
- switch (this.mouseMode) {
- case PAN:
- if (plt instanceof MapPlot) {
- MapPlot mplt = (MapPlot) plt;
- Graphics2D g = (Graphics2D) this.getGraphics();
- Rectangle2D mapRect = mplt.getGraphArea();
-
- this.lastMouseWheelTime = LocalDateTime.now();
- if (!this.mouseWheelDetctionTimer.isRunning()) {
- this.mouseWheelDetctionTimer.start();
- tempImage = new BufferedImage((int) mapRect.getWidth() - 2,
- (int) mapRect.getHeight() - 2, BufferedImage.TYPE_INT_ARGB);
- Graphics2D tg = tempImage.createGraphics();
- tg.setColor(Color.white);
- tg.fill(mapRect);
- tg.drawImage(this.mapBitmap, -(int) mapRect.getX() - 1, -(int) mapRect.getY() - 1, this);
- tg.dispose();
- }
-
- g.setClip(mapRect);
- g.setColor(Color.white);
- //g.clearRect((int)mapRect.getX(), (int)mapRect.getY(), (int)mapRect.getWidth(), (int)mapRect.getHeight());
- paintScale = paintScale / zoomF;
- float nWidth = (float)mapRect.getWidth() * (float) paintScale;
- float nHeight = (float)mapRect.getHeight() * (float) paintScale;
- float nx = ((float)mapRect.getWidth() - nWidth) / 2;
- float ny = ((float)mapRect.getHeight() - nHeight) / 2;
- if (nx > 0) {
- g.fillRect((int) mapRect.getX(), (int) mapRect.getY(), (int)nx, (int) mapRect.getHeight());
- g.fillRect((int) (mapRect.getMaxX() - nx), (int) mapRect.getY(), (int)nx, (int) mapRect.getHeight());
- }
- if (ny > 0) {
- g.fillRect((int) mapRect.getX(), (int) mapRect.getY(), (int) mapRect.getWidth(), (int)ny);
- g.fillRect((int) mapRect.getX(), (int) (mapRect.getMaxY() - ny), (int) mapRect.getWidth(), (int)ny);
- }
- g.drawImage(tempImage, (int)(mapRect.getX() + nx), (int)(mapRect.getY() + ny),
- (int)nWidth, (int)nHeight, null);
- g.setColor(this.getForeground());
- g.draw(mapRect);
- mplt.setDrawExtent(new Extent(minX, maxX, minY, maxY));
- } else {
- ((AbstractPlot2D) plt).setDrawExtent(new Extent(minX, maxX, minY, maxY));
- //this.paintGraphics();
- this.repaintNew();
- }
- break;
- }
- }
-
- /**
- * Zoom back to full extent
- */
- @Override
- public void onUndoZoomClick() {
- AbstractPlot2D xyplot;
- if (this.currentPlot == null) {
- xyplot = (AbstractPlot2D) this.chart.getPlots().get(0);
- } else {
- xyplot = (AbstractPlot2D) this.currentPlot;
- }
- xyplot.setDrawExtent((Extent) xyplot.getExtent().clone());
-// if (xyplot instanceof MapPlot) {
-// MapPlot plot = (MapPlot) xyplot;
-// plot.setDrawExtent(plot.getMapView().getLastAddedLayer().getExtent());
-// } else {
-// xyplot.setAutoExtent();
-// }
- //this.paintGraphics();
- this.repaintNew();
- }
-
- private void onSaveFigureClick(ActionEvent e) {
- String path = System.getProperty("user.dir");
- File pathDir = new File(path);
- JFileChooser aDlg = new JFileChooser();
- aDlg.setCurrentDirectory(pathDir);
- String[] fileExts = new String[]{"png"};
- GenericFileFilter pngFileFilter = new GenericFileFilter(fileExts, "Png Image (*.png)");
- aDlg.addChoosableFileFilter(pngFileFilter);
- fileExts = new String[]{"gif"};
- GenericFileFilter mapFileFilter = new GenericFileFilter(fileExts, "Gif Image (*.gif)");
- aDlg.addChoosableFileFilter(mapFileFilter);
- fileExts = new String[]{"jpg"};
- mapFileFilter = new GenericFileFilter(fileExts, "Jpeg Image (*.jpg)");
- aDlg.addChoosableFileFilter(mapFileFilter);
- fileExts = new String[]{"eps"};
- mapFileFilter = new GenericFileFilter(fileExts, "EPS file (*.eps)");
- aDlg.addChoosableFileFilter(mapFileFilter);
- fileExts = new String[]{"pdf"};
- mapFileFilter = new GenericFileFilter(fileExts, "PDF file (*.pdf)");
- aDlg.addChoosableFileFilter(mapFileFilter);
- fileExts = new String[]{"emf"};
- mapFileFilter = new GenericFileFilter(fileExts, "EMF file (*.emf)");
- aDlg.addChoosableFileFilter(mapFileFilter);
- aDlg.setFileFilter(pngFileFilter);
- aDlg.setAcceptAllFileFilterUsed(false);
- if (JFileChooser.APPROVE_OPTION == aDlg.showSaveDialog(this)) {
- File aFile = aDlg.getSelectedFile();
- System.setProperty("user.dir", aFile.getParent());
- String extent = ((GenericFileFilter) aDlg.getFileFilter()).getFileExtent();
- String fileName = aFile.getAbsolutePath();
- if (!fileName.substring(fileName.length() - extent.length()).equals(extent)) {
- fileName = fileName + "." + extent;
- }
- if (new File(fileName).exists()) {
- int overwrite = JOptionPane.showConfirmDialog(this, "File exists! Overwrite it?");
- if (overwrite == JOptionPane.YES_OPTION) {
- this.saveImage(fileName);
- }
- } else {
- this.saveImage(fileName);
- }
- }
- }
-
- /**
- * Save image to a picture file
- *
- * @param aFile File path
- */
- @Override
- public void saveImage(String aFile) {
- try {
- saveImage(aFile, null);
- } catch (PrintException | IOException | InterruptedException ex) {
- Logger.getLogger(ChartPanel.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
-
- /**
- * Save image to a picture file
- *
- * @param aFile File path
- * @param sleep Sleep seconds for web map layer
- * @throws java.io.FileNotFoundException
- * @throws javax.print.PrintException
- * @throws java.lang.InterruptedException
- */
- public void saveImage(String aFile, Integer sleep) throws FileNotFoundException, PrintException, IOException, InterruptedException {
- int w, h;
- if (this.chartSize == null) {
- w = this.getWidth();
- h = this.getHeight();
- } else {
- w = this.chartSize.width;
- h = this.chartSize.height;
- }
- this.saveImage(aFile, w, h, sleep);
- }
-
- /**
- * Save image to a picture file
- *
- * @param aFile File path
- * @param width Width
- * @param height Height
- * @param sleep Sleep seconds for web map layer
- * @throws java.io.FileNotFoundException
- * @throws javax.print.PrintException
- * @throws java.lang.InterruptedException
- */
- public void saveImage(String aFile, int width, int height, Integer sleep) throws FileNotFoundException, PrintException, IOException, InterruptedException {
- if (aFile.endsWith(".ps")) {
- DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
- String mimeType = "application/postscript";
- StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, mimeType);
- FileOutputStream out = new FileOutputStream(aFile);
- if (factories.length > 0) {
- PrintService service = factories[0].getPrintService(out);
- SimpleDoc doc = new SimpleDoc(new Printable() {
- @Override
- public int print(Graphics g, PageFormat pf, int page) {
- if (page >= 1) {
- return Printable.NO_SUCH_PAGE;
- } else {
- double sf1 = pf.getImageableWidth() / (getWidth() + 1);
- double sf2 = pf.getImageableHeight() / (getHeight() + 1);
- double s = Math.min(sf1, sf2);
- Graphics2D g2 = (Graphics2D) g;
- g2.translate((pf.getWidth() - pf.getImageableWidth()) / 2, (pf.getHeight() - pf.getImageableHeight()) / 2);
- g2.scale(s, s);
-
- paintGraphics(g2);
- return Printable.PAGE_EXISTS;
- }
- }
- }, flavor, null);
- DocPrintJob job = service.createPrintJob();
- PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
- job.print(doc, attributes);
- out.close();
- }
- } else if (aFile.endsWith(".eps")) {
- Properties p = new Properties();
- p.setProperty("PageSize", "A5");
- VectorGraphics g = new PSGraphics2D(new File(aFile), new Dimension(width, height));
- //g.setProperties(p);
- g.startExport();
- //this.paintGraphics(g);
- this.paintGraphics(g, width, height);
- g.endExport();
- g.dispose();
- } else if (aFile.endsWith(".pdf")) {
- try {
- Document document = new Document(new com.itextpdf.text.Rectangle(width, height));
- PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(aFile));
- document.open();
- PdfContentByte cb = writer.getDirectContent();
- PdfTemplate pdfTemp = cb.createTemplate(width, height);
- Graphics2D g2 = new PdfGraphics2D(pdfTemp, width, height, true);
- this.paintGraphics(g2, width, height);
- g2.dispose();
- cb.addTemplate(pdfTemp, 0, 0);
- document.close();
- } catch (DocumentException | FileNotFoundException e) {
- e.printStackTrace();
- }
- } else if (aFile.endsWith(".emf")) {
- VectorGraphics g = new EMFGraphics2D(new File(aFile), new Dimension(width, height));
- //g.setProperties(p);
- g.startExport();
- //this.paintGraphics(g);
- this.paintGraphics(g, width, height);
- g.endExport();
- g.dispose();
- } else {
- //String extension = aFile.substring(aFile.lastIndexOf('.') + 1);
- //ImageIO.write(this.mapBitmap, extension, new File(aFile));
-
- String extension = aFile.substring(aFile.lastIndexOf('.') + 1);
- BufferedImage aImage;
- if (extension.equalsIgnoreCase("bmp")) {
- aImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
- } else {
- aImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- }
- Graphics2D g = aImage.createGraphics();
- paintGraphics(g, width, height);
-
- if (sleep != null) {
- Thread.sleep(sleep * 1000);
- }
-
- if (extension.equalsIgnoreCase("jpg")) {
- BufferedImage newImage = new BufferedImage(aImage.getWidth(), aImage.getHeight(), BufferedImage.TYPE_INT_RGB);
- newImage.createGraphics().drawImage(aImage, 0, 0, Color.BLACK, null);
- ImageIO.write(newImage, extension, new File(aFile));
- } else {
- ImageIO.write(aImage, extension, new File(aFile));
- }
- }
- }
-
- /**
- * Save image to a picture file
- *
- * @param aFile File path
- * @param width Width
- * @param height Height
- * @param sleep Sleep seconds for web map layer
- * @throws java.io.FileNotFoundException
- * @throws javax.print.PrintException
- * @throws java.lang.InterruptedException
- */
- public void saveImage_bak(String aFile, int width, int height, Integer sleep) throws FileNotFoundException, PrintException, IOException, InterruptedException {
- if (aFile.endsWith(".ps")) {
- DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
- String mimeType = "application/postscript";
- StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, mimeType);
- FileOutputStream out = new FileOutputStream(aFile);
- if (factories.length > 0) {
- PrintService service = factories[0].getPrintService(out);
- SimpleDoc doc = new SimpleDoc(new Printable() {
- @Override
- public int print(Graphics g, PageFormat pf, int page) {
- if (page >= 1) {
- return Printable.NO_SUCH_PAGE;
- } else {
- double sf1 = pf.getImageableWidth() / (getWidth() + 1);
- double sf2 = pf.getImageableHeight() / (getHeight() + 1);
- double s = Math.min(sf1, sf2);
- Graphics2D g2 = (Graphics2D) g;
- g2.translate((pf.getWidth() - pf.getImageableWidth()) / 2, (pf.getHeight() - pf.getImageableHeight()) / 2);
- g2.scale(s, s);
-
- paintGraphics(g2);
- return Printable.PAGE_EXISTS;
- }
- }
- }, flavor, null);
- DocPrintJob job = service.createPrintJob();
- PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
- job.print(doc, attributes);
- out.close();
- }
- } else if (aFile.endsWith(".eps")) {
-// EPSGraphics2D g = new EPSGraphics2D(0.0, 0.0, width, height);
-// paintGraphics(g);
-// FileOutputStream file = new FileOutputStream(aFile);
-// try {
-// file.write(g.getBytes());
-// } finally {
-// file.close();
-// g.dispose();
-// }
-
- Properties p = new Properties();
- p.setProperty("PageSize", "A5");
- VectorGraphics g = new PSGraphics2D(new File(aFile), new Dimension(width, height));
- //g.setProperties(p);
- g.startExport();
- //this.paintGraphics(g);
- this.paintGraphics(g, width, height);
- g.endExport();
- g.dispose();
- } else if (aFile.endsWith(".pdf")) {
- VectorGraphics g = new PDFGraphics2D(new File(aFile), new Dimension(width, height));
- //g.setProperties(p);
- g.startExport();
- this.paintGraphics(g, width, height);
- g.endExport();
- g.dispose();
- } else if (aFile.endsWith(".emf")) {
- VectorGraphics g = new EMFGraphics2D(new File(aFile), new Dimension(width, height));
- //g.setProperties(p);
- g.startExport();
- //this.paintGraphics(g);
- this.paintGraphics(g, width, height);
- g.endExport();
- g.dispose();
- } else {
- //String extension = aFile.substring(aFile.lastIndexOf('.') + 1);
- //ImageIO.write(this.mapBitmap, extension, new File(aFile));
-
- String extension = aFile.substring(aFile.lastIndexOf('.') + 1);
- BufferedImage aImage;
- if (extension.equalsIgnoreCase("bmp")) {
- aImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
- } else {
- aImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- }
- Graphics2D g = aImage.createGraphics();
- paintGraphics(g, width, height);
-
- if (sleep != null) {
- Thread.sleep(sleep * 1000);
- }
-
- if (extension.equalsIgnoreCase("jpg")) {
- BufferedImage newImage = new BufferedImage(aImage.getWidth(), aImage.getHeight(), BufferedImage.TYPE_INT_RGB);
- newImage.createGraphics().drawImage(aImage, 0, 0, Color.BLACK, null);
- ImageIO.write(newImage, extension, new File(aFile));
- } else {
- ImageIO.write(aImage, extension, new File(aFile));
- }
- }
- }
-
- /**
- * Save image to Jpeg file
- *
- * @param fileName File name
- * @param dpi DPI
- * @throws java.io.IOException
- */
- public void saveImage_Jpeg_old(String fileName, int dpi) throws IOException {
- BufferedImage image = this.mapBitmap;
- Iterator i = ImageIO.getImageWritersByFormatName("jpeg");
- //are there any jpeg encoders available?
-
- if (i.hasNext()) //there's at least one ImageWriter, just use the first one
- {
- ImageWriter imageWriter = (ImageWriter) i.next();
- //get the param
- ImageWriteParam param = imageWriter.getDefaultWriteParam();
- ImageTypeSpecifier its = new ImageTypeSpecifier(image.getColorModel(), image.getSampleModel());
-
- //get metadata
- IIOMetadata iomd = imageWriter.getDefaultImageMetadata(its,
- param);
-
- String formatName = "javax_imageio_jpeg_image_1.0";//this is the DOCTYPE of the metadata we need
-
- Node node = iomd.getAsTree(formatName);
- //what are child nodes?
- NodeList nl = node.getChildNodes();
- for (int j = 0; j < nl.getLength(); j++) {
- Node n = nl.item(j);
- System.out.println("node from IOMetadata is : "
- + n.getNodeName());
-
- if (n.getNodeName().equals("JPEGvariety")) {
- NodeList childNodes = n.getChildNodes();
-
- for (int k = 0; k < childNodes.getLength(); k++) {
- System.out.println("node #" + k + " is "
- + childNodes.item(k).getNodeName());
- if (childNodes.item(k).getNodeName().equals("app0JFIF")) {
- NamedNodeMap nnm = childNodes.item(k).getAttributes();
- //get the resUnits, Xdensity, and Ydensity attribuutes
- Node resUnitsNode = getAttributeByName(childNodes.item(k), "resUnits");
- Node XdensityNode = getAttributeByName(childNodes.item(k), "Xdensity");
- Node YdensityNode = getAttributeByName(childNodes.item(k), "Ydensity");
-
- //reset values for nodes
- resUnitsNode.setNodeValue("1"); //indicate DPI mode
- XdensityNode.setNodeValue(String.valueOf(dpi));
- YdensityNode.setNodeValue(String.valueOf(dpi));
-
- System.out.println("name="
- + resUnitsNode.getNodeName() + ", value=" + resUnitsNode.getNodeValue());
- System.out.println("name="
- + XdensityNode.getNodeName() + ", value=" + XdensityNode.getNodeValue());
- System.out.println("name="
- + YdensityNode.getNodeName() + ", value=" + YdensityNode.getNodeValue());
-
- } //end if (childNodes.item(k).getNodeName().equals("app0JFIF"))
- } //end if (n.getNodeName().equals("JPEGvariety")
- break; //we don't care about the rest of the children
- } //end if (n.getNodeName().equals("JPEGvariety"))
-
- } //end for (int j = 0; j < nl.getLength(); j++)
-
- try {
- iomd.setFromTree(formatName, node);
- } catch (IIOInvalidTreeException e) {
- e.printStackTrace(); //To change body of catch statement use Options | File Templates.
- }
- //attach the metadata to an image
- IIOImage iioimage = new IIOImage(image, null, iomd);
- FileImageOutputStream stream = new FileImageOutputStream(new File(fileName));
- try {
- imageWriter.setOutput(stream);
- imageWriter.write(iioimage);
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- stream.close();
- }
- } //end if (i.hasNext()) //there's at least one ImageWriter, just use the first one
- }
-
- /**
- * @param node
- * @param attributeName - name of child node to return
- * @return Node
- */
- private Node getAttributeByName(Node node, String attributeName) {
- if (node == null) {
- return null;
- }
- NamedNodeMap nnm = node.getAttributes();
- for (int i = 0; i < nnm.getLength(); i++) {
- Node n = nnm.item(i);
- if (n.getNodeName().equals(attributeName)) {
- return n;
- }
- }
- return null; // no such attribute was found
- }
-
- public boolean saveImage_Jpeg(String file, int dpi) {
- int w, h;
- if (this.chartSize == null) {
- w = this.getWidth();
- h = this.getHeight();
- } else {
- w = this.chartSize.width;
- h = this.chartSize.height;
- }
- return this.saveImage_Jpeg(file, w, h, dpi);
- }
-
- public boolean saveImage_Jpeg(String file, int width, int height, int dpi) {
- double scaleFactor = dpi / 72.0;
- BufferedImage bufferedImage = new BufferedImage((int)(width * scaleFactor), (int)(height * scaleFactor), BufferedImage.TYPE_INT_RGB);
- Graphics2D g = bufferedImage.createGraphics();
- AffineTransform at = g.getTransform();
- at.scale(scaleFactor, scaleFactor);
- g.setTransform(at);
- paintGraphics(g, width, height);
-
- try {
- // Image writer
- ImageWriter imageWriter = ImageIO.getImageWritersBySuffix("jpeg").next();
- ImageOutputStream ios = ImageIO.createImageOutputStream(new File(file));
- imageWriter.setOutput(ios);
-
- // Compression
- JPEGImageWriteParam jpegParams = (JPEGImageWriteParam) imageWriter.getDefaultWriteParam();
- jpegParams.setCompressionMode(JPEGImageWriteParam.MODE_EXPLICIT);
- jpegParams.setCompressionQuality(0.85f);
-
- // Metadata (dpi)
- IIOMetadata data = imageWriter.getDefaultImageMetadata(new ImageTypeSpecifier(bufferedImage), jpegParams);
- Element tree = (Element) data.getAsTree("javax_imageio_jpeg_image_1.0");
- Element jfif = (Element) tree.getElementsByTagName("app0JFIF").item(0);
- jfif.setAttribute("Xdensity", Integer.toString(dpi));
- jfif.setAttribute("Ydensity", Integer.toString(dpi));
- jfif.setAttribute("resUnits", "1"); // density is dots per inch
- data.setFromTree("javax_imageio_jpeg_image_1.0", tree);
-
- // Write and clean up
- imageWriter.write(null, new IIOImage(bufferedImage, null, data), jpegParams);
- ios.close();
- imageWriter.dispose();
- } catch (Exception e) {
- return false;
- }
- g.dispose();
-
- return true;
- }
-
- /**
- * Save image
- *
- * @param fileName File name
- * @param dpi DPI
- * @throws IOException
- * @throws java.lang.InterruptedException
- */
- public void saveImage(String fileName, int dpi) throws IOException, InterruptedException {
- saveImage(fileName, dpi, null);
- }
-
- /**
- * Save image
- *
- * @param fileName File name
- * @param dpi DPI
- * @param sleep Sleep seconds for web map layer
- * @throws IOException
- * @throws java.lang.InterruptedException
- */
- public void saveImage(String fileName, int dpi, Integer sleep) throws IOException, InterruptedException {
- int width, height;
- if (this.chartSize != null) {
- height = this.chartSize.height;
- width = this.chartSize.width;
- } else {
- width = this.getWidth();
- height = this.getHeight();
- }
-
- this.saveImage(fileName,dpi, width, height, sleep);
- }
-
- /**
- * Save image
- *
- * @param fileName File name
- * @param dpi DPI
- * @param width Width
- * @param height Height
- * @param sleep Sleep seconds for web map layer
- * @throws IOException
- * @throws java.lang.InterruptedException
- */
- public void saveImage(String fileName, int dpi, int width, int height, Integer sleep) throws IOException, InterruptedException {
- File output = new File(fileName);
- output.delete();
-
- String formatName = fileName.substring(fileName.lastIndexOf('.') + 1);
- if (formatName.equals("jpg")) {
- formatName = "jpeg";
- saveImage_Jpeg(fileName, width, height, dpi);
- return;
- }
-
- double scaleFactor = dpi / 72.0;
- BufferedImage image = new BufferedImage((int)(width * scaleFactor), (int)(height * scaleFactor), BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = image.createGraphics();
- AffineTransform at = g.getTransform();
- at.scale(scaleFactor, scaleFactor);
- g.setTransform(at);
- paintGraphics(g, width, height);
- for (Iterator iw = ImageIO.getImageWritersByFormatName(formatName); iw.hasNext();) {
- ImageWriter writer = iw.next();
- ImageWriteParam writeParam = writer.getDefaultWriteParam();
- ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_ARGB);
- IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);
- if (metadata == null) {
- metadata = writer.getDefaultImageMetadata(typeSpecifier, null);
- }
- if (metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported()) {
- continue;
- }
-
- ImageUtil.setDPI(metadata, dpi);
-
- if (sleep != null) {
- Thread.sleep(sleep * 1000);
- }
- final ImageOutputStream stream = ImageIO.createImageOutputStream(output);
- try {
- writer.setOutput(stream);
- writer.write(metadata, new IIOImage(image, null, metadata), writeParam);
- } finally {
- stream.close();
- }
- break;
- }
- g.dispose();
- }
-
- /**
- * Get view image
- *
- * @return View image
- */
- public BufferedImage getViewImage() {
- return this.mapBitmap;
- }
-
- /**
- * Paint view image
- *
- * @return View image
- */
- public BufferedImage paintViewImage() {
- int w, h;
- if (this.chartSize == null) {
- w = this.getWidth();
- h = this.getHeight();
- } else {
- w = this.chartSize.width;
- h = this.chartSize.height;
- }
- return paintViewImage(w, h);
- }
-
- /**
- * Paint view image
- *
- * @param width Image width
- * @param height Image height
- * @return View image
- */
- public BufferedImage paintViewImage(int width, int height) {
- BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = image.createGraphics();
- paintGraphics(g);
-
- return image;
- }
-
- /**
- * Paint view image
- *
- * @param dpi Image resolution
- * @return View image
- */
- public BufferedImage paintViewImage(int dpi) {
- int w, h;
- if (this.chartSize == null) {
- w = this.getWidth();
- h = this.getHeight();
- } else {
- w = this.chartSize.width;
- h = this.chartSize.height;
- }
- return paintViewImage(w, h, dpi);
- }
-
- /**
- * Paint view image
- *
- * @param width Image width
- * @param height Image height
- * @param dpi Image resolution
- * @return View image
- */
- public BufferedImage paintViewImage(int width, int height, int dpi) {
- double scaleFactor = dpi / 72.0;
- BufferedImage image = new BufferedImage((int)(width * scaleFactor), (int)(height * scaleFactor),
- BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = image.createGraphics();
- AffineTransform at = g.getTransform();
- at.scale(scaleFactor, scaleFactor);
- g.setTransform(at);
- paintGraphics(g, width, height);
-
- return image;
- }
-
- /**
- * Check if has web map layer
- *
- * @return Boolean
- */
- public boolean hasWebMap() {
- if (this.chart != null) {
- return this.chart.hasWebMap();
- }
-
- return false;
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartScaleBar.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartScaleBar.java
deleted file mode 100644
index 4e813f5d..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartScaleBar.java
+++ /dev/null
@@ -1,457 +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;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.FontMetrics;
-import java.awt.Graphics2D;
-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.common.PointF;
-import org.meteoinfo.layout.ScaleBarType;
-import org.meteoinfo.layout.ScaleBarUnits;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class ChartScaleBar extends ChartElement {
- //
-
- private MapPlot mapPlot;
- private boolean _antiAlias;
- private float lineWidth;
- private Font _font;
- private ScaleBarType _scaleBarType;
- private ScaleBarUnits _unit;
- private String _unitText;
- private int _numBreaks;
- private boolean _drawNeatLine;
- private Color _neatLineColor;
- private float _neatLineSize;
- private boolean _drawScaleText;
- private float _yShiftScale = 2.0f;
- //
- //
-
- /**
- * Constructor
- *
- * @param mapPlot The map plot
- */
- public ChartScaleBar(MapPlot mapPlot) {
- super();
- //this.setElementType(ElementType.LayoutScaleBar);
- //this.setResizeAbility(ResizeAbility.ResizeAll);
-
- this.width = 200;
- this.height = 50;
- this.mapPlot = mapPlot;
- _antiAlias = true;
- _scaleBarType = ScaleBarType.SCALELINE_1;
- lineWidth = 1;
- _drawNeatLine = false;
- _neatLineColor = Color.black;
- _neatLineSize = 1;
- _font = new Font("Arial", Font.PLAIN, 12);
- _unit = ScaleBarUnits.KILOMETERS;
- _unitText = "km";
- _numBreaks = 4;
- _drawScaleText = false;
- }
- //
- //
-
- /**
- * Get map plot
- *
- * @return The map plot
- */
- public MapPlot getMapPlot() {
- return mapPlot;
- }
-
- /**
- * Get line widht
- * @return Line width
- */
- public float getLineWidth() {
- return this.lineWidth;
- }
-
- /**
- * Set line width
- * @param value Line width
- */
- public void setLineWidth(float value) {
- this.lineWidth = value;
- }
-
- /**
- * Get scale bar type
- *
- * @return Scale bar type
- */
- public ScaleBarType getScaleBarType() {
- return _scaleBarType;
- }
-
- /**
- * Set scale bar type
- *
- * @param type Scale bar type
- */
- public void setScaleBarType(ScaleBarType type) {
- _scaleBarType = type;
- }
-
- /**
- * Get if draw neat line
- *
- * @return If draw neat line
- */
- public boolean isDrawNeatLine() {
- return _drawNeatLine;
- }
-
- /**
- * Set if draw neat line
- *
- * @param istrue If draw neat line
- */
- public void setDrawNeatLine(boolean istrue) {
- _drawNeatLine = istrue;
- }
-
- /**
- * Get neat line color
- *
- * @return Neat line color
- */
- public Color getNeatLineColor() {
- return _neatLineColor;
- }
-
- /**
- * Set neat line color
- *
- * @param color Neat line color
- */
- public void setNeatLineColor(Color color) {
- _neatLineColor = color;
- }
-
- /**
- * Get neat line size
- *
- * @return Neat line size
- */
- public float getNeatLineSize() {
- return _neatLineSize;
- }
-
- /**
- * Set neat line size
- *
- * @param size Neat line size
- */
- public void setNeatLineSize(float size) {
- _neatLineSize = size;
- }
-
- /**
- * Get font
- *
- * @return The font
- */
- public Font getFont() {
- return _font;
- }
-
- /**
- * Set font
- *
- * @param font The font
- */
- public void setFont(Font font) {
- _font = font;
- }
-
- /**
- * Get break number
- *
- * @return The break number
- */
- public int getBreakNumber() {
- return _numBreaks;
- }
-
- /**
- * Set break number
- *
- * @param num Break number
- */
- public void setBreakNumber(int num) {
- _numBreaks = num;
- }
-
- /**
- * Get if draw scale text
- *
- * @return If draw scale text
- */
- public boolean isDrawScaleText() {
- return _drawScaleText;
- }
-
- /**
- * Set if draw scale text
- *
- * @param istrue If draw scale text
- */
- public void setDrawScaleText(boolean istrue) {
- _drawScaleText = istrue;
- }
- //
- //
- /**
- * Draw text
- *
- * @param g Graphics2D
- * @param x X
- * @param y Y
- */
- public void draw(Graphics2D g, float x, float y) {
- AffineTransform oldMatrix = g.getTransform();
- g.translate(x, y);
- if (_antiAlias) {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- } else {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
- }
-
- //Draw background color
- if (this.isDrawBackColor()){
- g.setColor(this.getBackground());
- g.fill(new Rectangle.Float(0, 0, this.getWidth(), this.getHeight()));
- }
-
- drawScaleBar(g);
-
- //Draw neatline
- if (_drawNeatLine) {
- Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
- (this.getWidth() - _neatLineSize), (this.getHeight() - _neatLineSize));
- g.setColor(_neatLineColor);
- g.setStroke(new BasicStroke(_neatLineSize));
- g.draw(mapRect);
- }
-
- g.setTransform(oldMatrix);
- }
-
- /**
- * Paint graphics
- *
- * @param g Graphics
- * @param pageLocation Page location
- * @param zoom Zoom
- */
- public void paintGraphics(Graphics2D g, PointF pageLocation) {
- AffineTransform oldMatrix = g.getTransform();
- PointF aP = pageToScreen(this.getX(), this.getY(), pageLocation, 1);
- g.translate(aP.X, aP.Y);
- if (_antiAlias) {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- } else {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
- }
-
- //Draw background color
- if (this.isDrawBackColor()){
- g.setColor(this.getBackground());
- g.fill(new Rectangle.Float(0, 0, this.getWidth(), this.getHeight()));
- }
-
- drawScaleBar(g);
-
- //Draw neatline
- if (_drawNeatLine) {
- Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
- (this.getWidth() - _neatLineSize), (this.getHeight() - _neatLineSize));
- g.setColor(_neatLineColor);
- g.setStroke(new BasicStroke(_neatLineSize));
- g.draw(mapRect);
- }
-
- g.setTransform(oldMatrix);
- }
-
- private void drawScaleBar(Graphics2D g) {
- //Calculates the width of one break in greographic units
- FontMetrics metrics = g.getFontMetrics(this._font);
- float unitLegnth = metrics.stringWidth(_unitText) * 2;
- float widthNoUnit = (this.getWidth() - unitLegnth);
- long geoBreakWidth = (long) (getGeoWidth(widthNoUnit / _numBreaks));
-
- //If the geobreakWidth is less than 1 we return and don't draw anything
- if (geoBreakWidth < 1) {
- return;
- }
-
- double n = Math.pow(10, String.valueOf(geoBreakWidth).length() - 1);
- geoBreakWidth = (long) (Math.floor(geoBreakWidth / n) * n);
-
- long breakWidth = (long) (getWidth(geoBreakWidth));
- FontMetrics metrics1 = g.getFontMetrics(_font);
- float fontHeight = metrics1.getHeight();
- float leftStart = metrics1.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
-
- //Draw scale text
- double scale = geoBreakWidth * getConversionFactor(_unit) * 100 / (breakWidth / 96 * 2.539999918);
- if (_drawScaleText) {
- g.setFont(this._font);
- g.setColor(this.getForeground());
- g.drawString("1 : " + String.format("{0:0,0}", scale),
- leftStart - (metrics.stringWidth(String.valueOf(Math.abs(0))) / 2), fontHeight * 2.5F);
- }
-
- //Draw scale bar
- switch (_scaleBarType) {
- case SCALELINE_1:
- drawScaleLine1(g, breakWidth, geoBreakWidth);
- break;
- case SCALELINE_2:
- drawScaleLine2(g, breakWidth, geoBreakWidth);
- break;
- case ALTERNATING_BAR:
- drawAlternatingBar(g, breakWidth, geoBreakWidth);
- break;
- }
- }
-
- private double getConversionFactor(ScaleBarUnits unit) {
- switch (unit) {
- case KILOMETERS:
- return 1000;
- default:
- return 1;
- }
- }
-
- private double getGeoWidth(double width) {
- double geoWidth = width / mapPlot.getMapFrame().getMapView().getXScale() / getConversionFactor(_unit);
- if (mapPlot.getMapFrame().getMapView().getProjection().isLonLatMap()) {
- geoWidth = geoWidth * getLonDistScale();
- }
-
- return geoWidth;
- }
-
- private double getWidth(double geoWidth) {
- double width = geoWidth * mapPlot.getMapFrame().getMapView().getXScale() * getConversionFactor(_unit);
- if (mapPlot.getMapFrame().getMapView().getProjection().isLonLatMap()) {
- width = width / getLonDistScale();
- }
-
- return width;
- }
-
- private double getLonDistScale() {
- //Get meters of one longitude degree
- double pY = (mapPlot.getMapFrame().getMapView().getViewExtent().maxY + mapPlot.getMapFrame().getMapView().getViewExtent().minY) / 2;
- double ProjX = 0, ProjY = pY, pProjX = 1, pProjY = pY;
- double dx = Math.abs(ProjX - pProjX);
- double dy = Math.abs(ProjY - pProjY);
- double dist;
- double y = (ProjY + pProjY) / 2;
- double factor = Math.cos(y * Math.PI / 180);
- dx *= factor;
- dist = Math.sqrt(dx * dx + dy * dy);
- dist = dist * 111319.5;
-
- return dist;
- }
-
- private void drawScaleLine1(Graphics2D g, long breakWidth, long geoBreakWidth) {
- FontMetrics metrics = g.getFontMetrics(_font);
- float fontHeight = metrics.getHeight();
- float leftStart = metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
- int yShift = 10;
-
- g.setColor(this.getForeground());
- g.setStroke(new BasicStroke(this.lineWidth));
- g.draw(new Line2D.Float(leftStart, fontHeight * 1.6f + yShift, leftStart + (breakWidth * _numBreaks), fontHeight * 1.6f + yShift));
- g.setFont(this._font);
- for (int i = 0; i <= _numBreaks; i++) {
- g.draw(new Line2D.Float(leftStart, fontHeight * 1.1f + yShift, leftStart, fontHeight * 1.6f + yShift));
- g.drawString(String.valueOf(Math.abs(geoBreakWidth * i)),
- leftStart - (metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth * i))) / 2), yShift * _yShiftScale);
- leftStart = leftStart + breakWidth;
- }
- g.drawString(_unitText, leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f + yShift * _yShiftScale);
- }
-
- private void drawScaleLine2(Graphics2D g, long breakWidth, long geoBreakWidth) {
- FontMetrics metrics = g.getFontMetrics(_font);
- float fontHeight = metrics.getHeight();
- float leftStart = metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
- int yShift = 5;
-
- g.setColor(this.getForeground());
- g.setStroke(new BasicStroke(this.lineWidth));
- g.draw(new Line2D.Float(leftStart, fontHeight * 1.6f + yShift, leftStart + (breakWidth * _numBreaks), fontHeight * 1.6f + yShift));
- g.setFont(this._font);
- for (int i = 0; i <= _numBreaks; i++) {
- g.draw(new Line2D.Float(leftStart, fontHeight * 1.1f + yShift, leftStart, fontHeight + (fontHeight * 1.1f) + yShift));
- g.drawString(String.valueOf(Math.abs(geoBreakWidth * i)),
- leftStart - (metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth * i))) / 2), yShift * _yShiftScale);
- leftStart = leftStart + breakWidth;
- }
- g.drawString(_unitText, leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f + yShift * _yShiftScale);
- }
-
- private void drawAlternatingBar(Graphics2D g, long breakWidth, long geoBreakWidth) {
- FontMetrics metrics = g.getFontMetrics(_font);
- float fontHeight = metrics.getHeight();
- float leftStart = metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
- int yShift = 5;
- float rHeight = fontHeight / 2;
-
- boolean isFill = false;
- g.setStroke(new BasicStroke(this.lineWidth));
- g.setColor(this.getForeground());
- g.setFont(this._font);
- for (int i = 0; i <= _numBreaks; i++) {
- if (i < _numBreaks) {
- if (isFill) {
- g.fill(new Rectangle.Float(leftStart, fontHeight * 1.1f + yShift, breakWidth, rHeight));
- }
- g.draw(new Rectangle.Float(leftStart, fontHeight * 1.1f + yShift, breakWidth, rHeight));
- }
- g.drawString(String.valueOf(Math.abs(geoBreakWidth * i)),
- leftStart - (metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth * i))) / 2), yShift * _yShiftScale);
- leftStart = leftStart + breakWidth;
- isFill = !isFill;
- }
- g.setColor(this.getForeground());
- g.drawString(_unitText, leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f + yShift * _yShiftScale);
- }
-
- @Override
- public void moveUpdate() {
- }
-
- @Override
- public void resizeUpdate() {
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartText.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartText.java
deleted file mode 100644
index ac0fdcf3..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartText.java
+++ /dev/null
@@ -1,741 +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;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.awt.Stroke;
-import java.awt.geom.AffineTransform;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.common.XAlign;
-import org.meteoinfo.common.YAlign;
-import org.meteoinfo.drawing.Draw;
-import org.locationtech.jts.geom.Geometry;
-import org.locationtech.jts.geom.GeometryFactory;
-import org.meteoinfo.geometry.shape.Shape;
-import org.meteoinfo.geometry.shape.ShapeTypes;
-
-/**
- *
- * @author yaqiang
- */
-public class ChartText extends Shape {
-
- //
- protected double x;
- protected double y;
- private Font font;
- private List text;
- private Color color;
- private int lineSpace;
- private CoordinateType coordinates;
- private Color background;
- private boolean drawBackground;
- private boolean drawNeatline;
- private Color neatLineColor;
- private float neatLineSize;
- private float gap;
- protected float angle;
- private XAlign xAlign;
- private YAlign yAlign;
- private boolean useExternalFont;
- protected double xShift;
- protected double yShift;
-
- //
- //
- /**
- * Constructor
- */
- public ChartText() {
- font = new Font("Arial", Font.PLAIN, 14);
- color = Color.black;
- lineSpace = 5;
- coordinates = CoordinateType.DATA;
- this.background = Color.white;
- this.drawBackground = false;
- this.drawNeatline = false;
- this.neatLineColor = Color.black;
- this.neatLineSize = 1.0f;
- this.gap = 3.0f;
- this.angle = 0.0f;
- this.xAlign = XAlign.LEFT;
- this.yAlign = YAlign.BOTTOM;
- this.useExternalFont = false;
- this.xShift = 0;
- this.yShift = 0;
- }
-
- /**
- * Constructor
- *
- * @param text Text
- */
- public ChartText(String text) {
- this();
- this.text = new ArrayList<>();
- String[] lines = text.split("\n");
- this.text.addAll(Arrays.asList(lines));
- }
-
- /**
- * Constructor
- *
- * @param text Text
- */
- public ChartText(List text) {
- this();
- this.text = text;
- }
-
- /**
- * Constructor
- *
- * @param text Text
- * @param font Font
- */
- public ChartText(String text, Font font) {
- this();
- this.text = new ArrayList<>();
- String[] lines = text.split("\n");
- this.text.addAll(Arrays.asList(lines));
- this.font = font;
- }
-
- /**
- * Constructor
- *
- * @param text Text
- * @param font Font
- */
- public ChartText(List text, Font font) {
- this();
- this.text = text;
- this.font = font;
- }
- //
- //
-
- /**
- * Get text
- *
- * @return Text
- */
- public String getText() {
- return text.get(0);
- }
-
- /**
- * Set text
- *
- * @param value Text
- */
- public void setText(String value) {
- text = new ArrayList<>();
- String[] lines = value.split("\n");
- this.text.addAll(Arrays.asList(lines));
- }
-
- /**
- * Get texts
- *
- * @return Text list
- */
- public List getTexts() {
- return text;
- }
-
- /**
- * Set texts
- *
- * @param value Text list
- */
- public void setTexts(List value) {
- text = value;
- }
-
- /**
- * Get font
- *
- * @return Font
- */
- public Font getFont() {
- return font;
- }
-
- /**
- * Set font
- *
- * @param value Font
- */
- public void setFont(Font value) {
- font = value;
- }
-
- /**
- * Get title color
- *
- * @return Title color
- */
- public Color getColor() {
- return color;
- }
-
- /**
- * Set title color
- *
- * @param value Title color
- */
- public void setColor(Color value) {
- this.color = value;
- }
-
- /**
- * Get x
- *
- * @return X
- */
- public double getX() {
- return this.x;
- }
-
- /**
- * Set x
- *
- * @param value X
- */
- public void setX(double value) {
- this.x = value;
- }
-
- /**
- * Get y
- *
- * @return Y
- */
- public double getY() {
- return this.y;
- }
-
- /**
- * Set y
- *
- * @param value Y
- */
- public void setY(double value) {
- this.y = value;
- }
-
- /**
- * Get line space
- *
- * @return Line space
- */
- public int getLineSpace() {
- return this.lineSpace;
- }
-
- /**
- * Set line space
- *
- * @param value Line space
- */
- public void setLineSpace(int value) {
- this.lineSpace = value;
- }
-
- /**
- * Get coordinates
- *
- * @return Coordinates
- */
- public CoordinateType getCoordinates() {
- return this.coordinates;
- }
-
- /**
- * Set coordinates
- *
- * @param value Coordinates
- */
- public void setCoordinates(CoordinateType value) {
- this.coordinates = value;
- }
-
- /**
- * Set coordinates
- *
- * @param value Coordinates
- */
- public void setCoordinates(String value) {
- switch (value) {
- case "axes":
- this.coordinates = CoordinateType.AXES;
- break;
- case "figure":
- this.coordinates = CoordinateType.FIGURE;
- break;
- case "data":
- this.coordinates = CoordinateType.DATA;
- break;
- case "inches":
- this.coordinates = CoordinateType.INCHES;
- break;
- }
- }
-
- /**
- * Get background color
- *
- * @return Background color
- */
- public Color getBackground() {
- return this.background;
- }
-
- /**
- * Set background color
- *
- * @param value Background color
- */
- public void setBackground(Color value) {
- this.background = value;
- }
-
- /**
- * Get if is fill background
- *
- * @return Boolean
- */
- public boolean isFill() {
- return this.drawBackground;
- }
-
- /**
- * Set fill background or not
- *
- * @param value Boolean
- */
- public void setFill(boolean value) {
- this.drawBackground = value;
- }
-
- /**
- * Get draw neatline or not
- *
- * @return Boolean
- */
- public boolean isDrawNeatline() {
- return this.drawNeatline;
- }
-
- /**
- * Set draw neatline or not
- *
- * @param value Boolean
- */
- public void setDrawNeatline(boolean value) {
- this.drawNeatline = value;
- }
-
- /**
- * Get neatline color
- *
- * @return Neatline color
- */
- public Color getNeatlineColor() {
- return this.neatLineColor;
- }
-
- /**
- * Set neatline color
- *
- * @param value Neatline color
- */
- public void setNeatlineColor(Color value) {
- this.neatLineColor = value;
- }
-
- /**
- * Get neatline size
- *
- * @return Neatline size
- */
- public float getNeatlineSize() {
- return this.neatLineSize;
- }
-
- /**
- * Set neatline size
- *
- * @param value Neatline size
- */
- public void setNeatlineSize(float value) {
- this.neatLineSize = value;
- }
-
- /**
- * Get gap
- *
- * @return Gap
- */
- public float getGap() {
- return this.gap;
- }
-
- /**
- * Set gap
- *
- * @param value Gap
- */
- public void setGap(float value) {
- this.gap = value;
- }
-
- /**
- * Get angle
- *
- * @return Angle
- */
- public float getAngle() {
- return this.angle;
- }
-
- /**
- * Set angle
- *
- * @param value Angle
- */
- public void setAngle(float value) {
- this.angle = value;
- }
-
- /**
- * Get x align
- *
- * @return X align
- */
- public XAlign getXAlign() {
- return this.xAlign;
- }
-
- /**
- * Set x align
- *
- * @param value X align
- */
- public void setXAlign(XAlign value) {
- this.xAlign = value;
- }
-
- /**
- * Set x align
- *
- * @param value X align string
- */
- public void setXAlign(String value) {
- this.xAlign = XAlign.valueOf(value.toUpperCase());
- }
-
- /**
- * Get y align
- *
- * @return Y align
- */
- public YAlign getYAlign() {
- return this.yAlign;
- }
-
- /**
- * Set y align
- *
- * @param value Y align
- */
- public void setYAlign(YAlign value) {
- this.yAlign = value;
- }
-
- /**
- * Set y align
- *
- * @param value Y align string
- */
- public void setYAlign(String value) {
- this.yAlign = YAlign.valueOf(value.toUpperCase());
- }
-
- /**
- * Get if use external font - only for LaTeX string
- *
- * @return Boolean
- */
- public boolean isUseExternalFont() {
- return this.useExternalFont;
- }
-
- /**
- * Set if use external font - only for LaTeX string
- *
- * @param value Boolean
- */
- public void setUseExternalFont(boolean value) {
- this.useExternalFont = value;
- }
-
- /**
- * Get x shift
- * @return X shift
- */
- public double getXShift() {
- return this.xShift;
- }
-
- /**
- * Set x shift
- * @param value X shift
- */
- public void setXShift(double value) {
- this.xShift = value;
- }
-
- /**
- * Get y shift
- * @return Y shift
- */
- public double getYShift() {
- return this.yShift;
- }
-
- /**
- * Set y shift
- * @param value Y shift
- */
- public void setYShift(double value) {
- this.yShift = value;
- }
-
- //
- //
- /**
- * Add text in new line
- *
- * @param value The text string
- */
- public void addText(String value) {
- this.text.add(value);
- }
-
- @Override
- public ShapeTypes getShapeType() {
- return ShapeTypes.TEXT;
- }
-
- /**
- * Get text line number
- *
- * @return Text line number
- */
- public int getLineNum() {
- return this.text.size();
- }
-
- /**
- * Get text dimension with angle
- *
- * @param g Graphics2D
- * @return Dimension
- */
- public Dimension getTrueDimension(Graphics2D g) {
- Dimension dim = getDimension(g);
- if (this.angle != 0) {
- int width = dim.width;
- int height = dim.height;
- int temp;
- if (angle == 90 || angle == -90) {
- temp = width;
- width = height;
- height = temp;
- } else {
- width = (int) ((width * Math.cos(Math.toRadians(angle))) + (height * Math.sin(Math.toRadians(angle))));
- height = (int) ((width * Math.sin(Math.toRadians(angle))) + (height * Math.cos(Math.toRadians(angle))));
- }
- return new Dimension(width, height);
- } else {
- return dim;
- }
- }
-
- /**
- * Get text dimension
- *
- * @param g Graphics2D
- * @return Dimension
- */
- public Dimension getDimension(Graphics2D g) {
- g.setFont(font);
- int width = 0, height = 0;
- for (String line : this.text) {
- Dimension dim = Draw.getStringDimension(line, g);
- if (width < dim.width) {
- width = dim.width;
- }
- height += dim.height + this.lineSpace;
- }
- height -= this.lineSpace;
-
- return new Dimension(width, height);
- }
-
- /**
- * To geometry method
- *
- * @param factory GeometryFactory
- * @return Geometry
- */
- @Override
- public Geometry toGeometry(GeometryFactory factory) {
- return null;
- }
-
- /**
- * Set point
- *
- * @param x X
- * @param y Y
- */
- public void setPoint(double x, double y) {
- this.x = x;
- this.y = y;
- Extent aExtent = new Extent();
- aExtent.minX = x;
- aExtent.maxX = x;
- aExtent.minY = y;
- aExtent.maxY = y;
- this.setExtent(aExtent);
- }
-
- /**
- * To string
- *
- * @return String
- */
- @Override
- public String toString() {
- if (this.text.size() == 1) {
- return this.text.get(0);
- } else {
- String r = "";
- for (int i = 0; i < this.text.size(); i++) {
- if (i == 0) {
- r = this.text.get(i);
- } else {
- r = r + "\n" + this.text.get(i);
- }
- }
- return r;
- }
- }
-
- /**
- * Draw text
- *
- * @param g Graphics2D
- * @param x X
- * @param y Y
- */
- public void draw(Graphics2D g, float x, float y) {
- Dimension dim = this.getDimension(g);
- x += this.xShift;
- y += this.yShift;
-
- AffineTransform tempTrans = g.getTransform();
- if (this.angle != 0) {
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- myTrans.translate(x, y);
- //myTrans.translate(tempTrans.getTranslateX() + x, tempTrans.getTranslateY() + y);
- myTrans.rotate(-angle * Math.PI / 180);
- g.setTransform(myTrans);
- x = 0;
- y = 0;
- }
-
- Rectangle.Double rect = new Rectangle.Double(x, y - dim.getHeight(), dim.getWidth(), dim.getHeight());
- rect.setRect(rect.x - gap, rect.y - gap, rect.width + gap * 2,
- rect.height + gap * 2);
- if (this.drawBackground) {
- g.setColor(this.background);
- g.fill(rect);
- }
- if (this.drawNeatline) {
- g.setColor(this.neatLineColor);
- Stroke oldStroke = g.getStroke();
- g.setStroke(new BasicStroke(neatLineSize));
- g.draw(rect);
- g.setStroke(oldStroke);
- }
-
- g.setColor(this.color);
- g.setFont(font);
- switch (this.yAlign) {
- case BOTTOM:
- y = y - dim.height;
- break;
- case CENTER:
- y = y - dim.height * 0.5f;
- break;
- }
-
- for (String str : this.text) {
- dim = Draw.getStringDimension(str, g);
- Draw.drawString(g, x, y, str, xAlign, YAlign.TOP, useExternalFont);
- y += dim.height;
- y += this.lineSpace;
- }
-
- if (this.angle != 0) {
- g.setTransform(tempTrans);
- }
- }
-
- /**
- * Clone
- *
- * @return Cloned object
- */
- @Override
- public Object clone() {
- ChartText ct = new ChartText();
- ct.angle = this.angle;
- ct.background = this.background;
- ct.color = this.color;
- ct.coordinates = this.coordinates;
- ct.drawBackground = this.drawBackground;
- ct.drawNeatline = this.drawNeatline;
- ct.font = this.font;
- ct.gap = this.gap;
- ct.lineSpace = this.lineSpace;
- ct.neatLineColor = this.neatLineColor;
- ct.neatLineSize = this.neatLineSize;
- ct.text = this.text;
- ct.useExternalFont = this.useExternalFont;
- ct.x = this.x;
- ct.xAlign = this.xAlign;
- ct.y = this.y;
- ct.yAlign = this.yAlign;
-
- return ct;
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartText3D.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartText3D.java
deleted file mode 100644
index 22d25881..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartText3D.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/* This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.chart;
-
-import java.awt.Point;
-import org.meteoinfo.chart.plot3d.Projector;
-import org.meteoinfo.common.Extent3D;
-import org.meteoinfo.data.DataMath;
-import org.meteoinfo.geometry.shape.PointZ;
-
-/**
- *
- * @author Yaqiang Wang
- * yaqiang.wang@gmail.com
- */
-public class ChartText3D extends ChartText {
- private double z;
- private PointZ zdir = null;
-
- /**
- * Get z coordinate value
- * @return Z coordinate value
- */
- public double getZ(){
- return this.z;
- }
-
- /**
- * Set z coordinate value
- * @param value Z coordinate value
- */
- public void setZ(double value){
- this.z = value;
- }
-
- /**
- * Get zdir point
- * @return ZDir point
- */
- public PointZ getZDir(){
- return zdir;
- }
-
- /**
- * Set zdir point
- * @param value ZDir point
- */
- public void setZDir(PointZ value){
- this.zdir = value;
- }
-
- /**
- * Set zdir point
- * @param x X coordinate value
- * @param y Y coordinate value
- * @param z Z coordinate value
- */
- public void setZDir(float x, float y, float z){
- if (x == 0 && y == 0 && z == 0)
- this.zdir = null;
- else
- this.zdir = new PointZ(x, y, z);
- }
-
- /**
- * Set zdir point
- * @param value ZDir point
- */
- public void setZDir(String value){
- float x1 = 0, y1 = 0, z1 = 0;
- switch(value.toLowerCase()){
- case "x":
- x1 = 1;
- break;
- case "y":
- y1 = 1;
- break;
- case "z":
- z1 = 1;
- break;
- }
- this.setZDir(x1, y1, z1);
- }
-
- /**
- * Set point
- *
- * @param x X
- * @param y Y
- * @param z Z
- */
- public void setPoint(double x, double y, double z) {
- this.x = x;
- this.y = y;
- this.z = z;
- Extent3D aExtent = new Extent3D();
- aExtent.minX = x;
- aExtent.maxX = x;
- aExtent.minY = y;
- aExtent.maxY = y;
- aExtent.minZ = z;
- aExtent.maxZ = z;
- this.setExtent(aExtent);
- }
-
- /**
- * Update angle
- * @param projector Projector
- */
- public void updateAngle(Projector projector){
- if (this.zdir == null)
- return;
-
- Point p0 = projector.project(0, 0, 0);
- Point p1 = projector.project((float)this.zdir.X, (float)this.zdir.Y, (float)this.zdir.Z);
- double[] value = DataMath.getDSFromUV(p1.x - p0.x, p1.y - p0.y);
- this.angle = (float)value[0];
- }
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartWindArrow.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartWindArrow.java
deleted file mode 100644
index f2c2c818..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/ChartWindArrow.java
+++ /dev/null
@@ -1,391 +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;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.geom.Rectangle2D;
-
-import org.meteoinfo.common.DataConvert;
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.drawing.Draw;
-import org.meteoinfo.geometry.legend.ArrowBreak;
-import org.meteoinfo.layer.VectorLayer;
-import org.meteoinfo.geometry.graphic.GraphicCollection;
-import org.meteoinfo.geometry.shape.WindArrow;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class ChartWindArrow {
-
- //
- private final WindArrow windArrow;
- private ArrowBreak arrowBreak;
- private Font font;
- //private Color color;
- private Color labelColor;
- private float x;
- private float y;
- private String label;
- private int labelSep;
- private Object layer;
- private Color background;
- private boolean drawBackground;
- private boolean drawNeatline;
- private Color neatLineColor;
- private float neatLineSize;
-
- //
- //
- /**
- * Constructor
- */
- public ChartWindArrow() {
- this.windArrow = new WindArrow();
- this.windArrow.angle = 270;
- this.windArrow.length = 20;
- this.arrowBreak = new ArrowBreak();
- this.font = new Font("Arial", Font.PLAIN, 12);
- //this.color = Color.black;
- this.labelColor = Color.black;
- this.labelSep = 5;
- this.background = Color.white;
- this.drawBackground = false;
- this.drawNeatline = false;
- this.neatLineColor = Color.black;
- this.neatLineSize = 1.0f;
- }
-
- //
- //
- /**
- * Get wind arrow
- *
- * @return Wind arrow
- */
- public WindArrow getWindArrow() {
- return this.windArrow;
- }
-
- /**
- * Get arrow break
- * @return Arrow break
- */
- public ArrowBreak getArrowBreak() {
- return this.arrowBreak;
- }
-
- /**
- * Set arrow break
- * @param value Arrow break
- */
- public void setArrowBreak(ArrowBreak value) {
- this.arrowBreak = value;
- }
-
- /**
- * Get length
- *
- * @return Length
- */
- public float getLength() {
- return this.windArrow.length;
- }
-
- /**
- * Set length
- *
- * @param value Length
- */
- public void setLength(float value) {
- this.windArrow.length = value;
- this.label = String.valueOf(value);
- this.label = DataConvert.removeTailingZeros(this.label);
- }
-
- /**
- * Get angle
- *
- * @return Angle
- */
- public double getAngle() {
- return this.windArrow.angle;
- }
-
- /**
- * Set angle
- *
- * @param value Angle
- */
- public void setAngle(double value) {
- this.windArrow.angle = value;
- }
-
- /**
- * Get layer
- *
- * @return Layer
- */
- public Object getLayer() {
- return this.layer;
- }
-
- /**
- * Set layer
- *
- * @param value Layer
- */
- public void setLayer(Object value) {
- this.layer = value;
- }
-
- /**
- * Get font
- *
- * @return Font
- */
- public Font getFont() {
- return font;
- }
-
- /**
- * Set font
- *
- * @param value Font
- */
- public void setFont(Font value) {
- font = value;
- }
-
- /**
- * Get label color
- *
- * @return Label color
- */
- public Color getLabelColor() {
- return this.labelColor;
- }
-
- /**
- * Set label color
- *
- * @param value Label color
- */
- public void setLabelColor(Color value) {
- this.labelColor = value;
- }
-
- /**
- * Get the distance between arrow and label
- * @return Distance between arrow and label
- */
- public int getLabelSep(){
- return this.labelSep;
- }
-
- /**
- * Set the distance between arrow and label
- * @param value Distance between arrow and label
- */
- public void setLabelSep(int value) {
- this.labelSep = value;
- }
-
- /**
- * Get x
- *
- * @return X
- */
- public float getX() {
- return this.x;
- }
-
- /**
- * Set x
- *
- * @param value X
- */
- public void setX(float value) {
- this.x = value;
- }
-
- /**
- * Get y
- *
- * @return Y
- */
- public float getY() {
- return this.y;
- }
-
- /**
- * Set y
- *
- * @param value Y
- */
- public void setY(float value) {
- this.y = value;
- }
-
- /**
- * Get label
- *
- * @return Label
- */
- public String getLabel() {
- return this.label;
- }
-
- /**
- * Set label
- *
- * @param value Label
- */
- public void setLabel(String value) {
- this.label = value;
- }
-
- /**
- * Get background color
- *
- * @return Background color
- */
- public Color getBackground() {
- return this.background;
- }
-
- /**
- * Set background color
- *
- * @param value Background color
- */
- public void setBackground(Color value) {
- this.background = value;
- }
-
- /**
- * Get if is fill background
- *
- * @return Boolean
- */
- public boolean isFill() {
- return this.drawBackground;
- }
-
- /**
- * Set fill background or not
- *
- * @param value Boolean
- */
- public void setFill(boolean value) {
- this.drawBackground = value;
- }
-
- /**
- * Get draw neatline or not
- *
- * @return Boolean
- */
- public boolean isDrawNeatline() {
- return this.drawNeatline;
- }
-
- /**
- * Set draw neatline or not
- *
- * @param value Boolean
- */
- public void setDrawNeatline(boolean value) {
- this.drawNeatline = value;
- }
-
- /**
- * Get neatline color
- *
- * @return Neatline color
- */
- public Color getNeatlineColor() {
- return this.neatLineColor;
- }
-
- /**
- * Set neatline color
- *
- * @param value Neatline color
- */
- public void setNeatlineColor(Color value) {
- this.neatLineColor = value;
- }
-
- /**
- * Get neatline size
- *
- * @return Neatline size
- */
- public float getNeatlineSize() {
- return this.neatLineSize;
- }
-
- /**
- * Set neatline size
- *
- * @param value Neatline size
- */
- public void setNeatlineSize(float value) {
- this.neatLineSize = value;
- }
-
- //
- //
- /**
- * Draw text
- *
- * @param g Graphics2D
- * @param x X
- * @param y Y
- */
- public void draw(Graphics2D g, float x, float y) {
- Object rendering = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- float zoom = 1.0f;
- if (this.layer != null) {
- if (this.layer instanceof VectorLayer) {
- zoom = ((VectorLayer) this.layer).getDrawingZoom();
- } else if (this.layer instanceof GraphicCollection) {
- zoom = ((GraphicCollection) this.layer).getArrowZoom();
- }
- }
- g.setFont(this.font);
- //String drawStr = this.label wa.getLabel();
- Dimension dim = Draw.getStringDimension(this.label, g);
- if (this.drawBackground || this.drawNeatline) {
- Rectangle2D rect = Draw.getArrawBorder(new PointF(x, y), this.windArrow, g, zoom);
- double gap = 5;
- double width = Math.max(rect.getWidth(), dim.getWidth());
- rect.setRect(rect.getX() - gap, rect.getY() - gap - 2, width + gap * 2,
- rect.getHeight() + dim.height + this.labelSep + gap + 2);
- if (this.drawBackground) {
- g.setColor(this.background);
- g.fill(rect);
- }
- if (this.drawNeatline) {
- g.setColor(this.neatLineColor);
- g.draw(rect);
- }
- }
- //Draw.drawArraw(this.color, new PointF(x, y), this.windArrow, g, zoom);
- Draw.drawArraw(new PointF(x, y), windArrow, arrowBreak, g, zoom);
- g.setColor(this.labelColor);
- Draw.drawString(g, this.label, x, y + dim.height + this.labelSep);
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, rendering);
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/CoordinateType.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/CoordinateType.java
deleted file mode 100644
index 5b155c1c..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/CoordinateType.java
+++ /dev/null
@@ -1,17 +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;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public enum CoordinateType {
- AXES,
- FIGURE,
- DATA,
- INCHES
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/IChartPanel.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/IChartPanel.java
deleted file mode 100644
index 94793140..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/IChartPanel.java
+++ /dev/null
@@ -1,34 +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;
-
-/**
- *
- * @author yaqiang
- */
-public interface IChartPanel {
- /**
- * Save image
- * @param fn Image file name
- */
- public abstract void saveImage(String fn);
-
- /**
- * Set mouse mode
- * @param value Mouse mode
- */
- public abstract void setMouseMode(MouseMode value);
-
- /**
- * Zoom back to full extent
- */
- public abstract void onUndoZoomClick();
-
- /**
- * Paint graphics
- */
- public abstract void paintGraphics();
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/IPointSelectedListener.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/IPointSelectedListener.java
deleted file mode 100644
index 1513ca92..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/IPointSelectedListener.java
+++ /dev/null
@@ -1,24 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.chart;
-
-import java.util.EventListener;
-
-/**
- *
- * @author yaqiang
- */
-public interface IPointSelectedListener extends EventListener {
- public void pointSelectedEvent(PointSelectedEvent event);
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/LegendPosition.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/LegendPosition.java
deleted file mode 100644
index 236945ed..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/LegendPosition.java
+++ /dev/null
@@ -1,99 +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;
-
-/**
- *
- * @author yaqiang
- */
-public enum LegendPosition {
- UPPER_RIGHT,
- UPPER_LEFT,
- UPPER_CENTER,
- LOWER_LEFT,
- LOWER_RIGHT,
- LOWER_CENTER,
- RIGHT,
- CENTER_LEFT,
- CENTER_RIGHT,
- CENTER,
- LEFT,
- UPPER_RIGHT_OUTSIDE,
- UPPER_LEFT_OUTSIDE,
- UPPER_CENTER_OUTSIDE,
- LOWER_LEFT_OUTSIDE,
- LOWER_RIGHT_OUTSIDE,
- LOWER_CENTER_OUTSIDE,
- LEFT_OUTSIDE,
- RIGHT_OUTSIDE,
- CUSTOM;
-
- /**
- * If the position is custom
- * @return Boolean
- */
- public boolean isCustom(){
- switch (this){
- case CUSTOM:
- return true;
- default:
- return false;
- }
- }
-
- /**
- * Get LegendPostion from string
- * @param loc Location string
- * @return LegenPosition
- */
- public static LegendPosition fromString(String loc){
- LegendPosition lp = LegendPosition.UPPER_RIGHT;
- loc = loc.toLowerCase();
- switch (loc){
- case "upper left":
- lp = LegendPosition.UPPER_LEFT;
- break;
- case "upper right":
- lp = LegendPosition.UPPER_RIGHT;
- break;
- case "upper center":
- lp = LegendPosition.UPPER_CENTER;
- break;
- case "upper center outside":
- lp = LegendPosition.UPPER_CENTER_OUTSIDE;
- break;
- case "lower left":
- lp = LegendPosition.LOWER_LEFT;
- break;
- case "lower right":
- lp = LegendPosition.LOWER_RIGHT;
- break;
- case "lower center":
- lp = LegendPosition.LOWER_CENTER;
- break;
- case "lower center outside":
- lp = LegendPosition.LOWER_CENTER_OUTSIDE;
- break;
- case "left":
- lp = LegendPosition.LEFT;
- break;
- case "left outside":
- lp = LegendPosition.LEFT_OUTSIDE;
- break;
- case "right":
- lp = LegendPosition.RIGHT;
- break;
- case "right outside":
- lp = LegendPosition.RIGHT_OUTSIDE;
- break;
- case "custom":
- lp = LegendPosition.CUSTOM;
- break;
- }
-
- return lp;
- }
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/Location.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/Location.java
deleted file mode 100644
index f71e8a81..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/Location.java
+++ /dev/null
@@ -1,17 +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;
-
-/**
- *
- * @author yaqiang
- */
-public enum Location {
- LEFT,
- RIGHT,
- TOP,
- BOTTOM
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/Margin.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/Margin.java
deleted file mode 100644
index d057c8f7..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/Margin.java
+++ /dev/null
@@ -1,138 +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;
-
-import java.awt.geom.Rectangle2D;
-
-/**
- *
- * @author wyq
- */
-public class Margin {
- //
- private double left;
- private double right;
- private double top;
- private double bottom;
- //
- //
- /**
- * Constructor
- */
- public Margin(){
-
- }
-
- /**
- * Constructor
- * @param left Left
- * @param right Right
- * @param top Top
- * @param bottom Bottom
- */
- public Margin(double left, double right, double top, double bottom){
- this.left = left;
- this.right = right;
- this.top = top;
- this.bottom = bottom;
- }
- //
- //
- /**
- * Get left
- * @return Left
- */
- public double getLeft(){
- return this.left;
- }
-
- /**
- * Set left
- * @param value Left
- */
- public void setLeft(double value){
- this.left = value;
- }
-
- /**
- * Get right
- * @return Right
- */
- public double getRight(){
- return this.right;
- }
-
- /**
- * Set right
- * @param value Right
- */
- public void setRight(double value){
- this.right = value;
- }
-
- /**
- * Get top
- * @return Top
- */
- public double getTop(){
- return this.top;
- }
-
- /**
- * Set top
- * @param value Top
- */
- public void setTop(double value){
- this.top = value;
- }
-
- /**
- * Get bottom
- * @return Bottom
- */
- public double getBottom(){
- return this.bottom;
- }
-
- /**
- * Set bottom
- * @param value Bottom
- */
- public void setBottom(double value){
- this.bottom = value;
- }
- //
- //
- /**
- * Get margin area
- * @param inArea Inside area
- * @return Margin area
- */
- public Rectangle2D getArea(Rectangle2D inArea){
- double x = inArea.getX() - this.left;
- double y = inArea.getY() - this.top;
- double w = inArea.getWidth() + this.left + this.right;
- double h = inArea.getHeight() + this.top + this.bottom;
-
- return new Rectangle2D.Double(x, y, w, h);
- }
-
- /**
- * Extent
- * @param a Margin
- * @return Extented margin
- */
- public Margin extend(Margin a){
- Margin r = new Margin();
- r.setLeft(Math.max(this.left, a.left));
- r.setRight(Math.max(this.right, a.right));
- r.setTop(Math.max(this.top, a.top));
- r.setBottom(Math.max(this.bottom, a.bottom));
-
- return r;
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/MouseMode.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/MouseMode.java
deleted file mode 100644
index bba687d4..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/MouseMode.java
+++ /dev/null
@@ -1,20 +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;
-
-/**
- *
- * @author yaqiang
- */
-public enum MouseMode {
- DEFAULT,
- ZOOM_IN,
- ZOOM_OUT,
- SELECT,
- PAN,
- IDENTIFER,
- ROTATE
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/PointSelectedEvent.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/PointSelectedEvent.java
deleted file mode 100644
index 26262fb6..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/PointSelectedEvent.java
+++ /dev/null
@@ -1,31 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.chart;
-
-import java.util.EventObject;
-
-/**
- * Size changed event
- *
- * @author Yaqiang Wang
- */
-public class PointSelectedEvent extends EventObject {
- /**
- * Constructor
- * @param source Source object
- */
- public PointSelectedEvent(Object source){
- super(source);
- }
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/Axis.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/Axis.java
deleted file mode 100644
index 3c65f6dc..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/Axis.java
+++ /dev/null
@@ -1,1958 +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.axis;
-
-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.Stroke;
-import java.awt.geom.Line2D;
-import java.awt.geom.Rectangle2D;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.List;
-import org.meteoinfo.chart.ChartText;
-import org.meteoinfo.chart.Location;
-import org.meteoinfo.chart.plot.AbstractPlot2D;
-import org.meteoinfo.common.DataConvert;
-import org.meteoinfo.common.MIMath;
-import org.meteoinfo.common.XAlign;
-import org.meteoinfo.common.YAlign;
-import org.meteoinfo.common.util.JDateUtil;
-import org.meteoinfo.drawing.Draw;
-import org.meteoinfo.geometry.legend.LineStyles;
-import org.meteoinfo.ndarray.util.BigDecimalUtil;
-
-/**
- *
- * @author yaqiang
- */
-public class Axis implements Cloneable {
-
- //
- protected boolean xAxis;
- protected Location location;
- protected ChartText label;
- protected boolean visible;
- protected boolean drawTickLine;
- protected boolean drawTickLabel;
- protected boolean drawLabel;
- protected Color lineColor;
- protected float lineWidth;
- protected LineStyles lineStyle;
- //private Stroke lineStroke;
- protected Color tickColor;
- protected Stroke tickStroke;
- protected float tickLength;
- protected boolean insideTick;
- protected Font tickLabelFont;
- protected Color tickLabelColor;
- protected float tickLabelAngle;
- protected int tickLabelGap;
- protected double tickStartValue;
- protected double tickDeltaValue;
- protected double minValue;
- protected double maxValue;
- protected double[] tickValues;
- //private boolean timeAxis;
- //private String timeFormat;
- //private TimeUnit timeUnit;
- protected boolean inverse;
- //private float shift;
- protected List tickLocations;
- //private List tickLabels;
- protected List tickLabels;
- protected boolean autoTick;
- protected boolean minorTickVisible;
- protected int minorTickNum;
- protected int tickSpace;
- protected PositionType positionType;
- protected float position;
-
- //
- //
- /**
- * Constructor
- */
- public Axis() {
- this.xAxis = true;
- this.label = null;
- this.visible = true;
- this.drawTickLine = true;
- this.drawTickLabel = true;
- this.drawLabel = false;
- this.lineColor = Color.black;
- this.lineWidth = 1.0f;
- this.lineStyle = LineStyles.SOLID;
- //this.lineStroke = new BasicStroke(1.0f);
- this.tickColor = Color.black;
- this.tickStroke = new BasicStroke(1.0f);
- this.tickLength = 5;
- this.insideTick = true;
- this.tickLabelFont = new Font("Arial", Font.PLAIN, 14);
- this.tickLabelColor = Color.black;
- this.tickLabelAngle = 0;
- this.tickLabelGap = 1;
- this.minValue = 0;
- this.maxValue = 1;
- this.updateTickValues();
- //this.timeAxis = false;
- //this.timeFormat = "yyyy-MM-dd";
- //this.timeUnit = TimeUnit.DAY;
- this.inverse = false;
- //this.shift = 0;
- this.tickLocations = new ArrayList<>();
- this.tickLabels = new ArrayList<>();
- this.autoTick = true;
- this.minorTickVisible = false;
- this.minorTickNum = 5;
- this.tickSpace = 5;
- this.positionType = PositionType.OUTERWARD;
- this.position = 0;
- }
-
- /**
- * Constructor
- *
- * @param label Axis label
- */
- public Axis(ChartText label) {
- this();
- this.label = label;
- }
-
- /**
- * Constructor
- *
- * @param label Axis label
- */
- public Axis(String label) {
- this();
- this.label = new ChartText(label);
- }
-
- /**
- * Constructor
- *
- * @param label Axis label
- * @param xAxis If is x axis
- */
- public Axis(String label, boolean xAxis) {
- this(label);
- this.xAxis = xAxis;
- if (this.xAxis) {
- this.location = Location.BOTTOM;
- } else {
- this.location = Location.LEFT;
- }
- }
-
- /**
- * Constructor
- *
- * @param label Axis label
- * @param xAxis If is x axis
- */
- public Axis(ChartText label, boolean xAxis) {
- this(label);
- this.xAxis = xAxis;
- if (this.xAxis) {
- this.location = Location.BOTTOM;
- } else {
- this.location = Location.LEFT;
- }
- }
-
- /**
- * Constructor
- *
- * @param label Axis label
- * @param xAxis If is x axis
- * @param loc Location
- */
- public Axis(String label, boolean xAxis, Location loc) {
- this(label);
- this.xAxis = xAxis;
- this.location = loc;
- }
-
- /**
- * Constructor
- *
- * @param label Axis label
- * @param xAxis If is x axis
- * @param loc Location
- * @param drawTickLabel If draw tick label
- */
- public Axis(String label, boolean xAxis, Location loc, boolean drawTickLabel) {
- this(label);
- this.xAxis = xAxis;
- this.location = loc;
- this.drawTickLabel = drawTickLabel;
- }
-
- /**
- * Constructor
- *
- * @param axis Axis
- */
- public Axis(Axis axis) {
- this(axis.getLabel(), axis.isXAxis());
- this.autoTick = axis.isAutoTick();
- this.drawLabel = axis.isDrawLabel();
- this.drawTickLabel = axis.isDrawTickLabel();
- this.drawTickLine = axis.isDrawTickLine();
- this.insideTick = axis.isInsideTick();
- this.inverse = axis.isInverse();
- this.label.setColor(axis.getLabelColor());
- this.lineWidth = axis.getLineWidth();
- this.lineStyle = axis.getLineStyle();
- //this.setLineStroke(axis.getLineStroke());
- this.location = axis.getLocation();
- this.maxValue = axis.getMaxValue();
- this.minValue = axis.getMinValue();
- this.minorTickNum = axis.getMinorTickNum();
- this.minorTickVisible = axis.isMinorTickVisible();
- //this.shift = axis.getShift();
- this.tickColor = axis.getTickColor();
- this.tickDeltaValue = axis.getTickDeltaValue();
- this.tickLabelColor = axis.getTickLabelColor();
- this.tickLabelFont = axis.getTickLabelFont();
- this.tickLength = axis.getTickLength();
- this.visible = axis.isVisible();
- this.position = axis.getPosition();
- this.positionType = axis.getPositionType();
- }
-
- //
- //
- /**
- * Get if is x axis
- *
- * @return Boolean
- */
- public boolean isXAxis() {
- return this.xAxis;
- }
-
- /**
- * Set if is x axis
- *
- * @param value Boolean
- */
- public void setXAxis(boolean value) {
- this.xAxis = value;
- }
-
- /**
- * Get location
- *
- * @return Location
- */
- public Location getLocation() {
- return this.location;
- }
-
- /**
- * Set location
- *
- * @param value Location
- */
- public void setLocation(Location value) {
- this.location = value;
- }
-
- /**
- * Get axis label
- *
- * @return Axis label
- */
- public ChartText getLabel() {
- return label;
- }
-
- /**
- * Set axis label
- *
- * @param value Axis label
- */
- public void setLabel(ChartText value) {
- label = value;
- if (label != null && (this.location == Location.BOTTOM || this.location == Location.LEFT)) {
- this.drawLabel = true;
- }
- }
-
- /**
- * Set axis label
- *
- * @param value Axis label
- */
- public void setLabel(String value) {
- ChartText text = new ChartText(value);
- if (this.xAxis) {
- text.setXAlign(XAlign.CENTER);
- text.setYAlign(YAlign.TOP);
- } else {
- text.setAngle(90);
- text.setXAlign(XAlign.CENTER);
- text.setYAlign(YAlign.BOTTOM);
- }
- setLabel(text);
- }
-
- /**
- * If is visible
- *
- * @return Boolean
- */
- public boolean isVisible() {
- return visible;
- }
-
- /**
- * Set if is visible
- *
- * @param value Boolean
- */
- public void setVisible(boolean value) {
- visible = value;
- }
-
- /**
- * Get if draw tick lines
- *
- * @return Boolean
- */
- public boolean isDrawTickLine() {
- return this.drawTickLine;
- }
-
- /**
- * Set if draw tick lines
- *
- * @param value Boolean
- */
- public void setDrawTickLine(boolean value) {
- this.drawTickLine = value;
- }
-
- /**
- * Get is draw tick label
- *
- * @return Boolean
- */
- public boolean isDrawTickLabel() {
- return this.drawTickLabel;
- }
-
- /**
- * Set if draw tick label
- *
- * @param value Boolean
- */
- public void setDrawTickLabel(boolean value) {
- this.drawTickLabel = value;
- }
-
- /**
- * Get if draw label
- *
- * @return Boolean
- */
- public boolean isDrawLabel() {
- return this.drawLabel;
- }
-
- /**
- * Set if draw label
- *
- * @param value Boolean
- */
- public void setDrawLabel(boolean value) {
- this.drawLabel = value;
- }
-
- /**
- * Get line color
- *
- * @return Line color
- */
- public Color getLineColor() {
- return lineColor;
- }
-
- /**
- * Set line color
- *
- * @param value Line color
- */
- public void setLineColor(Color value) {
- lineColor = value;
- }
-
- /**
- * Get line width
- *
- * @return Line width
- */
- public float getLineWidth() {
- return this.lineWidth;
- }
-
- /**
- * Set line width
- *
- * @param value Line width
- */
- public void setLineWidth(float value) {
- this.lineWidth = value;
- }
-
- public LineStyles getLineStyle() {
- return this.lineStyle;
- }
-
- public void setLineStyle(LineStyles value) {
- this.lineStyle = value;
- }
-
- /**
- * Get line stroke
- *
- * @return Line stroke
- */
- public Stroke getLineStroke() {
- return new BasicStroke(this.lineWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER,
- 10.0f, Draw.getDashPattern(lineStyle), 0.0f);
- }
-
-// /**
-// * Set line stroke
-// *
-// * @param value Line stroke
-// */
-// public void setLineStroke(Stroke value) {
-// lineStroke = value;
-// }
- /**
- * Get tick color
- *
- * @return Tick color
- */
- public Color getTickColor() {
- return tickColor;
- }
-
- /**
- * Set tick color
- *
- * @param value Tick color
- */
- public void setTickColor(Color value) {
- tickColor = value;
- }
-
- /**
- * Get tick stroke
- *
- * @return Tick stroke
- */
- public Stroke getTickStroke() {
- return tickStroke;
- }
-
- /**
- * Set tick stroke
- *
- * @param value Tick stroke
- */
- public void setTickStroke(Stroke value) {
- tickStroke = value;
- }
-
- /**
- * Get tick length
- *
- * @return Tick length
- */
- public float getTickLength() {
- return this.tickLength;
- }
-
- /**
- * Set tick length
- *
- * @param value Tick length
- */
- public void setTickLength(float value) {
- this.tickLength = value;
- }
-
- /**
- * Get if is inside tick
- *
- * @return Boolean
- */
- public boolean isInsideTick() {
- return this.insideTick;
- }
-
- /**
- * Set if is inside tick
- *
- * @param value Boolean
- */
- public void setInsideTick(boolean value) {
- this.insideTick = value;
- }
-
- /**
- * Get label font
- *
- * @return Label font
- */
- public Font getLabelFont() {
- return this.label.getFont();
- }
-
- /**
- * Set lable font
- *
- * @param value Lable font
- */
- public void setLabelFont(Font value) {
- this.label.setFont(value);
- }
-
- /**
- * Get label color
- *
- * @return Label color
- */
- public Color getLabelColor() {
- return this.label.getColor();
- }
-
- /**
- * Set label color
- *
- * @param value Label color
- */
- public void setLabelColor(Color value) {
- this.label.setColor(value);
- }
-
- /**
- * Get tick label font
- *
- * @return Tick label font
- */
- public Font getTickLabelFont() {
- return tickLabelFont;
- }
-
- /**
- * Set tick lable font
- *
- * @param value Tick lable font
- */
- public void setTickLabelFont(Font value) {
- tickLabelFont = value;
- }
-
- /**
- * Get tick label color
- *
- * @return Tick label color
- */
- public Color getTickLabelColor() {
- return tickLabelColor;
- }
-
- /**
- * Set tick label color
- *
- * @param value Tick label color
- */
- public void setTickLabelColor(Color value) {
- tickLabelColor = value;
- }
-
- /**
- * Get tick label angle
- *
- * @return Tick label angle
- */
- public float getTickLabelAngle() {
- return this.tickLabelAngle;
- }
-
- /**
- * Set tick label angle
- *
- * @param value Angle
- */
- public void setTickLabelAngle(float value) {
- this.tickLabelAngle = value;
- }
-
- /**
- * Get tick label gap
- *
- * @return Tick label gap
- */
- public int getTickLabelGap() {
- return this.tickLabelGap;
- }
-
- /**
- * Set tick label gap
- *
- * @param value Tick label gap
- */
- public void setTickLabelGap(int value) {
- this.tickLabelGap = value;
- }
-
- /**
- * Get tick start value
- *
- * @return Tick start value
- */
- public double getTickStartValue() {
- return this.tickStartValue;
- }
-
- /**
- * Set tick start value
- *
- * @param value Tick start value
- */
- public void setTickStartValue(double value) {
- this.tickStartValue = value;
- }
-
- /**
- * Get tick delta value
- *
- * @return Tick delta value
- */
- public double getTickDeltaValue() {
- return this.tickDeltaValue;
- }
-
- /**
- * Set tick delta value
- *
- * @param value Tick delta value
- */
- public void setTickDeltaValue(double value) {
- this.tickDeltaValue = value;
- }
-
- /**
- * Get minimum value
- *
- * @return Minimum value
- */
- public double getMinValue() {
- return this.minValue;
- }
-
- /**
- * Set minimum value
- *
- * @param value Minimum value
- */
- public void setMinValue(double value) {
- this.minValue = value;
- }
-
- /**
- * Get maximum value
- *
- * @return Maximum value
- */
- public double getMaxValue() {
- return this.maxValue;
- }
-
- /**
- * Set maximum value
- *
- * @param value Maximum value
- */
- public void setMaxValue(double value) {
- this.maxValue = value;
- }
-
- /**
- * Get tick values
- *
- * @return Tick values
- */
- public double[] getTickValues() {
- if (this.autoTick) {
- return this.tickValues;
- } else {
- List values = new ArrayList<>();
- for (double v : this.tickLocations) {
- if (v >= this.minValue && v <= this.maxValue) {
- values.add(v);
- }
- }
- double[] vs = new double[values.size()];
- for (int i = 0; i < values.size(); i++) {
- vs[i] = values.get(i);
- }
- return vs;
- }
- }
-
- /**
- * Set tick values
- *
- * @param value Tick values
- */
- public void setTickValues(double[] value) {
- this.tickValues = value;
- if (value.length > 1) {
- this.tickDeltaValue = BigDecimalUtil.sub(value[1], value[0]);
- } else {
- this.tickDeltaValue = 0;
- }
- }
-
- /**
- * Set tick values
- *
- * @param value Tick value list
- */
- public void setTickValues(List value) {
- this.tickValues = new double[value.size()];
- for (int i = 0; i < value.size(); i++) {
- this.tickValues[i] = value.get(i);
- }
- if (value.size() > 1) {
- this.tickDeltaValue = BigDecimalUtil.sub(value.get(1), value.get(0));
- } else {
- this.tickDeltaValue = 0;
- }
- }
-
-// /**
-// * 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
- *
- * @return Boolean
- */
- public boolean isInverse() {
- return this.inverse;
- }
-
- /**
- * Set if is inverse
- *
- * @param value Boolean
- */
- public void setInverse(boolean value) {
- 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
- *
- * @return Tick locations
- */
- public List getTickLocations() {
- return this.tickLocations;
- }
-
- /**
- * Set tick locations
- *
- * @param value Tick locations
- */
- public void setTickLocations(List value) {
- this.tickLocations.clear();
- this.tickLabels.clear();
- for (Number v : value) {
- this.tickLocations.add(v.doubleValue());
- this.tickLabels.add(new ChartText(String.valueOf(v)));
- }
- this.autoTick = false;
- }
-
- /**
- * Set tick locations
- *
- * @param value Tick locations
- */
- public void setTickLocations(double[] value) {
- this.tickLocations.clear();
- this.tickLabels.clear();
- String tick;
- for (double v : value) {
- this.tickLocations.add(v);
- tick = String.valueOf(v);
- tick = DataConvert.removeTailingZeros(tick);
- this.tickLabels.add(new ChartText(tick));
- }
- this.autoTick = false;
- }
-
- /**
- * Get tick labels
- *
- * @return Tick labels
- */
- public List getTickLabels() {
- return this.tickLabels;
- }
-
- /**
- * Get tick label text
- *
- * @return Tick label text
- */
- public List getTickLabelText() {
- List strs = new ArrayList<>();
- for (ChartText ct : this.tickLabels) {
- strs.add(ct.toString());
- }
-
- return strs;
- }
-
- /**
- * Set tick label text
- *
- * @param value Tick label text
- */
- public void setTickLabelText(List value) {
- this.tickLabels = new ArrayList<>();
- for (String v : value) {
- this.tickLabels.add(new ChartText(v));
- }
- this.autoTick = false;
- }
-
- /**
- * Set tick labels.
- *
- * @param value Tick labels
- */
- public void setTickLabels(List value) {
- this.tickLabels = value;
- }
-
- /**
- * Set tick labels
- *
- * @param value Tick labels
- */
- public void setTickLabels_Number(List value) {
- this.tickLabels = new ArrayList<>();
- for (Number v : value) {
- this.tickLabels.add(new ChartText(v.toString()));
- }
- this.autoTick = false;
- }
-
- /**
- * Get if is auto tick labels
- *
- * @return Boolean
- */
- public boolean isAutoTick() {
- return this.autoTick;
- }
-
- /**
- * Set if auto tick labels
- *
- * @param value Boolean
- */
- public void setAutoTick(boolean value) {
- this.autoTick = value;
- }
-
- /**
- * Get if minor tick visible or not
- *
- * @return Boolean
- */
- public boolean isMinorTickVisible() {
- return this.minorTickVisible;
- }
-
- /**
- * Set if minor tick visible or not
- *
- * @param value Boolean
- */
- public void setMinorTickVisible(boolean value) {
- this.minorTickVisible = value;
- }
-
- /**
- * Get minor tick number
- *
- * @return Minor tick number
- */
- public int getMinorTickNum() {
- return this.minorTickNum;
- }
-
- /**
- * Set minor tick number
- *
- * @param value Minor tick number
- */
- public void setMinorTickNum(int value) {
- this.minorTickNum = value;
- }
-
- /**
- * Get tick space
- * @return Tick space
- */
- public int getTickSpace(){
- return this.tickSpace;
- }
-
- /**
- * Set tick space
- * @param value Tick space
- */
- public void setTickSpace(int value){
- this.tickSpace = value;
- }
-
- /**
- * Get position type
- * @return PositionType
- */
- public PositionType getPositionType() {
- return this.positionType;
- }
-
- /**
- * Set position type
- * @param value PositionType
- */
- public void setPositionType(PositionType value) {
- this.positionType = value;
- }
-
- /**
- * Set position type
- * @param value Position type string
- */
- public void setPositionType(String value) {
- this.positionType = PositionType.valueOf(value.toUpperCase());
- }
-
- /**
- * Get position value
- * @return Position value
- */
- public float getPosition() {
- return this.position;
- }
-
- /**
- * Set position value
- * @param value Position value
- */
- public void setPosition(float value) {
- this.position = value;
- }
- //
- //
-
- /**
- * Set minimum and maximum values
- *
- * @param minValue Start value
- * @param maxValue End value
- */
- public void setMinMaxValue(double minValue, double maxValue) {
- this.minValue = minValue;
- this.maxValue = maxValue;
- if (Double.isNaN(minValue) || Double.isNaN(maxValue)) {
- return;
- }
-
- updateTickValues();
-// if (this.timeAxis) {
-// this.updateTimeLabels();
-// } else {
-// tickValues = MIMath.getIntervalValues(minValue, maxValue);
-// }
- }
-
- /**
- * Update tick values
- */
- public void updateTickValues() {
- List
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/AxisProperty.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/AxisProperty.java
deleted file mode 100644
index b39183c7..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/AxisProperty.java
+++ /dev/null
@@ -1,95 +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.axis;
-
-/**
- *
- * @author yaqiang
- */
-public class AxisProperty {
- //
- private boolean visible;
- private boolean drawTick;
- private boolean drawLabel;
- //
- //
- /**
- * Constructor
- */
- public AxisProperty(){
- this.visible = true;
- this.drawTick = true;
- this.drawLabel = true;
- }
-
- /**
- * Constructor
- * @param visible Is visible
- * @param drawTick Is draw tick
- * @param drawLabel Is draw label
- */
- public AxisProperty(boolean visible, boolean drawTick, boolean drawLabel){
- this.visible = visible;
- this.drawTick = drawTick;
- this.drawLabel = drawLabel;
- }
- //
- //
- /**
- * If is visible
- *
- * @return Boolean
- */
- public boolean isVisible() {
- return visible;
- }
-
- /**
- * Set if is visible
- *
- * @param value Boolean
- */
- public void setVisible(boolean value) {
- visible = value;
- }
-
- /**
- * Get if draw tick lines
- * @return Boolean
- */
- public boolean isDrawTick(){
- return this.drawTick;
- }
-
- /**
- * Set if draw tick lines
- * @param value Boolean
- */
- public void setDrawTick(boolean value){
- this.drawTick = value;
- }
-
- /**
- * Get if draw label
- *
- * @return Boolean
- */
- public boolean isDrawLabel() {
- return this.drawLabel;
- }
-
- /**
- * Set if draw label
- *
- * @param value Boolean
- */
- public void setDrawLabel(boolean value) {
- this.drawLabel = value;
- }
- //
- //
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/LogAxis.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/LogAxis.java
deleted file mode 100644
index 1bcd167a..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/LogAxis.java
+++ /dev/null
@@ -1,83 +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.axis;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.meteoinfo.chart.ChartText;
-import org.meteoinfo.common.DataConvert;
-import org.meteoinfo.common.MIMath;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class LogAxis extends Axis {
- //
- //
- //
- /**
- * Constructor
- * @param axis Axis
- */
- public LogAxis(Axis axis){
- super(axis);
- }
- //
- //
- //
- //
- /**
- * Update tick values
- */
- @Override
- public void updateTickValues() {
- double[] r = MIMath.getIntervalValues_Log(this.getMinValue(), this.getMaxValue());
- this.setTickValues((double[]) r);
- this.setTickDeltaValue(1);
- }
-
- @Override
- public void updateTickLabels(){
- List tls = new ArrayList<>();
- String lab;
- if (this.isAutoTick()) {
- if (this.getTickValues() == null) {
- return;
- }
- for (double value : this.getTickValues()) {
- lab = String.valueOf(value);
- lab = DataConvert.removeTailingZeros(lab);
- tls.add(new ChartText(lab));
- }
-
- List values = new ArrayList<>();
- for (ChartText tl : tls){
- values.add(Double.parseDouble(tl.getText()));
- }
- tls.clear();
- int e;
- for (Double v : values){
- e = (int) Math.floor(Math.log10(v));
- tls.add(new ChartText("$10^{" + String.valueOf(e) + "}$"));
- }
- } else {
- for (int i = 0; i < this.getTickLocations().size(); i++) {
- if (i >= this.getTickLabels().size()) {
- break;
- }
- double v = this.getTickLocations().get(i);
- if (v >= this.getMinValue() && v <= this.getMaxValue()) {
- tls.add(this.getTickLabels().get(i));
- }
- }
- }
-
- this.setTickLabels(tls);
- }
-
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/LonLatAxis.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/LonLatAxis.java
deleted file mode 100644
index f86fe715..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/LonLatAxis.java
+++ /dev/null
@@ -1,182 +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.axis;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.meteoinfo.chart.ChartText;
-import org.meteoinfo.common.DataConvert;
-
-/**
- *
- * @author wyq
- */
-public class LonLatAxis extends Axis implements Cloneable {
-
- private boolean drawDegreeSymbol;
- private boolean longitude;
- private boolean degreeSpace;
-
- /**
- * Constructor
- * @param label Axis label
- * @param isX Is x axis or not
- * @param longitude Is longitude or not
- */
- public LonLatAxis(String label, boolean isX, boolean longitude){
- super(label, isX);
-
- this.drawDegreeSymbol = true;
- this.longitude = longitude;
- this.degreeSpace = false;
- }
-
- /**
- * Constructor
- * @param label Axis label
- * @param isX Is x axis or not
- */
- public LonLatAxis(String label, boolean isX){
- this(label, isX, isX);
- }
-
- /**
- * Constructor
- * @param axis Axis
- */
- public LonLatAxis(Axis axis) {
- this(axis.getLabel().getText(), axis.isXAxis());
- this.autoTick = axis.autoTick;
- this.drawLabel = axis.drawLabel;
- this.drawTickLabel = axis.drawTickLabel;
- this.drawTickLine = axis.drawTickLine;
- this.insideTick = axis.insideTick;
- this.inverse = axis.inverse;
- this.setLabelColor(axis.getLabelColor());
- this.lineWidth = axis.lineWidth;
- this.lineStyle = axis.lineStyle;
- this.location = axis.location;
- this.maxValue = axis.maxValue;
- this.minValue = axis.minValue;
- this.minorTickNum = axis.minorTickNum;
- this.minorTickVisible = axis.minorTickVisible;
- //this.setShift(axis.getShift());
- this.tickColor = axis.tickColor;
- this.tickDeltaValue = axis.tickDeltaValue;
- this.tickLabelColor = axis.tickLabelColor;
- this.tickLabelFont = axis.tickLabelFont;
- this.tickLength = axis.tickLength;
- this.visible = axis.visible;
- this.positionType = axis.positionType;
- this.position = axis.position;
- }
-
- /**
- * Get if draw degree symbol
- * @return Boolean
- */
- public boolean isDrawDegreeSymbol(){
- return this.drawDegreeSymbol;
- }
-
- /**
- * Set if draw degree symbol
- * @param value Boolean
- */
- public void setDrawDegreeSymbol(boolean value){
- this.drawDegreeSymbol = value;
- }
-
- /**
- * Get is longitude or not
- * @return Longitude or not
- */
- public boolean isLongitude(){
- return this.longitude;
- }
-
- /**
- * Set is longitude or not
- * @param value Longitude or not
- */
- public void setLongitude(boolean value){
- this.longitude = 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;
- }
-
- /**
- * Get tick labels
- *
- */
- @Override
- public void updateTickLabels() {
- List tls = new ArrayList<>();
- String lab;
- for (double v : this.getTickValues()) {
- double value = v;
- if (value > 180) {
- value = value - 360;
- }
- lab = String.valueOf(value);
- lab = DataConvert.removeTailingZeros(lab);
- if (this.isLongitude()) {
- if (value == -180) {
- lab = "180";
- } else if (!(value == 0 || value == 180)) {
- if (lab.substring(0, 1).equals("-")) {
- lab = lab.substring(1) + "W";
- } else {
- lab = lab + "E";
- }
- }
- } else {
- if (!(value == 0)) {
- if (lab.substring(0, 1).equals("-")) {
- lab = lab.substring(1) + "S";
- } else {
- lab = lab + "N";
- }
- }
- }
- if (drawDegreeSymbol) {
- if (lab.endsWith("E") || lab.endsWith("W") || lab.endsWith("N") || lab.endsWith("S")) {
- if (degreeSpace) {
- lab = lab.substring(0, lab.length() - 1) + String.valueOf((char) 186) + " " +
- lab.substring(lab.length() - 1);
- } else {
- lab = lab.substring(0, lab.length() - 1) + String.valueOf((char) 186) +
- lab.substring(lab.length() - 1);
- }
- } else {
- lab = lab + String.valueOf((char) 186);
- }
- }
- tls.add(new ChartText(lab));
- }
-
- this.setTickLabels(tls);
- }
-
- @Override
- public Object clone() throws CloneNotSupportedException {
- return (LonLatAxis)super.clone();
- }
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/PositionType.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/PositionType.java
deleted file mode 100644
index 713f7996..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/PositionType.java
+++ /dev/null
@@ -1,16 +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.axis;
-
-/**
- *
- * @author yaqiang
- */
-public enum PositionType {
- OUTERWARD,
- AXES,
- DATA
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/ProjLonLatAxis.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/ProjLonLatAxis.java
deleted file mode 100644
index afce49b4..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/ProjLonLatAxis.java
+++ /dev/null
@@ -1,174 +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.axis;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.meteoinfo.chart.ChartText;
-import org.meteoinfo.common.DataConvert;
-import org.meteoinfo.common.MIMath;
-import org.meteoinfo.projection.KnownCoordinateSystems;
-import org.meteoinfo.projection.ProjectionInfo;
-import org.meteoinfo.projection.Reproject;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class ProjLonLatAxis extends LonLatAxis{
- //
- private ProjectionInfo proj;
- private double x_y;
- //
- //
- /**
- * Constructor
- * @param label Label
- * @param isX Is x/longitude axis or not
- * @param proj Projection
- */
- public ProjLonLatAxis(String label, boolean isX, ProjectionInfo proj){
- super(label, isX, isX);
- this.proj = proj;
- }
-
- /**
- * Constructor
- * @param label Label
- * @param isX Is x/longitude axis or not
- * @param proj Projection
- * @param xy X or Y value of the axis - using for projection
- */
- public ProjLonLatAxis(String label, boolean isX, ProjectionInfo proj, double xy){
- super(label, isX);
- this.proj = proj;
- this.x_y = xy;
- }
- //
- //
- /**
- * Get projection
- * @return Projection
- */
- public ProjectionInfo getProject(){
- return this.proj;
- }
-
- /**
- * Set projection
- * @param value Projection
- */
- public void setProject(ProjectionInfo value){
- this.proj = value;
- }
-
- /**
- * Get x_y value
- * @return x_y value
- */
- public double getX_Y(){
- return this.x_y;
- }
-
- /**
- * Set x_y value
- * @param value x_y value
- */
- public void setX_Y(double value){
- this.x_y = value;
- //this.updateTickValues();
- }
- //
- //
- /**
- * Update tick values
- */
- @Override
- public void updateTickValues() {
- if (this.proj == null)
- return;
-
- double min = this.getMinValue();
- double max = this.getMaxValue();
- //Calculate min and max lon or lat
- ProjectionInfo toproj = KnownCoordinateSystems.geographic.world.WGS1984;
- double minv, maxv;
- double[][] points = new double[2][];
- if (this.isXAxis()){
- points[0] = new double[]{min, this.x_y};
- points[1] = new double[]{max, this.x_y};
- Reproject.reprojectPoints(points, this.proj, toproj);
- minv = points[0][0];
- maxv = points[1][0];
- } else {
- points[0] = new double[]{this.x_y, min};
- points[1] = new double[]{this.x_y, max};
- Reproject.reprojectPoints(points, this.proj, toproj);
- minv = points[0][1];
- maxv = points[1][1];
- }
- //Get tick values
- List
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/TimeAxis.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/TimeAxis.java
deleted file mode 100644
index 8694fa7c..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/TimeAxis.java
+++ /dev/null
@@ -1,379 +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.axis;
-
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.List;
-import org.meteoinfo.chart.ChartText;
-import org.meteoinfo.common.util.JDateUtil;
-
-/**
- *
- * @author wyq
- */
-public class TimeAxis extends Axis implements Cloneable {
-
- private String timeFormat;
- private TimeUnit timeUnit;
- private boolean varFormat;
-
- /**
- * Constructor
- *
- * @param label Axis label
- * @param xAxis If is x axis
- */
- public TimeAxis(String label, boolean xAxis) {
- super(label, xAxis);
-
- this.timeFormat = "yyyy-MM-dd";
- this.timeUnit = TimeUnit.DAY;
- this.varFormat = true;
- }
-
- /**
- * Constructor
- * @param axis Axis
- */
- public TimeAxis(Axis axis) {
- this(axis.getLabel().getText(), axis.isXAxis());
- this.autoTick = axis.autoTick;
- this.drawLabel = axis.drawLabel;
- this.drawTickLabel = axis.drawTickLabel;
- this.drawTickLine = axis.drawTickLine;
- this.insideTick = axis.insideTick;
- this.inverse = axis.inverse;
- this.setLabelColor(axis.getLabelColor());
- this.lineWidth = axis.lineWidth;
- this.lineStyle = axis.lineStyle;
- this.location = axis.location;
- this.maxValue = axis.maxValue;
- this.minValue = axis.minValue;
- this.minorTickNum = axis.minorTickNum;
- this.minorTickVisible = axis.minorTickVisible;
- //this.setShift(axis.getShift());
- this.tickColor = axis.tickColor;
- this.tickDeltaValue = axis.tickDeltaValue;
- this.tickLabelColor = axis.tickLabelColor;
- this.tickLabelFont = axis.tickLabelFont;
- this.tickLength = axis.tickLength;
- this.visible = axis.visible;
- this.positionType = axis.positionType;
- this.position = axis.position;
- }
-
- /**
- * 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;
- if (value.contains("s")) {
- this.timeUnit = TimeUnit.SECOND;
- } else if (value.contains("m")) {
- this.timeUnit = TimeUnit.MINUTE;
- } else if (value.contains("H")) {
- this.timeUnit = TimeUnit.HOUR;
- } else if (value.contains("d")) {
- this.timeUnit = TimeUnit.DAY;
- } else if (value.contains("M")) {
- this.timeUnit = TimeUnit.MONTH;
- } else {
- this.timeUnit = TimeUnit.YEAR;
- }
- this.varFormat = false;
- }
-
- /**
- * 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;
- }
-
- /**
- * If variable time format
- * @return Boolean
- */
- public boolean isVarFormat(){
- return this.varFormat;
- }
-
- /**
- * Set if variable format
- * @param value Boolean
- */
- public void setVarFormat(boolean value){
- this.varFormat = value;
- }
-
- /**
- * Get tick labels
- *
- */
- @Override
- public void updateTickLabels() {
- //this.updateTimeTickValues();
- List tls = new ArrayList<>();
- String lab;
- DateTimeFormatter format = DateTimeFormatter.ofPattern(this.timeFormat);
- LocalDateTime date;
- double[] tvs = this.getTickValues();
- if (tvs != null){
- for (double value : this.getTickValues()) {
- date = JDateUtil.fromOADate(value);
- lab = format.format(date);
- tls.add(new ChartText(lab));
- }
- }
-
- this.setTickLabels(tls);
- }
-
- /**
- * Update time tick values
- */
- @Override
- public void updateTickValues() {
- if (this.varFormat)
- updateTimeTickValues_var();
- else {
- if (this.timeUnit != null)
- updateTimeTickValues();
- }
- }
-
- /**
- * Update time tick values
- */
- private void updateTimeTickValues() {
- LocalDateTime sdate = JDateUtil.fromOADate(this.getMinValue());
- LocalDateTime edate = JDateUtil.fromOADate(this.getMaxValue());
- LocalDateTime ssdate = LocalDateTime.of(sdate.getYear(), sdate.getMonthValue(), sdate.getDayOfMonth(),
- sdate.getHour(), sdate.getMinute(), sdate.getSecond());
-
- List dates = new ArrayList<>();
- switch (this.timeUnit) {
- case YEAR:
- sdate = LocalDateTime.of(sdate.getYear(), 1, 1, 0, 0, 0);
- if (!sdate.isBefore(ssdate)) {
- dates.add(sdate);
- }
- while (!sdate.isAfter(edate)) {
- sdate = sdate.withYear(sdate.getYear() + 1);
- dates.add(sdate);
- }
- break;
- case MONTH:
- sdate = LocalDateTime.of(sdate.getYear(), sdate.getMonthValue(), 1, 0, 0, 0);
- if (!sdate.isBefore(ssdate)) {
- dates.add(sdate);
- }
- while (!sdate.isAfter(edate)) {
- sdate = sdate.plusMonths(1);
- if (!sdate.isBefore(ssdate)) {
- dates.add(sdate);
- }
- }
- break;
- case DAY:
- sdate = LocalDateTime.of(sdate.getYear(), sdate.getMonthValue(), sdate.getDayOfMonth(),
- 0, 0, 0);
- if (!sdate.isBefore(ssdate)) {
- dates.add(sdate);
- }
- while (!sdate.isAfter(edate)) {
- sdate = sdate.plusDays(1);
- if (sdate.isBefore(edate)) {
- dates.add(sdate);
- }
- }
- break;
- case HOUR:
- sdate = LocalDateTime.of(sdate.getYear(), sdate.getMonthValue(), sdate.getDayOfMonth(),
- sdate.getHour(), 0, 0);
- if (!sdate.isBefore(ssdate)) {
- dates.add(sdate);
- }
- while (!sdate.isAfter(edate)) {
- sdate = sdate.plusHours(1);
- if (sdate.isBefore(edate)) {
- dates.add(sdate);
- }
- }
- break;
- case MINUTE:
- sdate = ssdate.withSecond(0);
- if (!sdate.isBefore(ssdate)) {
- dates.add(sdate);
- }
- while (!sdate.isAfter(edate)) {
- sdate = sdate.plusMinutes(1);
- if (sdate.isBefore(edate)) {
- dates.add(sdate);
- }
- }
- break;
- case SECOND:
- if (!sdate.isBefore(ssdate)) {
- dates.add(sdate);
- }
- while (!sdate.isAfter(edate)) {
- sdate = sdate.plusSeconds(1);
- if (sdate.isBefore(edate)) {
- dates.add(sdate);
- }
- }
- break;
- }
-
- double[] tvs = new double[dates.size()];
- for (int i = 0; i < dates.size(); i++) {
- tvs[i] = JDateUtil.toOADate(dates.get(i));
- }
- this.setTickValues(tvs);
- }
-
- /**
- * Update time tick values
- */
- private void updateTimeTickValues_var() {
- LocalDateTime sdate = JDateUtil.fromOADate(this.getMinValue());
- LocalDateTime edate = JDateUtil.fromOADate(this.getMaxValue());
- LocalDateTime ssdate = sdate;
-
- List dates = new ArrayList<>();
- sdate = ssdate.plusYears(5);
- if (sdate.isBefore(edate)) {
- this.timeFormat = "yyyy";
- this.timeUnit = TimeUnit.YEAR;
- sdate = ssdate.withMonth(1);
- sdate = ssdate.withDayOfMonth(1);
- sdate = ssdate.withHour(0);
- sdate = ssdate.withMinute(0);
- sdate = ssdate.withSecond(0);
- if (!sdate.isBefore(ssdate)) {
- dates.add(sdate);
- }
- while (!sdate.isAfter(edate)) {
- sdate = sdate.plusYears(1);
- if (sdate.isBefore(edate))
- dates.add(sdate);
- }
- } else {
- sdate = ssdate.plusMonths(5);
- if (sdate.isBefore(edate)) {
- this.timeFormat = "M";
- this.timeUnit = TimeUnit.MONTH;
- sdate = ssdate.withDayOfMonth(1);
- sdate = ssdate.withHour(0);
- sdate = ssdate.withMinute(0);
- sdate = ssdate.withSecond(0);
- if (!sdate.isBefore(ssdate)) {
- dates.add(sdate);
- }
- while (!sdate.isAfter(edate)) {
- sdate = sdate.plusMonths(1);
- if (sdate.isBefore(edate))
- dates.add(sdate);
- }
- } else {
- sdate = ssdate.plusDays(5);
- if (sdate.isBefore(edate)) {
- this.timeFormat = "d";
- this.timeUnit = TimeUnit.DAY;
- sdate = ssdate.withHour(0);
- sdate = ssdate.withMinute(0);
- sdate = ssdate.withSecond(0);
- if (!sdate.isBefore(ssdate)) {
- dates.add(sdate);
- }
- while (!sdate.isAfter(edate)) {
- sdate = sdate.plusDays(1);
- if (sdate.isBefore(edate))
- dates.add(sdate);
- }
- } else {
- sdate = ssdate.plusHours(5);
- if (sdate.isBefore(edate)) {
- this.timeFormat = "H";
- this.timeUnit = TimeUnit.HOUR;
- sdate = ssdate.withMinute(0);
- sdate = ssdate.withSecond(0);
- if (!sdate.isBefore(ssdate)) {
- dates.add(sdate);
- }
- while (!sdate.isAfter(edate)) {
- sdate = sdate.plusHours(1);
- if (sdate.isBefore(edate))
- dates.add(sdate);
- }
- } else {
- sdate = ssdate.plusMinutes(5);
- if (sdate.isBefore(edate)) {
- this.timeFormat = "HH:mm";
- this.timeUnit = TimeUnit.MINUTE;
- sdate = ssdate.withSecond(0);
- if (!sdate.isBefore(ssdate)) {
- dates.add(sdate);
- }
- while (!sdate.isAfter(edate)) {
- sdate = sdate.plusMinutes(1);
- if (sdate.isBefore(edate))
- dates.add(sdate);
- }
- } else {
- this.timeFormat = "HH:mm:ss";
- this.timeUnit = TimeUnit.SECOND;
- if (!sdate.isBefore(ssdate)) {
- dates.add(sdate);
- }
- while (!sdate.isAfter(edate)) {
- sdate = sdate.plusSeconds(1);
- if (sdate.isBefore(edate))
- dates.add(sdate);
- }
- }
- }
- }
- }
- }
-
- double[] tvs = new double[dates.size()];
- for (int i = 0; i < dates.size(); i++) {
- tvs[i] = JDateUtil.toOADate(dates.get(i));
- }
- this.setTickValues(tvs);
- }
-
- @Override
- public Object clone() throws CloneNotSupportedException {
- return (TimeAxis) super.clone();
- }
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/TimeUnit.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/TimeUnit.java
deleted file mode 100644
index f5fca947..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/axis/TimeUnit.java
+++ /dev/null
@@ -1,19 +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.axis;
-
-/**
- *
- * @author yaqiang
- */
-public enum TimeUnit {
- YEAR,
- MONTH,
- DAY,
- HOUR,
- MINUTE,
- SECOND
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/AbstractPlot2D.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/AbstractPlot2D.java
deleted file mode 100644
index 7fcd0727..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/AbstractPlot2D.java
+++ /dev/null
@@ -1,1418 +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 java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.awt.RenderingHints;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Line2D;
-import java.awt.geom.Rectangle2D;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.meteoinfo.chart.ChartLegend;
-import org.meteoinfo.chart.ChartText;
-import org.meteoinfo.chart.ChartWindArrow;
-import org.meteoinfo.chart.LegendPosition;
-import org.meteoinfo.chart.Location;
-import org.meteoinfo.chart.Margin;
-import org.meteoinfo.chart.axis.Axis;
-import org.meteoinfo.chart.axis.LogAxis;
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.drawing.Draw;
-
-/**
- *
- * @author wyq
- */
-public abstract class AbstractPlot2D extends Plot {
-
- //
- protected Color background;
- //private boolean drawBackground;
- private Color selectColor = Color.yellow;
- private Extent extent;
- private Extent drawExtent;
- private final Map axis;
- private Location xAxisLocation;
- private Location yAxisLocation;
- private PlotOrientation orientation;
- private final GridLine gridLine;
- private boolean drawTopAxis;
- private boolean drawRightAxis;
- private boolean drawNeatLine;
- private ChartText title;
- private ChartText leftTitle;
- private ChartText rightTitle;
- private List legends;
- private List texts;
- private ChartWindArrow windArrow;
- private boolean autoAspect = true;
- private double aspect = 1;
- protected boolean clip = true;
-
- //
- //
- /**
- * Constructor
- */
- public AbstractPlot2D() {
- super();
- this.background = null;
- //this.drawBackground = false;
- this.drawExtent = new Extent(0, 1, 0, 1);
- //this.xAxis = new Axis("X", true);
- //this.yAxis = new Axis("Y", false);
- this.axis = new HashMap<>();
- this.axis.put(Location.BOTTOM, new Axis("X", true, Location.BOTTOM));
- this.axis.put(Location.LEFT, new Axis("Y", false, Location.LEFT));
- this.axis.put(Location.TOP, new Axis("X", true, Location.TOP, false));
- this.axis.put(Location.RIGHT, new Axis("Y", false, Location.RIGHT, false));
- this.xAxisLocation = Location.BOTTOM;
- this.yAxisLocation = Location.RIGHT;
- this.orientation = PlotOrientation.VERTICAL;
- this.gridLine = new GridLine();
- this.drawTopAxis = true;
- this.drawRightAxis = true;
- this.drawNeatLine = false;
- this.legends = new ArrayList<>();
- this.texts = new ArrayList<>();
- }
- //
-
- //
- /**
- * Get title
- *
- * @return Title
- */
- public ChartText getTitle() {
- return this.title;
- }
-
- /**
- * Set title
- *
- * @param value Title
- */
- public void setTitle(ChartText value) {
- this.title = value;
- }
-
- /**
- * Set title
- *
- * @param text Title text
- */
- public void setTitle(String text) {
- if (this.title == null) {
- this.title = new ChartText(text);
- } else {
- this.title.setText(text);
- }
- }
-
- /**
- * Get selected color
- *
- * @return Selected color
- */
- public Color getSelectedColor() {
- return this.selectColor;
- }
-
- /**
- * Set selected color
- *
- * @param value Selected color
- */
- public void setSelectedColor(Color value) {
- this.selectColor = value;
- }
-
- /**
- * Get left sub title
- *
- * @return Left sub title
- */
- public ChartText getLeftTitle() {
- return leftTitle;
- }
-
- /**
- * Set left sub title
- *
- * @param value Left sub title
- */
- public void setLeftTitle(ChartText value) {
- leftTitle = value;
- }
-
- /**
- * Set left sub title
- *
- * @param text Title text
- */
- public void setLeftTitle(String text) {
- if (this.leftTitle == null) {
- this.leftTitle = new ChartText(text);
- } else {
- this.leftTitle.setText(text);
- }
- }
-
- /**
- * Get right sub title
- *
- * @return Right sub title
- */
- public ChartText getRightTitle() {
- return rightTitle;
- }
-
- /**
- * Set right sub title
- *
- * @param value Right sub title
- */
- public void setRightTitle(ChartText value) {
- rightTitle = value;
- }
-
- /**
- * Set right sub title
- *
- * @param text Title text
- */
- public void setRightTitle(String text) {
- if (this.rightTitle == null) {
- this.rightTitle = new ChartText(text);
- } else {
- this.rightTitle.setText(text);
- }
- }
-
- /**
- * Get legends
- *
- * @return Legends
- */
- public List getLegends() {
- return this.legends;
- }
-
- /**
- * Get chart legend
- *
- * @param idx Index
- * @return Chart legend
- */
- public ChartLegend getLegend(int idx) {
- if (this.legends.isEmpty()) {
- return null;
- } else {
- return this.legends.get(idx);
- }
- }
-
- /**
- * Get chart legend
- *
- * @return Chart legend
- */
- public ChartLegend getLegend() {
- if (this.legends.isEmpty()) {
- return null;
- } else {
- return this.legends.get(this.legends.size() - 1);
- }
- }
-
- /**
- * Set chart legend
- *
- * @param value Legend
- */
- public void setLegend(ChartLegend value) {
- this.legends.clear();
- this.legends.add(value);
- }
-
- /**
- * Set legends
- *
- * @param value Legends
- */
- public void setLegends(List value) {
- this.legends = value;
- }
-
-// /**
-// * Get if draw legend
-// *
-// * @return If draw legend
-// */
-// public boolean isDrawLegend() {
-// return this.drawLegend;
-// }
-//
- /**
- * Set if draw legend
- *
- * @param value Boolean
- */
- public void setDrawLegend(boolean value) {
- //this.drawLegend = value;
- //this.updateLegendScheme();
- }
-
- /**
- * Get draw extent
- *
- * @return Draw extent
- */
- public Extent getDrawExtent() {
- return this.drawExtent;
- }
-
- /**
- * Set draw extent
- *
- * @param extent Extent
- */
- public void setDrawExtent(Extent extent) {
- this.drawExtent = 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);
- }
-
- /**
- * Set draw extent
- *
- * @param extent Extent
- */
- public void setDrawExtent1(Extent extent) {
- this.drawExtent = extent;
- }
-
- /**
- * Get extent
- *
- * @return Extent
- */
- public Extent getExtent() {
- return this.extent;
- }
-
- /**
- * Set extent
- *
- * @param extent Extent
- */
- public void setExtent(Extent extent) {
- this.extent = extent;
- }
-
- /**
- * Update draw extent
- */
- public void updateDrawExtent() {
- this.getAxis(Location.BOTTOM).setMinMaxValue(drawExtent.minX, drawExtent.maxX);
- this.getAxis(Location.TOP).setMinMaxValue(drawExtent.minX, drawExtent.maxX);
- this.getAxis(Location.LEFT).setMinMaxValue(drawExtent.minY, drawExtent.maxY);
- this.getAxis(Location.RIGHT).setMinMaxValue(drawExtent.minY, drawExtent.maxY);
- }
-
- /**
- * Get background
- *
- * @return Background
- */
- public Color getBackground() {
- return this.background;
- }
-
- /**
- * Set background
- *
- * @param value Background
- */
- public void setBackground(Color value) {
- this.background = value;
- }
-
-// /**
-// * Get if draw background
-// *
-// * @return Boolean
-// */
-// public boolean isDrawBackground() {
-// return this.drawBackground;
-// }
-
-// /**
-// * Set if draw background
-// *
-// * @param value Boolean
-// */
-// public void setDrawBackground(boolean value) {
-// this.drawBackground = value;
-// }
-
- @Override
- public PlotType getPlotType() {
- return PlotType.XY;
- }
-
- /**
- * Get bottom x axis
- *
- * @return Bottom x aixs
- */
- public Axis getXAxis() {
- return this.axis.get(Location.BOTTOM);
- }
-
- /**
- * Set x axis
- *
- * @param axis Axis
- * @throws java.lang.CloneNotSupportedException
- */
- public void setXAxis(Axis axis) throws CloneNotSupportedException {
- axis.setLocation(Location.BOTTOM);
- this.axis.put(Location.BOTTOM, axis);
- Axis topAxis = (Axis) axis.clone();
- topAxis.setLocation(Location.TOP);
- this.axis.put(Location.TOP, topAxis);
- }
-
- /**
- * Get left y axis
- *
- * @return Left y axis
- */
- public Axis getYAxis() {
- return this.axis.get(Location.LEFT);
- }
-
- /**
- * Set y axis
- *
- * @param axis Axis
- * @throws java.lang.CloneNotSupportedException
- */
- public void setYAxis(Axis axis) throws CloneNotSupportedException {
- axis.setLocation(Location.LEFT);
- this.axis.put(Location.LEFT, axis);
- Axis rightAxis = (Axis) axis.clone();
- rightAxis.setLocation(Location.RIGHT);
- this.axis.put(Location.RIGHT, rightAxis);
- }
-
- /**
- * Get axis
- *
- * @param loc Axis location
- * @return Axis
- */
- public Axis getAxis(Location loc) {
- return this.axis.get(loc);
- }
-
- /**
- * Get x axis location
- *
- * @return X axis location
- */
- public Location getXAxisLocation() {
- return this.xAxisLocation;
- }
-
- /**
- * Set x axis location
- *
- * @param value X axis location
- */
- public void setXAxisLocation(Location value) {
- this.xAxisLocation = value;
- }
-
- /**
- * Get y axis location
- *
- * @return Y axis location
- */
- public Location getYAxisLocation() {
- return this.yAxisLocation;
- }
-
- /**
- * Set y axis location
- *
- * @param value Y axis location
- */
- public void setYAxisLocation(Location value) {
- this.yAxisLocation = value;
- }
-
- /**
- * Get plot orientation
- *
- * @return Plot orientation
- */
- public PlotOrientation getPlotOrientation() {
- return this.orientation;
- }
-
- /**
- * Set plot orientation
- *
- * @param value Plot orientation
- */
- public void setPlotOrientation(PlotOrientation value) {
- this.orientation = value;
- }
-
- /**
- * Get grid line
- *
- * @return Grid line
- */
- public GridLine getGridLine() {
- return this.gridLine;
- }
-
- /**
- * get if draw top axis
- *
- * @return Boolean
- */
- public boolean isDrawTopAxis() {
- return this.drawTopAxis;
- }
-
- /**
- * Set if draw top right axis
- *
- * @param value Boolean
- */
- public void setDrawTopAxis(boolean value) {
- this.drawTopAxis = value;
- }
-
- /**
- * get if draw right axis
- *
- * @return Boolean
- */
- public boolean isDrawRightAxis() {
- return this.drawRightAxis;
- }
-
- /**
- * Set if draw right axis
- *
- * @param value Boolean
- */
- public void setDrawRightAxis(boolean value) {
- this.drawRightAxis = value;
- }
-
- /**
- * Get if draw neat line
- *
- * @return Boolean
- */
- public boolean isDrawNeatLine() {
- return this.drawNeatLine;
- }
-
- /**
- * Set if draw neat line
- *
- * @param value Boolean
- */
- public void setDrawNeatLine(boolean value) {
- this.drawNeatLine = value;
- }
-
- /**
- * Get texts
- *
- * @return Texts
- */
- public List getTexts() {
- return this.texts;
- }
-
- /**
- * Set texts
- *
- * @param value texts
- */
- public void setTexts(List value) {
- this.texts = value;
- }
-
- /**
- * Get wind arrow
- *
- * @return Wind arrow
- */
- public ChartWindArrow getWindArrow() {
- return this.windArrow;
- }
-
- /**
- * Set wind arrow
- *
- * @param value Wind arrow
- */
- public void setWindArrow(ChartWindArrow value) {
- this.windArrow = value;
- }
-
- /**
- * Get x axis is log or not
- *
- * @return Boolean
- */
- public boolean isLogX() {
- Axis xAxis = this.getXAxis();
- return xAxis instanceof LogAxis;
- }
-
- /**
- * Get y axis is log or not
- *
- * @return Boolean
- */
- public boolean isLogY() {
- Axis yAxis = this.getYAxis();
- return yAxis instanceof LogAxis;
- }
-
- /**
- * Get is auto aspect or not
- *
- * @return Boolean
- */
- public boolean isAutoAspect() {
- return this.autoAspect;
- }
-
- /**
- * Set is auto aspect or not
- *
- * @param value Boolean
- */
- public void setAutoAspect(boolean value) {
- this.autoAspect = value;
- }
-
- /**
- * Get aspect - scaling from data to plot units for x and y
- *
- * @return Aspect
- */
- public double getAspect() {
- return this.aspect;
- }
-
- /**
- * Set aspect
- *
- * @param value Aspect
- */
- public void setAspect(double value) {
- this.aspect = value;
- }
-
- /**
- * Get if y axis is reverse or not
- *
- * @return Boolean
- */
- public boolean isYReverse() {
- return this.getYAxis().isInverse();
- }
-
- /**
- * Get if x axis is reverse or not
- *
- * @return Boolean
- */
- public boolean isXReverse() {
- return this.getXAxis().isInverse();
- }
-
- /**
- * Get is clip axes or not
- * @return Boolean
- */
- public boolean isClip() {return this.clip;}
-
- /**
- * Set is clip axes or not
- * @param value Boolean
- */
- public void setClip(boolean value) {this.clip = value;}
-
- //
- //
- /**
- * Add a legend
- *
- * @param legend The legend
- */
- public void addLegend(ChartLegend legend) {
- this.legends.add(legend);
- }
-
- /**
- * Remove a legend
- *
- * @param legend The legend
- */
- public void removeLegend(ChartLegend legend) {
- this.legends.remove(legend);
- }
-
- /**
- * Remove a legend by index
- *
- * @param idx The legend index
- */
- public void removeLegend(int idx) {
- this.legends.remove(idx);
- }
-
- /**
- * Set axis
- *
- * @param axis The axis
- * @param loc Axis location
- */
- public void setAxis(Axis axis, Location loc) {
- this.axis.put(loc, axis);
- }
-
- /**
- * Set axis label font
- *
- * @param font Font
- */
- public void setAxisLabelFont(Font font) {
- for (Axis ax : this.axis.values()) {
- ax.setTickLabelFont(font);
- }
- }
-
- /**
- * Set all axis visible or not
- *
- * @param value Boolean
- */
- public void setAxisOn(boolean value) {
- for (Axis ax : this.axis.values()) {
- ax.setVisible(value);
- }
- }
-
- /**
- * Set axis tick line inside box or not
- *
- * @param isInside Inside box ot not
- */
- public void setInsideTick(boolean isInside) {
- this.getAxis(Location.LEFT).setInsideTick(isInside);
- this.getAxis(Location.RIGHT).setInsideTick(isInside);
- this.getAxis(Location.TOP).setInsideTick(isInside);
- this.getAxis(Location.BOTTOM).setInsideTick(isInside);
- }
-
- /**
- * Get is inside tick line or not
- *
- * @return Is inside or not
- */
- public boolean isInsideTick() {
- return this.getAxis(Location.BOTTOM).isInsideTick();
- }
-
- /**
- * Draw plot
- *
- * @param g Graphics2D
- * @param area Drawing area
- */
- @Override
- public void draw(Graphics2D g, Rectangle2D area) {
- // if the plot area is too small, just return...
- boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
- boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
- if (b1 || b2) {
- return;
- }
-
- Rectangle2D graphArea;
- graphArea = this.getPositionArea();
- this.setGraphArea(graphArea);
-
- //Draw title
- this.drawTitle(g, graphArea);
-
- if (graphArea.getWidth() < 10 || graphArea.getHeight() < 10) {
- return;
- }
-
- //Draw background
- if (this.background != null) {
- g.setColor(this.getBackground());
- g.fill(graphArea);
- }
-
- if (this.getGridLine().isTop()) {
- //Draw graph
- this.drawGraph(g, graphArea);
- //Draw grid line
- this.drawGridLine(g, graphArea);
- } else {
- //Draw grid line
- this.drawGridLine(g, graphArea);
- //Draw graph
- this.drawGraph(g, graphArea);
- }
-
- //Draw neat line
- if (this.drawNeatLine) {
- g.setStroke(new BasicStroke(1.0f));
- g.setColor(Color.black);
- g.draw(graphArea);
- }
-
- //Draw axis
- this.drawAxis(g, graphArea);
-
- //Draw text
- this.drawText(g, graphArea);
-
- //Draw legend
- this.drawLegend(g, area, graphArea);
-
- //Draw wind arrow - quiverkey
- if (this.getWindArrow() != null) {
- ChartWindArrow wa = this.getWindArrow();
- float x = (float) (area.getWidth() * wa.getX());
- float y = (float) (area.getHeight() * (1 - wa.getY()));
- wa.draw(g, x, y);
- }
- }
-
- /**
- * Get tight inset area
- *
- * @param g Graphics2D
- * @param positionArea Position area
- * @return Tight inset area
- */
- @Override
- public Margin getTightInset(Graphics2D g, Rectangle2D positionArea) {
- int left = 2, bottom = 2, right = 2, top = 10;
-
- top += this.getAxis(Location.TOP).getXAxisHeight(g);
- if (this.title != null) {
- top += this.title.getTrueDimension(g).height + 10;
- }
- if (this.leftTitle != null){
- top += this.leftTitle.getDimension(g).height + 5;
- } else {
- if (this.rightTitle != null){
- top += this.rightTitle.getDimension(g).height + 5;
- }
- }
-
- if (!this.legends.isEmpty()) {
- ChartLegend legend = this.getLegend();
- Dimension dim = legend.getLegendDimension(g, new Dimension((int) positionArea.getWidth(),
- (int) positionArea.getHeight()));
- switch (legend.getPosition()) {
- case UPPER_CENTER_OUTSIDE:
- top += dim.height + 10;
- break;
- case LOWER_CENTER_OUTSIDE:
- bottom += dim.height + 10;
- break;
- case LEFT_OUTSIDE:
- left += dim.width + 10;
- break;
- case RIGHT_OUTSIDE:
- right += dim.width + 10;
- break;
- }
- }
-
- //Get x axis space
- bottom += this.getXAxisHeight(g) + 5;
-
- //Get y axis space
- left += this.getYAxisWidth(g) + 5;
-
- //Set right space
- int radd = this.getAxis(Location.RIGHT).getYAxisWidth(g);
- if (this.getXAxis().isVisible()) {
- if (this.getXAxis().isDrawTickLabel()) {
- radd = Math.max(radd,this.getXAxis().getMaxLabelLength(g) / 2);
- }
- }
- right += radd;
-
- return new Margin(left, right, top, bottom);
- }
-
- /**
- * Get tight inset area
- *
- * @param g Graphics2D
- * @param positionArea Position area
- * @return Tight inset area
- */
- public Rectangle2D getTightInsetArea(Graphics2D g, Rectangle2D positionArea) {
- int left = 0, bottom = 0, right = 5, top = 5;
- int space = 1;
-
- if (this.title != null) {
- g.setFont(this.title.getFont());
- Dimension dim = Draw.getStringDimension(this.title.getText(), g);
- top += dim.getHeight() + 10;
- }
-
- if (!this.legends.isEmpty()) {
- ChartLegend legend = this.getLegend();
- Dimension dim = legend.getLegendDimension(g, new Dimension((int) positionArea.getWidth(),
- (int) positionArea.getHeight()));
- switch (legend.getPosition()) {
- case UPPER_CENTER_OUTSIDE:
- top += dim.height + 10;
- break;
- case LOWER_CENTER_OUTSIDE:
- bottom += dim.height + 10;
- break;
- case LEFT_OUTSIDE:
- left += dim.width + 10;
- break;
- case RIGHT_OUTSIDE:
- right += dim.width + 10;
- break;
- }
- }
-
- //Get x axis space
- bottom += this.getXAxisHeight(g);
-
- //Get y axis space
- left += this.getYAxisWidth(g);
-
- //Set right space
- if (this.getXAxis().isVisible()) {
- if (this.getXAxis().isDrawTickLabel()) {
- right += this.getXAxis().getMaxLabelLength(g) / 2;
- }
- }
-
- double x = positionArea.getX() - left;
- double y = positionArea.getY() - top;
- double w = positionArea.getWidth() + left + right;
- double h = positionArea.getHeight() + top + bottom;
-
- return new Rectangle2D.Double(x, y, w, h);
- }
-
- /**
- * Get position area
- *
- * @return Position area
- */
- @Override
- public Rectangle2D getPositionArea() {
- if (this.autoAspect) {
- return super.getPositionArea();
- } else {
- Rectangle2D plotArea = super.getPositionArea();
- double width = this.drawExtent.getWidth();
- double height = this.drawExtent.getHeight();
- if (width / height / aspect > plotArea.getWidth() / plotArea.getHeight()) {
- double h = plotArea.getWidth() * height * aspect / width;
- double delta = plotArea.getHeight() - h;
- plotArea.setRect(plotArea.getX(), plotArea.getY() + delta / 2, plotArea.getWidth(), h);
- } else {
- double w = width * plotArea.getHeight() / height / aspect;
- double delta = plotArea.getWidth() - w;
- plotArea.setRect(plotArea.getX() + delta / 2, plotArea.getY(), w, plotArea.getHeight());
- }
-
- return plotArea;
- }
- }
-
- /**
- * Get outer position area
- *
- * @param area Whole area
- * @return Position area
- */
- @Override
- public Rectangle2D getOuterPositionArea(Rectangle2D area) {
- Rectangle2D rect = this.getOuterPosition();
- double x = area.getWidth() * rect.getX() + area.getX();
- double y = area.getHeight() * (1 - rect.getHeight() - rect.getY()) + area.getY();
- double w = area.getWidth() * rect.getWidth();
- double h = area.getHeight() * rect.getHeight();
- return new Rectangle2D.Double(x, y, w, h);
- }
-
- /**
- * Get graphic area
- *
- * @param g Graphic2D
- * @param area Whole area
- * @return Graphic area
- */
- public Rectangle2D getGraphArea(Graphics2D g, Rectangle2D area) {
- int left = 5, bottom = 5, right = 5, top = 5;
- int space = 5;
-
- if (this.title != null) {
- top += this.title.getTrueDimension(g).height + 10;
- }
-
- if (!this.legends.isEmpty()) {
- ChartLegend legend = this.getLegend();
- Dimension dim = legend.getLegendDimension(g, new Dimension((int) area.getWidth(), (int) area.getHeight()));
- switch (legend.getPosition()) {
- case UPPER_CENTER_OUTSIDE:
- top += dim.height + 10;
- break;
- case LOWER_CENTER_OUTSIDE:
- bottom += dim.height + 10;
- break;
- case LEFT_OUTSIDE:
- left += dim.width + 10;
- break;
- case RIGHT_OUTSIDE:
- right += dim.width + 10;
- break;
- }
- }
-
- //Get x axis space
- bottom += this.getXAxisHeight(g);
-
- //Get y axis space
- left += this.getYAxisWidth(g);
-
- //Set right space
- if (this.getXAxis().isVisible()) {
- if (this.getXAxis().isDrawTickLabel()) {
- right += this.getXAxis().getMaxLabelLength(g) / 2;
- }
- }
-
- //Set area
- Rectangle2D plotArea = new Rectangle2D.Double(left, top,
- area.getWidth() - left - right, area.getHeight() - top - bottom);
- return plotArea;
- }
-
- int getXAxisHeight(Graphics2D g) {
- return this.getXAxis().getXAxisHeight(g);
- }
-
- int getYAxisWidth(Graphics2D g) {
- return this.getYAxis().getYAxisWidth(g);
- }
-
- int getTopAxisHeight(Graphics2D g) {
- int height = this.getAxis(Location.TOP).getXAxisHeight(g);
- return height;
- }
-
- void drawTitle(Graphics2D g, Rectangle2D graphArea) {
- float x;
- float y = (float) graphArea.getY() - this.getTopAxisHeight(g);
- int sh = 0;
- if (leftTitle != null) {
- x = (float) graphArea.getX();
- y -= 5;
- leftTitle.draw(g, x, y);
- y += 5;
- sh = leftTitle.getDimension(g).height + 5;
- }
- if (rightTitle != null) {
- x = (float) (graphArea.getX() + graphArea.getWidth());
- y -= 5;
- rightTitle.draw(g, x, y);
- y += 5;
- sh = rightTitle.getDimension(g).height + 5;
- }
- if (title != null) {
- y -= sh;
- y -= 8;
- x = (float) (graphArea.getX() + graphArea.getWidth() / 2);
- title.draw(g, x, y);
- }
- }
-
- void drawGridLine(Graphics2D g, Rectangle2D area) {
- if (!this.gridLine.isDrawXLine() && !this.gridLine.isDrawYLine()) {
- return;
- }
-
- double[] xy;
- double x, y;
- double miny = area.getY();
- double minx = area.getX();
- double maxx = area.getX() + area.getWidth();
- double maxy = area.getY() + area.getHeight();
-
- float[] dashPattern = Draw.getDashPattern(this.gridLine.getStyle());
- g.setColor(this.gridLine.getColor());
- g.setStroke(new BasicStroke(this.gridLine.getSize(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
- 10.0f, dashPattern, 0.0f));
-
- //Draw x grid lines
- if (this.gridLine.isDrawXLine()) {
- this.getXAxis().updateTickLabels();
- //this.getXAxis().updateLabelGap(g, area);
- int n = 0;
- while (n < this.getXAxis().getTickValues().length) {
- double value = this.getXAxis().getTickValues()[n];
- if (value <= this.getXAxis().getMinValue() || value >= this.getXAxis().getMaxValue()) {
- n += this.getXAxis().getTickLabelGap();
- continue;
- }
- xy = this.projToScreen(value, this.drawExtent.minY, area);
- x = xy[0];
- if (x > 0 && x < area.getWidth()) {
- if (this.getXAxis().isInverse()) {
- x = area.getWidth() - x;
- }
- x += minx;
- g.draw(new Line2D.Double(x, maxy, x, miny));
- }
- n += this.getXAxis().getTickLabelGap();
- }
- }
-
- //Draw y grid lines
- if (this.gridLine.isDrawYLine()) {
- this.getYAxis().updateTickLabels();
- //this.getYAxis().updateLabelGap(g, area);
- int n = 0;
- while (n < this.getYAxis().getTickValues().length) {
- double value = this.getYAxis().getTickValues()[n];
- if (value <= this.getYAxis().getMinValue() || value >= this.getYAxis().getMaxValue()) {
- n += this.getYAxis().getTickLabelGap();
- continue;
- }
- xy = this.projToScreen(this.drawExtent.minX, value, area);
- y = xy[1];
- if (y > 0 && y < area.getHeight()) {
- if (this.getYAxis().isInverse()) {
- y = area.getHeight() - y;
- }
- y += miny;
- g.draw(new Line2D.Double(minx, y, maxx, y));
- }
- n += this.getYAxis().getTickLabelGap();
- }
- }
- }
-
- abstract void drawGraph(Graphics2D g, Rectangle2D area);
-
- void drawAxis(Graphics2D g, Rectangle2D area) {
- for (Location loc : this.axis.keySet()) {
- Axis ax = this.axis.get(loc);
- if (ax.isVisible()) {
- ax.updateLabelGap(g, area);
- ax.draw(g, area, this);
- }
- }
- }
-
- void drawText(Graphics2D g, Rectangle2D area) {
-// Iterator iter = this.getTexts().iterator();
-// while (iter.hasNext()){
-// drawPlotText(iter.next(), g, area);
-// }
- for (int i = 0; i < this.getTexts().size(); i++){
- drawPlotText(this.getTexts().get(i), g, area);
- }
- }
-
- void drawPlotText(ChartText text, Graphics2D g, Rectangle2D area) {
- float x, y;
- switch (text.getCoordinates()) {
- case AXES:
- AffineTransform oldMatrix = g.getTransform();
- Rectangle oldRegion = g.getClipBounds();
- g.setClip(area);
- g.translate(area.getX(), area.getY());
- x = (float) (area.getWidth() * text.getX());
- y = (float) (area.getHeight() * (1 - text.getY()));
- this.drawText(text, g, x, y);
- g.setTransform(oldMatrix);
- g.setClip(oldRegion);
- break;
- case FIGURE:
- x = (float) (area.getWidth() * text.getX());
- y = (float) (area.getHeight() * (1 - text.getY()));
- this.drawText(text, g, x, y);
- break;
- case DATA:
- oldMatrix = g.getTransform();
- oldRegion = g.getClipBounds();
- if (this.clip)
- g.setClip(area);
- g.translate(area.getX(), area.getY());
- double[] xy = this.projToScreen(text.getX(), text.getY(), area);
- x = (float) xy[0];
- y = (float) xy[1];
- this.drawText(text, g, x, y);
- g.setTransform(oldMatrix);
- if (this.clip)
- g.setClip(oldRegion);
- break;
- }
- }
-
- void drawText(ChartText text, Graphics2D g, float x, float y) {
- g.setFont(text.getFont());
- text.draw(g, x, y);
- }
-
- void drawLegend(Graphics2D g, Rectangle2D area, Rectangle2D graphArea) {
- if (!this.legends.isEmpty()) {
- Object rendering = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- for (ChartLegend legend : this.legends) {
- if (legend.isColorbar()) {
- if (legend.getPlotOrientation() == PlotOrientation.VERTICAL) {
- legend.setHeight((int) (graphArea.getHeight() * legend.getShrink()));
- legend.setLegendHeight(legend.getHeight());
- } else {
- legend.setWidth((int) (graphArea.getWidth() * legend.getShrink()));
- legend.setLegendWidth(legend.getWidth());
- }
- }
- if (legend.getPosition() == LegendPosition.CUSTOM) {
- legend.getLegendDimension(g, new Dimension((int) area.getWidth(), (int) area.getHeight()));
- float x = (float) (area.getWidth() * legend.getX());
- float y = (float) (area.getHeight() * (1 - (this.getLegend().getHeight() / area.getHeight())
- - this.getLegend().getY()));
- legend.draw(g, new PointF(x, y));
- } else {
- this.drawLegendScheme(legend, g, graphArea);
- }
- }
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, rendering);
- }
- }
-
- void drawLegendScheme(ChartLegend legend, Graphics2D g, Rectangle2D area) {
- g.setFont(legend.getTickLabelFont());
- Dimension dim = legend.getLegendDimension(g, new Dimension((int) area.getWidth(), (int) area.getHeight()));
- float x = 0;
- float y = 0;
- switch (legend.getPosition()) {
- case UPPER_CENTER_OUTSIDE:
- x = (float) (area.getX() + area.getWidth() / 2 - dim.width / 2);
- y = (float) (area.getY() - this.getAxis(Location.TOP).getXAxisHeight(g) - dim.height - 5);
- break;
- case LOWER_CENTER_OUTSIDE:
- x = (float) (area.getX() + area.getWidth() / 2 - dim.width / 2);
- y = (float) (area.getY() + area.getHeight() + this.getXAxisHeight(g) + 10);
- break;
- case LEFT_OUTSIDE:
- x = 10;
- y = (float) area.getHeight() / 2 - dim.height / 2;
- break;
- case RIGHT_OUTSIDE:
- if (this.getAxis(Location.RIGHT).isDrawTickLabel() || this instanceof PolarPlot) {
- x = (float) area.getX() + (float) area.getWidth() + (float) this.getTightInset().getRight();
- x = x - dim.width;
- } else {
- x = (float) area.getX() + (float) area.getWidth() + 10;
- }
- y = (float) area.getY() + (float) area.getHeight() / 2 - dim.height / 2;
- break;
- case UPPER_CENTER:
- x = (float) (area.getX() + area.getWidth() / 2 - dim.width / 2);
- y = (float) area.getY() + 10;
- break;
- case UPPER_RIGHT:
- x = (float) (area.getX() + area.getWidth()) - dim.width - 10;
- y = (float) area.getY() + 10;
- break;
- case LOWER_CENTER:
- x = (float) (area.getX() + area.getWidth() / 2 - dim.width / 2);
- y = (float) (area.getY() + area.getHeight()) - dim.height - 10;
- break;
- case LOWER_RIGHT:
- x = (float) (area.getX() + area.getWidth()) - dim.width - 10;
- y = (float) (area.getY() + area.getHeight()) - dim.height - 10;
- break;
- case UPPER_LEFT:
- x = (float) area.getX() + 10;
- y = (float) area.getY() + 10;
- break;
- case LOWER_LEFT:
- x = (float) area.getX() + 10;
- y = (float) (area.getY() + area.getHeight()) - dim.height - 10;
- break;
- }
- legend.draw(g, new PointF(x, y));
- }
-
- /**
- * Convert coordinate from map to screen
- *
- * @param projX Map X
- * @param projY Map Y
- * @param area Drawing area
- * @return Screen X/Y array
- */
- public double[] projToScreen(double projX, double projY, Rectangle2D area) {
- double width = drawExtent.getWidth();
- double height = drawExtent.getHeight();
- if (this.isLogY()) {
- height = Math.log10(drawExtent.maxY) - Math.log10(drawExtent.minY);
- }
- if (this.isLogX()) {
- width = Math.log10(drawExtent.maxX) - Math.log10(drawExtent.minX);
- }
- double scaleX = area.getWidth() / width;
- double scaleY = area.getHeight() / height;
- double screenX = (projX - drawExtent.minX) * scaleX;
- double screenY = (drawExtent.maxY - projY) * scaleY;
- if (this.isLogY()) {
- screenY = (Math.log10(drawExtent.maxY) - Math.log10(projY)) * scaleY;
- }
- if (this.isLogX()) {
- screenX = (Math.log10(projX) - Math.log10(drawExtent.minX)) * scaleX;
- }
- if (this.isYReverse()) {
- screenY = area.getHeight() - screenY;
- }
- if (this.isXReverse()) {
- screenX = area.getWidth() - screenX;
- }
-
- return new double[]{screenX, screenY};
- }
-
- /**
- * Convert data length to screen length in x direction
- *
- * @param len data length
- * @param area Drawing area
- * @return Screen length
- */
- public double projXLength(double len, Rectangle2D area) {
- double scaleX = area.getWidth() / drawExtent.getWidth();
- return len * scaleX;
- }
-
- /**
- * Convert data length to screen length in y direction
- *
- * @param len data length
- * @param area Drawing area
- * @return Screen length
- */
- public double projYLength(double len, Rectangle2D area) {
- double scaleY = area.getHeight() / drawExtent.getHeight();
- return len * scaleY;
- }
-
- /**
- * Convert coordinate from screen to map
- *
- * @param screenX Screen X
- * @param screenY Screen Y
- * @param area Area
- * @return Projected X/Y
- */
- public double[] screenToProj(double screenX, double screenY, Rectangle2D area) {
- double width = drawExtent.getWidth();
- double height = drawExtent.getHeight();
- if (this.isLogY()) {
- height = Math.log10(drawExtent.maxY) - Math.log10(drawExtent.minY);
- }
- if (this.isLogX()) {
- width = Math.log10(drawExtent.maxX) - Math.log10(drawExtent.minX);
- }
- if (this.isYReverse()) {
- screenY = area.getHeight() - screenY;
- }
- if (this.isXReverse()) {
- screenX = area.getWidth() - screenX;
- }
- double scaleX = area.getWidth() / width;
- double scaleY = area.getHeight() / height;
- double projX = screenX / scaleX + drawExtent.minX;
- double projY = drawExtent.maxY - screenY / scaleY;
- if (this.isLogY()) {
- projY = Math.pow(10, Math.log10(drawExtent.maxY) - screenY / scaleY);
- }
- if (this.isLogX()) {
- projX = Math.pow(10, screenX / scaleX + Math.log10(drawExtent.minX));
- }
-
- return new double[]{projX, projY};
- }
-
- abstract Extent getAutoExtent();
-
- public abstract void setAutoExtent();
-
- public abstract void updateLegendScheme();
-
- /**
- * Zoom to screen extent
- *
- * @param minX Minimum x
- * @param maxX Maximum x
- * @param minY Minimum y
- * @param maxY Maximum y
- */
- public void zoomToExtentScreen(double minX, double maxX, double minY, double maxY) {
- double[] pMin = screenToProj(minX, maxY, this.getGraphArea());
- double[] pMax = screenToProj(maxX, minY, this.getGraphArea());
- this.setDrawExtent(new Extent(pMin[0], pMax[0], pMin[1], pMax[1]));
- }
-
- /**
- * Add text
- *
- * @param text Chart text
- */
- public void addText(ChartText text) {
- this.getTexts().add(text);
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/AxesUnits.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/AxesUnits.java
deleted file mode 100644
index 6d54c7c7..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/AxesUnits.java
+++ /dev/null
@@ -1,15 +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;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public enum AxesUnits {
- NORMALIZED,
- PIXELS;
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/ChartPlotMethod.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/ChartPlotMethod.java
deleted file mode 100644
index 8326251f..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/ChartPlotMethod.java
+++ /dev/null
@@ -1,18 +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;
-
-/**
- *
- * @author yaqiang
- */
-public enum ChartPlotMethod {
- LINE,
- BAR,
- POINT,
- LINE_POINT,
- FILL
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/GraphicFactory.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/GraphicFactory.java
deleted file mode 100644
index 9b2624d4..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/GraphicFactory.java
+++ /dev/null
@@ -1,5778 +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 java.awt.Color;
-import java.awt.Font;
-import java.awt.geom.AffineTransform;
-import java.awt.image.BufferedImage;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.commons.lang3.ArrayUtils;
-import org.meteoinfo.chart.ChartText;
-import org.meteoinfo.chart.plot3d.GraphicCollection3D;
-import org.meteoinfo.common.*;
-import org.meteoinfo.data.GridArray;
-import org.meteoinfo.data.GridData;
-import org.meteoinfo.data.XYListDataset;
-import org.meteoinfo.data.analysis.Statistics;
-import org.meteoinfo.drawing.ContourDraw;
-import org.meteoinfo.drawing.Draw;
-import org.meteoinfo.geometry.graphic.Graphic;
-import org.meteoinfo.geometry.graphic.GraphicCollection;
-import org.meteoinfo.geometry.graphic.ImageGraphic;
-import org.meteoinfo.geometry.legend.*;
-import org.meteoinfo.geoprocess.GeometryUtil;
-import org.meteoinfo.geoprocess.GeoComputation;
-import org.meteoinfo.layer.ImageLayer;
-import org.meteoinfo.layer.VectorLayer;
-import org.meteoinfo.legend.LegendManage;
-import org.meteoinfo.ndarray.math.ArrayMath;
-import org.meteoinfo.ndarray.math.ArrayUtil;
-import org.meteoinfo.math.meteo.MeteoMath;
-import org.meteoinfo.ndarray.*;
-import org.meteoinfo.ndarray.util.BigDecimalUtil;
-import org.meteoinfo.geometry.shape.*;
-import wcontour.Contour;
-import wcontour.global.Point3D;
-import wcontour.global.PolyLine;
-import wcontour.global.PolyLine3D;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class GraphicFactory {
-
- /**
- * Create LineString graphic
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param cb Color break
- * @return LineString graphic
- */
- public static GraphicCollection createLineString(Array xdata, Array ydata, ColorBreak cb) {
- GraphicCollection gc = new GraphicCollection();
- PolylineShape pls;
- List points = new ArrayList<>();
- double x, y;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- while (xIter.hasNext()) {
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- if (Double.isNaN(y) || Double.isNaN(x)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() == 1) {
- points.add((PointD) points.get(0).clone());
- }
- pls = new PolylineShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- points = new ArrayList<>();
- } else {
- points.add(new PointD(x, y));
- }
- }
- if (!points.isEmpty()) {
- if (points.size() == 1) {
- points.add((PointD) points.get(0).clone());
- }
- pls = new PolylineShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- }
-
- return gc;
- }
-
- /**
- * Create LineString graphic
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param cb Color break
- * @param iscurve Is curve line or not
- * @return LineString graphic
- */
- public static GraphicCollection createLineString(Array xdata, Array ydata, ColorBreak cb, boolean iscurve) {
- GraphicCollection gc = new GraphicCollection();
- PolylineShape pls;
- List points = new ArrayList<>();
- double x, y;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- if (xdata.getRank() == 1) {
- while (xIter.hasNext()) {
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- if (Double.isNaN(y) || Double.isNaN(x)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() == 1) {
- points.add((PointD) points.get(0).clone());
- }
- if (iscurve) {
- pls = new CurveLineShape();
- } else {
- pls = new PolylineShape();
- }
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- points = new ArrayList<>();
- } else {
- points.add(new PointD(x, y));
- }
- }
- if (!points.isEmpty()) {
- if (points.size() == 1) {
- points.add((PointD) points.get(0).clone());
- }
- if (iscurve) {
- pls = new CurveLineShape();
- } else {
- pls = new PolylineShape();
- }
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- }
- } else { //Two dimensions
- int[] shape = xdata.getShape();
- int yn = shape[0];
- int xn = shape[1];
- for (int j = 0; j < yn; j++) {
- points = new ArrayList<>();
- for (int i = 0; i < xn; i++) {
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- //x = xdata.getDouble(j * xn + i);
- //y = ydata.getDouble(j * xn + i);
- if (Double.isNaN(y) || Double.isNaN(x)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() == 1) {
- points.add((PointD) points.get(0).clone());
- }
- if (iscurve) {
- pls = new CurveLineShape();
- } else {
- pls = new PolylineShape();
- }
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- points = new ArrayList<>();
- } else {
- points.add(new PointD(x, y));
- }
- }
- if (points.size() > 1) {
- if (iscurve) {
- pls = new CurveLineShape();
- } else {
- pls = new PolylineShape();
- }
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- }
- }
- }
-
- return gc;
- }
-
- /**
- * Create LineString graphic
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param cbs Color break list
- * @param iscurve Is curve line or not
- * @return LineString graphic
- */
- public static GraphicCollection createLineString(Array xdata, Array ydata, List cbs, boolean iscurve) {
- GraphicCollection gc = new GraphicCollection();
- PolylineShape pls;
- List points;
- double x, y;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- ColorBreak cb;
- if (xdata.getRank() == 1) {
- points = new ArrayList<>();
- int i = 0;
- while (xIter.hasNext()) {
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- if (Double.isNaN(y) || Double.isNaN(x)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() == 1) {
- points.add((PointD) points.get(0).clone());
- }
- if (iscurve) {
- pls = new CurveLineShape();
- } else {
- pls = new PolylineShape();
- }
- pls.setPoints(points);
- cb = cbs.get(i);
- gc.add(new Graphic(pls, cb));
- points = new ArrayList<>();
- i += 1;
- } else {
- points.add(new PointD(x, y));
- }
- }
- if (points.size() > 1) {
- if (iscurve) {
- pls = new CurveLineShape();
- } else {
- pls = new PolylineShape();
- }
- pls.setPoints(points);
- cb = cbs.get(i);
- gc.add(new Graphic(pls, cb));
- }
- } else { //Two dimensions
- int[] shape = xdata.getShape();
- int yn = shape[0];
- int xn = shape[1];
- for (int j = 0; j < yn; j++) {
- points = new ArrayList<>();
- cb = cbs.get(j);
- for (int i = 0; i < xn; i++) {
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- //x = xdata.getDouble(j * xn + i);
- //y = ydata.getDouble(j * xn + i);
- if (Double.isNaN(y) || Double.isNaN(x)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() == 1) {
- points.add((PointD) points.get(0).clone());
- }
- if (iscurve) {
- pls = new CurveLineShape();
- } else {
- pls = new PolylineShape();
- }
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- points = new ArrayList<>();
- } else {
- points.add(new PointD(x, y));
- }
- }
- if (points.size() > 1) {
- if (iscurve) {
- pls = new CurveLineShape();
- } else {
- pls = new PolylineShape();
- }
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- }
- }
- }
- gc.setSingleLegend(false);
-
- return gc;
- }
-
- /**
- * Create LineString graphic
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param zdata Z data array
- * @param ls Legend scheme
- * @param iscurve Is curve line or not
- * @return LineString graphic
- */
- public static GraphicCollection createLineString(Array xdata, Array ydata, Array zdata, LegendScheme ls, boolean iscurve) {
- GraphicCollection gc = new GraphicCollection();
- PolylineShape pls;
- List points;
- ColorBreakCollection cbc;
- double x, y, z;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- IndexIterator zIter = zdata.getIndexIterator();
- ColorBreak cb;
- if (xdata.getRank() == 1) {
- points = new ArrayList<>();
- cbc = new ColorBreakCollection();
- while (xIter.hasNext()){
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- z = zIter.getDoubleNext();
- cb = ls.findLegendBreak(z);
- if (Double.isNaN(y) || Double.isNaN(x)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() == 1) {
- points.add((PointD) points.get(0).clone());
- }
- if (iscurve) {
- pls = new CurveLineShape();
- } else {
- pls = new PolylineShape();
- }
- pls.setPoints(points);
- gc.add(new Graphic(pls, cbc));
- points = new ArrayList<>();
- cbc = new ColorBreakCollection();
- } else {
- points.add(new PointD(x, y));
- cbc.add(cb);
- }
- }
- if (points.size() > 1) {
- if (iscurve) {
- pls = new CurveLineShape();
- } else {
- pls = new PolylineShape();
- }
- pls.setPoints(points);
- gc.add(new Graphic(pls, cbc));
- }
- gc.setLegendScheme(ls);
- } else { //Two dimensions
- int[] shape = xdata.getShape();
- int yn = shape[0];
- int xn = shape[1];
- for (int j = 0; j < yn; j++) {
- points = new ArrayList<>();
- cbc = new ColorBreakCollection();
- for (int i = 0; i < xn; i++) {
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- z = zIter.getDoubleNext();
- //x = xdata.getDouble(j * xn + i);
- //y = ydata.getDouble(j * xn + i);
- //z = zdata.getDouble(j * xn + i);
- cb = ls.findLegendBreak(z);
- if (Double.isNaN(y) || Double.isNaN(x)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() == 1) {
- points.add((PointD) points.get(0).clone());
- }
- if (iscurve) {
- pls = new CurveLineShape();
- } else {
- pls = new PolylineShape();
- }
- pls.setPoints(points);
- gc.add(new Graphic(pls, cbc));
- points = new ArrayList<>();
- cbc = new ColorBreakCollection();
- } else {
- points.add(new PointD(x, y));
- cbc.add(cb);
- }
- }
- if (points.size() > 1) {
- if (iscurve) {
- pls = new CurveLineShape();
- } else {
- pls = new PolylineShape();
- }
- pls.setPoints(points);
- gc.add(new Graphic(pls, cbc));
- }
- }
- gc.setLegendScheme(ls);
- gc.setSingleLegend(false);
- }
-
- return gc;
- }
-
- /**
- * Create LineString graphic
- *
- * @param data Y data array
- * @param cbs Color breaks
- * @return LineString graphic
- */
- public static GraphicCollection createLineString(XYListDataset data, List cbs) {
- GraphicCollection gc = new GraphicCollection();
- PolylineShape pls;
- List points;
- double x, y;
- for (int i = 0; i < data.getSeriesCount(); i++) {
- points = new ArrayList<>();
- for (int j = 0; j < data.getItemCount(i); j++) {
- x = data.getX(i, j);
- y = data.getY(i, j);
- points.add(new PointD(x, y));
- }
- pls = new PolylineShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cbs.get(i)));
- }
- gc.setSingleLegend(false);
-
- return gc;
- }
-
- /**
- * Create 3D LineString graphic
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param zdata Z data array
- * @param cb Color break
- * @return LineString graphic
- */
- public static GraphicCollection createLineString3D(Array xdata, Array ydata, Array zdata, ColorBreak cb) {
- GraphicCollection3D gc = new GraphicCollection3D();
- PolylineZShape pls;
- List points = new ArrayList<>();
- double x, y, z = 0;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- IndexIterator zIter = zdata.getIndexIterator();
- boolean fixZ = false;
- if (zdata.getSize() == 1 && xdata.getSize() > 1) {
- fixZ = true;
- z = zdata.getDouble(0);
- }
- if (xdata.getRank() == 1) {
- while (xIter.hasNext()) {
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- if (!fixZ) {
- z = zIter.getDoubleNext();
- }
- if (Double.isNaN(y) || Double.isNaN(x)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() == 1) {
- points.add((PointZ) points.get(0).clone());
- }
- pls = new PolylineZShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- points = new ArrayList<>();
- } else {
- points.add(new PointZ(x, y, z));
- }
- }
- if (points.size() > 1) {
- pls = new PolylineZShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- }
- } else { //two dimensions
- int[] shape = xdata.getShape();
- int yn = shape[0];
- int xn = shape[1];
- for (int j = 0; j < yn; j++) {
- for (int i = 0; i < xn; i++) {
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- //x = xdata.getDouble(j * xn + i);
- //y = ydata.getDouble(j * xn + i);
- if (!fixZ) {
- z = zIter.getDoubleNext();
- //z = zdata.getDouble(j * xn + i);
- }
- if (Double.isNaN(y) || Double.isNaN(x)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() == 1) {
- points.add((PointZ) points.get(0).clone());
- }
- pls = new PolylineZShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- points = new ArrayList<>();
- } else {
- points.add(new PointZ(x, y, z));
- }
- }
- if (points.size() > 1) {
- pls = new PolylineZShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- points = new ArrayList<>();
- }
- }
- }
-
- return gc;
- }
-
- /**
- * Create 3D LineString graphic
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param zdata Z data array
- * @param cbs Color break list
- * @return LineString graphic
- */
- public static GraphicCollection createLineString3D(Array xdata, Array ydata, Array zdata, List cbs) {
- GraphicCollection3D gc = new GraphicCollection3D();
- PolylineZShape pls;
- List points = new ArrayList<>();
- double x, y, z = 0;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- IndexIterator zIter = zdata.getIndexIterator();
- boolean fixZ = false;
- if (zdata.getSize() == 1 && xdata.getSize() > 1) {
- fixZ = true;
- z = zdata.getDouble(0);
- }
- ColorBreak cb;
- if (xdata.getRank() == 1) {
- int i = 0;
- while (xIter.hasNext()) {
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- if (!fixZ) {
- z = zIter.getDoubleNext();
- }
- if (Double.isNaN(y) || Double.isNaN(x)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() == 1) {
- points.add((PointZ) points.get(0).clone());
- }
- pls = new PolylineZShape();
- pls.setPoints(points);
- cb = cbs.get(i);
- gc.add(new Graphic(pls, cb));
- points = new ArrayList<>();
- i += 1;
- } else {
- points.add(new PointZ(x, y, z));
- }
- }
- if (points.size() > 1) {
- pls = new PolylineZShape();
- pls.setPoints(points);
- cb = cbs.get(i);
- gc.add(new Graphic(pls, cb));
- }
- } else { //two dimensions
- int[] shape = xdata.getShape();
- int yn = shape[0];
- int xn = shape[1];
- for (int j = 0; j < yn; j++) {
- cb = cbs.get(j);
- for (int i = 0; i < xn; i++) {
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- //x = xdata.getDouble(j * xn + i);
- //y = ydata.getDouble(j * xn + i);
- if (!fixZ) {
- z = zIter.getDoubleNext();
- //z = zdata.getDouble(j * xn + i);
- }
- if (Double.isNaN(y) || Double.isNaN(x)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() == 1) {
- points.add((PointZ) points.get(0).clone());
- }
- pls = new PolylineZShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- points = new ArrayList<>();
- } else {
- points.add(new PointZ(x, y, z));
- }
- }
- if (points.size() > 1) {
- pls = new PolylineZShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- points = new ArrayList<>();
- }
- }
- }
-
- return gc;
- }
-
- /**
- * Create 3D LineString graphic
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param zdata Z data array
- * @param mdata M data array
- * @param ls Legend scheme
- * @return LineString graphic
- */
- public static GraphicCollection createLineString3D(Array xdata, Array ydata, Array zdata, Array mdata,
- LegendScheme ls) {
- GraphicCollection3D gc = new GraphicCollection3D();
- PolylineZShape pls;
- List points = new ArrayList<>();
- double x, y, z = 0, m;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- IndexIterator zIter = zdata.getIndexIterator();
- IndexIterator mIter = mdata.getIndexIterator();
- boolean fixZ = false;
- if (zdata.getSize() == 1 && xdata.getSize() > 1) {
- fixZ = true;
- z = zdata.getDouble(0);
- }
- ColorBreak cb;
- ColorBreakCollection cbs;
- if (xdata.getRank() == 1) {
- cbs = new ColorBreakCollection();
- while (xIter.hasNext()){
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- if (!fixZ) {
- z = zIter.getDoubleNext();
- }
- m = mIter.getDoubleNext();
- cb = ls.findLegendBreak(m);
- if (Double.isNaN(y) || Double.isNaN(x)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() == 1) {
- points.add((PointZ) points.get(0).clone());
- }
- pls = new PolylineZShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cbs));
- points = new ArrayList<>();
- cbs = new ColorBreakCollection();
- } else {
- points.add(new PointZ(x, y, z));
- cbs.add(cb);
- }
- }
- if (points.size() > 1) {
- pls = new PolylineZShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cbs));
- }
- } else { //two dimensions
- int[] shape = xdata.getShape();
- int yn = shape[0];
- int xn = shape[1];
- for (int j = 0; j < yn; j++) {
- cbs = new ColorBreakCollection();
- for (int i = 0; i < xn; i++) {
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- //x = xdata.getDouble(j * xn + i);
- //y = ydata.getDouble(j * xn + i);
- if (!fixZ) {
- z = zIter.getDoubleNext();
- //z = zdata.getDouble(j * xn + i);
- }
- m = mIter.getDoubleNext();
- //m = mdata.getDouble(j * xn + i);
- cb = ls.findLegendBreak(m);
- if (Double.isNaN(y) || Double.isNaN(x)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() == 1) {
- points.add((PointZ) points.get(0).clone());
- }
- pls = new PolylineZShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cbs));
- points = new ArrayList<>();
- cbs = new ColorBreakCollection();
- } else {
- points.add(new PointZ(x, y, z));
- cbs.add(cb);
- }
- }
- if (points.size() > 1) {
- pls = new PolylineZShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cbs));
- points = new ArrayList<>();
- }
- }
- }
- gc.setLegendScheme(ls);
-
- return gc;
- }
-
- /**
- * Create error LineString graphic
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param xErrorLeft X error array - left
- * @param xErrorRight X error array - right
- * @param yErrorBottom Y error array - bottom
- * @param yErrorUp Y error array - up
- * @param cb Color break
- * @param ecb Error bar color break
- * @param capSize The length of the error bar caps.
- * @return LineString graphics
- */
- public static GraphicCollection createErrorLineString(Array xdata, Array ydata, Array xErrorLeft,
- Array xErrorRight, Array yErrorBottom, Array yErrorUp, PolylineBreak cb, PolylineBreak ecb, float capSize) {
- GraphicCollection gc = new GraphicCollection();
- PolylineShape pls;
- CapPolylineShape epls;
- List points = new ArrayList<>();
- List eps;
- double x, y, xerrL, xerrR, yerrB, yerrU;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- IndexIterator xelIter = xErrorLeft == null ? null : xErrorLeft.getIndexIterator();
- IndexIterator xerIter = xErrorRight == null ? null : xErrorRight.getIndexIterator();
- IndexIterator yebIter = yErrorBottom == null ? null : yErrorBottom.getIndexIterator();
- IndexIterator yeuIter = yErrorUp == null ? null : yErrorUp.getIndexIterator();
- //Loop
- while (xIter.hasNext()) {
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- if (Double.isNaN(y) || Double.isNaN(x)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() == 1) {
- points.add((PointD) points.get(0).clone());
- }
- pls = new PolylineShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- points = new ArrayList<>();
- if (yebIter != null) {
- yebIter.next();
- yeuIter.next();
- }
- if (xelIter != null) {
- xelIter.next();
- xerIter.next();
- }
- } else {
- points.add(new PointD(x, y));
- if (yebIter != null) {
- yerrB = yebIter.getDoubleNext();
- yerrU = yeuIter.getDoubleNext();
- eps = new ArrayList<>();
- eps.add(new PointD(x, y + yerrU));
- eps.add(new PointD(x, y - yerrB));
- epls = new CapPolylineShape();
- epls.setCapLen(capSize);
- epls.setPoints(eps);
- gc.add(new Graphic(epls, ecb));
- }
- if (xelIter != null) {
- xerrL = xelIter.getDoubleNext();
- xerrR = xerIter.getDoubleNext();
- eps = new ArrayList<>();
- eps.add(new PointD(x - xerrL, y));
- eps.add(new PointD(x + xerrR, y));
- epls = new CapPolylineShape();
- epls.setCapLen(capSize);
- epls.setCapAngle(90);
- epls.setPoints(eps);
- gc.add(new Graphic(epls, ecb));
- }
- }
- }
- if (!points.isEmpty()) {
- if (points.size() == 1) {
- points.add((PointD) points.get(0).clone());
- }
- pls = new PolylineShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- }
- gc.setSingleLegend(false);
- PolylineBreak lb = (PolylineBreak) ecb.clone();
- lb.setDrawSymbol(cb.getDrawSymbol());
- gc.setLegendBreak(lb);
-
- return gc;
- }
-
- /**
- * Create error LineString graphic
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param xErrorLeft X error array - left
- * @param xErrorRight X error array - right
- * @param yErrorBottom Y error array - bottom
- * @param yErrorUp Y error array - up
- * @param cb Color break
- * @param ecb Error bar color break
- * @param capSize The length of the error bar caps.
- * @return LineString graphics
- */
- public static GraphicCollection createErrorLineString_bak1(Array xdata, Array ydata, Array xErrorLeft,
- Array xErrorRight, Array yErrorBottom, Array yErrorUp, ColorBreak cb, ColorBreak ecb, Double capSize) {
- GraphicCollection gc = new GraphicCollection();
- PolylineShape pls, epls;
- List points = new ArrayList<>();
- List eps;
- double x, y, xerrL, xerrR, yerrB, yerrU;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- IndexIterator xelIter = xErrorLeft == null ? null : xErrorLeft.getIndexIterator();
- IndexIterator xerIter = xErrorRight == null ? null : xErrorRight.getIndexIterator();
- IndexIterator yebIter = yErrorBottom == null ? null : yErrorBottom.getIndexIterator();
- IndexIterator yeuIter = yErrorUp == null ? null : yErrorUp.getIndexIterator();
- double width;
- if (capSize == null) {
- width = (ArrayMath.getMaximum(xdata) - ArrayMath.getMinimum(xdata)) / xdata.getSize() * 0.1;
- } else {
- width = capSize * 0.5;
- }
- //Loop
- while (xIter.hasNext()){
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- if (Double.isNaN(y) || Double.isNaN(x)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() == 1) {
- points.add((PointD) points.get(0).clone());
- }
- pls = new PolylineShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- points = new ArrayList<>();
- if (yebIter != null) {
- yebIter.next();
- yeuIter.next();
- }
- if (xelIter != null) {
- xelIter.next();
- xerIter.next();
- }
- } else {
- points.add(new PointD(x, y));
- if (yErrorBottom != null) {
- yerrB = yebIter.getDoubleNext();
- yerrU = yeuIter.getDoubleNext();
- eps = new ArrayList<>();
- eps.add(new PointD(x, y + yerrU));
- eps.add(new PointD(x, y - yerrB));
- epls = new PolylineShape();
- epls.setPoints(eps);
- gc.add(new Graphic(epls, ecb));
- eps = new ArrayList<>();
- eps.add(new PointD(x - width, y + yerrU));
- eps.add(new PointD(x + width, y + yerrU));
- epls = new PolylineShape();
- epls.setPoints(eps);
- gc.add(new Graphic(epls, ecb));
- eps = new ArrayList<>();
- eps.add(new PointD(x - width, y - yerrB));
- eps.add(new PointD(x + width, y - yerrB));
- epls = new PolylineShape();
- epls.setPoints(eps);
- gc.add(new Graphic(epls, ecb));
- }
- if (xErrorLeft != null) {
- xerrL = xelIter.getDoubleNext();
- xerrR = xerIter.getDoubleNext();
- eps = new ArrayList<>();
- eps.add(new PointD(x - xerrL, y));
- eps.add(new PointD(x + xerrR, y));
- epls = new PolylineShape();
- epls.setPoints(eps);
- gc.add(new Graphic(epls, ecb));
- eps = new ArrayList<>();
- eps.add(new PointD(x - xerrL, y - width));
- eps.add(new PointD(x - xerrL, y + width));
- epls = new PolylineShape();
- epls.setPoints(eps);
- gc.add(new Graphic(epls, ecb));
- eps = new ArrayList<>();
- eps.add(new PointD(x + xerrR, y - width));
- eps.add(new PointD(x + xerrR, y + width));
- epls = new PolylineShape();
- epls.setPoints(eps);
- gc.add(new Graphic(epls, ecb));
- }
- }
- }
- if (!points.isEmpty()) {
- if (points.size() == 1) {
- points.add((PointD) points.get(0).clone());
- }
- pls = new PolylineShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- }
- gc.setSingleLegend(false);
-
- return gc;
- }
-
- /**
- * Create step LineString graphic
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param cb Color break
- * @param where Where - pre, post, mid
- * @return LineString graphic
- */
- public static GraphicCollection createStepLineString(Array xdata, Array ydata, ColorBreak cb, String where) {
- GraphicCollection gc = new GraphicCollection();
- PolylineShape pls;
- List points = new ArrayList<>();
- double x, x1, x2, y, y1, y2;
- if (!xdata.getIndexPrivate().isFastIterator()) {
- xdata = xdata.copy();
- }
- if (!ydata.getIndexPrivate().isFastIterator()) {
- ydata = ydata.copy();
- }
- switch (where) {
- case "mid":
- for (int i = 0; i < xdata.getSize() - 1; i++) {
- x1 = xdata.getDouble(i);
- x2 = xdata.getDouble(i + 1);
- y1 = ydata.getDouble(i);
- y2 = ydata.getDouble(i + 1);
- if (Double.isNaN(y1) || Double.isNaN(x1) || Double.isNaN(x2)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() > 1) {
- pls = new PolylineShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- points = new ArrayList<>();
- }
- } else {
- x = x1 + (x2 - x1) * 0.5;
- if (i == 0) {
- points.add(new PointD(x1, y1));
- points.add(new PointD(x, y1));
- points.add(new PointD(x, y2));
- } else if (i == xdata.getSize() - 2) {
- points.add(new PointD(x, y1));
- points.add(new PointD(x, y2));
- points.add(new PointD(x2, y2));
- } else {
- points.add(new PointD(x, y1));
- points.add(new PointD(x, y2));
- }
- }
- }
- if (points.size() > 1) {
- pls = new PolylineShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- }
- break;
- case "post":
- for (int i = 0; i < xdata.getSize() - 1; i++) {
- x1 = xdata.getDouble(i);
- x2 = xdata.getDouble(i + 1);
- y = ydata.getDouble(i);
- if (Double.isNaN(y) || Double.isNaN(x1) || Double.isNaN(x2)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() > 1) {
- pls = new PolylineShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- points = new ArrayList<>();
- }
- } else {
- points.add(new PointD(x1, y));
- points.add(new PointD(x2, y));
- if (i == xdata.getSize() - 2) {
- points.add(new PointD(x2, ydata.getDouble(i + 1)));
- }
- }
- }
- if (points.size() > 1) {
- pls = new PolylineShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- }
- break;
- default:
- for (int i = 0; i < xdata.getSize() - 1; i++) {
- x1 = xdata.getDouble(i);
- x2 = xdata.getDouble(i + 1);
- y = ydata.getDouble(i + 1);
- if (Double.isNaN(y) || Double.isNaN(x1) || Double.isNaN(x2)) {
- if (points.isEmpty()) {
- continue;
- }
- if (points.size() > 1) {
- pls = new PolylineShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- points = new ArrayList<>();
- }
- } else {
- if (i == 0) {
- points.add(new PointD(x1, ydata.getDouble(i)));
- }
- points.add(new PointD(x1, y));
- points.add(new PointD(x2, y));
- }
- }
- if (points.size() > 1) {
- pls = new PolylineShape();
- pls.setPoints(points);
- gc.add(new Graphic(pls, cb));
- }
- break;
- }
-
- return gc;
- }
-
- /**
- * Create graphics
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param cb Color break
- * @return LineString graphic
- */
- public static GraphicCollection createGraphics(Array xdata, Array ydata, ColorBreak cb) {
- GraphicCollection graphics = new GraphicCollection();
- if (cb instanceof PolylineBreak) {
- graphics.add(createLineString(xdata, ydata, cb));
- } else {
- PointShape ps;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- while (xIter.hasNext()){
- ps = new PointShape();
- ps.setPoint(new PointD(xIter.getDoubleNext(), yIter.getDoubleNext()));
- graphics.add(new Graphic(ps, cb));
- }
- }
- return graphics;
- }
-
- /**
- * Create a point graphic
- * @param x X
- * @param y Y
- * @param pb Point legend break
- * @return Point graphic
- */
- public static Graphic createPoint(float x, float y, PointBreak pb) {
- PointShape ps = new PointShape();
- ps.setPoint(new PointD(x, y));
- return new Graphic(ps, pb);
- }
-
- /**
- * Create graphics
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param pb Point legend break
- * @return Point graphics
- */
- public static GraphicCollection createPoints(Array xdata, Array ydata, PointBreak pb) {
- GraphicCollection graphics = new GraphicCollection();
- PointShape ps;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- while (xIter.hasNext()) {
- ps = new PointShape();
- ps.setPoint(new PointD(xIter.getDoubleNext(), yIter.getDoubleNext()));
- graphics.add(new Graphic(ps, pb));
- }
- return graphics;
- }
-
- /**
- * Create graphics
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param cbs Color breaks
- * @return Point graphics
- */
- public static GraphicCollection createPoints(Array xdata, Array ydata, List cbs) {
- GraphicCollection graphics = new GraphicCollection();
- PointShape ps;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- if (cbs.size() == xdata.getSize()) {
- int i = 0;
- while (xIter.hasNext()){
- ps = new PointShape();
- ps.setPoint(new PointD(xIter.getDoubleNext(), yIter.getDoubleNext()));
- graphics.add(new Graphic(ps, cbs.get(i)));
- i++;
- }
- graphics.setSingleLegend(false);
- LegendScheme ls = new LegendScheme();
- ls.setLegendBreaks(cbs);
- ls.setLegendType(LegendType.UniqueValue);
- ls.setShapeType(ShapeTypes.Point);
- graphics.setLegendScheme(ls);
- } else {
- while (xIter.hasNext()){
- ps = new PointShape();
- ps.setPoint(new PointD(xIter.getDoubleNext(), yIter.getDoubleNext()));
- graphics.add(new Graphic(ps, cbs.get(0)));
- LegendScheme ls = new LegendScheme();
- ls.setLegendBreaks(cbs);
- ls.setLegendType(LegendType.SingleSymbol);
- ls.setShapeType(ShapeTypes.Point);
- graphics.setLegendScheme(ls);
- }
- }
- return graphics;
- }
-
- /**
- * Create graphics
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param zdata Z data array
- * @param ls Legend scheme
- * @return LineString graphic
- */
- public static GraphicCollection createPoints(Array xdata, Array ydata, Array zdata, LegendScheme ls) {
- GraphicCollection graphics = new GraphicCollection();
- PointShape ps;
- double z;
- ColorBreak cb;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- IndexIterator zIter = zdata.getIndexIterator();
- while (xIter.hasNext()) {
- ps = new PointShape();
- ps.setPoint(new PointD(xIter.getDoubleNext(), yIter.getDoubleNext()));
- z = zIter.getDoubleNext();
- cb = ls.findLegendBreak(z);
- graphics.add(new Graphic(ps, cb));
- }
- graphics.setSingleLegend(false);
- graphics.setLegendScheme(ls);
- return graphics;
- }
-
- /**
- * Create graphics
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param zdata Z data array
- * @param cb Color break
- * @return LineString graphic
- */
- public static GraphicCollection createPoints3D(Array xdata, Array ydata, Array zdata, ColorBreak cb) {
- List cbs = new ArrayList<>();
- cbs.add(cb);
- return createPoints3D(xdata, ydata, zdata, cbs);
- }
-
- /**
- * Create graphics
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param zdata Z data array
- * @param cbs Color breaks
- * @return LineString graphic
- */
- public static GraphicCollection createPoints3D(Array xdata, Array ydata, Array zdata, List cbs) {
- GraphicCollection3D graphics = new GraphicCollection3D();
- PointShape ps;
- boolean fixZ = false;
- double z = 0;
- if (zdata.getSize() == 1 && xdata.getSize() > 1) {
- fixZ = true;
- z = zdata.getDouble(0);
- }
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- IndexIterator zIter = zdata.getIndexIterator();
- if (cbs.size() == xdata.getSize()) {
- int i = 0;
- while (xIter.hasNext()) {
- ps = new PointZShape();
- if (fixZ) {
- ps.setPoint(new PointZ(xIter.getDoubleNext(), yIter.getDoubleNext(), z));
- } else {
- ps.setPoint(new PointZ(xIter.getDoubleNext(), yIter.getDoubleNext(), zIter.getDoubleNext()));
- }
- graphics.add(new Graphic(ps, cbs.get(i)));
- i++;
- }
- graphics.setSingleLegend(false);
- LegendScheme ls = new LegendScheme();
- ls.setLegendBreaks(cbs);
- ls.setLegendType(LegendType.UniqueValue);
- ls.setShapeType(ShapeTypes.Point);
- graphics.setLegendScheme(ls);
- } else {
- while (xIter.hasNext()) {
- ps = new PointZShape();
- if (fixZ) {
- ps.setPoint(new PointZ(xIter.getDoubleNext(), yIter.getDoubleNext(), z));
- } else {
- ps.setPoint(new PointZ(xIter.getDoubleNext(), yIter.getDoubleNext(), zIter.getDoubleNext()));
- }
- graphics.add(new Graphic(ps, cbs.get(0)));
- LegendScheme ls = new LegendScheme();
- ls.setLegendBreaks(cbs);
- ls.setLegendType(LegendType.SingleSymbol);
- ls.setShapeType(ShapeTypes.Point);
- graphics.setLegendScheme(ls);
- }
- }
- return graphics;
- }
-
- /**
- * Create 3D point graphics
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param zdata Z data array
- * @param cdata C data array
- * @param ls Legend scheme
- * @return 3D point graphics
- */
- public static GraphicCollection createPoints3D(Array xdata, Array ydata, Array zdata, Array cdata, LegendScheme ls) {
- GraphicCollection3D graphics = new GraphicCollection3D();
- PointShape ps;
- double c;
- ColorBreak cb;
- boolean fixZ = false;
- double z = 0;
- if (zdata.getSize() == 1 && xdata.getSize() > 1) {
- fixZ = true;
- z = zdata.getDouble(0);
- }
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- IndexIterator zIter = zdata.getIndexIterator();
- IndexIterator cIter = cdata.getIndexIterator();
- while (xIter.hasNext()) {
- ps = new PointZShape();
- if (fixZ) {
- ps.setPoint(new PointZ(xIter.getDoubleNext(), yIter.getDoubleNext(), z));
- } else {
- ps.setPoint(new PointZ(xIter.getDoubleNext(), yIter.getDoubleNext(), zIter.getDoubleNext()));
- }
- c = cIter.getDoubleNext();
- cb = ls.findLegendBreak(c);
- graphics.add(new Graphic(ps, cb));
- }
- graphics.setSingleLegend(false);
- graphics.setLegendScheme(ls);
- return graphics;
- }
-
- /**
- * Create 3D stem graphics
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param zdata Z data array
- * @param cbs Color breaks
- * @param plb Stem line break
- * @param bottom Stem bottom
- * @param sameStemColor Same stem line and point color or not
- * @return Graphics
- */
- public static GraphicCollection[] createStems3D(Array xdata, Array ydata, Array zdata, List cbs,
- PolylineBreak plb, double bottom, boolean sameStemColor) {
- GraphicCollection3D graphics = new GraphicCollection3D();
- GraphicCollection3D stemlines = new GraphicCollection3D();
- PointShape ps;
- boolean fixZ = false;
- double x, y, z, z0 = 0;
- if (zdata.getSize() == 1 && xdata.getSize() > 1) {
- fixZ = true;
- z0 = zdata.getDouble(0);
- }
- List pzs;
- PolylineZShape pls;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- IndexIterator zIter = zdata.getIndexIterator();
- if (cbs.size() == xdata.getSize()) {
- int i = 0;
- while (xIter.hasNext()) {
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- if (Double.isNaN(x) || Double.isNaN(y)) {
- continue;
- }
- ps = new PointZShape();
- pzs = new ArrayList<>();
- if (fixZ) {
- ps.setPoint(new PointZ(x, y, z0));
- pzs.add(new PointZ(x, y, bottom));
- pzs.add(new PointZ(x, y, z0));
- } else {
- z = zIter.getDoubleNext();
- if (Double.isNaN(z)) {
- continue;
- }
- ps.setPoint(new PointZ(x, y, z));
- pzs.add(new PointZ(x, y, bottom));
- pzs.add(new PointZ(x, y, z));
- }
- graphics.add(new Graphic(ps, cbs.get(i)));
- pls = new PolylineZShape();
- pls.setPoints(pzs);
- if (sameStemColor) {
- PolylineBreak nplb = (PolylineBreak) plb.clone();
- nplb.setColor(cbs.get(i).getColor());
- stemlines.add(new Graphic(pls, nplb));
- } else {
- stemlines.add(new Graphic(pls, plb));
- }
- i++;
- }
- graphics.setSingleLegend(false);
- LegendScheme ls = new LegendScheme();
- ls.setLegendBreaks(cbs);
- ls.setLegendType(LegendType.UniqueValue);
- ls.setShapeType(ShapeTypes.Point);
- graphics.setLegendScheme(ls);
- } else {
- while (xIter.hasNext()) {
- ps = new PointZShape();
- pzs = new ArrayList<>();
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- if (fixZ) {
- ps.setPoint(new PointZ(x, y, z0));
- pzs.add(new PointZ(x, y, bottom));
- pzs.add(new PointZ(x, y, z0));
- } else {
- z = zIter.getDoubleNext();
- ps.setPoint(new PointZ(x, y, z));
- pzs.add(new PointZ(x, y, bottom));
- pzs.add(new PointZ(x, y, z));
- }
- graphics.add(new Graphic(ps, cbs.get(0)));
- pls = new PolylineZShape();
- pls.setPoints(pzs);
- if (sameStemColor) {
- PolylineBreak nplb = (PolylineBreak) plb.clone();
- nplb.setColor(cbs.get(0).getColor());
- stemlines.add(new Graphic(pls, nplb));
- } else {
- stemlines.add(new Graphic(pls, plb));
- }
- }
- LegendScheme ls = new LegendScheme();
- ls.setLegendBreaks(cbs);
- ls.setLegendType(LegendType.SingleSymbol);
- ls.setShapeType(ShapeTypes.Point);
- graphics.setLegendScheme(ls);
- }
- return new GraphicCollection[]{stemlines, graphics};
- }
-
- /**
- * Create 3D stem graphics
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param zdata Z data array
- * @param cdata C data array
- * @param ls Legend scheme
- * @param plb Stem line break
- * @param bottom Stem bottom
- * @param sameStemColor Same stem line and point color or not
- * @return 3D point graphics
- */
- public static GraphicCollection[] createStems3D(Array xdata, Array ydata, Array zdata, Array cdata, LegendScheme ls,
- PolylineBreak plb, double bottom, boolean sameStemColor) {
- GraphicCollection3D graphics = new GraphicCollection3D();
- GraphicCollection3D stemlines = new GraphicCollection3D();
- PointShape ps;
- double c;
- ColorBreak cb;
- boolean fixZ = false;
- double x, y, z, z0 = 0;
- if (zdata.getSize() == 1 && xdata.getSize() > 1) {
- fixZ = true;
- z0 = zdata.getDouble(0);
- }
- List pzs;
- PolylineZShape pls;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- IndexIterator zIter = zdata.getIndexIterator();
- IndexIterator cIter = cdata.getIndexIterator();
- while (xIter.hasNext()){
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- if (Double.isNaN(x) || Double.isNaN(y)) {
- continue;
- }
- ps = new PointZShape();
- pzs = new ArrayList<>();
- if (fixZ) {
- ps.setPoint(new PointZ(x, y, z0));
- pzs.add(new PointZ(x, y, bottom));
- pzs.add(new PointZ(x, y, z0));
- } else {
- z = zIter.getDoubleNext();
- if (Double.isNaN(z)) {
- continue;
- }
- ps.setPoint(new PointZ(x, y, z));
- pzs.add(new PointZ(x, y, bottom));
- pzs.add(new PointZ(x, y, z));
- }
- c = cIter.getDoubleNext();
- cb = ls.findLegendBreak(c);
- graphics.add(new Graphic(ps, cb));
- pls = new PolylineZShape();
- pls.setPoints(pzs);
- if (sameStemColor) {
- PolylineBreak nplb = (PolylineBreak) plb.clone();
- nplb.setColor(cb.getColor());
- stemlines.add(new Graphic(pls, nplb));
- } else {
- stemlines.add(new Graphic(pls, plb));
- }
- }
- graphics.setSingleLegend(false);
- graphics.setLegendScheme(ls);
- return new GraphicCollection[]{stemlines, graphics};
- }
-
- /**
- * Add polygons
- *
- * @param xa X coordinate array
- * @param ya Y coordinate array
- * @param pgb PolygonBreak
- * @return Graphics
- */
- public static GraphicCollection createPolygons(Array xa, Array ya, PolygonBreak pgb) {
- GraphicCollection graphics = new GraphicCollection();
- double x, y;
- int n = (int) xa.getSize();
- PolygonShape pgs;
- PointD p;
- List points = new ArrayList<>();
- IndexIterator xIter = xa.getIndexIterator();
- IndexIterator yIter = ya.getIndexIterator();
- while (xIter.hasNext()){
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- if (Double.isNaN(x)) {
- if (points.size() > 2) {
- pgs = new PolygonShape();
- pgs.setPoints(points);
- Graphic aGraphic = new Graphic(pgs, pgb);
- graphics.add(aGraphic);
- }
- points = new ArrayList<>();
- } else {
- p = new PointD(x, y);
- points.add(p);
- }
- }
- if (points.size() > 2) {
- pgs = new PolygonShape();
- pgs.setPoints(points);
- Graphic aGraphic = new Graphic(pgs, pgb);
- graphics.add(aGraphic);
- }
- return graphics;
- }
-
- /**
- * Add wireframe polylines
- *
- * @param xa X coordinate array
- * @param ya Y coordinate array
- * @param za Z coordinate array
- * @param pb Polyline break
- * @return Graphics
- */
- public static GraphicCollection createWireframe(Array xa, Array ya, Array za, PolylineBreak pb) {
- GraphicCollection3D graphics = new GraphicCollection3D();
- int[] shape = xa.getShape();
- int colNum = shape[1];
- int rowNum = shape[0];
- double z1, z2, z3, z4, z;
- int idx1, idx2, idx3, idx4;
- if (!xa.getIndexPrivate().isFastIterator())
- xa = xa.copy();
- if (!ya.getIndexPrivate().isFastIterator())
- ya = ya.copy();
- if (!za.getIndexPrivate().isFastIterator())
- za = za.copy();
- for (int i = 0; i < rowNum - 1; i++) {
- for (int j = 0; j < colNum - 1; j++) {
- idx1 = i * colNum + j;
- idx2 = i * colNum + j + 1;
- idx3 = (i + 1) * colNum + j;
- idx4 = (i + 1) * colNum + j + 1;
- z1 = za.getDouble(idx1);
- z2 = za.getDouble(idx2);
- z3 = za.getDouble(idx3);
- z4 = za.getDouble(idx4);
- z = (z1 + z2 + z3 + z4) / 4.0;
- PolylineZShape ps = new PolylineZShape();
- List points = new ArrayList<>();
- points.add(new PointZ(xa.getDouble(idx1), ya.getDouble(idx1), z1));
- points.add(new PointZ(xa.getDouble(idx3), ya.getDouble(idx3), z3));
- points.add(new PointZ(xa.getDouble(idx4), ya.getDouble(idx4), z4));
- points.add(new PointZ(xa.getDouble(idx2), ya.getDouble(idx2), z2));
- points.add((PointZ) points.get(0).clone());
- ps.setPoints(points);
- Graphic graphic = new Graphic(ps, pb);
- graphics.add(graphic);
- }
- }
-
- return graphics;
- }
-
- /**
- * Add wireframe polylines
- *
- * @param xa X coordinate array
- * @param ya Y coordinate array
- * @param za Z coordinate array
- * @param ls Legend scheme
- * @return Graphics
- */
- public static GraphicCollection createWireframe(Array xa, Array ya, Array za, LegendScheme ls) {
- GraphicCollection3D graphics = new GraphicCollection3D();
- int[] shape = xa.getShape();
- int colNum = shape[1];
- int rowNum = shape[0];
- double z1, z2, z3, z4, z;
- int idx1, idx2, idx3, idx4;
- PolylineBreak pb;
- PolylineZShape ps;
- Graphic graphic;
- List points;
- if (!xa.getIndexPrivate().isFastIterator())
- xa = xa.copy();
- if (!ya.getIndexPrivate().isFastIterator())
- ya = ya.copy();
- if (!za.getIndexPrivate().isFastIterator())
- za = za.copy();
- for (int i = 0; i < rowNum - 1; i++) {
- for (int j = 0; j < colNum - 1; j++) {
- idx1 = i * colNum + j;
- idx2 = i * colNum + j + 1;
- idx3 = (i + 1) * colNum + j;
- idx4 = (i + 1) * colNum + j + 1;
- z1 = za.getDouble(idx1);
- z2 = za.getDouble(idx2);
- z3 = za.getDouble(idx3);
- z4 = za.getDouble(idx4);
- ps = new PolylineZShape();
- points = new ArrayList<>();
- points.add(new PointZ(xa.getDouble(idx1), ya.getDouble(idx1), z1));
- points.add(new PointZ(xa.getDouble(idx3), ya.getDouble(idx3), z3));
- ps.setPoints(points);
- z = (z1 + z3) * 0.5;
- ps.setValue(z);
- pb = (PolylineBreak) ls.findLegendBreak(z);
- graphic = new Graphic(ps, pb);
- graphics.add(graphic);
- ps = new PolylineZShape();
- points = new ArrayList<>();
- points.add(new PointZ(xa.getDouble(idx3), ya.getDouble(idx3), z3));
- points.add(new PointZ(xa.getDouble(idx4), ya.getDouble(idx4), z4));
- ps.setPoints(points);
- z = (z3 + z4) * 0.5;
- ps.setValue(z);
- pb = (PolylineBreak) ls.findLegendBreak(z);
- graphic = new Graphic(ps, pb);
- graphics.add(graphic);
- ps = new PolylineZShape();
- points = new ArrayList<>();
- points.add(new PointZ(xa.getDouble(idx4), ya.getDouble(idx4), z4));
- points.add(new PointZ(xa.getDouble(idx2), ya.getDouble(idx2), z2));
- ps.setPoints(points);
- z = (z4 + z2) * 0.5;
- ps.setValue(z);
- pb = (PolylineBreak) ls.findLegendBreak(z);
- graphic = new Graphic(ps, pb);
- graphics.add(graphic);
- ps = new PolylineZShape();
- points = new ArrayList<>();
- points.add(new PointZ(xa.getDouble(idx2), ya.getDouble(idx2), z2));
- points.add(new PointZ(xa.getDouble(idx1), ya.getDouble(idx1), z1));
- ps.setPoints(points);
- z = (z1 + z2) * 0.5;
- ps.setValue(z);
- pb = (PolylineBreak) ls.findLegendBreak(z);
- graphic = new Graphic(ps, pb);
- graphics.add(graphic);
- }
- }
- graphics.setSingleLegend(false);
- graphics.setLegendScheme(ls);
-
- return graphics;
- }
-
- /**
- * Add mesh polygons
- *
- * @param xa X coordinate array
- * @param ya Y coordinate array
- * @param za Z coordinate array
- * @param ls Legend scheme
- * @return Graphics
- */
- public static GraphicCollection createMeshPolygons(Array xa, Array ya, Array za, LegendScheme ls) {
- GraphicCollection3D graphics = new GraphicCollection3D();
- int[] shape = xa.getShape();
- int colNum = shape[1];
- int rowNum = shape[0];
- double z1, z2, z3, z4, z;
- int idx1, idx2, idx3, idx4;
- PolygonBreak pb;
- xa = xa.copyIfView();
- ya = ya.copyIfView();
- za = za.copyIfView();
- for (int i = 0; i < rowNum - 1; i++) {
- for (int j = 0; j < colNum - 1; j++) {
- idx1 = i * colNum + j;
- idx2 = i * colNum + j + 1;
- idx3 = (i + 1) * colNum + j;
- idx4 = (i + 1) * colNum + j + 1;
- z1 = za.getDouble(idx1);
- z2 = za.getDouble(idx2);
- z3 = za.getDouble(idx3);
- z4 = za.getDouble(idx4);
- z = (z1 + z2 + z3 + z4) / 4.0;
- PolygonZShape ps = new PolygonZShape();
- List points = new ArrayList<>();
- points.add(new PointZ(xa.getDouble(idx1), ya.getDouble(idx1), z1));
- points.add(new PointZ(xa.getDouble(idx3), ya.getDouble(idx3), z3));
- points.add(new PointZ(xa.getDouble(idx4), ya.getDouble(idx4), z4));
- points.add(new PointZ(xa.getDouble(idx2), ya.getDouble(idx2), z2));
- points.add((PointZ) points.get(0).clone());
- ps.setPoints(points);
- ps.lowValue = z;
- ps.highValue = ps.lowValue;
- pb = (PolygonBreak) ls.findLegendBreak(z);
- //pb.setDrawOutline(true);
- Graphic graphic = new Graphic(ps, pb);
- graphics.add(graphic);
- }
- }
- graphics.setAllQuads(true);
- graphics.setSingleLegend(false);
- graphics.setLegendScheme(ls);
- return graphics;
- }
-
- /**
- * Create 3D graphics from a VectorLayer.
- *
- * @param layer The layer
- * @param offset Offset of z axis.
- * @param xshift X shift - to shift the grahpics in x direction, normally
- * for map in 180 - 360 degree east
- * @return Graphics
- */
- public static GraphicCollection createGraphicsFromLayer(VectorLayer layer, double offset, double xshift) {
- GraphicCollection3D graphics = new GraphicCollection3D();
- graphics.setFixZ(true);
- graphics.setZValue(offset);
- ShapeTypes shapeType = layer.getShapeType();
- LegendScheme ls = layer.getLegendScheme();
- PointZ pz;
- ColorBreak cb;
- switch (shapeType) {
- case Point:
- for (PointShape shape : (List) layer.getShapes()) {
- PointZShape s = new PointZShape();
- PointD pd = shape.getPoint();
- pz = new PointZ(pd.X + xshift, pd.Y, offset);
- s.setPoint(pz);
- cb = ls.getLegendBreaks().get(shape.getLegendIndex());
- graphics.add(new Graphic(s, cb));
- }
- break;
- case Polyline:
- for (PolylineShape shape : (List) layer.getShapes()) {
- cb = ls.getLegendBreaks().get(shape.getLegendIndex());
- for (Polyline pl : (List) shape.getPolylines()) {
- PolylineZShape s = new PolylineZShape();
- List plist = new ArrayList<>();
- for (PointD pd : pl.getPointList()) {
- pz = new PointZ(pd.X + xshift, pd.Y, offset);
- plist.add(pz);
- }
- s.setPoints(plist);
- graphics.add(new Graphic(s, cb));
- }
- }
- break;
- case Polygon:
- for (PolygonShape shape : (List) layer.getShapes()) {
- PolygonZShape s = new PolygonZShape();
- List plist = new ArrayList<>();
- for (PointD pd : shape.getPoints()) {
- pz = new PointZ(pd.X + xshift, pd.Y, offset);
- plist.add(pz);
- }
- s.setPartNum(shape.getPartNum());
- s.setParts(shape.getParts());
- s.setPoints(plist);
- cb = ls.getLegendBreaks().get(shape.getLegendIndex());
- graphics.add(new Graphic(s, cb));
- }
- break;
- case PointZ:
- case PolylineZ:
- case PolygonZ:
- graphics.setFixZ(false);
- if (xshift == 0) {
- for (Shape shape : layer.getShapes()) {
-
- cb = ls.getLegendBreaks().get(shape.getLegendIndex());
- graphics.add(new Graphic(shape, cb));
- }
- } else {
- switch (shapeType) {
- case PointZ:
- for (PointZShape shape : (List) layer.getShapes()) {
- PointZShape s = new PointZShape();
- PointZ pd = (PointZ) shape.getPoint();
- pz = new PointZ(pd.X + xshift, pd.Y, pd.Z, pd.M);
- s.setPoint(pz);
- cb = ls.getLegendBreaks().get(shape.getLegendIndex());
- graphics.add(new Graphic(s, cb));
- }
- break;
- case PolylineZ:
- for (PolylineZShape shape : (List) layer.getShapes()) {
- cb = ls.getLegendBreaks().get(shape.getLegendIndex());
- for (PolylineZ pl : (List) shape.getPolylines()) {
- PolylineZShape s = new PolylineZShape();
- List plist = new ArrayList<>();
- for (PointZ pd : (List) pl.getPointList()) {
- pz = new PointZ(pd.X + xshift, pd.Y, pd.Z, pd.M);
- plist.add(pz);
- }
- s.setPoints(plist);
- graphics.add(new Graphic(s, cb));
- }
- }
- break;
- case PolygonZ:
- for (PolygonZShape shape : (List) layer.getShapes()) {
- PolygonZShape s = new PolygonZShape();
- List plist = new ArrayList<>();
- for (PointZ pd : (List) shape.getPoints()) {
- pz = new PointZ(pd.X + xshift, pd.Y, pd.Z, pd.M);
- plist.add(pz);
- }
- s.setPartNum(shape.getPartNum());
- s.setParts(shape.getParts());
- s.setPoints(plist);
- cb = ls.getLegendBreaks().get(shape.getLegendIndex());
- graphics.add(new Graphic(s, cb));
- }
- break;
- }
- }
- break;
- }
- graphics.setLegendScheme(ls);
-
- return graphics;
- }
-
- /**
- * Create rectangle graphic
- *
- * @param pos Rectangle position
- * @param curvature Curvature
- * @param pgb Polygon break
- * @return
- */
- public static Graphic createRectangle(List pos, List curvature, PolygonBreak pgb) {
- RectangleShape rect = new RectangleShape(pos.get(0).doubleValue(), pos.get(1).doubleValue(),
- pos.get(2).doubleValue(), pos.get(3).doubleValue());
- if (curvature != null) {
- rect.setRoundX(curvature.get(0).doubleValue());
- rect.setRoundY(curvature.get(1).doubleValue());
- }
- Graphic graphic = new Graphic(rect, pgb);
- return graphic;
- }
-
- /**
- * Create bar graphics
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param autoWidth Is auto width or not
- * @param widths Width
- * @param drawError Is draw error or not
- * @param error Error
- * @param drawBottom Is draw bottom or not
- * @param bottom Bottom
- * @param bbs Bar breaks
- * @return Bar graphics
- */
- public static GraphicCollection createBars(Array xdata, Array ydata, boolean autoWidth,
- Array widths, boolean drawError, Array error, boolean drawBottom, Array bottom,
- List bbs) {
- GraphicCollection graphics = new GraphicCollection();
- int n = (int) xdata.getSize();
- double x, y;
- BarBreak bb = bbs.get(0);
- PolylineBreak ebreak = new PolylineBreak();
- ebreak.setColor(bb.getErrorColor());
- ebreak.setWidth(bb.getErrorSize());
- double width = widths.getDouble(0);
- if (autoWidth && xdata.getSize() > 1) {
- width = (xdata.getDouble(1) - xdata.getDouble(0)) * width;
- }
- double bot = 0;
- if (drawBottom) {
- bot = bottom.getDouble(0);
- }
- double miny = 0;
- //boolean baseLine = false;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- int i = 0;
- while (xIter.hasNext()){
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- // Add bar
- if (drawBottom) {
- if (bottom.getSize() > i) {
- bot = bottom.getDouble(i);
- }
- miny = bot;
- y += miny;
- }
-// if (y < miny) {
-// baseLine = true;
-// }
- if (widths.getSize() > 1 && widths.getSize() > i) {
- width = widths.getDouble(i);
- }
- List pList = new ArrayList<>();
- pList.add(new PointD(x, miny));
- pList.add(new PointD(x, y));
- pList.add(new PointD(x + width, y));
- pList.add(new PointD(x + width, miny));
- pList.add(new PointD(x, miny));
- PolygonShape pgs = new PolygonShape();
- pgs.setPoints(pList);
- if (bbs.size() > i) {
- bb = bbs.get(i);
- }
- graphics.add(new Graphic(pgs, bb));
-
- if (drawError) {
- //Add error line
- double e = error.getDouble(i);
- pList = new ArrayList<>();
- pList.add(new PointD(x + width * 0.5, y - e));
- pList.add(new PointD(x + width * 0.5, y + e));
- PolylineShape pls = new PolylineShape();
- pls.setPoints(pList);
- graphics.add(new Graphic(pls, ebreak));
- //Add cap
- pList = new ArrayList<>();
- pList.add(new PointD(x + width * 0.25, y - e));
- pList.add(new PointD(x + width * 0.75, y - e));
- pls = new PolylineShape();
- pls.setPoints(pList);
- graphics.add(new Graphic(pls, ebreak));
- pList = new ArrayList<>();
- pList.add(new PointD(x + width * 0.25, y + e));
- pList.add(new PointD(x + width * 0.75, y + e));
- pls = new PolylineShape();
- pls.setPoints(pList);
- graphics.add(new Graphic(pls, ebreak));
- }
- i++;
- }
-
-// if (baseLine) {
-// List pList = new ArrayList<>();
-// double x1 = xdata.getDouble(0);
-// double x2 = xdata.getDouble((int) xdata.getSize() - 1);
-// x1 -= (x2 - x1);
-// x2 += (x2 - x1);
-// pList.add(new PointD(x1, miny));
-// pList.add(new PointD(x2, miny));
-// PolylineShape pls = new PolylineShape();
-// pls.setPoints(pList);
-// ebreak = new PolylineBreak();
-// ebreak.setColor(Color.black);
-// graphics.add(new Graphic(pls, ebreak));
-// }
- graphics.setSingleLegend(false);
-
- return graphics;
- }
-
- /**
- * Create horizontal bar graphics
- *
- * @param ydata Y data array
- * @param xdata X data array
- * @param autoHeight Is auto height or not
- * @param heights Heights
- * @param drawError Is draw error or not
- * @param error Error
- * @param drawLeft Is draw left or not
- * @param left Left
- * @param bbs Bar breaks
- * @return Bar graphics
- */
- public static GraphicCollection createHBars(Array ydata, Array xdata, boolean autoHeight,
- Array heights, boolean drawError, Array error, boolean drawLeft, Array left,
- List bbs) {
- GraphicCollection graphics = new GraphicCollection();
- int n = (int) ydata.getSize();
- double x, y;
- BarBreak bb = bbs.get(0);
- PolylineBreak ebreak = new PolylineBreak();
- ebreak.setColor(bb.getErrorColor());
- ebreak.setWidth(bb.getErrorSize());
- double height = heights.getDouble(0);
- if (autoHeight && ydata.getSize() > 1) {
- height = (ydata.getDouble(1) - ydata.getDouble(0)) * height;
- }
- double bot = 0;
- if (drawLeft) {
- bot = left.getDouble(0);
- }
- double minx = 0;
- //boolean baseLine = false;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- int i = 0;
- while (xIter.hasNext()){
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- // Add bar
- if (drawLeft) {
- if (left.getSize() > i) {
- bot = left.getDouble(i);
- }
- minx = bot;
- x += minx;
- }
-// if (x < minx) {
-// baseLine = true;
-// }
- if (heights.getSize() > 1 && heights.getSize() > i) {
- height = heights.getDouble(i);
- }
- List pList = new ArrayList<>();
- pList.add(new PointD(minx, y));
- pList.add(new PointD(x, y));
- pList.add(new PointD(x, y + height));
- pList.add(new PointD(minx, y + height));
- pList.add(new PointD(minx, y));
- PolygonShape pgs = new PolygonShape();
- pgs.setPoints(pList);
- if (bbs.size() > i) {
- bb = bbs.get(i);
- }
- graphics.add(new Graphic(pgs, bb));
-
- if (drawError) {
- //Add error line
- double e = error.getDouble(i);
- pList = new ArrayList<>();
- pList.add(new PointD(x - e, y + height * 0.5));
- pList.add(new PointD(x + e, y + height * 0.5));
- PolylineShape pls = new PolylineShape();
- pls.setPoints(pList);
- graphics.add(new Graphic(pls, ebreak));
- //Add cap
- pList = new ArrayList<>();
- pList.add(new PointD(x - e, y + height * 0.25));
- pList.add(new PointD(x - e, y + height * 0.75));
- pls = new PolylineShape();
- pls.setPoints(pList);
- graphics.add(new Graphic(pls, ebreak));
- pList = new ArrayList<>();
- pList.add(new PointD(x + e, y + height * 0.25));
- pList.add(new PointD(x + e, y + height * 0.75));
- pls = new PolylineShape();
- pls.setPoints(pList);
- graphics.add(new Graphic(pls, ebreak));
- }
- i++;
- }
-
-// if (baseLine) {
-// List pList = new ArrayList<>();
-// double y1 = ydata.getDouble(0);
-// double y2 = ydata.getDouble((int) ydata.getSize() - 1);
-// y1 -= (y2 - y1);
-// y2 += (y2 - y1);
-// pList.add(new PointD(minx, y1));
-// pList.add(new PointD(minx, y2));
-// PolylineShape pls = new PolylineShape();
-// pls.setPoints(pList);
-// ebreak = new PolylineBreak();
-// ebreak.setColor(Color.black);
-// graphics.add(new Graphic(pls, ebreak));
-// }
- graphics.setSingleLegend(false);
-
- return graphics;
- }
-
- /**
- * Create bar graphics
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param autoWidth Is auto width or not
- * @param widths Width
- * @param drawError Is draw error or not
- * @param error Error
- * @param drawBottom Is draw bottom or not
- * @param bottom Bottom
- * @param bbs Bar breaks
- * @return Bar graphics
- */
- public static GraphicCollection createBars1(Array xdata, Array ydata, boolean autoWidth,
- Array widths, boolean drawError, Array error, boolean drawBottom, Array bottom,
- List bbs) {
- GraphicCollection graphics = new GraphicCollection();
- int n = (int) xdata.getSize();
- double x, y;
- BarBreak bb = bbs.get(0);
- PolylineBreak ebreak = new PolylineBreak();
- ebreak.setColor(bb.getErrorColor());
- ebreak.setWidth(bb.getErrorSize());
- double width = widths.getDouble(0);
- if (autoWidth && xdata.getSize() > 1) {
- width = (xdata.getDouble(1) - xdata.getDouble(0)) * width;
- }
- double bot = 0;
- if (drawBottom) {
- bot = bottom.getDouble(0);
- }
- double miny = 0;
- boolean baseLine = false;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- int i = 0;
- while (xIter.hasNext()){
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- // Add bar
- if (drawBottom) {
- if (bottom.getSize() > i) {
- bot = bottom.getDouble(i);
- }
- miny = bot;
- y += miny;
- }
- if (y < miny) {
- baseLine = true;
- }
- if (widths.getSize() > 1 && widths.getSize() > i) {
- width = widths.getDouble(i);
- }
- List pList = new ArrayList<>();
- pList.add(new PointD(x, miny));
- for (double x1 = x; x1 < x + width; x1 += width / 100) {
- pList.add(new PointD(x1, y));
- }
- pList.add(new PointD(x + width, y));
- for (double x1 = x + width; x1 > x; x1 -= width / 20) {
- pList.add(new PointD(x1, miny));
- }
- pList.add(new PointD(x, miny));
- PolygonShape pgs = new PolygonShape();
- pgs.setPoints(pList);
- if (bbs.size() > i) {
- bb = bbs.get(i);
- }
- graphics.add(new Graphic(pgs, bb));
-
- if (drawError) {
- //Add error line
- double e = error.getDouble(i);
- pList = new ArrayList<>();
- pList.add(new PointD(x + width * 0.5, y - e));
- pList.add(new PointD(x + width * 0.5, y + e));
- PolylineShape pls = new PolylineShape();
- pls.setPoints(pList);
- graphics.add(new Graphic(pls, ebreak));
- //Add cap
- pList = new ArrayList<>();
- pList.add(new PointD(x + width * 0.25, y - e));
- pList.add(new PointD(x + width * 0.75, y - e));
- pls = new PolylineShape();
- pls.setPoints(pList);
- graphics.add(new Graphic(pls, ebreak));
- pList = new ArrayList<>();
- pList.add(new PointD(x + width * 0.25, y + e));
- pList.add(new PointD(x + width * 0.75, y + e));
- pls = new PolylineShape();
- pls.setPoints(pList);
- graphics.add(new Graphic(pls, ebreak));
- }
- i++;
- }
-
- if (baseLine) {
- List pList = new ArrayList<>();
- double x1 = xdata.getDouble(0);
- double x2 = xdata.getDouble((int) xdata.getSize() - 1);
- x1 -= (x2 - x1);
- x2 += (x2 - x1);
- pList.add(new PointD(x1, miny));
- pList.add(new PointD(x2, miny));
- PolylineShape pls = new PolylineShape();
- pls.setPoints(pList);
- ebreak = new PolylineBreak();
- ebreak.setColor(Color.black);
- graphics.add(new Graphic(pls, ebreak));
- }
- graphics.setSingleLegend(false);
-
- return graphics;
- }
-
- /**
- * Create 3D bar graphics
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param zdata Z data array
- * @param autoWidth Is auto width or not
- * @param widths Width
- * @param bottom Bottom
- * @param bbs Bar breaks
- * @return Bar graphics
- */
- public static GraphicCollection createBars3D(Array xdata, Array ydata, Array zdata, boolean autoWidth,
- Array widths, Array bottom, List bbs) {
- GraphicCollection graphics = new GraphicCollection();
- int n = (int) xdata.getSize();
- double x, y, z;
- BarBreak bb = bbs.get(0);
- double width = widths.getDouble(0);
- if (autoWidth && xdata.getSize() > 1) {
- width = (xdata.getDouble(1) - xdata.getDouble(0)) * width;
- }
- double bot = 0;
- double minz = 0;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- IndexIterator zIter = zdata.getIndexIterator();
- int i = 0;
- double hw = width * 0.5;
- while (xIter.hasNext()){
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- z = zIter.getDoubleNext();
- if (!Double.isNaN(z)) {
- // Add bar
- if (widths.getSize() > 1 && widths.getSize() > i) {
- width = widths.getDouble(i);
- hw = width * 0.5;
- }
- List pList = new ArrayList<>();
- pList.add(new PointZ(x + hw, y + hw, minz));
- pList.add(new PointZ(x + hw, y - hw, minz));
- pList.add(new PointZ(x + hw, y + hw, z));
- pList.add(new PointZ(x + hw, y - hw, z));
- pList.add(new PointZ(x - hw, y + hw, minz));
- pList.add(new PointZ(x - hw, y - hw, minz));
- pList.add(new PointZ(x - hw, y + hw, z));
- pList.add(new PointZ(x - hw, y - hw, z));
- CubicShape cs = new CubicShape();
- cs.setPoints(pList);
- if (bbs.size() > i) {
- bb = bbs.get(i);
- }
- graphics.add(new Graphic(cs, bb));
-
- i++;
- }
- }
-
- graphics.setSingleLegend(false);
-
- return graphics;
- }
-
- /**
- * Create 3D cylinder bar graphics
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param zdata Z data array
- * @param autoWidth Is auto width or not
- * @param widths Width
- * @param bottom Bottom
- * @param bbs Bar breaks
- * @return Bar graphics
- */
- public static GraphicCollection createCylinderBars3D(Array xdata, Array ydata, Array zdata, boolean autoWidth,
- Array widths, Array bottom, List bbs) {
- GraphicCollection graphics = new GraphicCollection();
- int n = (int) xdata.getSize();
- double x, y, z;
- BarBreak bb = bbs.get(0);
- double width = widths.getDouble(0);
- if (autoWidth && xdata.getSize() > 1) {
- width = (xdata.getDouble(1) - xdata.getDouble(0)) * width;
- }
- double bot = 0;
- double minz = 0;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- IndexIterator zIter = zdata.getIndexIterator();
- int i = 0;
- double hw = width * 0.5;
- while (xIter.hasNext()){
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- z = zIter.getDoubleNext();
- // Add bar
- if (widths.getSize() > 1 && widths.getSize() > i) {
- width = widths.getDouble(i);
- hw = width * 0.5;
- }
- List pList = new ArrayList<>();
- pList.add(new PointZ(x, y, minz));
- pList.add(new PointZ(x, y, z));
- CylinderShape cs = new CylinderShape(pList, hw);
- if (bbs.size() > i) {
- bb = bbs.get(i);
- }
- graphics.add(new Graphic(cs, bb));
-
- i++;
- }
-
- graphics.setSingleLegend(false);
-
- return graphics;
- }
-
- /**
- * Create histogram bar graphics
- *
- * @param data The data array
- * @param bins Bins number
- * @param bbs Bar breaks
- * @return Bar graphics
- */
- public static GraphicCollection createHistBars(Array data, int bins,
- List bbs) {
- List r = ArrayUtil.histogram(data, bins);
- Array xdata = r.get(1);
- Array ydata = r.get(0);
- return createHistBars(data, xdata, ydata, bbs);
- }
-
- /**
- * Create histogram bar graphics
- *
- * @param data The data array
- * @param bins Bins array
- * @param bbs Bar breaks
- * @return Bar graphics
- */
- public static GraphicCollection createHistBars(Array data, Array bins,
- List bbs) {
- List r = ArrayUtil.histogram(data, bins);
- Array xdata = r.get(1);
- Array ydata = r.get(0);
- return createHistBars(data, xdata, ydata, bbs);
- }
-
- /**
- * Create histogram bar graphics
- *
- * @param data The data array
- * @param xdata X bins data
- * @param ydata Y bins data
- * @param bbs Bar breaks
- * @return Bar graphics
- */
- public static GraphicCollection createHistBars(Array data, Array xdata, Array ydata,
- List bbs) {
- GraphicCollection graphics = new GraphicCollection();
- int n = (int) ydata.getSize();
- double x, y, width;
- BarBreak bb = bbs.get(0);
- if (!xdata.getIndexPrivate().isFastIterator())
- xdata = xdata.copy();
- if (!ydata.getIndexPrivate().isFastIterator())
- ydata = ydata.copy();
- for (int i = 0; i < n; i++) {
- x = (xdata.getDouble(i + 1) + xdata.getDouble(i)) * 0.5;
- width = xdata.getDouble(i + 1) - xdata.getDouble(i);
- y = ydata.getDouble(i);
- BarShape bs = new BarShape();
- bs.setPoint(new PointD(x, y));
- bs.setAutoWidth(false);
- bs.setWidth(width);
- bs.setDrawBottom(false);
- if (bbs.size() > i) {
- bb = bbs.get(i);
- }
- graphics.add(new Graphic(bs, bb));
- }
- if (bbs.size() == 1) {
- graphics.setSingleLegend(true);
- } else {
- graphics.setSingleLegend(false);
- }
-
- return graphics;
- }
-
- /**
- * Create stem graphics
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param plb Polyline break
- * @param pb Point break
- * @param bplb Baseline break
- * @param bottom Bottom
- * @return Bar graphics
- */
- public static GraphicCollection createStems(Array xdata, Array ydata, PolylineBreak plb, PointBreak pb,
- PolylineBreak bplb, double bottom) {
- GraphicCollection graphics = new GraphicCollection();
- int n = (int) xdata.getSize();
- double x, y;
- double miny = bottom;
- boolean baseLine = false;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- while (xIter.hasNext()) {
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- if (Double.isNaN(x) || Double.isNaN(y)) {
- continue;
- }
- // Add stem
- if (y < miny) {
- baseLine = true;
- }
- List pList = new ArrayList<>();
- pList.add(new PointD(x, miny));
- pList.add(new PointD(x, y));
- PolylineShape pls = new PolylineShape();
- pls.setPoints(pList);
- graphics.add(new Graphic(pls, plb));
- PointShape ps = new PointShape();
- ps.setPoint(new PointD(x, y));
- graphics.add(new Graphic(ps, pb));
- }
-
- if (baseLine) {
- List pList = new ArrayList<>();
- Index xIdx = xdata.getIndex();
- xIdx.setCurrentCounter(0);
- double x1 = xdata.getDouble(xIdx);
- xIdx.setCurrentCounter((int)xdata.getSize() - 1);
- double x2 = xdata.getDouble(xIdx);
- pList.add(new PointD(x1, miny));
- pList.add(new PointD(x2, miny));
- PolylineShape pls = new PolylineShape();
- pls.setPoints(pList);
- graphics.add(new Graphic(pls, bplb));
- }
- graphics.setSingleLegend(false);
-
- return graphics;
- }
-
- /**
- * Create an image graphic
- *
- * @param image The image
- * @return Image graphic
- */
- public static Graphic createImage(BufferedImage image) {
- ImageShape ishape = new ImageShape();
- ishape.setPoint(new PointD(0, 0));
- ishape.setImage(image);
- ishape.setExtent(new Extent(0, image.getWidth(), 0, image.getHeight()));
- return new Graphic(ishape, new ColorBreak());
- }
-
- /**
- * Create image
- *
- * @param gdata data array
- * @param extent Extent
- * @return Image graphic
- */
- public static Graphic createImage(Array gdata, List extent) {
- int width, height;
- width = gdata.getShape()[1];
- height = gdata.getShape()[0];
- Color undefColor = Color.white;
- BufferedImage aImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- Color color;
- Index index = gdata.getIndex();
- boolean isAlpha = gdata.getShape()[2] == 4;
- if (gdata.getDataType() == DataType.FLOAT || gdata.getDataType() == DataType.DOUBLE) {
- float r, g, b;
- if (isAlpha) {
- float a;
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- r = gdata.getFloat(index.set(i, j, 0));
- g = gdata.getFloat(index.set(i, j, 1));
- b = gdata.getFloat(index.set(i, j, 2));
- a = gdata.getFloat(index.set(i, j, 3));
- if (Double.isNaN(r) || Double.isNaN(g) || Double.isNaN(b) || Double.isNaN(a)) {
- color = undefColor;
- } else {
- color = new Color(r, g, b, a);
- }
- aImage.setRGB(j, height - i - 1, color.getRGB());
- }
- }
- } else {
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- r = gdata.getFloat(index.set(i, j, 0));
- g = gdata.getFloat(index.set(i, j, 1));
- b = gdata.getFloat(index.set(i, j, 2));
- if (Double.isNaN(r) || Double.isNaN(g) || Double.isNaN(b)) {
- color = undefColor;
- } else {
- color = new Color(r, g, b);
- }
- aImage.setRGB(j, height - i - 1, color.getRGB());
- }
- }
- }
- } else {
- int r, g, b;
- if (isAlpha) {
- int a;
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- r = gdata.getInt(index.set(i, j, 0));
- g = gdata.getInt(index.set(i, j, 1));
- b = gdata.getInt(index.set(i, j, 2));
- a = gdata.getInt(index.set(i, j, 3));
- if (Double.isNaN(r) || Double.isNaN(g) || Double.isNaN(b) || Double.isNaN(a)) {
- color = undefColor;
- } else {
- color = new Color(r, g, b, a);
- }
- aImage.setRGB(j, height - i - 1, color.getRGB());
- }
- }
- } else {
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- r = gdata.getInt(index.set(i, j, 0));
- g = gdata.getInt(index.set(i, j, 1));
- b = gdata.getInt(index.set(i, j, 2));
- if (Double.isNaN(r) || Double.isNaN(g) || Double.isNaN(b)) {
- color = undefColor;
- } else {
- color = new Color(r, g, b);
- }
- aImage.setRGB(j, height - i - 1, color.getRGB());
- }
- }
- }
- }
-
- ImageShape ishape = new ImageShape();
- double minx, maxx, miny, maxy;
- if (extent == null) {
- minx = 0;
- maxx = width;
- miny = 0;
- maxy = height;
- } else {
- minx = extent.get(0).doubleValue();
- maxx = extent.get(1).doubleValue();
- miny = extent.get(2).doubleValue();
- maxy = extent.get(3).doubleValue();
- }
- ishape.setPoint(new PointD(minx, miny));
- ishape.setImage(aImage);
- ishape.setExtent(new Extent(minx, maxx, miny, maxy));
- return new Graphic(ishape, new ColorBreak());
- }
-
- /**
- * Create image by RGB data array
- *
- * @param data RGB data array list
- * @param extent Exent
- * @return Image graphic
- */
- public static Graphic createImage(List data, List extent) {
- int width, height;
- width = data.get(0).getShape()[1];
- height = data.get(0).getShape()[0];
- Color undefColor = Color.white;
- BufferedImage aImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- Color color;
- boolean isAlpha = data.size() == 4;
- Array rdata = data.get(0);
- Array gdata = data.get(1);
- Array bdata = data.get(2);
- Index rindex = rdata.getIndex();
- Index gindex = gdata.getIndex();
- Index bindex = bdata.getIndex();
- if (rdata.getDataType() == DataType.FLOAT || rdata.getDataType() == DataType.DOUBLE) {
- float r, g, b;
- if (isAlpha) {
- float a;
- Array adata = data.get(3);
- Index aindex = adata.getIndex();
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- r = rdata.getFloat(rindex.set(i, j));
- g = gdata.getFloat(gindex.set(i, j));
- b = bdata.getFloat(bindex.set(i, j));
- a = adata.getFloat(aindex.set(i, j));
- if (Double.isNaN(r) || Double.isNaN(g) || Double.isNaN(b) || Double.isNaN(a)) {
- color = undefColor;
- } else {
- color = new Color(r, g, b, a);
- }
- aImage.setRGB(j, height - i - 1, color.getRGB());
- }
- }
- } else {
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- r = rdata.getFloat(rindex.set(i, j));
- g = gdata.getFloat(gindex.set(i, j));
- b = bdata.getFloat(bindex.set(i, j));
- if (Double.isNaN(r) || Double.isNaN(g) || Double.isNaN(b)) {
- color = undefColor;
- } else {
- color = new Color(r, g, b);
- }
- aImage.setRGB(j, height - i - 1, color.getRGB());
- }
- }
- }
- } else {
- int r, g, b;
- if (isAlpha) {
- int a;
- Array adata = data.get(3);
- Index aindex = adata.getIndex();
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- r = rdata.getInt(rindex.set(i, j));
- g = gdata.getInt(gindex.set(i, j));
- b = bdata.getInt(bindex.set(i, j));
- a = adata.getInt(aindex.set(i, j));
- if (Double.isNaN(r) || Double.isNaN(g) || Double.isNaN(b) || Double.isNaN(a)) {
- color = undefColor;
- } else {
- color = new Color(r, g, b, a);
- }
- aImage.setRGB(j, height - i - 1, color.getRGB());
- }
- }
- } else {
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- r = rdata.getInt(rindex.set(i, j));
- g = gdata.getInt(gindex.set(i, j));
- b = bdata.getInt(bindex.set(i, j));
- if (Double.isNaN(r) || Double.isNaN(g) || Double.isNaN(b)) {
- color = undefColor;
- } else {
- color = new Color(r, g, b);
- }
- aImage.setRGB(j, height - i - 1, color.getRGB());
- }
- }
- }
- }
-
- ImageShape ishape = new ImageShape();
- double minx, maxx, miny, maxy;
- if (extent == null) {
- minx = 0;
- maxx = width;
- miny = 0;
- maxy = height;
- } else {
- minx = extent.get(0).doubleValue();
- maxx = extent.get(1).doubleValue();
- miny = extent.get(2).doubleValue();
- maxy = extent.get(3).doubleValue();
- }
- ishape.setPoint(new PointD(minx, miny));
- ishape.setImage(aImage);
- ishape.setExtent(new Extent(minx, maxx, miny, maxy));
- return new Graphic(ishape, new ColorBreak());
- }
-
- /**
- * Create image by RGB data array
- *
- * @param x X data array
- * @param y Y data array
- * @param data RGB data array list
- * @param offset Offset in z axis
- * @param zdir Z direction - x, y or z
- * @param interpolation Interpolation
- * @return Graphics
- */
- public static GraphicCollection createImage(Array x, Array y, List data, double offset,
- String zdir, String interpolation) {
- Graphic gg = createImage(data, null);
- if (interpolation != null) {
- ((ImageShape) gg.getShape()).setInterpolation(interpolation);
- }
- ImageShape shape = (ImageShape)gg.getShape();
- Extent extent = shape.getExtent();
- Extent3D ex3 = new Extent3D();
- List coords = new ArrayList<>();
- switch (zdir.toLowerCase()) {
- case "x":
- ex3 = new Extent3D(offset, offset, extent.minX, extent.maxX, extent.minY, extent.maxY);
- coords.add(new PointZ(offset, extent.minX, extent.minY));
- coords.add(new PointZ(offset, extent.maxX, extent.minY));
- coords.add(new PointZ(offset, extent.maxX, extent.maxY));
- coords.add(new PointZ(offset, extent.minX, extent.maxY));
- break;
- case "y":
- ex3 = new Extent3D(extent.minX, extent.maxX, offset, offset, extent.minY, extent.maxY);
- coords.add(new PointZ(extent.minX, offset, extent.minY));
- coords.add(new PointZ(extent.maxX, offset, extent.minY));
- coords.add(new PointZ(extent.maxX, offset, extent.maxY));
- coords.add(new PointZ(extent.minX, offset, extent.maxY));
- break;
- case "z":
- ex3 = new Extent3D(extent.minX, extent.maxX, extent.minY, extent.maxY, offset, offset);
- coords.add(new PointZ(extent.minX, extent.minY, offset));
- coords.add(new PointZ(extent.maxX, extent.minY, offset));
- coords.add(new PointZ(extent.maxX, extent.maxY, offset));
- coords.add(new PointZ(extent.minX, extent.maxY, offset));
- break;
- }
- shape.setExtent(ex3);
- shape.setCoords(coords);
- GraphicCollection3D graphics = new GraphicCollection3D();
- graphics.setFixZ(true);
- graphics.setZDir(zdir);
- graphics.setZValue(offset);
- graphics.add(gg);
- return graphics;
- }
-
- /**
- * Create image
- *
- * @param gdata Grid data array
- * @param ls Legend scheme
- * @param extent Extent
- * @return Image graphic
- */
- public static Graphic createImage(Array gdata, LegendScheme ls, List extent) {
- int width, height, breakNum;
- width = gdata.getShape()[1];
- height = gdata.getShape()[0];
- breakNum = ls.getBreakNum();
- double[] breakValue = new double[breakNum];
- Color[] breakColor = new Color[breakNum];
- Color undefColor = Color.white;
- for (int i = 0; i < breakNum; i++) {
- breakValue[i] = Double.parseDouble(ls.getLegendBreaks().get(i).getEndValue().toString());
- breakColor[i] = ls.getLegendBreaks().get(i).getColor();
- if (ls.getLegendBreaks().get(i).isNoData()) {
- undefColor = ls.getLegendBreaks().get(i).getColor();
- }
- }
- Color defaultColor = breakColor[breakNum - 1]; //Last color
- BufferedImage aImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- double oneValue;
- Color oneColor;
- Index index = gdata.getIndex();
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- index.set(i, j);
- oneValue = gdata.getDouble(index);
- if (Double.isNaN(oneValue)) {
- oneColor = undefColor;
- } else {
- oneColor = defaultColor;
- if (ls.getLegendType() == LegendType.GraduatedColor) {
- for (int k = 0; k < breakNum - 1; k++) {
- if (oneValue < breakValue[k]) {
- oneColor = breakColor[k];
- break;
- }
- }
- } else {
- for (int k = 0; k < breakNum - 1; k++) {
- if (oneValue == breakValue[k]) {
- oneColor = breakColor[k];
- break;
- }
- }
- }
- }
- aImage.setRGB(j, height - i - 1, oneColor.getRGB());
- }
- }
-
- ImageShape ishape = new ImageShape();
- double minx, maxx, miny, maxy;
- if (extent == null) {
- minx = 0;
- maxx = width;
- miny = 0;
- maxy = height;
- } else {
- minx = extent.get(0).doubleValue();
- maxx = extent.get(1).doubleValue();
- miny = extent.get(2).doubleValue();
- maxy = extent.get(3).doubleValue();
- }
- ishape.setPoint(new PointD(minx, miny));
- ishape.setImage(aImage);
- ishape.setExtent(new Extent(minx, maxx, miny, maxy));
- return new Graphic(ishape, new ColorBreak());
- }
-
- /**
- * Create image
- *
- * @param gdata Grid data array
- * @param ls Legend scheme
- * @return Image graphic
- */
- public static Graphic createImage(GridArray gdata, LegendScheme ls) {
- int width, height, breakNum;
- width = gdata.getXNum();
- height = gdata.getYNum();
- breakNum = ls.getBreakNum();
- double[] breakValue = new double[breakNum];
- Color[] breakColor = new Color[breakNum];
- Color undefColor = Color.white;
- for (int i = 0; i < breakNum; i++) {
- breakValue[i] = Double.parseDouble(ls.getLegendBreaks().get(i).getEndValue().toString());
- breakColor[i] = ls.getLegendBreaks().get(i).getColor();
- if (ls.getLegendBreaks().get(i).isNoData()) {
- undefColor = ls.getLegendBreaks().get(i).getColor();
- }
- }
- Color defaultColor = breakColor[breakNum - 1]; //Last color
- BufferedImage aImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- double oneValue;
- Color oneColor;
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- oneValue = gdata.getDoubleValue(i, j);
- if (Double.isNaN(oneValue) || MIMath.doubleEquals(oneValue, gdata.missingValue)) {
- oneColor = undefColor;
- } else {
- oneColor = defaultColor;
- if (ls.getLegendType() == LegendType.GraduatedColor) {
- for (int k = 0; k < breakNum - 1; k++) {
- if (oneValue < breakValue[k]) {
- oneColor = breakColor[k];
- break;
- }
- }
- } else {
- for (int k = 0; k < breakNum - 1; k++) {
- if (oneValue == breakValue[k]) {
- oneColor = breakColor[k];
- break;
- }
- }
- }
- }
- aImage.setRGB(j, height - i - 1, oneColor.getRGB());
- }
- }
-
- ImageShape ishape = new ImageShape();
- double xdelta = BigDecimalUtil.mul(gdata.getXDelt(), 0.5);
- double xmin = BigDecimalUtil.sub(gdata.xArray[0], xdelta);
- double xmax = BigDecimalUtil.add(gdata.getXMax(), xdelta);
- double ydelta = BigDecimalUtil.mul(gdata.getYDelt(), 0.5);
- double ymin = BigDecimalUtil.sub(gdata.yArray[0], ydelta);
- double ymax = BigDecimalUtil.add(gdata.getYMax(), ydelta);
- ishape.setPoint(new PointD(xmin, ymin));
- ishape.setImage(aImage);
- ishape.setExtent(new Extent(xmin, xmax, ymin, ymax));
- return new ImageGraphic(ishape, ls);
- }
-
- /**
- * Create image
- *
- * @param gdata Grid data array
- * @param ls Legend scheme
- * @param extent Extent
- * @return Image graphic
- */
- public static Graphic createImage(GridArray gdata, LegendScheme ls, List extent) {
- int width, height, breakNum;
- width = gdata.getXNum();
- height = gdata.getYNum();
- breakNum = ls.getBreakNum();
- double[] breakValue = new double[breakNum];
- Color[] breakColor = new Color[breakNum];
- Color undefColor = Color.white;
- for (int i = 0; i < breakNum; i++) {
- breakValue[i] = Double.parseDouble(ls.getLegendBreaks().get(i).getEndValue().toString());
- breakColor[i] = ls.getLegendBreaks().get(i).getColor();
- if (ls.getLegendBreaks().get(i).isNoData()) {
- undefColor = ls.getLegendBreaks().get(i).getColor();
- }
- }
- Color defaultColor = breakColor[breakNum - 1]; //Last color
- BufferedImage aImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- double oneValue;
- Color oneColor;
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- oneValue = gdata.getDoubleValue(i, j);
- if (Double.isNaN(oneValue) || MIMath.doubleEquals(oneValue, gdata.missingValue)) {
- oneColor = undefColor;
- } else {
- oneColor = defaultColor;
- if (ls.getLegendType() == LegendType.GraduatedColor) {
- for (int k = 0; k < breakNum - 1; k++) {
- if (oneValue < breakValue[k]) {
- oneColor = breakColor[k];
- break;
- }
- }
- } else {
- for (int k = 0; k < breakNum - 1; k++) {
- if (oneValue == breakValue[k]) {
- oneColor = breakColor[k];
- break;
- }
- }
- }
- }
- aImage.setRGB(j, height - i - 1, oneColor.getRGB());
- }
- }
-
- ImageShape ishape = new ImageShape();
- double xmin, xmax, ymin, ymax;
- if (extent == null) {
- double xdelta = BigDecimalUtil.mul(gdata.getXDelt(), 0.5);
- xmin = BigDecimalUtil.sub(gdata.xArray[0], xdelta);
- xmax = BigDecimalUtil.add(gdata.getXMax(), xdelta);
- double ydelta = BigDecimalUtil.mul(gdata.getYDelt(), 0.5);
- ymin = BigDecimalUtil.sub(gdata.yArray[0], ydelta);
- ymax = BigDecimalUtil.add(gdata.getYMax(), ydelta);
- } else {
- xmin = extent.get(0).doubleValue();
- xmax = extent.get(1).doubleValue();
- ymin = extent.get(2).doubleValue();
- ymax = extent.get(3).doubleValue();
- }
- ishape.setPoint(new PointD(xmin, ymin));
- ishape.setImage(aImage);
- ishape.setExtent(new Extent(xmin, xmax, ymin, ymax));
- return new ImageGraphic(ishape, ls);
- }
-
- /**
- * Create image
- *
- * @param gdata Grid data array
- * @param ls Legend scheme
- * @param offset Offset of z axis
- * @param zdir Z direction - x, y or z
- * @param sePoint Start and end points [xstart, ystart, xend, yend]
- * @param interpolation Interpolation
- * @return Graphics
- */
- public static GraphicCollection createImage(GridArray gdata, LegendScheme ls, double offset,
- String zdir, List sePoint, String interpolation) {
- Graphic gg = createImage(gdata, ls);
- if (interpolation != null) {
- ((ImageShape) gg.getShape()).setInterpolation(interpolation);
- }
- ImageShape shape = (ImageShape) gg.getShape();
- Extent extent = shape.getExtent();
- Extent3D ex3 = new Extent3D();
- List coords = new ArrayList<>();
- switch (zdir.toLowerCase()) {
- case "x":
- ex3 = new Extent3D(offset, offset, extent.minX, extent.maxX, extent.minY, extent.maxY);
- coords.add(new PointZ(offset, extent.minX, extent.minY));
- coords.add(new PointZ(offset, extent.maxX, extent.minY));
- coords.add(new PointZ(offset, extent.maxX, extent.maxY));
- coords.add(new PointZ(offset, extent.minX, extent.maxY));
- break;
- case "y":
- ex3 = new Extent3D(extent.minX, extent.maxX, offset, offset, extent.minY, extent.maxY);
- coords.add(new PointZ(extent.minX, offset, extent.minY));
- coords.add(new PointZ(extent.maxX, offset, extent.minY));
- coords.add(new PointZ(extent.maxX, offset, extent.maxY));
- coords.add(new PointZ(extent.minX, offset, extent.maxY));
- break;
- case "xy":
- ex3 = new Extent3D(sePoint.get(0).doubleValue(), sePoint.get(2).doubleValue(),
- sePoint.get(1).doubleValue(), sePoint.get(3).doubleValue(), extent.minY, extent.maxY);
- coords.add(new PointZ(sePoint.get(0).doubleValue(), sePoint.get(1).doubleValue(), extent.minY));
- coords.add(new PointZ(sePoint.get(2).doubleValue(), sePoint.get(1).doubleValue(), extent.minY));
- coords.add(new PointZ(sePoint.get(2).doubleValue(), sePoint.get(3).doubleValue(), extent.maxY));
- coords.add(new PointZ(sePoint.get(0).doubleValue(), sePoint.get(3).doubleValue(), extent.maxY));
- break;
- case "z":
- ex3 = new Extent3D(extent.minX, extent.maxX, extent.minY, extent.maxY, offset, offset);
- coords.add(new PointZ(extent.minX, extent.minY, offset));
- coords.add(new PointZ(extent.maxX, extent.minY, offset));
- coords.add(new PointZ(extent.maxX, extent.maxY, offset));
- coords.add(new PointZ(extent.minX, extent.maxY, offset));
- break;
- }
- shape.setExtent(ex3);
- shape.setCoords(coords);
- GraphicCollection3D graphics = new GraphicCollection3D();
- graphics.setFixZ(true);
- graphics.setZDir(zdir);
- graphics.setZValue(offset);
- graphics.setSEPoint(sePoint);
- graphics.add(gg);
- graphics.setLegendScheme(ls);
- graphics.setSingleLegend(false);
- return graphics;
- }
-
- /**
- * Create image
- *
- * @param layer Image layer
- * @param offset Offset of z axis
- * @param xshift X shift - to shift the grahpics in x direction, normally
- * for map in 180 - 360 degree east
- * @param interpolation Interpolation
- * @return Graphics
- */
- public static GraphicCollection createImage(ImageLayer layer, double offset, double xshift,
- String interpolation) {
- GraphicCollection3D graphics = new GraphicCollection3D();
- graphics.setFixZ(true);
- graphics.setZDir("z");
- graphics.setZValue(offset);
- ImageShape ishape = new ImageShape();
- ishape.setImage(layer.getImage());
- Extent extent = layer.getExtent();
- Extent3D ex3 = new Extent3D(extent.minX + xshift, extent.maxX + xshift, extent.minY, extent.maxY, offset, offset);
- List coords = new ArrayList<>();
- coords.add(new PointZ(extent.minX + xshift, extent.minY, offset));
- coords.add(new PointZ(extent.maxX + xshift, extent.minY, offset));
- coords.add(new PointZ(extent.maxX + xshift, extent.maxY, offset));
- coords.add(new PointZ(extent.minX + xshift, extent.maxY, offset));
- ishape.setExtent(ex3);
- ishape.setCoords(coords);
- Graphic gg = new Graphic(ishape, new ColorBreak());
- if (interpolation != null) {
- ((ImageShape) gg.getShape()).setInterpolation(interpolation);
- }
- graphics.add(gg);
-
- return graphics;
- }
-
- /**
- * Create contour lines
- *
- * @param gridData Grid data
- * @param ls Legend scheme
- * @param isSmooth Is smooth or not
- * @return Contour lines
- */
- public static GraphicCollection createContourLines(GridData gridData, LegendScheme ls, boolean isSmooth) {
- ls = ls.convertTo(ShapeTypes.Polyline);
- Object[] ccs = LegendManage.getContoursAndColors(ls);
- double[] cValues = (double[]) ccs[0];
-
- int[][] S1 = new int[gridData.data.length][gridData.data[0].length];
- double[] x = gridData.xArray;
- double[] y = gridData.yArray;
- if (gridData.getXDelt() < 0)
- ArrayUtils.reverse(x);
- if (gridData.getYDelt() < 0)
- ArrayUtils.reverse(y);
- Object[] cbs = ContourDraw.tracingContourLines(gridData.data,
- cValues, x, y, gridData.missingValue, S1);
- List ContourLines = (List) cbs[0];
-
- if (ContourLines.isEmpty()) {
- return null;
- }
-
- if (isSmooth) {
- ContourLines = wcontour.Contour.smoothLines(ContourLines);
- }
-
- wcontour.global.PolyLine aLine;
- double v;
- ColorBreak cbb = ls.findLegendBreak(0);
- GraphicCollection graphics = new GraphicCollection();
- for (int i = 0; i < ContourLines.size(); i++) {
- aLine = ContourLines.get(i);
- v = aLine.Value;
-
- PolylineShape aPolyline = new PolylineShape();
- PointD aPoint;
- List pList = new ArrayList<>();
- for (int j = 0; j < aLine.PointList.size(); j++) {
- aPoint = new PointD();
- aPoint.X = aLine.PointList.get(j).X;
- aPoint.Y = aLine.PointList.get(j).Y;
- pList.add(aPoint);
- }
- aPolyline.setPoints(pList);
- aPolyline.setValue(v);
- aPolyline.setExtent(GeometryUtil.getPointsExtent(pList));
-
- switch (ls.getLegendType()) {
- case UniqueValue:
- for (int j = 0; j < ls.getBreakNum(); j++) {
- ColorBreak cb = ls.getLegendBreaks().get(j);
- if (MIMath.doubleEquals(v, Double.parseDouble(cb.getStartValue().toString()))) {
- cbb = cb;
- break;
- }
- }
- break;
- case GraduatedColor:
- int blNum = 0;
- for (int j = 0; j < ls.getBreakNum(); j++) {
- ColorBreak cb = ls.getLegendBreaks().get(j);
- blNum += 1;
- if (MIMath.doubleEquals(v, Double.parseDouble(cb.getStartValue().toString()))
- || (v > Double.parseDouble(cb.getStartValue().toString())
- && v < Double.parseDouble(cb.getEndValue().toString()))
- || (blNum == ls.getBreakNum() && v == Double.parseDouble(cb.getEndValue().toString()))) {
- cbb = cb;
- break;
- }
- }
- break;
- }
- graphics.add(new Graphic(aPolyline, cbb));
- }
- graphics.setSingleLegend(false);
- graphics.setLegendScheme(ls);
-
- return graphics;
- }
-
- /**
- * Create contour lines
- *
- * @param gridData Grid data
- * @param offset Offset in z direction
- * @param zdir Z direction - x, y or z
- * @param ls Legend scheme
- * @param isSmooth Is smooth or not
- * @return Contour lines
- */
- public static GraphicCollection createContourLines(GridData gridData, double offset,
- String zdir, LegendScheme ls, boolean isSmooth) {
- ls = ls.convertTo(ShapeTypes.Polyline);
- Object[] ccs = LegendManage.getContoursAndColors(ls);
- double[] cValues = (double[]) ccs[0];
-
- int[][] S1 = new int[gridData.data.length][gridData.data[0].length];
- double[] x = gridData.xArray;
- double[] y = gridData.yArray;
- if (gridData.getXDelt() < 0)
- ArrayUtils.reverse(x);
- if (gridData.getYDelt() < 0)
- ArrayUtils.reverse(y);
- Object[] cbs = ContourDraw.tracingContourLines(gridData.data,
- cValues, x, y, gridData.missingValue, S1);
- List ContourLines = (List) cbs[0];
-
- if (ContourLines.isEmpty()) {
- return null;
- }
-
- if (isSmooth) {
- ContourLines = wcontour.Contour.smoothLines(ContourLines);
- }
-
- wcontour.global.PolyLine aLine;
- double v;
- ColorBreak cbb;
- GraphicCollection3D graphics = new GraphicCollection3D();
- graphics.setFixZ(true);
- graphics.setZValue(offset);
- zdir = zdir.toLowerCase();
- graphics.setZDir(zdir);
- for (int i = 0; i < ContourLines.size(); i++) {
- aLine = ContourLines.get(i);
- v = aLine.Value;
-
- PolylineZShape aPolyline = new PolylineZShape();
- PointZ aPoint;
- List pList = new ArrayList<>();
- switch (zdir) {
- case "x":
- for (int j = 0; j < aLine.PointList.size(); j++) {
- aPoint = new PointZ();
- aPoint.X = offset;
- aPoint.Y = aLine.PointList.get(j).X;
- aPoint.Z = aLine.PointList.get(j).Y;
- pList.add(aPoint);
- }
- break;
- case "y":
- for (int j = 0; j < aLine.PointList.size(); j++) {
- aPoint = new PointZ();
- aPoint.Y = offset;
- aPoint.X = aLine.PointList.get(j).X;
- aPoint.Z = aLine.PointList.get(j).Y;
- pList.add(aPoint);
- }
- break;
- case "z":
- for (int j = 0; j < aLine.PointList.size(); j++) {
- aPoint = new PointZ();
- aPoint.X = aLine.PointList.get(j).X;
- aPoint.Y = aLine.PointList.get(j).Y;
- aPoint.Z = offset;
- pList.add(aPoint);
- }
- break;
- }
- aPolyline.setPoints(pList);
- aPolyline.setValue(v);
- aPolyline.setExtent(GeometryUtil.getPointsExtent(pList));
- cbb = ls.findLegendBreak(v);
- graphics.add(new Graphic(aPolyline, cbb));
- }
- graphics.setSingleLegend(false);
- graphics.setLegendScheme(ls);
-
- return graphics;
- }
-
- /**
- * Create contour lines
- *
- * @param gridData Grid data
- * @param offset Offset in z direction
- * @param zdir Z direction - x, y or z
- * @param ls Legend scheme
- * @param isSmooth Is smooth or not
- * @param sePoint Start and end points [xstart, ystart, xend, yend]
- * @return Contour lines
- */
- public static GraphicCollection createContourLines(GridData gridData, double offset,
- String zdir, LegendScheme ls, boolean isSmooth, List sePoint) {
- ls = ls.convertTo(ShapeTypes.Polyline);
- Object[] ccs = LegendManage.getContoursAndColors(ls);
- double[] cValues = (double[]) ccs[0];
-
- int[][] S1 = new int[gridData.data.length][gridData.data[0].length];
- double[] xArray = gridData.xArray;
- double[] yArray = gridData.yArray;
- if (gridData.getXDelt() < 0)
- ArrayUtils.reverse(xArray);
- if (gridData.getYDelt() < 0)
- ArrayUtils.reverse(yArray);
- Object[] cbs = ContourDraw.tracingContourLines(gridData.data,
- cValues, xArray, yArray, gridData.missingValue, S1);
- List ContourLines = (List) cbs[0];
-
- if (ContourLines.isEmpty()) {
- return null;
- }
-
- if (isSmooth) {
- ContourLines = wcontour.Contour.smoothLines(ContourLines);
- }
-
- wcontour.global.PolyLine aLine;
- double v;
- ColorBreak cbb;
- GraphicCollection3D graphics = new GraphicCollection3D();
- graphics.setFixZ(true);
- graphics.setZValue(offset);
- graphics.setSEPoint(sePoint);
- zdir = zdir.toLowerCase();
- graphics.setZDir(zdir);
- double x, y, xs, xe, ys, ye;
- xs = sePoint.get(0).doubleValue();
- ys = sePoint.get(1).doubleValue();
- xe = sePoint.get(2).doubleValue();
- ye = sePoint.get(3).doubleValue();
- for (int i = 0; i < ContourLines.size(); i++) {
- aLine = ContourLines.get(i);
- v = aLine.Value;
-
- PolylineZShape aPolyline = new PolylineZShape();
- PointZ aPoint;
- List pList = new ArrayList<>();
- switch (zdir) {
- case "x":
- for (int j = 0; j < aLine.PointList.size(); j++) {
- aPoint = new PointZ();
- aPoint.X = offset;
- aPoint.Y = aLine.PointList.get(j).X;
- aPoint.Z = aLine.PointList.get(j).Y;
- pList.add(aPoint);
- }
- break;
- case "y":
- for (int j = 0; j < aLine.PointList.size(); j++) {
- aPoint = new PointZ();
- aPoint.Y = offset;
- aPoint.X = aLine.PointList.get(j).X;
- aPoint.Z = aLine.PointList.get(j).Y;
- pList.add(aPoint);
- }
- break;
- case "xy":
- for (int j = 0; j < aLine.PointList.size(); j++) {
- x = aLine.PointList.get(j).X;
- y = aLine.PointList.get(j).Y;
- aPoint = new PointZ();
- aPoint.X = x;
- aPoint.Y = ys + (ye - ys) * (x - xs) / (xe - xs);
- aPoint.Z = y;
- pList.add(aPoint);
- }
- break;
- case "z":
- for (int j = 0; j < aLine.PointList.size(); j++) {
- aPoint = new PointZ();
- aPoint.X = aLine.PointList.get(j).X;
- aPoint.Y = aLine.PointList.get(j).Y;
- aPoint.Z = offset;
- pList.add(aPoint);
- }
- break;
- }
- aPolyline.setPoints(pList);
- aPolyline.setValue(v);
- aPolyline.setExtent(GeometryUtil.getPointsExtent(pList));
- cbb = ls.findLegendBreak(v);
- graphics.add(new Graphic(aPolyline, cbb));
- }
- graphics.setSingleLegend(false);
- graphics.setLegendScheme(ls);
-
- return graphics;
- }
-
- /**
- * Create contour polygons
- *
- * @param gridData Grid data
- * @param ls Legend scheme
- * @param isSmooth Is smooth or not
- * @return Contour polygons
- */
- public static GraphicCollection createContourPolygons(GridData gridData, LegendScheme ls, boolean isSmooth) {
- ls = ls.convertTo(ShapeTypes.Polygon);
- Object[] ccs = LegendManage.getContoursAndColors(ls);
- double[] cValues = (double[]) ccs[0];
-
- double minData;
- double maxData;
- double[] maxmin = new double[2];
- gridData.getMaxMinValue(maxmin);
- maxData = maxmin[0];
- minData = maxmin[1];
-
- int[][] S1 = new int[gridData.data.length][gridData.data[0].length];
- double[] xArray = gridData.xArray;
- double[] yArray = gridData.yArray;
- if (gridData.getXDelt() < 0)
- ArrayUtils.reverse(xArray);
- if (gridData.getYDelt() < 0)
- ArrayUtils.reverse(yArray);
- Object[] cbs = ContourDraw.tracingContourLines(gridData.data,
- cValues, xArray, yArray, gridData.missingValue, S1);
- List contourLines = (List) cbs[0];
- List borders = (List) cbs[1];
-
- if (isSmooth) {
- contourLines = wcontour.Contour.smoothLines(contourLines);
- }
- List contourPolygons = ContourDraw.tracingPolygons(gridData.data, contourLines, borders, cValues);
-
- double v;
- ColorBreak cbb = ls.findLegendBreak(0);
- GraphicCollection graphics = new GraphicCollection();
- for (int i = 0; i < contourPolygons.size(); i++) {
- wcontour.global.Polygon poly = contourPolygons.get(i);
- v = poly.LowValue;
- PointD aPoint;
- List pList = new ArrayList<>();
- for (wcontour.global.PointD pointList : poly.OutLine.PointList) {
- aPoint = new PointD();
- aPoint.X = pointList.X;
- aPoint.Y = pointList.Y;
- pList.add(aPoint);
- }
- if (!GeoComputation.isClockwise(pList)) {
- Collections.reverse(pList);
- }
- PolygonShape aPolygonShape = new PolygonShape();
- aPolygonShape.setPoints(pList);
- aPolygonShape.setExtent(GeometryUtil.getPointsExtent(pList));
- aPolygonShape.lowValue = v;
- if (poly.HasHoles()) {
- for (PolyLine holeLine : poly.HoleLines) {
- pList = new ArrayList<>();
- for (wcontour.global.PointD pointList : holeLine.PointList) {
- aPoint = new PointD();
- aPoint.X = pointList.X;
- aPoint.Y = pointList.Y;
- pList.add(aPoint);
- }
- aPolygonShape.addHole(pList, 0);
- }
- }
- int valueIdx = Arrays.binarySearch(cValues, v);
- if (valueIdx < 0) {
- valueIdx = -valueIdx;
- }
- //int valueIdx = findIndex(cValues, v);
- if (valueIdx == cValues.length - 1) {
- aPolygonShape.highValue = maxData;
- } else {
- aPolygonShape.highValue = cValues[valueIdx + 1];
- }
-// if (!aPolygon.IsBorder) {
-// if (!aPolygon.IsHighCenter) {
-// aPolygonShape.highValue = aValue;
-// if (valueIdx == 0) {
-// aPolygonShape.lowValue = minData;
-// } else {
-// aPolygonShape.lowValue = cValues[valueIdx - 1];
-// }
-// }
-// }
- if (!poly.IsHighCenter && poly.HighValue == poly.LowValue) {
- aPolygonShape.highValue = v;
- if (valueIdx == 0) {
- aPolygonShape.lowValue = minData;
- } else {
- aPolygonShape.lowValue = cValues[valueIdx - 1];
- }
- }
-
- v = aPolygonShape.lowValue;
- switch (ls.getLegendType()) {
- case UniqueValue:
- for (int j = 0; j < ls.getBreakNum(); j++) {
- ColorBreak cb = ls.getLegendBreaks().get(j);
- if (MIMath.doubleEquals(v, Double.parseDouble(cb.getStartValue().toString()))) {
- cbb = cb;
- break;
- }
- }
- break;
- case GraduatedColor:
- int blNum = 0;
- for (int j = 0; j < ls.getBreakNum(); j++) {
- ColorBreak cb = ls.getLegendBreaks().get(j);
- blNum += 1;
- if (MIMath.doubleEquals(v, Double.parseDouble(cb.getStartValue().toString()))
- || (v > Double.parseDouble(cb.getStartValue().toString())
- && v < Double.parseDouble(cb.getEndValue().toString()))
- || (blNum == ls.getBreakNum() && v == Double.parseDouble(cb.getEndValue().toString()))) {
- cbb = cb;
- break;
- }
- }
- break;
- }
- graphics.add(new Graphic(aPolygonShape, cbb));
- }
- graphics.setSingleLegend(false);
- graphics.setLegendScheme(ls);
-
- return graphics;
- }
-
- /**
- * Create 3D contour polygons
- *
- * @param gridData Grid data
- * @param offset Offset of z axis
- * @param zdir Z direction - x, y or z
- * @param ls Legend scheme
- * @param isSmooth Is smooth or not
- * @return Contour polygons
- */
- public static GraphicCollection createContourPolygons(GridData gridData, double offset,
- String zdir, LegendScheme ls, boolean isSmooth) {
- ls = ls.convertTo(ShapeTypes.Polygon);
- Object[] ccs = LegendManage.getContoursAndColors(ls);
- double[] cValues = (double[]) ccs[0];
-
- double minData;
- double maxData;
- double[] maxmin = new double[2];
- gridData.getMaxMinValue(maxmin);
- maxData = maxmin[0];
- minData = maxmin[1];
-
- int[][] S1 = new int[gridData.data.length][gridData.data[0].length];
- double[] xArray = gridData.xArray;
- double[] yArray = gridData.yArray;
- if (gridData.getXDelt() < 0)
- ArrayUtils.reverse(xArray);
- if (gridData.getYDelt() < 0)
- ArrayUtils.reverse(yArray);
- Object[] cbs = ContourDraw.tracingContourLines(gridData.data,
- cValues, xArray, yArray, gridData.missingValue, S1);
- List contourLines = (List) cbs[0];
- List borders = (List) cbs[1];
-
- if (isSmooth) {
- contourLines = wcontour.Contour.smoothLines(contourLines);
- }
- List contourPolygons = ContourDraw.tracingPolygons(gridData.data, contourLines, borders, cValues);
-
- double v;
- ColorBreak cbb;
- GraphicCollection3D graphics = new GraphicCollection3D();
- graphics.setFixZ(true);
- graphics.setZValue(offset);
- zdir = zdir.toLowerCase();
- graphics.setZDir(zdir);
- for (int i = 0; i < contourPolygons.size(); i++) {
- wcontour.global.Polygon poly = contourPolygons.get(i);
- v = poly.LowValue;
- PointZ aPoint;
- List pList = new ArrayList<>();
- switch (zdir) {
- case "x":
- for (wcontour.global.PointD pointList : poly.OutLine.PointList) {
- aPoint = new PointZ();
- aPoint.Y = pointList.X;
- aPoint.Z = pointList.Y;
- aPoint.X = offset;
- pList.add(aPoint);
- }
- break;
- case "y":
- for (wcontour.global.PointD pointList : poly.OutLine.PointList) {
- aPoint = new PointZ();
- aPoint.X = pointList.X;
- aPoint.Z = pointList.Y;
- aPoint.Y = offset;
- pList.add(aPoint);
- }
- break;
- case "z":
- for (wcontour.global.PointD pointList : poly.OutLine.PointList) {
- aPoint = new PointZ();
- aPoint.X = pointList.X;
- aPoint.Y = pointList.Y;
- aPoint.Z = offset;
- pList.add(aPoint);
- }
- break;
- }
-
- if (!GeoComputation.isClockwise(pList)) {
- Collections.reverse(pList);
- }
- PolygonZShape aPolygonShape = new PolygonZShape();
- aPolygonShape.setPoints(pList);
- aPolygonShape.setExtent(GeometryUtil.getPointsExtent(pList));
- aPolygonShape.lowValue = v;
- if (poly.HasHoles()) {
- switch (zdir) {
- case "x":
- for (PolyLine holeLine : poly.HoleLines) {
- pList = new ArrayList<>();
- for (wcontour.global.PointD pointList : holeLine.PointList) {
- aPoint = new PointZ();
- aPoint.Y = pointList.X;
- aPoint.Z = pointList.Y;
- aPoint.X = offset;
- pList.add(aPoint);
- }
- aPolygonShape.addHole(pList, 0);
- }
- break;
- case "y":
- for (PolyLine holeLine : poly.HoleLines) {
- pList = new ArrayList<>();
- for (wcontour.global.PointD pointList : holeLine.PointList) {
- aPoint = new PointZ();
- aPoint.X = pointList.X;
- aPoint.Z = pointList.Y;
- aPoint.Y = offset;
- pList.add(aPoint);
- }
- aPolygonShape.addHole(pList, 0);
- }
- break;
- case "z":
- for (PolyLine holeLine : poly.HoleLines) {
- pList = new ArrayList<>();
- for (wcontour.global.PointD pointList : holeLine.PointList) {
- aPoint = new PointZ();
- aPoint.X = pointList.X;
- aPoint.Y = pointList.Y;
- aPoint.Z = offset;
- pList.add(aPoint);
- }
- aPolygonShape.addHole(pList, 0);
- }
- break;
- }
- }
- int valueIdx = Arrays.binarySearch(cValues, v);
- if (valueIdx < 0) {
- valueIdx = -valueIdx;
- }
- //int valueIdx = findIndex(cValues, v);
- if (valueIdx == cValues.length - 1) {
- aPolygonShape.highValue = maxData;
- } else {
- aPolygonShape.highValue = cValues[valueIdx + 1];
- }
- if (!poly.IsHighCenter && poly.HighValue == poly.LowValue) {
- aPolygonShape.highValue = v;
- if (valueIdx == 0) {
- aPolygonShape.lowValue = minData;
- } else {
- aPolygonShape.lowValue = cValues[valueIdx - 1];
- }
- }
-
- v = aPolygonShape.lowValue;
- cbb = ls.findLegendBreak(v);
- graphics.add(new Graphic(aPolygonShape, cbb));
- }
- graphics.setSingleLegend(false);
- graphics.setLegendScheme(ls);
-
- return graphics;
- }
-
- /**
- * Create 3D contour polygons
- *
- * @param gridData Grid data
- * @param offset Offset of z axis
- * @param zdir Z direction - x, y or z
- * @param ls Legend scheme
- * @param isSmooth Is smooth or not
- * @param sePoint Start and end points [xstart, ystart, xend, yend]
- * @return Contour polygons
- */
- public static GraphicCollection createContourPolygons(GridData gridData, double offset,
- String zdir, LegendScheme ls, boolean isSmooth, List sePoint) {
- ls = ls.convertTo(ShapeTypes.Polygon);
- Object[] ccs = LegendManage.getContoursAndColors(ls);
- double[] cValues = (double[]) ccs[0];
-
- double minData;
- double maxData;
- double[] maxmin = new double[2];
- gridData.getMaxMinValue(maxmin);
- maxData = maxmin[0];
- minData = maxmin[1];
-
- int[][] S1 = new int[gridData.data.length][gridData.data[0].length];
- double[] xArray = gridData.xArray;
- double[] yArray = gridData.yArray;
- if (gridData.getXDelt() < 0)
- ArrayUtils.reverse(xArray);
- if (gridData.getYDelt() < 0)
- ArrayUtils.reverse(yArray);
- Object[] cbs = ContourDraw.tracingContourLines(gridData.data,
- cValues, xArray, yArray, gridData.missingValue, S1);
- List contourLines = (List) cbs[0];
- List borders = (List) cbs[1];
-
- if (isSmooth) {
- contourLines = wcontour.Contour.smoothLines(contourLines);
- }
- List contourPolygons = ContourDraw.tracingPolygons(gridData.data, contourLines, borders, cValues);
-
- double v;
- ColorBreak cbb;
- GraphicCollection3D graphics = new GraphicCollection3D();
- graphics.setFixZ(true);
- graphics.setZValue(offset);
- graphics.setSEPoint(sePoint);
- zdir = zdir.toLowerCase();
- graphics.setZDir(zdir);
- double x, y, xs, xe, ys, ye;
- xs = sePoint.get(0).doubleValue();
- ys = sePoint.get(1).doubleValue();
- xe = sePoint.get(2).doubleValue();
- ye = sePoint.get(3).doubleValue();
- for (int i = 0; i < contourPolygons.size(); i++) {
- wcontour.global.Polygon poly = contourPolygons.get(i);
- v = poly.LowValue;
- PointZ aPoint;
- List pList = new ArrayList<>();
- switch (zdir) {
- case "x":
- for (wcontour.global.PointD pointList : poly.OutLine.PointList) {
- aPoint = new PointZ();
- aPoint.Y = pointList.X;
- aPoint.Z = pointList.Y;
- aPoint.X = offset;
- pList.add(aPoint);
- }
- break;
- case "y":
- for (wcontour.global.PointD pointList : poly.OutLine.PointList) {
- aPoint = new PointZ();
- aPoint.X = pointList.X;
- aPoint.Z = pointList.Y;
- aPoint.Y = offset;
- pList.add(aPoint);
- }
- break;
- case "xy":
- for (wcontour.global.PointD pointList : poly.OutLine.PointList) {
- x = pointList.X;
- y = pointList.Y;
- aPoint = new PointZ();
- aPoint.X = x;
- aPoint.Y = ys + (ye - ys) * (x - xs) / (xe - xs);
- aPoint.Z = y;
- pList.add(aPoint);
- }
- break;
- case "z":
- for (wcontour.global.PointD pointList : poly.OutLine.PointList) {
- aPoint = new PointZ();
- aPoint.X = pointList.X;
- aPoint.Y = pointList.Y;
- aPoint.Z = offset;
- pList.add(aPoint);
- }
- break;
- }
-
- if (!GeoComputation.isClockwise(pList)) {
- Collections.reverse(pList);
- }
- PolygonZShape aPolygonShape = new PolygonZShape();
- aPolygonShape.setPoints(pList);
- aPolygonShape.setExtent(GeometryUtil.getPointsExtent(pList));
- aPolygonShape.lowValue = v;
- if (poly.HasHoles()) {
- switch (zdir) {
- case "x":
- for (PolyLine holeLine : poly.HoleLines) {
- pList = new ArrayList<>();
- for (wcontour.global.PointD pointList : holeLine.PointList) {
- aPoint = new PointZ();
- aPoint.Y = pointList.X;
- aPoint.Z = pointList.Y;
- aPoint.X = offset;
- pList.add(aPoint);
- }
- aPolygonShape.addHole(pList, 0);
- }
- break;
- case "y":
- for (PolyLine holeLine : poly.HoleLines) {
- pList = new ArrayList<>();
- for (wcontour.global.PointD pointList : holeLine.PointList) {
- aPoint = new PointZ();
- aPoint.X = pointList.X;
- aPoint.Z = pointList.Y;
- aPoint.Y = offset;
- pList.add(aPoint);
- }
- aPolygonShape.addHole(pList, 0);
- }
- break;
- case "z":
- for (PolyLine holeLine : poly.HoleLines) {
- pList = new ArrayList<>();
- for (wcontour.global.PointD pointList : holeLine.PointList) {
- aPoint = new PointZ();
- aPoint.X = pointList.X;
- aPoint.Y = pointList.Y;
- aPoint.Z = offset;
- pList.add(aPoint);
- }
- aPolygonShape.addHole(pList, 0);
- }
- break;
- }
- }
- int valueIdx = Arrays.binarySearch(cValues, v);
- if (valueIdx < 0) {
- valueIdx = -valueIdx;
- }
- //int valueIdx = findIndex(cValues, v);
- if (valueIdx == cValues.length - 1) {
- aPolygonShape.highValue = maxData;
- } else {
- aPolygonShape.highValue = cValues[valueIdx + 1];
- }
- if (!poly.IsHighCenter && poly.HighValue == poly.LowValue) {
- aPolygonShape.highValue = v;
- if (valueIdx == 0) {
- aPolygonShape.lowValue = minData;
- } else {
- aPolygonShape.lowValue = cValues[valueIdx - 1];
- }
- }
-
- v = aPolygonShape.lowValue;
- cbb = ls.findLegendBreak(v);
- graphics.add(new Graphic(aPolygonShape, cbb));
- }
- graphics.setSingleLegend(false);
- graphics.setLegendScheme(ls);
-
- return graphics;
- }
-
- /**
- * Create pseudocolor polygons
- *
- * @param x_s scatter X array - 2D
- * @param y_s scatter Y array - 2D
- * @param a scatter value array - 2D
- * @param ls Legend scheme
- * @return Mesh polygon layer
- */
- public static GraphicCollection createPColorPolygons(Array x_s, Array y_s, Array a, LegendScheme ls) {
- GraphicCollection gc = new GraphicCollection();
-
- int[] shape = x_s.getShape();
- int colNum = shape[1];
- int rowNum = shape[0];
- double x1, x2, x3, x4, v;
- PolygonBreak pb;
- if (!x_s.getIndexPrivate().isFastIterator())
- x_s = x_s.copy();
- if (!y_s.getIndexPrivate().isFastIterator())
- y_s = y_s.copy();
- if (!a.getIndexPrivate().isFastIterator())
- a = a.copy();
- for (int i = 0; i < rowNum - 1; i++) {
- for (int j = 0; j < colNum - 1; j++) {
- x1 = x_s.getDouble(i * colNum + j);
- x2 = x_s.getDouble(i * colNum + j + 1);
- x3 = x_s.getDouble((i + 1) * colNum + j);
- x4 = x_s.getDouble((i + 1) * colNum + j + 1);
- PolygonShape ps = new PolygonShape();
- List points = new ArrayList<>();
- points.add(new PointD(x1, y_s.getDouble(i * colNum + j)));
- points.add(new PointD(x3, y_s.getDouble((i + 1) * colNum + j)));
- points.add(new PointD(x4, y_s.getDouble((i + 1) * colNum + j + 1)));
- points.add(new PointD(x2, y_s.getDouble(i * colNum + j + 1)));
- points.add((PointD) points.get(0).clone());
- ps.setPoints(points);
- v = a.getDouble(i * colNum + j);
- pb = (PolygonBreak) ls.findLegendBreak(v);
- Graphic graphic = new Graphic(ps, pb);
- gc.add(graphic);
- }
- }
-
- gc.setSingleLegend(false);
- gc.setLegendScheme(ls);
-
- return gc;
- }
-
- /**
- * Create grid polygons
- *
- * @param x_s X array - 1D
- * @param y_s Y array - 1D
- * @param a scatter value array - 2D
- * @param ls Legend scheme
- * @return Grid polygons
- */
- public static GraphicCollection createGridPolygons(Array x_s, Array y_s, Array a, LegendScheme ls) {
- GraphicCollection gc = new GraphicCollection();
-
- if (!x_s.getIndexPrivate().isFastIterator())
- x_s = x_s.copy();
- if (!y_s.getIndexPrivate().isFastIterator())
- y_s = y_s.copy();
- if (!a.getIndexPrivate().isFastIterator())
- a = a.copy();
-
- int colNum = (int) x_s.getSize();
- int rowNum = (int) y_s.getSize();
- double x, x1 = 0, x2, y, y1 = 0, y2, xd, yd, v;
- PolygonBreak pb;
- for (int i = 0; i < rowNum; i++) {
- if (i == 0) {
- y1 = y_s.getDouble(i);
- }
- y = y_s.getDouble(i);
- if (i < rowNum - 1) {
- y2 = y_s.getDouble(i + 1);
- yd = y2 - y;
- } else {
- y2 = y_s.getDouble(i - 1);
- yd = y - y2;
- }
- if (i == 0) {
- y1 = y1 - yd * 0.5;
- }
- y2 = y + yd * 0.5;
- for (int j = 0; j < colNum; j++) {
- if (j == 0) {
- x1 = x_s.getDouble(j);
- }
- x = x_s.getDouble(j);
- if (j < colNum - 1) {
- x2 = x_s.getDouble(j + 1);
- xd = x2 - x;
- } else {
- x2 = x_s.getDouble(j - 1);
- xd = x - x2;
- }
- if (j == 0) {
- x1 = x1 - xd * 0.5;
- }
- x2 = x + xd * 0.5;
- PolygonShape ps = new PolygonShape();
- List points = new ArrayList<>();
- points.add(new PointD(x1, y1));
- points.add(new PointD(x1, y2));
- points.add(new PointD(x2, y2));
- points.add(new PointD(x2, y1));
- points.add((PointD) points.get(0).clone());
- ps.setPoints(points);
- v = a.getDouble(i * colNum + j);
- pb = (PolygonBreak) ls.findLegendBreak(v);
- Graphic graphic = new Graphic(ps, pb);
- gc.add(graphic);
- x1 = x2;
- }
- y1 = y2;
- }
-
- gc.setSingleLegend(false);
- gc.setLegendScheme(ls);
-
- return gc;
- }
-
- /**
- * Create fill between polygons
- *
- * @param xdata X data array
- * @param y1data Y1 data array
- * @param y2data Y2 data array
- * @param where Where data array
- * @param pb Polygon break
- * @return GraphicCollection
- */
- public static GraphicCollection createFillBetweenPolygons(Array xdata, Array y1data,
- Array y2data, Array where, PolygonBreak pb) {
- GraphicCollection gc = new GraphicCollection();
- int len = (int) xdata.getSize();
- if (!xdata.getIndexPrivate().isFastIterator())
- xdata = xdata.copy();
- if (!y1data.getIndexPrivate().isFastIterator())
- y1data = y1data.copy();
- if (!y2data.getIndexPrivate().isFastIterator())
- y2data = y2data.copy();
- if (where == null) {
- if (ArrayMath.containsNaN(y1data) || ArrayMath.containsNaN(y2data)) {
- where = Array.factory(DataType.BOOLEAN, new int[]{len});
- double v1, v2;
- for (int i = 0; i < len; i++) {
- v1 = y1data.getDouble(i);
- v2 = y2data.getDouble(i);
- if (Double.isNaN(v1) || Double.isNaN(v2)) {
- where.setBoolean(i, false);
- } else {
- where.setBoolean(i, true);
- }
- }
- }
- }
- if (where == null) {
- PolygonShape pgs = new PolygonShape();
- List points = new ArrayList<>();
- for (int i = 0; i < len; i++) {
- points.add(new PointD(xdata.getDouble(i), y1data.getDouble(i)));
- }
- for (int i = len - 1; i >= 0; i--) {
- points.add(new PointD(xdata.getDouble(i), y2data.getDouble(i)));
- }
- pgs.setPoints(points);
- Graphic graphic = new Graphic(pgs, pb);
- gc.add(graphic);
- } else {
- if (!where.getIndexPrivate().isFastIterator())
- where = where.copy();
- boolean ob = false;
- List> idxs = new ArrayList<>();
- List idx = new ArrayList<>();
- for (int j = 0; j < len; j++) {
- if (where.getInt(j) == 1) {
- idx.add(j);
- } else if (ob) {
- idxs.add(idx);
- idx = new ArrayList<>();
- }
- ob = where.getInt(j) == 1;
- }
- if (!idx.isEmpty()) {
- idxs.add(idx);
- }
- for (List index : idxs) {
- int nn = index.size();
- if (nn >= 2) {
- PolygonShape pgs = new PolygonShape();
- List points = new ArrayList<>();
- int ii;
- for (int j = 0; j < nn; j++) {
- ii = index.get(j);
- points.add(new PointD(xdata.getDouble(ii), y1data.getDouble(ii)));
- }
- for (int j = 0; j < nn; j++) {
- ii = index.get(nn - j - 1);
- points.add(new PointD(xdata.getDouble(ii), y2data.getDouble(ii)));
- }
- pgs.setPoints(points);
- Graphic graphic = new Graphic(pgs, pb);
- gc.add(graphic);
- }
- }
- }
-
- return gc;
- }
-
- /**
- * Create fill between polygons - X direction
- *
- * @param ydata Y data array
- * @param x1data X1 data array
- * @param x2data X2 data array
- * @param where Where data array
- * @param pb Polygon break
- * @return GraphicCollection
- */
- public static GraphicCollection createFillBetweenPolygonsX(Array ydata, Array x1data,
- Array x2data, Array where, PolygonBreak pb) {
- GraphicCollection gc = new GraphicCollection();
- int len = (int) ydata.getSize();
- if (!ydata.getIndexPrivate().isFastIterator())
- ydata = ydata.copy();
- if (!x1data.getIndexPrivate().isFastIterator())
- x1data = x1data.copy();
- if (!x2data.getIndexPrivate().isFastIterator())
- x2data = x2data.copy();
- if (where == null) {
- if (ArrayMath.containsNaN(x1data) || ArrayMath.containsNaN(x2data)) {
- where = Array.factory(DataType.BOOLEAN, new int[]{len});
- double v1, v2;
- for (int i = 0; i < len; i++) {
- v1 = x1data.getDouble(i);
- v2 = x2data.getDouble(i);
- if (Double.isNaN(v1) || Double.isNaN(v2)) {
- where.setBoolean(i, false);
- } else {
- where.setBoolean(i, true);
- }
- }
- }
- }
- if (where == null) {
- PolygonShape pgs = new PolygonShape();
- List points = new ArrayList<>();
- for (int i = 0; i < len; i++) {
- points.add(new PointD(x1data.getDouble(i), ydata.getDouble(i)));
- }
- for (int i = len - 1; i >= 0; i--) {
- points.add(new PointD(x2data.getDouble(i), ydata.getDouble(i)));
- }
- pgs.setPoints(points);
- Graphic graphic = new Graphic(pgs, pb);
- gc.add(graphic);
- } else {
- if (!where.getIndexPrivate().isFastIterator())
- where = where.copy();
- boolean ob = false;
- List> idxs = new ArrayList<>();
- List idx = new ArrayList<>();
- for (int j = 0; j < len; j++) {
- if (where.getInt(j) == 1) {
- idx.add(j);
- } else if (ob) {
- idxs.add(idx);
- idx = new ArrayList<>();
- }
- ob = where.getInt(j) == 1;
- }
- if (!idx.isEmpty()) {
- idxs.add(idx);
- }
- for (List index : idxs) {
- int nn = index.size();
- if (nn >= 2) {
- PolygonShape pgs = new PolygonShape();
- List points = new ArrayList<>();
- int ii;
- for (int j = 0; j < nn; j++) {
- ii = index.get(j);
- points.add(new PointD(x1data.getDouble(ii), ydata.getDouble(ii)));
- }
- for (int j = 0; j < nn; j++) {
- ii = index.get(nn - j - 1);
- points.add(new PointD(x2data.getDouble(ii), ydata.getDouble(ii)));
- }
- pgs.setPoints(points);
- Graphic graphic = new Graphic(pgs, pb);
- gc.add(graphic);
- }
- }
- }
-
- return gc;
- }
-
- /**
- * Create fill between polygons
- *
- * @param xdata X data array
- * @param y1data Y1 data array
- * @param y2data Y2 data array
- * @param where Where data array
- * @param pb Polygon break
- * @param offset Offset
- * @param zdir Zdir
- * @return GraphicCollection
- */
- public static GraphicCollection createFillBetweenPolygons(Array xdata, Array y1data,
- Array y2data, Array where, PolygonBreak pb, double offset, String zdir) {
- GraphicCollection3D gc = new GraphicCollection3D();
- gc.setFixZ(true);
- gc.setZValue(offset);
- gc.setZDir(zdir);
- int len = (int) xdata.getSize();
- if (!xdata.getIndexPrivate().isFastIterator())
- xdata = xdata.copy();
- if (!y1data.getIndexPrivate().isFastIterator())
- y1data = y1data.copy();
- if (!y2data.getIndexPrivate().isFastIterator())
- y2data = y2data.copy();
- if (where == null) {
- if (ArrayMath.containsNaN(y1data) || ArrayMath.containsNaN(y2data)) {
- where = Array.factory(DataType.BOOLEAN, new int[]{len});
- double v1, v2;
- for (int i = 0; i < len; i++) {
- v1 = y1data.getDouble(i);
- v2 = y2data.getDouble(i);
- if (Double.isNaN(v1) || Double.isNaN(v2)) {
- where.setBoolean(i, false);
- } else {
- where.setBoolean(i, true);
- }
- }
- }
- }
- if (where == null) {
- PolygonZShape pgs = new PolygonZShape();
- List points = new ArrayList<>();
- switch (zdir) {
- case "x":
- for (int i = 0; i < len; i++) {
- points.add(new PointZ(offset, xdata.getDouble(i), y1data.getDouble(i)));
- }
- for (int i = len - 1; i >= 0; i--) {
- points.add(new PointZ(offset, xdata.getDouble(i), y2data.getDouble(i)));
- }
- break;
- case "y":
- for (int i = 0; i < len; i++) {
- points.add(new PointZ(xdata.getDouble(i), offset, y1data.getDouble(i)));
- }
- for (int i = len - 1; i >= 0; i--) {
- points.add(new PointZ(xdata.getDouble(i), offset, y2data.getDouble(i)));
- }
- break;
- case "z":
- for (int i = 0; i < len; i++) {
- points.add(new PointZ(xdata.getDouble(i), y1data.getDouble(i), offset));
- }
- for (int i = len - 1; i >= 0; i--) {
- points.add(new PointZ(xdata.getDouble(i), y2data.getDouble(i), offset));
- }
- break;
- }
- pgs.setPoints(points);
- Graphic graphic = new Graphic(pgs, pb);
- gc.add(graphic);
- } else {
- if (!where.getIndexPrivate().isFastIterator())
- where = where.copy();
- boolean ob = false;
- List> idxs = new ArrayList<>();
- List idx = new ArrayList<>();
- for (int j = 0; j < len; j++) {
- if (where.getInt(j) == 1) {
- idx.add(j);
- } else if (ob) {
- idxs.add(idx);
- idx = new ArrayList<>();
- }
- ob = where.getInt(j) == 1;
- }
- if (!idx.isEmpty()) {
- idxs.add(idx);
- }
- for (List index : idxs) {
- int nn = index.size();
- if (nn >= 2) {
- PolygonZShape pgs = new PolygonZShape();
- List points = new ArrayList<>();
- int ii;
- switch (zdir) {
- case "x":
- for (int j = 0; j < nn; j++) {
- ii = index.get(j);
- points.add(new PointZ(offset, xdata.getDouble(ii), y1data.getDouble(ii)));
- }
- for (int j = 0; j < nn; j++) {
- ii = index.get(nn - j - 1);
- points.add(new PointZ(offset, xdata.getDouble(ii), y2data.getDouble(ii)));
- }
- break;
- case "y":
- for (int j = 0; j < nn; j++) {
- ii = index.get(j);
- points.add(new PointZ(xdata.getDouble(ii), offset, y1data.getDouble(ii)));
- }
- for (int j = 0; j < nn; j++) {
- ii = index.get(nn - j - 1);
- points.add(new PointZ(xdata.getDouble(ii), offset, y2data.getDouble(ii)));
- }
- break;
- case "z":
- for (int j = 0; j < nn; j++) {
- ii = index.get(j);
- points.add(new PointZ(xdata.getDouble(ii), y1data.getDouble(ii), offset));
- }
- for (int j = 0; j < nn; j++) {
- ii = index.get(nn - j - 1);
- points.add(new PointZ(xdata.getDouble(ii), y2data.getDouble(ii), offset));
- }
- break;
- }
- pgs.setPoints(points);
- Graphic graphic = new Graphic(pgs, pb);
- gc.add(graphic);
- }
- }
- }
-
- return gc;
- }
-
- /**
- * Create fill between polygons
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param y1data Y1 data array
- * @param y2data Y2 data array
- * @param where Where data array
- * @param pb Polygon break
- * @param offset Offset
- * @param zdir Zdir
- * @return GraphicCollection
- */
- public static GraphicCollection createFillBetweenPolygons(Array xdata, Array ydata, Array y1data,
- Array y2data, Array where, PolygonBreak pb, double offset, String zdir) {
- GraphicCollection3D gc = new GraphicCollection3D();
- gc.setFixZ(true);
- gc.setZValue(offset);
- gc.setZDir(zdir);
- int len = (int) xdata.getSize();
- if (!xdata.getIndexPrivate().isFastIterator())
- xdata = xdata.copy();
- if (!y1data.getIndexPrivate().isFastIterator())
- y1data = y1data.copy();
- if (!y2data.getIndexPrivate().isFastIterator())
- y2data = y2data.copy();
- if (where == null) {
- PolygonZShape pgs = new PolygonZShape();
- List points = new ArrayList<>();
- switch (zdir) {
- case "x":
- for (int i = 0; i < len; i++) {
- points.add(new PointZ(offset, xdata.getDouble(i), y1data.getDouble(i)));
- }
- for (int i = len - 1; i >= 0; i--) {
- points.add(new PointZ(offset, xdata.getDouble(i), y2data.getDouble(i)));
- }
- break;
- case "y":
- for (int i = 0; i < len; i++) {
- points.add(new PointZ(xdata.getDouble(i), offset, y1data.getDouble(i)));
- }
- for (int i = len - 1; i >= 0; i--) {
- points.add(new PointZ(xdata.getDouble(i), offset, y2data.getDouble(i)));
- }
- break;
- case "xy":
- if (!ydata.getIndexPrivate().isFastIterator())
- ydata = ydata.copy();
- for (int i = 0; i < len; i++) {
- points.add(new PointZ(xdata.getDouble(i), ydata.getDouble(i), y1data.getDouble(i)));
- }
- for (int i = len - 1; i >= 0; i--) {
- points.add(new PointZ(xdata.getDouble(i), ydata.getDouble(i), y2data.getDouble(i)));
- }
- break;
- case "z":
- for (int i = 0; i < len; i++) {
- points.add(new PointZ(xdata.getDouble(i), y1data.getDouble(i), offset));
- }
- for (int i = len - 1; i >= 0; i--) {
- points.add(new PointZ(xdata.getDouble(i), y2data.getDouble(i), offset));
- }
- break;
- }
- pgs.setPoints(points);
- Graphic graphic = new Graphic(pgs, pb);
- gc.add(graphic);
- } else {
- boolean ob = false;
- List> idxs = new ArrayList<>();
- List idx = new ArrayList<>();
- for (int j = 0; j < len; j++) {
- if (where.getInt(j) == 1) {
- if (!ob) {
- idx = new ArrayList<>();
- }
- idx.add(j);
- } else if (ob) {
- idxs.add(idx);
- }
- ob = where.getInt(j) == 1;
- }
- for (List index : idxs) {
- int nn = index.size();
- if (nn >= 2) {
- PolygonZShape pgs = new PolygonZShape();
- List points = new ArrayList<>();
- int ii;
- switch (zdir) {
- case "x":
- for (int j = 0; j < nn; j++) {
- ii = index.get(j);
- points.add(new PointZ(offset, xdata.getDouble(ii), y1data.getDouble(ii)));
- }
- for (int j = 0; j < nn; j++) {
- ii = index.get(nn - j - 1);
- points.add(new PointZ(offset, xdata.getDouble(ii), y2data.getDouble(ii)));
- }
- break;
- case "y":
- for (int j = 0; j < nn; j++) {
- ii = index.get(j);
- points.add(new PointZ(xdata.getDouble(ii), offset, y1data.getDouble(ii)));
- }
- for (int j = 0; j < nn; j++) {
- ii = index.get(nn - j - 1);
- points.add(new PointZ(xdata.getDouble(ii), offset, y2data.getDouble(ii)));
- }
- break;
- case "xy":
- if (!ydata.getIndexPrivate().isFastIterator())
- ydata = ydata.copy();
- for (int j = 0; j < nn; j++) {
- ii = index.get(j);
- points.add(new PointZ(xdata.getDouble(ii), ydata.getDouble(ii), y1data.getDouble(ii)));
- }
- for (int j = 0; j < nn; j++) {
- ii = index.get(nn - j - 1);
- points.add(new PointZ(xdata.getDouble(ii), ydata.getDouble(ii), y2data.getDouble(ii)));
- }
- break;
- case "z":
- for (int j = 0; j < nn; j++) {
- ii = index.get(j);
- points.add(new PointZ(xdata.getDouble(ii), y1data.getDouble(ii), offset));
- }
- for (int j = 0; j < nn; j++) {
- ii = index.get(nn - j - 1);
- points.add(new PointZ(xdata.getDouble(ii), y2data.getDouble(ii), offset));
- }
- break;
- }
- pgs.setPoints(points);
- Graphic graphic = new Graphic(pgs, pb);
- gc.add(graphic);
- }
- }
- }
-
- return gc;
- }
-
- /**
- * Create wind barbs
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param udata U/WindDirection data array
- * @param vdata V/WindSpeed data array
- * @param cdata Colored data array
- * @param ls Legend scheme
- * @param isUV Is U/V or not
- * @return GraphicCollection
- */
- public static GraphicCollection createBarbs(Array xdata, Array ydata, Array udata, Array vdata,
- Array cdata, LegendScheme ls, boolean isUV) {
- GraphicCollection gc = new GraphicCollection();
- Array windDirData;
- Array windSpeedData;
- if (isUV) {
- Array[] wwData = MeteoMath.uv2ds(udata, vdata);
- windDirData = wwData[0];
- windSpeedData = wwData[1];
- } else {
- windDirData = udata;
- windSpeedData = vdata;
- }
-
- ShapeTypes sts = ls.getShapeType();
- ls = ls.convertTo(ShapeTypes.Point);
- if (sts != ShapeTypes.Point) {
- for (int i = 0; i < ls.getBreakNum(); i++) {
- ((PointBreak) ls.getLegendBreaks().get(i)).setSize(10);
- }
- }
-
- int i, j;
- WindBarb aWB;
- double windDir, windSpeed;
- PointD aPoint;
- ColorBreak cb;
- double v;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- IndexIterator wdIter = windDirData.getIndexIterator();
- IndexIterator wsIter = windSpeedData.getIndexIterator();
- IndexIterator cIter = cdata == null ? null : cdata.getIndexIterator();
- while (xIter.hasNext()){
- windDir = wdIter.getDoubleNext();
- windSpeed = wsIter.getDoubleNext();
- if (!Double.isNaN(windDir) && !Double.isNaN(windSpeed)) {
- aPoint = new PointD();
- aPoint.X = xIter.getDoubleNext();
- aPoint.Y = yIter.getDoubleNext();
- aWB = Draw.calWindBarb((float) windDir, (float) windSpeed, 0, 10, aPoint);
- if (cdata == null) {
- cb = ls.getLegendBreaks().get(0);
- } else {
- v = cIter.getDoubleNext();
- aWB.setValue(v);
- cb = ls.findLegendBreak(v);
- }
- Graphic graphic = new Graphic(aWB, cb);
- gc.add(graphic);
- } else {
- xIter.next();
- yIter.next();
- if (cIter != null)
- cIter.next();
- }
- }
-
- gc.setLegendScheme(ls);
- if (cdata != null) {
- gc.setSingleLegend(false);
- }
-
- return gc;
- }
-
- /**
- * Create arrow polygon
- *
- * @param x X coordinate
- * @param y Y coordinate
- * @param dx The length of arrow along x direction
- * @param dy The length of arrow along y direction
- * @param ab The arrow polygon break
- * @return Arrow polygon graphic
- */
- public static Graphic createArrow(double x, double y, double dx, double dy, ArrowPolygonBreak ab) {
- double[] r = MeteoMath.uv2ds(dx, dy);
- double length = r[1];
- if (ab.isLengthIncludesHead()) {
- length = length - ab.getHeadLength();
- }
-
- AffineTransform atf = new AffineTransform();
- atf.translate(x, y);
- atf.rotate(dx, dy);
-
- float width = ab.getWidth();
- float headLength = ab.getHeadLength();
- float overhang = ab.getOverhang();
- float lenShift = headLength * overhang;
- double[] srcPts = new double[8 * 2];
- srcPts[0] = 0;
- srcPts[1] = -width * 0.5;
- srcPts[2] = 0;
- srcPts[3] = width * 0.5;
- srcPts[4] = length + lenShift;
- srcPts[5] = width * 0.5;
- srcPts[6] = length;
- srcPts[7] = ab.getHeadWidth() * 0.5;
- srcPts[8] = length + ab.getHeadLength();
- srcPts[9] = 0;
- srcPts[10] = length;
- srcPts[11] = -ab.getHeadWidth() * 0.5;
- srcPts[12] = length + lenShift;
- srcPts[13] = -width * 0.5;
- srcPts[14] = 0;
- srcPts[15] = -width * 0.5;
- atf.transform(srcPts, 0, srcPts, 0, 8);
- List points = new ArrayList<>();
- for (int i = 0; i < srcPts.length; i += 2) {
- points.add(new PointD(srcPts[i], srcPts[i + 1]));
- }
- PolygonShape pgs = new PolygonShape();
- pgs.setPoints(points);
-
- return new Graphic(pgs, ab);
- }
-
- /**
- * Create arrow line
- *
- * @param x X coordinate
- * @param y Y coordinate
- * @param dx The length of arrow along x direction
- * @param dy The length of arrow along y direction
- * @param ab The arrow line break
- * @return Arrow line graphic
- */
- public static Graphic createArrowLine(double x, double y, double dx, double dy, ArrowLineBreak ab) {
- List points = new ArrayList<>();
- points.add(new PointD(x, y));
- points.add(new PointD(x + dx, y + dy));
- PolylineShape pls = new PolylineShape();
- pls.setPoints(points);
-
- return new Graphic(pls, ab);
- }
-
- /**
- * Create arrow line
- *
- * @param x X coordinates
- * @param y Y coordinates
- * @param ab The arrow line break
- * @param iscurve Is curve or not
- * @return Arrow line graphic
- */
- public static Graphic createArrowLine(Array x, Array y, ArrowLineBreak ab, boolean iscurve) {
- List points = new ArrayList<>();
- IndexIterator xIter = x.getIndexIterator();
- IndexIterator yIter = y.getIndexIterator();
- while (xIter.hasNext()){
- points.add(new PointD(xIter.getDoubleNext(), yIter.getDoubleNext()));
- }
- PolylineShape pls;
- if (iscurve) {
- pls = new CurveLineShape();
- } else {
- pls = new PolylineShape();
- }
- pls.setPoints(points);
-
- return new Graphic(pls, ab);
- }
-
- /**
- * Create wind arrows
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param udata U/WindDirection data array
- * @param vdata V/WindSpeed data array
- * @param cdata Colored data array
- * @param ls Legend scheme
- * @param isUV Is U/V or not
- * @return GraphicCollection
- */
- public static GraphicCollection createArrows(Array xdata, Array ydata, Array udata, Array vdata,
- Array cdata, LegendScheme ls, boolean isUV) {
- GraphicCollection gc = new GraphicCollection();
- Array windDirData;
- Array windSpeedData;
- if (isUV) {
- Array[] wwData = MeteoMath.uv2ds(udata, vdata);
- windDirData = wwData[0];
- windSpeedData = wwData[1];
- } else {
- windDirData = udata;
- windSpeedData = vdata;
- }
-
- ShapeTypes sts = ls.getShapeType();
- ls = ls.convertTo(ShapeTypes.Point);
- if (sts != ShapeTypes.Point) {
- for (int i = 0; i < ls.getBreakNum(); i++) {
- ((PointBreak) ls.getLegendBreaks().get(i)).setSize(10);
- }
- }
-
- int i;
- WindArrow wa;
- double windDir, windSpeed;
- PointD aPoint;
- ColorBreak cb;
- double x, y, v = 0;
- float size = 6;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- IndexIterator wdIter = windDirData.getIndexIterator();
- IndexIterator wsIter = windSpeedData.getIndexIterator();
- IndexIterator cIter = cdata == null ? null : cdata.getIndexIterator();
- while (xIter.hasNext()){
- windDir = wdIter.getDoubleNext();
- windSpeed = wsIter.getDoubleNext();
- x = xIter.getDoubleNext();
- y = yIter.getDoubleNext();
- if (cdata != null)
- v = cIter.getDoubleNext();
- if (!Double.isNaN(windDir) && !Double.isNaN(windSpeed)) {
- aPoint = new PointD();
- aPoint.X = x;
- aPoint.Y = y;
- wa = new WindArrow();
- wa.angle = windDir;
- wa.length = (float) windSpeed;
- wa.size = size;
- wa.setPoint(aPoint);
- if (cdata == null) {
- cb = ls.getLegendBreaks().get(0);
- } else {
- wa.setValue(v);
- cb = ls.findLegendBreak(v);
- }
- Graphic graphic = new Graphic(wa, cb);
- gc.add(graphic);
- }
- }
-
- gc.setLegendScheme(ls);
- if (cdata != null) {
- gc.setSingleLegend(false);
- }
-
- return gc;
- }
-
- /**
- * Create wind arrows
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param zdata Z data array
- * @param udata U data array
- * @param vdata V data array
- * @param wdata W data array
- * @param scale The length scale of each wind arrow
- * @param headWidth The head width of the arrow
- * @param headLength The head length of the arrow
- * @param cdata Colored data array
- * @param ls Legend scheme
- * @return GraphicCollection
- */
- public static GraphicCollection createArrows3D(Array xdata, Array ydata, Array zdata, Array udata,
- Array vdata, Array wdata, float scale, float headWidth, float headLength, Array cdata, LegendScheme ls) {
- GraphicCollection gc = new GraphicCollection();
- ShapeTypes sts = ls.getShapeType();
- ls = ls.convertTo(ShapeTypes.Point);
- if (sts != ShapeTypes.Point) {
- for (int i = 0; i < ls.getBreakNum(); i++) {
- ((PointBreak) ls.getLegendBreaks().get(i)).setSize(10);
- }
- }
-
- int i;
- WindArrow3D wa;
- double u, v, w;
- PointZ aPoint;
- ColorBreak cb;
- double value;
- IndexIterator xIter = xdata.getIndexIterator();
- IndexIterator yIter = ydata.getIndexIterator();
- IndexIterator zIter = zdata.getIndexIterator();
- IndexIterator uIter = udata.getIndexIterator();
- IndexIterator vIter = vdata.getIndexIterator();
- IndexIterator wIter = wdata.getIndexIterator();
- IndexIterator cIter = cdata == null ? null : cdata.getIndexIterator();
- while (xIter.hasNext()){
- u = uIter.getDoubleNext();
- v = vIter.getDoubleNext();
- w = wIter.getDoubleNext();
- if (!Double.isNaN(u) && !Double.isNaN(v) && !Double.isNaN(w)) {
- aPoint = new PointZ();
- aPoint.X = xIter.getDoubleNext();
- aPoint.Y = yIter.getDoubleNext();
- aPoint.Z = zIter.getDoubleNext();
- wa = new WindArrow3D();
- wa.u = u;
- wa.v = v;
- wa.w = w;
- wa.scale = scale;
- wa.setHeadWith(headWidth);
- wa.setHeadLength(headLength);
- wa.setPoint(aPoint);
- if (cdata == null) {
- cb = ls.getLegendBreaks().get(0);
- } else {
- value = cIter.getDoubleNext();
- wa.setValue(value);
- cb = ls.findLegendBreak(value);
- }
- Graphic graphic = new Graphic(wa, cb);
- gc.add(graphic);
- } else {
- xIter.next();
- yIter.next();
- zIter.next();
- if (cdata != null)
- cIter.next();
- }
- }
-
- gc.setLegendScheme(ls);
- if (cdata != null) {
- gc.setSingleLegend(false);
- }
-
- return gc;
- }
-
- /**
- * Create 3D streamlines
- * @param xdata X coordinate array
- * @param ydata Y coordinate array
- * @param zdata Z coordinate array
- * @param udata U wind component array
- * @param vdata V wind component array
- * @param wdata W wind component array
- * @param cdata Value array
- * @param density Streamline density
- * @param ls The legend scheme
- * @return
- */
- public static GraphicCollection3D createStreamlines3D(Array xdata, Array ydata, Array zdata,
- Array udata, Array vdata, Array wdata,
- Array cdata, int density, LegendScheme ls,
- int minPoints) {
- GraphicCollection3D graphics = new GraphicCollection3D();
- double[][][] u = (double[][][]) ArrayUtil.copyToNDJavaArray_Double(udata);
- double[][][] v = (double[][][]) ArrayUtil.copyToNDJavaArray_Double(vdata);
- double[][][] w = (double[][][]) ArrayUtil.copyToNDJavaArray_Double(wdata);
- if (xdata.getRank() == 1) {
- double[] x = (double[]) ArrayUtil.copyToNDJavaArray_Double(xdata);
- double[] y = (double[]) ArrayUtil.copyToNDJavaArray_Double(ydata);
- double[] z = (double[]) ArrayUtil.copyToNDJavaArray_Double(zdata);
-
- if (cdata == null) {
- List streamLines = Contour.tracingStreamline3D(u, v, w, null, x, y, z, density);
- ColorBreak cb = ls.getLegendBreak(0);
- for (PolyLine3D line : streamLines) {
- if (line.PointList.size() < minPoints)
- continue;
-
- PolylineZShape shape = new PolylineZShape();
- List points = new ArrayList<>();
- for (Point3D point : line.PointList) {
- points.add(new PointZ(point.X, point.Y, point.Z));
- }
- shape.setPoints(points);
- graphics.add(new Graphic(shape, cb));
- }
- } else {
- double[][][] m = (double[][][]) ArrayUtil.copyToNDJavaArray_Double(cdata);
- List streamLines = Contour.tracingStreamline3D(u, v, w, m, x, y, z, density);
- ColorBreak cb;
- double mm;
- for (PolyLine3D line : streamLines) {
- if (line.PointList.size() < minPoints)
- continue;
-
- PolylineZShape shape = new PolylineZShape();
- List points = new ArrayList<>();
- ColorBreakCollection cbs = new ColorBreakCollection();
- for (Point3D point : line.PointList) {
- points.add(new PointZ(point.X, point.Y, point.Z));
- cb = ls.findLegendBreak(point.M);
- cbs.add(cb);
- }
- shape.setPoints(points);
- graphics.add(new Graphic(shape, cbs));
- }
- }
- } else {
- double[][][] x = (double[][][]) ArrayUtil.copyToNDJavaArray_Double(xdata);
- double[][][] y = (double[][][]) ArrayUtil.copyToNDJavaArray_Double(ydata);
- double[][][] z = (double[][][]) ArrayUtil.copyToNDJavaArray_Double(zdata);
-
- if (cdata == null) {
- List streamLines = Contour.tracingStreamline3D(u, v, w, null, x, y, z, density);
- ColorBreak cb = ls.getLegendBreak(0);
- for (PolyLine3D line : streamLines) {
- if (line.PointList.size() < minPoints)
- continue;
-
- PolylineZShape shape = new PolylineZShape();
- List points = new ArrayList<>();
- for (Point3D point : line.PointList) {
- points.add(new PointZ(point.X, point.Y, point.Z));
- }
- shape.setPoints(points);
- graphics.add(new Graphic(shape, cb));
- }
- } else {
- double[][][] m = (double[][][]) ArrayUtil.copyToNDJavaArray_Double(cdata);
- List streamLines = Contour.tracingStreamline3D(u, v, w, m, x, y, z, density);
- ColorBreak cb;
- double mm;
- for (PolyLine3D line : streamLines) {
- if (line.PointList.size() < minPoints)
- continue;
-
- PolylineZShape shape = new PolylineZShape();
- List points = new ArrayList<>();
- ColorBreakCollection cbs = new ColorBreakCollection();
- for (Point3D point : line.PointList) {
- points.add(new PointZ(point.X, point.Y, point.Z));
- cb = ls.findLegendBreak(point.M);
- cbs.add(cb);
- }
- shape.setPoints(points);
- graphics.add(new Graphic(shape, cbs));
- }
- }
- }
- graphics.setLegendScheme(ls);
-
- return graphics;
- }
-
- /**
- * Create 3D streamlines
- * @param xdata X coordinate array
- * @param ydata Y coordinate array
- * @param zdata Z coordinate array
- * @param udata U wind component array
- * @param vdata V wind component array
- * @param wdata W wind component array
- * @param cdata Value array
- * @param density Streamline density
- * @param ls The legend scheme
- * @return
- */
- public static GraphicCollection3D createStreamlines3D(Array xdata, Array ydata, Array zdata,
- Array udata, Array vdata, Array wdata,
- Array cdata, int density, LegendScheme ls,
- int minPoints, Array startX, Array startY,
- Array startZ) {
- GraphicCollection3D graphics = new GraphicCollection3D();
- double[][][] u = (double[][][]) ArrayUtil.copyToNDJavaArray_Double(udata);
- double[][][] v = (double[][][]) ArrayUtil.copyToNDJavaArray_Double(vdata);
- double[][][] w = (double[][][]) ArrayUtil.copyToNDJavaArray_Double(wdata);
- double[] sX = (double[]) ArrayUtil.copyToNDJavaArray_Double(startX);
- double[] sY = (double[]) ArrayUtil.copyToNDJavaArray_Double(startY);
- double[] sZ = (double[]) ArrayUtil.copyToNDJavaArray_Double(startZ);
- if (xdata.getRank() == 1) {
- double[] x = (double[]) ArrayUtil.copyToNDJavaArray_Double(xdata);
- double[] y = (double[]) ArrayUtil.copyToNDJavaArray_Double(ydata);
- double[] z = (double[]) ArrayUtil.copyToNDJavaArray_Double(zdata);
-
- if (cdata == null) {
- List streamLines = Contour.tracingStreamline3D(u, v, w, null, x, y, z, density,
- sX, sY, sZ);
- ColorBreak cb = ls.getLegendBreak(0);
- for (PolyLine3D line : streamLines) {
- if (line.PointList.size() < minPoints)
- continue;
-
- PolylineZShape shape = new PolylineZShape();
- List points = new ArrayList<>();
- for (Point3D point : line.PointList) {
- points.add(new PointZ(point.X, point.Y, point.Z));
- }
- shape.setPoints(points);
- graphics.add(new Graphic(shape, cb));
- }
- } else {
- double[][][] m = (double[][][]) ArrayUtil.copyToNDJavaArray_Double(cdata);
- List streamLines = Contour.tracingStreamline3D(u, v, w, m, x, y, z, density,
- sX, sY, sZ);
- ColorBreak cb;
- double mm;
- for (PolyLine3D line : streamLines) {
- if (line.PointList.size() < minPoints)
- continue;
-
- PolylineZShape shape = new PolylineZShape();
- List points = new ArrayList<>();
- ColorBreakCollection cbs = new ColorBreakCollection();
- for (Point3D point : line.PointList) {
- points.add(new PointZ(point.X, point.Y, point.Z));
- cb = ls.findLegendBreak(point.M);
- cbs.add(cb);
- }
- shape.setPoints(points);
- graphics.add(new Graphic(shape, cbs));
- }
- }
- } else {
- double[][][] x = (double[][][]) ArrayUtil.copyToNDJavaArray_Double(xdata);
- double[][][] y = (double[][][]) ArrayUtil.copyToNDJavaArray_Double(ydata);
- double[][][] z = (double[][][]) ArrayUtil.copyToNDJavaArray_Double(zdata);
-
- if (cdata == null) {
- List streamLines = Contour.tracingStreamline3D(u, v, w, null, x, y, z, density,
- sX, sY, sZ);
- ColorBreak cb = ls.getLegendBreak(0);
- for (PolyLine3D line : streamLines) {
- if (line.PointList.size() < minPoints)
- continue;
-
- PolylineZShape shape = new PolylineZShape();
- List points = new ArrayList<>();
- for (Point3D point : line.PointList) {
- points.add(new PointZ(point.X, point.Y, point.Z));
- }
- shape.setPoints(points);
- graphics.add(new Graphic(shape, cb));
- }
- } else {
- double[][][] m = (double[][][]) ArrayUtil.copyToNDJavaArray_Double(cdata);
- List streamLines = Contour.tracingStreamline3D(u, v, w, m, x, y, z, density,
- sX, sY, sZ);
- ColorBreak cb;
- double mm;
- for (PolyLine3D line : streamLines) {
- if (line.PointList.size() < minPoints)
- continue;
-
- PolylineZShape shape = new PolylineZShape();
- List points = new ArrayList<>();
- ColorBreakCollection cbs = new ColorBreakCollection();
- for (Point3D point : line.PointList) {
- points.add(new PointZ(point.X, point.Y, point.Z));
- cb = ls.findLegendBreak(point.M);
- cbs.add(cb);
- }
- shape.setPoints(points);
- graphics.add(new Graphic(shape, cbs));
- }
- }
- }
- graphics.setLegendScheme(ls);
-
- return graphics;
- }
-
- /**
- * Create stream line
- *
- * @param xdata X data array
- * @param ydata Y data array
- * @param udata U/WindDirection data array
- * @param vdata V/WindSpeed data array
- * @param density Streamline density
- * @param slb Streamline break
- * @param isUV Is U/V or not
- * @return GraphicCollection
- */
- public static GraphicCollection createStreamlines(Array xdata, Array ydata, Array udata, Array vdata,
- int density, StreamlineBreak slb, boolean isUV) {
- GraphicCollection gc = new GraphicCollection();
- if (!isUV) {
- Array[] uvData = MeteoMath.ds2uv(udata, vdata);
- udata = uvData[0];
- vdata = uvData[1];
- }
-
- double[][] u = (double[][])ArrayUtil.copyToNDJavaArray_Double(udata);
- double[][] v = (double[][])ArrayUtil.copyToNDJavaArray_Double(vdata);
- double[] x = (double[]) ArrayUtil.copyToNDJavaArray_Double(xdata);
- double[] y = (double[]) ArrayUtil.copyToNDJavaArray_Double(ydata);
- List streamlines = wcontour.Contour.tracingStreamline(u, v,
- x, y, density);
- wcontour.global.PolyLine line;
- for (int i = 0; i < streamlines.size() - 1; i++) {
- line = streamlines.get(i);
- PolylineShape aPolyline = new PolylineShape();
- PointD aPoint;
- List pList = new ArrayList<>();
- for (int j = 0; j < line.PointList.size(); j++) {
- aPoint = new PointD();
- aPoint.X = (line.PointList.get(j)).X;
- aPoint.Y = (line.PointList.get(j)).Y;
- pList.add(aPoint);
- }
- aPolyline.setPoints(pList);
- aPolyline.setValue(density);
- gc.add(new Graphic(aPolyline, slb));
- }
-
- return gc;
- }
-
- /**
- * Trace streamlines
- * @param xa X coordinate array
- * @param ya Y coordinate array
- * @param z Z value
- * @param ua U component
- * @param va V component
- * @param data Data array
- * @param density Streamline density
- * @param zDir Z direction: "x", "y" or "z"
- * @param ls Legend scheme
- * @return Streamlines
- */
- public static GraphicCollection3D streamLines(Array xa, Array ya, double z, Array ua,
- Array va, Array data, int density,
- String zDir, LegendScheme ls) {
- GraphicCollection3D graphics = new GraphicCollection3D();
- double[][] u = (double[][]) ArrayUtil.copyToNDJavaArray_Double(ua);
- double[][] v = (double[][]) ArrayUtil.copyToNDJavaArray_Double(va);
- List streamlines;
- if (xa.getRank() == 1) {
- double[] x = (double[]) ArrayUtil.copyToNDJavaArray_Double(xa);
- double[] y = (double[]) ArrayUtil.copyToNDJavaArray_Double(ya);
- streamlines = wcontour.Contour.tracingStreamline(u, v,
- x, y, density);
- } else {
- xa = xa.copyIfView();
- ya = ya.copyIfView();
- double[][] x = (double[][]) ArrayUtil.copyToNDJavaArray_Double(xa);
- double[][] y = (double[][]) ArrayUtil.copyToNDJavaArray_Double(ya);
- streamlines = wcontour.Contour.tracingStreamline(u, v,
- x, y, density);
- }
-
- int ny = u.length;
- int nx = u[0].length;
- ColorBreak cb = ls.getLegendBreak(0);
- if (data == null) {
- for (wcontour.global.PolyLine line : streamlines) {
- PolylineZShape shape = new PolylineZShape();
- List points = new ArrayList<>();
- PointZ p;
- if (zDir.equals("x")) {
- for (int j = 0; j < line.PointList.size(); j++) {
- p = new PointZ();
- p.Y = (line.PointList.get(j)).X;
- p.Z = (line.PointList.get(j)).Y;
- p.X = z;
- points.add(p);
- }
- } else if (zDir.equals("y")) {
- for (int j = 0; j < line.PointList.size(); j++) {
- p = new PointZ();
- p.X = (line.PointList.get(j)).X;
- p.Z = (line.PointList.get(j)).Y;
- p.Y = z;
- points.add(p);
- }
- } else {
- for (int j = 0; j < line.PointList.size(); j++) {
- p = new PointZ();
- p.X = (line.PointList.get(j)).X;
- p.Y = (line.PointList.get(j)).Y;
- p.Z = z;
- points.add(p);
- }
- }
- shape.setPoints(points);
- graphics.add(new Graphic(shape, cb));
- }
- } else {
- for (wcontour.global.PolyLine line : streamlines) {
- PolylineZShape shape = new PolylineZShape();
- List points = new ArrayList<>();
- PointZ p;
- ColorBreakCollection cbs = new ColorBreakCollection();
- if (zDir.equals("x")) {
- for (int j = 0; j < line.PointList.size(); j++) {
- p = new PointZ();
- p.Y = (line.PointList.get(j)).X;
- p.Z = (line.PointList.get(j)).Y;
- p.X = z;
- int[] idx = ArrayUtil.gridIndex(xa, ya, p.Y, p.Z);
- if (idx != null) {
- int yi = idx[0];
- int xi = idx[1];
- p.M = data.getDouble(yi * nx + xi);
- }
- cb = ls.findLegendBreak(p.M);
- cbs.add(cb);
- points.add(p);
- }
- } else if (zDir.equals("y")) {
- for (int j = 0; j < line.PointList.size(); j++) {
- p = new PointZ();
- p.X = (line.PointList.get(j)).X;
- p.Z = (line.PointList.get(j)).Y;
- p.Y = z;
- int[] idx = ArrayUtil.gridIndex(xa, ya, p.X, p.Z);
- if (idx != null) {
- int yi = idx[0];
- int xi = idx[1];
- p.M = data.getDouble(yi * nx + xi);
- }
- cb = ls.findLegendBreak(p.M);
- cbs.add(cb);
- points.add(p);
- }
- } else {
- for (int j = 0; j < line.PointList.size(); j++) {
- p = new PointZ();
- p.X = (line.PointList.get(j)).X;
- p.Y = (line.PointList.get(j)).Y;
- p.Z = z;
- int[] idx = ArrayUtil.gridIndex(xa, ya, p.X, p.Y);
- if (idx != null) {
- int yi = idx[0];
- int xi = idx[1];
- p.M = data.getDouble(yi * nx + xi);
- }
- cb = ls.findLegendBreak(p.M);
- cbs.add(cb);
- points.add(p);
- }
- }
- shape.setPoints(points);
- graphics.add(new Graphic(shape, cbs));
- }
- }
- graphics.setLegendScheme(ls);
-
- return graphics;
- }
-
- /**
- * Trace streamlines
- * @param xa X coordinate array
- * @param ya Y coordinate array
- * @param za Z coordinate value
- * @param ua U component
- * @param va V component
- * @param data Data array
- * @param density Streamline density
- * @param ls Legend scheme
- * @return Streamlines
- */
- public static GraphicCollection3D streamLines(Array xa, Array ya, Array za, Array ua,
- Array va, Array data, int density,
- LegendScheme ls) {
- GraphicCollection3D graphics = new GraphicCollection3D();
- double[][] u = (double[][]) ArrayUtil.copyToNDJavaArray_Double(ua);
- double[][] v = (double[][]) ArrayUtil.copyToNDJavaArray_Double(va);
- List streamlines;
- if (xa.getRank() == 1) {
- double[] x = (double[]) ArrayUtil.copyToNDJavaArray_Double(xa);
- double[] y = (double[]) ArrayUtil.copyToNDJavaArray_Double(ya);
- streamlines = wcontour.Contour.tracingStreamline(u, v,
- x, y, density);
- } else {
- xa = xa.copyIfView();
- ya = ya.copyIfView();
- double[][] x = (double[][]) ArrayUtil.copyToNDJavaArray_Double(xa);
- double[][] y = (double[][]) ArrayUtil.copyToNDJavaArray_Double(ya);
- streamlines = wcontour.Contour.tracingStreamline(u, v,
- x, y, density);
- }
-
- int ny = u.length;
- int nx = u[0].length;
- ColorBreak cb = ls.getLegendBreak(0);
- if (data == null) {
- for (wcontour.global.PolyLine line : streamlines) {
- PolylineZShape shape = new PolylineZShape();
- List points = new ArrayList<>();
- PointZ p;
- for (int j = 0; j < line.PointList.size(); j++) {
- p = new PointZ();
- p.X = (line.PointList.get(j)).X;
- p.Y = (line.PointList.get(j)).Y;
- int[] idx = ArrayUtil.gridIndex(xa, ya, p.Y, p.Z);
- if (idx != null) {
- int yi = idx[0];
- int xi = idx[1];
- p.Z = za.getDouble(yi * nx + xi);
- }
- points.add(p);
- }
- shape.setPoints(points);
- graphics.add(new Graphic(shape, cb));
- }
- } else {
- for (wcontour.global.PolyLine line : streamlines) {
- PolylineZShape shape = new PolylineZShape();
- List points = new ArrayList<>();
- PointZ p;
- ColorBreakCollection cbs = new ColorBreakCollection();
- for (int j = 0; j < line.PointList.size(); j++) {
- p = new PointZ();
- p.X = (line.PointList.get(j)).X;
- p.Y = (line.PointList.get(j)).Y;
- int[] idx = ArrayUtil.gridIndex(xa, ya, p.X, p.Y);
- if (idx != null) {
- int yi = idx[0];
- int xi = idx[1];
- p.Z = za.getDouble(yi * nx + xi);
- p.M = data.getDouble(yi * nx + xi);
- }
- cb = ls.findLegendBreak(p.M);
- cbs.add(cb);
- points.add(p);
- }
- shape.setPoints(points);
- graphics.add(new Graphic(shape, cbs));
- }
- }
- graphics.setLegendScheme(ls);
-
- return graphics;
- }
-
- /**
- * Create streamline slices in 3D axes
- * @param xa X coordinate array
- * @param ya Y coordinate array
- * @param za Z coordinate array
- * @param ua U component array
- * @param va V component array
- * @param wa W component array
- * @param data Data array
- * @param xSlice X slices
- * @param ySlice Y slices
- * @param zSlice Z slices
- * @param density Streamline density
- * @param ls Legend scheme
- * @return Streamline slices graphics
- * @throws InvalidRangeException
- */
- public static List streamSlice(Array xa, Array ya, Array za, Array ua,
- Array va, Array wa, Array data, List xSlice,
- List ySlice, List zSlice,
- int density, LegendScheme ls) throws InvalidRangeException {
- List sgs = new ArrayList<>();
- double x, y, z;
-
- //X slice
- for (int i = 0; i < xSlice.size(); i++) {
- x = xSlice.get(i).doubleValue();
- Array aa = xa;
- if (xa.getRank() == 3) {
- int[] shape = xa.getShape();
- aa = xa.section(new int[]{0,0,0}, new int[]{1,1,shape[2]});
- }
- Array xua = ArrayUtil.slice(va, 2, aa, x);
- Array xva = ArrayUtil.slice(wa, 2, aa, x);
- Array r = data == null ? null : ArrayUtil.slice(data, 2, aa, x);
- Array yya = ya.getRank() == 1 ? ya : ArrayUtil.slice(ya, 2, aa, x);
- Array zza = za.getRank() == 1 ? za : ArrayUtil.slice(za, 2, aa, x);
- GraphicCollection3D graphics = streamLines(yya, zza, x, xua, xva, r, density, "x", ls);
- sgs.add(graphics);
- }
-
- //Y slice
- for (int i = 0; i < ySlice.size(); i++) {
- y = ySlice.get(i).doubleValue();
- Array aa = ya;
- if (ya.getRank() == 3) {
- int[] shape = ya.getShape();
- aa = ya.section(new int[]{0,0,0}, new int[]{1,shape[1],1});
- }
- Array xua = ArrayUtil.slice(ua, 1, aa, y);
- Array xva = ArrayUtil.slice(wa, 1, aa, y);
- Array r = data == null ? null : ArrayUtil.slice(data, 1, aa, y);
- Array xxa = xa.getRank() == 1 ? xa : ArrayUtil.slice(xa, 1, aa, y);
- Array zza = za.getRank() == 1 ? za : ArrayUtil.slice(za, 1, aa, y);
- GraphicCollection3D graphics = streamLines(xxa, zza, y, xua, xva, r, density, "y", ls);
- sgs.add(graphics);
- }
-
- //Z slice
- for (int i = 0; i < zSlice.size(); i++) {
- z = zSlice.get(i).doubleValue();
- Array aa = za;
- if (za.getRank() == 3) {
- int[] shape = za.getShape();
- aa = za.section(new int[]{0,0,0}, new int[]{shape[0],1,1});
- }
- Array xua = ArrayUtil.slice(ua, 0, aa, z);
- Array xva = ArrayUtil.slice(va, 0, aa, z);
- Array r = data == null ? null : ArrayUtil.slice(data, 0, aa, z);
- Array xxa = xa.getRank() == 1 ? xa : ArrayUtil.slice(xa, 0, aa, z);
- Array yya = ya.getRank() == 1 ? ya : ArrayUtil.slice(ya, 0, aa, z);
- GraphicCollection3D graphics = streamLines(xxa, yya, z, xua, xva, r, density, "z", ls);
- sgs.add(graphics);
- }
-
- return sgs;
- }
-
- /**
- * Create streamline slices in 3D axes
- * @param xa X coordinate array
- * @param ya Y coordinate array
- * @param za Z coordinate array
- * @param ua U component array
- * @param va V component array
- * @param wa W component array
- * @param data Data array
- * @param xSlice X slices
- * @param ySlice Y slices
- * @param zSlice Z slices
- * @param density Streamline density
- * @param ls Legend scheme
- * @return Streamline slices graphics
- * @throws InvalidRangeException
- */
- public static List streamSlice(Array xa, Array ya, Array za, Array ua,
- Array va, Array wa, Array data, List zSliceIndex,
- int density, LegendScheme ls) throws InvalidRangeException {
- List sgs = new ArrayList<>();
- int zIdx;
-
- //Z slice
- for (int i = 0; i < zSliceIndex.size(); i++) {
- zIdx = zSliceIndex.get(i);
- Array aa = za;
- Array xua = ArrayUtil.slice(ua, 0, zIdx);
- Array xva = ArrayUtil.slice(va, 0, zIdx);
- Array r = data == null ? null : ArrayUtil.slice(data, 0, zIdx);
- Array xxa = xa.getRank() == 1 ? xa : ArrayUtil.slice(xa, 0, zIdx);
- Array yya = ya.getRank() == 1 ? ya : ArrayUtil.slice(ya, 0, zIdx);
- GraphicCollection3D graphics;
- if (za.getRank() == 1) {
- double z = za.getDouble(zIdx);
- graphics = streamLines(xxa, yya, z, xua, xva, r, density, "z", ls);
- } else {
- Array zza = ArrayUtil.slice(za, 0, zIdx);
- zza = zza.copyIfView();
- graphics = streamLines(xxa, yya, zza, xua, xva, r, density, ls);
- }
- sgs.add(graphics);
- }
-
- return sgs;
- }
-
-// /**
-// * Create annotate
-// * @param text The text
-// * @param x X coordinate
-// * @param y Y coordinate
-// * @param xText X coordinate of the text
-// * @param yText Y coordinate of the text
-// * @param ab Arrow line break
-// * @return Arrow line break and text
-// */
-// public static GraphicCollection createAnnotate(ChartText text, float x, float y,
-// float xText, float yText, ArrowLineBreak ab) {
-// GraphicCollection gc = new GraphicCollection();
-// Graphic gg = createArrowLine(x, y, xText - x, xText - y, ab);
-// gc.add(gg)
-// }
- /**
- * Create pie arc polygons
- *
- * @param xdata X data array
- * @param colors Colors
- * @param labels Labels
- * @param startAngle Start angle
- * @param explode Explode
- * @param labelFont Label font
- * @param labelColor Label color
- * @param labelDis Label distance
- * @param autopct pct format
- * @param pctDis pct distance
- * @param radius Pie radius
- * @param wedgeprops Wedge properties
- * @return GraphicCollection
- */
- public static GraphicCollection[] createPieArcs(Array xdata, List colors,
- List labels, float startAngle, List explode, Font labelFont,
- Color labelColor, float labelDis, String autopct, float pctDis, float radius,
- HashMap wedgeprops) {
- GraphicCollection gc = new GraphicCollection();
- GraphicCollection lgc = new GraphicCollection();
- GraphicCollection pgc = new GraphicCollection();
- double sum = ArrayMath.sum(xdata).doubleValue();
- double v;
- float sweepAngle, angle;
- float ex;
- double dx, dy, ldx, ldy;
- String label, pct = null;
- LegendScheme ls = new LegendScheme(ShapeTypes.Polygon);
- Boolean drawEdge = wedgeprops.get("drawedge") == null ? null : (Boolean) wedgeprops.get("drawedge");
- Color edgeColor = wedgeprops.get("edgecolor") == null ? null : (Color) wedgeprops.get("edgecolor");
- Float lineWidth = wedgeprops.get("linewidth") == null ? null : Float.parseFloat(String.valueOf(wedgeprops.get("linewidth")));
- Float wedgeWidth = wedgeprops.get("width") == null ? null : Float.parseFloat(String.valueOf(wedgeprops.get("width")));
- IndexIterator xIter = xdata.getIndexIterator();
- int i = 0;
- while (xIter.hasNext()){
- v = xIter.getDoubleNext();
- if (Double.isNaN(v)) {
- continue;
- }
-
- if (sum > 1) {
- v = v / sum;
- }
- sweepAngle = (float) (360.0 * v);
- ArcShape aShape = new ArcShape();
- aShape.setStartAngle(startAngle);
- aShape.setSweepAngle(sweepAngle);
- angle = startAngle + sweepAngle / 2;
- if (explode == null) {
- dx = 0;
- dy = 0;
- } else {
- ex = explode.get(i).floatValue();
- aShape.setExplode(ex);
- dx = radius * ex * Math.cos(angle * Math.PI / 180);
- dy = radius * ex * Math.sin(angle * Math.PI / 180);
- }
- List points = new ArrayList<>();
- points.add(new PointD(-radius + dx, -radius + dy));
- points.add(new PointD(-radius + dx, radius + dy));
- points.add(new PointD(radius + dx, radius + dy));
- points.add(new PointD(radius + dx, -radius + dy));
- points.add(new PointD(dx, dy));
- aShape.setPoints(points);
- if (wedgeWidth != null) {
- aShape.setWedgeWidth(wedgeWidth);
- }
- PolygonBreak pgb = new PolygonBreak();
- pgb.setColor(colors.get(i));
- if (drawEdge != null) {
- pgb.setDrawOutline(drawEdge);
- }
- if (edgeColor != null) {
- pgb.setOutlineColor(edgeColor);
- }
- if (lineWidth != null) {
- pgb.setOutlineSize(lineWidth);
- }
- if (labels == null) {
- if (autopct == null) {
- label = "";
- } else {
- label = String.format(autopct, v * 100);
- }
- } else {
- label = labels.get(i);
- if (autopct != null) {
- pct = String.format(autopct, v * 100);
- }
- }
- pgb.setCaption(label);
- Graphic graphic = new Graphic(aShape, pgb);
- gc.add(graphic);
- ls.addLegendBreak(pgb);
-
- //Label text
- if (!label.isEmpty()) {
- ChartText ps = new ChartText();
- ldx = dx + radius * labelDis * Math.cos(angle * Math.PI / 180);
- ldy = dy + radius * labelDis * Math.sin(angle * Math.PI / 180);
- ps.setPoint(ldx, ldy);
- ps.setText(label);
- ps.setFont(labelFont);
- ps.setColor(labelColor);
- if (angle > 90 && angle < 270) {
- ps.setXAlign(XAlign.RIGHT);
- }
- if (angle > 180 && angle < 360) {
- ps.setYAlign(YAlign.TOP);
- }
- if (angle == 0 || angle == 180) {
- ps.setYAlign(YAlign.CENTER);
- } else if (angle == 90 || angle == 270) {
- ps.setXAlign(XAlign.CENTER);
- }
- lgc.add(new Graphic(ps, new ColorBreak()));
- }
-
- //pct text
- if (pct != null) {
- ChartText ps = new ChartText();
- ldx = dx + radius * pctDis * Math.cos(angle * Math.PI / 180);
- ldy = dy + radius * pctDis * Math.sin(angle * Math.PI / 180);
- ps.setPoint(ldx, ldy);
- ps.setText(pct);
- ps.setFont(labelFont);
- ps.setColor(labelColor);
- ps.setXAlign(XAlign.CENTER);
- ps.setYAlign(YAlign.CENTER);
- pgc.add(new Graphic(ps, new ColorBreak()));
- }
-
- startAngle += sweepAngle;
- i++;
- }
- gc.setSingleLegend(false);
- gc.setLegendScheme(ls);
- gc.getLabelSet().setLabelFont(labelFont);
- gc.getLabelSet().setLabelColor(labelColor);
- dx = radius * 0.1;
- if (labels != null || autopct != null) {
- Extent ext = gc.getExtent().extend(dx, dx);
- gc.setExtent(ext);
- }
-
- if (pct == null) {
- if (lgc.isEmpty()) {
- return new GraphicCollection[]{gc};
- } else {
- return new GraphicCollection[]{gc, lgc};
- }
- } else {
- if (lgc.isEmpty()) {
- return new GraphicCollection[]{gc, pgc};
- } else {
- return new GraphicCollection[]{gc, lgc, pgc};
- }
- }
- }
-
- /**
- * Create box graphics
- *
- * @param xdata X data array list
- * @param positions Box position list
- * @param widths Box width list
- * @param showcaps Show caps or not
- * @param showfliers Show fliers or not
- * @param showmeans Show means or not
- * @param showmedians Show medians or not
- * @param boxBreak Box polygon break
- * @param medianBreak Meandian line break
- * @param whiskerBreak Whisker line break
- * @param capBreak Whisker cap line break
- * @param meanBreak Mean point break
- * @param flierBreak Flier point break
- * @return GraphicCollection
- */
- public static GraphicCollection createBox(List xdata, List positions, List widths,
- boolean showcaps, boolean showfliers, boolean showmeans, boolean showmedians, PolygonBreak boxBreak,
- ColorBreak medianBreak, PolylineBreak whiskerBreak, PolylineBreak capBreak,
- ColorBreak meanBreak, PointBreak flierBreak) {
- GraphicCollection gc = new GraphicCollection();
- int n = xdata.size();
- if (positions == null) {
- positions = new ArrayList<>();
- for (int i = 0; i < n; i++) {
- positions.add(i + 1);
- }
- }
- if (widths == null) {
- widths = new ArrayList<>();
- for (int i = 0; i < n; i++) {
- widths.add(0.5);
- }
- }
- double v, width;
- if (boxBreak == null) {
- boxBreak = new PolygonBreak();
- boxBreak.setDrawFill(false);
- boxBreak.setOutlineColor(Color.blue);
- }
- if (medianBreak == null) {
- medianBreak = new PolylineBreak();
- medianBreak.setColor(Color.red);
- }
- if (whiskerBreak == null) {
- whiskerBreak = new PolylineBreak();
- whiskerBreak.setColor(Color.black);
- whiskerBreak.setStyle(LineStyles.DASH);
- }
- if (capBreak == null) {
- capBreak = new PolylineBreak();
- capBreak.setColor(Color.black);
- }
- if (flierBreak == null) {
- flierBreak = new PointBreak();
- flierBreak.setStyle(PointStyle.Plus);
- }
- if (meanBreak == null) {
- meanBreak = new PointBreak();
- ((PointBreak) meanBreak).setStyle(PointStyle.Square);
- ((PointBreak) meanBreak).setColor(Color.red);
- ((PointBreak) meanBreak).setOutlineColor(Color.black);
- }
-
- for (int i = 0; i < n; i++) {
- Array a = xdata.get(i);
- if (Double.isNaN(ArrayMath.min(a).doubleValue())) {
- continue;
- }
-
- v = positions.get(i).doubleValue();
- width = widths.get(i).doubleValue();
- //Add box polygon
- double q1 = Statistics.quantile(a, 1);
- double q3 = Statistics.quantile(a, 3);
- double median = Statistics.quantile(a, 2);
- double mind = ArrayMath.getMinimum(a);
- double maxd = ArrayMath.getMaximum(a);
- double mino = q1 - (q3 - q1) * 1.5;
- double maxo = q3 + (q3 - q1) * 1.5;
- List pList = new ArrayList<>();
- pList.add(new PointD(v - width * 0.5, q1));
- pList.add(new PointD(v - width * 0.5, q3));
- pList.add(new PointD(v + width * 0.5, q3));
- pList.add(new PointD(v + width * 0.5, q1));
- pList.add(new PointD(v - width * 0.5, q1));
- PolygonShape pgs = new PolygonShape();
- pgs.setPoints(pList);
- gc.add(new Graphic(pgs, boxBreak));
-
- //Add meadian line
- if (showmedians) {
- if (medianBreak.getBreakType() == BreakTypes.PolylineBreak) {
- pList = new ArrayList<>();
- pList.add(new PointD(v - width * 0.5, median));
- pList.add(new PointD(v + width * 0.5, median));
- PolylineShape pls = new PolylineShape();
- pls.setPoints(pList);
- gc.add(new Graphic(pls, medianBreak));
- } else {
- PointShape ps = new PointShape();
- ps.setPoint(new PointD(v, median));
- gc.add(new Graphic(ps, medianBreak));
- }
- }
-
- //Add low whisker line
- double min = Math.max(mino, mind);
- pList = new ArrayList<>();
- pList.add(new PointD(v, q1));
- pList.add(new PointD(v, min));
- PolylineShape pls = new PolylineShape();
- pls.setPoints(pList);
- gc.add(new Graphic(pls, whiskerBreak));
- //Add cap
- if (showcaps) {
- pList = new ArrayList<>();
- pList.add(new PointD(v - width * 0.25, min));
- pList.add(new PointD(v + width * 0.25, min));
- pls = new PolylineShape();
- pls.setPoints(pList);
- gc.add(new Graphic(pls, capBreak));
- }
- //Add low fliers
- if (showfliers) {
- if (mino > mind) {
- for (int j = 0; j < a.getSize(); j++) {
- if (a.getDouble(j) < mino) {
- PointShape ps = new PointShape();
- ps.setPoint(new PointD(v, a.getDouble(j)));
- gc.add(new Graphic(ps, flierBreak));
- }
- }
- }
- }
-
- //Add high whisker line
- double max = Math.min(maxo, maxd);
- pList = new ArrayList<>();
- pList.add(new PointD(v, q3));
- pList.add(new PointD(v, max));
- pls = new PolylineShape();
- pls.setPoints(pList);
- gc.add(new Graphic(pls, whiskerBreak));
- //Add cap
- if (showcaps) {
- pList = new ArrayList<>();
- pList.add(new PointD(v - width * 0.25, max));
- pList.add(new PointD(v + width * 0.25, max));
- pls = new PolylineShape();
- pls.setPoints(pList);
- gc.add(new Graphic(pls, capBreak));
- }
- //Add high fliers
- if (showfliers) {
- if (maxo < maxd) {
- for (int j = 0; j < a.getSize(); j++) {
- if (a.getDouble(j) > maxo) {
- PointShape ps = new PointShape();
- ps.setPoint(new PointD(v, a.getDouble(j)));
- gc.add(new Graphic(ps, flierBreak));
- }
- }
- }
- }
-
- //Add mean line
- if (showmeans) {
- double mean = ArrayMath.mean(a);
- if (meanBreak.getBreakType() == BreakTypes.PointBreak) {
- PointShape ps = new PointShape();
- ps.setPoint(new PointD(v, mean));
- gc.add(new Graphic(ps, meanBreak));
- } else {
- pList = new ArrayList<>();
- pList.add(new PointD(v - width * 0.5, mean));
- pList.add(new PointD(v + width * 0.5, mean));
- pls = new PolylineShape();
- pls.setPoints(pList);
- gc.add(new Graphic(pls, meanBreak));
- }
- }
- }
- gc.setSingleLegend(false);
-
- return gc;
- }
-
- /**
- * Convert graphics from polar to cartesian coordinate
- *
- * @param graphics Graphics
- */
- public static void polarToCartesian(GraphicCollection graphics) {
- for (int m = 0; m < graphics.getNumGraphics(); m++) {
- Graphic graphic = graphics.get(m);
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- Graphic gg = graphic.getGraphicN(i);
- Shape shape = gg.getShape();
- List points = new ArrayList<>();
- for (PointD p : shape.getPoints()) {
- double[] xy = MIMath.polarToCartesian(p.X, p.Y);
- points.add(new PointD(xy[0], xy[1]));
- }
- shape.setPoints(points);
- }
- }
- graphics.updateExtent();
- }
-
- /**
- * Convert graphics from polar to cartesian coordinate
- *
- * @param graphics Graphics
- */
- public static void polarToCartesian(GraphicCollection graphics, double bottom) {
- for (int m = 0; m < graphics.getNumGraphics(); m++) {
- Graphic graphic = graphics.get(m);
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- Graphic gg = graphic.getGraphicN(i);
- Shape shape = gg.getShape();
- List points = new ArrayList<>();
- for (PointD p : shape.getPoints()) {
- double[] xy = MIMath.polarToCartesian(p.X, p.Y + bottom);
- points.add(new PointD(xy[0], xy[1]));
- }
- shape.setPoints(points);
- }
- }
- graphics.updateExtent();
- }
-
- private static int findIndex(double[] values, double v) {
- int idx = -1;
- for (int i = 0; i < values.length; i++) {
- if (i == values.length - 1) {
- if (v == values[i]) {
- idx = i;
- break;
- }
- } else {
- if (v == values[i] || v < values[i + 1]) {
- idx = i;
- break;
- }
- }
- }
-
- return idx;
- }
-
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/GridLine.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/GridLine.java
deleted file mode 100644
index 12f6188a..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/GridLine.java
+++ /dev/null
@@ -1,166 +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.geometry.legend.LineStyles;
-
-import java.awt.Color;
-
-/**
- *
- * @author yaqiang
- */
-public class GridLine {
- //
- private Color color;
- private float size;
- private LineStyles style;
- private boolean drawXLine;
- private boolean drawYLine;
- private boolean drawZLine;
- private boolean top;
- //
- //
- /**
- * Constructor
- */
- public GridLine(){
- this.color = Color.LIGHT_GRAY;
- this.size = 1.0f;
- this.style = LineStyles.DASH;
- this.drawXLine = false;
- this.drawYLine = false;
- this.drawZLine = false;
- this.top = false;
- }
-
- /**
- * Constructor
- * @param visible
- */
- public GridLine(boolean visible) {
- this();
- this.drawXLine = visible;
- this.drawYLine = visible;
- this.drawZLine = visible;
- }
- //
- //
- /**
- * Get color
- * @return Color
- */
- public Color getColor(){
- return this.color;
- }
-
- /**
- * Set color
- * @param value Color
- */
- public void setColor(Color value){
- this.color = value;
- }
-
- /**
- * Get size
- * @return Size
- */
- public float getSize(){
- return this.size;
- }
-
- /**
- * Set size
- * @param value Size
- */
- public void setSize(float value) {
- this.size = value;
- }
-
- /**
- * Get style
- * @return Style
- */
- public LineStyles getStyle(){
- return this.style;
- }
-
- /**
- * Set style
- * @param value Style
- */
- public void setStyle(LineStyles value){
- this.style = value;
- }
-
- /**
- * Get if draw x grid lines
- * @return Boolean
- */
- public boolean isDrawXLine(){
- return this.drawXLine;
- }
-
- /**
- * Set if draw x grid lines
- * @param value Boolean
- */
- public void setDrawXLine(boolean value){
- this.drawXLine = value;
- }
-
- /**
- * Get if draw y grid lines
- * @return Boolean
- */
- public boolean isDrawYLine(){
- return this.drawYLine;
- }
-
- /**
- * Set if draw y grid lines
- * @param value Boolean
- */
- public void setDrawYLine(boolean value){
- this.drawYLine = value;
- }
-
- /**
- * Get if draw z grid lines
- * @return Boolean
- */
- public boolean isDrawZLine(){
- return this.drawZLine;
- }
-
- /**
- * Set if draw z grid lines
- * @param value Boolean
- */
- public void setDrawZLine(boolean value){
- this.drawZLine = value;
- }
-
- /**
- * Return if the grid draw on the top of the graph
- * @return Boolean
- */
- public boolean isTop(){
- return this.top;
- }
-
- /**
- * Set if the grid draw on the top of the graph
- * @param value Boolean
- */
- public void setTop(boolean value){
- this.top = value;
- }
- //
- //
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/MapPlot.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/MapPlot.java
deleted file mode 100644
index 4239cdc7..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/MapPlot.java
+++ /dev/null
@@ -1,1314 +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 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.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;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import org.meteoinfo.chart.ChartNorthArrow;
-import org.meteoinfo.chart.ChartPanel;
-import org.meteoinfo.chart.ChartScaleBar;
-import org.meteoinfo.chart.ChartText;
-import org.meteoinfo.chart.Location;
-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.drawing.Draw;
-import org.meteoinfo.geometry.graphic.Graphic;
-import org.meteoinfo.geometry.graphic.GraphicCollection;
-import org.meteoinfo.geometry.legend.*;
-import org.meteoinfo.layer.LayerCollection;
-import org.meteoinfo.layer.MapLayer;
-import org.meteoinfo.legend.MapFrame;
-import org.meteoinfo.map.MapView;
-import org.meteoinfo.projection.KnownCoordinateSystems;
-import org.meteoinfo.projection.ProjectionInfo;
-import org.meteoinfo.projection.ProjectionUtil;
-import org.meteoinfo.projection.Reproject;
-import org.meteoinfo.geometry.shape.*;
-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;
-
-/**
- *
- * @author wyq
- */
-public class MapPlot extends AbstractPlot2D implements IWebMapPanel {
-
- //
- private MapFrame mapFrame;
- private MapView mapView;
- private boolean antialias;
- private MapLayer selectedLayer;
- private final TileLoadListener tileLoadListener = new TileLoadListener(this);
- private ChartPanel parent;
- private float[] lonLim;
- private float[] latLim;
- private Graphic boundary;
- private ChartScaleBar scaleBar;
- private ChartNorthArrow northArrow;
- private boolean degreeSpace = false;
-
- //
- //
- /**
- * Constructor
- */
- public MapPlot() {
- super();
- this.antialias = false;
- this.setAutoAspect(false);
- try {
- this.setXAxis(new LonLatAxis("Longitude", true));
- this.setYAxis(new LonLatAxis("Latitude", false));
- } catch (CloneNotSupportedException ex) {
- Logger.getLogger(MapPlot.class.getName()).log(Level.SEVERE, null, ex);
- }
- this.getAxis(Location.TOP).setDrawTickLabel(false);
- this.getAxis(Location.RIGHT).setDrawTickLabel(false);
- this.setDrawNeatLine(true);
- this.getGridLine().setTop(true);
- }
-
- /**
- * Constructor
- *
- * @param mapView MapView
- */
- public MapPlot(MapView mapView) {
- this();
- this.setMapView(mapView, true);
- this.mapFrame = new MapFrame();
- this.mapFrame.setMapView(mapView);
- }
-
- /**
- * Constructor
- *
- * @param mapFrame MapFrame
- */
- public MapPlot(MapFrame mapFrame) {
- this();
- this.mapFrame = mapFrame;
- this.setMapView(mapFrame.getMapView(), true);
- }
-
- //
- //
- /**
- * ChartPanel parent
- *
- * @param value ChartPanel
- */
- public void setParent(ChartPanel 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.setGeoMap(isGeoMap);
- this.mapView.setMultiGlobalDraw(isGeoMap);
- Extent extent = this.getAutoExtent();
- this.setDrawExtent(extent);
- PolygonShape bvs = this.mapView.getProjection().getProjInfo().getBoundary();
- if (bvs != null) {
- this.setBoundary(bvs);
- }
- }
-
- @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.getMapView().getProjection().getProjInfo();
- }
-
- /**
- * Set projection info
- * @param proj Projection info
- */
- public void setProjInfo(ProjectionInfo 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.getMapView().getProjection().isLonLatMap();
- }
-
- /**
- * 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 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();
- }
- }
-
- /**
- * 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.setAntiAlias(this.antialias);
- this.mapView.setViewExtent((Extent) this.getDrawExtent().clone());
- 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);
- }
- }
-
- /**
- * 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.getMapView().getProjection().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()) {
- super.addText(text);
- } else {
- PointShape ps = new PointShape();
- PointD lonlatp = new PointD(text.getX(), text.getY());
- PointD xyp = Reproject.reprojectPoint(lonlatp, KnownCoordinateSystems.geographic.world.WGS1984,
- this.getMapView().getProjection().getProjInfo());
- ps.setPoint(xyp);
- LabelBreak lb = new LabelBreak();
- lb.setText(text.getText());
- lb.setFont(text.getFont());
- lb.setColor(text.getColor());
- Graphic aGraphic = new Graphic(ps, lb);
- this.getMapView().addGraphic(aGraphic);
- }
- } else {
- super.addText(text);
- }
- }
-
- /**
- * Add point graphic
- *
- * @param lat Latitude
- * @param lon Lontitude
- * @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.getMapView().getProjection().isLonLatMap()) {
- ps.setPoint(lonlatp);
- } else {
- PointD xyp = Reproject.reprojectPoint(lonlatp, KnownCoordinateSystems.geographic.world.WGS1984,
- this.getMapView().getProjection().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.getMapView().getProjection().isLonLatMap()) {
- ps.setPoint(lonlatp);
- } else {
- xyp = Reproject.reprojectPoint(lonlatp, KnownCoordinateSystems.geographic.world.WGS1984,
- this.getMapView().getProjection().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.getMapView().getProjection().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.mapView.addGraphic(graphic);
-
- return graphic;
- }
-
-// /**
-// * Add a layer
-// * @param idx Index
-// * @param layer Layer
-// */
-// public void addLayer(int idx, MapLayer layer){
-// this.mapFrame.addLayer(idx, layer);
-// }
-//
-// /**
-// * Add a layer
-// * @param layer Layer
-// */
-// public void addLayer(MapLayer layer){
-// this.mapFrame.addLayer(layer);
-// }
-//
-// /**
-// * Set extent
-// *
-// * @param extent Extent
-// */
-// public void setExtent(Extent extent) {
-// this.mapFrame.getMapView().setViewExtent(extent);
-// }
- /**
- * Get position area
- *
- * @param area Whole area
- * @return Graphic area
- */
- @Override
- public Rectangle2D getPositionArea(Rectangle2D area) {
- Rectangle2D plotArea = super.getPositionArea(area);
- if (!this.isAutoAspect()) {
- 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
-// public void drawGraph(Graphics2D g, Rectangle2D area) {
-// MapView mapView = this.mapFrame.getMapView();
-// mapView.setViewExtent(this.getDrawExtent());
-// Extent extent = mapView.getViewExtent();
-// double width = extent.getWidth();
-// double height = extent.getHeight();
-// double scaleFactor = mapView.getXYScaleFactor();
-// if (width / height / scaleFactor > area.getWidth() / area.getHeight()){
-// double h = area.getWidth() * height * scaleFactor / width;
-// double delta = area.getHeight() - h;
-// area.setRect(area.getX(), area.getY() + delta / 2, area.getWidth(), h);
-// } else {
-// double w = width * area.getHeight() / height / scaleFactor;
-// double delta = area.getWidth() - w;
-// area.setRect(area.getX() + delta / 2, area.getY(), w, area.getHeight());
-// }
-// mapView.paintGraphics(g, area);
-// }
-// /**
-// * Set draw extent
-// *
-// * @param extent Extent
-// */
-// @Override
-// public void setDrawExtent(Extent extent) {
-// if (this.isLonLatMap()){
-// super.updateDrawExtent();
-// } else {
-// ((ProjLonLatAxis)this.getAxis(Location.BOTTOM)).setX_Y(extent.minY);
-// ((ProjLonLatAxis)this.getAxis(Location.TOP)).setX_Y(extent.maxY);
-// ((ProjLonLatAxis)this.getAxis(Location.LEFT)).setX_Y(extent.minX);
-// ((ProjLonLatAxis)this.getAxis(Location.RIGHT)).setX_Y(extent.maxX);
-// super.setDrawExtent(extent);
-// }
-// }
-//
-// /**
-// * Update draw extent
-// */
-// @Override
-// public void updateDrawExtent(){
-// if (this.isLonLatMap()){
-// super.updateDrawExtent();
-// } else {
-// Extent extent = this.getDrawExtent();
-// ((ProjLonLatAxis)this.getAxis(Location.BOTTOM)).setX_Y(extent.minY);
-// ((ProjLonLatAxis)this.getAxis(Location.TOP)).setX_Y(extent.maxY);
-// ((ProjLonLatAxis)this.getAxis(Location.LEFT)).setX_Y(extent.minX);
-// ((ProjLonLatAxis)this.getAxis(Location.RIGHT)).setX_Y(extent.maxX);
-// super.updateDrawExtent();
-// }
-// }
- @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 = len + this.mapFrame.getGridLabelShift();
- if (mapFrame.isInsideTickLine()) {
- space = mapFrame.getGridLabelShift();
- }
-
- Object[] objs;
- float xShift, yShift;
- XAlign xAlign;
- YAlign yAlign;
- 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;
-
- 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:
- labX = labX - aSF.width / 2;
- labY = labY + aSF.height * 3 / 4 + space;
- eP.X = sP.X;
- if (mapFrame.isInsideTickLine()) {
- eP.Y = sP.Y - len;
- } else {
- eP.Y = sP.Y + len;
- }
- break;
- case Weast:
- labX = labX - aSF.width - space;
- labY = labY + aSF.height / 3;
- eP.Y = sP.Y;
- if (mapFrame.isInsideTickLine()) {
- eP.X = sP.X + len;
- } else {
- eP.X = sP.X - len;
- }
- break;
- case North:
- labX = labX - aSF.width / 2;
- //labY = labY - aSF.height / 3 - space;
- labY = labY - space;
- eP.X = sP.X;
- if (mapFrame.isInsideTickLine()) {
- eP.Y = sP.Y + len;
- } else {
- eP.Y = sP.Y - len;
- }
- break;
- case East:
- labX = labX + space;
- labY = labY + aSF.height / 3;
- eP.Y = sP.Y;
- if (mapFrame.isInsideTickLine()) {
- eP.X = sP.X - len;
- } else {
- eP.X = sP.X + len;
- }
- break;
- }
- g.setColor(mapFrame.getGridLineColor());
- g.draw(new Line2D.Float(sP.X, sP.Y, eP.X, eP.Y));
- g.setColor(this.getXAxis().getTickLabelColor());
- g.drawString(drawStr, labX, labY);
- } 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 org.xml.sax.SAXException
- * @throws java.io.IOException
- * @throws javax.xml.parsers.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 org.xml.sax.SAXException
- * @throws java.io.IOException
- * @throws javax.xml.parsers.ParserConfigurationException
- */
- public void loadMIProjectFile(String fn) throws SAXException, IOException, ParserConfigurationException {
- this.loadMIProjectFile(fn, 0);
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/PiePlot.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/PiePlot.java
deleted file mode 100644
index 13fbd7bb..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/PiePlot.java
+++ /dev/null
@@ -1,161 +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 java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
-
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.drawing.Draw;
-import org.meteoinfo.geometry.legend.ColorBreak;
-import org.meteoinfo.geometry.legend.PolygonBreak;
-import org.meteoinfo.geometry.shape.ArcShape;
-import org.meteoinfo.geometry.graphic.Graphic;
-import org.meteoinfo.geometry.graphic.GraphicCollection;
-import org.meteoinfo.geometry.shape.Shape;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class PiePlot extends Plot2D {
-
- //
- //
- //
- /**
- * Constructor
- */
- public PiePlot(){
- super();
- this.setAutoAspect(false);
- }
- //
- //
- //
- //
- @Override
- void drawGraph(Graphics2D g, Rectangle2D area) {
- AffineTransform oldMatrix = g.getTransform();
- //Rectangle oldRegion = g.getClipBounds();
- //g.setClip(area);
- g.translate(area.getX(), area.getY());
-
- //Draw background
- if (this.background != null) {
- g.setColor(this.getBackground());
- g.fill(new Rectangle2D.Double(0, 0, area.getWidth(), area.getHeight()));
- }
-
- for (int m = 0; m < this.getGraphics().getNumGraphics(); m++) {
- Graphic graphic = this.getGraphics().get(m);
- ColorBreak cb = graphic.getLegend();
- float dist = 5;
- float ex = this.getExplode();
- Font labelFont = ((GraphicCollection)graphic).getLabelSet().getLabelFont();
- Color labelColor = ((GraphicCollection)graphic).getLabelSet().getLabelColor();
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- Graphic gg = graphic.getGraphicN(i);
- if (!graphic.isSingleLegend()) {
- cb = gg.getLegend();
- }
- Shape shape = gg.getShape();
- this.drawArc(g, (ArcShape) shape, (PolygonBreak) cb, area, dist, ex, labelFont,
- labelColor);
- }
- }
-
- g.setTransform(oldMatrix);
- //g.setClip(oldRegion);
- }
-
- private float getExplode() {
- Graphic graphic = this.getGraphics().get(0);
- float ex = 0;
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- Graphic gg = graphic.getGraphicN(i);
- ArcShape shape = (ArcShape) gg.getShape();
- if (shape.getExplode() > 0) {
- ex = 10;
- break;
- }
- }
- return ex;
- }
-
- private void drawArc(Graphics2D g, ArcShape aShape, PolygonBreak aPGB,
- Rectangle2D area, float dist, float ex, Font labelFont, Color labelColor) {
- float startAngle = aShape.getStartAngle();
- float sweepAngle = aShape.getSweepAngle();
- float angle = startAngle + sweepAngle / 2;
- float space = 20;
- Rectangle2D rect = new Rectangle2D.Double(area.getX() + ex + space, area.getY() + ex + space, area.getWidth() - ex - space,
- area.getHeight() - ex - space);
- double dx = 0, dy = 0;
- if (aShape.getExplode() > 0) {
- dx = ex * Math.cos((360 - angle) * Math.PI / 180);
- dy = ex * Math.sin((360 - angle) * Math.PI / 180);
- rect.setRect(rect.getX() + dx, rect.getY() + dy, rect.getWidth(), rect.getHeight());
- }
- float sx = (float) (rect.getX() - area.getX());
- float sy = (float) (rect.getY() - area.getY());
- Draw.drawPie(new PointF(sx, sy), (float) rect.getWidth(), (float) rect.getHeight(),
- startAngle, sweepAngle, aPGB, g);
-
- //Draw label
- //Rectangle clip = g.getClipBounds();
- //if (clip != null) {
- // g.setClip(null);
- //}
- float x, y, w, h;
- PointF sPoint = new PointF((float) (rect.getWidth() * 0.5 + sx), (float) (rect.getHeight() * 0.5 + sy));
- String label = aPGB.getCaption();
- if (angle > 360) {
- angle = angle - 360;
- }
- float r = (float) (rect.getWidth() * 0.5) + dist;
- PointF lPoint = Draw.getPieLabelPoint(sPoint, r, angle);
- x = lPoint.X;
- y = lPoint.Y;
- Dimension dim = Draw.getStringDimension(label, g);
- h = dim.height;
- w = dim.width;
- if ((angle >= 0 && angle < 45)) {
- //x = x + dis;
- y = y - h;
- } else if (angle >= 45 && angle < 90) {
- //y = y - dis;
- } else if (angle >= 90 && angle < 135) {
- x = x - w;
- //y = y - dis;
- } else if (angle >= 135 && angle < 225) {
- x = x - w - 3;
- y = y + h / 2;
- } else if (angle >= 225 && angle < 270) {
- x = x - w / 2;
- y = y + h;
- } else if (angle >= 270 && angle < 315) {
- //x = x + dis;
- y = y + h;
- } else {
- //x = x + dis;
- y = y + h / 2;
- }
- g.setFont(labelFont);
- g.setColor(labelColor);
- //g.drawOval((int)(x - 3), (int)(y - 3), 6, 6);
- g.drawString(label, x, y);
-
- //if (clip != null) {
- // g.setClip(clip);
- //}
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/Plot.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/Plot.java
deleted file mode 100644
index abb7e6b3..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/Plot.java
+++ /dev/null
@@ -1,498 +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 java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.Paint;
-import java.awt.Shape;
-import java.awt.Stroke;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.Rectangle2D;
-import java.util.List;
-import org.meteoinfo.chart.Margin;
-import org.meteoinfo.data.Dataset;
-
-/**
- *
- * @author yaqiang
- */
-public abstract class Plot {
-
- /** The default outline stroke. */
- public static final Stroke DEFAULT_OUTLINE_STROKE = new BasicStroke(0.5f,
- BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
-
- /** The default outline color. */
- public static final Paint DEFAULT_OUTLINE_PAINT = Color.gray;
-
- /** The default foreground alpha transparency. */
- public static final float DEFAULT_FOREGROUND_ALPHA = 1.0f;
-
- /** The default background alpha transparency. */
- public static final float DEFAULT_BACKGROUND_ALPHA = 1.0f;
-
- /** The default background color. */
- public static final Paint DEFAULT_BACKGROUND_PAINT = Color.white;
-
- /** The minimum width at which the plot should be drawn. */
- public static final int MINIMUM_WIDTH_TO_DRAW = 10;
-
- /** The minimum height at which the plot should be drawn. */
- public static final int MINIMUM_HEIGHT_TO_DRAW = 10;
-
- /** A default box shape for legend items. */
- public static final Shape DEFAULT_LEGEND_ITEM_BOX
- = new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0);
-
- /** A default circle shape for legend items. */
- public static final Shape DEFAULT_LEGEND_ITEM_CIRCLE
- = new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0);
-
- protected Rectangle2D position = new Rectangle2D.Double(0.13, 0.11, 0.775, 0.815);
- protected Rectangle2D outerPosition = new Rectangle2D.Double(0, 0, 1, 1);
- private Rectangle2D outerPositionArea;
- private Margin tightInset = new Margin();
-
- /** If is sub plot. */
- public boolean isSubPlot = false;
-
- /** Column index as a sub plot. */
- public int columnIndex = 0;
-
- /** Row index as a sub plot. */
- public int rowIndex = 0;
-
- private boolean outerPosActive = true;
- private boolean sameShrink = false;
-
- //units - normalized or pixels
- protected AxesUnits units = AxesUnits.NORMALIZED;
-
- protected boolean symbolAntialias = true;
-
- /**
- * Get units
- * @return Units
- */
- public AxesUnits getUnits(){
- return this.units;
- }
-
- /**
- * Set units
- * @param value Units
- */
- public void setUnits(AxesUnits value){
- this.units = value;
- }
-
- /**
- * Set units
- * @param value Units
- */
- public void setUnits(String value){
- this.units = AxesUnits.valueOf(value.toUpperCase());
- }
-
- /**
- * Get if Outer position active
- * @return Boolean
- */
- public boolean isOuterPosActive(){
- return this.outerPosActive;
- }
-
- /**
- * Set outer position active or not
- * @param value Boolean
- */
- public void setOuterPosActive(boolean value){
- this.outerPosActive = value;
- }
-
- /**
- * Get if same shrink
- * @return Boolean
- */
- public boolean isSameShrink(){
- return this.sameShrink;
- }
-
- /**
- * Set if same shrink
- * @param value Boolean
- */
- public void setSameShrink(boolean value){
- this.sameShrink = value;
- }
-
- /**
- * Get position
- * @return Position
- */
- public Rectangle2D getPosition(){
- return this.position;
- }
-
- /**
- * Set position
- * @param value Position
- */
- public void setPosition(Rectangle2D value){
- this.position = value;
- }
-
- /**
- * Set position
- * @param xmin Minimum x
- * @param ymin Minimum y
- * @param width Width
- * @param height Height
- */
- public void setPosition(double xmin, double ymin, double width, double height){
- this.position = new Rectangle2D.Double(xmin, ymin, width, height);
- }
-
- /**
- * Set position
- * @param pos Position list
- */
- public void setPosition(List pos){
- this.position = new Rectangle2D.Double(pos.get(0).doubleValue(), pos.get(1).doubleValue(),
- pos.get(2).doubleValue(), pos.get(3).doubleValue());
- }
-
- /**
- * Update position
- * @param figureArea Figure area
- * @param outerArea Outer position area
- */
- public void updatePosition(Rectangle2D figureArea, Rectangle2D outerArea){
- double x = outerArea.getX() / figureArea.getWidth();
- double y = 1.0 - ((outerArea.getY() - figureArea.getY()) + outerArea.getHeight()) / figureArea.getHeight();
- double w = outerArea.getWidth() / figureArea.getWidth();
- double h = outerArea.getHeight() / figureArea.getHeight();
- this.setPosition(x, y, w, h);
- }
-
- /**
- * Update position
- * @param figureArea Figure areaa
- */
- public void updatePosition(Rectangle2D figureArea){
- double x = this.positionArea.getX() / figureArea.getWidth();
- double y = 1.0 - (this.positionArea.getY() + this.positionArea.getHeight()) / figureArea.getHeight();
- double w = this.positionArea.getWidth() / figureArea.getWidth();
- double h = this.positionArea.getHeight() / figureArea.getHeight();
- this.setPosition(x, y, w, h);
- }
-
- /**
- * Get tight inset
- * @return Tight inset
- */
- public Margin getTightInset(){
- return this.tightInset;
- }
-
- /**
- * Set tight inset
- * @param value Tight inset
- */
- public void setTightInset(Margin value){
- this.tightInset = value;
- }
-
- /**
- * Get outer position
- * @return Outer position
- */
- public Rectangle2D getOuterPosition(){
- return this.outerPosition;
- }
-
- /**
- * Set outer postion
- * @param value Outer position
- */
- public void setOuterPosition(Rectangle2D value){
- this.outerPosition = value;
- }
-
- /**
- * Set outer position
- * @param xmin Minimum x
- * @param ymin Minimum y
- * @param width Width
- * @param height Height
- */
- public void setOuterPosition(double xmin, double ymin, double width, double height){
- this.outerPosition = new Rectangle2D.Double(xmin, ymin, width, height);
- }
-
- /**
- * Set outer position
- * @param pos Outer position list
- */
- public void setOuterPosition(List pos){
- this.position = new Rectangle2D.Double(pos.get(0).doubleValue(), pos.get(1).doubleValue(),
- pos.get(2).doubleValue(), pos.get(3).doubleValue());
- }
-
- /**
- * Get outer position area
- * @return Outer positoin area
- */
- public Rectangle2D getOuterPositionArea(){
- return this.outerPositionArea;
- }
-
- /**
- * Get outer position area
- * @param area Whole area
- * @return Outer position area
- */
- public abstract Rectangle2D getOuterPositionArea(Rectangle2D area);
-
- /**
- * Set outer position area
- * @param value Outer position area
- */
- public void setOuterPositionArea(Rectangle2D value){
- this.outerPositionArea = value;
- }
-
- /**
- * Get dataset
- * @return Dataset
- */
- public abstract Dataset getDataset();
-
- /**
- * Set dataset
- * @param dataset Dataset
- */
- public abstract void setDataset(Dataset dataset);
-
- /**
- * Get plot type
- * @return Plot type
- */
- public abstract PlotType getPlotType();
-
- /**
- * Get symbol antialias
- * @return Boolean
- */
- public boolean isSymbolAntialias() {
- return this.symbolAntialias;
- }
-
- /**
- * Set symbol antialias
- * @param value Boolean
- */
- public void setSymbolAntialias(boolean value) {
- this.symbolAntialias = value;
- }
-
- /**
- * Draw graphics
- * @param g2 Graphics2D
- * @param area Graphics area
- */
- public abstract void draw(Graphics2D g2, Rectangle2D area);
-
- protected Rectangle2D positionArea = new Rectangle2D.Double();
-
- /**
- * Get position area
- * @return position area
- */
- public Rectangle2D getPositionArea() {
- return this.positionArea;
- }
-
- /**
- * Get position area
- * @param zoom Zoom
- * @return Position area
- */
- public Rectangle2D getPositionArea(double zoom) {
- double w = this.positionArea.getWidth() * zoom;
- double h = this.positionArea.getHeight() * zoom;
- double xshift = (this.positionArea.getWidth() - w) / 2.0;
- double yshift = (this.positionArea.getHeight() - h) / 2.0;
- double x = this.positionArea.getX() + xshift;
- double y = this.positionArea.getY() + yshift;
-
- return new Rectangle2D.Double(x, y, w, h);
- }
-
- /**
- * Set position area
- * @param value Position area
- */
- public void setPositionArea(Rectangle2D value){
- this.positionArea = value;
- }
-
- private Rectangle2D graphArea = new Rectangle2D.Double();
-
- /**
- * Get graph area
- * @return Graph area
- */
- public Rectangle2D getGraphArea(){
- return graphArea;
- }
-
- /**
- * Set graph area
- * @param value Graph area
- */
- public void setGraphArea(Rectangle2D value){
- graphArea = value;
- }
-
- /**
- * Get position area
- * @param area Figure area
- * @return Position area
- */
- public Rectangle2D getPositionArea(Rectangle2D area) {
- if (this.units == AxesUnits.NORMALIZED) {
- double x = area.getWidth() * this.getPosition().getX() + area.getX();
- double y = area.getHeight() * (1 - this.getPosition().getHeight() - this.getPosition().getY()) + area.getY();
- double w = area.getWidth() * this.getPosition().getWidth();
- double h = area.getHeight() * this.getPosition().getHeight();
- return new Rectangle2D.Double(x, y, w, h);
- } else {
- double x = this.position.getX() + area.getX();
- double y = area.getHeight() - this.position.getY() - this.position.getHeight();
- double w = this.position.getWidth();
- double h = this.position.getHeight();
- return new Rectangle2D.Double(x, y, w, h);
- }
- }
-
- /**
- * Get tight inset
- * @param g Graphics2D
- * @param positionArea Position area
- * @return Tight inset margin
- */
- public abstract Margin getTightInset(Graphics2D g, Rectangle2D positionArea);
-
- private double positionAreaZoom = 1.0;
-
- /**
- * Get position area zoom
- * @return Position area zoom
- */
- public double getPositionAreaZoom(){
- return this.positionAreaZoom;
- }
-
- /**
- * Set position area zoom
- * @param value Position area zoom
- */
- public void setPositionAreaZoom(double value){
- this.positionAreaZoom = value;
- }
-
- /**
- * Get plot shrink
- * @return Plot shrink
- */
- public Margin getPlotShrink(){
- Margin shrink = new Margin();
- if (this.tightInset.getLeft() + this.outerPositionArea.getX() > this.positionArea.getX()){
- shrink.setLeft(this.tightInset.getLeft() + this.outerPositionArea.getX() - this.positionArea.getX());
- }
- if (this.tightInset.getRight()+ this.positionArea.getX() + this.positionArea.getWidth() >
- this.outerPositionArea.getX() + this.outerPositionArea.getWidth()){
- shrink.setRight(this.tightInset.getRight()+ this.positionArea.getX() + this.positionArea.getWidth() -
- (this.outerPositionArea.getX() + this.outerPositionArea.getWidth()));
- }
- if (this.tightInset.getTop()+ this.outerPositionArea.getY()> this.positionArea.getY()){
- shrink.setTop(this.tightInset.getTop()+ this.outerPositionArea.getY()- this.positionArea.getY());
- }
- if (this.tightInset.getBottom()+ this.positionArea.getY()+ this.positionArea.getHeight()>
- this.outerPositionArea.getY() + this.outerPositionArea.getHeight()){
- shrink.setBottom(this.tightInset.getBottom()+ this.positionArea.getY()+ this.positionArea.getHeight() -
- (this.outerPositionArea.getY() + this.outerPositionArea.getHeight()));
- }
-
- return shrink;
- }
-
- /**
- * Set plot shrink
- * @param shrink Shrink
- */
- public void setPlotShrink(Margin shrink){
- if (this.positionArea == null)
- return;
-
- double x = this.positionArea.getX() + shrink.getLeft();
- double y = this.positionArea.getY() + shrink.getTop();
- double w = this.positionArea.getWidth() - (shrink.getLeft() + shrink.getRight());
- double h = this.positionArea.getHeight() - (shrink.getTop() + shrink.getBottom());
-
- this.positionArea = new Rectangle2D.Double(x, y, w, h);
- }
-
- /**
- * Update position area zoom
- * @return Position area zoom
- */
- public double updatePostionAreaZoom(){
- Rectangle2D tightInsetArea = this.tightInset.getArea(this.positionArea);
- double left = tightInsetArea.getX() - this.outerPositionArea.getX();
- double right = this.outerPositionArea.getX() + this.outerPositionArea.getWidth() -
- (tightInsetArea.getX() + tightInsetArea.getWidth());
- double top = tightInsetArea.getY() - this.outerPositionArea.getY();
- double bottom = this.outerPositionArea.getY() + this.outerPositionArea.getHeight() -
- (tightInsetArea.getY() + tightInsetArea.getHeight());
- double minh = Math.min(left, right);
- double minv = Math.min(top, bottom);
- double min = Math.min(minh, minv);
- double zoom = 1.0;
- double factor = 2;
- //if (this.isSubPlot)
- // factor = 1.5;
- if (min < 0){
- double zoomh = 1.0;
- if (minh < 0)
- zoomh = (this.positionArea.getWidth() - Math.abs(minh) * factor) / this.positionArea.getWidth();
- double zoomv = 1.0;
- if (minv < 0)
- zoomv = (this.positionArea.getHeight() - Math.abs(minv) * factor) / this.positionArea.getHeight();
- zoom = Math.min(zoomh, zoomv);
- if (zoom < 0){
- zoom = 0.2;
- }
- }
-
- return zoom;
- }
-
- /**
- * Update position area
- */
- public void updatePositionArea(){
- double w = this.outerPositionArea.getWidth() - this.tightInset.getLeft() - this.tightInset.getRight();
- double h = this.outerPositionArea.getHeight() - this.tightInset.getTop() - this.tightInset.getBottom();
- double x = this.outerPositionArea.getX() + this.tightInset.getLeft();
- double y = this.outerPositionArea.getY() + this.tightInset.getTop();
-
- this.positionArea = new Rectangle2D.Double(x, y, w, h);
- }
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/Plot2D.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/Plot2D.java
deleted file mode 100644
index 1024ebf4..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/Plot2D.java
+++ /dev/null
@@ -1,1245 +0,0 @@
-/* Copyright 2016 - Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.chart.plot;
-
-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.RenderingHints;
-import java.awt.TexturePaint;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Line2D;
-import java.awt.geom.Rectangle2D;
-import java.awt.geom.RectangularShape;
-import java.awt.geom.RoundRectangle2D;
-import java.awt.image.BufferedImage;
-import java.util.ArrayList;
-import java.util.List;
-import org.meteoinfo.chart.ChartLegend;
-import org.meteoinfo.chart.ChartText;
-import org.meteoinfo.chart.axis.LogAxis;
-import org.meteoinfo.chart.axis.TimeAxis;
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.common.MIMath;
-import org.meteoinfo.common.PointD;
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.data.Dataset;
-import org.meteoinfo.drawing.Draw;
-import static org.meteoinfo.drawing.Draw.getHatchImage;
-
-import org.meteoinfo.geometry.graphic.Graphic;
-import org.meteoinfo.geometry.graphic.GraphicCollection;
-import org.meteoinfo.geometry.graphic.ImageGraphic;
-import org.meteoinfo.geometry.legend.*;
-import org.meteoinfo.geoprocess.GeometryUtil;
-import org.meteoinfo.geometry.shape.*;
-import org.meteoinfo.shape.PolylineErrorShape;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class Plot2D extends AbstractPlot2D {
-
- //
- private GraphicCollection graphics;
- private float barsWidth = 0.8f;
-
- //
- //
- public Plot2D() {
- super();
- this.graphics = new GraphicCollection();
- }
-
- //
- //
- /**
- * Get graphics
- *
- * @return Graphics
- */
- public GraphicCollection getGraphics() {
- return this.graphics;
- }
-
- /**
- * Get the number of graphics
- * @return The number of graphics
- */
- public int getGraphicNumber() {
- return this.graphics.size();
- }
-
- /**
- * Set graphics
- *
- * @param value Graphics
- */
- public void setGraphics(GraphicCollection value) {
- this.graphics = value;
- }
-
- /**
- * Get bars width (0 - 1), only used for automatic bar width.
- * @return Bars width
- */
- public float getBarsWidth(){
- return this.barsWidth;
- }
-
- /**
- * Set bars width (0 - 1), only used for automatic bar width.
- * @param value Bars width
- */
- public void setBarsWidth(float value){
- this.barsWidth = value;
- }
-
- //
- //
- /**
- * Add a graphic
- *
- * @param g Grahic
- */
- public void addGraphic(Graphic g) {
- this.graphics.add(g);
- }
-
- /**
- * Add a graphic by index
- *
- * @param idx Index
- * @param g Graphic
- */
- public void addGraphic(int idx, Graphic g) {
- this.graphics.add(idx, g);
- }
-
- /**
- * Remove a graphic
- *
- * @param g Graphic
- */
- public void removeGraphic(Graphic g) {
- this.graphics.remove(g);
- }
-
- /**
- * Remove a graphic by index
- *
- * @param idx Index
- */
- public void removeGraphic(int idx) {
- this.graphics.remove(idx);
- }
-
- /**
- * Remove last graphic
- */
- public void removeLastGraphic() {
- this.graphics.remove(this.graphics.size() - 1);
- }
-
- /**
- * Add graphic list
- *
- * @param gs Graphic list
- */
- public void addGraphics(List gs) {
- this.graphics.addAll(gs);
- }
-
- @Override
- void drawGraph(Graphics2D g, Rectangle2D area) {
- if (isPiePlot()){
- plotPie(g, area);
- } else
- plotGraphics(g, area);
- }
-
- private boolean isPiePlot(){
- boolean isPie = false;
- int n = 0;
- for (int m = 0; m < this.graphics.getNumGraphics(); m++) {
- Graphic graphic = this.graphics.get(m).getGraphicN(0);
- ShapeTypes st = graphic.getShape().getShapeType();
- switch (st){
- case ARC:
- isPie = true;
- n += 1;
- break;
- }
- }
- //return isPie && n == 1;
- return isPie;
- }
-
- void plotPie(Graphics2D g, Rectangle2D area){
- AffineTransform oldMatrix = g.getTransform();
- g.translate(area.getX(), area.getY());
-
- //Draw background
- if (this.background != null) {
- g.setColor(this.getBackground());
- g.fill(new Rectangle2D.Double(0, 0, area.getWidth(), area.getHeight()));
- }
-
- for (int m = 0; m < this.graphics.getNumGraphics(); m++) {
- Graphic graphic = this.graphics.get(m);
- ColorBreak cb = graphic.getLegend();
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- Graphic gg = graphic.getGraphicN(i);
- if (!graphic.isSingleLegend()) {
- cb = gg.getLegend();
- }
- Shape shape = gg.getShape();
- switch (shape.getShapeType()) {
- case Point:
- case PointM:
- case PointZ:
- this.drawPoint(g, (PointShape) shape, (PointBreak) cb, area);
- break;
- case TEXT:
- this.drawText((ChartText)shape, g, area);
- break;
- case Polyline:
- case PolylineZ:
- if (cb instanceof PointBreak) {
- this.drawPolyline(g, (PolylineShape) shape, (PointBreak) cb, area);
- } else {
- this.drawPolyline(g, (PolylineShape) shape, (PolylineBreak) cb, area);
- }
- break;
- case Polygon:
- case PolygonZ:
- for (Polygon poly : ((PolygonShape) shape).getPolygons()) {
- drawPolygon(g, poly, (PolygonBreak) cb, false, area);
- }
- break;
- case Rectangle:
- this.drawRectangle(g, (RectangleShape) shape, (PolygonBreak) cb, false, area);
- break;
- case ARC:
- this.drawArc(g, (ArcShape) shape, (PolygonBreak) cb, area);
- break;
- case WindBarb:
- this.drawWindBarb(g, (WindBarb) shape, (PointBreak) cb, area);
- break;
- case WindArraw:
- this.drawWindArrow(g, (WindArrow) shape, (ArrowBreak) cb, area);
- break;
- case Image:
- this.drawImage(g, gg, area);
- break;
- }
- }
- if (graphic instanceof GraphicCollection) {
- GraphicCollection gc = (GraphicCollection) graphic;
- if (gc.getLabelSet().isDrawLabels()) {
- this.drawLabels(g, gc, area);
- }
- }
- }
-
- g.setTransform(oldMatrix);
- }
-
- void plotGraphics(Graphics2D g, Rectangle2D area) {
- AffineTransform oldMatrix = g.getTransform();
- java.awt.Shape oldRegion = g.getClip();
- if (this.clip) {
- g.setClip(area);
- }
- g.translate(area.getX(), area.getY());
-
- int barIdx = 0;
- for (int m = 0; m < this.graphics.getNumGraphics(); m++) {
- Graphic graphic = this.graphics.get(m);
- ColorBreak cb = graphic.getLegend();
- ShapeTypes shapeType = graphic.getGraphicN(0).getShape().getShapeType();
- switch(shapeType){
- case Bar:
- this.drawBars(g, (GraphicCollection) graphic, barIdx, area);
- barIdx += 1;
- break;
- }
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- Graphic gg = graphic.getGraphicN(i);
- if (!graphic.isSingleLegend()) {
- cb = gg.getLegend();
- }
- Shape shape = gg.getShape();
- switch (shape.getShapeType()) {
- case Point:
- case PointM:
- case PointZ:
- this.drawPoint(g, (PointShape) shape, (PointBreak) cb, area);
- break;
- case TEXT:
- this.drawText((ChartText)shape, g, area);
- break;
- case Polyline:
- case PolylineZ:
- if (shape instanceof CapPolylineShape){
- this.drawCapPolyline(g, (CapPolylineShape) shape, (PolylineBreak) cb, area);
- } else {
- switch (cb.getBreakType()){
- case PointBreak:
- this.drawPolyline(g, (PolylineShape) shape, (PointBreak) cb, area);
- break;
- case PolylineBreak:
- this.drawPolyline(g, (PolylineShape) shape, (PolylineBreak) cb, area);
- break;
- case ColorBreakCollection:
- this.drawPolyline(g, (PolylineShape) shape, (ColorBreakCollection) cb, area);
- break;
- }
- }
- break;
- case CurveLine:
- this.drawCurveline(g, (CurveLineShape) shape, (PolylineBreak) cb, area);
- break;
- case PolylineError:
- if (cb instanceof PointBreak) {
- this.drawPolylineError(g, (PolylineErrorShape) shape, (PointBreak) cb, area);
- } else {
- this.drawPolylineError(g, (PolylineErrorShape) shape, (PolylineBreak) cb, area);
- }
- break;
- case Polygon:
- case PolygonZ:
- for (Polygon poly : ((PolygonShape) shape).getPolygons()) {
- drawPolygon(g, poly, (PolygonBreak) cb, false, area);
- }
- break;
- case Rectangle:
- this.drawRectangle(g, (RectangleShape) shape, (PolygonBreak) cb, false, area);
- break;
- case ARC:
- this.drawArc(g, (ArcShape) shape, (PolygonBreak) cb, area);
- break;
- case WindBarb:
- this.drawWindBarb(g, (WindBarb) shape, (PointBreak) cb, area);
- break;
- case WindArraw:
- this.drawWindArrow(g, (WindArrow) shape, (ArrowBreak) cb, area);
- break;
- case Image:
- this.drawImage(g, gg, area);
- break;
- }
- }
- if (graphic instanceof GraphicCollection) {
- GraphicCollection gc = (GraphicCollection) graphic;
- if (gc.getLabelSet().isDrawLabels()) {
- this.drawLabels(g, gc, area);
- }
- }
- }
-
- g.setTransform(oldMatrix);
- if (this.clip) {
- g.setClip(oldRegion);
- }
- }
-
- private void drawPoint(Graphics2D g, PointShape aPS, PointBreak aPB, Rectangle2D area) {
- PointD p = aPS.getPoint();
- double[] sXY = projToScreen(p.X, p.Y, area);
- PointF pf = new PointF((float) sXY[0], (float) sXY[1]);
- RenderingHints rend = g.getRenderingHints();
- boolean rc = false;
- if (this.symbolAntialias && rend.get(RenderingHints.KEY_ANTIALIASING) != RenderingHints.VALUE_ANTIALIAS_ON) {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- rc = true;
- }
- Draw.drawPoint(pf, aPB, g);
- if (rc){
- g.setRenderingHints(rend);
- }
- }
-
- void drawText(ChartText text, Graphics2D g, Rectangle2D area) {
- float x, y;
- switch (text.getCoordinates()) {
- case AXES:
- x = (float) (area.getWidth() * text.getX());
- y = (float) (area.getHeight() * (1 - text.getY()));
- this.drawText(g, text, x, y);
- break;
- case FIGURE:
- x = (float) (area.getWidth() * text.getX());
- y = (float) (area.getHeight() * (1 - text.getY()));
- this.drawText(g, text, x, y);
- break;
- case DATA:
- double[] xy = this.projToScreen(text.getX(), text.getY(), area);
- x = (float) xy[0];
- y = (float) xy[1];
- this.drawText(g, text, x, y);
- break;
- }
- }
-
- private void drawText(Graphics2D g, ChartText text, float x, float y) {
- g.setFont(text.getFont());
- g.setColor(text.getColor());
- switch (text.getYAlign()) {
- case TOP:
- y += g.getFontMetrics(g.getFont()).getAscent();
- break;
- case CENTER:
- y += g.getFontMetrics(g.getFont()).getAscent() / 2;
- break;
- }
- String s = text.getText();
- switch (text.getXAlign()) {
- case RIGHT:
- x = x - g.getFontMetrics(g.getFont()).stringWidth(s);
- break;
- case CENTER:
- x = x - g.getFontMetrics(g.getFont()).stringWidth(s) * 0.5f;
- break;
- }
- Draw.drawString(g, s, x, y, text.isUseExternalFont());
- }
-
- private void drawWindBarb(Graphics2D g, WindBarb aPS, PointBreak aPB, Rectangle2D area) {
- PointD p = aPS.getPoint();
- double[] sXY = projToScreen(p.X, p.Y, area);
- PointF pf = new PointF((float) sXY[0], (float) sXY[1]);
- Draw.drawWindBarb(pf, aPS, aPB, g);
- }
-
- private void drawWindArrow(Graphics2D g, WindArrow aPS, ArrowBreak aPB, Rectangle2D area) {
- PointD p = aPS.getPoint();
- double[] sXY = projToScreen(p.X, p.Y, area);
- PointF pf = new PointF((float) sXY[0], (float) sXY[1]);
- float zoom = aPB.getSize() / 10;
- Draw.drawArraw(pf, aPS, aPB, g, zoom);
- }
-
- private void drawPolyline(Graphics2D g, PolylineShape aPLS, PointBreak aPB, Rectangle2D area) {
- for (Polyline aline : aPLS.getPolylines()) {
- double[] sXY;
- PointF p;
- for (int i = 0; i < aline.getPointList().size(); i++) {
- PointD wPoint = aline.getPointList().get(i);
- sXY = projToScreen(wPoint.X, wPoint.Y, area);
- p = new PointF((float) sXY[0], (float) sXY[1]);
- Draw.drawPoint(p, aPB, g);
- }
- }
- }
-
- private void drawPolyline(Graphics2D g, PolylineShape aPLS, PolylineBreak aPLB, Rectangle2D area) {
- for (Polyline aline : aPLS.getPolylines()) {
- double[] sXY;
- PointF[] points = new PointF[aline.getPointList().size()];
- for (int i = 0; i < aline.getPointList().size(); i++) {
- PointD wPoint = aline.getPointList().get(i);
- sXY = projToScreen(wPoint.X, wPoint.Y, area);
- points[i] = new PointF((float) sXY[0], (float) sXY[1]);
- }
- Draw.drawPolyline(points, aPLB, g);
- }
- }
-
- private void drawPolyline(Graphics2D g, PolylineShape aPLS, ColorBreakCollection cpc, Rectangle2D area) {
- for (Polyline aline : aPLS.getPolylines()) {
- double[] sXY;
- PointF[] points = new PointF[aline.getPointList().size()];
- for (int i = 0; i < aline.getPointList().size(); i++) {
- PointD wPoint = aline.getPointList().get(i);
- sXY = projToScreen(wPoint.X, wPoint.Y, area);
- points[i] = new PointF((float) sXY[0], (float) sXY[1]);
- }
- Draw.drawPolyline(points, cpc, g);
- }
- }
-
- private void drawCapPolyline(Graphics2D g, CapPolylineShape aPLS, PolylineBreak aPLB, Rectangle2D area) {
- for (Polyline aline : aPLS.getPolylines()) {
- double[] sXY;
- PointF[] points = new PointF[aline.getPointList().size()];
- for (int i = 0; i < aline.getPointList().size(); i++) {
- PointD wPoint = aline.getPointList().get(i);
- sXY = projToScreen(wPoint.X, wPoint.Y, area);
- points[i] = new PointF((float) sXY[0], (float) sXY[1]);
- }
- Draw.drawPolyline(points, aPLB, g);
- float capLen = aPLS.getCapLen();
- int idx = points.length - 1;
- if (aPLS.getCapAngle() == 0){
- PointF[] ps = new PointF[2];
- ps[0] = new PointF(points[0].X - capLen / 2, points[0].Y);
- ps[1] = new PointF(points[0].X + capLen / 2, points[0].Y);
- Draw.drawPolyline(ps, aPLB, g);
- ps = new PointF[2];
- ps[0] = new PointF(points[idx].X - capLen / 2, points[idx].Y);
- ps[1] = new PointF(points[idx].X + capLen / 2, points[idx].Y);
- Draw.drawPolyline(ps, aPLB, g);
- } else {
- PointF[] ps = new PointF[2];
- ps[0] = new PointF(points[0].X, points[0].Y - capLen / 2);
- ps[1] = new PointF(points[0].X, points[0].Y + capLen / 2);
- Draw.drawPolyline(ps, aPLB, g);
- ps = new PointF[2];
- ps[0] = new PointF(points[idx].X, points[idx].Y - capLen / 2);
- ps[1] = new PointF(points[idx].X, points[idx].Y + capLen / 2);
- Draw.drawPolyline(ps, aPLB, g);
- }
- }
- }
-
- private void drawCurveline(Graphics2D g, CurveLineShape aPLS, PolylineBreak aPLB, Rectangle2D area) {
- for (Polyline aline : aPLS.getPolylines()) {
- double[] sXY;
- PointF[] points = new PointF[aline.getPointList().size()];
- for (int i = 0; i < aline.getPointList().size(); i++) {
- PointD wPoint = aline.getPointList().get(i);
- sXY = projToScreen(wPoint.X, wPoint.Y, area);
- points[i] = new PointF((float) sXY[0], (float) sXY[1]);
- }
- Draw.drawCurveLine(points, aPLB, g);
- }
- }
-
- private void drawPolylineError(Graphics2D g, PolylineErrorShape aPLS, PointBreak aPB, Rectangle2D area) {
- for (Polyline aline : aPLS.getPolylines()) {
- double[] sXY;
- PointF p;
- double error;
- double elen = 6;
- g.setColor(aPB.getColor());
- for (int i = 0; i < aline.getPointList().size(); i++) {
- PointD wPoint = aline.getPointList().get(i);
- sXY = projToScreen(wPoint.X, wPoint.Y, area);
- p = new PointF((float) sXY[0], (float) sXY[1]);
- if (aPLS.getYerror() != null) {
- error = aPLS.getYerror(i);
- error = this.projYLength(error, area);
- g.draw(new Line2D.Double(p.X, p.Y - error, p.X, p.Y + error));
- g.draw(new Line2D.Double(p.X - (elen * 0.5), p.Y - error, p.X + (elen * 0.5), p.Y - error));
- g.draw(new Line2D.Double(p.X - (elen * 0.5), p.Y + error, p.X + (elen * 0.5), p.Y + error));
- }
- if (aPLS.getXerror() != null) {
- error = aPLS.getXerror(i);
- error = this.projXLength(error, area);
- g.draw(new Line2D.Double(p.X - error, p.Y, p.X + error, p.Y));
- g.draw(new Line2D.Double(p.X - error, p.Y - (elen * 0.5), p.X - error, p.Y + (elen * 0.5)));
- g.draw(new Line2D.Double(p.X + error, p.Y - (elen * 0.5), p.X + error, p.Y + (elen * 0.5)));
- }
- Draw.drawPoint(p, aPB, g);
- }
- }
- }
-
- private void drawPolylineError(Graphics2D g, PolylineErrorShape aPLS, PolylineBreak aPLB, Rectangle2D area) {
- for (Polyline aline : aPLS.getPolylines()) {
- double[] sXY;
- PointF[] points = new PointF[aline.getPointList().size()];
- PointF p;
- double error;
- double elen = 6;
- g.setColor(aPLB.getColor());
- for (int i = 0; i < aline.getPointList().size(); i++) {
- PointD wPoint = aline.getPointList().get(i);
- sXY = projToScreen(wPoint.X, wPoint.Y, area);
- p = new PointF((float) sXY[0], (float) sXY[1]);
- points[i] = p;
- if (aPLS.getYerror() != null) {
- error = aPLS.getYerror(i);
- error = this.projYLength(error, area);
- g.draw(new Line2D.Double(p.X, p.Y - error, p.X, p.Y + error));
- g.draw(new Line2D.Double(p.X - (elen * 0.5), p.Y - error, p.X + (elen * 0.5), p.Y - error));
- g.draw(new Line2D.Double(p.X - (elen * 0.5), p.Y + error, p.X + (elen * 0.5), p.Y + error));
- }
- if (aPLS.getXerror() != null) {
- error = aPLS.getXerror(i);
- error = this.projXLength(error, area);
- g.draw(new Line2D.Double(p.X - error, p.Y, p.X + error, p.Y));
- g.draw(new Line2D.Double(p.X - error, p.Y - (elen * 0.5), p.X - error, p.Y + (elen * 0.5)));
- g.draw(new Line2D.Double(p.X + error, p.Y - (elen * 0.5), p.X + error, p.Y + (elen * 0.5)));
- }
- }
- Draw.drawPolyline(points, aPLB, g);
- }
- }
-
- private void drawLabels(Graphics2D g, GraphicCollection graphics, Rectangle2D area) {
- Extent lExtent = graphics.getExtent();
- Extent drawExtent = this.getDrawExtent();
- if (!MIMath.isExtentCross(lExtent, drawExtent)) {
- return;
- }
-
- Font drawFont;
- List extentList = new ArrayList<>();
- Extent maxExtent = new Extent();
- Extent aExtent;
- int i, j;
- List LabelPoints = graphics.getLabelPoints();
- String LabelStr;
- PointF aPoint = new PointF();
-
- for (i = 0; i < LabelPoints.size(); i++) {
- Graphic aLP = LabelPoints.get(i);
- PointShape aPS = (PointShape) aLP.getShape();
- LabelBreak aLB = (LabelBreak) aLP.getLegend();
- aPS.setVisible(true);
- LabelStr = aLB.getText();
- aPoint.X = (float) aPS.getPoint().X;
- aPoint.Y = (float) aPS.getPoint().Y;
- drawFont = aLB.getFont();
- if (aPoint.X < drawExtent.minX || aPoint.X > drawExtent.maxX
- || aPoint.Y < drawExtent.minY || aPoint.Y > drawExtent.maxY) {
- continue;
- }
- double[] xy = projToScreen(aPoint.X, aPoint.Y, area);
- aPoint.X = (float) xy[0];
- aPoint.Y = (float) xy[1];
- FontMetrics metrics = g.getFontMetrics(drawFont);
- Dimension labSize = new Dimension(metrics.stringWidth(LabelStr), metrics.getHeight());
- switch (aLB.getAlignType()) {
- case Center:
- aPoint.X = (float) xy[0] - labSize.width / 2;
- break;
- case Left:
- aPoint.X = (float) xy[0] - labSize.width;
- break;
- }
- aPoint.Y += labSize.height / 2;
- aPoint.Y -= aLB.getYShift();
- aPoint.X += aLB.getXShift();
-
- AffineTransform tempTrans = g.getTransform();
- if (aLB.getAngle() != 0) {
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform)tempTrans.clone();
- myTrans.translate(aPoint.X, aPoint.Y);
- myTrans.rotate(aLB.getAngle() * Math.PI / 180);
- g.setTransform(myTrans);
- aPoint.X = 0;
- aPoint.Y = 0;
- }
-
- boolean ifDraw = true;
- Rectangle rect = this.getGraphicRectangle(g, aLP, area);
- aExtent = new Extent();
- aExtent.minX = rect.x;
- aExtent.maxX = rect.x + rect.width;
- aExtent.minY = rect.y;
- aExtent.maxY = rect.y + rect.height;
- if (graphics.getLabelSet().isAvoidCollision()) {
- //Judge extent
- if (extentList.isEmpty()) {
- maxExtent = (Extent) aExtent.clone();
- extentList.add(aExtent);
- } else if (!MIMath.isExtentCross(aExtent, maxExtent)) {
- extentList.add(aExtent);
- maxExtent = MIMath.getLagerExtent(maxExtent, aExtent);
- } else {
- for (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);
- } else {
- aPS.setVisible(false);
- }
- }
- }
-
- if (ifDraw) {
- if (graphics.getLabelSet().isDrawShadow()) {
- g.setColor(graphics.getLabelSet().getShadowColor());
- g.fill(new Rectangle.Float((float) aExtent.minX, (float) aExtent.minY, labSize.width, labSize.height));
- }
- g.setFont(drawFont);
- //g.setColor(aLayer.getLabelSet().getLabelColor());
- g.setColor(aLP.getLegend().getColor());
- g.drawString(LabelStr, aPoint.X, aPoint.Y);
-
- //Draw selected rectangle
- if (aPS.isSelected()) {
- float[] dashPattern = new float[]{2.0F, 1.0F};
- g.setColor(Color.cyan);
- g.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f));
- g.draw(new Rectangle.Float((float) aExtent.minX, (float) aExtent.minY, labSize.width, labSize.height));
- }
- }
-
- if (aLB.getAngle() != 0) {
- g.setTransform(tempTrans);
- }
- }
- }
-
- /**
- * Get graphic rectangle
- *
- * @param g The graphics
- * @param aGraphic The graphic
- * @param area Area
- * @return Rectangle
- */
- public Rectangle getGraphicRectangle(Graphics2D g, Graphic aGraphic, Rectangle2D area) {
- Rectangle rect = new Rectangle();
- double[] sXY;
- float aX, aY;
- switch (aGraphic.getShape().getShapeType()) {
- case Point:
- case PointM:
- PointShape aPS = (PointShape) aGraphic.getShape();
- sXY = projToScreen(aPS.getPoint().X, aPS.getPoint().Y, area);
- aX = (float) sXY[0];
- aY = (float) sXY[1];
- switch (aGraphic.getLegend().getBreakType()) {
- case PointBreak:
- PointBreak aPB = (PointBreak) aGraphic.getLegend();
- int buffer = (int) aPB.getSize() + 2;
- rect.x = (int) aX - buffer / 2;
- rect.y = (int) aY - buffer / 2;
- rect.width = buffer;
- rect.height = buffer;
- break;
- case LabelBreak:
- LabelBreak aLB = (LabelBreak) aGraphic.getLegend();
- g.setFont(aLB.getFont());
- //FontMetrics metrics = g.getFontMetrics(aLB.getFont());
- //Dimension labSize = new Dimension(metrics.stringWidth(aLB.getText()), metrics.getHeight());
- Dimension labSize = Draw.getStringDimension(aLB.getText(), g);
- switch (aLB.getAlignType()) {
- case Center:
- aX = aX - labSize.width / 2;
- break;
- case Left:
- aX = aX - labSize.width;
- break;
- }
- aY -= aLB.getYShift();
- aY -= labSize.height / 3;
- rect.x = (int) aX;
- rect.y = (int) aY;
- rect.width = (int) labSize.width;
- rect.height = (int) labSize.height;
- break;
- }
- break;
- case Polyline:
- case Polygon:
- case Rectangle:
- case CurveLine:
- case Ellipse:
- case Circle:
- case CurvePolygon:
- List newPList = (List) aGraphic.getShape().getPoints();
- List points = new ArrayList<>();
- for (PointD wPoint : newPList) {
- sXY = projToScreen(wPoint.X, wPoint.Y, area);
- aX = (float) sXY[0];
- aY = (float) sXY[1];
- points.add(new PointD(aX, aY));
- }
- Extent aExtent = GeometryUtil.getPointsExtent(points);
- rect.x = (int) aExtent.minX;
- rect.y = (int) aExtent.minY;
- rect.width = (int) (aExtent.maxX - aExtent.minX);
- rect.height = (int) (aExtent.maxY - aExtent.minY);
- break;
- }
-
- return rect;
- }
-
- private List drawPolygon(Graphics2D g, Polygon aPG, PolygonBreak aPGB,
- boolean isSelected, Rectangle2D area) {
- int len = aPG.getOutLine().size();
- GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, len);
- PointD wPoint;
- double[] sXY;
- List rPoints = new ArrayList<>();
- for (int i = 0; i < aPG.getOutLine().size(); i++) {
- wPoint = aPG.getOutLine().get(i);
- sXY = projToScreen(wPoint.X, wPoint.Y, area);
- if (i == 0) {
- path.moveTo(sXY[0], sXY[1]);
- } else {
- path.lineTo(sXY[0], sXY[1]);
- }
- rPoints.add(new PointF((float) sXY[0], (float) sXY[1]));
- }
-
- List newPList;
- if (aPG.hasHole()) {
- for (int h = 0; h < aPG.getHoleLines().size(); h++) {
- newPList = (List)aPG.getHoleLines().get(h);
- for (int j = 0; j < newPList.size(); j++) {
- wPoint = newPList.get(j);
- sXY = projToScreen(wPoint.X, wPoint.Y, area);
- if (j == 0) {
- path.moveTo(sXY[0], sXY[1]);
- } else {
- path.lineTo(sXY[0], sXY[1]);
- }
- }
- }
- }
- path.closePath();
-
- if (aPGB.isDrawFill()) {
- //int alpha = (int)((1 - (double)transparencyPerc / 100.0) * 255);
- //Color aColor = Color.FromArgb(alpha, aPGB.Color);
- Color aColor = aPGB.getColor();
- if (isSelected) {
- aColor = this.getSelectedColor();
- }
- if (aPGB.isUsingHatchStyle()) {
- int size = aPGB.getStyleSize();
- BufferedImage bi = getHatchImage(aPGB.getStyle(), size, aPGB.getColor(), aPGB.getBackColor());
- Rectangle2D rect = new Rectangle2D.Double(0, 0, size, size);
- g.setPaint(new TexturePaint(bi, rect));
- g.fill(path);
- } else {
- g.setColor(aColor);
- g.fill(path);
- }
- } else if (isSelected) {
- g.setColor(this.getSelectedColor());
- g.fill(path);
- }
-
- if (aPGB.isDrawOutline()) {
- BasicStroke pen = new BasicStroke(aPGB.getOutlineSize());
- g.setStroke(pen);
- g.setColor(aPGB.getOutlineColor());
- g.draw(path);
- }
-
- return rPoints;
- }
-
- private void drawRectangle(Graphics2D g, RectangleShape rs, PolygonBreak aPGB,
- boolean isSelected, Rectangle2D area) {
- Extent extent = rs.getExtent();
- double[] sXY;
- sXY = projToScreen(extent.minX, extent.minY + extent.getHeight(), area);
- double x = sXY[0];
- double y = sXY[1];
- double width = this.projXLength(extent.getWidth(), area);
- double height = this.projYLength(extent.getHeight(), area);
- RectangularShape rshape;
- if (rs.isRound())
- rshape = new RoundRectangle2D.Double(x, y, width, height, width * rs.getRoundX(), height * rs.getRoundY());
- else
- rshape = new Rectangle2D.Double(x, y, width, height);
-
- if (aPGB.isDrawFill()) {
- Color aColor = aPGB.getColor();
- if (isSelected) {
- aColor = this.getSelectedColor();
- }
- if (aPGB.isUsingHatchStyle()) {
- int size = aPGB.getStyleSize();
- BufferedImage bi = getHatchImage(aPGB.getStyle(), size, aPGB.getColor(), aPGB.getBackColor());
- Rectangle2D rect = new Rectangle2D.Double(0, 0, size, size);
- g.setPaint(new TexturePaint(bi, rect));
- g.fill(rshape);
- } else {
- g.setColor(aColor);
- g.fill(rshape);
- }
- } else if (isSelected) {
- g.setColor(this.getSelectedColor());
- g.fill(rshape);
- }
-
- if (aPGB.isDrawOutline()) {
- BasicStroke pen = new BasicStroke(aPGB.getOutlineSize());
- g.setStroke(pen);
- g.setColor(aPGB.getOutlineColor());
- g.draw(rshape);
- }
- }
-
- private void drawArc(Graphics2D g, ArcShape aShape, PolygonBreak aPGB,
- Rectangle2D area, float dist, float ex, Font labelFont, Color labelColor) {
- float startAngle = aShape.getStartAngle();
- float sweepAngle = aShape.getSweepAngle();
- float angle = startAngle + sweepAngle / 2;
- float space = 20;
- Rectangle2D rect = new Rectangle2D.Double(area.getX() + ex + space, area.getY() + ex + space, area.getWidth() - ex - space,
- area.getHeight() - ex - space);
- double dx = 0, dy = 0;
- if (aShape.getExplode() > 0) {
- dx = ex * Math.cos((360 - angle) * Math.PI / 180);
- dy = ex * Math.sin((360 - angle) * Math.PI / 180);
- rect.setRect(rect.getX() + dx, rect.getY() + dy, rect.getWidth(), rect.getHeight());
- }
- float sx = (float) (rect.getX() - area.getX());
- float sy = (float) (rect.getY() - area.getY());
- Draw.drawPie(new PointF(sx, sy), (float) rect.getWidth(), (float) rect.getHeight(),
- startAngle, sweepAngle, aPGB, g);
-
- float x, y, w, h;
- PointF sPoint = new PointF((float) (rect.getWidth() * 0.5 + sx), (float) (rect.getHeight() * 0.5 + sy));
- String label = aPGB.getCaption();
- if (angle > 360) {
- angle = angle - 360;
- }
- float r = (float) (rect.getWidth() * 0.5) + dist;
- PointF lPoint = Draw.getPieLabelPoint(sPoint, r, angle);
- x = lPoint.X;
- y = lPoint.Y;
- Dimension dim = Draw.getStringDimension(label, g);
- h = dim.height;
- w = dim.width;
- if ((angle >= 0 && angle < 45)) {
- //x = x + dis;
- y = y - h;
- } else if (angle >= 45 && angle < 90) {
- //y = y - dis;
- } else if (angle >= 90 && angle < 135) {
- x = x - w;
- //y = y - dis;
- } else if (angle >= 135 && angle < 225) {
- x = x - w - 3;
- y = y + h / 2;
- } else if (angle >= 225 && angle < 270) {
- x = x - w / 2;
- y = y + h;
- } else if (angle >= 270 && angle < 315) {
- //x = x + dis;
- y = y + h;
- } else {
- //x = x + dis;
- y = y + h / 2;
- }
- g.setFont(labelFont);
- g.setColor(labelColor);
- //g.drawOval((int)(x - 3), (int)(y - 3), 6, 6);
- g.drawString(label, x, y);
- }
-
- private void drawArc(Graphics2D g, ArcShape aShape, PolygonBreak aPGB,
- Rectangle2D area) {
- float startAngle = aShape.getStartAngle();
- float sweepAngle = aShape.getSweepAngle();
- Extent extent = aShape.getExtent();
- double[] sXY;
- sXY = projToScreen(extent.minX, extent.minY + extent.getHeight(), area);
- double x = sXY[0];
- double y = sXY[1];
- double width = this.projXLength(extent.getWidth(), area);
- double height = this.projYLength(extent.getHeight(), area);
- Float wedgeWidth = aShape.getWedgeWidth();
- if (wedgeWidth == null) {
- Draw.drawPie(new PointF((float)x, (float)y),
- (float) width, (float) height, startAngle, sweepAngle, aPGB, g);
- } else {
- wedgeWidth = (float)this.projXLength(wedgeWidth, area);
- Draw.drawPie(new PointF((float)x, (float)y),
- (float) width, (float) height, startAngle, sweepAngle, aPGB, wedgeWidth, g);
- }
- }
-
- private void drawBar(Graphics2D g, BarShape bar, BarBreak bb, float width, Rectangle2D area) {
- double[] xy;
- xy = this.projToScreen(0, 0, area);
- float y0 = (float) xy[1];
- width = (float) this.projXLength(width, area);
- xy = projToScreen(bar.getPoint().X, bar.getPoint().Y, area);
- double x = xy[0];
- double y = xy[1];
- float height;
- height = Math.abs((float) (y - y0));
- float yb = y0;
- if (y >= y0) {
- yb += height;
- }
- Draw.drawBar(new PointF((float) x, yb), width, height, bb, g, false, 5);
- }
-
- private int getBarSeriesNum() {
- int n = 0;
- for (Graphic g : this.graphics.getGraphics()) {
- if (g.getGraphicN(0).getShape().getShapeType() == ShapeTypes.Bar) {
- n += 1;
- }
- }
- return n;
- }
-
- private void drawBars(Graphics2D g, GraphicCollection bars, int barIdx, Rectangle2D area) {
- double[] xy;
- xy = this.projToScreen(0, 0, area);
- float y0 = (float) xy[1];
- int len = bars.getNumGraphics();
- PointF[] points = new PointF[len];
- for (int i = 0; i < len; i++) {
- BarShape bs = (BarShape) bars.getGraphicN(i).getShape();
- xy = this.projToScreen(bs.getPoint().X, bs.getPoint().Y, area);
- points[i] = new PointF((float) xy[0], (float) xy[1]);
- }
- float width;
- int barSeriesN = this.getBarSeriesNum();
- BarShape bs1 = (BarShape) bars.getGraphicN(0).getShape();
- if (bs1.isAutoWidth()) {
- if (len > 1) {
- width = (float) ((points[1].X - points[0].X) * this.barsWidth) / barSeriesN;
- } else {
- width = (float) (area.getWidth() / 10) / barSeriesN;
- }
- float height;
- BarBreak bb;
- for (int i = 0; i < len; i++) {
- BarShape bs = (BarShape) bars.getGraphicN(i).getShape();
- bb = (BarBreak) bars.getGraphicN(i).getLegend();
- height = Math.abs((float) (points[i].Y - y0));
- float yBottom = y0;
- if (bs.isDrawBottom()) {
- xy = this.projToScreen(bs.getPoint().X, bs.getBottom(), area);
- yBottom = (float) xy[1];
- }
- float yb = yBottom;
- if (points[i].Y >= y0) {
- yb += height;
- }
- Draw.drawBar(new PointF(points[i].X - width * barSeriesN / 2
- + barIdx * width, yb), width, height, bb, g, false, 5);
- if (bs.isDrawError()) {
- PointF p = (PointF) points[i].clone();
- p.Y -= y0 - yBottom;
- double elen = 6;
- double error = bs.getError();
- error = this.projYLength(error, area);
- double x = p.X - width * barSeriesN / 2
- + barIdx * width + width / 2;
- g.setColor(bb.getErrorColor());
- g.draw(new Line2D.Double(x, p.Y - error, x, p.Y + error));
- g.draw(new Line2D.Double(x - (elen * 0.5), p.Y - error, x + (elen * 0.5), p.Y - error));
- g.draw(new Line2D.Double(x - (elen * 0.5), p.Y + error, x + (elen * 0.5), p.Y + error));
- }
- }
- } else {
- width = (float) this.projXLength(bs1.getWidth(), area);
- float height;
- BarBreak bb;
- for (int i = 0; i < len; i++) {
- BarShape bs = (BarShape) bars.getGraphicN(i).getShape();
- bb = (BarBreak) bars.getGraphicN(i).getLegend();
- height = Math.abs((float) (points[i].Y - y0));
- float yBottom = y0;
- if (bs.isDrawBottom()) {
- xy = this.projToScreen(bs.getPoint().X, bs.getBottom(), area);
- yBottom = (float) xy[1];
- }
- float yb = yBottom;
- if (points[i].Y >= y0) {
- yb += height;
- }
- Draw.drawBar(new PointF(points[i].X, yb), width, height, bb, g, false, 5);
- if (bs.isDrawError()) {
- PointF p = (PointF) points[i].clone();
- p.Y -= y0 - yBottom;
- double elen = 6;
- double error = bs.getError();
- error = this.projYLength(error, area);
- double x = p.X + width / 2;
- g.setColor(bb.getErrorColor());
- g.draw(new Line2D.Double(x, p.Y - error, x, p.Y + error));
- g.draw(new Line2D.Double(x - (elen * 0.5), p.Y - error, x + (elen * 0.5), p.Y - error));
- g.draw(new Line2D.Double(x - (elen * 0.5), p.Y + error, x + (elen * 0.5), p.Y + error));
- }
- }
- }
-
- //Draw baseline
- boolean drawBaseline = true;
- if (drawBaseline) {
- g.setColor(Color.black);
- g.draw(new Line2D.Double(0, y0, area.getWidth(), y0));
- }
- }
-
- private double getBarXInterval(int idx) {
- Graphic gg = this.graphics.get(idx);
- if (gg.getNumGraphics() == 1) {
- if (gg.getGraphicN(0).getShape().getPoints().get(0).X == 0) {
- return 1;
- } else {
- return gg.getGraphicN(0).getShape().getPoints().get(0).X / 10;
- }
- } else {
- return gg.getGraphicN(1).getShape().getPoints().get(0).X
- - gg.getGraphicN(0).getShape().getPoints().get(0).X;
- }
- }
-
- private int getBarIndex() {
- int idx = -1;
- for (int i = 0; i < this.graphics.size(); i++) {
- if (this.graphics.get(i).getGraphicN(0).getShape().getShapeType() == ShapeTypes.Bar) {
- idx = i;
- break;
- }
- }
- return idx;
- }
-
- private int getImageIndex() {
- int idx = -1;
- for (int i = 0; i < this.graphics.size(); i++) {
- if (this.graphics.get(i).getGraphicN(0).getShape().getShapeType() == ShapeTypes.Image) {
- idx = i;
- break;
- }
- }
- return idx;
- }
-
- private void drawImage(Graphics2D g, Graphic igraphic, Rectangle2D area) {
- ImageShape ishape = (ImageShape) igraphic.getShape();
- BufferedImage image = ishape.getImage();
- //double sx = ishape.getPoint().X, sy = ishape.getPoint().Y + image.getHeight();
- Extent extent = ishape.getExtent();
- double sx = extent.minX, sy = extent.maxY;
- double[] xy1 = this.projToScreen(sx, sy, area);
- double ex = extent.maxX, ey = extent.minY;
- //double[] xy2 = this.projToScreen(sx + image.getWidth(), ishape.getPoint().Y, area);
- double[] xy2 = this.projToScreen(ex, ey, area);
- int x = (int) xy1[0];
- int y = (int) xy1[1];
- int width = (int) (xy2[0] - xy1[0]);
- int height = (int) (xy2[1] - xy1[1]);
- g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, ishape.getInterpolation());
- g.drawImage(image, x, y, width, height, null);
- }
-
- @Override
- Extent getAutoExtent() {
- Extent extent = (Extent)this.graphics.getExtent().clone();
- if (extent.minX == extent.maxX) {
- extent.minX = extent.minX - Math.abs(extent.minX);
- extent.maxX = extent.maxX + Math.abs(extent.minX);
- }
- if (extent.minY == extent.maxY) {
- extent.minY = extent.minY - Math.abs(extent.minY);
- extent.maxY = extent.maxY + Math.abs(extent.maxY);
- }
-
- int imageIdx = this.getImageIndex();
- if (imageIdx >= 0){
- return extent;
- }
-
- int barIdx = this.getBarIndex();
- if (barIdx >= 0) {
- double dx = getBarXInterval(barIdx);
- extent.minX -= dx;
- extent.maxX += dx;
- }
- double[] xValues;
- if (this.getXAxis() instanceof TimeAxis) {
- xValues = (double[]) MIMath.getIntervalValues(extent.minX, extent.maxX, false).get(0);
- xValues[0] = extent.minX;
- xValues[xValues.length - 1] = extent.maxX;
- } else if (this.getXAxis() instanceof LogAxis) {
- xValues = (double[]) MIMath.getIntervalValues_Log(extent.minX, extent.maxX);
- } else {
- xValues = (double[]) MIMath.getIntervalValues(extent.minX, extent.maxX, true).get(0);
- }
- double[] yValues;
- if (this.getYAxis() instanceof LogAxis) {
- yValues = (double[]) MIMath.getIntervalValues_Log(extent.minY, extent.maxY);
- } else {
- yValues = (double[]) MIMath.getIntervalValues(extent.minY, extent.maxY, true).get(0);
- }
- if (this.getPlotOrientation() == PlotOrientation.VERTICAL) {
- return new Extent(xValues[0], xValues[xValues.length - 1], yValues[0], yValues[yValues.length - 1]);
- } else {
- return new Extent(yValues[0], yValues[yValues.length - 1], xValues[0], xValues[xValues.length - 1]);
- }
- }
-
- /**
- * Set auto extent
- */
- @Override
- public void setAutoExtent() {
- Extent extent = this.getAutoExtent();
- this.setDrawExtent(extent);
- this.setExtent((Extent) extent.clone());
- }
-
- @Override
- public void updateLegendScheme() {
- if (this.getLegend() == null) {
- this.setLegend(new ChartLegend(this.getLegendScheme()));
- } else {
- this.getLegend().setLegendScheme(this.getLegendScheme());
- }
- }
-
- @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 legend scheme
- *
- * @return Legend scheme
- */
- public LegendScheme getLegendScheme() {
- LegendScheme ls = null;
- int n = this.graphics.getNumGraphics();
- for (int i = n - 1; i >= 0; i--) {
- Graphic g = this.graphics.getGraphicN(i);
- if (g instanceof ImageGraphic) {
- ls = ((ImageGraphic)g).getLegendScheme();
- } else if (g instanceof GraphicCollection) {
- ls = ((GraphicCollection)g).getLegendScheme();
- }
- }
-
- if (ls == null) {
- ShapeTypes stype = ShapeTypes.Polyline;
- ls = new LegendScheme(stype);
- for (Graphic g : this.graphics.getGraphics()) {
- ls.getLegendBreaks().add(g.getLegend());
- }
- }
- return ls;
- }
- //
-
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/Plot3D.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/Plot3D.java
deleted file mode 100644
index c3d3dc9c..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/Plot3D.java
+++ /dev/null
@@ -1,2375 +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 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.Point;
-import java.awt.Rectangle;
-import java.awt.RenderingHints;
-import java.awt.TexturePaint;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
-import java.util.ArrayList;
-import java.util.List;
-import org.meteoinfo.chart.ChartLegend;
-import org.meteoinfo.chart.ChartText;
-import org.meteoinfo.chart.ChartText3D;
-import org.meteoinfo.chart.LegendPosition;
-import org.meteoinfo.chart.Margin;
-import org.meteoinfo.chart.axis.Axis;
-import org.meteoinfo.chart.axis.LogAxis;
-import org.meteoinfo.chart.plot3d.GraphicCollection3D;
-import org.meteoinfo.chart.plot3d.Projector;
-import org.meteoinfo.common.*;
-import org.meteoinfo.data.DataMath;
-import org.meteoinfo.data.Dataset;
-import org.meteoinfo.drawing.Draw;
-import org.meteoinfo.geometry.graphic.Graphic;
-import org.meteoinfo.geometry.graphic.GraphicCollection;
-import org.meteoinfo.geometry.legend.*;
-import org.meteoinfo.math.sort.QuickSort;
-import org.meteoinfo.geometry.shape.*;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class Plot3D extends Plot {
-
- //
- private final GraphicCollection3D graphics;
- private Extent3D extent;
- private ChartText title;
- private List legends;
- private Axis xAxis;
- private Axis yAxis;
- private Axis zAxis;
- private GridLine gridLine;
-
- private final Projector projector; // the projector, controls the point of view
- private int prevwidth, prevheight; // canvas size
- private Rectangle graphBounds; //Graphic area bounds
-
- private boolean isBoxed, isMesh, isScaleBox, isDisplayXY, isDisplayZ,
- drawBoundingBox, drawBase;
- private boolean hideOnDrag;
- private float xmin, xmax, ymin;
- private float ymax, zmin, zmax;
-
- private Color boxColor = Color.getHSBColor(0f, 0f, 0.95f);
- //private Color lineboxColor = Color.getHSBColor(0f, 0f, 0.8f);
-
- // Projection parameters
- private int factor_x, factor_y; // conversion factors
- private int t_x, t_y, t_z; // determines ticks density
- //private final int poly_x[] = new int[9];
- //private final int poly_y[] = new int[9];
- private Point projection;
- float xfactor;
- float yfactor;
- float zfactor;
-
- //
- //
- /**
- * Constructor
- */
- public Plot3D() {
- this.legends = new ArrayList<>();
- this.xAxis = new Axis();
- this.xAxis.setLabel("X");
- this.xAxis.setTickLength(8);
- this.yAxis = new Axis();
- this.yAxis.setLabel("Y");
- this.yAxis.setTickLength(8);
- this.zAxis = new Axis();
- this.zAxis.setLabel("Z");
- this.zAxis.setTickLength(8);
- projector = new Projector();
- projector.setDistance(10000);
- projector.set2DScaling(15);
- projector.setRotationAngle(225);
- projector.setElevationAngle(30);
- this.graphics = new GraphicCollection3D();
- this.hideOnDrag = false;
- this.isBoxed = true;
- this.gridLine = new GridLine();
- //this.displayGrids = true;
- this.isDisplayXY = true;
- this.isDisplayZ = true;
- this.drawBoundingBox = false;
- this.drawBase = true;
- }
-
- //
- //
- /**
- * Get graphics
- * @return The graphics
- */
- public GraphicCollection3D getGraphics() {
- return this.graphics;
- }
-
- /**
- * Get the number of graphics
- * @return The number of graphics
- */
- public int getGraphicNumber() {
- return this.graphics.size();
- }
-
- /**
- * Get projector
- *
- * @return The Projector
- */
- public Projector getProjector() {
- return this.projector;
- }
-
- /**
- * Get title
- *
- * @return Title
- */
- public ChartText getTitle() {
- return this.title;
- }
-
- /**
- * Set title
- *
- * @param value Title
- */
- public void setTitle(ChartText value) {
- this.title = value;
- }
-
- /**
- * Set title
- *
- * @param text Title text
- */
- public void setTitle(String text) {
- if (this.title == null) {
- this.title = new ChartText(text);
- } else {
- this.title.setText(text);
- }
- }
-
- /**
- * Get legends
- *
- * @return Legends
- */
- public List getLegends() {
- return this.legends;
- }
-
- /**
- * Get chart legend
- *
- * @param idx Index
- * @return Chart legend
- */
- public ChartLegend getLegend(int idx) {
- if (this.legends.isEmpty()) {
- return null;
- } else {
- return this.legends.get(idx);
- }
- }
-
- /**
- * Get chart legend
- *
- * @return Chart legend
- */
- public ChartLegend getLegend() {
- if (this.legends.isEmpty()) {
- return null;
- } else {
- return this.legends.get(this.legends.size() - 1);
- }
- }
-
- /**
- * Set chart legend
- *
- * @param value Legend
- */
- public void setLegend(ChartLegend value) {
- this.legends.clear();
- this.legends.add(value);
- }
-
- /**
- * Set legends
- *
- * @param value Legends
- */
- public void setLegends(List value) {
- this.legends = value;
- }
-
- /**
- * Get x axis
- *
- * @return X axis
- */
- public Axis getXAxis() {
- return this.xAxis;
- }
-
- /**
- * Set x axis
- * @param value X axis
- */
- public void setXAxis(Axis value) {
- this.xAxis = value;
- }
-
- /**
- * Get y axis
- *
- * @return Y axis
- */
- public Axis getYAxis() {
- return this.yAxis;
- }
-
- /**
- * Set y axis
- * @param value Y axis
- */
- public void setYAxis(Axis value) { this.yAxis = value; }
-
- /**
- * Get z axis
- * @return Z axis
- */
- public Axis getZAxis() {
- return this.zAxis;
- }
-
- /**
- * Set z axis
- * @param value Z axis
- */
- public void setZAxis(Axis value) {
- this.zAxis = value;
- }
-
- /**
- * Get x minimum
- * @return X minimum
- */
- public float getXMin(){
- return this.xmin;
- }
-
- /**
- * Set minimum x
- *
- * @param value Minimum x
- */
- public void setXMin(float value) {
- this.xmin = value;
- updateExtent();
- this.xAxis.setMinMaxValue(xmin, xmax);
- }
-
- /**
- * Get x maximum
- * @return X maximum
- */
- public float getXMax() {
- return this.xmax;
- }
-
- /**
- * Set maximum x
- *
- * @param value Maximum x
- */
- public void setXMax(float value) {
- this.xmax = value;
- updateExtent();
- this.xAxis.setMinMaxValue(xmin, xmax);
- }
-
- /**
- * Set x minimum and maximum values
- *
- * @param min Minimum value
- * @param max Maximum value
- */
- public void setXMinMax(float min, float max) {
- this.xmin = min;
- this.xmax = max;
- updateExtent();
- this.xAxis.setMinMaxValue(min, max);
- }
-
- /**
- * Get y minimum
- * @return Y minimum
- */
- public float getYMin(){
- return this.ymin;
- }
-
- /**
- * Set minimum y
- *
- * @param value Minimum y
- */
- public void setYMin(float value) {
- this.ymin = value;
- updateExtent();
- this.yAxis.setMinMaxValue(ymin, ymax);
- }
-
- /**
- * Get y maximum
- * @return Y maximum
- */
- public float getYMax() {
- return this.ymax;
- }
-
- /**
- * Set Maximum y
- *
- * @param value Maximum y
- */
- public void setYMax(float value) {
- this.ymax = value;
- updateExtent();
- this.yAxis.setMinMaxValue(ymin, ymax);
- }
-
- /**
- * Set y minimum and maximum values
- *
- * @param min Minimum value
- * @param max Maximum value
- */
- public void setYMinMax(float min, float max) {
- this.ymin = min;
- this.ymax = max;
- updateExtent();
- this.yAxis.setMinMaxValue(min, max);
- }
-
- /**
- * Get z minimum
- * @return Z minimum
- */
- public float getZMin(){
- return this.zmin;
- }
-
- /**
- * Set minimum z
- *
- * @param value Minimum z
- */
- public void setZMin(float value) {
- this.zmin = value;
- updateExtent();
- this.zAxis.setMinMaxValue(zmin, zmax);
- }
-
- /**
- * Get z maximum
- * @return Z maximum
- */
- public float getZMax() {
- return this.zmax;
- }
-
- /**
- * Set maximum z
- *
- * @param value Maximum z
- */
- public void setZMax(float value) {
- this.zmax = value;
- updateExtent();
- this.zAxis.setMinMaxValue(zmin, zmax);
- }
-
- /**
- * Set z minimum and maximum values
- *
- * @param min Minimum value
- * @param max Maximum value
- */
- public void setZMinMax(float min, float max) {
- this.zmin = min;
- this.zmax = max;
- updateExtent();
- this.zAxis.setMinMaxValue(min, max);
- }
-
- /**
- * Get grid line
- *
- * @return Grid line
- */
- public GridLine getGridLine() {
- return this.gridLine;
- }
-
- /**
- * Set display X/Y axis or not
- *
- * @param value Boolean
- */
- public void setDisplayXY(boolean value) {
- this.isDisplayXY = value;
- }
-
- /**
- * Set display Z axis or not
- *
- * @param value Boolean
- */
- public void setDisplayZ(boolean value) {
- this.isDisplayZ = value;
- }
-
-// /**
-// * Get display grids or not
-// * @return Boolean
-// */
-// public boolean isDisplayGrids() {
-// return this.displayGrids;
-// }
-//
-// /**
-// * Set display grids or not
-// *
-// * @param value Boolean
-// */
-// public void setDisplayGrids(boolean value) {
-// this.displayGrids = value;
-// }
-
- /**
- * Set display box or not
- *
- * @param value Boolean
- */
- public void setBoxed(boolean value) {
- this.isBoxed = value;
- }
-
- /**
- * Set display mesh line or not
- *
- * @param value Boolean
- */
- public void setMesh(boolean value) {
- this.isMesh = value;
- }
-
- /**
- * Get if draw bounding box or not
- *
- * @return Boolean
- */
- public boolean isDrawBoundingBox() {
- return this.drawBoundingBox;
- }
-
- /**
- * Set if draw bounding box or not
- *
- * @param value Boolean
- */
- public void setDrawBoundingBox(boolean value) {
- this.drawBoundingBox = value;
- }
-
- /**
- * Get if draw base area
- * @return Draw base area or not
- */
- public boolean isDrawBase() {
- return this.drawBase;
- }
-
- /**
- * Set if draw base area
- * @param value Draw base area or not
- */
- public void setDrawBase(boolean value) {
- this.drawBase = value;
- }
-
- /**
- * Get extent
- *
- * @return Extent
- */
- public Extent3D getExtent() {
- return this.extent;
- }
-
- /**
- * Set extent
- *
- * @param value Extent
- */
- public void setExtent(Extent3D value) {
- this.extent = value;
- xmin = (float) extent.minX;
- xmax = (float) extent.maxX;
- ymin = (float) extent.minY;
- ymax = (float) extent.maxY;
- zmin = (float) extent.minZ;
- zmax = (float) extent.maxZ;
- xAxis.setMinMaxValue(xmin, xmax);
- yAxis.setMinMaxValue(ymin, ymax);
- zAxis.setMinMaxValue(zmin, zmax);
- if (zAxis instanceof LogAxis)
- this.projector.setZRange((float)Math.log10(zmin), (float)Math.log10(zmax));
- else
- this.projector.setZRange(zmin, zmax);
- }
-
- //
- //
- private void updateExtent() {
- this.extent = new Extent3D(xmin, xmax, ymin, ymax, zmin, zmax);
- }
-
- /**
- * Set axis tick font
- *
- * @param font Font
- */
- public void setAxisTickFont(Font font) {
- this.xAxis.setTickLabelFont(font);
- this.yAxis.setTickLabelFont(font);
- this.zAxis.setTickLabelFont(font);
- }
-
- /**
- * Add a graphic
- *
- * @param g Grahic
- */
- public void addGraphic(Graphic g) {
- this.graphics.add(g);
- Extent ex = this.graphics.getExtent();
- if (!ex.is3D()){
- ex = ex.to3D();
- }
- this.setExtent((Extent3D)ex);
- }
-
- /**
- * Remove a graphic by index
- *
- * @param idx Index
- */
- public void removeGraphic(int idx) {
- this.graphics.remove(idx);
- }
-
- /**
- * Remove last graphic
- */
- public void removeLastGraphic() {
- this.graphics.remove(this.graphics.size() - 1);
- }
-
- /**
- * Set auto extent
- */
- public void setAutoExtent() {
- }
-
- /**
- * Destroys the internal image. It will force SurfaceCanvas to
- * regenerate all images when the paint method is called.
- */
- public void destroyImage() {
- repaint();
- }
-
- private void repaint() {
-
- }
-
- /**
- * Add a legend
- *
- * @param legend The legend
- */
- public void addLegend(ChartLegend legend) {
- this.legends.add(legend);
- }
-
- /**
- * Remove a legend
- *
- * @param legend The legend
- */
- public void removeLegend(ChartLegend legend) {
- this.legends.remove(legend);
- }
-
- /**
- * Remove a legend by index
- *
- * @param idx The legend index
- */
- public void removeLegend(int idx) {
- this.legends.remove(idx);
- }
-
- /**
- * Get outer position area
- *
- * @param area Whole area
- * @return Position area
- */
- @Override
- public Rectangle2D getOuterPositionArea(Rectangle2D area) {
- Rectangle2D rect = this.getOuterPosition();
- double x = area.getWidth() * rect.getX() + area.getX();
- double y = area.getHeight() * (1 - rect.getHeight() - rect.getY()) + area.getY();
- double w = area.getWidth() * rect.getWidth();
- double h = area.getHeight() * rect.getHeight();
- return new Rectangle2D.Double(x, y, w, h);
- }
-
- @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.
- }
-
- @Override
- public PlotType getPlotType() {
- return PlotType.XYZ;
- }
-
- @Override
- public void draw(Graphics2D g2, Rectangle2D area) {
- this.setGraphArea(this.getPositionArea());
-
- //Draw title
- float y = this.drawTitle(g2, this.getGraphArea());
-
- //Set projection area
- Rectangle parea = this.getPositionArea(area).getBounds();
- if ((parea.width != prevwidth) || (parea.height != prevheight)) {
- prevwidth = parea.width;
- prevheight = parea.height;
- }
- projector.setProjectionArea(parea);
-
- if (this.xAxis instanceof LogAxis)
- xfactor = 20f / ((float)Math.log10(xmax) - (float)Math.log10(this.xmin));
- else
- xfactor = 20f / (this.xmax - this.xmin); // 20 aint magic: surface vertex requires a value in [-10 ; 10]
- if (this.yAxis instanceof LogAxis)
- yfactor = 20f / ((float)Math.log10(this.ymax) - (float)Math.log10(this.ymin));
- else
- yfactor = 20f / (this.ymax - this.ymin);
- if (this.zAxis instanceof LogAxis)
- zfactor = 20f / ((float)Math.log10(this.zmax) - (float)Math.log10(this.zmin));
- else
- zfactor = 20f / (this.zmax - this.zmin);
-
- //Get graph bounds
- this.graphBounds = this.projector.getBounds();
-
- //Draw box
- drawBoxGridsTicksLabels(g2);
-
- //Draw graph border polygon
- java.awt.Polygon border = getBorder();
- //g2.setColor(Color.red);
- //g2.draw(border);
-
- //Set graph border polygon clip
- Rectangle oldClip = g2.getClipBounds();
- g2.setClip(border);
-
- //Draw 3D graphics
- drawAllGraphics(g2);
-
- //Cancel the graph border polygon clip
- g2.setClip(oldClip);
-
- //Draw bounding box
- if (this.drawBoundingBox) {
- drawBoundingBox(g2);
- }
-
- //Draw legend
- this.drawLegend(g2, area, this.graphBounds, y);
- }
-
- float drawTitle(Graphics2D g, Rectangle2D graphArea) {
- float y = (float) graphArea.getY();
- if (title != null) {
- float x = (float) (graphArea.getX() + graphArea.getWidth() / 2);
- y -= 8;
- title.draw(g, x, y);
- g.setFont(new Font("Arial", Font.PLAIN, 14));
- }
- return y;
- }
-
- private void drawAllGraphics(Graphics2D g2) {
- for (int m = 0; m < this.graphics.getNumGraphics(); m++) {
- Graphic graphic = this.graphics.get(m);
- if (graphic instanceof GraphicCollection3D && ((GraphicCollection3D) graphic).isFixZ()) {
- this.drawGraphics_FixZ(g2, graphic);
- } else {
- this.drawGrahpics(g2, graphic);
- }
- }
- }
-
- private void drawGrahic(Graphics2D g, Graphic graphic) {
- Shape shape = graphic.getGraphicN(0).getShape();
- switch (shape.getShapeType()) {
- case Point:
- case PointZ:
- this.drawPoint(g, graphic);
- break;
- case TEXT:
- this.drawText((ChartText3D) shape, g);
- break;
- case Polyline:
- case PolylineZ:
- this.drawLineString(g, graphic);
- break;
- case Polygon:
- case PolygonZ:
- this.drawPolygonShape(g, graphic);
- break;
- case WindArraw:
- this.drawWindArrow(g, graphic);
- break;
- case Image:
-
- break;
- }
- }
-
- private void drawGraphics_FixZ(Graphics2D g, Graphic graphic) {
- //Set clip polygon
- float zValue = (float) ((GraphicCollection3D) graphic).getZValue();
- String zdir = ((GraphicCollection3D) graphic).getZDir();
- java.awt.Polygon polygon = new java.awt.Polygon();
- Point p;
- List points = new ArrayList<>();
- switch (zdir) {
- case "x":
- /*zValue = (zValue - this.xmin) * xfactor - 10;
- p = projector.project(zValue, -10, -10);*/
- p = this.project(zValue, this.ymin, this.zmin);
- points.add(p);
- //p = projector.project(zValue, -10, 10);
- p = this.project(zValue, this.ymin, this.zmax);
- points.add(p);
- //p = projector.project(zValue, 10, 10);
- p = this.project(zValue, this.ymax, this.zmax);
- points.add(p);
- //p = projector.project(zValue, 10, -10);
- p = this.project(zValue, this.ymax, this.zmin);
- points.add(p);
- break;
- case "y":
- //zValue = (zValue - this.ymin) * yfactor - 10;
- //p = projector.project(-10, zValue, -10);
- p = this.project(this.xmin, zValue, this.zmin);
- points.add(p);
- //p = projector.project(-10, zValue, 10);
- p = this.project(this.xmin, zValue, this.zmax);
- points.add(p);
- //p = projector.project(10, zValue, 10);
- p = this.project(this.xmax, zValue, this.zmax);
- points.add(p);
- //p = projector.project(10, zValue, -10);
- p = this.project(this.xmax, zValue, this.zmin);
- points.add(p);
- break;
- case "xy":
- List sePoint = ((GraphicCollection3D) graphic).getSEPoint();
- if (sePoint != null && sePoint.size() > 3){
- float sx = sePoint.get(0).floatValue();
- float sy = sePoint.get(1).floatValue();
- float ex = sePoint.get(2).floatValue();
- float ey = sePoint.get(3).floatValue();
- /*sx = (sx - this.xmin) * xfactor - 10;
- ex = (ex - this.xmin) * xfactor - 10;
- sy = (sy - this.ymin) * yfactor - 10;
- ey = (ey - this.ymin) * yfactor - 10;
- p = projector.project(sx, sy, -10);*/
- p = this.project(sx, sy, this.zmin);
- points.add(p);
- //p = projector.project(sx, sy, 10);
- p = this.project(sx, sy, this.zmax);
- points.add(p);
- //p = projector.project(ex, ey, 10);
- p = this.project(ex, ey, this.zmax);
- points.add(p);
- //p = projector.project(ex, ey, -10);
- p = this.project(ex, ey, this.zmin);
- points.add(p);
- }
- break;
- case "z":
- //zValue = (zValue - this.zmin) * zfactor - 10;
- //p = projector.project(-10, -10, zValue);
- p = this.project(this.xmin, this.ymin, zValue);
- points.add(p);
- //p = projector.project(-10, 10, zValue);
- p = this.project(this.xmin, this.ymax, zValue);
- points.add(p);
- //p = projector.project(10, 10, zValue);
- p = this.project(this.xmax, this.ymax, zValue);
- points.add(p);
- //p = projector.project(10, -10, zValue);
- p = this.project(this.xmax, this.ymin, zValue);
- points.add(p);
- break;
- }
- java.awt.Shape oldRegion = g.getClip();
- if (points.size() > 3){
- for (Point pp : points) {
- polygon.addPoint(pp.x, pp.y);
- }
- g.setClip(polygon);
- }
-
- //Draw graphics
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- Graphic gg = graphic.getGraphicN(i);
- if (gg.getShape().getShapeType() == ShapeTypes.Image) {
- //g.setClip(oldRegion);
- this.drawImage(g, gg, zdir, (float) ((GraphicCollection3D) graphic).getZValue());
- } else {
- this.drawGrahic(g, gg);
- }
- }
-
- //Set clip to orgin
- if (points.size() > 3){
- g.setClip(oldRegion);
- }
- }
-
- private void drawGrahpics(Graphics2D g, Graphic graphic) {
- if (graphic.getNumGraphics() == 1) {
- Graphic gg = graphic.getGraphicN(0);
- this.drawGrahic(g, gg);
- } else {
- int n = graphic.getNumGraphics();
- double[] dds = new double[n];
- int[] order = new int[n];
- PointZ p;
- double d;
- float angle = projector.getRotationAngle();
- boolean xdir = true;
- if (angle < 45 || angle > 135 && angle < 225 || angle > 315) {
- xdir = false;
- }
-
- if (xdir) {
- for (int i = 0; i < n; i++) {
- Graphic gg = graphic.getGraphicN(i);
- Shape shape = gg.getShape();
- p = (PointZ) shape.getPoints().get(0);
- d = p.X * projector.getSinRotationAngle();
- dds[i] = d;
- order[i] = i;
- }
- } else {
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- Graphic gg = graphic.getGraphicN(i);
- Shape shape = gg.getShape();
- p = (PointZ) shape.getPoints().get(0);
- d = p.Y * projector.getCosRotationAngle();
- dds[i] = d;
- order[i] = i;
- }
- }
-
- QuickSort.sort(dds, order);
-
- for (int i : order) {
- Graphic gg = graphic.getGraphicN(i);
- this.drawGrahic(g, gg);
- }
- }
- }
-
- private void drawGrahpics_bak(Graphics2D g, Graphic graphic) {
- if (graphic.getNumGraphics() == 1) {
- Graphic gg = graphic.getGraphicN(0);
- this.drawGrahic(g, gg);
- } else {
- List dds = new ArrayList<>();
- List order = new ArrayList<>();
- PointZ p;
- double d;
- boolean isIn;
- float angle = projector.getRotationAngle();
- boolean xdir = true;
- if (angle < 45 || angle > 135 && angle < 225 || angle > 315) {
- xdir = false;
- }
- if (xdir) {
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- Graphic gg = graphic.getGraphicN(i);
- Shape shape = gg.getShape();
- p = (PointZ) shape.getPoints().get(0);
- d = p.X * projector.getSinRotationAngle();
- isIn = false;
- for (int j = 0; j < dds.size(); j++) {
- if (d < dds.get(j)) {
- dds.add(j, d);
- order.add(j, i);
- isIn = true;
- break;
- }
- }
- if (!isIn) {
- dds.add(d);
- order.add(i);
- }
- }
- } else {
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- Graphic gg = graphic.getGraphicN(i);
- Shape shape = gg.getShape();
- p = (PointZ) shape.getPoints().get(0);
- d = p.Y * projector.getCosRotationAngle();
- isIn = false;
- for (int j = 0; j < dds.size(); j++) {
- if (d < dds.get(j)) {
- dds.add(j, d);
- order.add(j, i);
- isIn = true;
- break;
- }
- }
- if (!isIn) {
- dds.add(d);
- order.add(i);
- }
- }
- }
-
- for (int i : order) {
- Graphic gg = graphic.getGraphicN(i);
- this.drawGrahic(g, gg);
- }
- }
- }
-
- private void drawPoints(Graphics2D g, Graphic graphic) {
- if (graphic.getNumGraphics() == 1) {
- Graphic gg = graphic.getGraphicN(0);
- drawPoint(g, gg);
- } else {
- List dds = new ArrayList<>();
- List order = new ArrayList<>();
- PointZ p;
- double d;
- boolean isIn;
- float angle = projector.getRotationAngle();
- boolean xdir = true;
- if (angle < 45 || angle > 135 && angle < 225 || angle > 315) {
- xdir = false;
- }
- if (xdir) {
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- Graphic gg = graphic.getGraphicN(i);
- PointZShape shape = (PointZShape) gg.getShape();
- p = (PointZ) shape.getPoint();
- d = p.X * projector.getSinRotationAngle();
- isIn = false;
- for (int j = 0; j < dds.size(); j++) {
- if (d < dds.get(j)) {
- dds.add(j, d);
- order.add(j, i);
- isIn = true;
- break;
- }
- }
- if (!isIn) {
- dds.add(d);
- order.add(i);
- }
- }
- } else {
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- Graphic gg = graphic.getGraphicN(i);
- PointZShape shape = (PointZShape) gg.getShape();
- p = (PointZ) shape.getPoint();
- d = p.Y * projector.getCosRotationAngle();
- isIn = false;
- for (int j = 0; j < dds.size(); j++) {
- if (d < dds.get(j)) {
- dds.add(j, d);
- order.add(j, i);
- isIn = true;
- break;
- }
- }
- if (!isIn) {
- dds.add(d);
- order.add(i);
- }
- }
- }
-
- for (int i : order) {
- Graphic gg = graphic.getGraphicN(i);
- drawPoint(g, gg);
- }
- }
- }
-
- /**
- * Project 3D point
- *
- * @param x X
- * @param y Y
- * @param z Z
- * @return Projected 2D point
- */
- public Point project(float x, float y, float z) {
- float px, py, pz;
- if (this.xAxis instanceof LogAxis)
- px = (float)(Math.log10(x) - Math.log10(xmin)) * xfactor - 10;
- else
- px = (x - xmin) * xfactor - 10;
- if (this.yAxis instanceof LogAxis)
- py = (float)(Math.log10(y) - Math.log10(ymin)) * yfactor - 10;
- else
- py = (y - ymin) * yfactor - 10;
- if (this.zAxis instanceof LogAxis)
- pz = (float)(Math.log10(z) - Math.log10(zmin)) * zfactor - 10;
- else
- pz = (z - zmin) * zfactor - 10;
- return this.projector.project(px, py, pz);
- }
-
- /**
- * Project 3D point
- *
- * @param x X
- * @param y Y
- * @param z Z
- * @return Projected 2D point
- */
- public Point project_bak(float x, float y, float z) {
- return this.projector.project((x - xmin) * xfactor - 10,
- (y - ymin) * yfactor - 10, (z - zmin) * zfactor - 10);
- }
-
- void drawText(ChartText3D text, Graphics2D g) {
- float x, y;
- Point p = this.project((float) text.getX(), (float) text.getY(), (float) text.getZ());
- x = p.x;
- y = p.y;
- this.drawText(g, text, x, y);
- }
-
- private void drawText(Graphics2D g, ChartText3D text, float x, float y) {
- AffineTransform tempTrans = g.getTransform();
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform)tempTrans.clone();
- myTrans.translate(x, y);
- if (text.getZDir() != null) {
- text.updateAngle(projector);
- float angle = text.getAngle() + 90;
- myTrans.rotate(-angle * Math.PI / 180);
- }
- g.setTransform(myTrans);
- g.setFont(text.getFont());
- g.setColor(text.getColor());
- x = 0;
- y = 0;
- switch (text.getYAlign()) {
- case TOP:
- y += g.getFontMetrics(g.getFont()).getAscent();
- break;
- case CENTER:
- y += g.getFontMetrics(g.getFont()).getAscent() / 2;
- break;
- }
- String s = text.getText();
- Dimension labSize = Draw.getStringDimension(s, g);
- switch (text.getXAlign()) {
- case RIGHT:
- x = x - labSize.width;
- break;
- case CENTER:
- x = x - labSize.width / 2;
- break;
- }
- Draw.drawString(g, s, x, y);
- g.setTransform(tempTrans);
- }
-
- private void drawPoint(Graphics2D g, Graphic graphic) {
- if (extent.intersects(graphic.getExtent())) {
- PointZShape shape = (PointZShape) graphic.getShape();
- PointBreak pb = (PointBreak) graphic.getLegend();
- PointZ p = (PointZ) shape.getPoint();
- /*PointZ pp = new PointZ((p.X - xmin) * xfactor - 10, (p.Y - ymin) * yfactor - 10,
- (p.Z - this.zmin) * zfactor - 10);
- projection = projector.project((float) pp.X, (float) pp.Y, (float) pp.Z);*/
- projection = this.project((float)p.X, (float)p.Y, (float)p.Z);
- PointF pf = new PointF(projection.x, projection.y);
- Draw.drawPoint(pf, pb, g);
- }
- }
-
- private void drawLineStrings(Graphics2D g, Graphic graphic) {
- if (graphic.getNumGraphics() == 1) {
- Graphic gg = graphic.getGraphicN(0);
- drawLineString(g, gg);
- } else {
- List dds = new ArrayList<>();
- List order = new ArrayList<>();
- PointZ p;
- double d;
- boolean isIn;
- float angle = projector.getRotationAngle();
- boolean xdir = true;
- if (angle < 45 || angle > 135 && angle < 225 || angle > 315) {
- xdir = false;
- }
- if (xdir) {
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- Graphic gg = graphic.getGraphicN(i);
- Shape shape = gg.getShape();
- p = (PointZ) shape.getPoints().get(0);
- d = p.X * projector.getSinRotationAngle();
- isIn = false;
- for (int j = 0; j < dds.size(); j++) {
- if (d < dds.get(j)) {
- dds.add(j, d);
- order.add(j, i);
- isIn = true;
- break;
- }
- }
- if (!isIn) {
- dds.add(d);
- order.add(i);
- }
- }
- } else {
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- Graphic gg = graphic.getGraphicN(i);
- Shape shape = gg.getShape();
- p = (PointZ) shape.getPoints().get(0);
- d = p.Y * projector.getCosRotationAngle();
- isIn = false;
- for (int j = 0; j < dds.size(); j++) {
- if (d < dds.get(j)) {
- dds.add(j, d);
- order.add(j, i);
- isIn = true;
- break;
- }
- }
- if (!isIn) {
- dds.add(d);
- order.add(i);
- }
- }
- }
-
- for (int i : order) {
- Graphic gg = graphic.getGraphicN(i);
- drawLineString(g, gg);
- }
- }
- }
-
- private void drawLineString(Graphics2D g, Graphic graphic) {
- if (extent.intersects(graphic.getExtent())) {
- PolylineZShape shape = (PolylineZShape) graphic.getShape();
- ColorBreak pb = graphic.getLegend();
- for (Polyline line : shape.getPolylines()){
- List ps = (List)line.getPointList();
- PointF[] points = new PointF[ps.size()];
- PointZ p, pp;
- for (int i = 0; i < ps.size(); i++) {
- p = ps.get(i);
- projection = this.project((float)p.X, (float)p.Y, (float)p.Z);
- points[i] = new PointF(projection.x, projection.y);
- }
- if (pb.getBreakType() == BreakTypes.ColorBreakCollection)
- Draw.drawPolyline(points, (ColorBreakCollection)pb, g);
- else
- Draw.drawPolyline(points, (PolylineBreak)pb, g);
- }
- }
- }
-
- private void drawPolygons(Graphics2D g, Graphic graphic) {
- List dds = new ArrayList<>();
- List order = new ArrayList<>();
- PointZ p;
- double d;
- boolean isIn;
- float angle = projector.getRotationAngle();
- boolean xdir = true;
- if (angle < 45 || angle > 135 && angle < 225 || angle > 315) {
- xdir = false;
- }
- if (xdir) {
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- Graphic gg = graphic.getGraphicN(i);
- Shape shape = gg.getShape();
- p = (PointZ) shape.getPoints().get(0);
- d = p.X * projector.getSinRotationAngle();
- isIn = false;
- for (int j = 0; j < dds.size(); j++) {
- if (d < dds.get(j)) {
- dds.add(j, d);
- order.add(j, i);
- isIn = true;
- break;
- }
- }
- if (!isIn) {
- dds.add(d);
- order.add(i);
- }
- }
- } else {
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- Graphic gg = graphic.getGraphicN(i);
- Shape shape = gg.getShape();
- p = (PointZ) shape.getPoints().get(0);
- d = p.Y * projector.getCosRotationAngle();
- isIn = false;
- for (int j = 0; j < dds.size(); j++) {
- if (d < dds.get(j)) {
- dds.add(j, d);
- order.add(j, i);
- isIn = true;
- break;
- }
- }
- if (!isIn) {
- dds.add(d);
- order.add(i);
- }
- }
- }
-
- for (int i : order) {
- Graphic gg = graphic.getGraphicN(i);
- this.drawPolygonShape(g, gg);
- }
- }
-
- private void drawPolygonShape(Graphics2D g, Graphic graphic) {
- if (extent.intersects(graphic.getExtent())) {
- PolygonZShape shape = (PolygonZShape) graphic.getShape();
- PolygonBreak pb = (PolygonBreak) graphic.getLegend();
- for (PolygonZ poly : (List) shape.getPolygons()) {
- drawPolygon(g, poly, pb);
- }
- }
- }
-
- private List drawPolygon(Graphics2D g, PolygonZ aPG, PolygonBreak aPGB) {
- int len = aPG.getOutLine().size();
- GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, len);
- PointZ p, pp;
- List rPoints = new ArrayList<>();
- for (int i = 0; i < aPG.getOutLine().size(); i++) {
- p = ((List) aPG.getOutLine()).get(i);
-// pp = new PointZ((p.X - xmin) * xfactor - 10, (p.Y - ymin) * yfactor - 10,
-// (p.Z - this.zmin) * zfactor - 10);
-// projection = projector.project((float) pp.X, (float) pp.Y, (float) pp.Z);
- projection = this.project((float)p.X, (float)p.Y, (float)p.Z);
- if (i == 0) {
- path.moveTo(projection.x, projection.y);
- } else {
- path.lineTo(projection.x, projection.y);
- }
- rPoints.add(new PointF(projection.x, projection.y));
- }
-
- List newPList;
- if (aPG.hasHole()) {
- for (int h = 0; h < aPG.getHoleLines().size(); h++) {
- newPList = (List) aPG.getHoleLines().get(h);
- for (int j = 0; j < newPList.size(); j++) {
- p = newPList.get(j);
-// pp = new PointZ((p.X - xmin) * xfactor - 10, (p.Y - ymin) * yfactor - 10,
-// (p.Z - this.zmin) * zfactor - 10);
-// projection = projector.project((float) pp.X, (float) pp.Y, (float) pp.Z);
- projection = this.project((float)p.X, (float)p.Y, (float)p.Z);
- if (j == 0) {
- path.moveTo(projection.x, projection.y);
- } else {
- path.lineTo(projection.x, projection.y);
- }
- }
- }
- }
- path.closePath();
-
- if (aPGB.isDrawFill()) {
- Color aColor = aPGB.getColor();
- if (aPGB.isUsingHatchStyle()) {
- int size = aPGB.getStyleSize();
- BufferedImage bi = Draw.getHatchImage(aPGB.getStyle(), size, aPGB.getColor(), aPGB.getBackColor());
- Rectangle2D rect = new Rectangle2D.Double(0, 0, size, size);
- g.setPaint(new TexturePaint(bi, rect));
- g.fill(path);
- } else {
- g.setColor(aColor);
- g.fill(path);
- }
- }
-
- if (aPGB.isDrawOutline()) {
- BasicStroke pen = new BasicStroke(aPGB.getOutlineSize());
- g.setStroke(pen);
- g.setColor(aPGB.getOutlineColor());
- g.draw(path);
- }
-
- return rPoints;
- }
-
- private void drawImage(Graphics2D g, Graphic igraphic, String zdir, float zValue) {
- ImageShape ishape = (ImageShape) igraphic.getShape();
- BufferedImage image = ishape.getImage();
- Extent3D ext = (Extent3D) ishape.getExtent();
- Point p1, p2, p3, p4;
- AffineTransform transform = new AffineTransform();
- transform.setToIdentity();
- float minx, miny, maxx, maxy, minz, maxz;
- double angle, xscale, yscale, xtran, ytran;
- switch (zdir) {
- case "x":
- /*zValue = (zValue - this.xmin) * xfactor - 10;
- miny = ((float) ext.minY - ymin) * yfactor - 10;
- maxy = ((float) ext.maxY - ymin) * yfactor - 10;
- minz = ((float) ext.minZ - zmin) * zfactor - 10;
- maxz = ((float) ext.maxZ - zmin) * zfactor - 10;
- p1 = this.projector.project(zValue, miny, maxz);
- p2 = this.projector.project(zValue, maxy, maxz);
- p3 = this.projector.project(zValue, maxy, minz);
- p4 = this.projector.project(zValue, miny, minz);*/
- p1 = this.project(zValue, (float)ext.minY, (float)ext.maxZ);
- p2 = this.project(zValue, (float)ext.maxY, (float)ext.maxZ);
- p3 = this.project(zValue, (float)ext.maxY, (float)ext.minZ);
- p4 = this.project(zValue, (float)ext.minY, (float)ext.minZ);
- xscale = (double) Math.abs(p2.x - p1.x) / image.getWidth();
- yscale = (double) Math.abs(p1.y - p4.y) / image.getHeight();
- xtran = p1.x;
- ytran = p1.y;
- if (p2.x > p1.x) {
- angle = MIMath.cartesianToPolar(p2.x - p1.x, p1.y - p2.y)[0];
- } else {
- angle = MIMath.cartesianToPolar(p1.x - p2.x, p2.y - p1.y)[0];
- xscale = -xscale;
- }
- angle = -angle;
- transform.setTransform(Math.cos(angle), Math.sin(angle), 0, 1, xtran, ytran);
- transform.scale(xscale / Math.cos(angle), yscale);
- break;
- case "y":
- /*zValue = (zValue - this.ymin) * yfactor - 10;
- minx = ((float) ext.minX - xmin) * xfactor - 10;
- maxx = ((float) ext.maxX - xmin) * xfactor - 10;
- minz = ((float) ext.minZ - zmin) * zfactor - 10;
- maxz = ((float) ext.maxZ - zmin) * zfactor - 10;
- p1 = this.projector.project(minx, zValue, maxz);
- p2 = this.projector.project(maxx, zValue, maxz);
- p3 = this.projector.project(maxx, zValue, minz);
- p4 = this.projector.project(minx, zValue, minz);*/
- p1 = this.project((float)ext.minX, zValue, (float)ext.maxZ);
- p2 = this.project((float)ext.maxX, zValue, (float)ext.maxZ);
- p3 = this.project((float)ext.maxX, zValue, (float)ext.minZ);
- p4 = this.project((float)ext.minX, zValue, (float)ext.minZ);
- xscale = (double) Math.abs(p2.x - p1.x) / image.getWidth();
- yscale = (double) Math.abs(p1.y - p4.y) / image.getHeight();
- xtran = p1.x;
- ytran = p1.y;
- if (p2.x > p1.x) {
- angle = MIMath.cartesianToPolar(p2.x - p1.x, p1.y - p2.y)[0];
- } else {
- angle = MIMath.cartesianToPolar(p1.x - p2.x, p2.y - p1.y)[0];
- xscale = -xscale;
- }
- angle = -angle;
- transform.setTransform(Math.cos(angle), Math.sin(angle), 0, 1, xtran, ytran);
- transform.scale(xscale / Math.cos(angle), yscale);
- break;
- case "xy":
- /*miny = ((float) ext.minY - ymin) * yfactor - 10;
- maxy = ((float) ext.maxY - ymin) * yfactor - 10;
- minx = ((float) ext.minX - xmin) * xfactor - 10;
- maxx = ((float) ext.maxX - xmin) * xfactor - 10;
- minz = ((float) ext.minZ - zmin) * zfactor - 10;
- maxz = ((float) ext.maxZ - zmin) * zfactor - 10;
- p1 = this.projector.project(minx, miny, maxz);
- p2 = this.projector.project(maxx, maxy, maxz);
- p3 = this.projector.project(maxx, maxy, minz);
- p4 = this.projector.project(minx, miny, minz);*/
- p1 = this.project((float)ext.minX, (float)ext.minY, (float)ext.maxZ);
- p2 = this.project((float)ext.maxX, (float)ext.maxY, (float)ext.maxZ);
- p3 = this.project((float)ext.maxX, (float)ext.maxY, (float)ext.minZ);
- p4 = this.project((float)ext.minX, (float)ext.minY, (float)ext.minZ);
- xscale = (double) Math.abs(p2.x - p1.x) / image.getWidth();
- yscale = (double) Math.abs(p1.y - p4.y) / image.getHeight();
- xtran = p1.x;
- ytran = p1.y;
- if (p2.x > p1.x) {
- angle = MIMath.cartesianToPolar(p2.x - p1.x, p1.y - p2.y)[0];
- } else {
- angle = MIMath.cartesianToPolar(p1.x - p2.x, p2.y - p1.y)[0];
- xscale = -xscale;
- }
- angle = -angle;
- transform.setTransform(Math.cos(angle), Math.sin(angle), 0, 1, xtran, ytran);
- transform.scale(xscale / Math.cos(angle), yscale);
- break;
- case "z":
- /*zValue = (zValue - this.zmin) * zfactor - 10;
- minx = ((float) ext.minX - xmin) * xfactor - 10;
- maxx = ((float) ext.maxX - xmin) * xfactor - 10;
- miny = ((float) ext.minY - ymin) * yfactor - 10;
- maxy = ((float) ext.maxY - ymin) * yfactor - 10;
- p1 = this.projector.project(minx, maxy, zValue);
- p2 = this.projector.project(maxx, maxy, zValue);
- p3 = this.projector.project(maxx, miny, zValue);
- p4 = this.projector.project(minx, miny, zValue);*/
- p1 = this.project((float)ext.minX, (float)ext.maxY, zValue);
- p2 = this.project((float)ext.maxX, (float)ext.maxY, zValue);
- p3 = this.project((float)ext.maxX, (float)ext.minY, zValue);
- p4 = this.project((float)ext.minX, (float)ext.minY, zValue);
- xscale = (double) Math.abs(p2.x - p1.x) / image.getWidth();
- yscale = (double) Math.abs(p1.y - p4.y) / image.getHeight();
- xtran = p1.x;
- ytran = p1.y;
- angle = MIMath.cartesianToPolar(p2.x - p1.x, p1.y - p2.y)[0];
- double angle_y = MIMath.cartesianToPolar(p4.x - p1.x, p4.y - p1.y)[0];
- if (p2.x < p1.x) {
- xscale = -xscale;
- yscale = -yscale;
- }
- angle = -angle;
- angle_y = Math.PI * 0.5 - angle_y;
- angle_y = -angle_y;
- transform.setTransform(Math.cos(angle), Math.sin(angle), -Math.sin(angle_y), Math.cos(angle_y), xtran, ytran);
- transform.scale(xscale / Math.cos(angle), yscale / Math.cos(angle_y));
- break;
- }
- g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, ishape.getInterpolation());
- g.drawImage(image, transform, null);
- }
-
- private void drawWindArrow(Graphics2D g, Graphic graphic) {
- if (extent.intersects(graphic.getExtent())) {
- WindArrow3D shape = (WindArrow3D) graphic.getShape();
- PointBreak pb = (PointBreak) graphic.getLegend();
- PointZ p = (PointZ) shape.getPoint();
- /*PointZ pp = new PointZ((p.X - xmin) * xfactor - 10, (p.Y - ymin) * yfactor - 10,
- (p.Z - this.zmin) * zfactor - 10);
- projection = projector.project((float) pp.X, (float) pp.Y, (float) pp.Z);*/
- projection = this.project((float)p.X, (float)p.Y, (float)p.Z);
- PointF pf = new PointF(projection.x, projection.y);
- p = (PointZ)shape.getEndPoint();
- /*pp = new PointZ((p.X - xmin) * xfactor - 10, (p.Y - ymin) * yfactor - 10,
- (p.Z - this.zmin) * zfactor - 10);
- projection = projector.project((float) pp.X, (float) pp.Y, (float) pp.Z);*/
- projection = this.project((float)p.X, (float)p.Y, (float)p.Z);
- PointF epf = new PointF(projection.x, projection.y);
- PointF[] points = new PointF[]{pf, epf};
- Draw.drawArrow(points, pb, 4, g);
- }
- }
-
- /**
- * Draws the base plane. The base plane is the x-y plane.
- *
- * @param g the graphics context to draw.
- * @param x used to retrieve x coordinates of drawn plane from this method.
- * @param y used to retrieve y coordinates of drawn plane from this method.
- */
- private void drawBase(Graphics2D g, int[] x, int[] y) {
- Point p = projector.project(-10, -10, -10);
- x[0] = p.x;
- y[0] = p.y;
- p = projector.project(-10, 10, -10);
- x[1] = p.x;
- y[1] = p.y;
- p = projector.project(10, 10, -10);
- x[2] = p.x;
- y[2] = p.y;
- p = projector.project(10, -10, -10);
- x[3] = p.x;
- y[3] = p.y;
- x[4] = x[0];
- y[4] = y[0];
-
- g.setColor(this.boxColor);
- g.fillPolygon(x, y, 4);
-
- g.setColor(this.gridLine.getColor());
- g.setStroke(new BasicStroke(this.gridLine.getSize()));
- g.drawPolygon(x, y, 5);
- }
-
- /**
- * Draws string at the specified coordinates with the specified alignment.
- *
- * @param g graphics context to draw
- * @param x the x coordinate
- * @param y the y coordinate
- * @param s the string to draw
- * @param x_align the alignment in x direction
- * @param y_align the alignment in y direction
- */
- private void outString(Graphics2D g, int x, int y, String s, XAlign x_align, YAlign y_align) {
- switch (y_align) {
- case TOP:
- y += g.getFontMetrics(g.getFont()).getAscent();
- break;
- case CENTER:
- y += g.getFontMetrics(g.getFont()).getAscent() / 2;
- break;
- }
- switch (x_align) {
- case LEFT:
- g.drawString(s, x, y);
- break;
- case RIGHT:
- g.drawString(s, x - g.getFontMetrics(g.getFont()).stringWidth(s), y);
- break;
- case CENTER:
- g.drawString(s, x - g.getFontMetrics(g.getFont()).stringWidth(s) / 2, y);
- break;
- }
- }
-
- private void outString(Graphics2D g, int x, int y, String s, XAlign x_align, YAlign y_align, float angle) {
- AffineTransform tempTrans = g.getTransform();
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform)tempTrans.clone();
- myTrans.translate(x, y);
- myTrans.rotate(-angle * Math.PI / 180);
- g.setTransform(myTrans);
- x = 0; y = 0;
- switch (y_align) {
- case TOP:
- y += g.getFontMetrics(g.getFont()).getAscent();
- break;
- case CENTER:
- y += g.getFontMetrics(g.getFont()).getAscent() / 2;
- break;
- }
- Dimension labSize = Draw.getStringDimension(s, g);
- switch (x_align) {
- case RIGHT:
- x = x - labSize.width;
- break;
- case CENTER:
- x = x - labSize.width / 2;
- break;
- }
- Draw.drawString(g, s, x, y);
- g.setTransform(tempTrans);
- }
-
- private void outString_bak(Graphics2D g, int x, int y, String s, XAlign x_align, YAlign y_align, float angle) {
- switch (y_align) {
- case TOP:
- y += g.getFontMetrics(g.getFont()).getAscent();
- break;
- case CENTER:
- y += g.getFontMetrics(g.getFont()).getAscent() / 2;
- break;
- }
- Dimension labSize = Draw.getStringDimension(s, g);
- switch (x_align) {
- case RIGHT:
- x = x - labSize.width;
- break;
- case CENTER:
- x = x - labSize.width / 2;
- break;
- }
-
- AffineTransform tempTrans = g.getTransform();
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform)tempTrans.clone();
- myTrans.translate(x, y);
- myTrans.rotate(-angle * Math.PI / 180);
- g.setTransform(myTrans);
- x = 0; y = 0;
-// if (angle == 90) {
-// x = -(int) (labSize.getWidth() - 10);
-// y = (int) (labSize.getHeight() / 3);
-// } else {
-// x = -(int) (labSize.getWidth() - 5);
-// y = 0;
-// }
- Draw.drawString(g, s, x, y);
- g.setTransform(tempTrans);
- }
-
- /**
- * Sets the axes scaling factor. Computes the proper axis lengths based on
- * the ratio of variable ranges. The axis lengths will also affect the size
- * of bounding box.
- */
- private void setAxesScale() {
- float scale_x, scale_y, scale_z, divisor;
- int longest;
-
- if (!isScaleBox) {
- projector.setScaling(1);
- t_x = t_y = t_z = 4;
- return;
- }
-
- scale_x = xmax - xmin;
- scale_y = ymax - ymin;
- scale_z = zmax - zmin;
-
- if (scale_x < scale_y) {
- if (scale_y < scale_z) {
- longest = 3;
- divisor = scale_z;
- } else {
- longest = 2;
- divisor = scale_y;
- }
- } else if (scale_x < scale_z) {
- longest = 3;
- divisor = scale_z;
- } else {
- longest = 1;
- divisor = scale_x;
- }
- scale_x /= divisor;
- scale_y /= divisor;
- scale_z /= divisor;
-
- if ((scale_x < 0.2f) || (scale_y < 0.2f) && (scale_z < 0.2f)) {
- switch (longest) {
- case 1:
- if (scale_y < scale_z) {
- scale_y /= scale_z;
- scale_z = 1.0f;
- } else {
- scale_z /= scale_y;
- scale_y = 1.0f;
- }
- break;
- case 2:
- if (scale_x < scale_z) {
- scale_x /= scale_z;
- scale_z = 1.0f;
- } else {
- scale_z /= scale_x;
- scale_x = 1.0f;
- }
- break;
- case 3:
- if (scale_y < scale_x) {
- scale_y /= scale_x;
- scale_x = 1.0f;
- } else {
- scale_x /= scale_y;
- scale_y = 1.0f;
- }
- break;
- }
- }
- if (scale_x < 0.2f) {
- scale_x = 1.0f;
- }
- projector.setXScaling(scale_x);
- if (scale_y < 0.2f) {
- scale_y = 1.0f;
- }
- projector.setYScaling(scale_y);
- if (scale_z < 0.2f) {
- scale_z = 1.0f;
- }
- projector.setZScaling(scale_z);
-
- if (scale_x < 0.5f) {
- t_x = 8;
- } else {
- t_x = 4;
- }
- if (scale_y < 0.5f) {
- t_y = 8;
- } else {
- t_y = 4;
- }
- if (scale_z < 0.5f) {
- t_z = 8;
- } else {
- t_z = 4;
- }
- }
-
- /**
- * Draws float at the specified coordinates with the specified alignment.
- *
- * @param g graphics context to draw
- * @param x the x coordinate
- * @param y the y coordinate
- * @param f the float to draw
- * @param x_align the alignment in x direction
- * @param y_align the alignment in y direction
- */
- private void outFloat(Graphics2D g, int x, int y, float f, XAlign x_align, YAlign y_align) {
- // String s = Float.toString(f);
- String s = format(f);
- outString(g, x, y, s, x_align, y_align);
- }
-
- private String format(float f) {
- return String.format("%.3G", f);
- }
-
- private void drawAxes(Graphics2D g) {
- int x[], y[], i;
- x = new int[5];
- y = new int[5];
- drawBase(g, x, y);
- projection = projector.project(0, 0, -10);
- x[0] = projection.x;
- y[0] = projection.y;
- projection = projector.project(10.5f, 0, -10);
- g.drawLine(x[0], y[0], projection.x, projection.y);
- if (projection.x < x[0]) {
- outString(g, (int) (1.05 * (projection.x - x[0])) + x[0], (int) (1.05 * (projection.y - y[0])) + y[0], "x", XAlign.RIGHT, YAlign.TOP);
- } else {
- outString(g, (int) (1.05 * (projection.x - x[0])) + x[0], (int) (1.05 * (projection.y - y[0])) + y[0], "x", XAlign.LEFT, YAlign.TOP);
- }
- projection = projector.project(0, 11.5f, -10);
- g.drawLine(x[0], y[0], projection.x, projection.y);
- if (projection.x < x[0]) {
- outString(g, (int) (1.05 * (projection.x - x[0])) + x[0], (int) (1.05 * (projection.y - y[0])) + y[0], "y", XAlign.RIGHT, YAlign.TOP);
- } else {
- outString(g, (int) (1.05 * (projection.x - x[0])) + x[0], (int) (1.05 * (projection.y - y[0])) + y[0], "y", XAlign.LEFT, YAlign.TOP);
- }
- projection = projector.project(0, 0, 10.5f);
- g.drawLine(x[0], y[0], projection.x, projection.y);
- outString(g, (int) (1.05 * (projection.x - x[0])) + x[0], (int) (1.05 * (projection.y - y[0])) + y[0], "z", XAlign.CENTER, YAlign.CENTER);
- }
-
- private int getLabelGap(Graphics2D g, List labels, double len) {
- int n = labels.size();
- int nn;
- FontMetrics metrics = g.getFontMetrics();
- nn = (int) (len / metrics.getHeight());
- if (nn == 0) {
- nn = 1;
- }
- return n / nn + 1;
- }
-
- private java.awt.Polygon getBorder() {
- Point p;
- java.awt.Polygon polygon = new java.awt.Polygon();
- float elevation = this.projector.getElevationAngle();
- float rotation = this.projector.getRotationAngle();
- if (elevation == 0 && ((rotation > 90 && rotation < 180) || (rotation > 270 && rotation < 360))) {
- Rectangle rect = this.projector.getBounds();
- polygon.addPoint(rect.x, rect.y);
- polygon.addPoint(rect.x, rect.y + rect.height);
- polygon.addPoint(rect.x + rect.width, rect.y + rect.height);
- polygon.addPoint(rect.x + rect.width, rect.y);
- } else {
- p = projector.project(factor_x * 10, -factor_y * 10, -10);
- polygon.addPoint(p.x, p.y);
- p = projector.project(factor_x * 10, -factor_y * 10, 10);
- polygon.addPoint(p.x, p.y);
- p = projector.project(-factor_x * 10, -factor_y * 10, 10);
- polygon.addPoint(p.x, p.y);
- p = projector.project(-factor_x * 10, factor_y * 10, 10);
- polygon.addPoint(p.x, p.y);
- p = projector.project(-factor_x * 10, factor_y * 10, -10);
- polygon.addPoint(p.x, p.y);
- p = projector.project(factor_x * 10, factor_y * 10, -10);
- polygon.addPoint(p.x, p.y);
- }
-
- return polygon;
- }
-
- /**
- * Draws bounding box, axis grids, axis ticks, axis labels, base plane.
- *
- * @param g the graphics context to draw
- */
- private void drawBoxGridsTicksLabels(Graphics2D g) {
- Point tickpos;
- boolean x_left, y_left;
- int x[], y[], i;
-
- x = new int[5];
- y = new int[5];
- if (projector == null) {
- return;
- }
-
- factor_x = factor_y = 1;
- projection = projector.project(0, 0, -10);
- x[0] = projection.x;
- projection = projector.project(10.5f, 0, -10);
- y_left = projection.x > x[0];
- i = projection.y;
- projection = projector.project(-10.5f, 0, -10);
- if (projection.y > i) {
- factor_x = -1;
- y_left = projection.x > x[0];
- }
- projection = projector.project(0, 10.5f, -10);
- x_left = projection.x > x[0];
- i = projection.y;
- projection = projector.project(0, -10.5f, -10);
- if (projection.y > i) {
- factor_y = -1;
- x_left = projection.x > x[0];
- }
- setAxesScale();
-
- //Draw base area
- if (this.drawBase)
- drawBase(g, x, y);
-
- //Draw box
- if (isBoxed) {
- projection = projector.project(-factor_x * 10, -factor_y * 10, -10);
- x[0] = projection.x;
- y[0] = projection.y;
- projection = projector.project(-factor_x * 10, -factor_y * 10, 10);
- x[1] = projection.x;
- y[1] = projection.y;
- projection = projector.project(factor_x * 10, -factor_y * 10, 10);
- x[2] = projection.x;
- y[2] = projection.y;
- projection = projector.project(factor_x * 10, -factor_y * 10, -10);
- x[3] = projection.x;
- y[3] = projection.y;
- x[4] = x[0];
- y[4] = y[0];
-
- g.setColor(this.boxColor);
- g.fillPolygon(x, y, 4);
-
- g.setColor(this.gridLine.getColor());
- g.setStroke(new BasicStroke(this.gridLine.getSize()));
- g.drawPolygon(x, y, 5);
-
- projection = projector.project(-factor_x * 10, factor_y * 10, 10);
- x[2] = projection.x;
- y[2] = projection.y;
- projection = projector.project(-factor_x * 10, factor_y * 10, -10);
- x[3] = projection.x;
- y[3] = projection.y;
- x[4] = x[0];
- y[4] = y[0];
-
- g.setColor(this.boxColor);
- g.fillPolygon(x, y, 4);
-
- g.setColor(this.gridLine.getColor());
- g.setStroke(new BasicStroke(this.gridLine.getSize()));
- g.drawPolygon(x, y, 5);
- } /*else if (isDisplayZ) {
- projection = projector.project(factor_x * 10, -factor_y * 10, -10);
- x[0] = projection.x;
- y[0] = projection.y;
- projection = projector.project(factor_x * 10, -factor_y * 10, 10);
- g.drawLine(x[0], y[0], projection.x, projection.y);
-
- projection = projector.project(-factor_x * 10, factor_y * 10, -10);
- x[0] = projection.x;
- y[0] = projection.y;
- projection = projector.project(-factor_x * 10, factor_y * 10, 10);
- g.drawLine(x[0], y[0], projection.x, projection.y);
- }*/
-
- //Draw axis
- float v, vi;
- String s;
- double[] value;
- float angle, xangle, yangle, xlen, ylen;
- int skip;
- if (this.isDisplayXY) {
- //Draw x/y axis lines
- //x axis line
- projection = projector.project(-10, factor_y * 10, -10);
- x[0] = projection.x;
- y[0] = projection.y;
- projection = projector.project(10, factor_y * 10, -10);
- g.setColor(this.xAxis.getLineColor());
- g.drawLine(x[0], y[0], projection.x, projection.y);
- if (projection.x > x[0]) {
- value = DataMath.getDSFromUV(projection.x - x[0], projection.y - y[0]);
- } else {
- value = DataMath.getDSFromUV(x[0] - projection.x, y[0] - projection.y);
- }
- xangle = (float) value[0];
- xlen = (float) value[1];
-
- //yaxis line
- projection = projector.project(factor_x * 10, -10, -10);
- x[0] = projection.x;
- y[0] = projection.y;
- projection = projector.project(factor_x * 10, 10, -10);
- g.setColor(this.yAxis.getLineColor());
- g.drawLine(x[0], y[0], projection.x, projection.y);
- if (projection.x > x[0]) {
- value = DataMath.getDSFromUV(projection.x - x[0], projection.y - y[0]);
- } else {
- value = DataMath.getDSFromUV(x[0] - projection.x, y[0] - projection.y);
- }
- yangle = (float) value[0];
- ylen = (float) value[1];
-
- //Draw x ticks
- if (x_left) {
- angle = yangle;
- } else {
- angle = yangle + 180;
- if (angle > 360) {
- angle -= 360;
- }
- }
- g.setFont(this.xAxis.getTickLabelFont());
- this.xAxis.updateTickLabels();
- List tlabs = this.xAxis.getTickLabels();
- skip = getLabelGap(g, tlabs, Math.abs(xlen));
- int strWidth = 0, w;
- for (i = 0; i < this.xAxis.getTickValues().length; i += skip) {
- v = (float) this.xAxis.getTickValues()[i];
- if (i == tlabs.size()) {
- break;
- }
- s = tlabs.get(i).getText();
- if (v < xmin || v > xmax) {
- continue;
- }
- //vi = (v - xmin) * xfactor - 10;
- //tickpos = projector.project(vi, factor_y * 10, -10);
- tickpos = this.project(v, factor_y > 0 ? this.ymax : this.ymin, this.zmin);
- if (this.gridLine.isDrawXLine() && (v != xmin && v != xmax)) {
- //projection = projector.project(vi, -factor_y * 10, -10);
- projection = this.project(v, factor_y < 0 ? this.ymax : this.ymin, this.zmin);
- g.setColor(this.gridLine.getColor());
- g.setStroke(new BasicStroke(this.gridLine.getSize()));
- g.drawLine(projection.x, projection.y, tickpos.x, tickpos.y);
- if (this.isDisplayZ && this.isBoxed) {
- x[0] = projection.x;
- y[0] = projection.y;
- //projection = projector.project(vi, -factor_y * 10, 10);
- projection = this.project(v, factor_y < 0 ? this.ymax : this.ymin, this.zmax);
- g.drawLine(x[0], y[0], projection.x, projection.y);
- }
- }
- //projection = projector.project(vi, factor_y * 10.5f, -10);
- value = DataMath.getEndPoint(tickpos.x, tickpos.y, angle, this.xAxis.getTickLength());
- g.setColor(this.xAxis.getLineColor());
- //g.drawLine(projection.x, projection.y, tickpos.x, tickpos.y);
- g.drawLine(tickpos.x, tickpos.y, (int) value[0], (int) value[1]);
- value = DataMath.getEndPoint(tickpos.x, tickpos.y, angle, this.xAxis.getTickLength() + 5);
- tickpos = new Point((int) value[0], (int) value[1]);
- if (x_left) {
- //outString(g, tickpos.x, tickpos.y, s, XAlign.LEFT, YAlign.TOP);
- Draw.drawString(g, tickpos.x, tickpos.y, s, XAlign.LEFT, YAlign.TOP, true);
- } else {
- //outString(g, tickpos.x, tickpos.y, s, XAlign.RIGHT, YAlign.TOP);
- Draw.drawString(g, tickpos.x, tickpos.y, s, XAlign.RIGHT, YAlign.TOP, true);
- }
- //w = g.getFontMetrics().stringWidth(s);
- w = Draw.getStringDimension(s, g).width;
- if (strWidth < w) {
- strWidth = w;
- }
- }
- String label = this.xAxis.getLabel().getText();
- if (label != null) {
- g.setFont(this.xAxis.getLabelFont());
- g.setColor(this.xAxis.getLabelColor());
- tickpos = projector.project(0, factor_y * 10.f, -10);
- Dimension dim = Draw.getStringDimension(label, g);
- strWidth = (int) Math.abs((strWidth * Math.sin(Math.toRadians(angle))));
- value = DataMath.getEndPoint(tickpos.x, tickpos.y, angle, this.xAxis.getTickLength() + strWidth + dim.height + 5);
- tickpos.x = (int) value[0];
- tickpos.y = (int) value[1];
- if (this.projector.getElevationAngle() < 10) {
- tickpos.y += g.getFontMetrics().getHeight();
- }
- if (x_left) {
- //outString(g, tickpos.x, tickpos.y, label, XAlign.CENTER, YAlign.TOP, xangle + 90);
- Draw.drawString(g, tickpos.x, tickpos.y, label, XAlign.CENTER, YAlign.TOP, xangle + 90, true);
- } else {
- //outString(g, tickpos.x, tickpos.y, label, XAlign.CENTER, YAlign.TOP, xangle + 90);
- Draw.drawString(g, tickpos.x, tickpos.y, label, XAlign.CENTER, YAlign.TOP, xangle + 90, true);
- }
- }
-
- //Draw y ticks
- if (y_left) {
- angle = xangle;
- } else {
- angle = xangle + 180;
- if (angle > 360) {
- angle -= 360;
- }
- }
- g.setFont(this.yAxis.getTickLabelFont());
- this.yAxis.updateTickLabels();
- tlabs = this.yAxis.getTickLabels();
- skip = getLabelGap(g, tlabs, Math.abs(ylen));
- strWidth = 0;
- for (i = 0; i < this.yAxis.getTickValues().length; i += skip) {
- if (i >= tlabs.size())
- break;
-
- v = (float) this.yAxis.getTickValues()[i];
- s = tlabs.get(i).getText();
- if (v < ymin || v > ymax) {
- continue;
- }
- //vi = (v - ymin) * yfactor - 10;
- //tickpos = projector.project(factor_x * 10, vi, -10);
- tickpos = this.project(factor_x > 0 ? this.xmax : this.xmin, v, this.zmin);
- if (this.gridLine.isDrawYLine() && (v != ymin && v != ymax)) {
- //projection = projector.project(-factor_x * 10, vi, -10);
- projection = this.project(factor_x < 0 ? this.xmax : this.xmin, v, this.zmin);
- g.setColor(this.gridLine.getColor());
- g.setStroke(new BasicStroke(this.gridLine.getSize()));
- g.drawLine(projection.x, projection.y, tickpos.x, tickpos.y);
- if (this.isDisplayZ && this.isBoxed) {
- x[0] = projection.x;
- y[0] = projection.y;
- //projection = projector.project(-factor_x * 10, vi, 10);
- projection = this.project(factor_x < 0 ? this.xmax : this.xmin, v, this.zmax);
- g.drawLine(x[0], y[0], projection.x, projection.y);
- }
- }
- value = DataMath.getEndPoint(tickpos.x, tickpos.y, angle, this.xAxis.getTickLength());
- g.setColor(this.yAxis.getLineColor());
- g.drawLine(tickpos.x, tickpos.y, (int) value[0], (int) value[1]);
- value = DataMath.getEndPoint(tickpos.x, tickpos.y, angle, this.xAxis.getTickLength() + 5);
- tickpos = new Point((int) value[0], (int) value[1]);
- if (y_left) {
- //outString(g, tickpos.x, tickpos.y, s, XAlign.LEFT, YAlign.TOP);
- Draw.drawString(g, tickpos.x, tickpos.y, s, XAlign.LEFT, YAlign.TOP, true);
- } else {
- //outString(g, tickpos.x, tickpos.y, s, XAlign.RIGHT, YAlign.TOP);
- Draw.drawString(g, tickpos.x, tickpos.y, s, XAlign.RIGHT, YAlign.TOP, true);
- }
- //w = g.getFontMetrics().stringWidth(s);
- w = Draw.getStringDimension(s, g).width;
- if (strWidth < w) {
- strWidth = w;
- }
- }
- label = this.yAxis.getLabel().getText();
- if (label != null) {
- g.setFont(this.yAxis.getLabelFont());
- g.setColor(this.yAxis.getLabelColor());
- tickpos = projector.project(factor_x * 10.f, 0, -10);
- Dimension dim = Draw.getStringDimension(label, g);
- strWidth = (int) Math.abs((strWidth * Math.sin(Math.toRadians(angle))));
- value = DataMath.getEndPoint(tickpos.x, tickpos.y, angle, this.yAxis.getTickLength() + strWidth + dim.height + 5);
- tickpos.x = (int) value[0];
- tickpos.y = (int) value[1];
- if (this.projector.getElevationAngle() < 10) {
- tickpos.y += g.getFontMetrics().getHeight();
- }
- if (y_left) {
- //outString(g, tickpos.x, tickpos.y, label, XAlign.CENTER, YAlign.TOP, yangle + 90);
- Draw.drawString(g, tickpos.x, tickpos.y, label, XAlign.CENTER, YAlign.TOP, yangle + 90, true);
- } else {
- //outString(g, tickpos.x, tickpos.y, label, XAlign.CENTER, YAlign.TOP, yangle + 90);
- Draw.drawString(g, tickpos.x, tickpos.y, label, XAlign.CENTER, YAlign.TOP, yangle + 90, true);
- }
- }
- }
-
- //Draw z axis
- if (this.isDisplayZ) {
- float lf = 1;
- if (y_left) {
- lf = -1;
- }
- projection = projector.project(factor_x * 10 * lf, -factor_y * 10 * lf, -10);
- x[0] = projection.x;
- y[0] = projection.y;
- projection = projector.project(factor_x * 10 * lf, -factor_y * 10 * lf, 10);
- g.setFont(this.zAxis.getTickLabelFont());
- g.setColor(this.zAxis.getLineColor());
- g.drawLine(x[0], y[0], projection.x, projection.y);
- this.zAxis.updateTickLabels();
- List tlabs = this.zAxis.getTickLabels();
- int len = Math.abs(y[0] - projection.y);
- skip = getLabelGap(g, tlabs, len);
- int strWidth = 0, w;
- for (i = 0; i < this.zAxis.getTickValues().length; i += skip) {
- v = (float) this.zAxis.getTickValues()[i];
- s = tlabs.get(i).getText();
- if (v < zmin || v > zmax) {
- continue;
- }
- //vi = (v - zmin) * zfactor - 10;
- //tickpos = projector.project(factor_x * 10 * lf, -factor_y * 10 * lf, vi);
- tickpos = this.project(factor_x * lf > 0 ? this.xmax : this.xmin,
- factor_y * lf < 0 ? this.ymax : this.ymin, v);
- if (this.gridLine.isDrawZLine() && this.isBoxed && (v != zmin && v != zmax)) {
- //projection = projector.project(-factor_x * 10, -factor_y * 10, vi);
- projection = this.project(factor_x < 0 ? this.xmax : this.xmin,
- factor_y < 0 ? this.ymax : this.ymin, v);
- g.setColor(this.gridLine.getColor());
- g.setStroke(new BasicStroke(this.gridLine.getSize()));
- g.drawLine(projection.x, projection.y, tickpos.x, tickpos.y);
- x[0] = projection.x;
- y[0] = projection.y;
- //projection = projector.project(-factor_x * 10 * lf, factor_y * 10 * lf, vi);
- projection = this.project(factor_x * lf < 0 ? this.xmax : this.xmin,
- factor_y * lf > 0 ? this.ymax : this.ymin, v);
- g.drawLine(x[0], y[0], projection.x, projection.y);
- }
- //projection = projector.project(factor_x * 10.2f * lf, -factor_y * 10.2f * lf, vi);
- g.setColor(this.zAxis.getLineColor());
- //g.drawLine(projection.x, projection.y, tickpos.x, tickpos.y);
- g.drawLine(tickpos.x, tickpos.y, tickpos.x - (int)this.zAxis.getTickLength(), tickpos.y);
- //tickpos = projector.project(factor_x * 10.5f * lf, -factor_y * 10.5f * lf, vi);
- //outString(g, tickpos.x - this.zAxis.getTickLength() - 5, tickpos.y, s, XAlign.RIGHT, YAlign.CENTER);
- Draw.drawString(g, tickpos.x - this.zAxis.getTickLength() - 5, tickpos.y, s, XAlign.RIGHT, YAlign.CENTER, true);
- w = g.getFontMetrics().stringWidth(s);
- if (strWidth < w) {
- strWidth = w;
- }
- }
- String label = this.zAxis.getLabel().getText();
- if (label != null) {
- tickpos = projector.project(factor_x * 10 * lf, -factor_y * 10 * lf, 0);
- tickpos.x = tickpos.x - (int)this.xAxis.getTickLength() - 15 - strWidth;
- g.setFont(this.zAxis.getLabelFont());
- g.setColor(this.zAxis.getLabelColor());
- //Draw.drawLabelPoint_270(tickpos.x, tickpos.y, this.zAxis.getLabelFont(), label,
- // this.zAxis.getLabelColor(), g, null, this.zAxis.getLabel().isUseExternalFont());
- Draw.drawString(g, tickpos.x, tickpos.y, label, XAlign.CENTER, YAlign.BOTTOM, 90,
- this.zAxis.getLabel().isUseExternalFont());
- }
- }
- }
-
- /**
- * Draws the bounding box of surface.
- */
- private void drawBoundingBox(Graphics2D g2) {
- Point startingpoint;
-
- startingpoint = projector.project(factor_x * 10, factor_y * 10, 10);
- g2.setColor(this.gridLine.getColor());
- g2.setStroke(new BasicStroke(this.gridLine.getSize()));
- projection = projector.project(-factor_x * 10, factor_y * 10, 10);
- g2.drawLine(startingpoint.x, startingpoint.y, projection.x, projection.y);
- projection = projector.project(factor_x * 10, -factor_y * 10, 10);
- g2.drawLine(startingpoint.x, startingpoint.y, projection.x, projection.y);
- projection = projector.project(factor_x * 10, factor_y * 10, -10);
- g2.drawLine(startingpoint.x, startingpoint.y, projection.x, projection.y);
- }
-
- /**
- * Get tight inset area
- *
- * @param g Graphics2D
- * @param positionArea Position area
- * @return Tight inset area
- */
- @Override
- public Margin getTightInset(Graphics2D g, Rectangle2D positionArea) {
- int left = 2, bottom = 2, right = 2, top = 5;
- int space = 2;
-
- if (this.title != null) {
- top += this.title.getTrueDimension(g).height + 10;
- }
-
- if (!this.legends.isEmpty()) {
- ChartLegend legend = this.getLegend();
- Dimension dim = legend.getLegendDimension(g, new Dimension((int) positionArea.getWidth(),
- (int) positionArea.getHeight()));
- switch (legend.getPosition()) {
- case UPPER_CENTER_OUTSIDE:
- top += dim.height + 10;
- break;
- case LOWER_CENTER_OUTSIDE:
- bottom += dim.height + legend.getYShift() + 10;
- break;
- case LEFT_OUTSIDE:
- left += dim.width + 10;
- break;
- case RIGHT_OUTSIDE:
- right += dim.width + legend.getXShift() + 10;
- break;
- }
- }
-
- //Get x axis space
- //bottom += this.getXAxisHeight(g, space);
- //Get y axis space
- //left += this.getYAxisWidth(g, space);
- //Set right space
-// if (this.getXAxis().isVisible()) {
-// if (this.getXAxis().isDrawTickLabel()) {
-// right += this.getXAxis().getMaxLabelLength(g) / 2;
-// }
-// }
- return new Margin(left, right, top, bottom);
- }
-
- void drawLegend(Graphics2D g, Rectangle2D area, Rectangle2D graphArea, float y) {
- if (!this.legends.isEmpty()) {
- Object rendering = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- for (ChartLegend legend : this.legends) {
- if (legend.isColorbar()) {
- if (legend.getPlotOrientation() == PlotOrientation.VERTICAL) {
- legend.setHeight((int) (graphArea.getHeight() * legend.getShrink()));
- } else {
- legend.setWidth((int) (graphArea.getWidth() * legend.getShrink()));
- }
- }
- if (legend.getPosition() == LegendPosition.CUSTOM) {
- legend.getLegendDimension(g, new Dimension((int) area.getWidth(), (int) area.getHeight()));
- float x = (float) (area.getWidth() * legend.getX());
- y = (float) (area.getHeight() * (1 - (this.getLegend().getHeight() / area.getHeight())
- - this.getLegend().getY()));
- legend.draw(g, new PointF(x, y));
- } else {
- this.drawLegendScheme(legend, g, graphArea, y);
- }
- }
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, rendering);
- }
- }
-
- void drawLegendScheme(ChartLegend legend, Graphics2D g, Rectangle2D area, float y) {
- g.setStroke(new BasicStroke(1));
- g.setFont(legend.getTickLabelFont());
- Dimension dim = legend.getLegendDimension(g, new Dimension((int) area.getWidth(), (int) area.getHeight()));
- float x = 0;
- //Rectangle2D graphArea = this.getPositionArea();
- switch (legend.getPosition()) {
- case UPPER_CENTER_OUTSIDE:
- x = (float) (area.getX() + area.getWidth() / 2 - dim.width / 2);
- y += 5;
- break;
- case LOWER_CENTER_OUTSIDE:
- x = (float) (area.getX() + area.getWidth() / 2 - dim.width / 2);
- y = (float) (area.getY() + area.getHeight() + 10);
- break;
- case LEFT_OUTSIDE:
- x = 10;
- y = (float) area.getHeight() / 2 - dim.height / 2;
- break;
- case RIGHT_OUTSIDE:
- x = (float) area.getX() + (float) area.getWidth() + 10 + 40;
- y = (float) area.getY() + (float) area.getHeight() / 2 - dim.height / 2;
- break;
- case UPPER_CENTER:
- x = (float) (area.getX() + area.getWidth() / 2 - dim.width / 2);
- y = (float) area.getY() + 10;
- break;
- case UPPER_RIGHT:
- x = (float) (area.getX() + area.getWidth()) - dim.width - 10;
- y = (float) area.getY() + 10;
- break;
- case LOWER_CENTER:
- x = (float) (area.getX() + area.getWidth() / 2 - dim.width / 2);
- y = (float) (area.getY() + area.getHeight()) - dim.height - 10;
- break;
- case LOWER_RIGHT:
- x = (float) (area.getX() + area.getWidth()) - dim.width - 10;
- y = (float) (area.getY() + area.getHeight()) - dim.height - 10;
- break;
- case UPPER_LEFT:
- x = (float) area.getX() + 10;
- y = (float) area.getY() + 10;
- break;
- case LOWER_LEFT:
- x = (float) area.getX() + 10;
- y = (float) (area.getY() + area.getHeight()) - dim.height - 10;
- break;
- }
- legend.draw(g, new PointF(x, y));
- }
-
- /**
- * Get legend scheme
- *
- * @return Legend scheme
- */
- public LegendScheme getLegendScheme() {
- LegendScheme ls = null;
- int n = this.graphics.getNumGraphics();
- for (int i = n - 1; i >= 0; i--) {
- Graphic g = this.graphics.getGraphicN(i);
- if (g instanceof GraphicCollection) {
- ls = ((GraphicCollection)g).getLegendScheme();
- break;
- }
- }
-
- if (ls == null) {
- ShapeTypes stype = ShapeTypes.Polyline;
- ls = new LegendScheme(stype);
- for (Graphic g : this.graphics.getGraphics()) {
- ls.getLegendBreaks().add(g.getLegend());
- }
- }
- return ls;
- }
-
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/PlotOrientation.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/PlotOrientation.java
deleted file mode 100644
index 8dfd68a4..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/PlotOrientation.java
+++ /dev/null
@@ -1,15 +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;
-
-/**
- *
- * @author wyq
- */
-public enum PlotOrientation {
- VERTICAL,
- HORIZONTAL
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/PlotSeries.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/PlotSeries.java
deleted file mode 100644
index 26aad6c7..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/PlotSeries.java
+++ /dev/null
@@ -1,65 +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.data.XYSeriesData;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class PlotSeries {
- //
- private XYSeriesData data;
- private SeriesLegend legend;
- //
- //
- /**
- * Construtor
- * @param data Series data
- * @param legend Series legend
- */
- public PlotSeries(XYSeriesData data, SeriesLegend legend){
- this.data = data;
- this.legend = legend;
- }
- //
- //
- /**
- * Get series data
- * @return Series data
- */
- public XYSeriesData getData(){
- return this.data;
- }
-
- /**
- * Set series data
- * @param value Series data
- */
- public void setData(XYSeriesData value){
- this.data = value;
- }
-
- /**
- * Get series legend
- * @return Series legend
- */
- public SeriesLegend getLegend(){
- return this.legend;
- }
-
- /**
- * Set series legend
- * @param value Series legend
- */
- public void setLegend(SeriesLegend value){
- this.legend = value;
- }
- //
- //
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/PlotType.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/PlotType.java
deleted file mode 100644
index 63ce41a0..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/PlotType.java
+++ /dev/null
@@ -1,17 +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;
-
-/**
- *
- * @author yaqiang
- */
-public enum PlotType {
- XY,
- CATEGORY,
- XY2D,
- XYZ
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/PolarPlot.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/PolarPlot.java
deleted file mode 100644
index db616afb..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/PolarPlot.java
+++ /dev/null
@@ -1,838 +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 java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.Line2D;
-import java.awt.geom.Rectangle2D;
-import java.util.ArrayList;
-import java.util.List;
-import org.meteoinfo.chart.Margin;
-import org.meteoinfo.common.*;
-import org.meteoinfo.drawing.Draw;
-import static org.meteoinfo.drawing.Draw.getDashPattern;
-
-import org.meteoinfo.geometry.legend.LineStyles;
-import org.meteoinfo.geometry.graphic.Graphic;
-import org.meteoinfo.geometry.graphic.GraphicCollection;
-import org.meteoinfo.ndarray.util.BigDecimalUtil;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class PolarPlot extends Plot2D {
-
- //
- private double radius;
- private double bottom = 0;
- private Font xTickFont = new Font("Arial", Font.PLAIN, 12);
- private Font yTickFont = new Font("Aria", Font.PLAIN, 12);
- private Color xTickColor = Color.black;
- private Color yTickColor = Color.black;
- private List xTickLocations;
- private List xTickLabels;
- private boolean yTickAuto = true;
- private List yTickLocations;
- private List yTickLabels;
- private float yTickLabelPos = 22.5f;
- private String yTickFormat = "";
-
- //
- //
- /**
- * Constructor
- */
- public PolarPlot() {
- super();
- this.setAutoAspect(false);
- GridLine gl = this.getGridLine();
- gl.setDrawXLine(true);
- gl.setDrawYLine(true);
- this.xTickLocations = new ArrayList<>();
- this.xTickLabels = new ArrayList<>();
- double angle = 0;
- while (angle < 360) {
- this.xTickLocations.add(angle);
- String label = DataConvert.removeTailingZeros(String.valueOf(angle)) + String.valueOf((char) 186);
- this.xTickLabels.add(label);
- angle += 45;
- }
- }
- //
- //
- /**
- * Get max radius
- * @return Max radius
- */
- public double getRadius() {
- return this.radius;
- }
-
- /**
- * Set max radius
- * @param value Max radius
- */
- public void setRadius(double value){
- this.radius = value + this.bottom;
- super.setDrawExtent(new Extent(-this.radius, this.radius, -this.radius, this.radius));
- }
-
- /**
- * Get radius bottom - calm wind in center circle
- * @return Radius bottom
- */
- public double getBottom() {
- return this.bottom;
- }
-
- /**
- * Set radius bottom
- * @param value Radius bottom
- */
- public void setBottom(double value) {
- this.bottom = value;
- }
-
- /**
- * Get x tick font
- * @return X tick font
- */
- public Font getXTickFont(){
- return this.xTickFont;
- }
-
- /**
- * Set x tick font
- * @param value X tick font
- */
- public void setXTickFont(Font value){
- this.xTickFont = value;
- }
-
- /**
- * Get y tick font
- * @return Y tick font
- */
- public Font getYTickFont(){
- return this.yTickFont;
- }
-
- /**
- * Set y tick font
- * @param value Y tick font
- */
- public void setYTickFont(Font value){
- this.yTickFont = value;
- }
-
- /**
- * Get x tick label color
- * @return X tick label color
- */
- public Color getXTickColor() {return this.xTickColor;}
-
- /**
- * Set x tick label color
- * @param value X tick label color
- */
- public void setXTickColor(Color value) {this.xTickColor = value;}
-
- /**
- * Get y tick label color
- * @return Y tick label color
- */
- public Color getYTickColor() {return this.yTickColor;}
-
- /**
- * Set y tick label color
- * @param value Y tick label color
- */
- public void setYTickColor(Color value) {this.yTickColor = value;}
-
- /**
- * Get x tick locations
- * @return X tick locations
- */
- public List getXTickLocations(){
- return this.xTickLocations;
- }
-
- /**
- * Set x tick locations
- * @param value X tick locations
- */
- public void setXTickLocations(List value){
- this.xTickLocations = new ArrayList<>();
- for (Number v : value)
- this.xTickLocations.add(v.doubleValue());
- if (this.xTickLabels.size() != value.size()) {
- this.xTickLabels = new ArrayList<>();
- String label;
- for (Number v : value) {
- label = DataConvert.removeTailingZeros(String.valueOf(v.floatValue())) + String.valueOf((char) 186);
- this.xTickLabels.add(label);
- }
- }
- }
-
- /**
- * Get x tick labels
- * @return X tick labels
- */
- public List getXTickLabels(){
- return this.xTickLabels;
- }
-
- /**
- * Set x tick labels
- * @param value X tick labels
- */
- public void setXTickLabels(List value){
- this.xTickLabels = value;
- }
-
- /**
- * Get y tick locations
- * @return Y tick locations
- */
- public List getYTickLocations(){
- return this.yTickLocations;
- }
-
- /**
- * Set y tick locations
- * @param value Y tick locations
- */
- public void setYTickLocations(List value){
- this.yTickLocations = new ArrayList<>();
- for (Number v : value)
- this.yTickLocations.add(v.doubleValue());
- this.yTickAuto = false;
- }
-
- /**
- * Get y tick labels
- * @return Y tick labels
- */
- public List getYTickLabels(){
- return this.yTickLabels;
- }
-
- /**
- * Set y tick labels
- * @param value Y tick labels
- */
- public void setYTickLabels(List value){
- this.yTickLabels = value;
- this.yTickAuto = false;
- }
-
- /**
- * Get y tick label position
- * @return Y tick label position
- */
- public float getYTickLabelPos(){
- return this.yTickLabelPos;
- }
-
- /**
- * Set y tick label position
- * @param value Y tick label position
- */
- public void setYTickLabelPos(float value){
- this.yTickLabelPos = value;
- }
-
- /**
- * Get y tick format
- * @return Y tick format
- */
- public String getYTickFormat(){
- return this.yTickFormat;
- }
-
- /**
- * Set y tick format
- * @param value Y tick format
- */
- public void setYTickFormat(String value){
- this.yTickFormat = value;
- }
- //
- //
- /**
- * Add a graphic
- *
- * @param g Graphic
- */
- @Override
- public void addGraphic(Graphic g) {
- GraphicFactory.polarToCartesian((GraphicCollection) g, this.bottom);
- super.addGraphic(g);
- }
-
- /**
- * Add a graphic by index
- *
- * @param idx Index
- * @param g Graphic
- */
- @Override
- public void addGraphic(int idx, Graphic g) {
- GraphicFactory.polarToCartesian((GraphicCollection) g, this.bottom);
- super.addGraphic(idx, g);
- }
-
- @Override
- Extent getAutoExtent() {
- Extent extent = this.getGraphics().getExtent();
- if (extent.minX == extent.maxX) {
- extent.minX = extent.minX - Math.abs(extent.minX);
- extent.maxX = extent.maxX + Math.abs(extent.minX);
- }
- if (extent.minY == extent.maxY) {
- extent.minY = extent.minY - Math.abs(extent.minY);
- extent.maxY = extent.maxY + Math.abs(extent.maxY);
- }
-
- return extent;
- }
-
- /**
- * Set draw extent
- *
- * @param extent Extent
- */
- @Override
- public void setDrawExtent(Extent extent) {
- double max = Math.abs(extent.minX);
- max = Math.max(max, Math.abs(extent.maxX));
- max = Math.max(max, Math.abs(extent.minY));
- max = Math.max(max, Math.abs(extent.maxY));
- double[] values = (double[]) MIMath.getIntervalValues(0, max, true).get(0);
- this.radius = values[values.length - 1] + this.bottom;
- super.setDrawExtent(new Extent(-this.radius, this.radius, -this.radius, this.radius));
- }
-
- /**
- * Get tight inset area
- *
- * @param g Graphics2D
- * @param positionArea Position area
- * @return Tight inset area
- */
- @Override
- public Margin getTightInset(Graphics2D g, Rectangle2D positionArea) {
- int left = 2, bottom = 2, right = 2, top = 5;
-
- if (this.getTitle() != null) {
- top += this.getTitle().getTrueDimension(g).height + 15;
- }
-
- if (!this.getLegends().isEmpty()) {
- Dimension dim = this.getLegend().getLegendDimension(g, new Dimension((int) positionArea.getWidth(),
- (int) positionArea.getHeight()));
- switch (this.getLegend().getPosition()) {
- case UPPER_CENTER_OUTSIDE:
- top += dim.height + 10;
- break;
- case LOWER_CENTER_OUTSIDE:
- bottom += dim.height + 10;
- break;
- case LEFT_OUTSIDE:
- left += dim.width + 10;
- break;
- case RIGHT_OUTSIDE:
- right += dim.width + 10;
- break;
- }
- }
-
- int space = 5;
- if (this.xTickLabels != null && this.xTickLabels.size() > 0) {
- g.setFont(xTickFont);
- Dimension dim = Draw.getStringDimension(this.xTickLabels.get(0), g);
- bottom += dim.height;
- top += dim.height;
- left += dim.width + space;
- right += dim.width + space;
- }
-
- return new Margin(left, right, top, bottom);
- }
-
- /**
- * Get graphic area
- *
- * @param g Graphic2D
- * @param area Whole area
- * @return Graphic area
- */
- @Override
- public Rectangle2D getGraphArea(Graphics2D g, Rectangle2D area) {
- int left = 5, bottom = 5, right = 5, top = 5;
- int space = 10;
-
- if (this.getTitle() != null) {
- top += this.getTitle().getTrueDimension(g).height + 10;
- }
-
- if (!this.getLegends().isEmpty()) {
- Dimension dim = this.getLegend().getLegendDimension(g, new Dimension((int) area.getWidth(), (int) area.getHeight()));
- switch (this.getLegend().getPosition()) {
- case UPPER_CENTER_OUTSIDE:
- top += dim.height + 10;
- break;
- case LOWER_CENTER_OUTSIDE:
- bottom += dim.height + 10;
- break;
- case LEFT_OUTSIDE:
- left += dim.width + 10;
- break;
- case RIGHT_OUTSIDE:
- right += dim.width + 10;
- break;
- }
- }
-
- //Get x axis space
- bottom += space;
- left += space;
- top += space;
- right += space;
-
- //Set area
- Rectangle2D plotArea = new Rectangle2D.Double(left, top,
- area.getWidth() - left - right, area.getHeight() - top - bottom);
- return plotArea;
- }
-
- /**
- * Draw plot
- *
- * @param g Graphics2D
- * @param area Drawing area
- */
- @Override
- public void draw(Graphics2D g, Rectangle2D area) {
- // if the plot area is too small, just return...
- boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
- boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
- if (b1 || b2) {
- return;
- }
-
- Rectangle2D graphArea;
- graphArea = this.getPositionArea();
- this.setGraphArea(graphArea);
-
- //Draw title
- this.drawTitle(g, graphArea);
-
- if (graphArea.getWidth() < 10 || graphArea.getHeight() < 10) {
- return;
- }
-
- //Draw background
- if (this.background != null) {
- g.setColor(this.getBackground());
- //g.fill(graphArea);
- Ellipse2D ellipse=new Ellipse2D.Double();
- ellipse.setFrame(graphArea);
- g.fill(ellipse);
- }
-
- if (this.getGridLine().isTop()){
- //Draw graph
- this.drawGraph(g, graphArea);
- //Draw grid line
- this.drawGridLine(g, graphArea);
- } else {
- //Draw grid line
- this.drawGridLine(g, graphArea);
- //Draw graph
- this.drawGraph(g, graphArea);
- }
- this.drawGridLabel(g, graphArea);
-
- //Draw border circle
- this.drawBorder(g, graphArea);
-
- //Draw neat line
- if (this.isDrawNeatLine()) {
- g.setStroke(new BasicStroke(1.0f));
- g.setColor(Color.black);
- g.draw(graphArea);
- }
-
- //Draw text
- this.drawText(g, graphArea);
-
- //Draw legend
- this.drawLegend(g, area, graphArea);
-
- }
-
- @Override
- int getTopAxisHeight(Graphics2D g) {
- g.setFont(xTickFont);
- int height = Draw.getStringDimension("tick", g).height + 5;
- return height;
- }
-
- @Override
- void drawGraph(Graphics2D g, Rectangle2D area) {
- super.drawGraph(g, area);
- }
-
- @Override
- void drawGridLine(Graphics2D g, Rectangle2D area) {
- GridLine gridLine = this.getGridLine();
- if (!gridLine.isDrawXLine() && !gridLine.isDrawYLine()) {
- return;
- }
-
- double[] xy;
- double x, y;
- double miny = area.getY();
- double minx = area.getX();
-
- if (gridLine.getStyle() == LineStyles.SOLID) {
- g.setStroke(new BasicStroke(gridLine.getSize()));
- } else {
- float[] dashPattern = getDashPattern(gridLine.getStyle());
- g.setStroke(new BasicStroke(gridLine.getSize(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
- 10.0f, dashPattern, 0.0f));
- }
-
- xy = this.projToScreen(0, 0, area);
- double x0 = xy[0] + minx;
- double y0 = xy[1] + miny;
- //Draw straight grid lines
- if (gridLine.isDrawXLine()) {
- g.setFont(this.xTickFont);
- float shift = 5;
- for (int i = 0; i < this.xTickLocations.size(); i++) {
- double angle = this.xTickLocations.get(i);
- if (bottom != 0) {
- xy = MIMath.polarToCartesian(Math.toRadians(angle), bottom);
- xy = this.projToScreen(xy[0], xy[1], area);
- x0 = xy[0] + minx;
- y0 = xy[1] + miny;
- }
- xy = MIMath.polarToCartesian(Math.toRadians(angle), this.radius);
- xy = this.projToScreen(xy[0], xy[1], area);
- x = xy[0] + minx;
- y = xy[1] + miny;
- g.setColor(gridLine.getColor());
- g.draw(new Line2D.Double(x0, y0, x, y));
-// //Draw x tick label
-// String label = this.xTickLabels.get(i);
-// Dimension dim = Draw.getStringDimension(label, g);
-// float w = dim.width;
-// float h = dim.height;
-// if (angle == 0 || angle == 180){
-// y = y + h * 0.5;
-// if (angle == 0)
-// x += shift;
-// else {
-// x -= w;
-// x -= shift;
-// }
-// } else if (angle == 90 || angle == 270) {
-// x = x - w * 0.5;
-// if (angle == 90)
-// y -= shift;
-// else {
-// y += h;
-// y += shift;
-// }
-// } else if (angle > 0 && angle <= 45) {
-// x += shift;
-// } else if (angle > 45 && angle < 90) {
-// y -= shift;
-// } else if (angle > 90 && angle < 180) {
-// x -= w;
-// x -= shift;
-// } else if (angle > 180 && angle <= 225) {
-// x -= w;
-// x -= shift;
-// y += h;
-// } else if (angle > 225 && angle < 270) {
-// x -= w;
-// x -= shift;
-// y += h;
-// } else if (angle > 270) {
-// x += shift;
-// y += h;
-// }
-// g.setColor(Color.black);
-// g.drawString(label, (float) x, (float) y);
- }
- }
-
- //Draw y grid lines
- if (gridLine.isDrawYLine()) {
- g.setFont(this.yTickFont);
- if (this.yTickAuto)
- this.yTickLocations = this.getTickValues();
-
- for (int i = 0; i < this.yTickLocations.size(); i++) {
- double v = this.yTickLocations.get(i);
- if (v > 0 && v < this.radius) {
- g.setColor(gridLine.getColor());
- this.drawCircle(g, area, v + bottom);
- }
-// if (v > 0){
-// g.setColor(Color.black);
-// xy = MIMath.polarToCartesian(Math.toRadians(this.yTickLabelPos), v);
-// xy = this.projToScreen(xy[0], xy[1], area);
-// x = xy[0];
-// y = xy[1];
-// x += minx;
-// y += miny;
-// String label;
-// if (this.yTickLabels != null)
-// label = this.yTickLabels.get(i);
-// else {
-// if (this.yTickFormat.equals("%"))
-// label = DataConvert.removeTailingZeros(String.valueOf(BigDecimalUtil.mul(v, 100))) + "%";
-// else
-// label = DataConvert.removeTailingZeros(String.valueOf(v));
-// }
-// g.drawString(label, (float)x, (float)y);
-// }
- }
- }
- }
-
- void drawGridLabel_bak(Graphics2D g, Rectangle2D area) {
- GridLine gridLine = this.getGridLine();
- if (!gridLine.isDrawXLine() && !gridLine.isDrawYLine()) {
- return;
- }
-
- double[] xy;
- double x, y;
- double miny = area.getY();
- double minx = area.getX();
-
- //Draw straight grid lines
- if (gridLine.isDrawXLine()) {
- g.setFont(this.xTickFont);
- float shift = 5;
- for (int i = 0; i < this.xTickLocations.size(); i++) {
- double angle = this.xTickLocations.get(i);
- xy = MIMath.polarToCartesian(Math.toRadians(angle), this.radius);
- xy = this.projToScreen(xy[0], xy[1], area);
- x = xy[0];
- y = xy[1];
- x += minx;
- y += miny;
- //Draw x tick label
- String label = this.xTickLabels.get(i);
- Dimension dim = Draw.getStringDimension(label, g);
- float w = dim.width;
- float h = dim.height;
- if (angle == 0 || angle == 180){
- y = y + h * 0.5;
- if (angle == 0)
- x += shift;
- else {
- x -= w;
- x -= shift;
- }
- } else if (angle == 90 || angle == 270) {
- x = x - w * 0.5;
- if (angle == 90)
- y -= shift;
- else {
- y += h;
- y += shift;
- }
- } else if (angle > 0 && angle <= 45) {
- x += shift;
- } else if (angle > 45 && angle < 90) {
- y -= shift;
- } else if (angle > 90 && angle < 180) {
- x -= w;
- x -= shift;
- } else if (angle > 180 && angle <= 225) {
- x -= w;
- x -= shift;
- y += h;
- } else if (angle > 225 && angle < 270) {
- x -= w;
- x -= shift;
- y += h;
- } else if (angle > 270) {
- x += shift;
- y += h;
- }
- g.setColor(Color.black);
- g.drawString(label, (float) x, (float) y);
- }
- }
-
- //Draw y grid lines
- if (gridLine.isDrawYLine()) {
- g.setFont(this.yTickFont);
- if (this.yTickAuto)
- this.yTickLocations = this.getTickValues();
-
- for (int i = 0; i < this.yTickLocations.size(); i++) {
- double v = this.yTickLocations.get(i);
- if (v > 0){
- g.setColor(Color.black);
- xy = MIMath.polarToCartesian(Math.toRadians(this.yTickLabelPos), v);
- xy = this.projToScreen(xy[0], xy[1], area);
- x = xy[0];
- y = xy[1];
- x += minx;
- y += miny;
- String label;
- if (this.yTickLabels != null)
- label = this.yTickLabels.get(i);
- else {
- if (this.yTickFormat.equals("%"))
- label = DataConvert.removeTailingZeros(String.valueOf(BigDecimalUtil.mul(v, 100))) + "%";
- else
- label = DataConvert.removeTailingZeros(String.valueOf(v));
- }
- g.drawString(label, (float)x, (float)y);
- }
- }
- }
- }
-
- void drawGridLabel(Graphics2D g, Rectangle2D area) {
- GridLine gridLine = this.getGridLine();
- if (!gridLine.isDrawXLine() && !gridLine.isDrawYLine()) {
- return;
- }
-
- double[] xy;
- double x, y;
- double miny = area.getY();
- double minx = area.getX();
-
- //Draw x grid line labels
- if (gridLine.isDrawXLine()) {
- g.setFont(this.xTickFont);
- g.setColor(this.xTickColor);
- float shift = 5;
- for (int i = 0; i < this.xTickLocations.size(); i++) {
- double angle = this.xTickLocations.get(i);
- xy = MIMath.polarToCartesian(Math.toRadians(angle), this.radius);
- xy = this.projToScreen(xy[0], xy[1], area);
- x = xy[0];
- y = xy[1];
- x += minx;
- y += miny;
- //Draw x tick label
- String label = this.xTickLabels.get(i);
- Dimension dim = Draw.getStringDimension(label, g);
- float w = dim.width;
- float h = dim.height;
- if (angle == 0 || angle == 180){
- if (angle == 0) {
- x += shift;
- Draw.drawString(g, (float)x, (float)y, label, XAlign.LEFT, YAlign.CENTER, false);
- }
- else {
- x -= shift;
- Draw.drawString(g, (float)x, (float)y, label, XAlign.RIGHT, YAlign.CENTER, false);
- }
- } else if (angle == 90 || angle == 270) {
- if (angle == 90) {
- y -= shift;
- Draw.drawString(g, (float)x, (float)y, label, XAlign.CENTER, YAlign.BOTTOM, false);
- } else {
- y += shift;
- Draw.drawString(g, (float)x, (float)y, label, XAlign.CENTER, YAlign.TOP, false);
- }
- } else if (angle > 0 && angle < 90) {
- x += shift;
- Draw.drawString(g, (float)x, (float)y, label, XAlign.LEFT, YAlign.BOTTOM, false);
- } else if (angle > 90 && angle < 180) {
- x -= shift;
- Draw.drawString(g, (float)x, (float)y, label, XAlign.RIGHT, YAlign.BOTTOM, false);
- } else if (angle > 180 && angle < 270) {
- x -= shift;
- Draw.drawString(g, (float)x, (float)y, label, XAlign.RIGHT, YAlign.TOP, false);
- } else if (angle > 270) {
- x += shift;
- Draw.drawString(g, (float)x, (float)y, label, XAlign.LEFT, YAlign.TOP, false);
- }
- }
- }
-
- //Draw y grid lines
- if (gridLine.isDrawYLine()) {
- g.setFont(this.yTickFont);
- g.setColor(this.yTickColor);
- if (this.yTickAuto)
- this.yTickLocations = this.getTickValues();
-
- for (int i = 0; i < this.yTickLocations.size(); i++) {
- double v = this.yTickLocations.get(i);
- if (v > 0 && v < this.radius){
- xy = MIMath.polarToCartesian(Math.toRadians(this.yTickLabelPos), v + bottom);
- xy = this.projToScreen(xy[0], xy[1], area);
- x = xy[0];
- y = xy[1];
- x += minx;
- y += miny;
- String label;
- if (this.yTickLabels != null)
- label = this.yTickLabels.get(i);
- else {
- if (this.yTickFormat.equals("%"))
- label = DataConvert.removeTailingZeros(String.valueOf(BigDecimalUtil.mul(v, 100))) + "%";
- else
- label = DataConvert.removeTailingZeros(String.valueOf(v));
- }
- g.drawString(label, (float)x, (float)y);
- }
- }
- }
- }
-
- List getTickValues() {
- //List
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/SeriesLegend.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/SeriesLegend.java
deleted file mode 100644
index 88f3691a..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/SeriesLegend.java
+++ /dev/null
@@ -1,175 +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.geometry.legend.ColorBreak;
-import org.meteoinfo.geometry.legend.PointBreak;
-import org.meteoinfo.geometry.legend.PolygonBreak;
-import org.meteoinfo.geometry.legend.PolylineBreak;
-
-import java.awt.Color;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- *
- * @author wyq
- */
-public class SeriesLegend {
- //
- private ChartPlotMethod plotMethod;
- private List legendBreaks;
- private Color errorColor;
- //
- //
- /**
- * Constructor
- */
- public SeriesLegend(){
- this.plotMethod = ChartPlotMethod.LINE;
- this.legendBreaks = new ArrayList<>();
- this.errorColor = Color.black;
- }
-
- /**
- * Constructor
- * @param cb ColorBreak
- */
- public SeriesLegend(ColorBreak cb){
- this();
- this.legendBreaks.add(cb);
- }
-
- /**
- * Constructor
- * @param n Break number
- */
- public SeriesLegend(int n){
- this();
- for (int i = 0; i < n; i++)
- this.legendBreaks.add(new PolylineBreak());
- }
- //
- //
- /**
- * Get plot method
- * @return Plot method
- */
- public ChartPlotMethod getPlotMethod(){
- return this.plotMethod;
- }
-
- /**
- * Set plot method
- * @param value Plot method
- */
- public void setPlotMethod(ChartPlotMethod value){
- this.plotMethod = value;
- }
-
- /**
- * Get if the legend is PointBreak
- * @return Boolean
- */
- public boolean isPoint(){
- return this.legendBreaks.get(0) instanceof PointBreak;
- }
-
- /**
- * Get if the legend is PolylineBreak
- * @return Boolean
- */
- public boolean isLine(){
- return this.legendBreaks.get(0) instanceof PolylineBreak;
- }
-
- /**
- * Get if the legend is PolygonBreak
- * @return Boolean
- */
- public boolean isPolygon(){
- return this.legendBreaks.get(0) instanceof PolygonBreak;
- }
-
- /**
- * Get if if mutiple legend breaks
- * @return Boolean
- */
- public boolean isMutiple(){
- return this.legendBreaks.size() > 1;
- }
-
- /**
- * Get a legend break
- * @return Legend break
- */
- public ColorBreak getLegendBreak(){
- return this.legendBreaks.get(0);
- }
-
- /**
- * Set legend break
- * @param cb Legend break
- */
- public void setLegendBreak(ColorBreak cb){
- this.legendBreaks.clear();
- this.legendBreaks.add(cb);
- }
-
- /**
- * Get a legend break
- * @param idx Index
- * @return Legend break
- */
- public ColorBreak getLegendBreak(int idx){
- if (idx >= this.legendBreaks.size())
- idx = 0;
- return this.legendBreaks.get(idx);
- }
-
- /**
- * Set legend break
- * @param idx Index
- * @param cb Legend break
- */
- public void setLegendBreak(int idx, ColorBreak cb){
- this.legendBreaks.set(idx, cb);
- }
-
- /**
- * Get error color
- * @return Error color
- */
- public Color getErrorColor(){
- return this.errorColor;
- }
-
- /**
- * Set error color
- * @param value Error color
- */
- public void setErrorColor(Color value){
- this.errorColor = value;
- }
- //
- //
- /**
- * Add a legend break
- * @param cb Legend break
- */
- public void addLegendBreak(ColorBreak cb){
- this.legendBreaks.add(cb);
- }
-
- /**
- * Get legend break number
- * @return Legend break number
- */
- public int getBreakNum(){
- return this.legendBreaks.size();
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/XY1DPlot.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/XY1DPlot.java
deleted file mode 100644
index 16e89cae..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/XY1DPlot.java
+++ /dev/null
@@ -1,865 +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 java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Line2D;
-import java.awt.geom.Rectangle2D;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.meteoinfo.chart.ChartLegend;
-import org.meteoinfo.chart.Location;
-import org.meteoinfo.chart.axis.TimeAxis;
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.common.MIMath;
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.data.*;
-import org.meteoinfo.drawing.Draw;
-import org.meteoinfo.common.colors.ColorUtil;
-import org.meteoinfo.geometry.legend.*;
-import org.meteoinfo.geometry.shape.ShapeTypes;
-
-/**
- *
- * @author yaqiang
- */
-public class XY1DPlot extends AbstractPlot2D {
-
- //
- private XYListDataset dataset;
- private ChartPlotMethod chartPlotMethod;
- private List seriesLegends;
- private boolean useBreak2D;
- private float barWidth;
- private boolean autoBarWidth;
-
- //
- //
- /**
- * Constructor
- */
- public XY1DPlot() {
- super();
-
- this.dataset = new XYListDataset();
- this.chartPlotMethod = ChartPlotMethod.LINE;
- this.useBreak2D = false;
- this.seriesLegends = new ArrayList<>();
- this.barWidth = 0.8f;
- this.autoBarWidth = true;
- }
-
- /**
- * Constructor
- *
- * @param dateset Dataset
- */
- public XY1DPlot(XYDataset dateset) {
- this();
- this.setDataset(dateset);
- }
-
- /**
- * Constructor
- *
- * @param orientation Plot orientation
- * @param dateset Dataset
- */
- public XY1DPlot(PlotOrientation orientation, XYDataset dateset) {
- this();
- this.setPlotOrientation(orientation);
- this.setDataset(dateset);
- }
-
- /**
- * Constructor
- *
- * @param isTime If x axis is time
- * @param dateset Dataset
- */
- public XY1DPlot(boolean isTime, XYDataset dateset) {
- this();
- if (isTime) {
- try {
- this.setXAxis(new TimeAxis("X", true));
- } catch (CloneNotSupportedException ex) {
- Logger.getLogger(XY1DPlot.class.getName()).log(Level.SEVERE, null, ex);
- }
- this.getAxis(Location.TOP).setDrawTickLabel(false);
- }
- //this.getXAxis().setTimeAxis(isTime);
- this.setDataset(dateset);
- }
-
- /**
- * Constructor
- *
- * @param isTime If x axis is time
- * @param cpMethod Plot method
- * @param dateset Dataset
- */
- public XY1DPlot(boolean isTime, ChartPlotMethod cpMethod, XYDataset dateset) {
- this();
- if (isTime) {
- try {
- this.setXAxis(new TimeAxis("X", true));
- } catch (CloneNotSupportedException ex) {
- Logger.getLogger(XY1DPlot.class.getName()).log(Level.SEVERE, null, ex);
- }
- this.getAxis(Location.TOP).setDrawTickLabel(false);
- }
- //this.getXAxis().setTimeAxis(isTime);
- this.setChartPlotMethod(cpMethod);
- this.setDataset(dateset);
- }
-
- /**
- * Constructor
- *
- * @param isTime If x axis is time
- * @param orientation Plot orientation
- * @param dateset Dataset
- */
- public XY1DPlot(boolean isTime, PlotOrientation orientation, XYDataset dateset) {
- this();
- if (isTime) {
- try {
- this.setXAxis(new TimeAxis("X", true));
- } catch (CloneNotSupportedException ex) {
- Logger.getLogger(XY1DPlot.class.getName()).log(Level.SEVERE, null, ex);
- }
- this.getAxis(Location.TOP).setDrawTickLabel(false);
- }
- //this.getXAxis().setTimeAxis(isTime);
- this.setPlotOrientation(orientation);
- this.setDataset(dateset);
- }
-
- //
- //
- @Override
- public XYDataset getDataset() {
- return dataset;
- }
-
- @Override
- public void setDataset(Dataset value) {
- dataset = (XYListDataset) value;
- Extent extent = this.getAutoExtent();
- this.setDrawExtent(extent);
- this.setExtent(extent);
- this.updateSeriesLegend();
- }
-
- private void updateSeriesLegend() {
- //this.seriesLegends.clear();
- int si = this.seriesLegends.size();
- if (si > dataset.getSeriesCount()) {
- si = 0;
- }
- for (int i = si; i < dataset.getSeriesCount(); i++) {
- Color color = ColorUtil.getCommonColor(i);
- switch (this.chartPlotMethod) {
- case LINE:
- case LINE_POINT:
- PolylineBreak plb = new PolylineBreak();
- if (this.chartPlotMethod == ChartPlotMethod.LINE) {
- plb.setDrawSymbol(false);
- } else {
- plb.setDrawSymbol(true);
- plb.setSymbolColor(color);
- plb.setSymbolFillColor(color);
- }
- plb.setColor(color);
- plb.setCaption(dataset.getSeriesKey(i));
- seriesLegends.add(new SeriesLegend(plb));
- break;
- case POINT:
- PointBreak pb = new PointBreak();
- pb.setColor(color);
- pb.setCaption(dataset.getSeriesKey(i));
- seriesLegends.add(new SeriesLegend(pb));
- break;
- case BAR:
- PolygonBreak pgb = new PolygonBreak();
- pgb.setColor(color);
- pgb.setCaption(dataset.getSeriesKey(i));
- seriesLegends.add(new SeriesLegend(pgb));
- break;
- }
- }
- }
-
- /**
- * Get chart plot method
- *
- * @return Chart plot method
- */
- public ChartPlotMethod getChartPlotMethod() {
- return this.chartPlotMethod;
- }
-
- /**
- * Set chart plot method
- *
- * @param value Chart plot method
- */
- public void setChartPlotMethod(ChartPlotMethod value) {
- this.chartPlotMethod = value;
- if (this.dataset != null) {
- this.updateSeriesLegend();
- }
- }
-
- @Override
- public PlotType getPlotType() {
- return PlotType.XY;
- }
-
- /**
- * Get Series legend breaks
- *
- * @return Series legend breaks
- */
- public List getLegendBreaks() {
- return this.seriesLegends;
- }
-
-// /**
-// * Get point breaks
-// *
-// * @return Point breaks
-// */
-// public PointBreak[] getPointBreaks() {
-// return this.pointBreaks;
-// }
- /**
- * If use item 2D point breaks
- *
- * @return Boolean
- */
- public boolean isUseBreak2D() {
- return this.useBreak2D;
- }
-
- /**
- * Set if use item 2D point breaks
- *
- * @param value Boolean
- */
- public void setUseBeak2D(boolean value) {
- this.useBreak2D = value;
- }
-
- /**
- * Get bar width ratio
- *
- * @return Bar width ratio
- */
- public float getBarWidth() {
- return this.barWidth;
- }
-
- /**
- * Set bar width ratio
- *
- * @param value Bar width ratio
- */
- public void setBarWidth(float value) {
- this.barWidth = value;
- }
-
- /**
- * Get if automatically decide bar width
- *
- * @return Boolean
- */
- public boolean isAutoBarWidth() {
- return this.autoBarWidth;
- }
-
- /**
- * Set if automatically decide bar height
- *
- * @param value Boolean
- */
- public void setAutoBarWidth(boolean value) {
- this.autoBarWidth = value;
- }
-
- //
- //
- /**
- * Add a series data
- *
- * @param seriesKey Series key
- * @param xvs X value array
- * @param yvs Y value array
- */
- public void addSeries(String seriesKey, double[] xvs, double[] yvs) {
- ((XYListDataset) this.dataset).addSeries(seriesKey, xvs, yvs);
- PolylineBreak plb = new PolylineBreak();
- plb.setColor(ColorUtil.getCommonColor(this.dataset.getSeriesCount()));
- plb.setCaption(seriesKey);
- seriesLegends.add(new SeriesLegend(plb));
-
- Extent extent = this.getAutoExtent();
- this.setDrawExtent(extent);
- }
-
- /**
- * Remove last series
- */
- public void removeLastSeries() {
- XYListDataset ds = (XYListDataset) this.dataset;
- ds.removeSeries(dataset.getSeriesCount() - 1);
- this.seriesLegends.remove(this.seriesLegends.size() - 1);
-
- Extent extent = this.getAutoExtent();
- this.setDrawExtent(extent);
- }
-
- private PointF[] getScreenPoints(double[] xdata, double[] ydata, List mvIdx, Rectangle2D area) {
- int len = xdata.length;
- PointF[] points = new PointF[len];
- double[] xy;
- if (this.getPlotOrientation() == PlotOrientation.VERTICAL) {
- for (int j = 0; j < len; j++) {
- xy = this.projToScreen(xdata[j], ydata[j], area);
- points[j] = new PointF((float) xy[0], (float) xy[1]);
- }
- } else {
- for (int j = 0; j < len; j++) {
- xy = this.projToScreen(xdata[j], ydata[j], area);
- points[j] = new PointF((float) xy[0], (float) xy[1]);
- }
- }
-// if (this.getYAxis().isInverse()) {
-// PointF[] npoints = new PointF[len];
-// PointF p;
-// float y;
-// for (int j = 0; j < len; j++) {
-// p = points[len - j - 1];
-// y = (float) area.getHeight() - p.Y;
-// npoints[j] = new PointF(p.X, y);
-// }
-// points = npoints;
-// if (!mvIdx.isEmpty()) {
-// for (int j = 0; j < mvIdx.size(); j++) {
-// mvIdx.set(j, len - mvIdx.get(j) - 1);
-// }
-// }
-// }
-// if (this.getXAxis().isInverse()) {
-// PointF[] npoints = new PointF[len];
-// PointF p;
-// float x;
-// for (int j = 0; j < len; j++) {
-// p = points[len - j - 1];
-// x = (float) area.getWidth() - p.X;
-// npoints[j] = new PointF(x, p.Y);
-// }
-// points = npoints;
-// if (!mvIdx.isEmpty()) {
-// for (int j = 0; j < mvIdx.size(); j++) {
-// mvIdx.set(j, len - mvIdx.get(j) - 1);
-// }
-// }
-// }
-
- return points;
- }
-
- @Override
- void drawGraph(Graphics2D g, Rectangle2D area) {
- AffineTransform oldMatrix = g.getTransform();
- Rectangle oldRegion = g.getClipBounds();
- g.setClip(area);
- g.translate(area.getX(), area.getY());
-
- //Draw background
- if (this.background != null) {
- g.setColor(this.getBackground());
- g.fill(new Rectangle2D.Double(0, 0, area.getWidth(), area.getHeight()));
- }
-
- double[] xy;
- xy = this.projToScreen(0, 0, area);
- float y0 = (float) xy[1];
- boolean drawBaseline = false;
- for (int i = 0; i < this.dataset.getSeriesCount(); i++) {
- XYSeriesData sdata = this.dataset.getSeriesData(i);
- int len = sdata.dataLength();
- List mvIdx = sdata.getMissingValueIndex();
- PointF[] points = getScreenPoints(sdata.getXdata(), sdata.getYdata(), mvIdx, area);
- SeriesLegend slegend = this.seriesLegends.get(i);
- if (slegend.isLine()) {
- if (mvIdx.isEmpty()) {
- Draw.drawPolyline(points, (PolylineBreak) slegend.getLegendBreak(), g);
- } else {
- Draw.drawPolyline(points, (PolylineBreak) slegend.getLegendBreak(), g, mvIdx);
- }
- } else if (slegend.isPoint()) {
- if (slegend.isMutiple()) {
- for (int j = 0; j < len; j++) {
- if (!mvIdx.contains(j)) {
- Draw.drawPoint(points[j], (PointBreak) slegend.getLegendBreak(j), g);
- }
- }
- } else {
- for (int j = 0; j < len; j++) {
- if (!mvIdx.contains(j)) {
- Draw.drawPoint(points[j], (PointBreak) slegend.getLegendBreak(), g);
- }
- }
- }
- } else if (slegend.isPolygon()) {
- switch (slegend.getPlotMethod()) {
- case BAR:
- if (sdata instanceof XYErrorSeriesData) {
- drawBaseline = true;
- XYErrorSeriesData esdata = (XYErrorSeriesData) sdata;
- double[] bottom = esdata.getBottom();
- float[] yBottoms = null;
- if (bottom != null) {
- yBottoms = new float[bottom.length];
- for (int j = 0; j < bottom.length; j++) {
- xy = this.projToScreen(esdata.getBottom(j), esdata.getBottom(j), area);
- yBottoms[j] = (float) xy[1];
- }
- }
- float width = this.barWidth;
- if (this.autoBarWidth) {
- if (points.length > 1) {
- width = (float) ((points[1].X - points[0].X) * 0.5) / this.dataset.getSeriesCount();
- } else {
- width = (float) (area.getWidth() / 10) / this.dataset.getSeriesCount();
- }
- float height;
- PolygonBreak pgb;
- for (int j = 0; j < len; j++) {
- if (!mvIdx.contains(j)) {
- pgb = (PolygonBreak) slegend.getLegendBreak(j);
- height = Math.abs((float) (points[j].Y - y0));
- float yBottom = y0;
- if (yBottoms != null) {
- if (j < yBottoms.length) {
- yBottom = yBottoms[j];
- } else {
- yBottom = yBottoms[0];
- }
- }
- float yb = yBottom;
- if (points[j].Y >= y0) {
- yb += height;
- }
- Draw.drawBar(new PointF(points[j].X - width * this.dataset.getSeriesCount() / 2
- + i * width, yb), width, height, pgb, g, false, 5);
- if (esdata.getYerror() != null) {
- PointF p = (PointF) points[j].clone();
- p.Y -= y0 - yBottom;
- double elen = 6;
- double error = esdata.getYerror(j);
- error = this.projYLength(error, area);
- double x = p.X - width * this.dataset.getSeriesCount() / 2
- + i * width + width / 2;
- g.setColor(slegend.getErrorColor());
- g.draw(new Line2D.Double(x, p.Y - error, x, p.Y + error));
- g.draw(new Line2D.Double(x - (elen * 0.5), p.Y - error, x + (elen * 0.5), p.Y - error));
- g.draw(new Line2D.Double(x - (elen * 0.5), p.Y + error, x + (elen * 0.5), p.Y + error));
- }
- }
- }
- } else {
- width = (float) this.projXLength(width, area);
- float height;
- PolygonBreak pgb;
- for (int j = 0; j < len; j++) {
- if (!mvIdx.contains(j)) {
- pgb = (PolygonBreak) slegend.getLegendBreak(j);
- height = Math.abs((float) (points[j].Y - y0));
- float yBottom = y0;
- if (yBottoms != null) {
- if (j < yBottoms.length) {
- yBottom = yBottoms[j];
- } else {
- yBottom = yBottoms[0];
- }
- }
- float yb = yBottom;
- if (points[j].Y >= y0) {
- yb += height;
- }
- Draw.drawBar(new PointF(points[j].X, yb), width, height, pgb, g, false, 5);
- if (esdata.getYerror() != null) {
- PointF p = (PointF) points[j].clone();
- p.Y -= y0 - yBottom;
- double elen = 6;
- double error = esdata.getYerror(j);
- error = this.projYLength(error, area);
- double x = p.X + width / 2;
- g.setColor(slegend.getErrorColor());
- g.draw(new Line2D.Double(x, p.Y - error, x, p.Y + error));
- g.draw(new Line2D.Double(x - (elen * 0.5), p.Y - error, x + (elen * 0.5), p.Y - error));
- g.draw(new Line2D.Double(x - (elen * 0.5), p.Y + error, x + (elen * 0.5), p.Y + error));
- }
- }
- }
- }
- } else {
- drawBaseline = true;
- float width = this.barWidth;
- if (this.autoBarWidth) {
- if (points.length > 1) {
- width = (float) ((points[1].X - points[0].X) * 0.5) / this.dataset.getSeriesCount();
- } else {
- width = (float) (area.getWidth() / 10) / this.dataset.getSeriesCount();
- }
- float height;
- PolygonBreak pgb;
- for (int j = 0; j < len; j++) {
- if (!mvIdx.contains(j)) {
- pgb = (PolygonBreak) slegend.getLegendBreak(j);
- height = Math.abs((float) (points[j].Y - y0));
- float yb = y0;
- if (points[j].Y >= y0) {
- yb += height;
- }
- Draw.drawBar(new PointF(points[j].X - width * this.dataset.getSeriesCount() / 2
- + i * width, yb), width, height, pgb, g, false, 5);
- }
- }
- } else {
- width = (float) this.projXLength(width, area);
- float height;
- PolygonBreak pgb;
- for (int j = 0; j < len; j++) {
- if (!mvIdx.contains(j)) {
- pgb = (PolygonBreak) slegend.getLegendBreak(j);
- height = Math.abs((float) (points[j].Y - y0));
- float yb = y0;
- if (points[j].Y >= y0) {
- yb += height;
- }
- Draw.drawBar(new PointF(points[j].X, yb), width, height, pgb, g, false, 5);
- }
- }
- }
- }
- break;
- case FILL:
- XYYSeriesData xyydata = (XYYSeriesData) sdata;
- PointF[] y2Points = this.getScreenPoints(xyydata.getXdata(), xyydata.getY2data(), mvIdx, area);
- if (xyydata.getWhere() == null) {
- PointF[] npoints = new PointF[len * 2];
- for (int j = 0; j < len; j++) {
- npoints[j] = points[len - j - 1];
- npoints[j + len] = y2Points[j];
- }
- Draw.drawPolygon(npoints, (PolygonBreak) slegend.getLegendBreak(), g);
- } else {
- boolean ob = false;
- List> idxs = new ArrayList<>();
- List idx = new ArrayList<>();
- for (int j = 0; j < len; j++) {
- if (xyydata.getWhere().get(j)) {
- if (!ob) {
- idx = new ArrayList<>();
- }
- idx.add(j);
- } else if (ob) {
- idxs.add(idx);
- }
- ob = xyydata.getWhere().get(j);
- }
- for (List index : idxs) {
- int nn = index.size();
- if (nn >= 2) {
- PointF[] npoints = new PointF[nn * 2];
- int ii, ii2;
- for (int j = 0; j < nn; j++) {
- ii = index.get(j);
- ii2 = index.get(nn - j - 1);
- npoints[j] = points[ii];
- npoints[j + index.size()] = y2Points[ii2];
- }
- Draw.drawPolygon(npoints, (PolygonBreak) slegend.getLegendBreak(), g);
- }
- }
- }
- break;
- }
- }
-
- //Draw baseline
- if (drawBaseline) {
- g.setColor(Color.black);
- g.draw(new Line2D.Double(0, y0, area.getWidth(), y0));
- }
-
- //Draw error bar
- if (sdata instanceof XYErrorSeriesData) {
- XYErrorSeriesData esdata = (XYErrorSeriesData) sdata;
- g.setColor(slegend.getLegendBreak().getColor());
- PointF p;
- double error;
- double elen = 6;
- if (esdata.getYerror() != null) {
- if (slegend.getPlotMethod() == ChartPlotMethod.BAR) {
-
- } else {
- for (int j = 0; j < len; j++) {
- if (!mvIdx.contains(j)) {
- p = points[j];
- error = esdata.getYerror(j);
- error = this.projYLength(error, area);
- g.draw(new Line2D.Double(p.X, p.Y - error, p.X, p.Y + error));
- g.draw(new Line2D.Double(p.X - (elen * 0.5), p.Y - error, p.X + (elen * 0.5), p.Y - error));
- g.draw(new Line2D.Double(p.X - (elen * 0.5), p.Y + error, p.X + (elen * 0.5), p.Y + error));
- }
- }
- }
- }
- if (esdata.getXerror() != null) {
- for (int j = 0; j < len; j++) {
- if (!mvIdx.contains(j)) {
- p = points[j];
- error = esdata.getXerror(j);
- error = this.projXLength(error, area);
- g.draw(new Line2D.Double(p.X - error, p.Y, p.X + error, p.Y));
- g.draw(new Line2D.Double(p.X - error, p.Y - (elen * 0.5), p.X - error, p.Y + (elen * 0.5)));
- g.draw(new Line2D.Double(p.X + error, p.Y - (elen * 0.5), p.X + error, p.Y + (elen * 0.5)));
- }
- }
- }
- }
- }
-
- //Draw texts
-// for (ChartText text : this.getTexts()) {
-// xy = this.projToScreen(text.getX(), text.getY(), area);
-// float x = (float) xy[0];
-// float y = (float) xy[1];
-// g.setFont(text.getFont());
-// g.setColor(text.getColor());
-// //Dimension dim = Draw.getStringDimension(text.getText(), g);
-// //y -= dim.height * 2 / 3;
-// Draw.drawString(g, text.getText(), x, y);
-// }
- g.setTransform(oldMatrix);
- g.setClip(oldRegion);
- }
-
- /**
- * Get a item point break
- *
- * @param seriesIdx Series index
- * @param itemIdx Item index
- * @return Item point break;
- */
- public PointBreak getItemPointBreak(int seriesIdx, int itemIdx) {
- return (PointBreak) this.seriesLegends.get(seriesIdx).getLegendBreak(itemIdx);
- }
-
- /**
- * Set item point break
- *
- * @param seriesIdx Series index
- * @param itemIdx Item index
- * @param pb Item point break
- */
- public void setItemPointBreak(int seriesIdx, int itemIdx, PointBreak pb) {
- this.seriesLegends.get(seriesIdx).setLegendBreak(itemIdx, pb);
- }
-
- /**
- * Get legend break
- *
- * @param seriesIdx Series index
- * @return Legend break
- */
- public ColorBreak getLegendBreak(int seriesIdx) {
- return this.seriesLegends.get(seriesIdx).getLegendBreak();
- }
-
- /**
- * Set legend break
- *
- * @param seriesIdx Series index
- * @param cb Legend break
- */
- public void setLegendBreak(int seriesIdx, ColorBreak cb) {
- this.seriesLegends.get(seriesIdx).setLegendBreak(cb);
- }
-
- /**
- * Set series legend
- *
- * @param seriesIdx Series index
- * @param sLegend SeriesLegend
- */
- public void setLegendBreak(int seriesIdx, SeriesLegend sLegend) {
- this.seriesLegends.set(seriesIdx, sLegend);
- }
-
-// /**
-// * Get point break
-// *
-// * @param seriesIdx Series index
-// * @return Point break
-// */
-// public PointBreak getPointBreak(int seriesIdx) {
-// return this.pointBreaks[seriesIdx];
-// }
-//
-// /**
-// * Set point break
-// *
-// * @param seriesIdx Series index
-// * @param pb Point break
-// */
-// public void setPointBreak(int seriesIdx, PointBreak pb) {
-// this.pointBreaks[seriesIdx] = pb;
-// }
-//
-// /**
-// * Get polygon break
-// *
-// * @param seriesIdx Series index
-// * @return Polygon break
-// */
-// public PolygonBreak getPolygonBreak(int seriesIdx) {
-// return this.polygonBreaks[seriesIdx];
-// }
-//
-// /**
-// * Set polygon break
-// *
-// * @param seriesIdx Series index
-// * @param pgb Polygon break
-// */
-// public void setPolygonBreak(int seriesIdx, PolygonBreak pgb) {
-// this.polygonBreaks[seriesIdx] = pgb;
-// }
- private double getBarXInterval(int idx) {
- double[] xvalues = this.dataset.getXValues(idx);
- if (xvalues.length == 1) {
- if (xvalues[0] == 0) {
- return 1;
- } else {
- return xvalues[0] / 10;
- }
- } else {
- return xvalues[1] - xvalues[0];
- }
- }
-
- private int getBarIndex() {
- int idx = -1;
- for (int i = 0; i < this.seriesLegends.size(); i++) {
- if (this.seriesLegends.get(i).getPlotMethod() == ChartPlotMethod.BAR) {
- idx = i;
- break;
- }
- }
- return idx;
- }
-
- /**
- * Get auto extent
- *
- * @return Auto extent
- */
- @Override
- public Extent getAutoExtent() {
- Extent extent = dataset.getDataExtent();
- if (extent.minX == extent.maxX){
- extent.minX = extent.minX - Math.abs(extent.minX);
- extent.maxX = extent.maxX + Math.abs(extent.minX);
- }
- if (extent.minY == extent.maxY){
- extent.minY = extent.minY - Math.abs(extent.minY);
- extent.maxY = extent.maxY + Math.abs(extent.maxY);
- }
-
- int barIdx = this.getBarIndex();
- if (barIdx >= 0) {
- double dx = getBarXInterval(barIdx);
- extent.minX -= dx;
- extent.maxX += dx;
- }
- double[] xValues;
- if (this.getXAxis() instanceof TimeAxis) {
- //if (this.getXAxis().isTimeAxis()) {
- xValues = (double[]) MIMath.getIntervalValues(extent.minX, extent.maxX, false).get(0);
- xValues[0] = extent.minX;
- xValues[xValues.length - 1] = extent.maxX;
- } else {
- xValues = (double[]) MIMath.getIntervalValues(extent.minX, extent.maxX, true).get(0);
- }
- double[] yValues = (double[]) MIMath.getIntervalValues(extent.minY, extent.maxY, true).get(0);
- if (this.getPlotOrientation() == PlotOrientation.VERTICAL) {
- return new Extent(xValues[0], xValues[xValues.length - 1], yValues[0], yValues[yValues.length - 1]);
- } else {
- return new Extent(yValues[0], yValues[yValues.length - 1], xValues[0], xValues[xValues.length - 1]);
- }
- }
-
- /**
- * Set auto extent
- */
- @Override
- public void setAutoExtent() {
- Extent extent = this.getAutoExtent();
- this.setDrawExtent(extent);
- }
-
- /**
- * Get legend scheme
- *
- * @return Legend scheme
- */
- public LegendScheme getLegendScheme() {
-// LegendScheme ls = null;
-// switch (this.chartPlotMethod) {
-// case LINE:
-// case LINE_POINT:
-// ls = new LegendScheme(ShapeTypes.Polyline);
-// ls.getLegendBreaks().addAll(Arrays.asList(this.lineBreaks));
-// break;
-// case POINT:
-// ls = new LegendScheme(ShapeTypes.Point);
-// ls.getLegendBreaks().addAll(Arrays.asList(this.pointBreaks));
-// break;
-// case BAR:
-// ls = new LegendScheme(ShapeTypes.Polygon);
-// ls.getLegendBreaks().addAll(Arrays.asList(this.polygonBreaks));
-// break;
-// }
- ShapeTypes stype = ShapeTypes.Polyline;
- LegendScheme ls = new LegendScheme(stype);
- for (SeriesLegend slegend : this.seriesLegends) {
- ls.getLegendBreaks().add(slegend.getLegendBreak());
- }
- return ls;
- }
-
- @Override
- public void updateLegendScheme() {
- if (this.getLegend() == null) {
- this.setLegend(new ChartLegend(this.getLegendScheme()));
- } else {
- this.getLegend().setLegendScheme(this.getLegendScheme());
- }
- }
-
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot3d/GraphicCollection3D.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot3d/GraphicCollection3D.java
deleted file mode 100644
index e8aba60b..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot3d/GraphicCollection3D.java
+++ /dev/null
@@ -1,180 +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.plot3d;
-
-import java.util.List;
-import org.meteoinfo.geometry.graphic.GraphicCollection;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class GraphicCollection3D extends GraphicCollection{
-
- private boolean fixZ;
- private double zValue;
- private String zdir;
- private List sePoint;
- protected boolean allQuads;
- protected boolean allTriangle;
- protected boolean allConvexPolygon;
- protected boolean usingLight;
-
- /**
- * Constructor
- */
- public GraphicCollection3D(){
- super();
- fixZ = false;
- zdir = "z";
- sePoint = null;
- allQuads = false;
- allTriangle = false;
- allConvexPolygon = false;
- usingLight = true;
- }
-
- /**
- * Get if is 3D
- * @return Boolean
- */
- @Override
- public boolean is3D(){
- return true;
- }
-
- /**
- * Get if is fixed z graphics
- * @return Boolean
- */
- public boolean isFixZ(){
- return this.fixZ;
- }
-
- /**
- * Set if is fixed z graphics
- * @param value Boolean
- */
- public void setFixZ(boolean value){
- this.fixZ = value;
- }
-
- /**
- * Get fixed z value
- * @return Fixed z value
- */
- public double getZValue(){
- return this.zValue;
- }
-
- /**
- * Set fixed z value
- * @param value Fixed z value
- */
- public void setZValue(double value){
- this.zValue = value;
- }
-
- /**
- * Get z direction - x, y or z
- * @return Z direction
- */
- public String getZDir(){
- return this.zdir;
- }
-
- /**
- * Set z direction - x, y or z
- * @param value Z direction
- */
- public void setZDir(String value){
- this.zdir = value;
- }
-
- /**
- * Get start and end points [xstart, ystart, xend, yend]
- * @return Start and end points
- */
- public List getSEPoint(){
- return this.sePoint;
- }
-
- /**
- * Set start and end points
- * @param value Start and end points
- */
- public void setSEPoint(List value){
- this.sePoint = value;
- }
-
- /**
- * Get is all quads or not
- * @return All quads or not
- */
- public boolean isAllQuads() {
- return this.allQuads;
- }
-
- /**
- * Set is all quads or not
- * @param value All quads or not
- */
- public void setAllQuads(boolean value) {
- this.allQuads = value;
- }
-
- /**
- * Get is all triangle or not
- * @return All triangle or not
- */
- public boolean isAllTriangle() {
- return this.allTriangle;
- }
-
- /**
- * Set is all triangle or not
- * @param value All triangle or not
- */
- public void setAllTriangle(boolean value) {
- this.allTriangle = value;
- }
-
- /**
- * Get is all convex polygon or not
- * @return All convex polygon or not
- */
- public boolean isAllConvexPolygon() {
- if (this.allConvexPolygon) {
- return true;
- } else {
- return this.allQuads || this.allTriangle;
- }
- }
-
- /**
- * Set is all convex polygon or not
- * @param value All convex polygon or not
- */
- public void setAllConvexPolygon(boolean value) {
- this.allConvexPolygon = value;
- }
-
- /**
- * Get using light or not
- * @return Boolean
- */
- public boolean isUsingLight() {
- return this.usingLight;
- }
-
- /**
- * Set using light or not
- * @param value Boolean
- */
- public void setUsingLight(boolean value) {
- this.usingLight = value;
- }
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot3d/ImageShape3D.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot3d/ImageShape3D.java
deleted file mode 100644
index 57f9e4d1..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot3d/ImageShape3D.java
+++ /dev/null
@@ -1,58 +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.plot3d;
-
-import org.meteoinfo.geometry.shape.ImageShape;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class ImageShape3D extends ImageShape {
- private double zValue;
- private String zdir;
-
- /**
- * Constructor
- */
- public ImageShape3D(){
- super();
- this.zValue = 0;
- this.zdir = "z";
- }
-
- /**
- * Get fixed z value
- * @return Fixed z value
- */
- public double getZValue(){
- return this.zValue;
- }
-
- /**
- * Set fixed z value
- * @param value Fixed z value
- */
- public void setZValue(double value){
- this.zValue = value;
- }
-
- /**
- * Get z direction - x, y or z
- * @return Z direction
- */
- public String getZDir(){
- return this.zdir;
- }
-
- /**
- * Set z direction - x, y or z
- * @param value Z direction
- */
- public void setZDir(String value){
- this.zdir = value;
- }
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot3d/Projector.java b/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot3d/Projector.java
deleted file mode 100644
index 0debf382..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot3d/Projector.java
+++ /dev/null
@@ -1,548 +0,0 @@
-/*----------------------------------------------------------------------------------------*
- * Projector.java version 1.7 Nov 8 1996 *
- * Projector.java version 1.71 May 14 1997 *
- * *
- * Copyright (c) Yanto Suryono *
- * *
- * This program is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as published by the *
- * Free Software Foundation; either version 2 of the License, or (at your option) *
- * any later version. *
- * *
- * This program is distributed in the hope that it will be useful, but *
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for *
- * more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public License along *
- * with this program; if not, write to the Free Software Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- * *
- *----------------------------------------------------------------------------------------*/
-package org.meteoinfo.chart.plot3d;
-
-import org.meteoinfo.data.DataMath;
-
-import java.awt.Point;
-import java.awt.Rectangle;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * The class Projector projects points in 3D space to 2D space.
- *
- * @author Yanto Suryono
- */
-public final class Projector {
-
- private float scale_x, scale_y, scale_z; // 3D scaling factor
- private float distance; // distance to object
- private float _2D_scale_x, _2D_scale_y; // 2D scaling factor
- private float rotation, elevation; // rotation and elevation angle
- private float sin_rotation, cos_rotation; // sin and cos of rotation angle
- private float sin_elevation, cos_elevation; // sin and cos of elevation angle
- private int _2D_trans_x, _2D_trans_y; // 2D translation
- private int x1, x2, y1, y2; // projection area
- private int center_x, center_y; // center of projection area
-
- private int trans_x, trans_y;
- private float factor_x, factor_y;
- private float sx_cos, sy_cos, sz_cos;
- private float sx_sin, sy_sin, sz_sin;
-
- private final float DEGTORAD = (float) Math.PI / 180;
-
- //was static in SurfaceVertex ! now Dynamic in Projector
- float zmin, zmax;
- float zfactor;
-
- /**
- * The constructor of Projector.
- */
- public Projector() {
- setScaling(1);
- setRotationAngle(0);
- setElevationAngle(0);
- setDistance(10);
- set2DScaling(1);
- set2DTranslation(0, 0);
- }
-
- /**
- * Sets the projection area.
- *
- * @param r the projection area
- */
- public void setProjectionArea(Rectangle r) {
- x1 = r.x;
- x2 = x1 + r.width;
- y1 = r.y;
- y2 = y1 + r.height;
- center_x = (x1 + x2) / 2;
- center_y = (y1 + y2) / 2;
-
- trans_x = center_x + _2D_trans_x;
- trans_y = center_y + _2D_trans_y;
-
- this.update2DScaling();
- }
-
- /**
- * Sets the rotation angle.
- *
- * @param angle the rotation angle in degrees
- */
- public void setRotationAngle(float angle) {
- rotation = angle;
- sin_rotation = (float) Math.sin(angle * DEGTORAD);
- cos_rotation = (float) Math.cos(angle * DEGTORAD);
-
- sx_cos = -scale_x * cos_rotation;
- sx_sin = -scale_x * sin_rotation;
- sy_cos = -scale_y * cos_rotation;
- sy_sin = scale_y * sin_rotation;
- }
-
- /**
- * Gets current rotation angle.
- *
- * @return the rotation angle in degrees.
- */
- public float getRotationAngle() {
- return rotation;
- }
-
- /**
- * Gets the sine of rotation angle.
- *
- * @return the sine of rotation angle
- */
- public float getSinRotationAngle() {
- return sin_rotation;
- }
-
- /**
- * Gets the cosine of rotation angle.
- *
- * @return the cosine of rotation angle
- */
- public float getCosRotationAngle() {
- return cos_rotation;
- }
-
- /**
- * Sets the elevation angle.
- *
- * @param angle the elevation angle in degrees
- */
- public void setElevationAngle(float angle) {
- elevation = angle;
- sin_elevation = (float) Math.sin(angle * DEGTORAD);
- cos_elevation = (float) Math.cos(angle * DEGTORAD);
- sz_cos = scale_z * cos_elevation;
- sz_sin = scale_z * sin_elevation;
- }
-
- /**
- * Gets current elevation angle.
- *
- * @return the elevation angle in degrees.
- */
- public float getElevationAngle() {
- return elevation;
- }
-
- /**
- * Gets the sine of elevation angle.
- *
- * @return the sine of elevation angle
- */
- public float getSinElevationAngle() {
- return sin_elevation;
- }
-
- /**
- * Gets the cosine of elevation angle.
- *
- * @return the cosine of elevation angle
- */
- public float getCosElevationAngle() {
- return cos_elevation;
- }
-
- /**
- * Sets the projector distance.
- *
- * @param new_distance the new distance
- */
- public void setDistance(float new_distance) {
- distance = new_distance;
- factor_x = distance * _2D_scale_x;
- }
-
- /**
- * Gets the projector distance.
- *
- * @return the projector distance
- */
- public float getDistance() {
- return distance;
- }
-
- /**
- * Sets the scaling factor in x direction.
- *
- * @param scaling the scaling factor
- */
- public void setXScaling(float scaling) {
- scale_x = scaling;
- sx_cos = -scale_x * cos_rotation;
- sx_sin = -scale_x * sin_rotation;
- }
-
- /**
- * Gets the scaling factor in x direction.
- *
- * @return the scaling factor
- */
- public float getXScaling() {
- return scale_x;
- }
-
- /**
- * Sets the scaling factor in y direction.
- *
- * @param scaling the scaling factor
- */
- public void setYScaling(float scaling) {
- scale_y = scaling;
- sy_cos = -scale_y * cos_rotation;
- sy_sin = scale_y * sin_rotation;
- }
-
- /**
- * Gets the scaling factor in y direction.
- *
- * @return the scaling factor
- */
- public float getYScaling() {
- return scale_y;
- }
-
- /**
- * Sets the scaling factor in z direction.
- *
- * @param scaling the scaling factor
- */
- public void setZScaling(float scaling) {
- scale_z = scaling;
- sz_cos = scale_z * cos_elevation;
- sz_sin = scale_z * sin_elevation;
- }
-
- /**
- * Gets the scaling factor in z direction.
- *
- * @return the scaling factor
- */
- public float getZScaling() {
- return scale_z;
- }
-
- /**
- * Sets the scaling factor in all direction.
- *
- * @param x the scaling factor in x direction
- * @param y the scaling factor in y direction
- * @param z the scaling factor in z direction
- */
- public void setScaling(float x, float y, float z) {
- scale_x = x;
- scale_y = y;
- scale_z = z;
-
- sx_cos = -scale_x * cos_rotation;
- sx_sin = -scale_x * sin_rotation;
- sy_cos = -scale_y * cos_rotation;
- sy_sin = scale_y * sin_rotation;
- sz_cos = scale_z * cos_elevation;
- sz_sin = scale_z * sin_elevation;
- }
-
- /**
- * Sets the same scaling factor for all direction.
- *
- * @param scaling the scaling factor
- */
- public void setScaling(float scaling) {
- scale_x = scale_y = scale_z = scaling;
-
- sx_cos = -scale_x * cos_rotation;
- sx_sin = -scale_x * sin_rotation;
- sy_cos = -scale_y * cos_rotation;
- sy_sin = scale_y * sin_rotation;
- sz_cos = scale_z * cos_elevation;
- sz_sin = scale_z * sin_elevation;
- }
-
- /**
- * Sets the 2D scaling factor.
- *
- * @param scaling the scaling factor
- */
- public void set2DScaling(float scaling) {
- _2D_scale_x = scaling;
- _2D_scale_y = scaling;
- factor_x = distance * _2D_scale_x;
- factor_y = distance * _2D_scale_y;
- }
-
- /**
- * Sets the x 2D scaling factor.
- *
- * @param scaling the x scaling factor
- */
- public void setX2DScaling(float scaling) {
- _2D_scale_x = scaling;
- factor_x = distance * _2D_scale_x;
- }
-
- /**
- * Sets the 2D scaling factor.
- *
- * @param scaling the scaling factor
- */
- public void setY2DScaling(float scaling) {
- _2D_scale_y = scaling;
- factor_y = distance * _2D_scale_y;
- }
-
- /**
- * Gets the x 2D scaling factor.
- *
- * @return the x scaling factor
- */
- public float getX2DScaling() {
- return _2D_scale_x;
- }
-
- /**
- * Gets the x 2D scaling factor.
- *
- * @return the x scaling factor
- */
- public float getY2DScaling() {
- return _2D_scale_y;
- }
-
- /**
- * Sets the 2D translation.
- *
- * @param x the x translation
- * @param y the y translation
- */
- public void set2DTranslation(int x, int y) {
- _2D_trans_x = x;
- _2D_trans_y = y;
-
- trans_x = center_x + _2D_trans_x;
- trans_y = center_y + _2D_trans_y;
- }
-
- /**
- * Sets the 2D x translation.
- *
- * @param x the x translation
- */
- public void set2D_xTranslation(int x) {
- _2D_trans_x = x;
- trans_x = center_x + _2D_trans_x;
- }
-
- /**
- * Gets the 2D x translation.
- *
- * @return the x translation
- */
- public int get2D_xTranslation() {
- return _2D_trans_x;
- }
-
- /**
- * Sets the 2D y translation.
- *
- * @param y the y translation
- */
- public void set2D_yTranslation(int y) {
- _2D_trans_y = y;
- trans_y = center_y + _2D_trans_y;
- }
-
- /**
- * Gets the 2D y translation.
- *
- * @return the y translation
- */
- public int get2D_yTranslation() {
- return _2D_trans_y;
- }
-
- /**
- * Projects 3D points.
- *
- * @param x the x coordinate
- * @param y the y coordinate
- * @param z the z coordinate
- * @return Projected point
- */
- public final Point project(float x, float y, float z) {
- float temp;
-
- // rotates
- temp = x;
- x = x * sx_cos + y * sy_sin;
- y = temp * sx_sin + y * sy_cos;
-
- // elevates and projects
- //float temp_x = factor_x / (x * sin_elevation - z * sz_sin + distance);
- float temp_x = factor_x / (y * cos_elevation - z * sz_sin + distance);
- float temp_y = factor_y / (y * cos_elevation - z * sz_sin + distance);
- return new Point((int) (Math.round(x * temp_x) + trans_x),
- (int) (Math.round((y * sin_elevation + z * sz_cos) * -temp_y) + trans_y));
- }
-
- /**
- * Project angle and length from two points
- * @param x1 Point 1 x
- * @param y1 Point 1 y
- * @param z1 Point 1 z
- * @param x2 Point 2 x
- * @param y2 Point 2 y
- * @param z2 Point 2 z
- * @return Angle and length
- */
- public double[] projectAL(float x1, float y1, float z1, float x2, float y2, float z2){
- Point p1 = project(x1, y1, z1);
- Point p2 = project(x2, y2, z2);
- float u = p2.x - p1.x;
- float v = p2.y - p1.y;
- return DataMath.getDSFromUV(u, v);
- }
-
- /**
- * Projects 3D points without scaling.
- *
- * @param x the x coordinate
- * @param y the y coordinate
- * @param z the z coordinate
- * @return Projected point
- */
- public final Point project_noScale(float x, float y, float z) {
- float temp;
-
- // rotates
- temp = x;
- x = x * sx_cos + y * sy_sin;
- y = temp * sx_sin + y * sy_cos;
-
- // elevates and projects
- return new Point((int) (Math.round(x) + trans_x),
- (int) (Math.round((y * sin_elevation + z * sz_cos)) + trans_y));
- }
-
- public void setZRange(float zmin, float zmax) {
- this.zmin = zmin;
- this.zmax = zmax;
- this.zfactor = 20 / (zmax - zmin);
- }
-
- /**
- * Get bounds
- * @return Bounds rectangle
- */
- public Rectangle getBounds(){
- List ps = new ArrayList<>();
- ps.add(this.project(10, 10, 10));
- ps.add(this.project(-10, 10, 10));
- ps.add(this.project(10, -10, 10));
- ps.add(this.project(-10, -10, 10));
- ps.add(this.project(10, 10, -10));
- ps.add(this.project(-10, -10, -10));
- ps.add(this.project(-10, 10, -10));
- ps.add(this.project(10, -10, -10));
- int i = 0;
- int minx =0, miny = 0, maxx = 0, maxy = 0;
- for (Point p : ps){
- if (i == 0){
- minx = p.x;
- maxx = p.x;
- miny = p.y;
- maxy = p.y;
- } else {
- if (minx > p.x)
- minx = p.x;
- else if (maxx < p.x)
- maxx = p.x;
- if (miny > p.y)
- miny = p.y;
- else if (maxy < p.y)
- maxy = p.y;
- }
- i += 1;
- }
-
- return new Rectangle(minx, miny, maxx - minx, maxy - miny);
- }
-
- /**
- * Get bounds without scale
- * @return Bounds rectangle
- */
- public Rectangle getBounds_noScale(){
- List ps = new ArrayList<>();
- ps.add(this.project_noScale(10, 10, 10));
- ps.add(this.project_noScale(-10, 10, 10));
- ps.add(this.project_noScale(10, -10, 10));
- ps.add(this.project_noScale(-10, -10, 10));
- ps.add(this.project_noScale(10, 10, -10));
- ps.add(this.project_noScale(-10, -10, -10));
- ps.add(this.project_noScale(-10, 10, -10));
- ps.add(this.project_noScale(10, -10, -10));
- int i = 0;
- int minx =0, miny = 0, maxx = 0, maxy = 0;
- for (Point p : ps){
- if (i == 0){
- minx = p.x;
- maxx = p.x;
- miny = p.y;
- maxy = p.y;
- } else {
- if (minx > p.x)
- minx = p.x;
- else if (maxx < p.x)
- maxx = p.x;
- if (miny > p.y)
- miny = p.y;
- else if (maxy < p.y)
- maxy = p.y;
- }
- i += 1;
- }
-
- return new Rectangle(minx, miny, maxx - minx, maxy - miny);
- }
-
- /**
- * Update 2D scaling
- */
- public void update2DScaling(){
- Rectangle rect = this.getBounds();
- float s1 = (float)((x2 - x1) / rect.getWidth());
- float s2 = (float)((y2 - y1) / rect.getHeight());
- s1 = s1 * this._2D_scale_x;
- s2 = s2 * this._2D_scale_y;
- this.setX2DScaling(s1);
- this.setY2DScaling(s2);
- }
-
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/data/mapdata/FrmAttriData.java b/MeteoInfoLib/src/main/java/org/meteoinfo/data/mapdata/FrmAttriData.java
deleted file mode 100644
index 077dec8e..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/data/mapdata/FrmAttriData.java
+++ /dev/null
@@ -1,415 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.data.mapdata;
-
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.io.File;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.swing.JFrame;
-import javax.swing.JOptionPane;
-import javax.swing.table.JTableHeader;
-
-import com.formdev.flatlaf.extras.FlatSVGUtils;
-import org.meteoinfo.table.*;
-import org.meteoinfo.ndarray.DataType;
-import org.meteoinfo.layer.VectorLayer;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class FrmAttriData extends javax.swing.JFrame {
-
- private VectorLayer _layer;
- private DataTable _dataTable;
- private boolean _isEditing = false;
-
- /**
- * Creates new form FrmAttriData
- */
- public FrmAttriData() {
- initComponents();
-
- this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- this.setIconImages(FlatSVGUtils.createWindowIconImages("/org/meteoinfo/icons/table.svg"));
-
- //this.jTable1.setColumnSelectionAllowed(true);
- //this.jTable1.setRowSelectionAllowed(false);
- final JTableHeader header = this.jTable1.getTableHeader();
- header.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseReleased(MouseEvent e) {
-
- if (!e.isShiftDown()) {
- jTable1.clearSelection();
- }
-
- //Get column index of the mouse point
- int pick = header.columnAtPoint(e.getPoint());
-
- //set select model
- //jTable1.addColumnSelectionInterval(pick, pick);
- jTable1.setColumnSelectionAllowed(true);
- jTable1.setRowSelectionAllowed(false);
- jTable1.setColumnSelectionInterval(pick, pick);
-
- if (_isEditing) {
- jMenuItem_RemoveField.setEnabled(true);
- jMenuItem_RenameField.setEnabled(true);
- }
- }
- });
- this.jTable1.setDefaultEditor(Object.class, new MyCellEditor());
- this.jTable1.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseReleased(MouseEvent e) {
- jTable1.clearSelection();
- int pick = jTable1.rowAtPoint(e.getPoint());
- jTable1.setColumnSelectionAllowed(false);
- jTable1.setRowSelectionAllowed(true);
- jTable1.setRowSelectionInterval(pick, pick);
-
- if (jMenuItem_RemoveField.isEnabled()) {
- jMenuItem_RemoveField.setEnabled(false);
- }
- if (jMenuItem_RenameField.isEnabled()) {
- jMenuItem_RenameField.setEnabled(false);
- }
- }
- });
-
- this.jMenuItem_AddField.setEnabled(false);
- this.jMenuItem_RemoveField.setEnabled(false);
- this.jMenuItem_RenameField.setEnabled(false);
- this.jMenuItem_StopEdit.setEnabled(false);
- }
-
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // //GEN-BEGIN:initComponents
- private void initComponents() {
-
- jScrollPane1 = new javax.swing.JScrollPane();
- jTable1 = new javax.swing.JTable();
- jMenuBar1 = new javax.swing.JMenuBar();
- jMenu_Edit = new javax.swing.JMenu();
- jMenuItem_StartEdit = new javax.swing.JMenuItem();
- jMenuItem_StopEdit = new javax.swing.JMenuItem();
- jSeparator1 = new javax.swing.JPopupMenu.Separator();
- jMenuItem_AddField = new javax.swing.JMenuItem();
- jMenuItem_RemoveField = new javax.swing.JMenuItem();
- jMenuItem_RenameField = new javax.swing.JMenuItem();
-
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
-
- jTable1.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- {null, null, null, null},
- {null, null, null, null},
- {null, null, null, null},
- {null, null, null, null}
- },
- new String [] {
- "Title 1", "Title 2", "Title 3", "Title 4"
- }
- ));
- jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
- jScrollPane1.setViewportView(jTable1);
-
- jMenu_Edit.setText("Edit");
-
- jMenuItem_StartEdit.setText("Start Edit");
- jMenuItem_StartEdit.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem_StartEditActionPerformed(evt);
- }
- });
- jMenu_Edit.add(jMenuItem_StartEdit);
-
- jMenuItem_StopEdit.setText("Stop Edit");
- jMenuItem_StopEdit.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem_StopEditActionPerformed(evt);
- }
- });
- jMenu_Edit.add(jMenuItem_StopEdit);
- jMenu_Edit.add(jSeparator1);
-
- jMenuItem_AddField.setText("Add Field");
- jMenuItem_AddField.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem_AddFieldActionPerformed(evt);
- }
- });
- jMenu_Edit.add(jMenuItem_AddField);
-
- jMenuItem_RemoveField.setText("Remove Field");
- jMenuItem_RemoveField.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem_RemoveFieldActionPerformed(evt);
- }
- });
- jMenu_Edit.add(jMenuItem_RemoveField);
-
- jMenuItem_RenameField.setText("Rename Field");
- jMenuItem_RenameField.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem_RenameFieldActionPerformed(evt);
- }
- });
- jMenu_Edit.add(jMenuItem_RenameField);
-
- jMenuBar1.add(jMenu_Edit);
-
- setJMenuBar(jMenuBar1);
-
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 580, Short.MAX_VALUE)
- .addGap(0, 0, 0))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE)
- .addGap(0, 0, 0))
- );
-
- pack();
- }// //GEN-END:initComponents
-
- private void jMenuItem_StartEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_StartEditActionPerformed
- // TODO add your handling code here:
- this.jMenuItem_StartEdit.setEnabled(false);
- this.jMenuItem_AddField.setEnabled(true);
- this.jMenuItem_StopEdit.setEnabled(true);
- if (this.jTable1.getSelectedColumnCount() > 0) {
- this.jMenuItem_RemoveField.setEnabled(true);
- this.jMenuItem_RenameField.setEnabled(true);
- }
- this._isEditing = true;
-
- DataTableModel dataTableModel = new DataTableModel(_dataTable) {
- @Override
- public boolean isCellEditable(int row, int column) {
- return true;
- }
- };
- this.jTable1.setModel(dataTableModel);
- }//GEN-LAST:event_jMenuItem_StartEditActionPerformed
-
- private void jMenuItem_StopEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_StopEditActionPerformed
- // TODO add your handling code here:
- this.jMenuItem_StartEdit.setEnabled(true);
- this.jMenuItem_AddField.setEnabled(false);
- this.jMenuItem_RemoveField.setEnabled(false);
- this.jMenuItem_RenameField.setEnabled(false);
- this.jMenuItem_StopEdit.setEnabled(false);
- this._isEditing = false;
-
- int result = JOptionPane.showConfirmDialog(null, "If save the edition?", "Confirm", JOptionPane.YES_NO_OPTION);
- if (result == JOptionPane.YES_OPTION) {
- this.saveDataTable();
- } else {
- _dataTable = _layer.getAttributeTable().getTable().cloneTable_Field();
- }
-
- DataTableModel dataTableModel = new DataTableModel(_dataTable) {
- @Override
- public boolean isCellEditable(int row, int column) {
- return false;
- }
- };
- this.jTable1.setModel(dataTableModel);
- }//GEN-LAST:event_jMenuItem_StopEditActionPerformed
-
- private void jMenuItem_AddFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_AddFieldActionPerformed
- // TODO add your handling code here:
- FrmAddField frmField = new FrmAddField(null, true);
- frmField.setLocationRelativeTo(this);
- frmField.setVisible(true);
- if (frmField.isOK()) {
- String fieldName = frmField.getFieldName();
- if (fieldName.isEmpty()) {
- JOptionPane.showMessageDialog(null, "Field name is empty!");
- return;
- }
- List fieldNames = _layer.getFieldNames();
- if (fieldNames.contains(fieldName)) {
- JOptionPane.showMessageDialog(null, "Field name has exist in the data table!");
- return;
- }
- DataType dataType = frmField.getDataType();
- try {
- _dataTable.addColumn(new Field(fieldName, dataType));
- //this.jTable1.revalidate();
- DataTableModel dataTableModel = new DataTableModel(_dataTable) {
- @Override
- public boolean isCellEditable(int row, int column) {
- return true;
- }
- };
- this.jTable1.setModel(dataTableModel);
- } catch (Exception ex) {
- Logger.getLogger(FrmAttriData.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }//GEN-LAST:event_jMenuItem_AddFieldActionPerformed
-
- private void jMenuItem_RemoveFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_RemoveFieldActionPerformed
- // TODO add your handling code here:
- if (this.jTable1.getSelectedColumnCount() == 0) {
- JOptionPane.showMessageDialog(null, "Please select one field firstly!");
- return;
- }
-
- int fieldIdx = this.jTable1.getSelectedColumn();
- String fieldName = this.jTable1.getColumnName(fieldIdx);
- int result = JOptionPane.showConfirmDialog(null, "If remove the field: " + fieldName + "?", "Confirm",
- JOptionPane.YES_NO_OPTION);
- if (result == JOptionPane.YES_OPTION) {
- _dataTable.removeColumn(_dataTable.getColumns().get(fieldName));
- DataTableModel dataTableModel = new DataTableModel(_dataTable) {
- @Override
- public boolean isCellEditable(int row, int column) {
- return true;
- }
- };
- this.jTable1.setModel(dataTableModel);
- }
- }//GEN-LAST:event_jMenuItem_RemoveFieldActionPerformed
-
- private void jMenuItem_RenameFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_RenameFieldActionPerformed
- // TODO add your handling code here:
- if (this.jTable1.getSelectedColumnCount() == 0) {
- JOptionPane.showMessageDialog(null, "Please select one field firstly!");
- return;
- }
-
- int fieldIdx = this.jTable1.getSelectedColumn();
- String fieldName = this.jTable1.getColumnName(fieldIdx);
- String result = JOptionPane.showInputDialog(this, "Please input new field name:", fieldName);
- if (result != null) {
- if (result.isEmpty()){
- JOptionPane.showMessageDialog(null, "The field name is empty!");
- return;
- }
- List fieldNames = _dataTable.getColumnNames();
- if (fieldNames.contains(result)){
- JOptionPane.showMessageDialog(null, "The field name is exist!");
- return;
- }
- _dataTable.renameColumn(_dataTable.getColumns().get(fieldName), result);
- DataTableModel dataTableModel = new DataTableModel(_dataTable) {
- @Override
- public boolean isCellEditable(int row, int column) {
- return true;
- }
- };
- this.jTable1.setModel(dataTableModel);
- }
- }//GEN-LAST:event_jMenuItem_RenameFieldActionPerformed
-
- /**
- * Set vector layer
- *
- * @param aLayer The vector layer
- */
- public void setLayer(VectorLayer aLayer) {
- _layer = aLayer;
- _dataTable = _layer.getAttributeTable().getTable().cloneTable_Field();
- this.setTitle("Attribute Data - " + _layer.getLayerName());
- DataTableModel dataTableModel = new DataTableModel(_dataTable);
- this.jTable1.setModel(dataTableModel);
- this.jScrollPane1.setRowHeaderView(new RowHeaderTable(this.jTable1, 40));
- }
-
- private void saveDataTable() {
-// for (int i = 0; i < _layer.getFieldNumber(); i++){
-// for (int j = 0; j < _layer.getShapeNum(); j++){
-// _layer.editCellValue(i, j, this.jTable1.getModel().getValueAt(j, i));
-// }
-// }
-
- _layer.getAttributeTable().setTable(_dataTable.cloneTable_Field());
- if (new File(_layer.getFileName()).exists())
- _layer.getAttributeTable().save();
- else
- _layer.saveFile();
- }
-
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(FrmAttriData.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(FrmAttriData.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(FrmAttriData.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(FrmAttriData.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //
-
- /* Create and display the dialog */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- FrmAttriData dialog = new FrmAttriData();
- dialog.addWindowListener(new java.awt.event.WindowAdapter() {
- @Override
- public void windowClosing(java.awt.event.WindowEvent e) {
- System.exit(0);
- }
- });
- dialog.setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JMenuBar jMenuBar1;
- private javax.swing.JMenuItem jMenuItem_AddField;
- private javax.swing.JMenuItem jMenuItem_RemoveField;
- private javax.swing.JMenuItem jMenuItem_RenameField;
- private javax.swing.JMenuItem jMenuItem_StartEdit;
- private javax.swing.JMenuItem jMenuItem_StopEdit;
- private javax.swing.JMenu jMenu_Edit;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JPopupMenu.Separator jSeparator1;
- private javax.swing.JTable jTable1;
- // End of variables declaration//GEN-END:variables
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/data/mapdata/MapDataManage.java b/MeteoInfoLib/src/main/java/org/meteoinfo/data/mapdata/MapDataManage.java
deleted file mode 100644
index 81eee517..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/data/mapdata/MapDataManage.java
+++ /dev/null
@@ -1,747 +0,0 @@
-/* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.data.mapdata;
-
-import org.meteoinfo.common.DataConvert;
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.common.PointD;
-import org.meteoinfo.common.util.GlobalUtil;
-import org.meteoinfo.data.GridArray;
-import org.meteoinfo.data.GridData;
-import org.meteoinfo.data.mapdata.geotiff.GeoTiff;
-import org.meteoinfo.data.meteodata.DrawMeteoData;
-import org.meteoinfo.geometry.legend.LegendScheme;
-import org.meteoinfo.geometry.legend.LegendType;
-import org.meteoinfo.geoprocess.GeometryUtil;
-import org.meteoinfo.ndarray.DataType;
-import org.meteoinfo.layer.ImageLayer;
-import org.meteoinfo.layer.LayerDrawType;
-import org.meteoinfo.layer.MapLayer;
-import org.meteoinfo.layer.VectorLayer;
-import org.meteoinfo.layer.WorldFilePara;
-import org.meteoinfo.legend.LegendManage;
-import org.meteoinfo.geometry.shape.PolylineShape;
-import org.meteoinfo.geometry.shape.ShapeTypes;
-import java.awt.Color;
-import java.awt.image.BufferedImage;
-import java.io.BufferedInputStream;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.imageio.ImageIO;
-import javax.swing.JOptionPane;
-
-import org.meteoinfo.data.meteodata.ascii.ASCIIGridDataInfo;
-import org.meteoinfo.data.meteodata.ascii.SurferGridDataInfo;
-import org.meteoinfo.data.meteodata.bandraster.BILDataInfo;
-import org.meteoinfo.common.io.IOUtil;
-import org.meteoinfo.layer.RasterLayer;
-import org.meteoinfo.projection.KnownCoordinateSystems;
-import org.meteoinfo.projection.ProjectionInfo;
-import org.meteoinfo.geometry.shape.PointShape;
-import org.meteoinfo.geometry.shape.PolygonShape;
-import org.meteoinfo.geometry.shape.Shape;
-import org.meteoinfo.ndarray.Array;
-import org.meteoinfo.table.Field;
-
-/**
- *
- * @author yaqiang
- */
-public class MapDataManage {
-
- /**
- * Can open or not as a map layer
- *
- * @param fileName File name
- * @return MapDataType
- * @throws java.io.FileNotFoundException
- */
- public static MapDataType canOpen(String fileName) throws FileNotFoundException, IOException {
- MapDataType mdt = null;
- if (new File(fileName).isFile()) {
- String ext = GlobalUtil.getFileExtension(fileName);
- switch (ext.toLowerCase()) {
- case "shp":
- mdt = MapDataType.SHAPE;
- break;
- case "wmp":
- mdt = MapDataType.WMP;
- break;
- case "bmp":
- case "gif":
- case "jpg":
- case "png":
- mdt = MapDataType.IMAGE;
- break;
- case "tif":
- mdt = MapDataType.GEO_TIFF;
- break;
- case "bil":
- case "bip":
- case "bsq":
- mdt = MapDataType.BIL;
- break;
- default:
- RandomAccessFile br = new RandomAccessFile(fileName, "r");
- byte[] bytes = new byte[100];
- br.read(bytes);
- String line = new String(bytes).trim().toUpperCase();
- br.close();
- if (line.contains("NCOLS")) {
- mdt = MapDataType.ESRI_ASCII_GRID;
- } else if (line.contains("DSAA")) {
- mdt = MapDataType.SURFER_ASCII_GRID;
- } else {
- mdt = MapDataType.GRADS;
- }
- break;
- }
- }
-
- return mdt;
- }
-
- /**
- * Load a layer from a file
- *
- * @param aFile The file path
- * @return The layer
- * @throws java.io.IOException
- * @throws java.io.FileNotFoundException
- */
- public static MapLayer loadLayer(String aFile) throws IOException, FileNotFoundException, Exception {
- MapDataType mdt = canOpen(aFile);
- if (mdt == null) {
- return null;
- }
-
- MapLayer aLayer = null;
- switch (mdt) {
- case SHAPE:
- aLayer = readMapFile_ShapeFile(aFile);
- break;
- case WMP:
- aLayer = readMapFile_WMP(aFile);
- break;
- case IMAGE:
- aLayer = readImageFile(aFile);
- break;
- case GEO_TIFF:
- aLayer = readGeoTiffFile(aFile);
- break;
- case BIL:
- aLayer = readBILFile(aFile);
- break;
- case ESRI_ASCII_GRID:
- aLayer = readESRI_ASCII_GRID(aFile);
- break;
- case SURFER_ASCII_GRID:
- aLayer = readSurfer_ASCII_GRID(aFile);
- break;
- case GRADS:
- aLayer = readMapFile_GrADS(aFile);
- break;
- }
-
- if (aLayer != null) {
- switch (mdt) {
- case BIL:
- case ESRI_ASCII_GRID:
- case SURFER_ASCII_GRID:
- String projFn = aFile.substring(0, aFile.length() - 4) + ".prj";
- File pFile = new File(projFn);
- if (pFile.isFile()) {
- ProjectionInfo projInfo = ShapeFileManage.loadProjFile(pFile);
- aLayer.setProjInfo(projInfo);
- }
- break;
- }
- }
-
- return aLayer;
- }
-
- /**
- * Load a layer from a file with a certain projection
- *
- * @param aFile The file name
- * @param projInfo The projection
- * @return The layer
- * @throws IOException
- * @throws FileNotFoundException
- * @throws Exception
- */
- public static MapLayer loadLayer(String aFile, ProjectionInfo projInfo) throws IOException, FileNotFoundException, Exception {
- MapLayer layer = loadLayer(aFile);
- layer.setProjInfo(projInfo);
-
- return layer;
- }
-
- /**
- * Read shape file as map
- *
- * @param fn File name
- * @return Vector layer
- * @throws java.io.IOException
- * @throws java.io.FileNotFoundException
- */
- public static VectorLayer readMapFile_ShapeFile(String fn) throws IOException, FileNotFoundException, Exception {
- String encoding = IOUtil.encodingDetectShp(fn);
- if (encoding.equals("ISO8859_1")) {
- encoding = "UTF-8";
- }
-
- return readMapFile_ShapeFile(fn, encoding);
- }
-
- /**
- * Read shape file as map
- *
- * @param aFile File name
- * @param encoding Encoding
- * @return Vector layer
- * @throws java.io.IOException
- * @throws java.io.FileNotFoundException
- */
- public static VectorLayer readMapFile_ShapeFile(String aFile, String encoding) throws IOException, FileNotFoundException, Exception {
- VectorLayer aLayer = ShapeFileManage.loadShapeFile(aFile, encoding);
-
- return aLayer;
- }
-
- /**
- * Read GrADS map file
- *
- * @param aFile The file path
- * @return The layer
- * @throws java.io.FileNotFoundException
- */
- public static VectorLayer readMapFile_GrADS(String aFile) throws FileNotFoundException, IOException, Exception {
- DataInputStream br = new DataInputStream(new BufferedInputStream(new FileInputStream(new File(aFile))));
- int i, lineNum;
- byte b;
- short N, lType;
- double lon, lat;
- byte[] bytes;
-
- PointD aPoint;
- List pList = new ArrayList<>();
-
- VectorLayer aLayer = new VectorLayer(ShapeTypes.Polyline);
- String columnName = "Value";
- Field aDC = new Field(columnName, DataType.INT);
- aLayer.editAddField(aDC);
-
- lineNum = 0;
- do {
- b = br.readByte(); // 1-data, 2-skip
- if ("2".equals(Byte.toString(b))) {
- br.skipBytes(18);
- continue;
- }
- b = br.readByte(); // Line type: country, river ...
- lType = (short) DataConvert.byte2Int(b);
- b = br.readByte(); // Point number
- N = (short) DataConvert.byte2Int(b);
- for (i = 0; i < N; i++) {
- bytes = new byte[3];
- br.read(bytes); //Longitude
- int val = 0;
- for (int bb = 0; bb < 3; bb++) {
- val <<= 8;
- val |= (int) bytes[bb] & 0xFF;
- }
- lon = val / 10000.0;
-
- bytes = new byte[3];
- br.read(bytes); //Latitude
- val = 0;
- for (int bb = 0; bb < 3; bb++) {
- val <<= 8;
- val |= (int) bytes[bb] & 0xFF;
- }
- lat = val / 10000.0 - 90.0;
-
- aPoint = new PointD();
- aPoint.X = lon;
- aPoint.Y = lat;
- pList.add(aPoint);
- }
- if (pList.size() > 1) {
- PolylineShape aPolyline = new PolylineShape();
- aPolyline.setValue(lineNum);
- aPolyline.setPoints(pList);
- aPolyline.setExtent(GeometryUtil.getPointsExtent(pList));
- aPolyline.setPartNum(1);
- aPolyline.parts = new int[1];
- aPolyline.parts[0] = 0;
-
- int shapeNum = aLayer.getShapeNum();
- if (aLayer.editInsertShape(aPolyline, shapeNum)) {
- aLayer.editCellValue(columnName, shapeNum, lineNum);
- }
-
- lineNum++;
- }
- pList = new ArrayList<>();
-
- } while (br.available() > 0);
-
- br.close();
-
- aLayer.setLayerName(new File(aFile).getName());
- aLayer.setFileName(aFile);
- aLayer.setLayerDrawType(LayerDrawType.Map);
- aLayer.setLegendScheme(LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Polyline, Color.darkGray, 1.0F));
- aLayer.setVisible(true);
-
- return aLayer;
- }
-
- /**
- * Read image file
- *
- * @param aFile File path
- * @return Image layer
- * @throws java.io.IOException
- */
- public static ImageLayer readImageFile(String aFile) throws IOException {
- String oEx = aFile.substring(aFile.lastIndexOf("."));
- String last = oEx.substring(oEx.length() - 1);
- String sEx = oEx.substring(0, oEx.length() - 2) + last;
- sEx = sEx + "w";
- String wFile = aFile.replace(oEx, sEx);
- BufferedImage aImage = ImageIO.read(new File(aFile));
- ImageLayer aImageLayer = new ImageLayer();
- aImageLayer.setFileName(aFile);
- aImageLayer.setWorldFileName(wFile);
- aImageLayer.setImage(aImage);
- aImageLayer.setLayerName(new File(aFile).getName());
- aImageLayer.setVisible(true);
- if (new File(wFile).exists()) {
- aImageLayer.readImageWorldFile(wFile);
- } else {
- WorldFilePara aWFP = new WorldFilePara();
- aWFP.xUL = 0;
- aWFP.yUL = 90;
- aWFP.xScale = 0.05;
- aWFP.yScale = -0.05;
- aWFP.xRotate = 0;
- aWFP.yRotate = 0;
- aImageLayer.setWorldFilePara(aWFP);
- aImageLayer.writeImageWorldFile(wFile, aImageLayer.getWorldFilePara());
- }
-
- double XBR, YBR;
- XBR = aImageLayer.getImage().getWidth() * aImageLayer.getWorldFilePara().xScale + aImageLayer.getWorldFilePara().xUL;
- YBR = aImageLayer.getImage().getHeight() * aImageLayer.getWorldFilePara().yScale + aImageLayer.getWorldFilePara().yUL;
- Extent aExtent = new Extent();
- aExtent.minX = aImageLayer.getWorldFilePara().xUL;
- aExtent.minY = YBR;
- aExtent.maxX = XBR;
- aExtent.maxY = aImageLayer.getWorldFilePara().yUL;
- aImageLayer.setExtent(aExtent);
- aImageLayer.setLayerDrawType(LayerDrawType.Image);
- aImageLayer.setMaskout(true);
-
- return aImageLayer;
- }
-
- /**
- * Create a raster layer from geotiff file
- *
- * @param fileName File path
- * @return Raster layer
- */
- public static RasterLayer readGeoTiffFile(String fileName) {
- try {
- GeoTiff geoTiff = new GeoTiff(fileName);
- geoTiff.read();
- GridArray gData = geoTiff.getGridArray();
-// LegendScheme aLS = LegendManage.createLegendSchemeFromGridData(gData, LegendType.GraduatedColor,
-// ShapeTypes.Image);
- RasterLayer aLayer = DrawMeteoData.createRasterLayer(gData, new File(fileName).getName());
- aLayer.setProjInfo(gData.projInfo);
- aLayer.setFileName(fileName);
-
- return aLayer;
- } catch (IOException ex) {
- Logger.getLogger(MapDataManage.class.getName()).log(Level.SEVERE, null, ex);
- return null;
- }
- }
-
- /**
- * Read BIL file and create a raster layer
- *
- * @param fileName BIL file name
- * @return Raster layer
- */
- public static RasterLayer readBILFile(String fileName) {
- BILDataInfo dataInfo = new BILDataInfo();
- dataInfo.readDataInfo(fileName);
- //GridData gData = dataInfo.getGridData_LonLat(0, 0, 0);
- Array a = dataInfo.read(dataInfo.getVariableNames().get(0));
- GridArray data = new GridArray();
- data.setData(a);
- data.xArray = dataInfo.getXDimension().getValues();
- data.yArray = dataInfo.getYDimension().getValues();
- data.missingValue = dataInfo.getMissingValue();
- LegendScheme aLS = LegendManage.createLegendSchemeFromGridData(data, LegendType.GraduatedColor,
- ShapeTypes.Image);
- RasterLayer aLayer = DrawMeteoData.createRasterLayer(data, new File(fileName).getName(), aLS);
- aLayer.setFileName(fileName);
-
- return aLayer;
- }
-
- /**
- * Read ESRI ASCII grid file and create a raster layer
- *
- * @param fileName File name
- * @return Raster layer
- */
- public static RasterLayer readESRI_ASCII_GRID(String fileName) {
- ASCIIGridDataInfo dataInfo = new ASCIIGridDataInfo();
- dataInfo.readDataInfo(fileName);
- GridArray gData = dataInfo.getGridArray("var");
- RasterLayer aLayer = DrawMeteoData.createRasterLayer(gData, new File(fileName).getName());
- aLayer.setProjInfo(KnownCoordinateSystems.geographic.world.WGS1984);
- aLayer.setFileName(fileName);
-
- return aLayer;
- }
-
- /**
- * Read surfer ASCII grid file and create a raster layer
- *
- * @param fileName File name
- * @return Raster layer
- */
- public static RasterLayer readSurfer_ASCII_GRID(String fileName) {
- SurferGridDataInfo dataInfo = new SurferGridDataInfo();
- dataInfo.readDataInfo(fileName);
- GridData gData = dataInfo.getGridData_LonLat(0, "var", 0);
- LegendScheme aLS = LegendManage.createLegendSchemeFromGridData(gData, LegendType.GraduatedColor,
- ShapeTypes.Image);
- RasterLayer aLayer = DrawMeteoData.createRasterLayer(gData, new File(fileName).getName(), aLS);
- aLayer.setFileName(fileName);
-
- return aLayer;
- }
-
- /**
- * Read WMP file
- *
- * @param fileName The file name
- * @return Created vector layer
- * @throws java.io.IOException
- */
- public static VectorLayer readMapFile_WMP(String fileName) throws IOException, Exception {
- BufferedReader sr = null;
- try {
- File file = new File(fileName);
- sr = new BufferedReader(new FileReader(file));
- String aLine;
- String shapeType;
- String[] dataArray;
- int shapeNum;
- int i, j, pNum;
- List pList = new ArrayList<>();
- PointD aPoint;
- boolean IsTrue;
- String columnName = "Value";
- VectorLayer aLayer = new VectorLayer(ShapeTypes.Point);
- //Read shape type
- shapeType = sr.readLine().trim().toLowerCase();
- //Read shape number
- shapeNum = Integer.parseInt(sr.readLine());
- switch (shapeType) {
- case "point":
- aLayer = new VectorLayer(ShapeTypes.Point);
- aLayer.editAddField(columnName, DataType.INT);
- for (i = 0; i < shapeNum; i++) {
- aLine = sr.readLine();
- dataArray = aLine.split(",");
- aPoint = new PointD();
- aPoint.X = Double.parseDouble(dataArray[0]);
- aPoint.Y = Double.parseDouble(dataArray[1]);
- pList.add(aPoint);
- PointShape aPS = new PointShape();
- aPS.setValue(i);
- aPS.setPoint(aPoint);
-
- int sNum = aLayer.getShapeNum();
- if (aLayer.editInsertShape(aPS, sNum)) {
- aLayer.editCellValue(columnName, sNum, i);
- }
- }
- aLayer.setLayerName(file.getName());
- aLayer.setFileName(fileName);
- aLayer.setLayerDrawType(LayerDrawType.Map);
- aLayer.setLegendScheme(LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Point, Color.black, 5));
- aLayer.setVisible(true);
- IsTrue = true;
- break;
- case "polyline":
- aLayer = new VectorLayer(ShapeTypes.Polyline);
- aLayer.editAddField(columnName, DataType.INT);
- for (i = 0; i < shapeNum; i++) {
- pNum = Integer.parseInt(sr.readLine());
- pList = new ArrayList<>();
- for (j = 0; j < pNum; j++) {
- aLine = sr.readLine();
- dataArray = aLine.split(",");
- aPoint = new PointD();
- aPoint.X = Double.parseDouble(dataArray[0]);
- aPoint.Y = Double.parseDouble(dataArray[1]);
- pList.add(aPoint);
- }
- PolylineShape aPLS = new PolylineShape();
- aPLS.setValue(i);
- aPLS.setExtent(GeometryUtil.getPointsExtent(pList));
- aPLS.setPoints(pList);
-
- int sNum = aLayer.getShapeNum();
- if (aLayer.editInsertShape(aPLS, sNum)) {
- aLayer.editCellValue(columnName, sNum, i);
- }
- }
- aLayer.setLayerName(file.getName());
- aLayer.setFileName(fileName);
- aLayer.setLayerDrawType(LayerDrawType.Map);
- aLayer.setLegendScheme(LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Polyline, Color.darkGray, 1.0F));
- aLayer.setVisible(true);
- IsTrue = true;
- break;
- case "polygon":
- aLayer = new VectorLayer(ShapeTypes.Polygon);
- aLayer.editAddField(columnName, DataType.INT);
- //ArrayList polygons = new ArrayList();
- for (i = 0; i < shapeNum; i++) {
- pNum = Integer.parseInt(sr.readLine());
- pList = new ArrayList<>();
- for (j = 0; j < pNum; j++) {
- aLine = sr.readLine();
- dataArray = aLine.split(",");
- aPoint = new PointD();
- aPoint.X = Double.parseDouble(dataArray[0]);
- aPoint.Y = Double.parseDouble(dataArray[1]);
- pList.add(aPoint);
- }
- PolygonShape aPGS = new PolygonShape();
- aPGS.lowValue = i;
- aPGS.highValue = i;
- aPGS.setExtent(GeometryUtil.getPointsExtent(pList));
- aPGS.setPoints(pList);
-
- int sNum = aLayer.getShapeNum();
- if (aLayer.editInsertShape(aPGS, sNum)) {
- aLayer.editCellValue(columnName, sNum, i);
- }
- }
- aLayer.setLayerName(file.getName());
- aLayer.setFileName(fileName);
- aLayer.setLayerDrawType(LayerDrawType.Map);
- aLayer.setLegendScheme(LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Polygon, new Color(255, 251, 195), 1.0F));
- aLayer.setVisible(true);
- IsTrue = true;
- break;
- default:
- JOptionPane.showMessageDialog(null, "Shape type is invalid!" + System.getProperty("line.separator")
- + shapeType);
- IsTrue = false;
- break;
- }
- sr.close();
- if (IsTrue) {
- return aLayer;
- } else {
- return null;
- }
- } catch (FileNotFoundException ex) {
- Logger.getLogger(MapDataManage.class.getName()).log(Level.SEVERE, null, ex);
- return null;
- } finally {
- try {
- if (sr != null) {
- sr.close();
- }
- } catch (IOException ex) {
- Logger.getLogger(MapDataManage.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
-
- /**
- * Write WMP file
- *
- * @param fileName The file name
- * @param shapes Shapes
- */
- public static void writeMapFile_WMP(String fileName, List shapes) {
- BufferedWriter sw = null;
- try {
- File file = new File(fileName);
- sw = new BufferedWriter(new FileWriter(file));
- int shpNum = shapes.size();
- int i;
- switch (shapes.get(0).getShapeType()) {
- case Point:
- sw.write("Point");
- sw.newLine();
- sw.write(String.valueOf(shpNum));
- sw.newLine();
- PointShape aPS;
- for (i = 0; i < shpNum; i++) {
- aPS = (PointShape) shapes.get(i);
- if (aPS.isSelected()) {
- sw.write(String.valueOf(aPS.getPoint().X) + "," + String.valueOf(aPS.getPoint().Y));
- sw.newLine();
- }
- }
- break;
- case Polyline:
- case PolylineZ:
- sw.write("Polyline");
- sw.newLine();
- int shapeNum = 0;
- PolylineShape aPLS;
- for (i = 0; i < shpNum; i++) {
- aPLS = (PolylineShape) shapes.get(i);
- shapeNum += aPLS.getPartNum();
- }
- sw.write(String.valueOf(shapeNum));
- sw.newLine();
-
- shapeNum = 0;
- for (i = 0; i < shpNum; i++) {
- aPLS = (PolylineShape) shapes.get(i);
- PointD[] Pointps;
- for (int p = 0; p < aPLS.getPartNum(); p++) {
- if (p == aPLS.getPartNum() - 1) {
- Pointps = new PointD[aPLS.getPointNum() - aPLS.parts[p]];
- for (int pp = aPLS.parts[p]; pp < aPLS.getPointNum(); pp++) {
- Pointps[pp - aPLS.parts[p]] = (PointD) aPLS.getPoints().get(pp);
- }
- } else {
- Pointps = new PointD[aPLS.parts[p + 1] - aPLS.parts[p]];
- for (int pp = aPLS.parts[p]; pp < aPLS.parts[p + 1]; pp++) {
- Pointps[pp - aPLS.parts[p]] = (PointD) aPLS.getPoints().get(pp);
- }
- }
- sw.write(String.valueOf(Pointps.length));
- sw.newLine();
- for (PointD aPoint : Pointps) {
- sw.write(String.valueOf(aPoint.X) + "," + String.valueOf(aPoint.Y));
- sw.newLine();
- }
- shapeNum += 1;
- }
- }
- break;
- case Polygon:
- sw.write("Polygon");
- sw.newLine();
- shapeNum = 0;
- PolygonShape aPGS;
- for (i = 0; i < shpNum; i++) {
- aPGS = (PolygonShape) shapes.get(i);
- shapeNum += aPGS.getPartNum();
- }
- sw.write(String.valueOf(shapeNum));
- sw.newLine();
-
- shapeNum = 0;
- for (i = 0; i < shpNum; i++) {
- aPGS = (PolygonShape) shapes.get(i);
-
- PointD[] Pointps;
- for (int p = 0; p < aPGS.getPartNum(); p++) {
- if (p == aPGS.getPartNum() - 1) {
- Pointps = new PointD[aPGS.getPointNum() - aPGS.parts[p]];
- for (int pp = aPGS.parts[p]; pp < aPGS.getPointNum(); pp++) {
- Pointps[pp - aPGS.parts[p]] = (PointD) aPGS.getPoints().get(pp);
- }
- } else {
- Pointps = new PointD[aPGS.parts[p + 1] - aPGS.parts[p]];
- for (int pp = aPGS.parts[p]; pp < aPGS.parts[p + 1]; pp++) {
- Pointps[pp - aPGS.parts[p]] = (PointD) aPGS.getPoints().get(pp);
- }
- }
- sw.write(String.valueOf(Pointps.length));
- sw.newLine();
- for (PointD aPoint : Pointps) {
- sw.write(String.valueOf(aPoint.X) + "," + String.valueOf(aPoint.Y));
- sw.newLine();
- }
- shapeNum += 1;
- }
- }
- break;
- }
- sw.close();
- } catch (IOException ex) {
- Logger.getLogger(MapDataManage.class.getName()).log(Level.SEVERE, null, ex);
- } finally {
- try {
- if (sw != null) {
- sw.close();
- }
- } catch (IOException ex) {
- Logger.getLogger(MapDataManage.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
-
- /**
- * Write projection file
- *
- * @param projFilePath Projection file path
- * @param projInfo Projection info
- */
- public static void writeProjFile(String projFilePath, ProjectionInfo projInfo) {
- BufferedWriter sw = null;
- try {
- String esriString = projInfo.toEsriString();
- sw = new BufferedWriter(new FileWriter(new File(projFilePath)));
- sw.write(esriString);
- sw.flush();
- sw.close();
- } catch (IOException ex) {
- Logger.getLogger(ShapeFileManage.class.getName()).log(Level.SEVERE, null, ex);
- } finally {
- try {
- if (sw != null) {
- sw.close();
- }
- } catch (IOException ex) {
- Logger.getLogger(ShapeFileManage.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/drawing/ContourDraw.java b/MeteoInfoLib/src/main/java/org/meteoinfo/drawing/ContourDraw.java
deleted file mode 100644
index dae1da75..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/drawing/ContourDraw.java
+++ /dev/null
@@ -1,140 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.drawing;
-
-import org.meteoinfo.common.MIMath;
-
-import java.util.List;
-
-/**
- * Template
- *
- * @author Yaqiang Wang
- */
-public class ContourDraw {
- //
- //
- //
- //
- //
- //
- //
-
- /**
- * Tracing contour borders
- *
- * @param gridData Grid data
- * @param X X array
- * @param Y Y array
- * @param S1 Flat array
- * @param undef Undefine value
- * @return Borders
- */
- public static List tracingBorders(double[][] gridData, double[] X, double[] Y, int[][] S1,
- double undef) {
- return wcontour.Contour.tracingBorders(gridData, X, Y, S1, undef);
- }
-
-// /**
-// * Tracing contour lines with undefined data
-// *
-// * @param gridData Grid data
-// * @param cValues Values
-// * @param X X array
-// * @param Y Y array
-// * @param noData Undefine data
-// * @param borders Contour line borders
-// * @param S1 Flag array
-// * @return Traced contour lines
-// */
-// public static List tracingContourLines(double[][] gridData, double[] cValues, double[] X,
-// double[] Y, double noData, List borders, int[][] S1) {
-// int nc = cValues.length;
-// return wContour.Contour.tracingContourLines(gridData, X, Y, nc, cValues, noData, borders, S1);
-// }
-
- /**
- * Tracing contour lines with undefined data
- *
- * @param gridData Grid data
- * @param cValues Values
- * @param X X array
- * @param Y Y array
- * @param noData Undefine data
- * @param S1 Flag array
- * @return Traced contour lines and borders
- */
- public static Object[] tracingContourLines(double[][] gridData, double[] cValues, double[] X,
- double[] Y, double noData, int[][] S1) {
- int nc = cValues.length;
- List borders = wcontour.Contour.tracingBorders(gridData, X, Y, S1, noData);
- List contourLines = wcontour.Contour.tracingContourLines(gridData, X, Y, nc, cValues, noData, borders, S1);
- return new Object[]{contourLines, borders};
- }
-
- /**
- * Tracing shaded polygons with undefined data
- *
- * @param gridData Grid data
- * @param contourLines Contour lines
- * @param borders Border lines
- * @param cValues Values
- * @return Polygon list
- */
- public static List tracingPolygons(double[][] gridData,
- List contourLines, List borders, double[] cValues) {
- return wcontour.Contour.tracingPolygons(gridData, contourLines, borders, cValues);
- }
-
- /**
- * Get max/min values from a station data
- *
- * @param S Discrete data
- * @param noData Missing value
- * @param minmax Min/Max data array
- * @return If has missing value
- */
- public static boolean getMinMaxValueFDiscreteData(double[][] S, double noData, double[] minmax) {
- int i, validNum;
- boolean isNodata = false;
- double min = 0.0, max = 0.0;
-
- validNum = 0;
- for (i = 0; i < S.length; i++) {
- if (!MIMath.doubleEquals(S[i][2], noData)) {
- validNum++;
- if (validNum == 1) {
- min = S[i][2];
- max = min;
- } else {
- if (S[i][2] < min) {
- min = S[i][2];
- }
- if (S[i][2] > max) {
- max = S[i][2];
- }
- }
- } else {
- isNodata = true;
- }
-
- }
-
- minmax[0] = min;
- minmax[1] = max;
-
- return isNodata;
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/drawing/StringType.java b/MeteoInfoLib/src/main/java/org/meteoinfo/drawing/StringType.java
deleted file mode 100644
index f4275edb..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/drawing/StringType.java
+++ /dev/null
@@ -1,16 +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.drawing;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public enum StringType {
- NORMAL,
- LATEX,
- MIXING
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/GeoComputation.java b/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/GeoComputation.java
index 5a9e8d5f..6d78a014 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/GeoComputation.java
+++ b/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/GeoComputation.java
@@ -33,7 +33,7 @@ import java.util.logging.Logger;
import org.meteoinfo.table.DataColumn;
import org.meteoinfo.table.DataRow;
import org.meteoinfo.table.DataTable;
-import org.meteoinfo.layer.VectorLayer;
+import org.meteoinfo.geo.layer.VectorLayer;
import org.meteoinfo.table.Field;
/**
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/GeometryUtil.java b/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/GeometryUtil.java
index a238960d..15a4c264 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/GeometryUtil.java
+++ b/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/GeometryUtil.java
@@ -13,7 +13,7 @@ import org.locationtech.jts.geom.GeometryFactory;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.Extent3D;
import org.meteoinfo.common.PointD;
-import org.meteoinfo.layer.VectorLayer;
+import org.meteoinfo.geo.layer.VectorLayer;
import org.meteoinfo.ndarray.math.ArrayMath;
import org.meteoinfo.ndarray.*;
import org.meteoinfo.geometry.shape.*;
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/analysis/AnalysisTypes.java b/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/analysis/AnalysisTypes.java
deleted file mode 100644
index 0ad07cc1..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/analysis/AnalysisTypes.java
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package org.meteoinfo.geoprocess.analysis;
-
-/**
- *
- * @author yaqiang
- */
-public enum AnalysisTypes {
- Resample,
- Aggregate
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/analysis/Clustering.java b/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/analysis/Clustering.java
deleted file mode 100644
index 96ec8772..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/analysis/Clustering.java
+++ /dev/null
@@ -1,664 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package org.meteoinfo.geoprocess.analysis;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.List;
-import org.meteoinfo.layer.VectorLayer;
-import org.meteoinfo.geometry.shape.PointZ;
-import org.meteoinfo.geometry.shape.PolylineZShape;
-
-/**
- *
- * @author wyq
- */
-public class Clustering {
-
- /**
- * Clustering calculation
- *
- * @param inFile Input file
- * @param outFile Output file
- * @param N Row number
- * @param M Column number
- * @param LN Level number
- * @param disType Distant define type: Euclidean or Angle
- * @throws java.io.FileNotFoundException
- */
- public static void calculate(String inFile, String outFile, int N, int M, int LN, DistanceType disType) throws FileNotFoundException, IOException {
- double[][] DATA = new double[N][M];
-
- //---- Open input File
- String aLine;
- String[] aDataArray;
- int i;
- int j;
- int row;
- int col;
- List flags = new ArrayList<>(); //Date time and height
-
- BufferedReader sr = new BufferedReader(new FileReader(new File(inFile)));
- row = 0;
- while ((aLine = sr.readLine()) != null) {
- if (aLine.isEmpty()) {
- continue;
- }
-
- aDataArray = aLine.split(",");
-
- //Ignor the data line with not normal point number
- if ((aDataArray.length - 2) / 3 != M / 2) {
- continue;
- }
-
- flags.add(aDataArray[0] + "," + aDataArray[1]);
-
- col = 0;
- for (i = 0; i <= M / 2 - 1; i++) {
- for (j = 0; j <= 2; j++) {
- if (j != 2) {
- DATA[row][col] = Double.parseDouble(aDataArray[i * 3 + j + 2]);
- col += 1;
- }
- }
- }
- row += 1;
- }
- sr.close();
-
- //Clustering calculation
- int[][] ICLASS = calculation(DATA, LN, disType);
-
- //Write clustering result to output file
- BufferedWriter sw = new BufferedWriter(new FileWriter(new File(outFile)));
- aLine = "Time,Height";
- for (i = 2; i <= LN; i++) {
- aLine = aLine + "," + String.valueOf(i) + "CL";
- }
- sw.write(aLine);
- sw.newLine();
- for (i = 0; i <= N - 1; i++) {
- aLine = flags.get(i);
- for (j = 0; j <= LN - 2; j++) {
- aLine = aLine + "," + String.valueOf(ICLASS[i][j]);
- }
- sw.write(aLine);
- sw.newLine();
- }
- sw.close();
- }
-
- /**
- * Clustering calculation
- *
- * @param trajLayers Trajectory layers
- * @param outFile Output file
- * @param N Row number - trajectory number
- * @param M Column number - 2 times of point number
- * @param LN Level number
- * @param interval Point interval
- * @param disType Distant define type: Euclidean or Angle
- * @throws java.io.IOException
- */
- public static void calculate(List trajLayers, String outFile, int N, int M, int LN, int interval, DistanceType disType) throws IOException {
- double[][] DATA = new double[N][M];
-
- //---- Get data array
- String aLine;
- int i;
- int j;
- int row;
- int col;
- List flags = new ArrayList<>(); //Date time and height
- LocalDateTime aDate;
-
- row = 0;
- DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyyMMddHH");
- for (VectorLayer layer : trajLayers) {
- PointZ aPoint;
- int sNum = layer.getShapeNum();
- for (i = 0; i < sNum; i++) {
- aDate = (LocalDateTime) layer.getCellValue("Date", i);
- int hour = Integer.parseInt(layer.getCellValue("Hour", i).toString());
- aDate = aDate.withHour(hour);
- aLine = format.format(aDate);
- String height = layer.getCellValue("Height", i).toString();
- flags.add(aLine + "," + height);
- PolylineZShape aPLZ = (PolylineZShape) layer.getShapes().get(i);
- col = 0;
- for (j = 0; j < aPLZ.getPointNum(); j++) {
- if (j % interval == 0) {
- aPoint = (PointZ) aPLZ.getPoints().get(j);
- DATA[row][col] = aPoint.Y;
- col += 1;
- DATA[row][col] = aPoint.X;
- col += 1;
- }
- }
- row += 1;
- }
- }
-
- //Clustering calculation
- int[][] ICLASS = calculation(DATA, LN, disType);
-
- //Write clustering result to output file
- BufferedWriter sw = new BufferedWriter(new FileWriter(new File(outFile)));
- aLine = "Time,Height";
- for (i = 2; i <= LN; i++) {
- aLine = aLine + "," + String.valueOf(i) + "CL";
- }
- sw.write(aLine);
- sw.newLine();
- for (i = 0; i <= N - 1; i++) {
- aLine = flags.get(i);
- for (j = 0; j <= LN - 2; j++) {
- aLine = aLine + "," + String.valueOf(ICLASS[i][j]);
- }
- sw.write(aLine);
- sw.newLine();
- }
- sw.close();
- }
-
- /**
- * Clustering calculation
- *
- * @param DATA Input data array
- * @param outFile Output file
- * @param LN Level number
- * @param disType Distant define type: Euclidean or Angle
- * @throws java.io.IOException
- */
- public static void calculation(double[][] DATA, String outFile, int LN, DistanceType disType) throws IOException {
- int N = DATA.length;
- int M = DATA[0].length;
- double[] CRIT = new double[N];
- double[] MEMBR = new double[N];
- double[] CRITVAL = new double[LN];
- int[] IA = new int[N];
- int[] IB = new int[N];
- int[][] ICLASS = new int[N][LN];
- int[] HVALS = new int[LN];
- int[] IORDER = new int[LN];
- int[] HEIGHT = new int[LN];
- int[] NN = new int[N];
- double[] DISNN = new double[N];
- double[] D = new double[N * (N - 1) / 2];
- boolean[] FLAG = new boolean[N];
-
- //---- IN ABOVE, 18=N, 16=M, 9=LEV, 153=N(N-1)/2
-
-
- //---- Call HC
- int LEN = (N * (N - 1)) / 2;
- int IOPT = 1;
- HC(N, M, IOPT, DATA, IA, IB, CRIT, MEMBR, NN, DISNN, FLAG, D, disType);
-
- //---- Call HCASS
- HCASS(N, IA, IB, CRIT, LN, ICLASS, HVALS, IORDER, CRITVAL, HEIGHT);
-
- //---- Write output file
- BufferedWriter sw = new BufferedWriter(new FileWriter(new File(outFile)));
- int i, j;
- String aLine = "NO";
- for (i = 2; i <= LN; i++) {
- aLine = aLine + "," + String.valueOf(i) + "CL";
- }
- sw.write(aLine);
- sw.newLine();
- for (i = 0; i <= N - 1; i++) {
- aLine = String.valueOf(i + 1);
- for (j = 0; j <= LN - 2; j++) {
- aLine = aLine + "," + String.valueOf(ICLASS[i][j]);
- }
- sw.write(aLine);
- sw.newLine();
- }
- sw.close();
-
- //---- Call HCDEN
- //Call HCDEN(LEV, IORDER, HEIGHT, CRITVAL)
-
- }
-
- /**
- * Clustering calculation
- *
- * @param DATA Input data array
- * @param LN Level number
- * @param disType Distant define type: Euclidean or Angle
- * @return Clustering result array
- */
- public static int[][] calculation(double[][] DATA, int LN, DistanceType disType) {
- //double[,] DATA = new double[N, M];
- int N = DATA.length;
- int M = DATA[0].length;
- double[] CRIT = new double[N];
- double[] MEMBR = new double[N];
- double[] CRITVAL = new double[LN];
- int[] IA = new int[N];
- int[] IB = new int[N];
- int[][] ICLASS = new int[N][LN];
- int[] HVALS = new int[LN];
- int[] IORDER = new int[LN];
- int[] HEIGHT = new int[LN];
- int[] NN = new int[N];
- double[] DISNN = new double[N];
- double[] D = new double[N * (N - 1) / 2];
- boolean[] FLAG = new boolean[N];
-
- //---- IN ABOVE, 18=N, 16=M, 9=LEV, 153=N(N-1)/2
-
-
- //---- Call HC
- //int LEN = (N * (N - 1)) / 2;
- int IOPT = 1;
- HC(N, M, IOPT, DATA, IA, IB, CRIT, MEMBR, NN, DISNN, FLAG, D, disType);
-
- //---- Call HCASS
- HCASS(N, IA, IB, CRIT, LN, ICLASS, HVALS, IORDER, CRITVAL, HEIGHT);
-
- //---- Call HCDEN
- //Call HCDEN(LEV, IORDER, HEIGHT, CRITVAL)
-
- return ICLASS;
- }
-
- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- // C
- // HIERARCHICAL CLUSTERING using (user-specified) criterion. C
- // C
- // Parameters: C
- // C
- // DATA(N,M) input data matrix, C
- // DISS(LEN) dissimilarities in lower half diagonal C
- // storage; LEN = N.N-1/2, C
- // IOPT clustering criterion to be used, C
- // IA, IB, CRIT history of agglomerations; dimensions C
- // N, first N-1 locations only used, C
- // MEMBR, NN, DISNN vectors of length N, used to store C
- // cluster cardinalities, current nearest C
- // neighbour, and the dissimilarity assoc. C
- // with the latter. C
- // FLAG boolean indicator of agglomerable obj./ C
- // clusters. C
- // C
- // F. Murtagh, ESA/ESO/STECF, Garching, February 1986. C
- // C
- //------------------------------------------------------------C
- private static void HC(int N, int M, int IOPT, double[][] DATA, int[] IA, int[] IB, double[] CRIT, double[] MEMBR,
- int[] NN, double[] DISNN, boolean[] FLAG, double[] DISS, DistanceType DISTYPE) {
- double INF = 1.0 * (Math.pow(10, 20));
- int i;
- int j;
- int k;
-
- //---- Initializations
- for (i = 0; i <= N - 1; i++) {
- MEMBR[i] = 1.0;
- FLAG[i] = true;
- }
- int NCL = N;
-
- //---- Construct dissimilarity matrix
- int IND;
-
- if (DISTYPE == DistanceType.ANGLE) {
- double X0;
- double Y0;
- double ANGLE;
- double A;
- double B;
- double C;
- X0 = DATA[0][0];
- Y0 = DATA[0][1];
- for (i = 0; i <= N - 2; i++) {
- for (j = i + 1; j <= N - 1; j++) {
- IND = IOFFSET(N, i + 1, j + 1);
- DISS[IND] = 0.0;
- for (k = 1; k <= M / 2 - 1; k++) {
- A = Math.pow((DATA[i][2 * k] - X0), 2) + Math.pow((DATA[i][2 * k + 1] - Y0), 2);
- B = Math.pow((DATA[j][2 * k] - X0), 2) + Math.pow((DATA[j][2 * k + 1] - Y0), 2);
- C = Math.pow((DATA[j][2 * k] - DATA[i][2 * k]), 2) + Math.pow((DATA[j][2 * k + 1] - DATA[i][2 * k + 1]), 2);
- if (A == 0 | B == 0) {
- ANGLE = 0;
- } else {
- ANGLE = 0.5 * (A + B - C) / Math.sqrt(A * B);
- }
- if ((Math.abs(ANGLE) > 1.0)) {
- ANGLE = 1.0;
- }
- DISS[IND] = DISS[IND] + Math.acos(ANGLE);
- }
- DISS[IND] = DISS[IND] / (M / 2);
- if (IOPT == 1) {
- DISS[IND] = DISS[IND] / 2.0;
- }
- // (Above is done for the case of the min. var. method
- // where merging criteria are defined in terms of variances
- // rather than distances.)
- }
- }
- } else {
- for (i = 0; i <= N - 2; i++) {
- for (j = i + 1; j <= N - 1; j++) {
- IND = IOFFSET(N, i + 1, j + 1);
- DISS[IND] = 0.0;
- for (k = 0; k <= M / 2 - 1; k++) {
- DISS[IND] = DISS[IND] + Math.pow((DATA[i][2 * k] - DATA[j][2 * k]), 2) + Math.pow((DATA[i][2 * k + 1] - DATA[j][2 * k + 1]), 2);
- }
- DISS[IND] = Math.sqrt(DISS[IND]);
- if (IOPT == 1) {
- DISS[IND] = DISS[IND] / 2;
- }
- //---- (Above is done for the case of the min. var. method
- //---- where merging criteria are defined in terms of variances
- //---- rather than distances.)
- }
- }
-
- //For i = 0 To N - 2
- //For j = i + 1 To N - 1
- //IND = IOFFSET(N, i + 1, j + 1)
- //DISS(IND) = 0.0
- //For k = 0 To M - 1
- //DISS(IND) = DISS(IND) + (DATA(i, k) - DATA(j, k)) ^ 2
- //Next
- //If IOPT = 1 Then
- //DISS(IND) = DISS(IND) / 2
- //End If
- //---- (Above is done for the case of the min. var. method
- //---- where merging criteria are defined in terms of variances
- //---- rather than distances.)
- //Next
- //Next
- }
-
- //---- Carry out an agglomeration - first create list of NNs
- double DMIN;
- int JM = 0;
- for (i = 0; i <= N - 2; i++) {
- DMIN = INF;
- for (j = i + 1; j <= N - 1; j++) {
- IND = IOFFSET(N, i + 1, j + 1);
- if (DISS[IND] >= DMIN) {
- continue;
- }
- DMIN = DISS[IND];
- JM = j;
- }
- NN[i] = JM;
- DISNN[i] = DMIN;
- }
-
- //---- Loop
- do {
- //---- Next, determine least diss. using list of NNs
- int IM = 0;
- DMIN = INF;
- for (i = 0; i <= N - 2; i++) {
- if (!FLAG[i]) {
- continue;
- }
- if (DISNN[i] >= DMIN) {
- continue;
- }
- DMIN = DISNN[i];
- IM = i;
- JM = NN[i];
- }
- NCL = NCL - 1;
-
- //---- This allows an agglomeration to be carried out.
- int I2;
- int J2;
-
- I2 = Math.min(IM, JM);
- J2 = Math.max(IM, JM);
- IA[N - NCL - 1] = I2 + 1;
- IB[N - NCL - 1] = J2 + 1;
- CRIT[N - NCL - 1] = DMIN;
-
- //---- Update dissimilarities from new cluster.
- double X;
- double XX;
- int IND1;
- int IND2;
- int IND3;
- int JJ = 0;
- FLAG[J2] = false;
- DMIN = INF;
- for (k = 0; k <= N - 1; k++) {
- if (!FLAG[k]) {
- continue;
- }
- if (k == I2) {
- continue;
- }
- X = MEMBR[I2] + MEMBR[J2] + MEMBR[k];
- if (I2 < k) {
- IND1 = IOFFSET(N, I2 + 1, k + 1);
- } else {
- IND1 = IOFFSET(N, k + 1, I2 + 1);
- }
- if (J2 < k) {
- IND2 = IOFFSET(N, J2 + 1, k + 1);
- } else {
- IND2 = IOFFSET(N, k + 1, J2 + 1);
- }
- IND3 = IOFFSET(N, I2 + 1, J2 + 1);
- XX = DISS[IND3];
-
- //---- Ward's minimum variance method - IOPT=1.
- if (IOPT == 1) {
- DISS[IND1] = (MEMBR[I2] + MEMBR[k]) * DISS[IND1] + (MEMBR[J2] + MEMBR[k]) * DISS[IND2] - MEMBR[k] * XX;
- DISS[IND1] = DISS[IND1] / X;
- }
-
- //---- Single link method - IOPT=2.
- if (IOPT == 2) {
- DISS[IND1] = Math.min(DISS[IND1], DISS[IND2]);
- }
-
- //---- Complete link method - IOPT=3.
- if (IOPT == 3) {
- DISS[IND1] = Math.max(DISS[IND1], DISS[IND2]);
- }
-
- //---- Average link (or group average) method - IOPT=4.
- if (IOPT == 4) {
- DISS[IND1] = (MEMBR[I2] * DISS[IND1] + MEMBR[J2] * DISS[IND2]) / (MEMBR[I2] + MEMBR[J2]);
- }
-
- //---- Mcquitty's method - IOPT=5.
- if (IOPT == 5) {
- DISS[IND1] = 0.5 * DISS[IND1] + 0.5 * DISS[IND2];
- }
-
- //---- MEDIAN (GOWER'S) METHOD - IOPT=6.
- if (IOPT == 6) {
- DISS[IND1] = 0.5 * DISS[IND1] + 0.5 * DISS[IND2] - 0.25 * XX;
- }
-
- // CENTROID METHOD - IOPT=7.
- if (IOPT == 7) {
- DISS[IND1] = (MEMBR[I2] * DISS[IND1] + MEMBR[J2] * DISS[IND2] - MEMBR[I2] * MEMBR[J2] * XX / (MEMBR[I2] + MEMBR[J2])) / (MEMBR[I2] + MEMBR[J2]);
- }
-
- if (I2 > k) {
- continue;
- }
- if (DISS[IND1] >= DMIN) {
- continue;
- }
- DMIN = DISS[IND1];
- JJ = k;
- }
- MEMBR[I2] = MEMBR[I2] + MEMBR[J2];
- DISNN[I2] = DMIN;
- NN[I2] = JJ;
-
- //---- Update list of NNs insofar as this is required.
- for (i = 0; i <= N - 2; i++) {
- if (!FLAG[i]) {
- continue;
- }
- if (NN[i] == I2 | NN[i] == J2) {
- //---- Redetermine NN of I
- DMIN = INF;
- for (j = i + 1; j <= N - 1; j++) {
- IND = IOFFSET(N, i + 1, j + 1);
- if (!FLAG[j]) {
- continue;
- }
- if (i == j) {
- continue;
- }
- if (DISS[IND] >= DMIN) {
- continue;
- }
- DMIN = DISS[IND];
- JJ = j;
- }
- NN[i] = JJ;
- DISNN[i] = DMIN;
- }
- }
- } while (!(NCL == 1));
-
- }
-
- private static int IOFFSET(int N, int I, int J) {
- // Map row I and column J of upper half diagonal symmetric matrix
- // onto vector.
- return J + (I - 1) * N - (I * (I + 1)) / 2 - 1;
- }
-
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++C
- // C
- // Given a HIERARCHIC CLUSTERING, described as a sequence of C
- // agglomerations, derive the assignments into clusters for the C
- // top LEV-1 levels of the hierarchy. C
- // Prepare also the required data for representing the C
- // dendrogram of this top part of the hierarchy. C
- // C
- // Parameters: C
- // C
- // IA, IB, CRIT: vectors of dimension N defining the agglomer- C
- // ations. C
- // LEV: number of clusters in largest partition. C
- // HVALS: vector of dim. LEV, used internally only. C
- // ICLASS: array of cluster assignments; dim. N by LEV. C
- // IORDER, CRITVAL, HEIGHT: vectors describing the dendrogram, C
- // all of dim. LEV. C
- // C
- // F. Murtagh, ESA/ESO/STECF, Garching, February 1986. C
- // C
- //---------------------------------------------------------------C
- private static void HCASS(int N, int[] IA, int[] IB, double[] CRIT, int LEV, int[][] ICLASS, int[] HVALS, int[] IORDER,
- double[] CRITVAL, int[] HEIGHT) {
- // Pick out the clusters which the N objects belong to,
- // at levels N-2, N-3, ... N-LEV+1 of the hierarchy.
- // The clusters are identified by the lowest seq. no. of
- // their members.
- // There are 2, 3, ... LEV clusters, respectively, for the
- // above levels of the hierarchy.
-
- HVALS[0] = 1;
- HVALS[1] = IB[N - 2];
- int LOC = 2;
- int i;
- int j;
- boolean ifGo;
- for (i = N - 3; i >= N - LEV; i += -1) {
- ifGo = true;
- for (j = 0; j <= LOC - 1; j++) {
- if (IA[i] == HVALS[j]) {
- ifGo = false;
- }
- }
- if (ifGo) {
- HVALS[LOC] = IA[i];
- LOC += 1;
- }
- ifGo = true;
- for (j = 0; j <= LOC - 1; j++) {
- if (IB[i] == HVALS[j]) {
- ifGo = false;
- }
- }
- if (ifGo) {
- HVALS[LOC] = IB[i];
- LOC += 1;
- }
- }
-
- int LEVEL;
- int ICL;
- int ILEV;
- int NCL;
- for (LEVEL = N - LEV; LEVEL <= N - 2; LEVEL++) {
- for (i = 0; i <= N - 1; i++) {
- ICL = i + 1;
- for (ILEV = 0; ILEV <= LEVEL - 1; ILEV++) {
- if (IB[ILEV] == ICL) {
- ICL = IA[ILEV];
- }
- }
- NCL = N - LEVEL - 1;
- ICLASS[i][NCL - 1] = ICL;
- }
- }
-
- int k;
- for (i = 0; i <= N - 1; i++) {
- for (j = 0; j <= LEV - 2; j++) {
- for (k = 1; k <= LEV - 1; k++) {
- if (ICLASS[i][j] != HVALS[k]) {
- continue;
- }
- ICLASS[i][j] = k + 1;
- break;
- }
- }
- }
-
- }
-
- //+++++++++++++++++++++++++++++++++++++++++++++++++C
- // C
- // Construct a DENDROGRAM of the top 8 levels of C
- // a HIERARCHIC CLUSTERING. C
- // C
- // Parameters: C
- // C
- // IORDER, HEIGHT, CRITVAL: vectors of length LEV C
- // defining the dendrogram. C
- // These are: the ordering of objects C
- // along the bottom of the dendrogram C
- // (IORDER); the height of the vertical C
- // above each object, in ordinal values C
- // (HEIGHT); and in real values (CRITVAL).C
- // C
- // NOTE: these vectors MUST have been set up with C
- // LEV = 9 in the prior call to routine C
- // HCASS.
- // C
- // F. Murtagh, ESA/ESO/STECF, Garching, Feb. 1986.C
- // C
- //-------------------------------------------------C
- private static void HCDEN(int LEV, int[] IORDER, int[] HEIGHT, double[] CRITVAL) {
- }
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/analysis/DistanceType.java b/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/analysis/DistanceType.java
deleted file mode 100644
index b27cd241..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/analysis/DistanceType.java
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package org.meteoinfo.geoprocess.analysis;
-
-/**
- *
- * @author yaqiang
- */
-public enum DistanceType {
- EUCLIDEAN,
- ANGLE
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/analysis/InterpolationMethods.java b/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/analysis/InterpolationMethods.java
deleted file mode 100644
index dcd62af1..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/analysis/InterpolationMethods.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.geoprocess.analysis;
-
-/**
- *
- * @author yaqiang
- */
-public enum InterpolationMethods {
- ///
- /// IDW radius
- ///
-
- IDW_Radius,
- ///
- /// IDV neighbors
- ///
- IDW_Neighbors,
- ///
- /// Cressman analysis
- ///
- Cressman,
- ///
- /// Assign point to grid
- ///
- AssignPointToGrid,
-
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/analysis/InterpolationSetting.java b/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/analysis/InterpolationSetting.java
deleted file mode 100644
index 4b39fb0f..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/geoprocess/analysis/InterpolationSetting.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.geoprocess.analysis;
-
-import org.meteoinfo.data.GridDataSetting;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- *
- * @author yaqiang
- */
-public class InterpolationSetting {
- //
-
- private GridDataSetting _gridDataPara = new GridDataSetting();
- private InterpolationMethods _gridInterMethod;
- private int _minPointNum;
- private double _radius;
- private double _missingValue = -9999.0;
- private List _radList; //For cressman analysis
- //
- //
-
- /**
- * Constructor
- */
- public InterpolationSetting() {
- _gridDataPara.xNum = 50;
- _gridDataPara.yNum = 50;
- _gridInterMethod = InterpolationMethods.IDW_Radius;
- _minPointNum = 1;
- _radius = 1;
- _radList = new ArrayList<>();
- double[] values = new double[]{10, 7, 4, 2, 1};
- for (double v : values) {
- _radList.add(v);
- }
- }
-
- /**
- * Constructor
- *
- * @param minX Minimum x
- * @param maxX Maximum x
- * @param minY Minimum y
- * @param maxY Maximum y
- * @param xNum X number
- * @param yNum Y number
- * @param aInterMethod Interpolation method
- * @param radius Radius
- * @param minNum Minimum number
- */
- public InterpolationSetting(double minX, double maxX, double minY, double maxY, int xNum, int yNum,
- String aInterMethod, float radius, int minNum) {
- GridDataSetting aGDP = new GridDataSetting();
- aGDP.dataExtent.minX = minX;
- aGDP.dataExtent.maxX = maxX;
- aGDP.dataExtent.minY = minY;
- aGDP.dataExtent.maxY = maxY;
- aGDP.xNum = xNum;
- aGDP.yNum = yNum;
- _gridDataPara = aGDP;
-
- _gridInterMethod = InterpolationMethods.valueOf(aInterMethod);
- _radius = radius;
- _minPointNum = minNum;
-
- _radList = new ArrayList<>();
- double[] values = new double[]{10, 7, 4, 2, 1};
- for (double v : values) {
- _radList.add(v);
- }
- }
-
- /**
- * Constructor
- *
- * @param minX Minimum x
- * @param maxX Maximum x
- * @param minY Minimum y
- * @param maxY Maximum y
- * @param xNum X number
- * @param yNum Y number
- * @param aInterMethod Interpolation method
- * @param radList Radius list - Cressman
- */
- public InterpolationSetting(double minX, double maxX, double minY, double maxY, int xNum, int yNum,
- String aInterMethod, List radList) {
- GridDataSetting aGDP = new GridDataSetting();
- aGDP.dataExtent.minX = minX;
- aGDP.dataExtent.maxX = maxX;
- aGDP.dataExtent.minY = minY;
- aGDP.dataExtent.maxY = maxY;
- aGDP.xNum = xNum;
- aGDP.yNum = yNum;
- _gridDataPara = aGDP;
-
- _gridInterMethod = InterpolationMethods.valueOf(aInterMethod);
- _radList = radList;
- _minPointNum = 1;
- }
- //
- //
-
- /**
- * Get grid data setting
- *
- * @return Grid data setting
- */
- public GridDataSetting getGridDataSetting() {
- return _gridDataPara;
- }
-
- /**
- * Set grid data setting
- *
- * @param value Grid data setting
- */
- public void setGridDataSetting(GridDataSetting value) {
- _gridDataPara = value;
- }
-
- /**
- * Get interpolation method
- *
- * @return Interpolation method
- */
- public InterpolationMethods getInterpolationMethod() {
- return _gridInterMethod;
- }
-
- /**
- * Set interpolation method
- *
- * @param value Interpolation method
- */
- public void setInterpolationMethod(InterpolationMethods value) {
- _gridInterMethod = value;
- }
-
- /**
- * Get minimum point number
- *
- * @return Minimum point number
- */
- public int getMinPointNum() {
- return _minPointNum;
- }
-
- /**
- * Set minimum point number
- *
- * @param value Minimum point number
- */
- public void setMinPointNum(int value) {
- _minPointNum = value;
- }
-
- /**
- * Get search radius
- *
- * @return Radius
- */
- public double getRadius() {
- return _radius;
- }
-
- /**
- * Set search radius
- *
- * @param value Radius
- */
- public void setRadius(double value) {
- _radius = value;
- }
-
- /**
- * Get missing value
- *
- * @return Missing value
- */
- public double getMissingValue() {
- return _missingValue;
- }
-
- /**
- * Set missing value
- *
- * @param value Missing value
- */
- public void setMissingValue(double value) {
- _missingValue = value;
- }
-
- /**
- * Get radius list
- *
- * @return Radius list
- */
- public List getRadiusList() {
- return _radList;
- }
-
- /**
- * Set radius list
- *
- * @param value Radius list
- */
- public void setRadiusList(List value) {
- _radList = value;
- }
- //
- //
-
-
-
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/ChartSet.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layer/ChartSet.java
deleted file mode 100644
index 57527ffc..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/ChartSet.java
+++ /dev/null
@@ -1,457 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.layer;
-
-import java.awt.Color;
-import java.awt.Font;
-
-import org.meteoinfo.geometry.legend.AlignType;
-import org.meteoinfo.geometry.legend.ChartTypes;
-import org.meteoinfo.geometry.legend.LegendScheme;
-import org.meteoinfo.geometry.shape.ShapeTypes;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Template
- *
- * @author Yaqiang Wang
- */
-public class ChartSet {
- //
-
- private ChartTypes _chartType;
- private boolean _drawCharts;
- private List _fieldNames;
- private int _xShift;
- private int _yShift;
- private LegendScheme _legendScheme;
- private int _maxSize;
- private int _minSize;
- private float _maxValue;
- private float _minValue;
- private int _barWidth;
- private boolean _avoidCollision;
- private AlignType _alignType;
- private boolean _view3D;
- private int _thickness;
- private boolean drawLabel;
- private Font labelFont;
- private Color labelColor;
- private int decimalDigits;
- //
- //
-
- /**
- * Constructor
- */
- public ChartSet() {
- _chartType = ChartTypes.BarChart;
- _drawCharts = false;
- _fieldNames = new ArrayList<>();
- _xShift = 0;
- _yShift = 0;
- _legendScheme = new LegendScheme(ShapeTypes.Polygon);
- _maxSize = 50;
- _minSize = 0;
- _barWidth = 8;
- _avoidCollision = true;
- _alignType = AlignType.Center;
- _view3D = false;
- _thickness = 5;
- drawLabel = false;
- labelFont = new Font("Arial", Font.PLAIN, 12);
- labelColor = Color.black;
- this.decimalDigits = 0;
- }
- //
- //
-
- /**
- * Get chart type
- *
- * @return Chart type
- */
- public ChartTypes getChartType() {
- return _chartType;
- }
-
- /**
- * Set chart type
- *
- * @param type Chart type
- */
- public void setChartType(ChartTypes type) {
- _chartType = type;
- }
-
- /**
- * Set chart type
- * @param tstr Chart type string
- */
- public void setChartType(String tstr) {
- switch(tstr.toLowerCase()) {
- case "bar":
- this._chartType = ChartTypes.BarChart;
- break;
- case "pie":
- this._chartType = ChartTypes.PieChart;
- break;
- }
- }
-
- /**
- * Set if draw charts
- *
- * @return If draw charts
- */
- public boolean isDrawCharts() {
- return _drawCharts;
- }
-
- /**
- * Set if draw charts
- *
- * @param istrue If draw charts
- */
- public void setDrawCharts(boolean istrue) {
- _drawCharts = istrue;
- }
-
- /**
- * Get field names
- *
- * @return The file names
- */
- public List getFieldNames() {
- return _fieldNames;
- }
-
- /**
- * Set field names
- *
- * @param names Field names
- */
- public void setFieldNames(List names) {
- _fieldNames = names;
- }
-
- /**
- * Get x shift
- *
- * @return X shift
- */
- public int getXShift() {
- return _xShift;
- }
-
- /**
- * Set x shift
- *
- * @param shift X shift
- */
- public void setXShift(int shift) {
- _xShift = shift;
- }
-
- /**
- * Get y shift
- *
- * @return Y shift
- */
- public int getYShift() {
- return _yShift;
- }
-
- /**
- * Set y shift
- *
- * @param shift Y shift
- */
- public void setYShift(int shift) {
- _yShift = shift;
- }
-
- /**
- * Get legend scheme
- *
- * @return The legend scheme
- */
- public LegendScheme getLegendScheme() {
- return _legendScheme;
- }
-
- /**
- * Set legend scheme
- *
- * @param ls The legend scheme
- */
- public void setLegendScheme(LegendScheme ls) {
- _legendScheme = ls;
- }
-
- /**
- * Get maximum size
- *
- * @return Maximum size
- */
- public int getMaxSize() {
- return _maxSize;
- }
-
- /**
- * Set maximum size
- *
- * @param size Maximum size
- */
- public void setMaxSize(int size) {
- _maxSize = size;
- }
-
- /**
- * Get minimum size
- *
- * @return Minimum size
- */
- public int getMinSize() {
- return _minSize;
- }
-
- /**
- * Set minimum size
- *
- * @param size Minimum size
- */
- public void setMinSize(int size) {
- _minSize = size;
- }
-
- /**
- * Get maximum value
- *
- * @return Maximum value
- */
- public float getMaxValue() {
- return _maxValue;
- }
-
- public void setMaxValue(float value) {
- _maxValue = value;
- }
-
- /**
- * Get minimum value
- *
- * @return Minimum value
- */
- public float getMinValue() {
- return _minValue;
- }
-
- /**
- * Set minimum value
- *
- * @param value Minimum value
- */
- public void setMinValue(float value) {
- _minValue = value;
- }
-
- /**
- * Get bar width
- *
- * @return Bar width
- */
- public int getBarWidth() {
- return _barWidth;
- }
-
- /**
- * Set bar width
- *
- * @param width Bar width
- */
- public void setBarWidth(int width) {
- _barWidth = width;
- }
-
- /**
- * Get if avoid collision
- *
- * @return If avoid collisioin
- */
- public boolean isAvoidCollision() {
- return _avoidCollision;
- }
-
- /**
- * Set if avoid collision
- *
- * @param istrue If avoid collision
- */
- public void setAvoidCollision(boolean istrue) {
- _avoidCollision = istrue;
- }
-
- /**
- * Get align type
- *
- * @return Align type
- */
- public AlignType getAlignType() {
- return _alignType;
- }
-
- /**
- * Set align type
- *
- * @param type Align type
- */
- public void setAlignType(AlignType type) {
- _alignType = type;
- }
-
- /**
- * Set align type
- * @param tstr Align type string
- */
- public void setAlignType(String tstr) {
- switch(tstr.toLowerCase()) {
- case "center":
- this._alignType = AlignType.Center;
- break;
- case "left":
- this._alignType = AlignType.Left;
- break;
- case "right":
- this._alignType = AlignType.Right;
- break;
- case "none":
- this._alignType = AlignType.None;
- break;
- }
- }
-
- /**
- * Get if view 3D
- *
- * @return If view 3D
- */
- public boolean isView3D() {
- return _view3D;
- }
-
- /**
- * Set if view 3D
- *
- * @param istrue If view 3D
- */
- public void setView3D(boolean istrue) {
- _view3D = istrue;
- }
-
- /**
- * Get 3D thickness
- *
- * @return 3D thickness
- */
- public int getThickness() {
- return _thickness;
- }
-
- /**
- * Set 3D thickness
- *
- * @param value 3D thickness
- */
- public void setThickness(int value) {
- _thickness = value;
- }
-
- /**
- * Get if draw label
- * @return Boolean
- */
- public boolean isDrawLabel(){
- return this.drawLabel;
- }
-
- /**
- * Set if draw label
- * @param value Boolean
- */
- public void setDrawLabel(boolean value){
- this.drawLabel = value;
- }
-
- /**
- * Get label font
- * @return Label font
- */
- public Font getLabelFont(){
- return this.labelFont;
- }
-
- /**
- * Set label font
- * @param value Label font
- */
- public void setLabelFont(Font value){
- this.labelFont = value;
- }
-
- /**
- * Get label color
- * @return Label color
- */
- public Color getLabelColor(){
- return this.labelColor;
- }
-
- /**
- * Set label color
- * @param value Label color
- */
- public void setLabelColor(Color value){
- this.labelColor = value;
- }
-
- /**
- * Get decimal digits
- * @return Decimal digits
- */
- public int getDecimalDigits(){
- return this.decimalDigits;
- }
-
- /**
- * Set decimal digits
- * @param value Decimal digits
- */
- public void setDecimalDigits(int value){
- this.decimalDigits = value;
- }
- //
- //
- /**
- * Update - avoid the disagree of field names and legend scheme
- */
- public void update(){
- if (this._fieldNames.size() != this._legendScheme.getBreakNum()){
- this._fieldNames = new ArrayList<>();
- _legendScheme = new LegendScheme(ShapeTypes.Polygon);
- }
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/FrmChartLabel.form b/MeteoInfoLib/src/main/java/org/meteoinfo/layer/FrmChartLabel.form
deleted file mode 100644
index 58c8d9f2..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/FrmChartLabel.form
+++ /dev/null
@@ -1,146 +0,0 @@
-
-
-
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/FrmLabelSet.form b/MeteoInfoLib/src/main/java/org/meteoinfo/layer/FrmLabelSet.form
deleted file mode 100644
index b0291a86..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/FrmLabelSet.form
+++ /dev/null
@@ -1,363 +0,0 @@
-
-
-
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/FrmLayerProperty.form b/MeteoInfoLib/src/main/java/org/meteoinfo/layer/FrmLayerProperty.form
deleted file mode 100644
index 9dcc1e0d..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/FrmLayerProperty.form
+++ /dev/null
@@ -1,727 +0,0 @@
-
-
-
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/ImageLayer.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layer/ImageLayer.java
deleted file mode 100644
index ae0b39c9..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/ImageLayer.java
+++ /dev/null
@@ -1,890 +0,0 @@
-/* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.layer;
-
-import com.l2fprod.common.beans.BaseBeanInfo;
-import com.l2fprod.common.beans.ExtendedPropertyDescriptor;
-import com.l2fprod.common.beans.editor.ComboBoxPropertyEditor;
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.common.util.GlobalUtil;
-import org.meteoinfo.geometry.shape.ShapeTypes;
-import java.awt.Color;
-import java.awt.Image;
-import java.awt.RenderingHints;
-import java.awt.image.BufferedImage;
-import java.awt.image.Raster;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class ImageLayer extends MapLayer {
- //
-
- private BufferedImage _image;
- private WorldFilePara _worldFilePara = new WorldFilePara();
- private String _worldFileName;
- private boolean _isSetTransColor;
- private Color _transparencyColor;
- protected Object interp;
- //
- //
-
- /**
- * Constructor
- */
- public ImageLayer() {
- super();
- this.setLayerType(LayerTypes.ImageLayer);
- this.setShapeType(ShapeTypes.Image);
- _isSetTransColor = false;
- _transparencyColor = Color.black;
- this.interp = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
- }
- //
- //
-
- /**
- * Get image
- *
- * @return The image
- */
- public BufferedImage getImage() {
- return _image;
- }
-
- /**
- * Set image
- *
- * @param image The image
- */
- public void setImage(BufferedImage image) {
- _image = image;
- _transparencyColor = new Color(image.getRGB(1, 1));
- }
-
- /**
- * Get world file name of the layer
- *
- * @return World file name
- */
- public String getWorldFileName() {
- return _worldFileName;
- }
-
- /**
- * Set world file name
- *
- * @param name World file name
- */
- public void setWorldFileName(String name) {
- _worldFileName = name;
- }
-
- /**
- * Get world file parameters
- *
- * @return World file parameters
- */
- public WorldFilePara getWorldFilePara() {
- return _worldFilePara;
- }
-
- /**
- * Set world file parameters
- *
- * @param value World file parameters
- */
- public void setWorldFilePara(WorldFilePara value) {
- _worldFilePara = value;
- }
-
- /**
- * Get if set transparency color
- *
- * @return Boolean
- */
- public boolean isUseTransColor() {
- return _isSetTransColor;
- }
-
- /**
- * Set if using transparency color
- *
- * @param istrue Boolean
- */
- public void setUseTransColor(boolean istrue) {
- _isSetTransColor = istrue;
- if (istrue) {
- Image image = GlobalUtil.makeColorTransparent(_image, _transparencyColor);
- _image = GlobalUtil.imageToBufferedImage(image);
- }
- }
-
- /**
- * Get transparency color
- *
- * @return Transparency color
- */
- public Color getTransparencyColor() {
- return _transparencyColor;
- }
-
- /**
- * Set transparency color
- *
- * @param color The color
- */
- public void setTransparencyColor(Color color) {
- _transparencyColor = color;
- if (_isSetTransColor) {
- Image image = GlobalUtil.makeColorTransparent(_image, _transparencyColor);
- _image = GlobalUtil.imageToBufferedImage(image);
- }
- }
-
- /**
- * Get X upper-left
- *
- * @return Upper-left x value
- */
- public double getXUL() {
- return _worldFilePara.xUL;
- }
-
- /**
- * Set upper-left x
- *
- * @param value The value
- * @throws java.io.IOException
- */
- public void setXUL(double value) throws IOException {
- _worldFilePara.xUL = value;
- Extent aExtent = (Extent) this.getExtent().clone();
- aExtent.minX = _worldFilePara.xUL;
- aExtent.maxX = _worldFilePara.xUL + this.getExtent().getWidth();
- this.setExtent(aExtent);
- if (new File(_worldFileName).exists()) {
- writeImageWorldFile(_worldFileName, _worldFilePara);
- }
- }
-
- /**
- * Get y upper-left
- *
- * @return Upper-left y
- */
- public double getYUL() {
- return _worldFilePara.yUL;
- }
-
- /**
- * Set upper-left y
- *
- * @param value The value
- * @throws java.io.IOException
- */
- public void setYUL(double value) throws IOException {
- _worldFilePara.yUL = value;
- Extent aExtent = (Extent) this.getExtent().clone();
- aExtent.maxY = _worldFilePara.yUL;
- aExtent.minY = _worldFilePara.yUL - this.getExtent().getHeight();
- this.setExtent(aExtent);
- if (new File(_worldFileName).exists()) {
- writeImageWorldFile(_worldFileName, _worldFilePara);
- }
- }
-
- /**
- * Get x scale
- *
- * @return The x scale
- */
- public double getXScale() {
- return _worldFilePara.xScale;
- }
-
- /**
- * Set x scale
- *
- * @param value The value
- * @throws java.io.IOException
- */
- public void setXScale(double value) throws IOException {
- _worldFilePara.xScale = value;
- Extent aExtent = (Extent) this.getExtent();
- double width = _image.getWidth() * _worldFilePara.xScale;
- aExtent.maxX = _worldFilePara.xUL + width;
- this.setExtent(aExtent);
- if (new File(_worldFileName).exists()) {
- writeImageWorldFile(_worldFileName, _worldFilePara);
- }
- }
-
- /**
- * Get y scale
- *
- * @return The y scale
- */
- public double getYScale() {
- return _worldFilePara.yScale;
- }
-
- /**
- * Set y scale
- *
- * @param value The y scale value
- * @throws IOException
- */
- public void setYScale(double value) throws IOException {
- _worldFilePara.yScale = value;
- Extent aExtent = (Extent) this.getExtent();
- double height = _image.getHeight() * _worldFilePara.yScale;
- aExtent.minY = _worldFilePara.yUL + height;
- this.setExtent(aExtent);
- if (new File(_worldFileName).exists()) {
- writeImageWorldFile(_worldFileName, _worldFilePara);
- }
- }
-
- /**
- * Get x rotate(shear)
- *
- * @return X rotate
- */
- public double getXRotate() {
- return _worldFilePara.xRotate;
- }
-
- /**
- * Set x rotate(shear)
- *
- * @param value Value
- * @throws IOException
- */
- public void setXRotate(double value) throws IOException {
- _worldFilePara.xRotate = value;
- if (new File(_worldFileName).exists()) {
- writeImageWorldFile(_worldFileName, _worldFilePara);
- }
- }
-
- /**
- * Get y rotate(shear)
- *
- * @return X rotate
- */
- public double getYRotate() {
- return _worldFilePara.yRotate;
- }
-
- /**
- * Set y rotate(shear)
- *
- * @param value Value
- * @throws IOException
- */
- public void setYRotate(double value) throws IOException {
- _worldFilePara.yRotate = value;
- if (new File(_worldFileName).exists()) {
- writeImageWorldFile(_worldFileName, _worldFilePara);
- }
- }
-
- /**
- * Get interpolation
- *
- * @return Interpolation
- */
- public Object getInterpolation() {
- return this.interp;
- }
-
- /**
- * Get interpolation string
- *
- * @return Interpolation string
- */
- public String getInterpolationStr() {
- if (interp == RenderingHints.VALUE_INTERPOLATION_BILINEAR) {
- return "bilinear";
- } else if (interp == RenderingHints.VALUE_INTERPOLATION_BICUBIC) {
- return "bicubic";
- } else {
- return "nearest";
- }
- }
-
- /**
- * Set interpolation object
- *
- * @param value Interpolation object
- */
- public void setInterpolation(Object value) {
- this.interp = value;
- }
-
- /**
- * Set interpolation string
- *
- * @param value Interpolation string
- */
- public void setInterpolation(String value) {
- switch (value) {
- case "nearest":
- this.interp = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
- break;
- case "bilinear":
- this.interp = RenderingHints.VALUE_INTERPOLATION_BILINEAR;
- break;
- case "bicubic":
- this.interp = RenderingHints.VALUE_INTERPOLATION_BICUBIC;
- break;
- }
- }
- //
- //
-
- /**
- * Read image world file
- *
- * @param aIFile Image world file path
- * @throws java.io.FileNotFoundException
- */
- public void readImageWorldFile(String aIFile) throws FileNotFoundException, IOException {
- BufferedReader sr = new BufferedReader(new FileReader(new File(aIFile)));
-
- _worldFilePara.xScale = Double.parseDouble(sr.readLine());
- _worldFilePara.yRotate = Double.parseDouble(sr.readLine());
- _worldFilePara.xRotate = Double.parseDouble(sr.readLine());
- _worldFilePara.yScale = Double.parseDouble(sr.readLine());
- _worldFilePara.xUL = Double.parseDouble(sr.readLine());
- _worldFilePara.yUL = Double.parseDouble(sr.readLine());
- sr.close();
- }
-
- /**
- * Write image world file
- *
- * @param aFile File path
- * @param aWFP WorldFilePara
- * @throws java.io.IOException
- */
- public void writeImageWorldFile(String aFile, WorldFilePara aWFP) throws IOException {
- BufferedWriter sw = new BufferedWriter(new FileWriter(new File(aFile)));
- sw.write(String.valueOf(aWFP.xScale));
- sw.newLine();
- sw.write(String.valueOf(aWFP.yRotate));
- sw.newLine();
- sw.write(String.valueOf(aWFP.xRotate));
- sw.newLine();
- sw.write(String.valueOf(aWFP.yScale));
- sw.newLine();
- sw.write(String.valueOf(aWFP.xUL));
- sw.newLine();
- sw.write(String.valueOf(aWFP.yUL));
- sw.close();
- }
-
- /**
- * Get colors from palette file
- *
- * @param pFile Palette file path
- * @return Colors
- */
- public List getColorsFromPaletteFile(String pFile) {
- BufferedReader sr;
- try {
- sr = new BufferedReader(new InputStreamReader(new FileInputStream(pFile)));
- sr.readLine();
- String aLine = sr.readLine();
- String[] dataArray;
- List colors = new ArrayList<>();
- while (aLine != null) {
- if (aLine.isEmpty()) {
- aLine = sr.readLine();
- continue;
- }
-
- aLine = aLine.trim();
- dataArray = aLine.split("\\s+");
- colors.add(new Color(Integer.parseInt(dataArray[3]), Integer.parseInt(dataArray[2]),
- Integer.parseInt(dataArray[1])));
-
- aLine = sr.readLine();
- }
- sr.close();
-
- return colors;
- } catch (FileNotFoundException ex) {
- Logger.getLogger(ImageLayer.class.getName()).log(Level.SEVERE, null, ex);
- return null;
- } catch (IOException ex) {
- Logger.getLogger(ImageLayer.class.getName()).log(Level.SEVERE, null, ex);
- return null;
- }
- }
-
- /**
- * Set palette
- *
- * @param colors Colors
- */
- public void setPalette(List colors) {
- Raster imageData = _image.getData();
-
- for (int i = 0; i < _image.getWidth(); i++) {
- for (int j = 0; j < _image.getHeight(); j++) {
- _image.setRGB(i, _image.getHeight() - j - 1, colors.get(imageData.getSample(i, j, 0)).getRGB());
- }
- }
- }
-
- /**
- * Set color palette to a image from a palette file
- *
- * @param aFile File path
- */
- public void setPalette(String aFile) {
- List colors = getColorsFromPaletteFile(aFile);
-
- setPalette(colors);
- }
- //
-
- //
- public class ImageLayerBean {
-
- ImageLayerBean() {
- }
-
- //
- /**
- * Get layer type
- *
- * @return Layer type
- */
- public LayerTypes getLayerType() {
- return ImageLayer.this.getLayerType();
- }
-
- /**
- * Set layer type
- *
- * @param lt Layer type
- */
- public void setLayerType(LayerTypes lt) {
- ImageLayer.this.setLayerType(lt);
- }
-
- /**
- * Get layer draw type
- *
- * @return Layer draw type
- */
- public LayerDrawType getLayerDrawType() {
- return ImageLayer.this.getLayerDrawType();
- }
-
- /**
- * Set layer draw type
- *
- * @param ldt Layer draw type
- */
- public void setLayerDrawType(LayerDrawType ldt) {
- ImageLayer.this.setLayerDrawType(ldt);
- }
-
- /**
- * Get file name
- *
- * @return File name
- */
- public String getFileName() {
- return ImageLayer.this.getFileName();
- }
-
- /**
- * Set file name
- *
- * @param fn File name
- */
- public void setFileName(String fn) {
- ImageLayer.this.setFileName(fn);
- }
-
- /**
- * Get layer handle
- *
- * @return Layer handle
- */
- public int getHandle() {
- return ImageLayer.this.getHandle();
- }
-
- /**
- * Get layer name
- *
- * @return Layer name
- */
- public String getLayerName() {
- return ImageLayer.this.getLayerName();
- }
-
- /**
- * Set layer name
- *
- * @param name Layer name
- */
- public void setLayerName(String name) {
- ImageLayer.this.setLayerName(name);
- }
-
- /**
- * Get if is maskout
- *
- * @return If is maskout
- */
- public boolean isMaskout() {
- return ImageLayer.this.isMaskout();
- }
-
- /**
- * Set if maskout
- *
- * @param value If maskout
- */
- public void setMaskout(boolean value) {
- ImageLayer.this.setMaskout(value);
- }
-
- /**
- * Get if is visible
- *
- * @return If is visible
- */
- public boolean isVisible() {
- return ImageLayer.this.isVisible();
- }
-
- /**
- * Set if is visible
- *
- * @param value If is visible
- */
- public void setVisible(boolean value) {
- ImageLayer.this.setVisible(value);
- }
-
- /**
- * Get world file name of the layer
- *
- * @return World file name
- */
- public String getWorldFileName() {
- return _worldFileName;
- }
-
- /**
- * Get if set transparency color
- *
- * @return Boolean
- */
- public boolean isUseTransColor() {
- return _isSetTransColor;
- }
-
- /**
- * Set if using transparency color
- *
- * @param istrue Boolean
- */
- public void setUseTransColor(boolean istrue) {
- _isSetTransColor = istrue;
- if (istrue) {
- Image image = GlobalUtil.makeColorTransparent(_image, _transparencyColor);
- _image = GlobalUtil.imageToBufferedImage(image);
- }
- }
-
- /**
- * Get transparency color
- *
- * @return Transparency color
- */
- public Color getTransparencyColor() {
- return _transparencyColor;
- }
-
- /**
- * Set transparency color
- *
- * @param color The color
- */
- public void setTransparencyColor(Color color) {
- _transparencyColor = color;
- if (_isSetTransColor) {
- Image image = GlobalUtil.makeColorTransparent(_image, _transparencyColor);
- _image = GlobalUtil.imageToBufferedImage(image);
- }
- }
-
- /**
- * Get transparency percent
- *
- * @return Transparency percent
- */
- public int getTransparency() {
- return ImageLayer.this.getTransparency();
- }
-
- /**
- * Set transparency percent
- *
- * @param value Transparency percent
- */
- public void setTransparency(int value) {
- ImageLayer.this.setTransparency(value);
- }
-
- /**
- * Get X upper-left
- *
- * @return Upper-left x value
- */
- public double getXUL() {
- return _worldFilePara.xUL;
- }
-
- /**
- * Set upper-left x
- *
- * @param value The value
- * @throws java.io.IOException
- */
- public void setXUL(double value) throws IOException {
- _worldFilePara.xUL = value;
- Extent aExtent = (Extent) ImageLayer.this.getExtent().clone();
- aExtent.minX = _worldFilePara.xUL;
- aExtent.maxX = _worldFilePara.xUL + ImageLayer.this.getExtent().getWidth();
- ImageLayer.this.setExtent(aExtent);
- if (new File(_worldFileName).exists()) {
- writeImageWorldFile(_worldFileName, _worldFilePara);
- }
- }
-
- /**
- * Get y upper-left
- *
- * @return Upper-left y
- */
- public double getYUL() {
- return _worldFilePara.yUL;
- }
-
- /**
- * Set upper-left y
- *
- * @param value The value
- * @throws java.io.IOException
- */
- public void setYUL(double value) throws IOException {
- _worldFilePara.yUL = value;
- Extent aExtent = (Extent) ImageLayer.this.getExtent().clone();
- aExtent.maxY = _worldFilePara.yUL;
- aExtent.minY = _worldFilePara.yUL - ImageLayer.this.getExtent().getHeight();
- ImageLayer.this.setExtent(aExtent);
- if (new File(_worldFileName).exists()) {
- writeImageWorldFile(_worldFileName, _worldFilePara);
- }
- }
-
- /**
- * Get x scale
- *
- * @return The x scale
- */
- public double getXScale() {
- return _worldFilePara.xScale;
- }
-
- /**
- * Set x scale
- *
- * @param value The value
- * @throws java.io.IOException
- */
- public void setXScale(double value) throws IOException {
- _worldFilePara.xScale = value;
- Extent aExtent = (Extent) ImageLayer.this.getExtent();
- double width = _image.getWidth() * _worldFilePara.xScale;
- aExtent.maxX = _worldFilePara.xUL + width;
- ImageLayer.this.setExtent(aExtent);
- if (new File(_worldFileName).exists()) {
- writeImageWorldFile(_worldFileName, _worldFilePara);
- }
- }
-
- /**
- * Get y scale
- *
- * @return The y scale
- */
- public double getYScale() {
- return _worldFilePara.yScale;
- }
-
- public void setYScale(double value) throws IOException {
- _worldFilePara.yScale = value;
- Extent aExtent = (Extent) ImageLayer.this.getExtent();
- double height = _image.getHeight() * _worldFilePara.yScale;
- aExtent.minY = _worldFilePara.yUL + height;
- ImageLayer.this.setExtent(aExtent);
- if (new File(_worldFileName).exists()) {
- writeImageWorldFile(_worldFileName, _worldFilePara);
- }
- }
-
- /**
- * Get x rotate(shear)
- *
- * @return X rotate
- */
- public double getXRotate() {
- return _worldFilePara.xRotate;
- }
-
- /**
- * Set x rotate(shear)
- *
- * @param value Value
- * @throws IOException
- */
- public void setXRotate(double value) throws IOException {
- _worldFilePara.xRotate = value;
- if (new File(_worldFileName).exists()) {
- writeImageWorldFile(_worldFileName, _worldFilePara);
- }
- }
-
- /**
- * Get y rotate(shear)
- *
- * @return X rotate
- */
- public double getYRotate() {
- return _worldFilePara.yRotate;
- }
-
- /**
- * Set y rotate(shear)
- *
- * @param value Value
- * @throws IOException
- */
- public void setYRotate(double value) throws IOException {
- _worldFilePara.yRotate = value;
- if (new File(_worldFileName).exists()) {
- writeImageWorldFile(_worldFileName, _worldFilePara);
- }
- }
-
- /**
- * Get interpolation
- *
- * @return Interpolation
- */
- public String getInterpolation() {
- if (interp == RenderingHints.VALUE_INTERPOLATION_BILINEAR) {
- return "bilinear";
- } else if (interp == RenderingHints.VALUE_INTERPOLATION_BICUBIC) {
- return "bicubic";
- } else {
- return "nearest";
- }
- }
-
- /**
- * Set interpolation
- *
- * @param value Interpolation
- */
- public void setInterpolation(String value) {
- switch (value) {
- case "nearest":
- interp = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
- break;
- case "bilinear":
- interp = RenderingHints.VALUE_INTERPOLATION_BILINEAR;
- break;
- case "bicubic":
- interp = RenderingHints.VALUE_INTERPOLATION_BICUBIC;
- break;
- }
- }
- //
- }
-
- public static class ImageLayerBeanBeanInfo extends BaseBeanInfo {
-
- public ImageLayerBeanBeanInfo() {
- super(ImageLayerBean.class);
- addProperty("fileName").setCategory("Read only").setReadOnly().setDisplayName("File name");
- addProperty("layerType").setCategory("Read only").setReadOnly().setDisplayName("Layer type");
- addProperty("layerDrawType").setCategory("Read only").setReadOnly().setDisplayName("Layer draw type");
- addProperty("handle").setCategory("Read only").setReadOnly().setDisplayName("Handle");
- addProperty("layerName").setCategory("Editable").setDisplayName("Layer name");
- addProperty("visible").setCategory("Editable").setDisplayName("Visible");
- addProperty("maskout").setCategory("Editable").setDisplayName("Is maskout");
- addProperty("transparency").setCategory("Editable").setDisplayName("Transparency Percent");
- addProperty("useTransColor").setCategory("Editable").setDisplayName("If use transparency color");
- addProperty("transparencyColor").setCategory("Editable").setDisplayName("Transparency color");
- addProperty("xScale").setCategory("Editable").setDisplayName("X scale");
- addProperty("yScale").setCategory("Editable").setDisplayName("Y scale");
- addProperty("xUL").setCategory("Editable").setDisplayName("X upper left");
- addProperty("yUL").setCategory("Editable").setDisplayName("Y upper left");
- addProperty("xRotate").setCategory("Editable").setDisplayName("X rotate");
- addProperty("yRotate").setCategory("Editable").setDisplayName("Y rotate");
- ExtendedPropertyDescriptor e = addProperty("interpolation");
- e.setCategory("Editable").setPropertyEditorClass(InterpolationEditor.class);
- e.setDisplayName("Interpolation");
- }
- }
-
- public static class InterpolationEditor extends ComboBoxPropertyEditor {
-
- public InterpolationEditor() {
- super();
- String[] names = new String[3];
- names[0] = "nearest";
- names[1] = "bilinear";
- names[2] = "bicubic";
- setAvailableValues(names);
- }
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/LabelSet.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layer/LabelSet.java
deleted file mode 100644
index e3e0be4e..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/LabelSet.java
+++ /dev/null
@@ -1,323 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.layer;
-
-import org.meteoinfo.common.util.GlobalUtil;
-import org.meteoinfo.geometry.legend.AlignType;
-
-import java.awt.Color;
-import java.awt.Font;
-
- /**
- * Template
- *
- * @author Yaqiang Wang
- */
-public class LabelSet {
- //
-
- private boolean _drawLabels;
- private String _fieldName;
- private Font _labelFont;
- private Color _labelColor;
- private boolean _drawShadow;
- private Color _shadowColor;
- private AlignType _labelAlignType;
- private int _xOffset;
- private int _yOffset;
- private boolean _avoidCollision;
- private boolean _colorByLegend;
- private boolean _dynamicContourLabel;
- private boolean _autoDecimal;
- private int _decimalDigits;
- //
- //
-
- public LabelSet() {
- _drawLabels = false;
- _fieldName = null;
- _labelFont = new Font(GlobalUtil.getDefaultFontName(), Font.PLAIN, 12);
- _labelColor = Color.black;
- _drawShadow = false;
- _shadowColor = Color.white;
- _labelAlignType = AlignType.Center;
- _xOffset = 0;
- _yOffset = 0;
- _avoidCollision = true;
- _colorByLegend = false;
- _dynamicContourLabel = false;
- _autoDecimal = true;
- _decimalDigits = 2;
- }
- //
- //
-
- /**
- * Get if draw labels
- *
- * @return If draw labels
- */
- public boolean isDrawLabels() {
- return _drawLabels;
- }
-
- /**
- * Set if draw labels
- *
- * @param istrue If draw labels
- */
- public void setDrawLabels(boolean istrue) {
- _drawLabels = istrue;
- }
-
- /**
- * Get label field name
- *
- * @return Label field name
- */
- public String getFieldName() {
- return _fieldName;
- }
-
- /**
- * Set label field name
- *
- * @param name Label field name
- */
- public void setFieldName(String name) {
- _fieldName = name;
- }
-
- /**
- * Get label font
- *
- * @return Font
- */
- public Font getLabelFont() {
- return _labelFont;
- }
-
- /**
- * Set label font
- *
- * @param font Label font
- */
- public void setLabelFont(Font font) {
- _labelFont = font;
- }
-
- /**
- * Get label color
- *
- * @return Label color
- */
- public Color getLabelColor() {
- return _labelColor;
- }
-
- /**
- * Set label color
- *
- * @param color Label color
- */
- public void setLabelColor(Color color) {
- _labelColor = color;
- }
-
- /**
- * Get if show shadow
- *
- * @return If show shadow
- */
- public boolean isDrawShadow() {
- return _drawShadow;
- }
-
- /**
- * Set if show shadow
- *
- * @param istrue If show shadow
- */
- public void setDrawShadow(boolean istrue) {
- _drawShadow = istrue;
- }
-
- /**
- * Get shadow color
- *
- * @return Shadow color
- */
- public Color getShadowColor() {
- return _shadowColor;
- }
-
- /**
- * Set shadow color
- *
- * @param color Shadow color
- */
- public void setShadowColor(Color color) {
- _shadowColor = color;
- }
-
- /**
- * Get label align type
- *
- * @return Align type
- */
- public AlignType getLabelAlignType() {
- return _labelAlignType;
- }
-
- /**
- * Set label align type
- *
- * @param type Align type
- */
- public void setLabelAlignType(AlignType type) {
- _labelAlignType = type;
- }
-
- /**
- * Get x offset
- *
- * @return X offset
- */
- public int getXOffset() {
- return _xOffset;
- }
-
- /**
- * Set x offset
- *
- * @param value X offset
- */
- public void setXOffset(int value) {
- _xOffset = value;
- }
-
- /**
- * Get y offset
- *
- * @return Y offset
- */
- public int getYOffset() {
- return _yOffset;
- }
-
- /**
- * Set y offset
- *
- * @param value Y offset
- */
- public void setYOffset(int value) {
- _yOffset = value;
- }
-
- /**
- * Get if avoid collision
- *
- * @return If avoid collision
- */
- public boolean isAvoidCollision() {
- return _avoidCollision;
- }
-
- /**
- * Set if avoid collision
- *
- * @param istrue If avoid collision
- */
- public void setAvoidCollision(boolean istrue) {
- _avoidCollision = istrue;
- }
-
- /**
- * Get if set color by legend
- *
- * @return Boolean
- */
- public boolean isColorByLegend() {
- return _colorByLegend;
- }
-
- /**
- * Set if set color by legend
- *
- * @param istrue Boolean
- */
- public void setColorByLegend(boolean istrue) {
- _colorByLegend = istrue;
- }
-
- /**
- * Get if using dynamic contour label
- *
- * @return Boolean
- */
- public boolean isDynamicContourLabel() {
- return _dynamicContourLabel;
- }
-
- /**
- * Set if using dynamic contour label
- *
- * @param istrue Boolean
- */
- public void setDynamicContourLabel(boolean istrue) {
- _dynamicContourLabel = istrue;
- }
-
- ///
- /// Get or set if automatic set decimal digits
- ///
- /**
- * Get if automatic set decimal digits
- *
- * @return Boolean
- */
- public boolean isAutoDecimal() {
- return _autoDecimal;
- }
-
- /**
- * Set if automatic set decimal digits
- *
- * @param istrue Boolean
- */
- public void setAutoDecimal(boolean istrue) {
- _autoDecimal = istrue;
- }
-
- /**
- * Get decimal digits
- *
- * @return Decimal digits
- */
- public int getDecimalDigits() {
- return _decimalDigits;
- }
-
- /**
- * Set decimal digits
- *
- * @param value Decimal digits
- */
- public void setDecimalDigits(int value) {
- _decimalDigits = value;
- }
- //
- //
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/LayerCollection.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layer/LayerCollection.java
deleted file mode 100644
index fcbf4d14..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/LayerCollection.java
+++ /dev/null
@@ -1,59 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.layer;
-
-import java.util.ArrayList;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class LayerCollection extends ArrayList {
- //
-
- private int _selectedLayer;
- //
- //
-
- /**
- * Constructor
- */
- public LayerCollection() {
- _selectedLayer = -1;
- }
- //
- //
-
- /**
- * Get selected layer
- *
- * @return Selected layer handle
- */
- public int getSelectedLayer() {
- return _selectedLayer;
- }
-
- /**
- * Set selected layer handle
- *
- * @param handle Layer handle
- */
- public void setSelectedLayer(int handle) {
- _selectedLayer = handle;
- }
-
- //
- //
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/LayerDrawType.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layer/LayerDrawType.java
deleted file mode 100644
index de6f94cb..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/LayerDrawType.java
+++ /dev/null
@@ -1,38 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.layer;
-
-/**
- * Layer draw type enum
- *
- * @author Yaqiang Wang
- */
-public enum LayerDrawType {
-
- Map,
- Shaded,
- Contour,
- GridFill,
- GridPoint,
- Vector,
- StationPoint,
- Barb,
- WeatherSymbol,
- StationModel,
- Image,
- Raster,
- TrajLine,
- TrajPoint,
- Streamline
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/LayerTypes.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layer/LayerTypes.java
deleted file mode 100644
index daa426bb..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/LayerTypes.java
+++ /dev/null
@@ -1,26 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.layer;
-
-/**
- * Layer type enum
- *
- * @author Yaqiang Wang
- */
-public enum LayerTypes {
- VectorLayer,
- ImageLayer,
- RasterLayer,
- WebMapLayer
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/MapLayer.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layer/MapLayer.java
deleted file mode 100644
index 66ce5c08..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/MapLayer.java
+++ /dev/null
@@ -1,382 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.layer;
-
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.geometry.legend.LegendScheme;
-import org.meteoinfo.projection.KnownCoordinateSystems;
-import org.meteoinfo.projection.ProjectionInfo;
-import org.meteoinfo.geometry.shape.ShapeTypes;
-
-/**
- * Map layer class
- *
- * @author Yaqiang Wang
- */
-public class MapLayer implements Cloneable {
- //
-
- private LayerTypes _layerType;
- private ShapeTypes _shapeType;
- private int _handle;
- private String _layerName;
- private String _fileName;
- protected ProjectionInfo _projInfo;
- private Extent _extent;
- private boolean _visible;
- private LayerDrawType _layerDrawType;
- private boolean _isMaskout;
- private LegendScheme _legendScheme;
- private boolean _expanded;
- private int _transparencyPerc;
- private String _tag;
- private VisibleScale _visibleScale;
- //
- //
-
- /**
- * Constructor
- */
- public MapLayer() {
- _layerName = "layer";
- _fileName = "";
- _projInfo = KnownCoordinateSystems.geographic.world.WGS1984;
- _handle = -1;
- _extent = new Extent();
- _visible = true;
- _isMaskout = false;
- _expanded = false;
- _transparencyPerc = 0;
- _layerDrawType = LayerDrawType.Map;
- _tag = "";
- _visibleScale = new VisibleScale();
- }
- //
- //
-
- /**
- * Get layer type
- *
- * @return Layer type
- */
- public LayerTypes getLayerType() {
- return _layerType;
- }
-
- /**
- * Set layer type
- *
- * @param lt Layer type
- */
- public void setLayerType(LayerTypes lt) {
- _layerType = lt;
- }
-
- /**
- * Get shape type
- *
- * @return Shape type
- */
- public ShapeTypes getShapeType() {
- return _shapeType;
- }
-
- /**
- * Set shape type
- *
- * @param st Shape type
- */
- public void setShapeType(ShapeTypes st) {
- _shapeType = st;
- }
-
- /**
- * Get layer draw type
- *
- * @return Layer draw type
- */
- public LayerDrawType getLayerDrawType() {
- return _layerDrawType;
- }
-
- /**
- * Set layer draw type
- *
- * @param ldt Layer draw type
- */
- public void setLayerDrawType(LayerDrawType ldt) {
- _layerDrawType = ldt;
- }
-
- /**
- * Get file name
- *
- * @return File name
- */
- public String getFileName() {
- return _fileName;
- }
-
- /**
- * Set file name
- *
- * @param fn File name
- */
- public void setFileName(String fn) {
- _fileName = fn;
- }
-
- /**
- * Get layer handle
- *
- * @return Layer handle
- */
- public int getHandle() {
- return _handle;
- }
-
- /**
- * Set layer handle
- *
- * @param handle Layer handle
- */
- public void setHandle(int handle) {
- _handle = handle;
- }
-
- /**
- * Get layer name
- *
- * @return Layer name
- */
- public String getLayerName() {
- return _layerName;
- }
-
- /**
- * Set layer name
- *
- * @param lName Layer name
- */
- public void setLayerName(String lName) {
- _layerName = lName;
- }
-
- /**
- * Get extent
- *
- * @return Extent
- */
- public Extent getExtent() {
- return _extent;
- }
-
- /**
- * Set extent
- *
- * @param extent Extent
- */
- public void setExtent(Extent extent) {
- _extent = extent;
- }
-
- /**
- * Get if layer is visible
- *
- * @return Boolean
- */
- public boolean isVisible() {
- return _visible;
- }
-
- /**
- * Set if layer is visible
- *
- * @param isTrue Boolean
- */
- public void setVisible(boolean isTrue) {
- _visible = isTrue;
- }
-
- /**
- * Get legend scheme
- *
- * @return Legend scheme
- */
- public LegendScheme getLegendScheme() {
- return _legendScheme;
- }
-
- /**
- * Get if is maskout
- * @return Boolean
- */
- public boolean isMaskout(){
- return this._isMaskout;
- }
-
- /**
- * Set if is maskout
- * @param istrue Boolean
- */
- public void setMaskout(boolean istrue){
- this._isMaskout = istrue;
- }
-
- /**
- * Set legend scheme
- *
- * @param ls
- */
- public void setLegendScheme(LegendScheme ls) {
- _legendScheme = ls;
- }
-
- /**
- * Get transparency percent
- *
- * @return Transparency percent
- */
- public int getTransparency() {
- return this._transparencyPerc;
- }
-
- /**
- * Set transparency percent
- *
- * @param trans Transparency percent
- */
- public void setTransparency(int trans) {
- this._transparencyPerc = trans;
- }
-
- /**
- * Get if is expanded
- *
- * @return Boolean
- */
- public boolean isExpanded() {
- return this._expanded;
- }
-
- /**
- * Set if expand
- *
- * @param istrue Boolean
- */
- public void setExpanded(boolean istrue) {
- this._expanded = istrue;
- }
-
- /**
- * Get projection info
- * @return Projection info
- */
- public ProjectionInfo getProjInfo(){
- return _projInfo;
- }
-
- /**
- * Set projection info
- * @param projInfo Projection info
- */
- public void setProjInfo(ProjectionInfo projInfo){
- _projInfo = projInfo;
- }
-
- /**
- * Get tag
- * @return Tag
- */
- public String getTag(){
- return _tag;
- }
-
- /**
- * Set tag
- * @param value Tag value
- */
- public void setTag(String value){
- _tag = value;
- }
-
- /**
- * Get visible scale
- * @return Visible scale
- */
- public VisibleScale getVisibleScale(){
- return _visibleScale;
- }
-
- /**
- * Set visible scale
- * @param value Visible scale
- */
- public void setVisibleScale(VisibleScale value){
- _visibleScale = value;
- }
- //
- //
- /**
- * If the layer has legend schem or not
- * @return Boolean
- */
- public boolean hasLegendScheme(){
- return this._legendScheme != null;
- }
-
- @Override
- public Object clone() throws CloneNotSupportedException {
- MapLayer aLayer = (MapLayer)super.clone();
- if (_legendScheme != null)
- aLayer._legendScheme = (LegendScheme)this._legendScheme.clone();
-
- return aLayer;
- }
-
- /**
- * To string
- * @return String
- */
- @Override
- public String toString(){
- return this.getLayerName();
- }
-
- /**
- * To string
- * @return String
- */
- public String getLayerInfo(){
- String str = "Layer name: " + this.getLayerName();
- str += System.getProperty("line.separator") + "Layer file: " + this.getFileName();
- str += System.getProperty("line.separator") + "Layer type: " + this.getLayerType();
- str += System.getProperty("line.separator") + "Shape type: " + this.getShapeType();
-
- return str;
- }
-
- /**
- * Save layer to a file
- */
- public void saveFile(){}
-
- /**
- * Save layer to a file
- * @param fileName File name
- */
- public void saveFile(String fileName){}
- //
-
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/RasterLayer.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layer/RasterLayer.java
deleted file mode 100644
index a8b186e2..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/RasterLayer.java
+++ /dev/null
@@ -1,582 +0,0 @@
-/* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.layer;
-
-import com.l2fprod.common.beans.BaseBeanInfo;
-import com.l2fprod.common.beans.ExtendedPropertyDescriptor;
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.common.GenericFileFilter;
-import org.meteoinfo.common.MIMath;
-import org.meteoinfo.common.util.GlobalUtil;
-import org.meteoinfo.data.GridArray;
-import org.meteoinfo.geometry.legend.LegendScheme;
-import org.meteoinfo.geometry.shape.ShapeTypes;
-import java.awt.Color;
-import java.awt.RenderingHints;
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.swing.JFileChooser;
-import javax.swing.JOptionPane;
-
-import org.meteoinfo.data.mapdata.MapDataManage;
-import org.meteoinfo.projection.ProjectionInfo;
-import org.meteoinfo.ndarray.Index;
-
-/**
- *
- * @author yaqiang
- */
-public class RasterLayer extends ImageLayer {
- //
-
- //private LegendScheme _legendScheme;
- private GridArray _gridData;
- private GridArray _originGridData = null;
- private boolean _isProjected = false;
- private List _colors;
- //private InterpolationMode _interpMode = InterpolationMode.NearestNeighbor;
- //
- //
-
- /**
- * Constructor
- */
- public RasterLayer() {
- this.setLayerType(LayerTypes.RasterLayer);
- this.setShapeType(ShapeTypes.Image);
- }
- //
- //
-
- /**
- * Set legend scheme
- *
- * @param ls Legend scheme
- */
- @Override
- public void setLegendScheme(LegendScheme ls) {
- super.setLegendScheme(ls);
- if (ls == null) {
- updateImage(ls);
- } else if (ls.getBreakNum() < 200) {
- updateImage(ls);
- } else {
- setPaletteByLegend();
- }
- }
-
- /**
- * Get grid data
- *
- * @return Grid data
- */
- public GridArray getGridData() {
- return _gridData;
- }
-
- /**
- * Set grid data
- *
- * @param gdata Grid data
- */
- public void setGridData(GridArray gdata) {
- _gridData = gdata;
- updateGridData();
- }
-
- /**
- * Get if is projected
- *
- * @return Boolean
- */
- public boolean isProjected() {
- return _isProjected;
- }
-
- /**
- * Set if is projected
- *
- * @param istrue Boolean
- */
- public void setProjected(boolean istrue) {
- _isProjected = istrue;
- }
-
-// public InterpolationMode InterpMode
-// {
-// get { return _interpMode; }
-// set
-// {
-// _interpMode = value;
-// if (_interpMode == InterpolationMode.Invalid)
-// _interpMode = InterpolationMode.NearestNeighbor;
-// }
-// }
- //
- //
- /**
- * Get cell value by a point
- *
- * @param iIdx I index
- * @param jIdx J index
- * @return Cell value
- */
- public double getCellValue(int iIdx, int jIdx) {
- return _gridData.getDoubleValue(iIdx, jIdx);
- }
-
- /**
- * Update image by legend scheme
- *
- * @param als The legend scheme
- */
- public void updateImage(LegendScheme als) {
- BufferedImage image;
- if (_gridData.getData().getRank() <= 2) {
- image = getImageFromGridData(_gridData, als);
- } else {
- image = getRGBImage(_gridData);
- super.setLegendScheme(null);
- }
- this.setImage(image);
- }
-
- /**
- * Update image by legend scheme
- */
- public void updateImage() {
- BufferedImage image = getImageFromGridData(_gridData, this.getLegendScheme());
- this.setImage(image);
- }
-
- private BufferedImage getRGBImage(GridArray gdata) {
- int width, height, r, g, b;
- width = gdata.getXNum();
- height = gdata.getYNum();
- BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- Index index = gdata.getData().getIndex();
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- r = gdata.getData().getInt(index);
- index.incr();
- g = gdata.getData().getInt(index);
- index.incr();
- b = gdata.getData().getInt(index);
- index.incr();
- image.setRGB(j, height - i - 1, new Color(r, g, b).getRGB());
- }
- }
-
- return image;
- }
-
- private BufferedImage getImageFromGridData(GridArray gdata, LegendScheme als) {
- int width, height, breakNum;
- width = gdata.getXNum();
- height = gdata.getYNum();
- breakNum = als.getBreakNum();
- double[] breakValue = new double[breakNum];
- Color[] breakColor = new Color[breakNum];
- Color undefColor = new Color(255, 255, 255, 0);
- Color defaultColor = als.getLegendBreaks().get(breakNum - 1).getColor();
- Color color;
- for (int i = 0; i < breakNum; i++) {
- breakValue[i] = Double.parseDouble(als.getLegendBreaks().get(i).getEndValue().toString());
- color = als.getLegendBreaks().get(i).getColor();
- breakColor[i] = color;
- if (als.getLegendBreaks().get(i).isNoData()) {
- undefColor = color;
- } else {
- defaultColor = color;
- }
- }
- BufferedImage aImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- double oneValue;
- Color oneColor;
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- //oneValue = gdata.data[i][j];
- oneValue = gdata.getDoubleValue(i, j);
- if (Double.isNaN(oneValue) || MIMath.doubleEquals(oneValue, gdata.missingValue)) {
- oneColor = undefColor;
- } else {
- oneColor = als.findLegendBreak(oneValue).getColor();
- }
- aImage.setRGB(j, height - i - 1, oneColor.getRGB());
- }
- }
-
- return aImage;
- }
-
- private BufferedImage getImageFromGridData(GridArray gdata, List colors) {
- int width, height;
- width = gdata.getXNum();
- height = gdata.getYNum();
- BufferedImage aImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- int oneValue;
- Color oneColor;
- int n = colors.size();
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- oneValue = gdata.getValue(i, j).intValue();
- oneColor = colors.get(oneValue);
- aImage.setRGB(j, height - i - 1, oneColor.getRGB());
- }
- }
-
- return aImage;
- }
-
- /**
- * Set color palette to a image from a palette file
- *
- * @param aFile File path
- */
- @Override
- public void setPalette(String aFile) {
- List colors = this.getColorsFromPaletteFile(aFile);
- BufferedImage image = this.getImageFromGridData(_gridData, colors);
- this.setImage(image);
-
- LegendScheme ls = new LegendScheme(ShapeTypes.Image);
- ls.importFromPaletteFile_Unique(aFile);
- this.setLegendScheme(ls);
- }
-
- /**
- * Set color palette by legend scheme
- */
- public void setPaletteByLegend() {
- _colors = this.getLegendScheme().getColors();
- BufferedImage image = this.getImageFromGridData(_gridData, _colors);
- this.setImage(image);
- }
-
- /**
- * Update grid data
- */
- public void updateGridData() {
- WorldFilePara aWFP = new WorldFilePara();
-
- //aWFP.xUL = _gridData.xArray[0];
- //aWFP.yUL = _gridData.yArray[_gridData.getYNum() - 1];
- aWFP.xUL = _gridData.xArray[0] - _gridData.getXDelt() / 2;
- aWFP.yUL = _gridData.yArray[_gridData.getYNum() - 1] + _gridData.getYDelt() / 2;
- aWFP.xScale = _gridData.getXDelt();
- aWFP.yScale = -_gridData.getYDelt();
-
- aWFP.xRotate = 0;
- aWFP.yRotate = 0;
-
- this.setWorldFilePara(aWFP);
-
- updateExtent();
- }
-
- private void updateExtent() {
- double XBR, YBR;
- XBR = _gridData.getXNum() * this.getWorldFilePara().xScale + this.getWorldFilePara().xUL;
- YBR = _gridData.getYNum() * this.getWorldFilePara().yScale + this.getWorldFilePara().yUL;
- Extent aExtent = new Extent();
- aExtent.minX = this.getWorldFilePara().xUL;
- aExtent.minY = YBR;
- aExtent.maxX = XBR;
- aExtent.maxY = this.getWorldFilePara().yUL;
- this.setExtent(aExtent);
- }
-
- /**
- * Update origin data
- */
- public void updateOriginData() {
- _originGridData = (GridArray) _gridData.clone();
- _isProjected = true;
- }
-
- /**
- * Get origin data
- */
- public void getOriginData() {
- _gridData = (GridArray) _originGridData.clone();
- }
-
- /**
- * Save layer as a shape file
- */
- @Override
- public void saveFile() {
- File aFile = new File(this.getFileName());
- if (aFile.exists()) {
- saveFile(aFile.getAbsolutePath());
- } else {
- JFileChooser aDlg = new JFileChooser();
- String curDir = System.getProperty("user.dir");
- aDlg.setCurrentDirectory(new File(curDir));
- String[] fileExts = {"bil"};
- GenericFileFilter pFileFilter = new GenericFileFilter(fileExts, "BIL File (*.bil)");
- aDlg.addChoosableFileFilter(pFileFilter);
- aDlg.setFileFilter(pFileFilter);
- fileExts = new String[]{"grd"};
- pFileFilter = new GenericFileFilter(fileExts, "Surfer ASCII Grid File (*.grd)");
- aDlg.addChoosableFileFilter(pFileFilter);
- fileExts = new String[]{"asc"};
- pFileFilter = new GenericFileFilter(fileExts, "ESRI ASCII Grid File (*.asc)");
- aDlg.addChoosableFileFilter(pFileFilter);
- aDlg.setAcceptAllFileFilterUsed(false);
- if (JFileChooser.APPROVE_OPTION == aDlg.showSaveDialog(null)) {
- aFile = aDlg.getSelectedFile();
- System.setProperty("user.dir", aFile.getParent());
- String extent = ((GenericFileFilter) aDlg.getFileFilter()).getFileExtent();
- String fileName = aFile.getAbsolutePath();
- if (!fileName.substring(fileName.length() - extent.length()).equals(extent)) {
- fileName = fileName + "." + extent;
- }
- saveFile(fileName);
- }
- }
- }
-
- /**
- * Save layer as a file
- *
- * @param fileName File name
- */
- @Override
- public void saveFile(String fileName) {
- this.saveFile(fileName, this.getProjInfo());
- }
-
- /**
- * Save layer as a file
- *
- * @param fileName File name
- * @param projInfo Projection information
- */
- public void saveFile(String fileName, ProjectionInfo projInfo) {
- File aFile = new File(fileName);
- if (aFile.exists()) {
- int n = JOptionPane.showConfirmDialog(null, "Overwirte the existing file?", "Overwrite confirm", JOptionPane.YES_NO_OPTION);
- if (n == JOptionPane.NO_OPTION) {
- return;
- }
- }
- try {
- this.setFileName(fileName);
- String ext = GlobalUtil.getFileExtension(fileName);
- switch (ext) {
- case "bil":
- this._gridData.saveAsBILFile(fileName);
- break;
- case "grd":
- this._gridData.saveAsSurferASCIIFile(fileName);
- break;
- case "asc":
- this._gridData.saveAsESRIASCIIFile(fileName);
- break;
- default:
- return;
- }
- if (!this.getProjInfo().isLonLat()) {
- String projFn = fileName.substring(0, fileName.length() - 3) + "prj";
- MapDataManage.writeProjFile(projFn, projInfo);
- }
- } catch (IOException ex) {
- Logger.getLogger(RasterLayer.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
-
- //
- //
- public class RasterLayerBean {
-
- RasterLayerBean() {
- }
-
- //
- /**
- * Get layer type
- *
- * @return Layer type
- */
- public LayerTypes getLayerType() {
- return RasterLayer.this.getLayerType();
- }
-
- /**
- * Set layer type
- *
- * @param lt Layer type
- */
- public void setLayerType(LayerTypes lt) {
- RasterLayer.this.setLayerType(lt);
- }
-
- /**
- * Get layer draw type
- *
- * @return Layer draw type
- */
- public LayerDrawType getLayerDrawType() {
- return RasterLayer.this.getLayerDrawType();
- }
-
- /**
- * Set layer draw type
- *
- * @param ldt Layer draw type
- */
- public void setLayerDrawType(LayerDrawType ldt) {
- RasterLayer.this.setLayerDrawType(ldt);
- }
-
- /**
- * Get file name
- *
- * @return File name
- */
- public String getFileName() {
- return RasterLayer.this.getFileName();
- }
-
- /**
- * Set file name
- *
- * @param fn File name
- */
- public void setFileName(String fn) {
- RasterLayer.this.setFileName(fn);
- }
-
- /**
- * Get layer handle
- *
- * @return Layer handle
- */
- public int getHandle() {
- return RasterLayer.this.getHandle();
- }
-
- /**
- * Get layer name
- *
- * @return Layer name
- */
- public String getLayerName() {
- return RasterLayer.this.getLayerName();
- }
-
- /**
- * Set layer name
- *
- * @param name Layer name
- */
- public void setLayerName(String name) {
- RasterLayer.this.setLayerName(name);
- }
-
- /**
- * Get if is maskout
- *
- * @return If is maskout
- */
- public boolean isMaskout() {
- return RasterLayer.this.isMaskout();
- }
-
- /**
- * Set if maskout
- *
- * @param value If maskout
- */
- public void setMaskout(boolean value) {
- RasterLayer.this.setMaskout(value);
- }
-
- /**
- * Get if is visible
- *
- * @return If is visible
- */
- public boolean isVisible() {
- return RasterLayer.this.isVisible();
- }
-
- /**
- * Set if is visible
- *
- * @param value If is visible
- */
- public void setVisible(boolean value) {
- RasterLayer.this.setVisible(value);
- }
-
- /**
- * Get interpolation
- *
- * @return Interpolation
- */
- public String getInterpolation() {
- if (interp == RenderingHints.VALUE_INTERPOLATION_BILINEAR) {
- return "bilinear";
- } else if (interp == RenderingHints.VALUE_INTERPOLATION_BICUBIC) {
- return "bicubic";
- } else {
- return "nearest";
- }
- }
-
- /**
- * Set interpolation
- *
- * @param value Interpolation
- */
- public void setInterpolation(String value) {
- switch (value) {
- case "nearest":
- interp = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
- break;
- case "bilinear":
- interp = RenderingHints.VALUE_INTERPOLATION_BILINEAR;
- break;
- case "bicubic":
- interp = RenderingHints.VALUE_INTERPOLATION_BICUBIC;
- break;
- }
- }
- //
- }
-
- public static class RasterLayerBeanBeanInfo extends BaseBeanInfo {
-
- public RasterLayerBeanBeanInfo() {
- super(RasterLayer.RasterLayerBean.class);
- addProperty("fileName").setCategory("Read only").setReadOnly().setDisplayName("File name");
- addProperty("layerType").setCategory("Read only").setReadOnly().setDisplayName("Layer type");
- addProperty("layerDrawType").setCategory("Read only").setReadOnly().setDisplayName("Layer draw type");
- addProperty("handle").setCategory("Read only").setReadOnly().setDisplayName("Handle");
- addProperty("layerName").setCategory("Editable").setDisplayName("Layer name");
- addProperty("visible").setCategory("Editable").setDisplayName("Visible");
- addProperty("maskout").setCategory("Editable").setDisplayName("Is maskout");
- ExtendedPropertyDescriptor e = addProperty("interpolation");
- e.setCategory("Editable").setPropertyEditorClass(InterpolationEditor.class);
- e.setDisplayName("Interpolation");
- }
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/VectorLayer.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layer/VectorLayer.java
deleted file mode 100644
index 071c160a..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/VectorLayer.java
+++ /dev/null
@@ -1,3144 +0,0 @@
-/* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.layer;
-
-import org.meteoinfo.common.*;
-import org.meteoinfo.data.mapdata.ShapeFileManage;
-import org.meteoinfo.geometry.legend.*;
-import org.meteoinfo.geoprocess.GeoComputation;
-import org.meteoinfo.common.colors.ColorUtil;
-import org.meteoinfo.projection.ProjectionInfo;
-import org.meteoinfo.table.*;
-import org.meteoinfo.ndarray.DataType;
-import org.meteoinfo.geometry.graphic.Graphic;
-import org.meteoinfo.geometry.shape.PointShape;
-import org.meteoinfo.geometry.shape.PolygonShape;
-import org.meteoinfo.geometry.shape.PolylineShape;
-import org.meteoinfo.geometry.shape.Shape;
-import org.meteoinfo.geometry.shape.ShapeTypes;
-import java.awt.Color;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.swing.JFileChooser;
-import javax.swing.JOptionPane;
-import javax.swing.undo.UndoManager;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Result;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.sax.SAXTransformerFactory;
-import javax.xml.transform.sax.TransformerHandler;
-import javax.xml.transform.stream.StreamResult;
-
-import org.locationtech.jts.geom.Coordinate;
-import org.locationtech.jts.geom.Geometry;
-import org.locationtech.jts.geom.GeometryFactory;
-import org.locationtech.jts.operation.union.CascadedPolygonUnion;
-import org.meteoinfo.legend.LegendManage;
-import org.meteoinfo.geometry.graphic.ChartGraphic;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.AttributesImpl;
-import org.meteoinfo.geometry.shape.PointZShape;
-import org.meteoinfo.geometry.shape.Polygon;
-import org.meteoinfo.geometry.shape.Polyline;
-import org.meteoinfo.geometry.shape.PolylineZShape;
-
-/**
- * Vector layer class
- *
- * @author yaqiang
- */
-public class VectorLayer extends MapLayer {
-
- enum SelectType {
- NEW,
- ADD_TO_CURRENT,
- REMOVE_FROM_CURRENT,
- SELECT_FROM_CURRENT
- }
-
- //
- //private final boolean _isEditing;
- private boolean _avoidCollision;
- private List _shapeList;
- private AttributeTable _attributeTable;
- private LabelSet _labelSet;
- private List _labelPoints;
- private ChartSet _chartSet;
- private List _chartPoints;
- //private int _numFields;
- private int _identiferShape;
- private float _drawingZoom = 1.0f;
- private List _originShapes = null;
- private AttributeTable _originAttributeTable = null;
- private List _originLabelPoints = null;
- private List _originChartPoints = null;
- private ProjectionInfo originProjInfo = null;
- private boolean _projected = false;
- private boolean editing = false;
- private Shape editingShape;
- private final UndoManager undoManager = new UndoManager();
- //
-
- //
- /**
- * Constructor
- *
- * @param shapeType Shape type
- */
- public VectorLayer(ShapeTypes shapeType) {
- super();
- this.setLayerType(LayerTypes.VectorLayer);
- this.setShapeType(shapeType);
- _avoidCollision = false;
- _attributeTable = new AttributeTable();
- _labelSet = new LabelSet();
- _labelPoints = new ArrayList<>();
- _chartSet = new ChartSet();
- _chartPoints = new ArrayList<>();
- _shapeList = new ArrayList<>();
- LegendScheme ls = LegendManage.createSingleSymbolLegendScheme(shapeType);
- super.setLegendScheme(ls);
- //_isEditing = false;
- }
- //
-
- //
- /**
- * Get UndoManager
- *
- * @return UndoManager
- */
- public UndoManager getUndoManager() {
- return undoManager;
- }
-
- /**
- * Get if avoid collision
- *
- * @return Boolean
- */
- public boolean getAvoidCollision() {
- return this._avoidCollision;
- }
-
- /**
- * Set if avoid collision
- *
- * @param istrue Boolean
- */
- public void setAvoidCollision(boolean istrue) {
- this._avoidCollision = istrue;
- }
-
- /**
- * Get shape number
- *
- * @return Shape number
- */
- public int getShapeNum() {
- return _shapeList.size();
- }
-
- /**
- * Get shape list
- *
- * @return Shape list
- */
- public List extends Shape> getShapes() {
- return _shapeList;
- }
-
- /**
- * Set shape list
- *
- * @param shapes Shape list
- */
- public void setShapes(List extends Shape> shapes) {
- _shapeList = (List) shapes;
- }
-
- /**
- * Get attribute table
- *
- * @return The attribute table
- */
- public AttributeTable getAttributeTable() {
- return _attributeTable;
- }
-
- /**
- * Set attribute table
- *
- * @param table The attribute table
- */
- public void setAttributeTable(AttributeTable table) {
- _attributeTable = table;
- }
-
-// /**
-// * Get field number
-// *
-// * @return Field number
-// */
-// public int getFieldNum() {
-// return this._numFields;
-// }
-// /**
-// * Set field number
-// *
-// * @param fNum Field number
-// */
-// public void setFieldNum(int fNum) {
-// this._numFields = fNum;
-// }
- /**
- * Get identifer shape index
- *
- * @return The identifer shape index
- */
- public int getIdentiferShape() {
- return this._identiferShape;
- }
-
- /**
- * Set identifer shape index
- *
- * @param idx Identifer shape index
- */
- public void setIdentiferShape(int idx) {
- this._identiferShape = idx;
- }
-
- @Override
- public void setTransparency(int trans) {
- super.setTransparency(trans);
- switch (this.getShapeType()) {
- case Polygon:
- case PolygonM:
- case PolygonZ:
- for (int i = 0; i < this.getLegendScheme().getBreakNum(); i++) {
- PolygonBreak aPGB = (PolygonBreak) this.getLegendScheme().getLegendBreaks().get(i);
- int alpha = (int) ((1 - (double) trans / 100.0) * 255);
- Color aColor = aPGB.getColor();
- aPGB.setColor(new Color(aColor.getRed(), aColor.getGreen(), aColor.getBlue(), alpha));
- }
- break;
- }
- }
-
- /**
- * Get label set
- *
- * @return Label set
- */
- public LabelSet getLabelSet() {
- return _labelSet;
- }
-
- /**
- * Set label set
- *
- * @param ls Label set
- */
- public void setLabelSet(LabelSet ls) {
- _labelSet = ls;
- }
-
- /**
- * Get label points
- *
- * @return The lable points
- */
- public List getLabelPoints() {
- return this._labelPoints;
- }
-
- /**
- * Set label points
- *
- * @param lps The lable points
- */
- public void setLabelPoints(List lps) {
- this._labelPoints = lps;
- }
-
- /**
- * Get chart set
- *
- * @return Chart set
- */
- public ChartSet getChartSet() {
- return _chartSet;
- }
-
- /**
- * Set chart set
- *
- * @param cs Chart set
- */
- public void setChartSet(ChartSet cs) {
- _chartSet = cs;
- }
-
- /**
- * Get chart points
- *
- * @return The chart points
- */
- public List getChartPoints() {
- return this._chartPoints;
- }
-
- /**
- * Set chart pints
- *
- * @param cps The chart points
- */
- public void setChartPoints(List cps) {
- this._chartPoints = cps;
- }
-
- /**
- * Get drawing zoom
- *
- * @return Drawing zoom
- */
- public float getDrawingZoom() {
- return this._drawingZoom;
- }
-
- /**
- * Set drawing zoom
- *
- * @param zoom Drawing zoom
- */
- public void setDrawingZoom(float zoom) {
- _drawingZoom = zoom;
- }
-
- /**
- * Get origin ProjectionInfo
- * @return ProjectionInfo
- */
- public ProjectionInfo getOriginProjInfo() {
- return this.originProjInfo == null ? this._projInfo : this.originProjInfo;
- }
-
- /**
- * Get if is projected
- *
- * @return Boolean
- */
- public boolean isProjected() {
- return _projected;
- }
-
- /**
- * Set if is projected
- *
- * @param istrue Boolean
- */
- public void setProjected(boolean istrue) {
- _projected = istrue;
- }
-
- /**
- * Override set legend scheme
- *
- * @param value Legend scheme
- */
- @Override
- public void setLegendScheme(LegendScheme value) {
- super.setLegendScheme(value);
- List fieldNames = this._attributeTable.getTable().getColumnNames();
- switch (value.getLegendType()) {
- case UniqueValue:
- if (!fieldNames.contains(value.getFieldName())) {
- LegendScheme ls = this.getLegendScheme();
- ls.setFieldName(fieldNames.get(0));
- for (int i = 0; i < this.getShapeNum(); i++) {
- ColorBreak cb = ls.getLegendBreaks().get(i);
- cb.setStartValue(this.getCellValue(fieldNames.get(0), i));
- cb.setEndValue(cb.getStartValue());
- }
- }
- break;
- case GraduatedColor:
- if (!fieldNames.contains(value.getFieldName()) && !value.isGeometry()) {
- String fName = "";
- if (fieldNames.size() > 0) {
- fName = fieldNames.get(0);
- }
- LegendScheme ls = this.createLegendScheme(LegendType.SingleSymbol, fName);
- super.setLegendScheme(ls);
- }
- break;
- }
- updateLegendIndexes();
- }
-
- /**
- * Get if is editing
- *
- * @return Boolean
- */
- public boolean isEditing() {
- return editing;
- }
-
- /**
- * Set if is editing
- *
- * @param value Boolean
- */
- public void setEditing(boolean value) {
- editing = value;
- }
-
- /**
- * Get editing shape
- *
- * @return Editing shape
- */
- public Shape getEditingShape() {
- return editingShape;
- }
-
- /**
- * Set editing shape
- *
- * @param value The shape
- */
- public void setEditingShape(Shape value) {
- editingShape = value;
- for (Shape shape : _shapeList) {
- shape.setEditing(false);
- }
- editingShape.setEditing(true);
- }
-
- //
- //
- //
- /**
- * Update charts properties
- */
- public void updateChartsProp() {
- for (Graphic chartG : _chartPoints) {
- ChartBreak aCP = (ChartBreak) chartG.getLegend();
- aCP.setLegendScheme(_chartSet.getLegendScheme());
- aCP.setMinSize(_chartSet.getMinSize());
- aCP.setMaxSize(_chartSet.getMaxSize());
- aCP.setMinValue(_chartSet.getMinValue());
- aCP.setMaxValue(_chartSet.getMaxValue());
- aCP.setBarWidth(_chartSet.getBarWidth());
- aCP.setAlignType(_chartSet.getAlignType());
- aCP.setView3D(_chartSet.isView3D());
- aCP.setThickness(_chartSet.getThickness());
- aCP.setDrawLabel(_chartSet.isDrawLabel());
- aCP.setLabelColor(_chartSet.getLabelColor());
- aCP.setLabelFont(_chartSet.getLabelFont());
- }
- }
-
- /**
- * Add charts
- */
- public void addCharts() {
- List shapeList = new ArrayList<>(this._shapeList);
- int shapeIdx = -1;
- PointD aPoint = new PointD();
-
- List selShapeIdx = getSelectedShapeIndexes();
- boolean isShapeSel = true;
- if (selShapeIdx.isEmpty()) {
- isShapeSel = false;
- }
- for (Shape aShape : shapeList) {
- shapeIdx += 1;
- if (isShapeSel) {
- if (!aShape.isSelected()) {
- continue;
- }
- }
-
- PointShape aPS = new PointShape();
- switch (this.getShapeType()) {
- case Point:
- case PointM:
- case PointZ:
- aPS.setPoint((PointD) ((PointShape) aShape).getPoint().clone());
- break;
- case Polyline:
- case PolylineM:
- case PolylineZ:
- int pIdx = ((PolylineShape) aShape).getPoints().size() / 2;
- aPS.setPoint((PointD) ((PolylineShape) aShape).getPoints().get(pIdx - 1).clone());
- break;
- case Polygon:
- case PolygonM:
- case PolygonZ:
- Extent aExtent = aShape.getExtent();
- aPoint.X = (aExtent.minX + aExtent.maxX) / 2;
- aPoint.Y = (aExtent.minY + aExtent.maxY) / 2;
- aPS.setPoint(aPoint);
- break;
- }
-
- ChartBreak aCP = new ChartBreak(_chartSet.getChartType());
- for (String fn : _chartSet.getFieldNames()) {
- aCP.getChartData().add(Float.parseFloat(getCellValue(fn, shapeIdx).toString()));
- }
- aCP.setXShift(_chartSet.getXShift());
- aCP.setYShift(_chartSet.getYShift());
- aCP.setLegendScheme(_chartSet.getLegendScheme());
- aCP.setMinSize(_chartSet.getMinSize());
- aCP.setMaxSize(_chartSet.getMaxSize());
- aCP.setMinValue(_chartSet.getMinValue());
- aCP.setMaxValue(_chartSet.getMaxValue());
- aCP.setBarWidth(_chartSet.getBarWidth());
- aCP.setAlignType(_chartSet.getAlignType());
- aCP.setView3D(_chartSet.isView3D());
- aCP.setThickness(_chartSet.getThickness());
- aCP.setShapeIndex(shapeIdx);
- aCP.setDrawLabel(_chartSet.isDrawLabel());
- aCP.setLabelColor(_chartSet.getLabelColor());
- aCP.setLabelFont(_chartSet.getLabelFont());
- aCP.setDecimalDigits(_chartSet.getDecimalDigits());
-
- ChartGraphic aGraphic = new ChartGraphic(aPS, aCP);
- addChart(aGraphic);
- }
- _chartSet.setDrawCharts(true);
- }
-
- /**
- * Update chart set with minimum and maximum values
- */
- public void updateChartSet() {
- List minList = new ArrayList<>();
- List maxList = new ArrayList<>();
- List sumList = new ArrayList<>();
- double[] minMax;
- List fieldNames = this._chartSet.getFieldNames();
- for (int i = 0; i < this.getShapeNum(); i++) {
- List vList = new ArrayList<>();
- double sum = 0;
- double v;
- for (int j = 0; j < fieldNames.size(); j++) {
- v = Double.parseDouble(this.getCellValue(fieldNames.get(j), i).toString());
- vList.add(v);
- sum += v;
- }
- //values.add(vList);
- minMax = MIMath.getMinMaxValue(vList, -9999.0);
- minList.add(minMax[0]);
- maxList.add(minMax[1]);
- sumList.add(sum);
- }
-
- switch (_chartSet.getChartType()) {
- case BarChart:
- minMax = MIMath.getMinMaxValue(minList, -9999.0);
- _chartSet.setMinValue((float) minMax[0]);
- minMax = MIMath.getMinMaxValue(maxList, -9999.0);
- _chartSet.setMaxValue((float) minMax[1]);
- break;
- case PieChart:
- minMax = MIMath.getMinMaxValue(sumList, -9999.0);
- _chartSet.setMinValue((float) minMax[0]);
- _chartSet.setMaxValue((float) minMax[1]);
- break;
- }
- }
-
- /**
- * Update charts
- */
- public void updateCharts() {
- int shapeIdx;
- for (ChartGraphic cg : this._chartPoints) {
- ChartBreak aCP = (ChartBreak) cg.getLegend();
- shapeIdx = aCP.getShapeIndex();
- aCP.getChartData().clear();
- for (String fn : _chartSet.getFieldNames()) {
- aCP.getChartData().add(Float.parseFloat(getCellValue(fn, shapeIdx).toString()));
- }
- aCP.setXShift(_chartSet.getXShift());
- aCP.setYShift(_chartSet.getYShift());
- aCP.setLegendScheme(_chartSet.getLegendScheme());
- aCP.setMinSize(_chartSet.getMinSize());
- aCP.setMaxSize(_chartSet.getMaxSize());
- aCP.setMinValue(_chartSet.getMinValue());
- aCP.setMaxValue(_chartSet.getMaxValue());
- aCP.setBarWidth(_chartSet.getBarWidth());
- aCP.setAlignType(_chartSet.getAlignType());
- aCP.setView3D(_chartSet.isView3D());
- aCP.setThickness(_chartSet.getThickness());
- aCP.setDrawLabel(_chartSet.isDrawLabel());
- aCP.setLabelColor(_chartSet.getLabelColor());
- aCP.setLabelFont(_chartSet.getLabelFont());
- aCP.setDecimalDigits(_chartSet.getDecimalDigits());
- }
- _chartSet.setDrawCharts(true);
- }
-
- /**
- * Add a chart point
- *
- * @param aCP Chart point
- */
- public void addChart(ChartGraphic aCP) {
- _chartPoints.add(aCP);
- }
-
- /**
- * Remove all charts
- */
- public void removeCharts() {
- _chartPoints.clear();
- _chartSet.setDrawCharts(false);
- }
-
- //
- //
- /**
- * Get a shape by index
- *
- * @param idx Shape index
- * @return Shape
- */
- public Shape getShape(int idx) {
- return this._shapeList.get(idx);
- }
-
- /**
- * Add a shape
- *
- * @param aShape Shape
- */
- public void addShape(Shape aShape) {
- _shapeList.add(aShape);
- updateLayerExtent(aShape);
- }
-
- /**
- * Find a shape contains anthor shape
- *
- * @param other Another shape
- * @return Result shape
- */
- public Shape findShape_contains(Shape other) {
- for (Shape s : this._shapeList) {
- if (s.contains(other)) {
- return s;
- }
- }
-
- return null;
- }
-
- /**
- * Find a shape crosses anthor shape
- *
- * @param other Another shape
- * @return Result shape
- */
- public Shape findShape_crosses(Shape other) {
- for (Shape s : this._shapeList) {
- if (s.crosses(other)) {
- return s;
- }
- }
-
- return null;
- }
-
- /**
- * Find a shape for reformation by a polyline shape
- *
- * @param other The polyline shape
- * @return Result shape
- */
- public Shape findReformShape(PolylineShape other) {
- if (this.getShapeType().isLine()) {
- return this.findShape_crosses(other);
- } else if (this.getShapeType().isPolygon()) {
- PointShape a = new PointShape();
- a.setPoint(other.getPoints().get(0));
- PolygonShape r = (PolygonShape) this.findShape_contains(a);
- if (r == null) {
- return null;
- } else {
- PointShape b = new PointShape();
- b.setPoint(other.getPoints().get(other.getPointNum() - 1));
- if (r.contains(b)) {
- return r;
- } else {
- return null;
- }
- }
- }
- return null;
- }
-
- /**
- * Select shapes
- *
- * @param extent The extent
- * @return Selected shapes
- */
- public List selectShapes(Extent extent) {
- return this.selectShapes(extent, false);
- }
-
- /**
- * Select shapes
- *
- * @param aExtent The extent
- * @param isSingleSel If just select one shape
- * @return Selected shapes
- */
- public List selectShapes(Extent aExtent, boolean isSingleSel) {
- return this.selectShapes(aExtent, _shapeList, isSingleSel);
- }
-
- /**
- * Select shapes
- *
- * @param aExtent The extent
- * @param shapes The shape list to be selected
- * @param isSingleSel If just select one shape
- * @return Selected shapes
- */
- public List selectShapes(Extent aExtent, List shapes, boolean isSingleSel) {
- List selectedShapes = new ArrayList<>();
- int i, j;
- PointD sp = aExtent.getCenterPoint();
-
- switch (this.getShapeType()) {
- case Point:
- case PointM:
- case PointZ:
- case WindArraw:
- case WindBarb:
- case WeatherSymbol:
- case StationModel:
- for (i = 0; i < shapes.size(); i++) {
- PointShape aPS = (PointShape) shapes.get(i);
- if (MIMath.pointInExtent(aPS.getPoint(), aExtent)) {
- selectedShapes.add(_shapeList.indexOf(aPS));
- if (isSingleSel) {
- break;
- }
- }
- }
- break;
- case Polyline:
- case PolylineM:
- case PolylineZ:
- Object sel;
- List dislist = new ArrayList<>();
- for (i = 0; i < shapes.size(); i++) {
- PolylineShape aPLS = (PolylineShape) shapes.get(i);
- if (MIMath.isExtentCross(aExtent, aPLS.getExtent())) {
- sel = GeoComputation.selectPolylineShape(sp, aPLS, aExtent.getWidth() / 2);
- if (sel != null) {
- if (dislist.size() > 0) {
- for (j = 0; j < dislist.size(); j++) {
- if ((Double) sel < dislist.get(j)) {
- selectedShapes.add(j, _shapeList.indexOf(aPLS));
- dislist.add(j, (Double) sel);
- break;
- }
- }
- } else {
- selectedShapes.add(_shapeList.indexOf(aPLS));
- dislist.add((Double) sel);
- }
- if (isSingleSel) {
- break;
- }
- }
- }
- }
- break;
- case Polygon:
- case PolygonM:
- case PolygonZ:
- for (i = shapes.size() - 1; i >= 0; i--) {
- PolygonShape aPGS = (PolygonShape) shapes.get(i);
- if (isSingleSel) {
- if (GeoComputation.pointInPolygon(aPGS, sp)) {
- selectedShapes.add(_shapeList.indexOf(aPGS));
- break;
- }
- } else if (GeoComputation.pointInPolygon(aPGS, sp)) {
- selectedShapes.add(_shapeList.indexOf(aPGS));
- } else if (MIMath.isExtentCross(aExtent, aPGS.getExtent())) {
- for (j = 0; j < aPGS.getPolygons().get(0).getOutLine().size(); j++) {
- if (MIMath.pointInExtent(aPGS.getPolygons().get(0).getOutLine().get(j), aExtent)) {
- selectedShapes.add(_shapeList.indexOf(aPGS));
- break;
- }
- }
- }
- }
- break;
- }
-
- return selectedShapes;
- }
-
- /**
- * Select shapes by a polygon shape
- *
- * @param polygonShape The polygon shape
- * @return Selected shape indexes
- */
- public List selectShapes(PolygonShape polygonShape) {
- List selIdxs = new ArrayList<>();
- for (int i = 0; i < _shapeList.size(); i++) {
- boolean isIn = false;
- List points = (List) _shapeList.get(i).getPoints();
- for (PointD aPoint : points) {
- if (GeoComputation.pointInPolygon(polygonShape, aPoint)) {
- isIn = true;
- break;
- }
- }
-
- if (isIn) {
- _shapeList.get(i).setSelected(true);
- selIdxs.add(i);
- }
- }
-
- return selIdxs;
- }
-
- /**
- * Select shapes by SQL expression
- *
- * @param expression The SQL expression
- */
- public void sqlSelect(String expression) {
- this.sqlSelect(expression, SelectType.NEW);
- }
-
- /**
- * Select shapes by SQL expression
- *
- * @param expression The SQL expression
- * @param selType Selection type
- */
- public void sqlSelect(String expression, String selType) {
- SelectType st = SelectType.valueOf(selType.toUpperCase());
- this.sqlSelect(expression, st);
- }
-
- /**
- * Select shapes by SQL expression
- *
- * @param expression The SQL expression
- * @param selType Selection type
- */
- public void sqlSelect(String expression, SelectType selType) {
- List rows = this._attributeTable.getTable().select(expression);
- List rowIdxs = new ArrayList<>();
- for (DataRow row : rows) {
- rowIdxs.add(row.getRowIndex());
- }
-
- int i;
- switch (selType) {
- case NEW: //Create a new selection
- for (i = 0; i < this.getShapeNum(); i++) {
- if (rowIdxs.contains(i)) {
- this._shapeList.get(i).setSelected(true);
- } else {
- this._shapeList.get(i).setSelected(false);
- }
- }
- break;
- case ADD_TO_CURRENT: //Add to current selection
- for (i = 0; i < this.getShapeNum(); i++) {
- if (rowIdxs.contains(i)) {
- this._shapeList.get(i).setSelected(true);
- }
- }
- break;
- case REMOVE_FROM_CURRENT: //Remove from current selection
- for (i = 0; i < this.getShapeNum(); i++) {
- if (rowIdxs.contains(i)) {
- this._shapeList.get(i).setSelected(false);
- }
- }
- break;
- case SELECT_FROM_CURRENT: //Select from current selection
- for (i = 0; i < this.getShapeNum(); i++) {
- if (this._shapeList.get(i).isSelected()) {
- if (!rowIdxs.contains(i)) {
- this._shapeList.get(i).setSelected(false);
- }
- }
- }
- break;
- }
- }
-
- /**
- * Select a shape by point
- *
- * @param p The point
- * @return Selected shape
- */
- public Shape selectShape(PointD p) {
- Coordinate c = new Coordinate(p.X, p.Y);
- Geometry point = new GeometryFactory().createPoint(c);
- for (Shape shape : _shapeList) {
- if (point.within(shape.toGeometry())) {
- return shape;
- }
- }
- return null;
- }
-
- /**
- * Get polygon hole index by point
- *
- * @param p The point
- * @return PolygonShape and polygon hole index
- */
- public Object[] selectPolygonHole(PointD p) {
- for (Shape shape : _shapeList) {
- int i = 0;
- for (Polygon poly : ((PolygonShape) shape).getPolygons()) {
- if (poly.hasHole()) {
- if (GeoComputation.pointInPolygon(poly.getOutLine(), p)) {
- int j = 0;
- for (List extends PointD> hole : poly.getHoleLines()) {
- if (GeoComputation.pointInPolygon(hole, p)) {
- return new Object[]{shape, i, j};
- }
- j += 1;
- }
- }
- }
- i += 1;
- }
- }
- return null;
- }
-
- /**
- * Get seleted data rows
- *
- * @return Selected data rows
- */
- public List getSelectedDataRows() {
- List rows = this.getDataRows();
- List selRows = new ArrayList<>();
- int i = 0;
- for (Shape shape : _shapeList) {
- if (shape.isSelected()) {
- selRows.add(rows.get(i));
- }
- i++;
- }
-
- return selRows;
- }
-
- /**
- * Get selected shapes
- *
- * @return Selected shapes
- */
- public List extends Shape> getSelectedShapes() {
- List selShapes = new ArrayList<>();
- for (Shape shape : _shapeList) {
- if (shape.isSelected()) {
- selShapes.add(shape);
- }
- }
-
- return selShapes;
- }
-
- /**
- * Get selected shape index list
- *
- * @return Index list
- */
- public List getSelectedShapeIndexes() {
- List selIndexes = new ArrayList<>();
- for (int i = 0; i < this.getShapeNum(); i++) {
- if (_shapeList.get(i).isSelected()) {
- selIndexes.add(i);
- }
- }
-
- return selIndexes;
- }
-
- /**
- * Get visible shapes
- *
- * @return The visible shapes
- */
- public List getVisibleShapes() {
- List visShapes = new ArrayList<>();
- for (Shape shape : _shapeList) {
- if (shape.isVisible()) {
- visShapes.add(shape);
- }
- }
-
- return visShapes;
- }
-
- /**
- * Clear selected shapes
- */
- public void clearSelectedShapes() {
- for (Shape aShape : _shapeList) {
- if (aShape.isSelected()) {
- aShape.setSelected(false);
- }
- }
- }
-
- /**
- * Get if has selected shape
- *
- * @return Boolean
- */
- public boolean hasSelectedShapes() {
- for (Shape shape : _shapeList) {
- if (shape.isSelected()) {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Clear editing shape
- */
- public void clearEditingShape() {
- if (editingShape != null) {
- editingShape.setEditing(false);
- }
- }
-
- //
- //
- /**
- * Get field number
- *
- * @return Field number
- */
- public int getFieldNumber() {
- return _attributeTable.getTable().getColumns().size();
- }
-
- /**
- * Get field name by index
- *
- * @param FieldIndex Field index
- * @return Field name
- */
- public String getFieldName(int FieldIndex) {
- return _attributeTable.getTable().getColumns().get(FieldIndex).getColumnName();
- }
-
- /**
- * Get field name list
- *
- * @return The field name list
- */
- public List getFieldNames() {
- List FNList = new ArrayList<>();
- for (int i = 0; i < this.getFieldNumber(); i++) {
- FNList.add(getFieldName(i));
- }
- return FNList;
- }
-
- /**
- * Get fields
- *
- * @return Fields
- */
- public List getFields() {
- DataColumnCollection cols = _attributeTable.getTable().getColumns();
- List fields = new ArrayList<>();
- for (DataColumn col : cols) {
- fields.add((Field) col);
- }
-
- return fields;
- }
-
- /**
- * Get field by index
- *
- * @param idx The field index
- * @return The field
- */
- public Field getField(int idx) {
- return (Field) _attributeTable.getTable().getColumns().get(idx);
- }
-
- /**
- * Get field by field name
- *
- * @param fieldName Field name
- * @return The field
- */
- public Field getField(String fieldName) {
- return (Field) _attributeTable.getTable().getColumns().get(fieldName);
- }
-
- /**
- * Get field index by name
- *
- * @param fieldName The field name
- * @return Field index
- */
- public int getFieldIdxByName(String fieldName) {
- int fieldIdx = -1;
- for (int i = 0; i < this.getFieldNumber(); i++) {
- if (_attributeTable.getTable().getColumns().get(i).getColumnName().equals(fieldName)) {
- fieldIdx = i;
- break;
- }
- }
-
- return fieldIdx;
- }
-
- /**
- * Get cell value
- *
- * @param fieldIndex Field index
- * @param shapeIndex Shape index
- * @return Cell value
- */
- public Object getCellValue(int fieldIndex, int shapeIndex) {
- return _attributeTable.getTable().getValue(shapeIndex, fieldIndex);
- }
-
- /**
- * 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 all data rows
- *
- * @return All data rows
- */
- public List getDataRows() {
- return this._attributeTable.getTable().getRows();
- }
-
- /**
- * Edit: Add a field
- *
- * @param aField The field
- */
- public void editAddField(Field aField) {
- for (int i = 0; i < this.getFieldNumber(); i++) {
- if (aField.getColumnName().equals(_attributeTable.getTable().getColumns().get(i).getColumnName())) {
- aField.setColumnName(aField.getColumnName() + "_1");
- }
- }
- _attributeTable.getTable().getColumns().add(aField);
- }
-
- /**
- * Edit: Add a field
- *
- * @param fieldName Field name
- * @param fieldType Field data type
- */
- public void editAddField(String fieldName, DataType fieldType) {
- Field aField = new Field(fieldName, fieldType);
- editAddField(aField);
- }
-
- /**
- * Edit: Remove a field
- *
- * @param fieldName Field name
- */
- public void editRemoveField(String fieldName) {
- this._attributeTable.getTable().removeColumn(this.getField(fieldName));
- }
-
- /**
- * Edit: Rename a field
- *
- * @param fieldName Origin field name
- * @param newFieldName New field name
- */
- public void editRenameField(String fieldName, String newFieldName) {
- this._attributeTable.getTable().renameColumn(this.getField(fieldName), newFieldName);
- }
-
- private void insertRecord(int position) throws Exception {
- DataRow aDR = _attributeTable.getTable().newRow();
- _attributeTable.getTable().getRows().add(position, aDR);
- }
-
- private void insertRecord(int position, DataRow record) throws Exception {
- _attributeTable.getTable().getRows().add(position, record);
- }
-
- /**
- * Edit: Edit cell value
- *
- * @param fieldName Field name
- * @param shapeIndex Shape index
- * @param value The data value
- */
- public void editCellValue(String fieldName, int shapeIndex, Object value) {
- _attributeTable.getTable().getRows().get(shapeIndex).setValue(fieldName, value);
- }
-
- /**
- * Edit: Edit cell value
- *
- * @param fieldIndex Field index
- * @param shapeIndex Shape index
- * @param value Data value
- */
- public void editCellValue(int fieldIndex, int shapeIndex, Object value) {
- _attributeTable.getTable().getRows().get(shapeIndex).setValue(fieldIndex, value);
- }
-
- /**
- * 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.getShapeNum(); 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;
- }
- }
-
- /**
- * Join data table
- *
- * @param dataTable The input data table
- * @param colName The column name for join
- */
- public void joinTable(DataTable dataTable, String colName) {
- this.joinTable(dataTable, colName, false);
- }
-
- /**
- * Join data table
- *
- * @param dataTable The input data table
- * @param colName The column name for join
- * @param isUpdate
- */
- public void joinTable(DataTable dataTable, String colName, boolean isUpdate) {
- DataTable thisTable = this._attributeTable.getTable();
- thisTable.join(dataTable, colName, isUpdate);
- this._attributeTable.updateDataTable();
- }
-
- /**
- * Join data table
- *
- * @param dataTable The input data table
- * @param colName_this The column name of this data table for join
- * @param colName_in The column name of the input data table for join
- * @param isUpdate If update the existing values with same column name
- */
- public void joinTable(DataTable dataTable, String colName_this, String colName_in, boolean isUpdate) {
- DataTable thisTable = this._attributeTable.getTable();
- thisTable.join(dataTable, colName_this, colName_in, isUpdate);
- this._attributeTable.updateDataTable();
- }
-
- /**
- * Remove joined data columns
- */
- public void removeJoins() {
- DataTable thisTable = this._attributeTable.getTable();
- for (DataColumn col : thisTable.getColumns()) {
- if (col.isJoined()) {
- thisTable.removeColumn(col);
- }
- }
- }
- //
-
- //
- /**
- * Edit: Insert shape
- *
- * @param aShape The shape
- * @param position The position index
- * @return If success
- * @throws java.lang.Exception
- */
- public boolean editInsertShape(Shape aShape, int position) throws Exception {
- if (position < 0) {
- position = 0;
- } else if (position > _shapeList.size()) {
- position = _shapeList.size();
- }
-
- _shapeList.add(position, aShape);
- insertRecord(position);
- updateLayerExtent(aShape);
-
- return true;
- }
-
- /**
- * Edit: Insert shape
- *
- * @param aShape The shape
- * @param position The position index
- * @param record
- * @return If success
- * @throws java.lang.Exception
- */
- public boolean editInsertShape(Shape aShape, int position, DataRow record) throws Exception {
- if (position < 0) {
- position = 0;
- } else if (position > _shapeList.size()) {
- position = _shapeList.size();
- }
-
- _shapeList.add(position, aShape);
- insertRecord(position, record);
- updateLayerExtent(aShape);
-
- return true;
- }
-
- /**
- * Edit: Add a shape
- *
- * @param aShape The shape
- * @return If success
- * @throws Exception
- */
- public boolean editAddShape(Shape aShape) throws Exception {
- int pos = _shapeList.size();
- return this.editInsertShape(aShape, pos);
- }
-
- /**
- * Edit: Add a shape
- *
- * @param aShape The shape
- * @param fvalues Field values
- * @throws Exception
- */
- public void editAddShape(Shape aShape, List
-
- //
- /**
- * Add label point
- *
- * @param aLP Label point
- */
- public void addLabel(Graphic aLP) {
- _labelPoints.add(aLP);
- }
-
- /**
- * 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);
- }
-
- /**
- * Add labels
- */
- public void addLabels() {
- addLabelsByColor();
-
- _labelSet.setDrawLabels(true);
- }
-
- /**
- * Add labels
- */
- private 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;
- }
-
- List selShapeIdx = getSelectedShapeIndexes();
- boolean isShapeSel = true;
- if (selShapeIdx.isEmpty()) {
- isShapeSel = false;
- }
- for (Shape aShape : _shapeList) {
- shapeIdx += 1;
- if (isShapeSel) {
- if (!aShape.isSelected()) {
- continue;
- }
- }
-
- ColorBreak aCB = null;
- if (this.getLegendScheme().getLegendType() == LegendType.SingleSymbol) {
- aCB = this.getLegendScheme().getLegendBreaks().get(0);
- } else if (this.getLegendScheme().getFieldName() != null) {
- String vStr = getCellValue(this.getLegendScheme().getFieldName(), shapeIdx).toString().trim();
- aCB = getColorBreak(vStr);
- }
- if (aCB == null) {
- continue;
- }
- if (!aCB.isDrawShape()) {
- continue;
- }
-
- PointShape aPS = new PointShape();
- switch (this.getShapeType()) {
- case Point:
- case PointM:
- case PointZ:
- aPS.setPoint((PointD) ((PointShape) aShape).getPoint().clone());
- break;
- case Polyline:
- case PolylineM:
- case PolylineZ:
- int pIdx = ((PolylineShape) aShape).getPoints().size() / 2;
- aPS.setPoint((PointD) ((PolylineShape) aShape).getPoints().get(pIdx - 1).clone());
- break;
- case Polygon:
- case PolygonM:
- case PolygonZ:
- Extent aExtent = aShape.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);
- }
- }
-
- private ColorBreak getColorBreak(String vStr) {
- ColorBreak aCB = null;
- switch (this.getLegendScheme().getLegendType()) {
- case SingleSymbol:
- aCB = this.getLegendScheme().getLegendBreaks().get(0);
- break;
- case UniqueValue:
- for (int j = 0; j < this.getLegendScheme().getLegendBreaks().size(); j++) {
- if (vStr.equals(this.getLegendScheme().getLegendBreaks().get(j).getStartValue().toString())) {
- aCB = this.getLegendScheme().getLegendBreaks().get(j);
- break;
- }
- }
- break;
- case GraduatedColor:
- double value;
- if ("".equals(vStr) || vStr == null) {
- value = 0;
- } else {
- value = Double.parseDouble(vStr);
- }
- int blNum = 0;
- for (int j = 0; j < this.getLegendScheme().getLegendBreaks().size(); j++) {
- ColorBreak aPB = this.getLegendScheme().getLegendBreaks().get(j);
- blNum += 1;
- if (value == Double.parseDouble(aPB.getStartValue().toString()) || (value > Double.parseDouble(aPB.getStartValue().toString())
- && value < Double.parseDouble(aPB.getEndValue().toString()))
- || (blNum == this.getLegendScheme().getLegendBreaks().size()
- && value == Double.parseDouble(aPB.getEndValue().toString()))) {
- aCB = aPB;
- break;
- }
- }
- break;
- }
-
- return aCB;
- }
-
- /**
- * Add labels of contour layer dynamicly
- *
- * @param sExtent View extent of MapView
- */
- public void addLabelsContourDynamic(Extent sExtent) {
- String dFormat;
- if (_labelSet.isAutoDecimal()) {
- double min = getMinValue(_labelSet.getFieldName());
- _labelSet.setDecimalDigits(MIMath.getDecimalNum(min));
- }
-
- dFormat = "%1$." + String.valueOf(_labelSet.getDecimalDigits()) + "f";
- int shapeIdx = 0;
- String text;
- for (Shape aShape : _shapeList) {
- PolylineShape aPLS = (PolylineShape) aShape;
- Extent IExtent = aPLS.getExtent();
- if (IExtent.maxX - IExtent.minX > (sExtent.maxX - sExtent.minX) / 10
- || IExtent.maxY - IExtent.minY > (sExtent.maxY - sExtent.minY) / 10) {
- LabelBreak aLP = new LabelBreak();
- int pIdx = aPLS.getPoints().size() / 2;
- //PointF aPoint = new PointF(0, 0);
- PointShape aPS = new PointShape();
- aPS.setPoint(aPLS.getPoints().get(pIdx - 1));
- if (this._labelSet.isAutoDecimal()) {
- text = DataConvert.removeTailingZeros(getCellValue(_labelSet.getFieldName(), shapeIdx).toString());
- } else {
- text = String.format(dFormat, Double.parseDouble(getCellValue(_labelSet.getFieldName(), shapeIdx).toString()));
- }
- aLP.setText(text);
- aLP.setFont(_labelSet.getLabelFont());
- aLP.setAlignType(_labelSet.getLabelAlignType());
- aLP.setYShift(_labelSet.getYOffset());
-
- String vStr;
- PolylineBreak aPLB;
- switch (this.getLegendScheme().getLegendType()) {
- case SingleSymbol:
- aPLB = (PolylineBreak) this.getLegendScheme().getLegendBreaks().get(0);
- aLP.setColor(aPLB.getColor());
- break;
- case UniqueValue:
- vStr = getCellValue(_labelSet.getFieldName(), shapeIdx).toString();
- for (int j = 0; j < this.getLegendScheme().getLegendBreaks().size(); j++) {
- aPLB = (PolylineBreak) this.getLegendScheme().getLegendBreaks().get(j);
- if (vStr.equals(aPLB.getStartValue().toString())) {
- aLP.setColor(aPLB.getColor());
- }
- }
- break;
- case GraduatedColor:
- vStr = getCellValue(_labelSet.getFieldName(), shapeIdx).toString();
- double value = Double.parseDouble(vStr);
- int blNum = 0;
- for (int j = 0; j < this.getLegendScheme().getLegendBreaks().size(); j++) {
- aPLB = (PolylineBreak) this.getLegendScheme().getLegendBreaks().get(j);
- blNum += 1;
- if (value == Double.parseDouble(aPLB.getStartValue().toString())
- || (value > Double.parseDouble(aPLB.getStartValue().toString())
- && value < Double.parseDouble(aPLB.getEndValue().toString()))
- || (blNum == this.getLegendScheme().getLegendBreaks().size()
- && value == Double.parseDouble(aPLB.getEndValue().toString()))) {
- aLP.setColor(aPLB.getColor());
- }
- }
- break;
- }
-
- Graphic aGraphic = new Graphic(aPS, aLP);
- addLabel(aGraphic);
- }
- shapeIdx += 1;
- }
-
- _labelSet.setDrawLabels(true);
- }
- //
-
- //
- /**
- * Update data to origion set
- */
- public void updateOriginData() {
- _originAttributeTable = (AttributeTable) _attributeTable.clone();
- _originShapes = new ArrayList<>();
- for (Shape aShape : _shapeList) {
- _originShapes.add((Shape) aShape.clone());
- }
-
- _originLabelPoints = new ArrayList<>(_labelPoints);
- _originChartPoints = new ArrayList<>(_chartPoints);
- this.originProjInfo = (ProjectionInfo) this._projInfo.clone();
- _projected = true;
- }
-
- /**
- * Get origin data
- */
- public void getOriginData() {
- _attributeTable = (AttributeTable) _originAttributeTable.clone();
- _shapeList = new ArrayList<>();
- for (Shape aShape : _originShapes) {
- _shapeList.add((Shape) aShape.clone());
- }
-
- _labelPoints = _originLabelPoints;
- _chartPoints = _originChartPoints;
- this._projInfo = (ProjectionInfo) this.originProjInfo.clone();
- updateExtent();
- }
-
- //
- //
- /**
- * Save as KML (Google Earth data format) file
- *
- * @param fileName KML file name
- */
- public void saveAsKMLFile(String fileName) {
- if (this.getShapeType().isPoint()) {
- saveAsKMLFile_Point(fileName);
- } else if (this.getShapeType().isLine()) {
- saveAsKMLFile_Polyline(fileName);
- } else if (this.getShapeType().isPolygon()) {
- saveAsKMLFile_Polygon(fileName);
- }
- }
-
- /**
- * Save as KML (Google Earth data format) file - Polygon
- *
- * @param fileName KML file name
- */
- private void saveAsKMLFile_Polygon(String fileName) {
- try {
- // Create XML text file
- SAXTransformerFactory fac = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
- TransformerHandler handler = fac.newTransformerHandler();
- Transformer transformer = handler.getTransformer();
- transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
- OutputStream outStream = new FileOutputStream(fileName);
- Result resultxml = new StreamResult(outStream);
- handler.setResult(resultxml);
- AttributesImpl atts = new AttributesImpl();
-
- //Write KML
- handler.startDocument();
- atts.addAttribute("", "", "xmlns", String.class.getName(), "http://www.opengis.net/kml/2.2");
- handler.startElement("", "", "kml", atts);
- atts.clear();
- handler.startElement("", "", "Document", atts);
- handler.startElement("", "", "Name", atts);
- handler.characters(fileName.toCharArray(), 0, fileName.length());
- handler.endElement("", "", "Name"); //Name
-
- //Write styles
- int styleNum = 0;
- String str;
- for (ColorBreak cb : this.getLegendScheme().getLegendBreaks()) {
- //StyleMap
- atts.addAttribute("", "", "id", "", "pg" + String.valueOf(styleNum));
- handler.startElement("", "", "StyleMap", atts);
- atts.clear();
- handler.startElement("", "", "Pair", atts);
- handler.startElement("", "", "key", atts);
- str = "normal";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "key"); //key
- handler.startElement("", "", "styleUrl", atts);
- str = "#pgn" + String.valueOf(styleNum);
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "styleUrl"); //styleUrl
- handler.endElement("", "", "Pair"); //Pair
-
- handler.startElement("", "", "Pair", atts);
- handler.startElement("", "", "key", atts);
- str = "highlight";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "key"); //key
- handler.startElement("", "", "styleUrl", atts);
- str = "#pgn";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "styleUrl"); //styleUrl
- handler.endElement("", "", "Pair"); //Pair
- handler.endElement("", "", "StyleMap"); //StyleMap
-
- //Normal style
- PolygonBreak pgb = (PolygonBreak) cb;
- atts.addAttribute("", "", "id", "", "pgn" + String.valueOf(styleNum));
- handler.startElement("", "", "Style", atts);
- atts.clear();
- handler.startElement("", "", "LineStyle", atts);
- handler.startElement("", "", "color", atts);
- str = ColorUtil.toKMLColor(pgb.getOutlineColor());
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "color"); //color
- handler.startElement("", "", "width", atts);
- str = String.valueOf((int) pgb.getOutlineSize());
- if (!pgb.isDrawOutline()) {
- str = "0";
- }
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "width");
- handler.endElement("", "", "LineStyle"); //LineStyle
- handler.startElement("", "", "PolyStyle", atts);
- handler.startElement("", "", "color", atts);
- str = ColorUtil.toKMLColor(pgb.getColor());
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "color"); //color
- handler.startElement("", "", "fill", atts);
- str = "1";
- if (!pgb.isDrawFill()) {
- str = "0";
- }
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "fill"); //fill
- handler.endElement("", "", "PolyStyle"); //PolyStyle
- handler.endElement("", "", "Style"); //Style
-
- styleNum += 1;
- }
-
- // Highlight style - shared by all elements
- atts.addAttribute("", "", "id", "", "pgh");
- handler.startElement("", "", "Style", atts);
- atts.clear();
- handler.startElement("", "", "LineStyle", atts);
- handler.startElement("", "", "color", atts);
- str = "00000000";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "color"); //color
- handler.endElement("", "", "LineStyle"); //LineStyle
- handler.startElement("", "", "PolyStyle", atts);
- handler.startElement("", "", "color", atts);
- str = "a0ff00ff";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "color"); //color
- handler.startElement("", "", "fill", atts);
- str = "1";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "fill"); //fill
- handler.endElement("", "", "PolyStyle"); //PolyStyle
- handler.endElement("", "", "Style"); //Style
-
- //Write shape coordinates
- handler.startElement("", "", "Folder", atts);
- handler.startElement("", "", "name", atts);
- str = fileName;
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "name"); //name
- handler.startElement("", "", "description", atts);
- str = "Generated using MeteoInfo";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "description"); //description
-
- boolean hasSelShape = this.hasSelectedShapes();
- for (Shape shp : _shapeList) {
- PolygonShape pgs = (PolygonShape) shp;
- if (hasSelShape) {
- if (!pgs.isSelected()) {
- continue;
- }
- }
- double currentLevel = pgs.lowValue;
- int levelNum = pgs.getLegendIndex();
-
- for (Polygon polygon : pgs.getPolygons()) {
- handler.startElement("", "", "Placemark", atts);
- handler.startElement("", "", "name", atts);
- str = "Level " + String.valueOf(currentLevel);
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "name"); //name
- handler.startElement("", "", "description", atts);
- str = "Level " + String.valueOf(currentLevel);
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "description"); //description
- handler.startElement("", "", "styleUrl", atts);
- str = "#pg" + String.valueOf(levelNum);
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "styleUrl");
- handler.startElement("", "", "Polygon", atts);
- handler.startElement("", "", "outerBoundaryIs", atts);
- handler.startElement("", "", "LinearRing", atts);
- handler.startElement("", "", "coordinates", atts);
- for (PointD point : polygon.getOutLine()) {
- str = String.valueOf(point.X) + "," + String.valueOf(point.Y) + " ";
- handler.characters(str.toCharArray(), 0, str.length());
- }
- handler.endElement("", "", "coordinates"); //coordinates
- handler.endElement("", "", "LinearRing"); //LinearRing
- handler.endElement("", "", "outerBoundaryIs"); //outerBoundaryIs
-
- // If Fill=true then add innerBoundaryIs for the contour 'holes'
- if (((PolygonBreak) this.getLegendScheme().getLegendBreaks().get(levelNum)).isDrawFill()) {
- if (polygon.hasHole()) {
- for (List extends PointD> hole : polygon.getHoleLines()) {
- handler.startElement("", "", "innerBoundaryIs", atts);
- handler.startElement("", "", "LinearRing", atts);
- handler.startElement("", "", "coordinates", atts);
- for (PointD point : hole) {
- str = String.valueOf(point.X) + "," + String.valueOf(point.Y) + " ";
- handler.characters(str.toCharArray(), 0, str.length());
- }
- handler.endElement("", "", "coordinates"); //coordinates
- handler.endElement("", "", "LinearRing"); //LinearRing
- handler.endElement("", "", "innerBoundaryIs"); //innerBoundaryIs
- }
- }
- }
-
- handler.endElement("", "", "Polygon"); //Polygon
- handler.endElement("", "", "Placemark"); //Placemark
- }
- }
-
- handler.endElement("", "", "Folder"); //Folder
- handler.endElement("", "", "Document"); //Document
- handler.endElement("", "", "kml"); //kml
-
- //End the document
- handler.endDocument();
-
- //Close
- outStream.close();
-
- } catch (TransformerConfigurationException e) {
- } catch (FileNotFoundException e) {
- } catch (SAXException e) {
- } catch (IOException e) {
- }
-
- }
-
- /**
- * Save as KML (Google Earth data format) file - Polyline
- *
- * @param fileName KML file name
- */
- private void saveAsKMLFile_Polyline(String fileName) {
- try {
- // Create XML text file
- SAXTransformerFactory fac = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
- TransformerHandler handler = fac.newTransformerHandler();
- Transformer transformer = handler.getTransformer();
- transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
- OutputStream outStream = new FileOutputStream(fileName);
- Result resultxml = new StreamResult(outStream);
- handler.setResult(resultxml);
- AttributesImpl atts = new AttributesImpl();
-
- //Write KML
- handler.startDocument();
- atts.addAttribute("", "", "xmlns", String.class.getName(), "http://www.opengis.net/kml/2.2");
- handler.startElement("", "", "kml", atts);
- atts.clear();
- handler.startElement("", "", "Document", atts);
- handler.startElement("", "", "Name", atts);
- handler.characters(fileName.toCharArray(), 0, fileName.length());
- handler.endElement("", "", "Name"); //Name
-
- //Write styles
- int styleNum = 0;
- String str;
- for (ColorBreak cb : this.getLegendScheme().getLegendBreaks()) {
- //StyleMap
- atts.addAttribute("", "", "id", "", "pg" + String.valueOf(styleNum));
- handler.startElement("", "", "StyleMap", atts);
- atts.clear();
- handler.startElement("", "", "Pair", atts);
- handler.startElement("", "", "key", atts);
- str = "normal";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "key"); //key
- handler.startElement("", "", "styleUrl", atts);
- str = "#pgn" + String.valueOf(styleNum);
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "styleUrl"); //styleUrl
- handler.endElement("", "", "Pair"); //Pair
-
- handler.startElement("", "", "Pair", atts);
- handler.startElement("", "", "key", atts);
- str = "highlight";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "key"); //key
- handler.startElement("", "", "styleUrl", atts);
- str = "#pgn";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "styleUrl"); //styleUrl
- handler.endElement("", "", "Pair"); //Pair
- handler.endElement("", "", "StyleMap"); //StyleMap
-
- //Normal style
- PolylineBreak pgb = (PolylineBreak) cb;
- atts.addAttribute("", "", "id", "", "pgn" + String.valueOf(styleNum));
- handler.startElement("", "", "Style", atts);
- atts.clear();
- handler.startElement("", "", "LineStyle", atts);
- handler.startElement("", "", "color", atts);
- str = ColorUtil.toKMLColor(pgb.getColor());
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "color"); //color
- handler.endElement("", "", "LineStyle"); //LineStyle
- handler.endElement("", "", "Style"); //Style
-
- styleNum += 1;
- }
-
- // Highlight style - shared by all elements
- atts.addAttribute("", "", "id", "", "pgh");
- handler.startElement("", "", "Style", atts);
- atts.clear();
- handler.startElement("", "", "LineStyle", atts);
- handler.startElement("", "", "color", atts);
- str = "00000000";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "color"); //color
- handler.endElement("", "", "LineStyle"); //LineStyle
- handler.endElement("", "", "Style"); //Style
-
- //Write shape coordinates
- handler.startElement("", "", "Folder", atts);
- handler.startElement("", "", "name", atts);
- str = fileName;
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "name"); //name
- handler.startElement("", "", "description", atts);
- str = "Generated using MeteoInfo";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "description"); //description
-
- boolean hasSelShape = this.hasSelectedShapes();
- for (Shape shp : _shapeList) {
- PolylineShape pgs = (PolylineShape) shp;
- if (hasSelShape) {
- if (!pgs.isSelected()) {
- continue;
- }
- }
- double currentLevel = pgs.getValue();
- int levelNum = pgs.getLegendIndex();
- int i = 0;
- for (Polyline line : pgs.getPolylines()) {
- handler.startElement("", "", "Placemark", atts);
- handler.startElement("", "", "name", atts);
- str = "Level " + String.valueOf(currentLevel);
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "name"); //name
- handler.startElement("", "", "description", atts);
- str = "Level " + String.valueOf(currentLevel);
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "description"); //description
- handler.startElement("", "", "styleUrl", atts);
- str = "#pg" + String.valueOf(levelNum);
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "styleUrl"); //styleUrl
- handler.startElement("", "", "LineString", atts);
- handler.startElement("", "", "coordinates", atts);
- for (PointD point : line.getPointList()) {
- str = String.valueOf(point.X) + "," + String.valueOf(point.Y);
- if (this.getShapeType() == ShapeTypes.PolylineZ) {
- str = str + "," + String.valueOf(((PolylineZShape) shp).getZArray()[i]);
- }
- str = str + " ";
- handler.characters(str.toCharArray(), 0, str.length());
- i += 1;
- }
- handler.endElement("", "", "coordinates"); //coordinates
- handler.endElement("", "", "LineString"); //LineString
- handler.endElement("", "", "Placemark"); //Placemark
- }
- }
-
- handler.endElement("", "", "Folder"); //Folder
- handler.endElement("", "", "Document"); //Document
- handler.endElement("", "", "kml"); //kml
-
- //End the document
- handler.endDocument();
-
- //Close
- outStream.close();
-
- } catch (TransformerConfigurationException e) {
- } catch (FileNotFoundException e) {
- } catch (SAXException e) {
- } catch (IOException e) {
- }
- }
-
- /**
- * Save as KML (Google Earth data format) file - Point
- *
- * @param fileName KML file name
- */
- private void saveAsKMLFile_Point(String fileName) {
- try {
- // Create XML text file
- SAXTransformerFactory fac = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
- TransformerHandler handler = fac.newTransformerHandler();
- Transformer transformer = handler.getTransformer();
- transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
- transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
- OutputStream outStream = new FileOutputStream(fileName);
- Result resultxml = new StreamResult(outStream);
- handler.setResult(resultxml);
- AttributesImpl atts = new AttributesImpl();
-
- //Write KML
- handler.startDocument();
- atts.addAttribute("", "", "xmlns", String.class.getName(), "http://www.opengis.net/kml/2.2");
- handler.startElement("", "", "kml", atts);
- atts.clear();
- handler.startElement("", "", "Document", atts);
- handler.startElement("", "", "Name", atts);
- handler.characters(fileName.toCharArray(), 0, fileName.length());
- handler.endElement("", "", "Name"); //Name
-
- //Write styles
- int styleNum = 0;
- String str;
- for (ColorBreak cb : this.getLegendScheme().getLegendBreaks()) {
- //StyleMap
- atts.addAttribute("", "", "id", "", "pg" + String.valueOf(styleNum));
- handler.startElement("", "", "StyleMap", atts);
- atts.clear();
- handler.startElement("", "", "Pair", atts);
- handler.startElement("", "", "key", atts);
- str = "normal";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "key"); //key
- handler.startElement("", "", "styleUrl", atts);
- str = "#pgn" + String.valueOf(styleNum);
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "styleUrl"); //styleUrl
- handler.endElement("", "", "Pair"); //Pair
-
- handler.startElement("", "", "Pair", atts);
- handler.startElement("", "", "key", atts);
- str = "highlight";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "key"); //key
- handler.startElement("", "", "styleUrl", atts);
- str = "#pgn";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "styleUrl"); //styleUrl
- handler.endElement("", "", "Pair"); //Pair
- handler.endElement("", "", "StyleMap"); //StyleMap
-
- //Normal style
- PointBreak pgb = (PointBreak) cb;
- atts.addAttribute("", "", "id", "", "pgn" + String.valueOf(styleNum));
- handler.startElement("", "", "Style", atts);
- atts.clear();
- handler.startElement("", "", "BalloonStyle", atts);
- handler.startElement("", "", "bgColor", atts);
- str = ColorUtil.toKMLColor(pgb.getColor());
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "bgColor"); //color
- handler.endElement("", "", "BalloonStyle"); //BalloonStyle
- handler.endElement("", "", "Style"); //Style
-
- styleNum += 1;
- }
-
- // Highlight style - shared by all elements
- atts.addAttribute("", "", "id", "", "pgh");
- handler.startElement("", "", "Style", atts);
- atts.clear();
- handler.startElement("", "", "BalloonStyle", atts);
- handler.startElement("", "", "color", atts);
- str = "00000000";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "color"); //color
- handler.endElement("", "", "BalloonStyle"); //BalloonStyle
- handler.endElement("", "", "Style"); //Style
-
- //Write shape coordinates
- handler.startElement("", "", "Folder", atts);
- handler.startElement("", "", "name", atts);
- str = fileName;
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "name"); //name
- handler.startElement("", "", "description", atts);
- str = "Generated using MeteoInfo";
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "description"); //description
-
- boolean hasSelShape = this.hasSelectedShapes();
- int shapIdx = 0;
- for (Shape shp : _shapeList) {
- PointShape pgs = (PointShape) shp;
- if (hasSelShape) {
- if (!pgs.isSelected()) {
- shapIdx += 1;
- continue;
- }
- }
- double currentLevel = pgs.getValue();
- int levelNum = pgs.getLegendIndex();
-
- handler.startElement("", "", "Placemark", atts);
- if (this.getLabelSet().isDrawLabels()) {
- handler.startElement("", "", "name", atts);
- str = this.getCellValue(this.getLabelSet().getFieldName(), shapIdx).toString();
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "name"); //name
- }
- handler.startElement("", "", "description", atts);
- str = "Level " + String.valueOf(currentLevel);
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "description"); //description
- handler.startElement("", "", "styleUrl", atts);
- str = "#pg" + String.valueOf(levelNum);
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "styleUrl"); //sytleUrl
- handler.startElement("", "", "Point", atts);
- handler.startElement("", "", "coordinates", atts);
- str = String.valueOf(pgs.getPoint().X) + "," + String.valueOf(pgs.getPoint().Y);
- if (this.getShapeType() == ShapeTypes.PointZ) {
- str = str + "," + String.valueOf(((PointZShape) shp).getZ());
- }
- handler.characters(str.toCharArray(), 0, str.length());
- handler.endElement("", "", "coordinates"); //coordinates
- handler.endElement("", "", "Point"); //Point
- handler.endElement("", "", "Placemark"); //Placemark
- }
-
- handler.endElement("", "", "Folder"); //Folder
- handler.endElement("", "", "Document"); //Document
- handler.endElement("", "", "kml"); //kml
-
- //End the document
- handler.endDocument();
-
- //Close
- outStream.close();
-
- } catch (TransformerConfigurationException e) {
- } catch (FileNotFoundException e) {
- } catch (SAXException e) {
- } catch (IOException e) {
- }
- }
- //
-
- //
- /**
- * Update extent
- */
- public void updateExtent() {
- for (int i = 0; i < _shapeList.size(); i++) {
- if (i == 0) {
- this.setExtent((Extent) _shapeList.get(i).getExtent().clone());
- } else {
- this.setExtent(MIMath.getLagerExtent(this.getExtent(), _shapeList.get(i).getExtent()));
- }
- }
- }
-
- /**
- * Update legend scheme
- *
- * @param aLT Legend type
- * @param fieldName Field name
- */
- public void updateLegendScheme(LegendType aLT, String fieldName) {
- this.setLegendScheme(createLegendScheme(aLT, fieldName));
- }
-
- /**
- * Update legend scheme - update legend indexes of the shapes
- */
- public void updateLegendIndexes() {
- LegendScheme ls = this.getLegendScheme();
- switch (ls.getLegendType()) {
- case UniqueValue:
- int shapeIdx = 0;
- if (this.getField(ls.getFieldName()).isNumeric()) {
- for (Shape aShape : this.getShapes()) {
- String vStr = this.getCellValue(ls.getFieldName(), shapeIdx).toString();
- aShape.setLegendIndex(-1);
- for (int i = 0; i < ls.getBreakNum(); i++) {
- if (MIMath.doubleEquals(Double.parseDouble(ls.getLegendBreaks().get(i).getStartValue().toString()),
- Double.parseDouble(vStr))) {
- aShape.setLegendIndex(i);
- break;
- }
- }
- shapeIdx += 1;
- }
- } else {
- for (Shape aShape : this.getShapes()) {
- String vStr = this.getCellValue(ls.getFieldName(), shapeIdx).toString();
- aShape.setLegendIndex(-1);
- for (int i = 0; i < ls.getBreakNum(); i++) {
- if (vStr.equals(ls.getLegendBreaks().get(i).getStartValue().toString())) {
- aShape.setLegendIndex(i);
- break;
- }
- }
- shapeIdx += 1;
- }
- }
- break;
- case GraduatedColor:
- if (!ls.isGeometry()) {
- shapeIdx = 0;
- int idx = -1;
- for (Shape aShape : this.getShapes()) {
- String vStr = this.getCellValue(ls.getFieldName(), shapeIdx).toString();
- double v = Double.parseDouble(vStr);
- if (Double.isNaN(v))
- idx = -1;
- else if (v <= ls.getMinValue())
- idx = 0;
- else if (v >= ls.getMaxValue())
- idx = ls.getBreakNum() - 1;
- else {
- int blNum = 0;
- for (int i = 0; i < ls.getBreakNum(); i++) {
- ColorBreak cb = ls.getLegendBreaks().get(i);
- blNum += 1;
- if (MIMath.doubleEquals(v, Double.parseDouble(cb.getStartValue().toString()))
- || (v > Double.parseDouble(cb.getStartValue().toString())
- && v < Double.parseDouble(cb.getEndValue().toString()))
- || (blNum == ls.getBreakNum() && v == Double.parseDouble(cb.getEndValue().toString()))) {
- idx = i;
- break;
- }
- }
- }
- aShape.setLegendIndex(idx);
- shapeIdx += 1;
- }
- }
- break;
- default:
- for (Shape aShape : this.getShapes()) {
- aShape.setLegendIndex(0);
- }
- break;
- }
- }
-
- /**
- * Create legend scheme
- *
- * @param aLT Legend type
- * @param fieldName Field name
- * @return Legend scheme
- */
- public LegendScheme createLegendScheme(LegendType aLT, String fieldName) {
- double min, max;
- ShapeTypes aST = this.getShapeType();
- LegendScheme aLS = new LegendScheme(this.getShapeType());
-
- min = aLS.getMinValue();
- max = aLS.getMaxValue();
- switch (aLT) {
- case SingleSymbol:
- Color aColor = Color.black;
- float size = 1.0F;
- switch (aST) {
- case Point:
- case PointM:
- case PointZ:
- aColor = Color.black;
- size = 5;
- break;
- case Polyline:
- case PolylineM:
- case PolylineZ:
- aColor = Color.black;
- break;
- case Polygon:
- case PolygonM:
- case PolygonZ:
- case Image:
- aColor = new Color(255, 251, 195);
- break;
- }
-
- aLS = LegendManage.createSingleSymbolLegendScheme(aST, aColor, size);
- break;
- case UniqueValue:
- Color[] colors;
- List valueList = new ArrayList<>();
- boolean isDateField = false;
- DataType colType = this.getAttributeTable().getTable().getColumns().get(fieldName).getDataType();
- if (colType == DataType.DATE) {
- isDateField = true;
- }
-
- List captions = new ArrayList<>();
- DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy/M/d");
-
- for (int i = 0; i < this.getAttributeTable().getTable().getRows().size(); i++) {
- Object value = this.getAttributeTable().getTable().getRows().get(i).getValue(fieldName);
- if (!valueList.contains(value.toString())) {
- valueList.add(value.toString());
- if (isDateField) {
- captions.add(format.format((LocalDateTime) value));
- }
- }
- }
-
-// if (valueList.size() == 1) {
-// JOptionPane.showMessageDialog(null, "The values of all shapes are same!");
-// break;
-// }
- if (valueList.size() <= 13) {
- colors = LegendManage.createRainBowColors(valueList.size());
- } else {
- colors = LegendManage.createRandomColors(valueList.size());
- }
- Color[] newcolors = new Color[colors.length + 1];
- newcolors[0] = Color.white;
- for (int i = 1; i < newcolors.length; i++) {
- newcolors[i] = colors[i - 1];
- }
-
- if (isDateField) {
- aLS = LegendManage.createUniqValueLegendScheme(valueList, captions, newcolors, aST, min,
- max, aLS.getHasNoData(), aLS.getUndefValue());
- } else {
- aLS = LegendManage.createUniqValueLegendScheme(valueList, newcolors,
- aST, min, max, aLS.getHasNoData(), aLS.getUndefValue());
- }
-
- aLS.setFieldName(fieldName);
- break;
- case GraduatedColor:
- double[] S = new double[this.getAttributeTable().getTable().getRows().size()];
- for (int i = 0; i < S.length; i++) {
- S[i] = Double.parseDouble(this.getAttributeTable().getTable().getRows().get(i).getValue(fieldName).toString());
- }
- double[] minmax = MIMath.getMinMaxValue(S, aLS.getUndefValue());
- min = minmax[0];
- max = minmax[1];
-
- if (min == max) {
- JOptionPane.showMessageDialog(null, "The values of all shapes are same!");
- break;
- }
-
- double[] CValues;
- CValues = LegendManage.createContourValues(min, max);
- colors = LegendManage.createRainBowColors(CValues.length + 1);
-
- aLS = LegendManage.createGraduatedLegendScheme(CValues, colors,
- aST, min, max, aLS.getHasNoData(), aLS.getUndefValue());
- aLS.setFieldName(fieldName);
- break;
- }
-
- return aLS;
- }
-
- /**
- * Clone VectorLayer object
- *
- * @return VectorLayer object
- */
- @Override
- public Object clone() {
- VectorLayer aLayer = new VectorLayer(this.getShapeType());
- aLayer.setExtent((Extent) this.getExtent().clone());
- aLayer.setFileName(this.getFileName());
- aLayer.setHandle(this.getHandle());
- aLayer.setLayerName(this.getLayerName());
- if (_projected) {
- for (Shape shape : _originShapes) {
- aLayer.addShape((Shape) shape.clone());
- }
- aLayer.setAttributeTable((AttributeTable) _originAttributeTable.clone());
- } else {
- for (Shape shape : _shapeList) {
- aLayer.addShape((Shape) shape.clone());
- }
- aLayer.setAttributeTable((AttributeTable) _attributeTable.clone());
- }
- aLayer.setLegendScheme((LegendScheme) this.getLegendScheme().clone());
- aLayer.setTransparency(this.getTransparency());
- aLayer.setLayerDrawType(this.getLayerDrawType());
- aLayer.setVisible(this.isVisible());
- aLayer.setLabelSet(_labelSet);
- aLayer.setExpanded(this.isExpanded());
- aLayer.setAvoidCollision(this._avoidCollision);
- aLayer.setMaskout(this.isMaskout());
- aLayer.setTag(this.getTag());
-
- return aLayer;
- }
-
- /**
- * Clone VectorLayer object - without attribute table
- *
- * @return Object
- */
- public Object cloneShapes() {
- VectorLayer aLayer = new VectorLayer(this.getShapeType());
- aLayer.setExtent((Extent) this.getExtent().clone());
- //aLayer.setFileName(this.getFileName());
- //aLayer.setHandle(this.getHandle());
- aLayer.setLayerName(this.getLayerName());
- aLayer.setProjInfo(this.getProjInfo());
- aLayer.setLegendScheme((LegendScheme) this.getLegendScheme().clone());
- if (_projected) {
- for (Shape shape : _originShapes) {
- aLayer.addShape((Shape) shape.clone());
- }
- } else {
- for (Shape shape : _shapeList) {
- aLayer.addShape((Shape) shape.clone());
- }
- }
- aLayer.setTransparency(this.getTransparency());
- aLayer.setLayerDrawType(this.getLayerDrawType());
- aLayer.setVisible(this.isVisible());
- aLayer.setLabelSet(_labelSet);
- aLayer.setExpanded(this.isExpanded());
- aLayer.setAvoidCollision(this._avoidCollision);
- aLayer.setMaskout(this.isMaskout());
- //aLayer.setTag(this.getTag());
-
- return aLayer;
- }
-
- /**
- * Clone VectorLayer object - only parameters
- *
- * @return Object
- */
- public Object cloneValue() {
- VectorLayer aLayer = new VectorLayer(this.getShapeType());
- //aLayer.setExtent((Extent) this.getExtent().clone());
- //aLayer.setFileName(this.getFileName());
- //aLayer.setHandle(this.getHandle());
- aLayer.setLayerName(this.getLayerName());
- aLayer.setProjInfo(this.getProjInfo());
- //aLayer.setLegendScheme((LegendScheme) this.getLegendScheme().clone());
- //aLayer.setTransparency(this.getTransparency());
- aLayer.setLayerDrawType(this.getLayerDrawType());
- aLayer.setVisible(this.isVisible());
- aLayer.setLabelSet(_labelSet);
- aLayer.setExpanded(this.isExpanded());
- aLayer.setAvoidCollision(this._avoidCollision);
- aLayer.setMaskout(this.isMaskout());
- //aLayer.setTag(this.getTag());
-
- return aLayer;
- }
-
- /**
- * To string
- *
- * @return String
- */
- @Override
- public String getLayerInfo() {
- String str = "Layer name: " + this.getLayerName();
- str += System.getProperty("line.separator") + "Layer file: " + this.getFileName();
- str += System.getProperty("line.separator") + "Layer type: " + this.getLayerType();
- str += System.getProperty("line.separator") + "Shape type: " + this.getShapeType();
- str += System.getProperty("line.separator") + "Shape count: " + String.valueOf(this.getShapeNum());
- str += System.getProperty("line.separator") + "Fields:";
- for (Field field : this.getFields()) {
- str += System.getProperty("line.separator") + "\t" + field.getColumnName() + ": " + field.getDataTypeName();
- }
-
- return str;
- }
- //
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/VectorLayerBeanInfo.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layer/VectorLayerBeanInfo.java
deleted file mode 100644
index 5b1f6856..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/VectorLayerBeanInfo.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package org.meteoinfo.layer;
-
-import com.l2fprod.common.beans.BaseBeanInfo;
-
-/**
- *
- * @author Yaqiang
- */
-public class VectorLayerBeanInfo extends BaseBeanInfo {
- public VectorLayerBeanInfo(){
- super(VectorLayer.class);
- addProperty("fileName").setCategory("Read only").setReadOnly().setDisplayName("File name");
- addProperty("layerType").setCategory("Read only").setReadOnly().setDisplayName("Layer type");
- addProperty("layerDrawType").setCategory("Read only").setReadOnly().setDisplayName("Layer draw type");
- addProperty("shapeType").setCategory("Read only").setReadOnly().setDisplayName("Shape type");
- addProperty("handle").setCategory("Read only").setReadOnly().setDisplayName("Handle");
- addProperty("layerName").setCategory("Editable").setDisplayName("Layer name");
- addProperty("visible").setCategory("Editable").setDisplayName("Visible");
- addProperty("maskout").setCategory("Editable").setDisplayName("Is maskout");
- //addProperty("transparency").setCategory("Editable").setDisplayName("Transparency Percent");
- addProperty("avoidCollision").setCategory("Editable").setDisplayName("Avoid collision");
- }
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/VisibleScale.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layer/VisibleScale.java
deleted file mode 100644
index f54374c3..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/VisibleScale.java
+++ /dev/null
@@ -1,119 +0,0 @@
- /* Copyright 2012 - Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.layer;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class VisibleScale {
- //
-
- private boolean _enableMinVisScale = false;
- private boolean _enableMaxVisScale = false;
- private double _minVisScale;
- private double _maxVisScale;
- //
- //
- //
- //
-
- /**
- * Get if is enable minimum visible scale
- *
- * @return Boolean
- */
- public boolean isEnableMinVisScale() {
- return _enableMinVisScale;
- }
-
- /**
- * Set if is enable minimum visible scale
- *
- * @param value Boolean
- */
- public void setEnableMinVisScale(boolean value) {
- _enableMinVisScale = value;
- }
-
- /**
- * Get if is enable maximum visible scale
- *
- * @return Boolean
- */
- public boolean isEnableMaxVisScale() {
- return _enableMaxVisScale;
- }
-
- /**
- * Set if is enable maximum visible scale
- *
- * @param value Boolean
- */
- public void setEnableMaxVisScale(boolean value) {
- _enableMaxVisScale = value;
- }
-
- /**
- * Get minimum visible scale value
- *
- * @return Minimum visible scale value
- */
- public double getMinVisScale() {
- return _minVisScale;
- }
-
- /**
- * Set minimum visible scale value
- *
- * @param value Minimum visible scale value
- */
- public void setMinVisScale(double value) {
- _minVisScale = value;
- }
-
- /**
- * Get maximum visible scale value
- *
- * @return maximum visible scale value
- */
- public double getMaxVisScale() {
- return _maxVisScale;
- }
-
- /**
- * Set maximum visible scale value
- *
- * @param value maximum visible scale value
- */
- public void setMaxVisScale(double value) {
- _maxVisScale = value;
- }
- //
- //
-
- /**
- * Get if is visible scale enabled
- *
- * @return Is visible scale enabled
- */
- public boolean isVisibleScaleEnabled() {
- if (this._enableMaxVisScale || this._enableMinVisScale) {
- return true;
- } else {
- return false;
- }
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/WebMapLayer.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layer/WebMapLayer.java
deleted file mode 100644
index 29c4593d..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/WebMapLayer.java
+++ /dev/null
@@ -1,919 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package org.meteoinfo.layer;
-
-//import com.sun.java.swing.Painter;
-import com.l2fprod.common.beans.BaseBeanInfo;
-import com.l2fprod.common.beans.ExtendedPropertyDescriptor;
-import com.l2fprod.common.beans.editor.ComboBoxPropertyEditor;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.Image;
-import java.awt.Rectangle;
-import java.awt.geom.Point2D;
-import java.awt.image.BufferedImage;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-import javax.imageio.ImageIO;
-
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.common.PointD;
-import org.meteoinfo.data.mapdata.webmap.*;
-import org.meteoinfo.data.mapdata.webmap.empty.EmptyTileFactory;
-import org.meteoinfo.data.mapdata.webmap.GeoUtil;
-import org.meteoinfo.projection.KnownCoordinateSystems;
-import org.meteoinfo.projection.Reproject;
-import org.meteoinfo.geometry.shape.ShapeTypes;
-
-/**
- *
- * @author wyq
- */
-public class WebMapLayer extends MapLayer {
- //
-
- private final boolean isNegativeYAllowed = true; //maybe rename to isNorthBounded and isSouthBounded?
- /**
- * The zoom level. Generally a value between 1 and 15 (TODO Is this true for
- * all the mapping worlds? What does this mean if some mapping system
- * doesn't support the zoom level?
- */
- private int zoom = 11;
- /**
- * The position, in map coordinates of the center point. This is
- * defined as the distance from the top and left edges of the map in pixels.
- * Dragging the map component will change the center position. Zooming
- * in/out will cause the center to be recalculated so as to remain in the
- * center of the new "map".
- */
- private Point2D center = new Point2D.Double(0, 0);
- /**
- * Indicates whether or not to draw the borders between tiles. Defaults to
- * false.
- *
- * TODO Generally not very nice looking, very much a product of testing
- * Consider whether this should really be a property or not.
- */
- private boolean drawTileBorders = false;
- /**
- * Factory used by this component to grab the tiles necessary for painting
- * the map.
- */
- private TileFactory factory;
- /**
- * The position in latitude/longitude of the "address" being mapped. This is
- * a special coordinate that, when moved, will cause the map to be moved as
- * well. It is separate from "center" in that "center" tracks the current
- * center (in pixels) of the viewport whereas this will not change when
- * panning or zooming. Whenever the addressLocation is changed, however, the
- * map will be repositioned.
- */
- private GeoPosition addressLocation;
- /**
- * Specifies whether panning is enabled. Panning is being able to click and
- * drag the map around to cause it to move
- */
- private boolean panEnabled = true;
- /**
- * Specifies whether zooming is enabled (the mouse wheel, for example,
- * zooms)
- */
- private boolean zoomEnabled = true;
- /**
- * Indicates whether the component should recenter the map when the "middle"
- * mouse button is pressed
- */
- private boolean recenterOnClickEnabled = true;
- /**
- * The overlay to delegate to for painting the "foreground" of the map
- * component. This would include painting waypoints, day/night, etc. Also
- * receives mouse events.
- */
- //private Painter overlay;
- private boolean designTime;
- private double webMapScale = 0.;
- private Image loadingImage;
- private boolean restrictOutsidePanning = false;
- private boolean horizontalWrapped = true;
- private WebMapProvider defaultProvider = WebMapProvider.OpenStreetMap;
- private Graphics2D graphics;
- private int width;
- private int height;
- private List scales = new ArrayList<>();
- //
- //
- // a property change listener which forces repaints when tiles finish loading
- //private TileLoadListener tileLoadListener = new TileLoadListener();
-
-// private final class TileLoadListener implements PropertyChangeListener {
-//
-// @Override
-// public void propertyChange(PropertyChangeEvent evt) {
-// if ("loaded".equals(evt.getPropertyName())
-// && Boolean.TRUE.equals(evt.getNewValue())) {
-// Tile t = (Tile) evt.getSource();
-// if (t.getZoom() == getZoom()) {
-// repaint();
-// /* this optimization doesn't save much and it doesn't work if you
-// * wrap around the world
-// Rectangle viewportBounds = getViewportBounds();
-// TilePoint tilePoint = t.getLocation();
-// Point point = new Point(tilePoint.getX() * getTileFactory().getTileSize(), tilePoint.getY() * getTileFactory().getTileSize());
-// Rectangle tileRect = new Rectangle(point, new Dimension(getTileFactory().getTileSize(), getTileFactory().getTileSize()));
-// if (viewportBounds.intersects(tileRect)) {
-// //convert tileRect from world space to viewport space
-// repaint(new Rectangle(
-// tileRect.x - viewportBounds.x,
-// tileRect.y - viewportBounds.y,
-// tileRect.width,
-// tileRect.height
-// ));
-// }*/
-// }
-// }
-// }
-// }
- //
- //
-
- /**
- * Constructor
- */
- public WebMapLayer() {
- super();
- this.setLayerType(LayerTypes.WebMapLayer);
- this.setShapeType(ShapeTypes.Image);
- this.setLayerDrawType(LayerDrawType.Image);
- this.setLayerName("OpenStreetMap");
- this.setExtent(new Extent(-2.0037508342789244E7, 2.0037508342789244E7, -1.8375854901481014E7, 1.8375854901481014E7));
- factory = new EmptyTileFactory();
-
- // make a dummy loading image
- try {
- URL url = this.getClass().getResource("/images/loading.png");
- this.setLoadingImage(ImageIO.read(url));
- } catch (Throwable ex) {
- System.out.println("could not load 'loading.png'");
- BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g2 = img.createGraphics();
- g2.setColor(Color.black);
- g2.fillRect(0, 0, 16, 16);
- g2.dispose();
- this.setLoadingImage(img);
- }
- }
- //
- //
-
- /**
- * Gets the current zoom level
- *
- * @return the current zoom level
- */
- public int getZoom() {
- return this.zoom;
- }
-
- /**
- * Set the current zoom level
- *
- * @param zoom the new zoom level
- */
- public void setZoom(int zoom) {
- if (zoom == this.zoom) {
- return;
- }
-
- TileFactoryInfo info = getTileFactory().getInfo();
- // don't repaint if we are out of the valid zoom levels
- if (info != null
- && (zoom < info.getMinimumZoomLevel()
- || zoom > info.getMaximumZoomLevel())) {
- return;
- }
-
- //if(zoom >= 0 && zoom <= 15 && zoom != this.zoom) {
- int oldzoom = this.zoom;
- Point2D oldCenter = getCenter();
- Dimension oldMapSize = getTileFactory().getMapSize(oldzoom);
- this.zoom = zoom;
- //this.firePropertyChange("zoom", oldzoom, zoom);
-
- Dimension mapSize = getTileFactory().getMapSize(zoom);
-
- setCenter(new Point2D.Double(
- oldCenter.getX() * (mapSize.getWidth() / oldMapSize.getWidth()),
- oldCenter.getY() * (mapSize.getHeight() / oldMapSize.getHeight())));
-
- //repaint();
- }
-
- /**
- * Gets the current pixel center of the map. This point is in the global
- * bitmap coordinate system, not as lat/longs.
- *
- * @return the current center of the map as a pixel value
- */
- public Point2D getCenter() {
- return center;
- }
-
- public boolean isRestrictOutsidePanning() {
- return restrictOutsidePanning;
- }
-
- public void setRestrictOutsidePanning(boolean restrictOutsidePanning) {
- this.restrictOutsidePanning = restrictOutsidePanning;
- }
-
- /**
- * Sets the new center of the map in pixel coordinates.
- *
- * @param center the new center of the map in pixel coordinates
- */
- public void setCenter(Point2D center) {
- this.center = center;
-// if(isRestrictOutsidePanning()) {
-// Insets insets = getInsets();
-// int viewportHeight = getHeight() - insets.top - insets.bottom;
-// int viewportWidth = getWidth() - insets.left - insets.right;
-//
-// // don't let the user pan over the top edge
-// Rectangle newVP = calculateViewportBounds(center);
-// if(newVP.getY() < 0) {
-// double centerY = viewportHeight/2;
-// center = new Point2D.Double(center.getX(),centerY);
-// }
-//
-// // don't let the user pan over the left edge
-// if(!isHorizontalWrapped() && newVP.getX() <0) {
-// double centerX = viewportWidth/2;
-// center = new Point2D.Double(centerX, center.getY());
-// }
-//
-// // don't let the user pan over the bottom edge
-// Dimension mapSize = getTileFactory().getMapSize(getZoom());
-// int mapHeight = (int)mapSize.getHeight()*getTileFactory().getTileSize(getZoom());
-// if(newVP.getY() + newVP.getHeight() > mapHeight) {
-// double centerY = mapHeight - viewportHeight/2;
-// center = new Point2D.Double(center.getX(),centerY);
-// }
-//
-// //don't let the user pan over the right edge
-// int mapWidth = (int)mapSize.getWidth()*getTileFactory().getTileSize(getZoom());
-// if(!isHorizontalWrapped() && (newVP.getX() + newVP.getWidth() > mapWidth)) {
-// double centerX = mapWidth - viewportWidth/2;
-// center = new Point2D.Double(centerX, center.getY());
-// }
-//
-// // if map is to small then just center it vert
-// if(mapHeight < newVP.getHeight()) {
-// double centerY = mapHeight/2;//viewportHeight/2;// - mapHeight/2;
-// center = new Point2D.Double(center.getX(),centerY);
-// }
-//
-// // if map is too small then just center it horiz
-// if(!isHorizontalWrapped() && mapWidth < newVP.getWidth()) {
-// double centerX = mapWidth/2;
-// center = new Point2D.Double(centerX, center.getY());
-// }
-// }
-//
-// //joshy: this is an evil hack to force a property change event
-// //i don't know why it doesn't work normally
-// old = new Point(5,6);
-//
-// GeoPosition oldGP = this.getCenterPosition();
- }
-
- /**
- * A property indicating the center position of the map
- *
- * @param geoPosition the new property value
- */
- public void setCenterPosition(GeoPosition geoPosition) {
- GeoPosition oldVal = getCenterPosition();
- setCenter(getTileFactory().geoToPixel(geoPosition, zoom));
- //repaint();
- GeoPosition newVal = getCenterPosition();
- //firePropertyChange("centerPosition", oldVal, newVal);
- }
-
- /**
- * A property indicating the center position of the map
- *
- * @return the current center position
- */
- public GeoPosition getCenterPosition() {
- return getTileFactory().pixelToGeo(getCenter(), zoom);
- }
-
- /**
- * Get the current factory
- *
- * @return the current property value
- */
- public TileFactory getTileFactory() {
- return factory;
- }
-
- /**
- * Set the current tile factory
- *
- * @param factory the new property value
- */
- public void setTileFactory(TileFactory factory) {
- this.factory = factory;
- this.setZoom(factory.getInfo().getDefaultZoomLevel());
- this.setCenterPosition(new GeoPosition(0, 0));
- }
-
- /**
- * Get web map scale
- * @return Web map scale
- */
- public double getWebMapScale() {
- return this.webMapScale;
- }
-
- /**
- * Set web map scale
- * @param value Web map scale
- */
- public void setWebMapScale(double value) {
- this.webMapScale = value;
- }
-
- /**
- * A property for an image which will be display when an image is still
- * loading.
- *
- * @return the current property value
- */
- public Image getLoadingImage() {
- return loadingImage;
- }
-
- /**
- * A property for an image which will be display when an image is still
- * loading.
- *
- * @param loadingImage the new property value
- */
- public void setLoadingImage(Image loadingImage) {
- this.loadingImage = loadingImage;
- }
-
- /**
- * Indicates if the tile borders should be drawn. Mainly used for debugging.
- *
- * @return the value of this property
- */
- public boolean isDrawTileBorders() {
- return drawTileBorders;
- }
-
- /**
- * Set if the tile borders should be drawn. Mainly used for debugging.
- *
- * @param drawTileBorders new value of this drawTileBorders
- */
- public void setDrawTileBorders(boolean drawTileBorders) {
- //boolean old = isDrawTileBorders();
- this.drawTileBorders = drawTileBorders;
- //firePropertyChange("drawTileBorders", old, isDrawTileBorders());
- //repaint();
- }
-
- /**
- * Set web map provider
- * @param prov The web map provider
- */
- public void setWebMapProvider(WebMapProvider prov) {
- TileFactoryInfo info = null;
- switch (prov) {
-// case SwingLabsBlueMarble:
-// setTileFactory(new CylindricalProjectionTileFactory());
-// setZoom(3);
-// return;
- case OpenStreetMap:
- info = new OpenStreetMapInfo();
- break;
- case OpenStreetMapQuestSatellite:
- info = new OpenStreetMapQuestSatelliteInfo();
- break;
- case BingMap:
- info = new BingMapInfo();
- break;
- case BingSatelliteMap:
- info = new BingSatelliteMapInfo();
- break;
- case BingHybridMap:
- info = new BingHybridMapInfo();
- break;
-// case OviMap:
-// info = new OviMapInfo();
-// break;
-// case OviSatelliteMap:
-// info = new OviSatelliteMapInfo();
-// break;
-// case OviTerrainMap:
-// info = new OviTerrainMapInfo();
-// break;
-// case OviHybridMap:
-// info = new OviHybridMapInfo();
-// break;
- case YahooMap:
- info = new YahooMapInfo();
- break;
- case YahooSatelliteMap:
- info = new YahooSatelliteMapInfo();
- break;
- case YahooHybridMap:
- info = new YahooHybridMapInfo();
- break;
- case GoogleMap:
- info = new GoogleMapInfo();
- break;
- case GoogleSatelliteMap:
- info = new GoogleSatelliteMapInfo();
- break;
- case GoogleTerrainMap:
- info = new GoogleTerrainMapInfo();
- break;
- case GoogleHybridMap:
- info = new GoogleHybridMapInfo();
- break;
- case GoogleHybridTerrainMap:
- info = new GoogleHybridTerrainMapInfo();
- break;
-// case BaiduMap:
-// info = new BaiduMapInfo();
-// break;
-// case BaiduSatelliteMap:
-// info = new BaiduSatelliteMapInfo();
-// break;
- case AMap:
- info = new AMapInfo();
- break;
- case ASatelliteMap:
- info = new ASatelliteMapInfo();
- break;
- case AHybridMap:
- info = new AHybridMapInfo();
- break;
- case TencentMap:
- info = new TencentMapInfo();
- break;
- case CMA_CVA_MAP:
- info = new CMACvaMapInfo();
- break;
- case CMA_VEC_MAP:
- info = new CMAVecMapInfo();
- break;
- case CMA_IMG_MAP:
- info = new CMAImgMapInfo();
- break;
-// case ArcGISImage:
-// info = new ArcGISImageInfo();
-// break;
- }
-
- if (info != null) {
- this.defaultProvider = prov;
- this.setLayerName("WebMap_" + info.getName());
- TileFactory tf = new DefaultTileFactory(info);
- setTileFactory(tf);
- //setZoom(11);
- setAddressLocation(new GeoPosition(51.5, 0));
- }
- }
-
- /**
- * Get web map provider
- * @return Web map provider
- */
- public WebMapProvider getWebMapProvider() {
- return this.defaultProvider;
- }
-
- public GeoPosition getAddressLocation() {
- return this.addressLocation;
- }
-
- public void setAddressLocation(GeoPosition pos, int zoom) {
- this.addressLocation = pos;
- setCenter(getTileFactory().geoToPixel(pos, zoom));
- }
-
- public void setAddressLocation(GeoPosition pos) {
- this.addressLocation = pos;
- setCenter(getTileFactory().geoToPixel(addressLocation, getZoom()));
- }
- //
- //
-
- /**
- * Repaint
- */
- public void repaint() {
- Rectangle rect = this.calculateViewportBounds(graphics, width, height);
- this.drawMapTiles(graphics, zoom, rect);
- }
-
- /**
- * Draw the map tiles
- *
- * @param g Graphics2D
- * @param zoom Zoom level to draw at
- * @param width The width
- * @param height The height
- */
- public void drawMapTiles(final Graphics2D g, final int zoom, int width, int height) {
- this.graphics = g;
- this.zoom = zoom;
- this.width = width;
- this.height = height;
- Rectangle rect = this.calculateViewportBounds(g, width, height);
- this.drawMapTiles(g, zoom, rect);
- }
-
- /**
- * Draw the map tiles. This method is for implementation use only.
- *
- * @param g Graphics
- * @param zoom zoom level to draw at
- * @param viewportBounds View bounds
- */
- public void drawMapTiles(final Graphics2D g, final int zoom, final Rectangle viewportBounds) {
- int size = getTileFactory().getTileSize(zoom);
- Dimension mapSize = getTileFactory().getMapSize(zoom);
-
- //calculate the "visible" viewport area in tiles
- int numWide = viewportBounds.width / size + 2;
- int numHigh = viewportBounds.height / size + 2;
-
- //TilePoint topLeftTile = getTileFactory().getTileCoordinate(
- // new Point2D.Double(viewportBounds.x, viewportBounds.y));
- TileFactoryInfo info = getTileFactory().getInfo();
- int tpx = (int) Math.floor(viewportBounds.getX() / info.getTileSize(0));
- int tpy = (int) Math.floor(viewportBounds.getY() / info.getTileSize(0));
- //TilePoint topLeftTile = new TilePoint(tpx, tpy);
-
- //p("top tile = " + topLeftTile);
- //fetch the tiles from the factory and store them in the tiles cache
- //attach the tileLoadListener
- for (int x = 0; x <= numWide; x++) {
- for (int y = 0; y <= numHigh; y++) {
- int itpx = x + tpx;//topLeftTile.getX();
- int itpy = y + tpy;//topLeftTile.getY();
- //TilePoint point = new TilePoint(x + topLeftTile.getX(), y + topLeftTile.getY());
- //only proceed if the specified tile point lies within the area being painted
- //if (g.getClipBounds().intersects(new Rectangle(itpx * size - viewportBounds.x,
- //itpy * size - viewportBounds.y, size, size))) {
- Tile tile = getTileFactory().getTile(itpx, itpy, zoom);
- //tile.addUniquePropertyChangeListener("loaded", tileLoadListener); //this is a filthy hack
- int ox = ((itpx * getTileFactory().getTileSize(zoom)) - viewportBounds.x);
- int oy = ((itpy * getTileFactory().getTileSize(zoom)) - viewportBounds.y);
-
- //if the tile is off the map to the north/south, then just don't paint anything
- if (isTileOnMap(itpx, itpy, mapSize)) {
-// if (isOpaque()) {
-// g.setColor(getBackground());
-// g.fillRect(ox,oy,size,size);
-// }
- } else if (tile.isLoaded()) {
- g.drawImage(tile.getImage(), ox, oy, null);
- }
-// else {
-// int imageX = (getTileFactory().getTileSize(zoom) - getLoadingImage().getWidth(null)) / 2;
-// int imageY = (getTileFactory().getTileSize(zoom) - getLoadingImage().getHeight(null)) / 2;
-// g.setColor(Color.GRAY);
-// g.fillRect(ox, oy, size, size);
-// g.drawImage(getLoadingImage(), ox + imageX, oy + imageY, null);
-// }
- if (isDrawTileBorders()) {
-
- g.setColor(Color.black);
- g.drawRect(ox, oy, size, size);
- g.drawRect(ox + size / 2 - 5, oy + size / 2 - 5, 10, 10);
- g.setColor(Color.white);
- g.drawRect(ox + 1, oy + 1, size, size);
-
- String text = itpx + ", " + itpy + ", " + getZoom();
- g.setColor(Color.BLACK);
- g.drawString(text, ox + 10, oy + 30);
- g.drawString(text, ox + 10 + 2, oy + 30 + 2);
- g.setColor(Color.WHITE);
- g.drawString(text, ox + 10 + 1, oy + 30 + 1);
- }
- //}
- }
- }
- }
-
- /**
- * Draw layer
- * @param g The Graphics2D
- * @param width Canvas width
- * @param height Canvas height
- * @param tll TileLoadListener
- */
- public void drawWebMapLayer(Graphics2D g, int width, int height, TileLoadListener tll) {
- //layer.setZoom(zoom);
- //layer.drawMapTiles(g, zoom, width, height);
- Rectangle viewportBounds = this.calculateViewportBounds(g, width, height);
- int size = this.getTileFactory().getTileSize(zoom);
- Dimension mapSize = this.getTileFactory().getMapSize(zoom);
-
- //calculate the "visible" viewport area in tiles
- int numWide = viewportBounds.width / size + 2;
- int numHigh = viewportBounds.height / size + 2;
-
- //TilePoint topLeftTile = getTileFactory().getTileCoordinate(
- // new Point2D.Double(viewportBounds.x, viewportBounds.y));
- TileFactoryInfo info = this.getTileFactory().getInfo();
- int tpx = (int) Math.floor(viewportBounds.getX() / info.getTileSize(0));
- int tpy = (int) Math.floor(viewportBounds.getY() / info.getTileSize(0));
- //TilePoint topLeftTile = new TilePoint(tpx, tpy);
-
- //p("top tile = " + topLeftTile);
- //fetch the tiles from the factory and store them in the tiles cache
- //attach the TileLoadListener
- //String language = layer.getTileFactory().getInfo().getLanguage();
- for (int x = 0; x <= numWide; x++) {
- for (int y = 0; y <= numHigh; y++) {
- int itpx = x + tpx;//topLeftTile.getX();
- int itpy = y + tpy;//topLeftTile.getY();
- //TilePoint point = new TilePoint(x + topLeftTile.getX(), y + topLeftTile.getY());
- //only proceed if the specified tile point lies within the area being painted
- //if (g.getClipBounds().intersects(new Rectangle(itpx * size - viewportBounds.x,
- //itpy * size - viewportBounds.y, size, size))) {
- Tile tile = this.getTileFactory().getTile(itpx, itpy, zoom);
- tile.addUniquePropertyChangeListener("loaded", tll); //this is a filthy hack
- int ox = ((itpx * this.getTileFactory().getTileSize(zoom)) - viewportBounds.x);
- int oy = ((itpy * this.getTileFactory().getTileSize(zoom)) - viewportBounds.y);
-
- //if the tile is off the map to the north/south, then just don't paint anything
- if (this.isTileOnMap(itpx, itpy, mapSize)) {
-// if (isOpaque()) {
-// g.setColor(getBackground());
-// g.fillRect(ox,oy,size,size);
-// }
- } else if (tile.isLoaded()) {
- g.drawImage(tile.getImage(), ox, oy, null);
- } else {
- int imageX = (this.getTileFactory().getTileSize(zoom) - this.getLoadingImage().getWidth(null)) / 2;
- int imageY = (this.getTileFactory().getTileSize(zoom) - this.getLoadingImage().getHeight(null)) / 2;
- g.setColor(Color.GRAY);
- g.fillRect(ox, oy, size, size);
- g.drawImage(this.getLoadingImage(), ox + imageX, oy + imageY, null);
- }
- if (this.isDrawTileBorders()) {
-
- g.setColor(Color.black);
- g.drawRect(ox, oy, size, size);
- g.drawRect(ox + size / 2 - 5, oy + size / 2 - 5, 10, 10);
- g.setColor(Color.white);
- g.drawRect(ox + 1, oy + 1, size, size);
-
- String text = itpx + ", " + itpy + ", " + this.getZoom();
- g.setColor(Color.BLACK);
- g.drawString(text, ox + 10, oy + 30);
- g.drawString(text, ox + 10 + 2, oy + 30 + 2);
- g.setColor(Color.WHITE);
- g.drawString(text, ox + 10 + 1, oy + 30 + 1);
- }
- //}
- }
- }
- }
-
- private double getWebMapScale(int zoom, int width, int height) {
- Point2D center = this.getCenter();
- double minx = center.getX() - width / 2;
- double miny = center.getY() - height / 2;
- double maxx = center.getX() + width / 2;
- double maxy = center.getY() + height / 2;
- GeoPosition pos1 = GeoUtil.getPosition(new Point2D.Double(minx, miny), zoom, this.getTileFactory().getInfo());
- GeoPosition pos2 = GeoUtil.getPosition(new Point2D.Double(maxx, maxy), zoom, this.getTileFactory().getInfo());
- PointD p1 = Reproject.reprojectPoint(new PointD(pos1.getLongitude(), pos1.getLatitude()),
- KnownCoordinateSystems.geographic.world.WGS1984, this.getProjInfo());
- PointD p2 = Reproject.reprojectPoint(new PointD(pos2.getLongitude(), pos2.getLatitude()),
- KnownCoordinateSystems.geographic.world.WGS1984, this.getProjInfo());
- if (pos2.getLongitude() - pos1.getLongitude() < 360.0) {
- double xlen = p2.X - p1.X;
-// if (pos2.getLongitude() - pos1.getLongitude() > 360)
-// xlen += 2.0037497210840166E7 * 2;
- return (double) width / xlen;
- } else {
- double ylen = Math.abs(p2.Y - p1.Y);
- return (double) height / ylen;
- }
- }
-
- public boolean isTileOnMap(int x, int y, Dimension mapSize) {
- return !isNegativeYAllowed && y < 0 || y >= mapSize.getHeight();
- }
-
- /**
- * Calculate view port bounds
- *
- * @param g Graphic2D
- * @param width The width
- * @param height The height
- * @return View port bounds rectangle
- */
- public Rectangle calculateViewportBounds(Graphics2D g, int width, int height) {
- //calculate the "visible" viewport area in pixels
- //double sx = g.getTransform().getTranslateX();
- //double sy = g.getTransform().getTranslateY();
- double viewportX = (center.getX() - width / 2);
- double viewportY = (center.getY() - height / 2);
- return new Rectangle((int) viewportX, (int) viewportY, width, height);
- }
-
- /**
- * To string
- * @return String
- */
- @Override
- public String getLayerInfo(){
- String str = "Layer name: " + this.getLayerName();
- str += System.getProperty("line.separator") + "Layer file: " + this.getFileName();
- str += System.getProperty("line.separator") + "Layer type: " + this.getLayerType();
- str += System.getProperty("line.separator") + "Data provider: " + this.defaultProvider;
-
- return str;
- }
- //
- //
- public class WebMapLayerBean {
- public WebMapLayerBean(){
-
- }
-
- //
- /**
- * Get layer type
- *
- * @return Layer type
- */
- public LayerTypes getLayerType() {
- return WebMapLayer.this.getLayerType();
- }
-
- /**
- * Get layer draw type
- *
- * @return Layer draw type
- */
- public LayerDrawType getLayerDrawType() {
- return WebMapLayer.this.getLayerDrawType();
- }
-
- /**
- * Get layer handle
- *
- * @return Layer handle
- */
- public int getHandle() {
- return WebMapLayer.this.getHandle();
- }
-
- /**
- * Get layer name
- *
- * @return Layer name
- */
- public String getLayerName() {
- return WebMapLayer.this.getLayerName();
- }
-
- /**
- * Set layer name
- *
- * @param name Layer name
- */
- public void setLayerName(String name) {
- WebMapLayer.this.setLayerName(name);
- }
-
- /**
- * Get web map provider
- * @return The web map provider
- */
- public String getWebMapProvider(){
- return WebMapLayer.this.defaultProvider.toString();
- }
-
- /**
- * Set web map provider
- * @param provider The web map provider
- */
- public void setWebMapProvider(String provider){
- WebMapLayer.this.setWebMapProvider(WebMapProvider.valueOf(provider));
- }
-
- /**
- * Get if is maskout
- *
- * @return If is maskout
- */
- public boolean isMaskout() {
- return WebMapLayer.this.isMaskout();
- }
-
- /**
- * Set if maskout
- *
- * @param value If maskout
- */
- public void setMaskout(boolean value) {
- WebMapLayer.this.setMaskout(value);
- }
-
- /**
- * Get if is visible
- *
- * @return If is visible
- */
- public boolean isVisible() {
- return WebMapLayer.this.isVisible();
- }
-
- /**
- * Set if is visible
- *
- * @param value If is visible
- */
- public void setVisible(boolean value) {
- WebMapLayer.this.setVisible(value);
- }
-
- /**
- * Get language
- * @return The language
- */
- public String getLanguage(){
- return WebMapLayer.this.getTileFactory().getInfo().getLanguage();
- }
-
- /**
- * Set language
- * @param value The language
- */
- public void setLanguage(String value) {
- WebMapLayer.this.getTileFactory().getInfo().setLanguage(value);
- }
-
- //
- }
-
- public static class WebMapLayerBeanBeanInfo extends BaseBeanInfo {
-
- public WebMapLayerBeanBeanInfo() {
- super(WebMapLayer.WebMapLayerBean.class);
- addProperty("layerType").setCategory("Read only").setReadOnly().setDisplayName("Layer type");
- addProperty("layerDrawType").setCategory("Read only").setReadOnly().setDisplayName("Layer draw type");
- addProperty("handle").setCategory("Read only").setReadOnly().setDisplayName("Handle");
- ExtendedPropertyDescriptor e = addProperty("webMapProvider");
- e.setCategory("Editable").setDisplayName("Web Map Provider");
- e.setPropertyEditorClass(WebMapProviderEditor.class);
- e = addProperty("language");
- e.setCategory("Editable").setDisplayName("Language");
- e.setPropertyEditorClass(LanguageEditor.class);
- addProperty("visible").setCategory("Editable").setDisplayName("Visible");
- addProperty("maskout").setCategory("Editable").setDisplayName("Is maskout");
- }
- }
-
- public static class WebMapProviderEditor extends ComboBoxPropertyEditor {
-
- public WebMapProviderEditor() {
- super();
- WebMapProvider[] providers = WebMapProvider.values();
- String[] types = new String[providers.length];
- int i = 0;
- for (WebMapProvider prov : providers) {
- types[i] = prov.toString();
- i += 1;
- }
- setAvailableValues(types);
- }
- }
-
- public static class LanguageEditor extends ComboBoxPropertyEditor {
-
- public LanguageEditor() {
- super();
- String[] langs = new String[]{"en-us", "zh-cn"};
- setAvailableValues(langs);
- }
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/WorldFilePara.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layer/WorldFilePara.java
deleted file mode 100644
index 8303ad0c..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layer/WorldFilePara.java
+++ /dev/null
@@ -1,54 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.layer;
-
-/**
- * World file parameters
- *
- * @author Yaqiang Wang
- */
-public class WorldFilePara {
- //
- ///
- /// x of up-left
- ///
- public double xUL;
- ///
- /// y of up-left
- ///
- public double yUL;
- ///
- /// x scale
- ///
- public double xScale;
- ///
- /// y scale
- ///
- public double yScale;
- ///
- /// x rotate
- ///
- public double xRotate;
- ///
- /// y rotate
- ///
- public double yRotate;
- //
- //
- //
- //
- //
- //
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layout/FrmPageSet.form b/MeteoInfoLib/src/main/java/org/meteoinfo/layout/FrmPageSet.form
deleted file mode 100644
index 642fdea3..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layout/FrmPageSet.form
+++ /dev/null
@@ -1,259 +0,0 @@
-
-
-
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layout/LayoutChart.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layout/LayoutChart.java
deleted file mode 100644
index 3eb65f45..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layout/LayoutChart.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package org.meteoinfo.layout;
-
-import java.awt.Graphics2D;
-import java.awt.geom.Rectangle2D;
-import org.meteoinfo.chart.Chart;
-import org.meteoinfo.common.PointF;
-
-/**
- *
- * @author yaqiang
- */
-public class LayoutChart extends LayoutElement {
-
- //
- private Chart chart;
- //
- //
-
- /**
- * Constructor
- */
- public LayoutChart() {
- super();
- this.setElementType(ElementType.LayoutChart);
- this.setResizeAbility(ResizeAbility.ResizeAll);
- this.setWidth(200);
- this.setHeight(150);
- }
- //
- //
-
- /**
- * Get chart
- *
- * @return The chart
- */
- public Chart getChart() {
- return chart;
- }
-
- /**
- * Set chart
- *
- * @param value The chart
- */
- public void setChart(Chart value) {
- chart = value;
- }
- //
- //
-
- @Override
- public void paint(Graphics2D g) {
- }
-
- @Override
- public void paintOnLayout(Graphics2D g, PointF pageLocation, float zoom) {
- if (chart == null)
- return;
-
- PointF aP = pageToScreen(this.getLeft(), this.getTop(), pageLocation, zoom);
- Rectangle2D area = new Rectangle2D.Double(aP.X, aP.Y, this.getWidth() * zoom, this.getHeight() * zoom);
- chart.draw(g, area);
- }
-
- @Override
- public void moveUpdate() {
- }
-
- @Override
- public void resizeUpdate() {
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layout/LayoutElement.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layout/LayoutElement.java
deleted file mode 100644
index 3a5778b2..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layout/LayoutElement.java
+++ /dev/null
@@ -1,371 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.layout;
-
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.ui.event.ILocationChangedListener;
-import org.meteoinfo.ui.event.ISizeChangedListener;
-import org.meteoinfo.ui.event.LocationChangedEvent;
-import org.meteoinfo.ui.event.SizeChangedEvent;
-
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import javax.swing.event.EventListenerList;
-
-/**
- *
- * @author yaqiang
- */
-public abstract class LayoutElement {
- //
-
- public void addLocationChangedListener(ILocationChangedListener listener) {
- this._listeners.add(ILocationChangedListener.class, listener);
- }
-
- public void removeLocationChangedListener(ILocationChangedListener listener) {
- this._listeners.remove(ILocationChangedListener.class, listener);
- }
-
- public void fireLocationChangedEvent() {
- fireLocationChangedEvent(new LocationChangedEvent(this));
- }
-
- private void fireLocationChangedEvent(LocationChangedEvent event) {
- Object[] listeners = _listeners.getListenerList();
- for (int i = 0; i < listeners.length; i = i + 2) {
- if (listeners[i] == ILocationChangedListener.class) {
- ((ILocationChangedListener) listeners[i + 1]).locationChangedEvent(event);
- }
- }
- }
-
- public void addSizeChangedListener(ISizeChangedListener listener) {
- this._listeners.add(ISizeChangedListener.class, listener);
- }
-
- public void removeSizeChangedListener(ISizeChangedListener listener) {
- this._listeners.remove(ISizeChangedListener.class, listener);
- }
-
- public void fireSizeChangedEvent() {
- fireSizeChangedEvent(new SizeChangedEvent(this));
- }
-
- private void fireSizeChangedEvent(SizeChangedEvent event) {
- Object[] listeners = _listeners.getListenerList();
- for (int i = 0; i < listeners.length; i = i + 2) {
- if (listeners[i] == ISizeChangedListener.class) {
- ((ISizeChangedListener) listeners[i + 1]).sizeChangedEvent(event);
- }
- }
- }
- //
- //
- private final EventListenerList _listeners = new EventListenerList();
- private int _left;
- private int _top;
- private int _width;
- private int _height;
- private ElementType _elementType;
- private Color _foreColor;
- private Color _backColor;
- private boolean _selected;
- private ResizeAbility _resizeAbility;
- private boolean _visible = true;
- private boolean drawBackColor = false;
- //
- //
-
- public LayoutElement() {
- _foreColor = Color.black;
- _backColor = Color.white;
- _selected = false;
- _resizeAbility = ResizeAbility.None;
- }
- //
- //
-
- /**
- * Get if visible
- *
- * @return Boolean
- */
- public boolean isVisible() {
- return _visible;
- }
-
- /**
- * Set if visible
- *
- * @param istrue Boolean
- */
- public void setVisible(boolean istrue) {
- _visible = istrue;
- }
-
- /**
- * Get left
- *
- * @return Left
- */
- public int getLeft() {
- return _left;
- }
-
- /**
- * Set left
- *
- * @param left
- */
- public void setLeft(int left) {
- _left = left;
- this.fireLocationChangedEvent();
- }
-
- /**
- * Get top
- *
- * @return Top
- */
- public int getTop() {
- return _top;
- }
-
- /**
- * Set top
- *
- * @param top Top
- */
- public void setTop(int top) {
- _top = top;
- this.fireLocationChangedEvent();
- }
-
- /**
- * Get width
- *
- * @return Width
- */
- public int getWidth() {
- return _width;
- }
-
- /**
- * Set width
- *
- * @param width Width
- */
- public void setWidth(int width) {
- _width = width;
- this.fireSizeChangedEvent();
- }
-
- /**
- * Get height
- *
- * @return Height
- */
- public int getHeight() {
- return _height;
- }
-
- /**
- * Set height
- *
- * @param height Height
- */
- public void setHeight(int height) {
- _height = height;
- this.fireSizeChangedEvent();
- }
-
- /**
- * Get right
- *
- * @return Right
- */
- public int getRight() {
- return _left + _width;
- }
-
- /**
- * Get bottom
- *
- * @return Bottom
- */
- public int getBottom() {
- return _top + _height;
- }
-
- /**
- * Get bounds rectangle
- *
- * @return Bounds rectangle
- */
- public Rectangle getBounds() {
- return new Rectangle(_left, _top, _width, _height);
- }
-
- /**
- * Get element type
- *
- * @return The element type
- */
- public ElementType getElementType() {
- return _elementType;
- }
-
- /**
- * Set element type
- *
- * @param type Element type
- */
- public void setElementType(ElementType type) {
- _elementType = type;
- }
-
- /**
- * Get foreground color
- *
- * @return Foreground color
- */
- public Color getForeColor() {
- return _foreColor;
- }
-
- /**
- * Set foreground color
- *
- * @param color Foreground color
- */
- public void setForeColor(Color color) {
- _foreColor = color;
- }
-
- /**
- * Get background color
- *
- * @return Background color
- */
- public Color getBackColor() {
- return _backColor;
- }
-
- /**
- * Set background color
- *
- * @param color Background color
- */
- public void setBackColor(Color color) {
- _backColor = color;
- }
-
- /**
- * Get if is selected
- *
- * @return Boolean
- */
- public boolean isSelected() {
- return _selected;
- }
-
- /**
- * Set if is selected
- *
- * @param istrue Boolean
- */
- public void setSelected(boolean istrue) {
- _selected = istrue;
- }
-
- /**
- * Get resize ability
- *
- * @return Resize ability
- */
- public ResizeAbility getResizeAbility() {
- return _resizeAbility;
- }
-
- /**
- * Set resize ability
- *
- * @param ra Resize ability
- */
- public void setResizeAbility(ResizeAbility ra) {
- _resizeAbility = ra;
- }
-
- /**
- * Get is draw backcolor
- * @return Boolean
- */
- public boolean isDrawBackColor(){
- return drawBackColor;
- }
-
- /**
- * Set is draw backcolor
- * @param value Boolean
- */
- public void setDrawBackColor(boolean value){
- drawBackColor = value;
- }
- //
- //
-
- /**
- * Paint method
- *
- * @param g Graphics2D
- */
- public abstract void paint(Graphics2D g);
-
- /**
- * Paint on layout method
- *
- * @param g Grahpics2D
- * @param pageLocation Page location
- * @param zoom Zoom
- */
- public abstract void paintOnLayout(Graphics2D g, PointF pageLocation, float zoom);
-
- /**
- * Move update method
- */
- public abstract void moveUpdate();
-
- /**
- * Resize update method
- */
- public abstract void resizeUpdate();
-
- /**
- * Page to screen
- *
- * @param pageX Page X
- * @param pageY Page Y
- * @param pageLocation Page location
- * @param zoom Zoom
- * @return Screen point
- */
- public PointF pageToScreen(float pageX, float pageY, PointF pageLocation, float zoom) {
- float x = pageX * zoom + pageLocation.X;
- float y = pageY * zoom + pageLocation.Y;
- return (new PointF(x, y));
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layout/LayoutScaleBar.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layout/LayoutScaleBar.java
deleted file mode 100644
index fc64637e..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layout/LayoutScaleBar.java
+++ /dev/null
@@ -1,730 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.layout;
-
-import com.l2fprod.common.beans.BaseBeanInfo;
-import com.l2fprod.common.beans.ExtendedPropertyDescriptor;
-import com.l2fprod.common.beans.editor.ComboBoxPropertyEditor;
-import org.meteoinfo.common.PointF;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.FontMetrics;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.awt.RenderingHints;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Line2D;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class LayoutScaleBar extends LayoutElement {
-//
-
- private LayoutMap _layoutMap;
- private boolean _antiAlias;
- private Font _font;
- private ScaleBarType _scaleBarType;
- private ScaleBarUnits _unit;
- private String _unitText;
- private int _numBreaks;
- private boolean _drawNeatLine;
- private Color _neatLineColor;
- private float _neatLineSize;
- private boolean _drawScaleText;
- private float _yShiftScale = 2.0f;
- //
- //
-
- /**
- * Constructor
- *
- * @param layoutMap The layout map
- */
- public LayoutScaleBar(LayoutMap layoutMap) {
- super();
- this.setElementType(ElementType.LayoutScaleBar);
- this.setResizeAbility(ResizeAbility.ResizeAll);
-
- this.setWidth(200);
- this.setHeight(50);
- _layoutMap = layoutMap;
- _antiAlias = true;
- _scaleBarType = ScaleBarType.SCALELINE_1;
- _drawNeatLine = false;
- _neatLineColor = Color.black;
- _neatLineSize = 1;
- _font = new Font("Arial", Font.PLAIN, 12);
- _unit = ScaleBarUnits.KILOMETERS;
- _unitText = "km";
- _numBreaks = 4;
- _drawScaleText = false;
- }
- //
- //
-
- /**
- * Get layout map
- *
- * @return The layout map
- */
- public LayoutMap getLayoutMap() {
- return _layoutMap;
- }
-
- /**
- * Get scale bar type
- *
- * @return Scale bar type
- */
- public ScaleBarType getScaleBarType() {
- return _scaleBarType;
- }
-
- /**
- * Set scale bar type
- *
- * @param type Scale bar type
- */
- public void setScaleBarType(ScaleBarType type) {
- _scaleBarType = type;
- }
-
- /**
- * Get if draw neat line
- *
- * @return If draw neat line
- */
- public boolean isDrawNeatLine() {
- return _drawNeatLine;
- }
-
- /**
- * Set if draw neat line
- *
- * @param istrue If draw neat line
- */
- public void setDrawNeatLine(boolean istrue) {
- _drawNeatLine = istrue;
- }
-
- /**
- * Get neat line color
- *
- * @return Neat line color
- */
- public Color getNeatLineColor() {
- return _neatLineColor;
- }
-
- /**
- * Set neat line color
- *
- * @param color Neat line color
- */
- public void setNeatLineColor(Color color) {
- _neatLineColor = color;
- }
-
- /**
- * Get neat line size
- *
- * @return Neat line size
- */
- public float getNeatLineSize() {
- return _neatLineSize;
- }
-
- /**
- * Set neat line size
- *
- * @param size Neat line size
- */
- public void setNeatLineSize(float size) {
- _neatLineSize = size;
- }
-
- /**
- * Get font
- *
- * @return The font
- */
- public Font getFont() {
- return _font;
- }
-
- /**
- * Set font
- *
- * @param font The font
- */
- public void setFont(Font font) {
- _font = font;
- }
-
- /**
- * Get break number
- *
- * @return The break number
- */
- public int getBreakNumber() {
- return _numBreaks;
- }
-
- /**
- * Set break number
- *
- * @param num Break number
- */
- public void setBreakNumber(int num) {
- _numBreaks = num;
- }
-
- /**
- * Get if draw scale text
- *
- * @return If draw scale text
- */
- public boolean isDrawScaleText() {
- return _drawScaleText;
- }
-
- /**
- * Set if draw scale text
- *
- * @param istrue If draw scale text
- */
- public void setDrawScaleText(boolean istrue) {
- _drawScaleText = istrue;
- }
- //
- //
-
- @Override
- public void paint(Graphics2D g) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- public void paintOnLayout(Graphics2D g, PointF pageLocation, float zoom) {
- if (this.isVisible()) {
- paintGraphics(g, pageLocation, zoom);
- }
- }
-
- /**
- * Paint graphics
- *
- * @param g Graphics
- * @param pageLocation Page location
- * @param zoom Zoom
- */
- public void paintGraphics(Graphics2D g, PointF pageLocation, float zoom) {
- AffineTransform oldMatrix = g.getTransform();
- PointF aP = pageToScreen(this.getLeft(), this.getTop(), pageLocation, zoom);
- g.translate(aP.X, aP.Y);
- g.scale(zoom, zoom);
- if (_antiAlias) {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- } else {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
- }
-
- //Draw background color
- if (this.isDrawBackColor()){
- g.setColor(this.getBackColor());
- g.fill(new Rectangle.Float(0, 0, this.getWidth() * zoom, this.getHeight() * zoom));
- }
-
- drawScaleBar(g, zoom);
-
- //Draw neatline
- if (_drawNeatLine) {
- Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
- (this.getWidth() - _neatLineSize) * zoom, (this.getHeight() - _neatLineSize) * zoom);
- g.setColor(_neatLineColor);
- g.setStroke(new BasicStroke(_neatLineSize));
- g.draw(mapRect);
- }
-
- g.setTransform(oldMatrix);
- }
-
- private void drawScaleBar(Graphics2D g, float zoom) {
- Font aFont = new Font(_font.getFontName(), _font.getStyle(), (int) (_font.getSize() * zoom));
- //Calculates the width of one break in greographic units
- FontMetrics metrics = g.getFontMetrics(aFont);
- float unitLegnth = metrics.stringWidth(_unitText) * 2;
- float widthNoUnit = (this.getWidth() * zoom - unitLegnth);
- long geoBreakWidth = (long) (getGeoWidth(widthNoUnit / _numBreaks));
-
- //If the geobreakWidth is less than 1 we return and don't draw anything
- if (geoBreakWidth < 1) {
- return;
- }
-
- double n = Math.pow(10, String.valueOf(geoBreakWidth).length() - 1);
- geoBreakWidth = (long) (Math.floor(geoBreakWidth / n) * n);
-
- long breakWidth = (long) (getWidth(geoBreakWidth));
- FontMetrics metrics1 = g.getFontMetrics(_font);
- float fontHeight = metrics1.getHeight() * zoom;
- float leftStart = metrics1.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
-
- //Draw scale text
- double scale = geoBreakWidth * getConversionFactor(_unit) * 100 / (breakWidth / 96 * 2.539999918) * zoom;
- if (_drawScaleText) {
- g.setFont(aFont);
- g.setColor(this.getForeColor());
- g.drawString("1 : " + String.format("{0:0,0}", scale),
- leftStart - (metrics.stringWidth(String.valueOf(Math.abs(0))) / 2), fontHeight * 2.5F);
- }
-
- //Draw scale bar
- switch (_scaleBarType) {
- case SCALELINE_1:
- drawScaleLine1(g, zoom, aFont, breakWidth, geoBreakWidth);
- break;
- case SCALELINE_2:
- drawScaleLine2(g, zoom, aFont, breakWidth, geoBreakWidth);
- break;
- case ALTERNATING_BAR:
- drawAlternatingBar(g, zoom, aFont, breakWidth, geoBreakWidth);
- break;
- }
- }
-
- private double getConversionFactor(ScaleBarUnits unit) {
- switch (unit) {
- case KILOMETERS:
- return 1000;
- default:
- return 1;
- }
- }
-
- private double getGeoWidth(double width) {
- double geoWidth = width / _layoutMap.getMapFrame().getMapView().getXScale() / getConversionFactor(_unit);
- if (_layoutMap.getMapFrame().getMapView().getProjection().isLonLatMap()) {
- geoWidth = geoWidth * getLonDistScale();
- }
-
- return geoWidth;
- }
-
- private double getWidth(double geoWidth) {
- double width = geoWidth * _layoutMap.getMapFrame().getMapView().getXScale() * getConversionFactor(_unit);
- if (_layoutMap.getMapFrame().getMapView().getProjection().isLonLatMap()) {
- width = width / getLonDistScale();
- }
-
- return width;
- }
-
- private double getLonDistScale() {
- //Get meters of one longitude degree
- double pY = (_layoutMap.getMapFrame().getMapView().getViewExtent().maxY + _layoutMap.getMapFrame().getMapView().getViewExtent().minY) / 2;
- double ProjX = 0, ProjY = pY, pProjX = 1, pProjY = pY;
- double dx = Math.abs(ProjX - pProjX);
- double dy = Math.abs(ProjY - pProjY);
- double dist;
- double y = (ProjY + pProjY) / 2;
- double factor = Math.cos(y * Math.PI / 180);
- dx *= factor;
- dist = Math.sqrt(dx * dx + dy * dy);
- dist = dist * 111319.5;
-
- return dist;
- }
-
- private void drawScaleLine1(Graphics2D g, float zoom, Font aFont, long breakWidth, long geoBreakWidth) {
- FontMetrics metrics = g.getFontMetrics(_font);
- float fontHeight = metrics.getHeight() * zoom;
- float leftStart = metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
- int yShift = 10;
-
- g.setColor(this.getForeColor());
- g.setStroke(new BasicStroke(zoom));
- g.draw(new Line2D.Float(leftStart, fontHeight * 1.6f + yShift, leftStart + (breakWidth * _numBreaks), fontHeight * 1.6f + yShift));
- FontMetrics metrics1 = g.getFontMetrics(aFont);
- g.setFont(aFont);
- for (int i = 0; i <= _numBreaks; i++) {
- g.draw(new Line2D.Float(leftStart, fontHeight * 1.1f + yShift, leftStart, fontHeight * 1.6f + yShift));
- g.drawString(String.valueOf(Math.abs(geoBreakWidth * i)),
- leftStart - (metrics1.stringWidth(String.valueOf(Math.abs(geoBreakWidth * i))) / 2), yShift * _yShiftScale);
- leftStart = leftStart + breakWidth;
- }
- g.drawString(_unitText, leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f + yShift * _yShiftScale);
- }
-
- private void drawScaleLine2(Graphics2D g, float zoom, Font aFont, long breakWidth, long geoBreakWidth) {
- FontMetrics metrics = g.getFontMetrics(_font);
- float fontHeight = metrics.getHeight() * zoom;
- float leftStart = metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
- int yShift = 5;
-
- g.setColor(this.getForeColor());
- g.draw(new Line2D.Float(leftStart, fontHeight * 1.6f + yShift, leftStart + (breakWidth * _numBreaks), fontHeight * 1.6f + yShift));
- FontMetrics metrics1 = g.getFontMetrics(aFont);
- g.setFont(aFont);
- for (int i = 0; i <= _numBreaks; i++) {
- g.draw(new Line2D.Float(leftStart, fontHeight * 1.1f + yShift, leftStart, fontHeight + (fontHeight * 1.1f) + yShift));
- g.drawString(String.valueOf(Math.abs(geoBreakWidth * i)),
- leftStart - (metrics1.stringWidth(String.valueOf(Math.abs(geoBreakWidth * i))) / 2), yShift * _yShiftScale);
- leftStart = leftStart + breakWidth;
- }
- g.drawString(_unitText, leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f + yShift * _yShiftScale);
- }
-
- private void drawAlternatingBar(Graphics2D g, float zoom, Font aFont, long breakWidth, long geoBreakWidth) {
- FontMetrics metrics = g.getFontMetrics(_font);
- float fontHeight = metrics.getHeight() * zoom;
- float leftStart = metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
- int yShift = 5;
- float rHeight = fontHeight / 2;
- FontMetrics metrics1 = g.getFontMetrics(aFont);
-
- boolean isFill = false;
- for (int i = 0; i <= _numBreaks; i++) {
- if (i < _numBreaks) {
- if (isFill) {
- g.setColor(this.getForeColor());
- g.fill(new Rectangle.Float(leftStart, fontHeight * 1.1f + yShift, breakWidth, rHeight));
- } else {
- g.setColor(this.getForeColor());
- g.draw(new Rectangle.Float(leftStart, fontHeight * 1.1f + yShift, breakWidth, rHeight));
- }
- }
-
- g.setColor(this.getForeColor());
- g.setFont(aFont);
- g.drawString(String.valueOf(Math.abs(geoBreakWidth * i)),
- leftStart - (metrics1.stringWidth(String.valueOf(Math.abs(geoBreakWidth * i))) / 2), yShift * _yShiftScale);
- leftStart = leftStart + breakWidth;
- isFill = !isFill;
- }
- g.setColor(this.getForeColor());
- g.setFont(aFont);
- g.drawString(_unitText, leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f + yShift * _yShiftScale);
- }
-
- @Override
- public void moveUpdate() {
- }
-
- @Override
- public void resizeUpdate() {
- }
- //
- //
-
- public class LayoutScaleBarBean {
-
- LayoutScaleBarBean() {
- }
- //
-
- /**
- * Get scale bar type
- *
- * @return Scale bar type
- */
- public String getScaleBarType() {
- return _scaleBarType.toString();
- }
-
- /**
- * Set scale bar type
- *
- * @param type Scale bar type
- */
- public void setScaleBarType(String type) {
- _scaleBarType = ScaleBarType.valueOf(type);
- }
-
- /**
- * Get if draw neat line
- *
- * @return If draw neat line
- */
- public boolean isDrawNeatLine() {
- return _drawNeatLine;
- }
-
- /**
- * Set if draw neat line
- *
- * @param istrue If draw neat line
- */
- public void setDrawNeatLine(boolean istrue) {
- _drawNeatLine = istrue;
- }
-
- /**
- * Get neat line color
- *
- * @return Neat line color
- */
- public Color getNeatLineColor() {
- return _neatLineColor;
- }
-
- /**
- * Set neat line color
- *
- * @param color Neat line color
- */
- public void setNeatLineColor(Color color) {
- _neatLineColor = color;
- }
-
- /**
- * Get neat line size
- *
- * @return Neat line size
- */
- public float getNeatLineSize() {
- return _neatLineSize;
- }
-
- /**
- * Set neat line size
- *
- * @param size Neat line size
- */
- public void setNeatLineSize(float size) {
- _neatLineSize = size;
- }
-
- /**
- * Get font
- *
- * @return The font
- */
- public Font getFont() {
- return _font;
- }
-
- /**
- * Set font
- *
- * @param font The font
- */
- public void setFont(Font font) {
- _font = font;
- }
-
- /**
- * Get break number
- *
- * @return The break number
- */
- public int getBreakNumber() {
- return _numBreaks;
- }
-
- /**
- * Set break number
- *
- * @param num Break number
- */
- public void setBreakNumber(int num) {
- _numBreaks = num;
- }
-
- /**
- * Get if draw scale text
- *
- * @return If draw scale text
- */
- public boolean isDrawScaleText() {
- return _drawScaleText;
- }
-
- /**
- * Set if draw scale text
- *
- * @param istrue If draw scale text
- */
- public void setDrawScaleText(boolean istrue) {
- _drawScaleText = istrue;
- }
-
- /**
- * Get is draw backcolor
- * @return Boolean
- */
- public boolean isDrawBackColor(){
- return LayoutScaleBar.this.isDrawBackColor();
- }
-
- /**
- * Set is draw backcolor
- * @param value Boolean
- */
- public void setDrawBackColor(boolean value){
- LayoutScaleBar.this.setDrawBackColor(value);
- }
-
- /**
- * Get background color
- *
- * @return Background color
- */
- public Color getBackColor() {
- return LayoutScaleBar.this.getBackColor();
- }
-
- /**
- * Set background color
- *
- * @param c Background color
- */
- public void setBackColor(Color c) {
- LayoutScaleBar.this.setBackColor(c);
- }
-
- /**
- * Get foreground color
- *
- * @return Foreground color
- */
- public Color getForeColor() {
- return LayoutScaleBar.this.getForeColor();
- }
-
- /**
- * Set foreground color
- *
- * @param c Foreground color
- */
- public void setForeColor(Color c) {
- LayoutScaleBar.this.setForeColor(c);
- }
-
- /**
- * Get left
- *
- * @return Left
- */
- public int getLeft() {
- return LayoutScaleBar.this.getLeft();
- }
-
- /**
- * Set left
- *
- * @param left Left
- */
- public void setLeft(int left) {
- LayoutScaleBar.this.setLeft(left);
- }
-
- /**
- * Get top
- *
- * @return Top
- */
- public int getTop() {
- return LayoutScaleBar.this.getTop();
- }
-
- /**
- * Set top
- *
- * @param top Top
- */
- public void setTop(int top) {
- LayoutScaleBar.this.setTop(top);
- }
-
- /**
- * Get width
- *
- * @return Width
- */
- public int getWidth() {
- return LayoutScaleBar.this.getWidth();
- }
-
- /**
- * Set width
- *
- * @param width Width
- */
- public void setWidth(int width) {
- LayoutScaleBar.this.setWidth(width);
- }
-
- /**
- * Get height
- *
- * @return Height
- */
- public int getHeight() {
- return LayoutScaleBar.this.getHeight();
- }
-
- /**
- * Set height
- *
- * @param height Height
- */
- public void setHeight(int height) {
- LayoutScaleBar.this.setHeight(height);
- }
- //
- }
-
- public static class LayoutScaleBarBeanBeanInfo extends BaseBeanInfo {
-
- public LayoutScaleBarBeanBeanInfo() {
- super(LayoutScaleBarBean.class);
- ExtendedPropertyDescriptor e = addProperty("scaleBarType");
- e.setCategory("General").setDisplayName("Scale Bar Type");
- e.setPropertyEditorClass(ScaleBarTypeEditor.class);
- addProperty("drawBackColor").setCategory("General").setDisplayName("Draw Background");
- addProperty("backColor").setCategory("General").setDisplayName("Background");
- addProperty("foreColor").setCategory("General").setDisplayName("Foreground");
- addProperty("font").setCategory("General").setDisplayName("Font");
- addProperty("drawScaleText").setCategory("General").setDisplayName("Draw Scale Text");
- addProperty("drawNeatLine").setCategory("Neat Line").setDisplayName("Draw Neat Line");
- addProperty("neatLineColor").setCategory("Neat Line").setDisplayName("Neat Line Color");
- addProperty("neatLineSize").setCategory("Neat Line").setDisplayName("Neat Line Size");
- addProperty("left").setCategory("Location").setDisplayName("Left");
- addProperty("top").setCategory("Location").setDisplayName("Top");
- addProperty("width").setCategory("Location").setDisplayName("Width");
- addProperty("height").setCategory("Location").setDisplayName("Height");
- }
- }
-
- public static class ScaleBarTypeEditor extends ComboBoxPropertyEditor {
-
- public ScaleBarTypeEditor() {
- super();
- ScaleBarType[] lutypes = ScaleBarType.values();
- String[] types = new String[lutypes.length];
- int i = 0;
- for (ScaleBarType type : lutypes) {
- types[i] = type.toString();
- i += 1;
- }
- setAvailableValues(types);
- }
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/layout/MapLayout.java b/MeteoInfoLib/src/main/java/org/meteoinfo/layout/MapLayout.java
deleted file mode 100644
index 392c2bc6..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/layout/MapLayout.java
+++ /dev/null
@@ -1,4445 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.layout;
-
-import com.itextpdf.awt.PdfGraphics2D;
-import com.itextpdf.text.DocumentException;
-import com.itextpdf.text.pdf.PdfContentByte;
-import com.itextpdf.text.pdf.PdfTemplate;
-import com.itextpdf.text.pdf.PdfWriter;
-import org.meteoinfo.common.MIMath;
-import org.meteoinfo.common.PointD;
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.common.util.GlobalUtil;
-import org.meteoinfo.drawing.Draw;
-import org.meteoinfo.geometry.legend.*;
-import org.meteoinfo.geoprocess.GeoComputation;
-import org.meteoinfo.common.colors.ColorUtil;
-import org.meteoinfo.ui.event.ActiveMapFrameChangedEvent;
-import org.meteoinfo.ui.event.ElementSelectedEvent;
-import org.meteoinfo.ui.event.IActiveMapFrameChangedListener;
-import org.meteoinfo.ui.event.IElementSelectedListener;
-import org.meteoinfo.ui.event.IMapFramesUpdatedListener;
-import org.meteoinfo.ui.event.IMapViewUpdatedListener;
-import org.meteoinfo.ui.event.IZoomChangedListener;
-import org.meteoinfo.ui.event.MapFramesUpdatedEvent;
-import org.meteoinfo.ui.event.MapViewUpdatedEvent;
-import org.meteoinfo.ui.event.ZoomChangedEvent;
-import org.meteoinfo.global.FrmMeasurement;
-import org.meteoinfo.global.FrmMeasurement.MeasureTypes;
-import org.meteoinfo.global.FrmProperty;
-import org.meteoinfo.layer.LayerTypes;
-import org.meteoinfo.layer.MapLayer;
-import org.meteoinfo.layer.VectorLayer;
-import org.meteoinfo.legend.FrmLabelSymbolSet;
-import org.meteoinfo.legend.FrmPointSymbolSet;
-import org.meteoinfo.legend.FrmPolygonSymbolSet;
-import org.meteoinfo.legend.FrmPolylineSymbolSet;
-import org.meteoinfo.legend.GridLabelPosition;
-import org.meteoinfo.legend.MapFrame;
-import org.meteoinfo.map.FrmIdentifer;
-import org.meteoinfo.geometry.shape.CircleShape;
-import org.meteoinfo.geometry.shape.CurveLineShape;
-import org.meteoinfo.geometry.shape.CurvePolygonShape;
-import org.meteoinfo.geometry.shape.EllipseShape;
-import org.meteoinfo.geometry.graphic.Graphic;
-import org.meteoinfo.geometry.shape.PointShape;
-import org.meteoinfo.geometry.shape.PolygonShape;
-import org.meteoinfo.geometry.shape.PolylineShape;
-import org.meteoinfo.geometry.shape.RectangleShape;
-import org.meteoinfo.geometry.shape.ShapeTypes;
-import org.meteoinfo.geometry.shape.WindArrow;
-
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.AdjustmentEvent;
-import java.awt.event.AdjustmentListener;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.ComponentEvent;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseMotionAdapter;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.awt.geom.AffineTransform;
-import java.awt.image.AffineTransformOp;
-import java.awt.image.BufferedImage;
-import java.awt.print.PageFormat;
-import java.awt.print.Printable;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.imageio.IIOImage;
-import javax.imageio.ImageIO;
-import javax.imageio.ImageTypeSpecifier;
-import javax.imageio.ImageWriteParam;
-import javax.imageio.ImageWriter;
-import javax.imageio.metadata.IIOMetadata;
-import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
-import javax.imageio.stream.ImageOutputStream;
-import javax.print.DocFlavor;
-import javax.print.DocPrintJob;
-import javax.print.PrintException;
-import javax.print.PrintService;
-import javax.print.SimpleDoc;
-import javax.print.StreamPrintServiceFactory;
-import javax.print.attribute.HashPrintRequestAttributeSet;
-import javax.print.attribute.PrintRequestAttributeSet;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JPopupMenu;
-import javax.swing.JScrollBar;
-import javax.swing.JSeparator;
-import javax.swing.SwingUtilities;
-import javax.swing.event.EventListenerList;
-import javax.swing.table.DefaultTableModel;
-import javax.swing.undo.UndoableEdit;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import org.freehep.graphics2d.VectorGraphics;
-import org.freehep.graphicsio.emf.EMFGraphics2D;
-import org.freehep.graphicsio.ps.PSGraphics2D;
-import org.meteoinfo.data.mapdata.webmap.IWebMapPanel;
-import org.meteoinfo.data.mapdata.webmap.TileLoadListener;
-import org.meteoinfo.ui.event.IUndoEditListener;
-import org.meteoinfo.ui.event.UndoEditEvent;
-import org.meteoinfo.image.ImageUtil;
-import org.meteoinfo.layer.RasterLayer;
-import org.meteoinfo.layer.WebMapLayer;
-import org.meteoinfo.map.FrmIdentiferGrid;
-import org.meteoinfo.map.MapView;
-import org.meteoinfo.geometry.shape.Shape;
-import org.w3c.dom.Attr;
-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;
-
-/**
- *
- * @author yaqiang
- */
-public class MapLayout extends JPanel implements IWebMapPanel {
-
- //
- private final EventListenerList _listeners = new EventListenerList();
- private final TileLoadListener tileLoadListener = new TileLoadListener(this);
- private FrmIdentifer frmIdentifier = null;
- private FrmIdentiferGrid frmIdentifierGrid = null;
- private FrmMeasurement _frmMeasure = null;
- private JScrollBar _vScrollBar;
- private JScrollBar _hScrollBar;
- private boolean _lockViewUpdate = false;
- private List _mapFrames = new ArrayList<>();
- private final List _layoutElements = new ArrayList<>();
- private LayoutMap _currentLayoutMap;
- private BufferedImage _layoutBitmap = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
- private BufferedImage _tempImage = null;
- private boolean newPaint = false;
- private boolean doubleBuffer = true;
- private boolean _antiAlias = false;
- private FrmLabelSymbolSet _frmLabelSymbolSet = null;
- private FrmPointSymbolSet _frmPointSymbolSet = null;
- private FrmPolylineSymbolSet _frmPolylineSymbolSet = null;
- private FrmPolygonSymbolSet _frmPolygonSymbolSet = null;
- private Rectangle _pageBounds;
- private Color _pageForeColor = Color.black;
- private Color _pageBackColor = Color.white;
- private PaperSize _paperSize = new PaperSize();
- private final List _paperSizeList = new ArrayList<>();
- private boolean _isLandscape;
- private float _zoom = 1.0f;
- private PointF _pageLocation = new PointF(0, 0);
- private PointBreak _defPointBreak = new PointBreak();
- private LabelBreak _defLabelBreak = new LabelBreak();
- private PolylineBreak _defPolylineBreak = new PolylineBreak();
- private PolygonBreak _defPolygonBreak = new PolygonBreak();
- private final int _xShift = 0;
- private final int _yShift = 0;
- private MouseMode _mouseMode = MouseMode.Default;
- private List _selectedElements = new ArrayList<>();
- private Rectangle _selectedRectangle = new Rectangle();
- private final Point _mouseDownPos = new Point(0, 0);
- private Point _mouseLastPos = new Point(0, 0);
- private final Point _mouseDownPoint = new Point(0, 0);
- private Edge _resizeSelectedEdge = Edge.None;
- private boolean _startNewGraphic = true;
- private List _graphicPoints = new ArrayList<>();
- private final List _editingVertices = new ArrayList<>();
- private int _editingVerticeIndex;
- private boolean _dragMode = false;
- //
-
- //
- public MapLayout() {
- super();
- this.setLayout(new BorderLayout());
- initComponents();
-
- this.addComponentListener(new ComponentAdapter() {
- @Override
- public void componentResized(ComponentEvent e) {
- onComponentResized(e);
- }
- });
- this.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- try {
- onMouseClicked(e);
- } catch (CloneNotSupportedException ex) {
- Logger.getLogger(MapLayout.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
-
- @Override
- public void mousePressed(MouseEvent e) {
- onMousePressed(e);
- }
-
- @Override
- public void mouseReleased(MouseEvent e) {
- try {
- onMouseReleased(e);
- } catch (CloneNotSupportedException ex) {
- Logger.getLogger(MapLayout.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- });
- this.addMouseMotionListener(new MouseMotionAdapter() {
- @Override
- public void mouseMoved(MouseEvent e) {
- onMouseMoved(e);
- }
-
- @Override
- public void mouseDragged(MouseEvent e) {
- onMouseDragged(e);
- }
- });
-// this.addMouseWheelListener(new MouseWheelListener() {
-// @Override
-// public void mouseWheelMoved(MouseWheelEvent e) {
-// onMouseWheelMoved(e);
-// }
-// });
- this.addKeyListener(new KeyListener() {
- @Override
- public void keyTyped(KeyEvent e) {
- }
-
- @Override
- public void keyPressed(KeyEvent e) {
- onKeyPressed(e);
- }
-
- @Override
- public void keyReleased(KeyEvent e) {
- }
- });
-
- this.setBackground(Color.lightGray);
- this.setForeground(Color.black);
- //Set page
- PaperSize aPS = new PaperSize("A4", 827, 1169);
- _paperSizeList.add(aPS);
- aPS = new PaperSize("Letter", 850, 1100);
- _paperSizeList.add(aPS);
- aPS = new PaperSize("A5", 583, 827);
- _paperSizeList.add(aPS);
- aPS = new PaperSize("Custom", 500, 750);
- _paperSizeList.add(aPS);
- _isLandscape = true;
-
- //Set default size
- _pageBounds = new Rectangle();
- _pageBounds.x = 0;
- _pageBounds.y = 0;
- _pageBounds.width = 730;
- _pageBounds.height = 480;
- _zoom = 1.0F;
- this.setPaperSize(aPS);
-
- //Add a default map frame
- MapFrame aMF = new MapFrame();
- aMF.setActive(true);
- aMF.setLayoutBounds(new Rectangle(40, 36, 606, 420));
- _mapFrames.add(aMF);
- LayoutMap layoutMap = new LayoutMap(aMF, this.tileLoadListener);
- this.addElement(layoutMap);
-
- _defPointBreak.setSize(10);
- _defLabelBreak.setText("Text");
- _defLabelBreak.setFont(new Font(GlobalUtil.getDefaultFontName(), Font.PLAIN, 12));
- _defPolylineBreak.setColor(Color.red);
- _defPolylineBreak.setWidth(2);
- _defPolygonBreak.setColor(new Color(104, 255, 104, 125));
- }
-
- private void initComponents() {
- _vScrollBar = new JScrollBar(JScrollBar.VERTICAL);
- _vScrollBar.addAdjustmentListener(new AdjustmentListener() {
- @Override
- public void adjustmentValueChanged(AdjustmentEvent e) {
- onScrollValueChanged(e);
- }
- });
- this.add(_vScrollBar, BorderLayout.EAST);
-
- _hScrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
- _hScrollBar.addAdjustmentListener(new AdjustmentListener() {
- @Override
- public void adjustmentValueChanged(AdjustmentEvent e) {
- onScrollValueChanged(e);
- }
- });
- this.add(_hScrollBar, BorderLayout.SOUTH);
-
- this._vScrollBar.setLocation(this.getWidth() - this._vScrollBar.getWidth(), 0);
- if (this._hScrollBar.isVisible()) {
- this._vScrollBar.setSize(21, this.getHeight() - 21);
- } else {
- this._vScrollBar.setSize(21, this.getHeight());
- }
-
- this._hScrollBar.setLocation(0, this.getHeight() - this._hScrollBar.getHeight());
- if (this._vScrollBar.isVisible()) {
- this._hScrollBar.setSize(this.getWidth() - 21, 21);
- } else {
- this._hScrollBar.setSize(this.getWidth(), 21);
- }
- }
- //
-
- //
- public void addMapFramesUpdatedListener(IMapFramesUpdatedListener listener) {
- this._listeners.add(IMapFramesUpdatedListener.class, listener);
- }
-
- public void removeMapFramesUpdatedListener(IMapFramesUpdatedListener listener) {
- this._listeners.remove(IMapFramesUpdatedListener.class, listener);
- }
-
- public void fireMapFramesUpdatedEvent() {
- fireMapFramesUpdatedEvent(new MapFramesUpdatedEvent(this));
- }
-
- private void fireMapFramesUpdatedEvent(MapFramesUpdatedEvent event) {
- Object[] listeners = _listeners.getListenerList();
- for (int i = 0; i < listeners.length; i = i + 2) {
- if (listeners[i] == IMapFramesUpdatedListener.class) {
- ((IMapFramesUpdatedListener) listeners[i + 1]).mapFramesUpdatedEvent(event);
- }
- }
- }
-
- public void addActiveMapFrameChangedListener(IActiveMapFrameChangedListener listener) {
- this._listeners.add(IActiveMapFrameChangedListener.class, listener);
- }
-
- public void removeActiveMapFrameChangedListener(IActiveMapFrameChangedListener listener) {
- this._listeners.remove(IActiveMapFrameChangedListener.class, listener);
- }
-
- public void fireActiveMapFrameChangedEvent() {
- fireActiveMapFrameChangedEvent(new ActiveMapFrameChangedEvent(this));
- }
-
- private void fireActiveMapFrameChangedEvent(ActiveMapFrameChangedEvent event) {
- Object[] listeners = _listeners.getListenerList();
- for (int i = 0; i < listeners.length; i = i + 2) {
- if (listeners[i] == IActiveMapFrameChangedListener.class) {
- ((IActiveMapFrameChangedListener) listeners[i + 1]).activeMapFrameChangedEvent(event);
- }
- }
- }
-
- public void addElementSelectedListener(IElementSelectedListener listener) {
- this._listeners.add(IElementSelectedListener.class, listener);
- }
-
- public void removeElementSelectedListener(IElementSelectedListener listener) {
- this._listeners.remove(IElementSelectedListener.class, listener);
- }
-
- public void fireElementSelectedEvent() {
- fireElementSelectedEvent(new ElementSelectedEvent(this));
- }
-
- private void fireElementSelectedEvent(ElementSelectedEvent event) {
- Object[] listeners = _listeners.getListenerList();
- for (int i = 0; i < listeners.length; i = i + 2) {
- if (listeners[i] == IElementSelectedListener.class) {
- ((IElementSelectedListener) listeners[i + 1]).elementSelectedEvent(event);
- }
- }
- }
-
- public void addZoomChangedListener(IZoomChangedListener listener) {
- this._listeners.add(IZoomChangedListener.class, listener);
- }
-
- public void removeZoomChangedListener(IZoomChangedListener listener) {
- this._listeners.remove(IZoomChangedListener.class, listener);
- }
-
- public void fireZoomChangedEvent() {
- fireZoomChangedEvent(new ZoomChangedEvent(this));
- }
-
- private void fireZoomChangedEvent(ZoomChangedEvent event) {
- Object[] listeners = _listeners.getListenerList();
- for (int i = 0; i < listeners.length; i = i + 2) {
- if (listeners[i] == IZoomChangedListener.class) {
- ((IZoomChangedListener) listeners[i + 1]).zoomChangedEvent(event);
- }
- }
- }
-
- public void addUndoEditListener(IUndoEditListener listener) {
- this._listeners.add(IUndoEditListener.class, listener);
- }
-
- public void removeUndoEditListener(IUndoEditListener listener) {
- this._listeners.remove(IUndoEditListener.class, listener);
- }
-
- public void fireUndoEditEvent(UndoableEdit undoEdit) {
- fireUndoEditEvent(new UndoEditEvent(this), undoEdit);
- }
-
- private void fireUndoEditEvent(UndoEditEvent event, UndoableEdit undoEdit) {
- Object[] listeners = _listeners.getListenerList();
- for (int i = 0; i < listeners.length; i = i + 2) {
- if (listeners[i] == IUndoEditListener.class) {
- ((IUndoEditListener) listeners[i + 1]).undoEditEvent(event, undoEdit);
- }
- }
- }
-
- public void onScrollValueChanged(AdjustmentEvent e) {
- if (e.getSource() == _vScrollBar) {
- //_vScrollBar.setValue(e.getValue());
- //this._yShift = - this._vScrollBar.getValue();
- int y = -e.getValue();
- if (y == 1) {
- y = 0;
- }
- this._pageLocation.Y = y;
- }
- if (e.getSource() == _hScrollBar) {
- //_hScrollBar.setValue(e.getValue());
- //this._xShift = - this._hScrollBar.getValue();
- int x = -e.getValue();
- if (x == 1) {
- x = 0;
- }
- this._pageLocation.X = x;
- }
- //this.paintGraphics();
- this.repaintNew();
- //this.repaint();
- }
-
- void onComponentResized(ComponentEvent e) {
- if (this.getWidth() > 0 && this.getHeight() > 0) {
- this._vScrollBar.setLocation(this.getWidth() - this._vScrollBar.getWidth(), 0);
- if (this._hScrollBar.isVisible()) {
- this._vScrollBar.setSize(this._vScrollBar.getWidth(), this.getHeight() - this._vScrollBar.getWidth());
- } else {
- this._vScrollBar.setSize(this._vScrollBar.getWidth(), this.getHeight());
- }
-
- this._hScrollBar.setLocation(0, this.getHeight() - this._hScrollBar.getHeight());
- if (this._vScrollBar.isVisible()) {
- this._hScrollBar.setSize(this.getWidth() - this._hScrollBar.getHeight(), this._hScrollBar.getHeight());
- } else {
- this._hScrollBar.setSize(this.getWidth(), this._hScrollBar.getHeight());
- }
-
- //this.paintGraphics();
- this.repaintNew();
- }
- }
-
- void onMousePressed(MouseEvent e) {
- if (e.getButton() == MouseEvent.BUTTON1) {
- //int left = e.getX();
- //int top = e.getY();
- Point pageP = screenToPage(e.getX(), e.getY());
- Graphics2D g = (Graphics2D) this.getGraphics();
- LayoutMap aLM = getLayoutMap(pageP);
- if (aLM != null) {
- _currentLayoutMap = aLM;
- }
-
- switch (_mouseMode) {
- case Map_Pan:
- Rectangle mapRect = pageToScreen(_currentLayoutMap.getBounds());
- _tempImage = new BufferedImage(mapRect.width - 2,
- mapRect.height - 2, BufferedImage.TYPE_INT_ARGB);
- Graphics2D tg = _tempImage.createGraphics();
- tg.setColor(_currentLayoutMap.getMapFrame().getMapView().getBackground());
- tg.fill(mapRect);
- tg.drawImage(_layoutBitmap, -mapRect.x - 1, -mapRect.y - 1, this);
- tg.dispose();
- break;
- case Select:
- List tempGraphics = selectElements(pageP, _selectedElements, 3);
- if (tempGraphics.size() > 0) {
- _selectedRectangle = (Rectangle) _selectedElements.get(0).getBounds().clone();
- _selectedRectangle = pageToScreen(_selectedRectangle);
- if (_resizeSelectedEdge == Edge.None) {
- _mouseMode = MouseMode.MoveSelection;
- } else {
- _mouseMode = MouseMode.ResizeSelected;
- }
- } else {
- _mouseMode = MouseMode.CreateSelection;
- }
-
- break;
- case New_Point:
- PointShape aPS = new PointShape();
- aPS.setPoint(new PointD(pageP.x, pageP.y));
- Graphic aGraphic = new Graphic(aPS, (PointBreak) _defPointBreak.clone());
- LayoutGraphic aLayoutGraphic = new LayoutGraphic(aGraphic, this);
- addElement(aLayoutGraphic);
- //this.paintGraphics();
- this.repaintNew();
- UndoableEdit edit = (new MapLayoutUndoRedo()).new AddElementEdit(this, aLayoutGraphic);
- this.fireUndoEditEvent(edit);
- break;
- case New_Label:
- aPS = new PointShape();
- aPS.setPoint(new PointD(pageP.x, pageP.y));
- aGraphic = new Graphic(aPS, (LabelBreak) _defLabelBreak.clone());
- aLayoutGraphic = new LayoutGraphic(aGraphic, this);
- addElement(aLayoutGraphic);
- //this.paintGraphics();
- this.repaintNew();
- edit = (new MapLayoutUndoRedo()).new AddElementEdit(this, aLayoutGraphic);
- this.fireUndoEditEvent(edit);
- break;
- case New_Polyline:
- case New_Polygon:
- case New_Curve:
- case New_CurvePolygon:
- case New_Freehand:
- case Map_SelectFeatures_Polygon:
- case Map_SelectFeatures_Lasso:
- if (_startNewGraphic) {
- _graphicPoints = new ArrayList<>();
- _startNewGraphic = false;
- }
- _graphicPoints.add(new PointF(e.getX(), e.getY()));
- break;
- case EditVertices:
- if (_selectedElements.size() > 0) {
- _editingVerticeIndex = selectEditVertices(pageP, ((LayoutGraphic) _selectedElements.get(0)).getGraphic().getShape(),
- _editingVertices);
- if (_editingVerticeIndex >= 0) {
- _mouseMode = MouseMode.InEditingVertices;
- }
- }
- break;
- case Map_Measurement:
- if (_frmMeasure == null) {
- break;
- }
- if (_frmMeasure.isVisible()) {
- switch (_frmMeasure.getMeasureType()) {
- case Length:
- case Area:
- if (_startNewGraphic) {
- _graphicPoints = new ArrayList<>();
- _startNewGraphic = false;
- }
- _frmMeasure.setPreviousValue(_frmMeasure.getTotalValue());
- _graphicPoints.add(new PointF(e.getX(), e.getY()));
- break;
- case Feature:
- MapLayer aMLayer = _currentLayoutMap.getMapFrame().getMapView().getSelectedLayer();
- if (aMLayer != null) {
- if (aMLayer.getLayerType() == LayerTypes.VectorLayer) {
- VectorLayer aLayer = (VectorLayer) aMLayer;
- if (aLayer.getShapeType() != ShapeTypes.Point) {
- PointF mapP = pageToScreen(_currentLayoutMap.getLeft(), _currentLayoutMap.getTop());
- PointF aPoint = new PointF(e.getX() - mapP.X, e.getY() - mapP.Y);
- List selectedShapes = _currentLayoutMap.getMapFrame().getMapView().selectShapes(aLayer, aPoint);
- if (selectedShapes.size() > 0) {
- int shapeIdx = selectedShapes.get(0);
- org.meteoinfo.geometry.shape.Shape aShape = aLayer.getShapes().get(shapeIdx);
- aLayer.setIdentiferShape(shapeIdx);
- _currentLayoutMap.getMapFrame().getMapView().setDrawIdentiferShape(true);
- //this.repaint();
- this.repaintOld();
- //_currentLayoutMap.getMapFrame().getMapView().drawIdShape((Graphics2D) this.getGraphics(), aLayer.getShapes().get(shapeIdx), rect);
- double value = 0.0;
- switch (aShape.getShapeType()) {
- case Polyline:
- case PolylineZ:
- _frmMeasure.setArea(false);
- if (_currentLayoutMap.getMapFrame().getMapView().getProjection().isLonLatMap()) {
- value = GeoComputation.getDistance(((PolylineShape) aShape).getPoints(), true);
- } else {
- value = ((PolylineShape) aShape).getLength();
- value *= _currentLayoutMap.getMapFrame().getMapView().getProjection().getProjInfo().getCoordinateReferenceSystem().getProjection().getFromMetres();
- }
- break;
- case Polygon:
- case PolygonM:
- case PolygonZ:
- _frmMeasure.setArea(true);
- if (_currentLayoutMap.getMapFrame().getMapView().getProjection().isLonLatMap()) {
- value = ((PolygonShape) aShape).getSphericalArea();
- } else {
- value = ((PolygonShape) aShape).getArea();
- }
- value *= _currentLayoutMap.getMapFrame().getMapView().getProjection().getProjInfo().getCoordinateReferenceSystem().getProjection().getFromMetres()
- * _currentLayoutMap.getMapFrame().getMapView().getProjection().getProjInfo().getCoordinateReferenceSystem().getProjection().getFromMetres();
- break;
- }
- _frmMeasure.setCurrentValue(value);
- }
- }
- }
- }
- break;
- }
- }
- break;
- }
- } else if (e.getButton() == MouseEvent.BUTTON3) {
- switch (_mouseMode) {
- case Map_Measurement:
- if (_frmMeasure.isVisible()) {
- switch (_frmMeasure.getMeasureType()) {
- case Length:
- case Area:
- _startNewGraphic = true;
- _frmMeasure.setTotalValue(0);
- break;
- }
- }
- break;
- }
- }
-
- _mouseDownPoint.x = e.getX();
- _mouseDownPoint.y = e.getY();
- _mouseLastPos = new Point(_mouseDownPoint.x, _mouseDownPoint.y);
- }
-
- void onMouseDragged(MouseEvent e) {
- _dragMode = true;
- int deltaX = e.getX() - _mouseLastPos.x;
- int deltaY = e.getY() - _mouseLastPos.y;
- _mouseLastPos.x = e.getX();
- _mouseLastPos.y = e.getY();
-
- Point pageP = screenToPage(e.getX(), e.getY());
-
- Graphics2D g = (Graphics2D) this.getGraphics();
- //Pen aPen = new Pen(Color.Red);
- //aPen.DashStyle = DashStyle.Dash;
- //Rectangle rect = new Rectangle();
- _vScrollBar.setCursor(Cursor.getDefaultCursor());
- _hScrollBar.setCursor(Cursor.getDefaultCursor());
- //this.setCursor(Cursor.getDefaultCursor());
-
- switch (_mouseMode) {
- case Map_ZoomIn:
- if (isInLayoutMaps(pageP)) {
- this.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(Toolkit.getDefaultToolkit().
- getImage(this.getClass().getResource("/images/zoom_in_32x32x32.png")), new Point(8, 8), "Zoom In"));
-
- //this.repaint();
- this.repaintOld();
- }
- break;
- case Map_Pan:
- if (isInLayoutMaps(pageP)) {
- this.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(Toolkit.getDefaultToolkit().
- getImage(this.getClass().getResource("/images/Pan_Open_32x32x32.png")), new Point(8, 8), "Pan"));
-
- Rectangle mapRect = pageToScreen(_currentLayoutMap.getBounds());
- g.setClip(mapRect);
- Color aColor = _currentLayoutMap.getMapFrame().getBackColor();
- if (aColor.getAlpha() == 255) {
- aColor = Color.white;
- }
- g.setColor(aColor);
- int aX = e.getX() - _mouseDownPoint.x;
- int aY = e.getY() - _mouseDownPoint.y;
- aX = (int) (aX / _zoom);
- aY = (int) (aY / _zoom);
- if (aX > 0) {
- if (mapRect.x >= 0) {
- g.fillRect(mapRect.x, mapRect.y, aX, mapRect.height);
- } else {
- g.fillRect(0, mapRect.y, aX, mapRect.height);
- }
- } else {
- if (mapRect.x <= this.getWidth()) {
- g.fillRect(mapRect.x + mapRect.width + aX, mapRect.y, Math.abs(aX), mapRect.height);
- } else {
- g.fillRect(this.getWidth() + aX, mapRect.y, Math.abs(aX), mapRect.height);
- }
- }
- if (aY > 0) {
- if (mapRect.y >= 0) {
- g.fillRect(mapRect.x, mapRect.y, mapRect.width, aY);
- } else {
- g.fillRect(mapRect.x, 0, mapRect.width, aY);
- }
- } else {
- if (mapRect.y + mapRect.height <= this.getX() + this.getHeight()) {
- g.fillRect(mapRect.x, mapRect.y + mapRect.height + aY, mapRect.width, Math.abs(aY));
- } else {
- g.fillRect(mapRect.x, this.getY() + this.getHeight() + aY, mapRect.width, Math.abs(aY));
- }
- }
- int startX = mapRect.x + aX;
- int startY = mapRect.y + aY;
- AffineTransformOp aop = new AffineTransformOp(new AffineTransform(), AffineTransformOp.TYPE_BILINEAR);
- g.drawImage(_tempImage, aop, startX, startY);
- //g.drawImage(_tempImage, startX, startY, this);
- g.setColor(this.getForeground());
- g.draw(mapRect);
- }
- break;
- case Map_SelectFeatures_Rectangle:
- //this.repaint();
- this.repaintOld();
- break;
- case MoveSelection:
- this.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
- //this.repaint();
- this.repaintOld();
- break;
- case ResizeSelected:
- LayoutElement oElement = _selectedElements.get(0);
- switch (oElement.getResizeAbility()) {
- case SameWidthHeight:
- switch (_resizeSelectedEdge) {
- case TopLeft:
- _selectedRectangle.x += deltaX;
- _selectedRectangle.y += deltaX;
- _selectedRectangle.width -= deltaX;
- _selectedRectangle.height -= deltaX;
- break;
- case BottomRight:
- _selectedRectangle.width += deltaX;
- _selectedRectangle.height += deltaX;
- break;
- case TopRight:
- _selectedRectangle.y += deltaY;
- _selectedRectangle.width -= deltaY;
- _selectedRectangle.height -= deltaY;
- break;
- case BottomLeft:
- _selectedRectangle.x += deltaX;
- _selectedRectangle.width -= deltaX;
- _selectedRectangle.height -= deltaX;
- break;
- }
- break;
- case ResizeAll:
- switch (_resizeSelectedEdge) {
- case TopLeft:
- _selectedRectangle.x += deltaX;
- _selectedRectangle.y += deltaY;
- _selectedRectangle.width -= deltaX;
- _selectedRectangle.height -= deltaY;
- break;
- case BottomRight:
- _selectedRectangle.width += deltaX;
- _selectedRectangle.height += deltaY;
- break;
- case Top:
- _selectedRectangle.y += deltaY;
- _selectedRectangle.height -= deltaY;
- break;
- case Bottom:
- _selectedRectangle.height += deltaY;
- break;
- case TopRight:
- _selectedRectangle.y += deltaY;
- _selectedRectangle.width += deltaX;
- _selectedRectangle.height -= deltaY;
- break;
- case BottomLeft:
- _selectedRectangle.x += deltaX;
- _selectedRectangle.width -= deltaX;
- _selectedRectangle.height += deltaY;
- break;
- case Left:
- _selectedRectangle.x += deltaX;
- _selectedRectangle.width -= deltaX;
- break;
- case Right:
- _selectedRectangle.width += deltaX;
- break;
- }
- break;
- }
- //this.repaint();
- this.repaintOld();
- break;
- case New_Rectangle:
- case New_Ellipse:
- case New_Freehand:
- case New_Circle:
- case Map_SelectFeatures_Polygon:
- case Map_SelectFeatures_Lasso:
- case Map_SelectFeatures_Circle:
- //this.repaint();
- this.repaintOld();
- break;
- case InEditingVertices:
- //this.repaint();
- this.repaintOld();
- break;
- }
- }
-
- void onMouseMoved(MouseEvent e) {
- //int deltaX = e.getX() - _mouseLastPos.x;
- //int deltaY = e.getY() - _mouseLastPos.y;
- _mouseLastPos.x = e.getX();
- _mouseLastPos.y = e.getY();
-
- Point pageP = screenToPage(e.getX(), e.getY());
-
- Graphics2D g = (Graphics2D) this.getGraphics();
- //Pen aPen = new Pen(Color.Red);
- //aPen.DashStyle = DashStyle.Dash;
- //Rectangle rect = new Rectangle();
- _vScrollBar.setCursor(Cursor.getDefaultCursor());
- _hScrollBar.setCursor(Cursor.getDefaultCursor());
- //this.setCursor(Cursor.getDefaultCursor());
-
- switch (_mouseMode) {
- case Map_ZoomIn:
- if (isInLayoutMaps(pageP)) {
- this.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(Toolkit.getDefaultToolkit().
- getImage(this.getClass().getResource("/images/zoom_in_32x32x32.png")), new Point(8, 8), "Zoom In"));
- }
- break;
- case Map_ZoomOut:
- if (isInLayoutMaps(pageP)) {
- this.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(Toolkit.getDefaultToolkit().
- getImage(this.getClass().getResource("/images/zoom_out_32x32x32.png")), new Point(8, 8), "Zoom Out"));
- }
- break;
- case Map_Pan:
- if (isInLayoutMaps(pageP)) {
- this.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(Toolkit.getDefaultToolkit().
- getImage(this.getClass().getResource("/images/Pan_Open_32x32x32.png")), new Point(8, 8), "Pan"));
- }
- break;
- case Map_Identifer:
- if (isInLayoutMaps(pageP)) {
- this.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(Toolkit.getDefaultToolkit().
- getImage(this.getClass().getResource("/images/identifer_32x32x32.png")), new Point(8, 8), "Identifer"));
- }
- break;
- case Map_SelectFeatures_Rectangle:
- //case Map_SelectFeatures_Polygon:
- //case Map_SelectFeatures_Lasso:
- //case Map_SelectFeatures_Circle:
- if (isInLayoutMaps(pageP)) {
- this.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
- }
- break;
- case Select:
- if (_selectedElements.size() > 0) {
- List tempElements = selectElements(pageP, _selectedElements, 3);
- if (tempElements.size() > 0) {
- //Change mouse cursor
- Rectangle aRect = (Rectangle) _selectedElements.get(0).getBounds().clone();
- _resizeSelectedEdge = intersectElementEdge(aRect, new PointF(pageP.x, pageP.y), 3F);
- switch (_selectedElements.get(0).getResizeAbility()) {
- case SameWidthHeight:
- switch (_resizeSelectedEdge) {
- case TopLeft:
- case BottomRight:
- this.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
- break;
- case TopRight:
- case BottomLeft:
- this.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
- break;
- default:
- this.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
- break;
- }
- break;
- case ResizeAll:
- switch (_resizeSelectedEdge) {
- case TopLeft:
- case BottomRight:
- this.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
- break;
- case Top:
- case Bottom:
- this.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
- break;
- case TopRight:
- case BottomLeft:
- this.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
- break;
- case Left:
- case Right:
- this.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
- break;
- case None:
- this.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
- break;
- }
- break;
- default:
- this.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
- break;
- }
- } else {
- this.setCursor(Cursor.getDefaultCursor());
- }
- } else {
- this.setCursor(Cursor.getDefaultCursor());
- }
-
- break;
- case MoveSelection:
- break;
- case ResizeSelected:
- break;
- case New_Polyline:
- case New_Polygon:
- case New_Curve:
- case New_CurvePolygon:
- case Map_SelectFeatures_Polygon:
- if (!_startNewGraphic) {
- //this.repaint();
- this.repaintOld();
- }
- break;
- case EditVertices:
- if (_selectedElements.size() > 0) {
- _editingVerticeIndex = selectEditVertices(pageP, ((LayoutGraphic) _selectedElements.get(0)).getGraphic().getShape(),
- _editingVertices);
- Toolkit toolkit = Toolkit.getDefaultToolkit();
- if (_editingVerticeIndex >= 0) {
- this.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(Toolkit.getDefaultToolkit().
- getImage(this.getClass().getResource("/images/VertexEdit_32x32x32.png")), new Point(8, 8), "Vertices edit"));
- } else {
- Image image = toolkit.getImage(this.getClass().getResource("/images/Edit_tool.png"));
- this.setCursor(toolkit.createCustomCursor(image, new Point(2, 2), "Edit Tool"));
- }
- }
- break;
- case Map_Measurement:
- if (isInLayoutMaps(pageP)) {
- this.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
- }
-
- if (_frmMeasure == null) {
- break;
- }
- if (_frmMeasure.isVisible()) {
- switch (_frmMeasure.getMeasureType()) {
- case Length:
- case Area:
- if (!_startNewGraphic) {
- //Draw graphic
- //g.SmoothingMode = SmoothingMode.AntiAlias;
- //this.repaint();
- this.repaintOld();
- PointF[] fpoints = (PointF[]) _graphicPoints.toArray(new PointF[_graphicPoints.size()]);
- PointF[] points = new PointF[fpoints.length + 1];
- System.arraycopy(fpoints, 0, points, 0, fpoints.length);
- points[_graphicPoints.size()] = new PointF(e.getX(), e.getY());
-
- //Calculate
- PointF mapP = pageToScreen(_currentLayoutMap.getLeft(), _currentLayoutMap.getTop());
- PointF aPoint = new PointF(e.getX() - mapP.X, e.getY() - mapP.Y);
- float[] pXY = _currentLayoutMap.getMapFrame().getMapView().screenToProj(aPoint.X, aPoint.Y);
- if (_frmMeasure.getMeasureType() == MeasureTypes.Length) {
- aPoint = new PointF(_mouseDownPoint.x - mapP.X, _mouseDownPoint.y - mapP.Y);
- float[] pPXY = _currentLayoutMap.getMapFrame().getMapView().screenToProj(aPoint.X, aPoint.Y);
- double dx = Math.abs(pXY[0] - pPXY[0]);
- double dy = Math.abs(pXY[1] - pPXY[1]);
- double dist;
- if (_currentLayoutMap.getMapFrame().getMapView().getProjection().isLonLatMap()) {
- double y = (pXY[1] + pPXY[1]) / 2;
- double factor = Math.cos(y * Math.PI / 180);
- dx *= factor;
- dist = Math.sqrt(dx * dx + dy * dy);
- dist = dist * 111319.5;
- } else {
- dist = Math.sqrt(dx * dx + dy * dy);
- dist *= _currentLayoutMap.getMapFrame().getMapView().getProjection().getProjInfo().getCoordinateReferenceSystem().getProjection().getFromMetres();
- }
-
- _frmMeasure.setCurrentValue(dist);
- } else {
- List mPoints = new ArrayList<>();
- for (int i = 0; i < points.length; i++) {
- aPoint = new PointF(points[i].X - mapP.X, points[i].Y - mapP.Y);
- pXY = _currentLayoutMap.getMapFrame().getMapView().screenToProj(aPoint.X, aPoint.Y);
- mPoints.add(new PointD(pXY[0], pXY[1]));
- }
- double area = GeoComputation.getArea(mPoints);
- if (_currentLayoutMap.getMapFrame().getMapView().getProjection().isLonLatMap()) {
- area = area * 111319.5 * 111319.5;
- } else {
- area *= _currentLayoutMap.getMapFrame().getMapView().getProjection().getProjInfo().getCoordinateReferenceSystem().getProjection().getFromMetres()
- * _currentLayoutMap.getMapFrame().getMapView().getProjection().getProjInfo().getCoordinateReferenceSystem().getProjection().getFromMetres();
- }
- _frmMeasure.setCurrentValue(area);
- }
- }
- break;
- }
- }
- break;
- }
- }
-
- void onMouseReleased(MouseEvent e) throws CloneNotSupportedException {
- _dragMode = false;
- double MinX, MaxX, MinY, MaxY, ZoomF;
- Point pageP = screenToPage(e.getX(), e.getY());
- switch (_mouseMode) {
- case Map_ZoomIn:
- MinX = Math.min(e.getX(), _mouseDownPoint.x);
- MinY = Math.min(e.getY(), _mouseDownPoint.y);
- MaxX = Math.max(e.getX(), _mouseDownPoint.x);
- MaxY = Math.max(e.getY(), _mouseDownPoint.y);
- if (MaxX - MinX < 5) {
- if (e.getButton() == MouseEvent.BUTTON1) {
- ZoomF = 0.75;
- } else {
- ZoomF = 1.5;
- }
- MinX = pageP.x - (_currentLayoutMap.getWidth() / 2 * ZoomF);
- MaxX = pageP.x + (_currentLayoutMap.getWidth() / 2 * ZoomF);
- MinY = pageP.y - (_currentLayoutMap.getHeight() / 2 * ZoomF);
- MaxY = pageP.y + (_currentLayoutMap.getHeight() / 2 * ZoomF);
- } else {
- PointF minP = screenToPage((float) MinX, (float) MinY);
- PointF maxP = screenToPage((float) MaxX, (float) MaxY);
- MinX = minP.X;
- MinY = minP.Y;
- MaxX = maxP.X;
- MaxY = maxP.Y;
- }
-
- MinX -= _currentLayoutMap.getLeft();
- MinY -= _currentLayoutMap.getTop();
- MaxX -= _currentLayoutMap.getLeft();
- MaxY -= _currentLayoutMap.getTop();
- if (MaxX - MinX > 0.001) {
- _currentLayoutMap.getMapFrame().getMapView().zoomToExtentScreen(MinX, MaxX, MinY, MaxY, _zoom);
- }
- break;
- case Map_ZoomOut:
- if (e.getButton() == MouseEvent.BUTTON1) {
- ZoomF = 1.5;
- } else {
- ZoomF = 0.75;
- }
- MinX = pageP.x - (_currentLayoutMap.getWidth() / 2 * ZoomF);
- MaxX = pageP.x + (_currentLayoutMap.getWidth() / 2 * ZoomF);
- MinY = pageP.y - (_currentLayoutMap.getHeight() / 2 * ZoomF);
- MaxY = pageP.y + (_currentLayoutMap.getHeight() / 2 * ZoomF);
-
- MinX -= _currentLayoutMap.getLeft();
- MinY -= _currentLayoutMap.getTop();
- MaxX -= _currentLayoutMap.getLeft();
- MaxY -= _currentLayoutMap.getTop();
- if (MaxX - MinX > 0.001) {
- _currentLayoutMap.getMapFrame().getMapView().zoomToExtentScreen(MinX, MaxX, MinY, MaxY, _zoom);
- }
- break;
- case Map_Pan:
- if (e.getButton() == MouseEvent.BUTTON1) {
- int deltaX = e.getX() - _mouseDownPoint.x;
- int deltaY = e.getY() - _mouseDownPoint.y;
- deltaX = (int) (deltaX / _zoom);
- deltaY = (int) (deltaY / _zoom);
- MinX = -deltaX;
- MinY = -deltaY;
- MaxX = _currentLayoutMap.getWidth() - deltaX;
- MaxY = _currentLayoutMap.getHeight() - deltaY;
- _currentLayoutMap.getMapFrame().getMapView().zoomToExtentScreen(MinX, MaxX, MinY, MaxY, _zoom);
- }
- break;
- }
-
- if (e.getButton() == MouseEvent.BUTTON1) {
- switch (_mouseMode) {
- case Map_SelectFeatures_Rectangle:
- if (_currentLayoutMap.getMapFrame().getMapView().getSelectedLayerHandle() < 0) {
- return;
- }
- MapLayer aMLayer = _currentLayoutMap.getMapFrame().getMapView().getSelectedLayer();
- if (aMLayer == null) {
- return;
- }
- if (aMLayer.getLayerType() != LayerTypes.VectorLayer) {
- return;
- }
-
- VectorLayer aLayer = (VectorLayer) aMLayer;
- PointF mapP = pageToScreen(_currentLayoutMap.getLeft(), _currentLayoutMap.getTop());
- Point aPoint = new Point(e.getX() - (int) mapP.X, e.getY() - (int) mapP.Y);
- Point bPoint = new Point(_mouseDownPoint.x - (int) mapP.X, _mouseDownPoint.y - (int) mapP.Y);
- int minx = Math.min(bPoint.x, aPoint.x);
- int miny = Math.min(bPoint.y, aPoint.y);
- int width = Math.abs(aPoint.x - bPoint.x);
- int height = Math.abs(aPoint.y - bPoint.y);
- Rectangle.Float rect = new Rectangle.Float(minx, miny, width, height);
- List selectedShapes = _currentLayoutMap.getMapFrame().getMapView().selectShapes(aLayer, rect);
- if (!(e.isControlDown() || e.isShiftDown())) {
- aLayer.clearSelectedShapes();
- }
- if (selectedShapes.size() > 0) {
- for (int shapeIdx : selectedShapes) {
- Shape shape = aLayer.getShapes().get(shapeIdx);
- shape.setSelected(!shape.isSelected());
- }
- _currentLayoutMap.getMapFrame().getMapView().fireShapeSelectedEvent();
- }
- //this.paintGraphics();
- this.repaintNew();
- break;
- case CreateSelection:
- //Remove selected graphics
- for (LayoutElement aElement : _selectedElements) {
- aElement.setSelected(false);
- }
- _selectedElements.clear();
-
- //Select elements
- if (Math.abs(e.getX() - _mouseDownPoint.x) > 2 || Math.abs(e.getY() - _mouseDownPoint.y) > 2) {
- //this.paintGraphics();
- this.repaintNew();
- return;
- }
-
- //Point mousePoint = new Point(_mouseDownPoint.X, _mouseDownPoint.Y);
- _selectedElements = selectElements(pageP, _layoutElements, 0);
- if (_selectedElements.size() > 0) {
- for (int i = 0; i < _selectedElements.size() - 1; i++) {
- _selectedElements.remove(_selectedElements.size() - 1);
- }
- _selectedElements.get(0).setSelected(true);
- if (_selectedElements.get(0).getElementType() == ElementType.LayoutMap) {
- setActiveMapFrame(((LayoutMap) _selectedElements.get(0)).getMapFrame());
- }
- }
- this.fireElementSelectedEvent();
-
- _mouseMode = MouseMode.Select;
- //this.paintGraphics();
- this.repaintNew();
- break;
- case MoveSelection:
- //Select elements
- if (Math.abs(e.getX() - _mouseDownPoint.x) < 2 && Math.abs(e.getY() - _mouseDownPoint.y) < 2) {
- LayoutElement aElement = _selectedElements.get(0);
- _selectedElements = selectElements(pageP, _layoutElements, 0);
- if (_selectedElements.size() > 1) {
- aElement.setSelected(false);
- int idx = _selectedElements.indexOf(aElement);
- if (idx == 0) {
- idx = _selectedElements.size() - 1;
- } else {
- idx -= 1;
- }
- if (idx < 0) {
- idx = 0;
- }
- aElement = _selectedElements.get(idx);
- _selectedElements.clear();
- _selectedElements.add(aElement);
- _selectedElements.get(0).setSelected(true);
- if (_selectedElements.get(0).getElementType() == ElementType.LayoutMap) {
- setActiveMapFrame(((LayoutMap) _selectedElements.get(0)).getMapFrame());
- }
- }
- this.fireElementSelectedEvent();
- } else {
- int deltaX = (int) ((e.getX() - _mouseDownPoint.x) / _zoom);
- int deltaY = (int) ((e.getY() - _mouseDownPoint.y) / _zoom);
- for (LayoutElement aElement : _selectedElements) {
- aElement.setLeft(aElement.getLeft() + deltaX);
- aElement.setTop(aElement.getTop() + deltaY);
- aElement.moveUpdate();
- }
- UndoableEdit edit = (new MapLayoutUndoRedo()).new MoveElementsEdit(this, _selectedElements, deltaX, deltaY);
- this.fireUndoEditEvent(edit);
- }
-
- _mouseMode = MouseMode.Select;
- //this.paintGraphics();
- this.repaintNew();
- break;
- case ResizeSelected:
- _mouseMode = MouseMode.Select;
- LayoutElement oElement = _selectedElements.get(0);
- if (_selectedRectangle.width < 3) {
- _selectedRectangle.width = 3;
- }
- if (_selectedRectangle.height < 3) {
- _selectedRectangle.height = 3;
- }
-
- UndoableEdit edit = (new MapLayoutUndoRedo()).new ResizeElementEdit(this, oElement, _selectedRectangle);
- this.fireUndoEditEvent(edit);
- PointF minP = screenToPage((float) _selectedRectangle.x, (float) _selectedRectangle.y);
- PointF maxP = screenToPage((float) _selectedRectangle.x + _selectedRectangle.width, _selectedRectangle.y + _selectedRectangle.height);
- oElement.setLeft((int) minP.X);
- oElement.setTop((int) minP.Y);
- oElement.setWidth((int) (maxP.X - minP.X));
- oElement.setHeight((int) (maxP.Y - minP.Y));
- oElement.resizeUpdate();
- //this.paintGraphics();
- this.repaintNew();
- break;
- case New_Rectangle:
- case New_Ellipse:
- if (e.getButton() == MouseEvent.BUTTON1) {
- if (e.getX() - _mouseDownPoint.x < 2 || e.getY() - _mouseDownPoint.y < 2) {
- return;
- }
-
- _startNewGraphic = true;
- _graphicPoints = new ArrayList<>();
- _graphicPoints.add(new PointF(_mouseDownPoint.x, _mouseDownPoint.y));
- _graphicPoints.add(new PointF(_mouseDownPoint.x, e.getY()));
- _graphicPoints.add(new PointF(e.getX(), e.getY()));
- _graphicPoints.add(new PointF(e.getX(), _mouseDownPoint.y));
- List points = new ArrayList<>();
- for (PointF cPoint : _graphicPoints) {
- PointF dPoint = screenToPage(cPoint.X, cPoint.Y);
- points.add(new PointD(dPoint.X, dPoint.Y));
- }
-
- Graphic aGraphic = null;
- switch (_mouseMode) {
- case New_Rectangle:
- RectangleShape aPGS = new RectangleShape();
- points.add((PointD) points.get(0).clone());
- aPGS.setPoints(points);
- aGraphic = new Graphic(aPGS, (PolygonBreak) _defPolygonBreak.clone());
- break;
- case New_Ellipse:
- EllipseShape aES = new EllipseShape();
- aES.setPoints(points);
- aGraphic = new Graphic(aES, (PolygonBreak) _defPolygonBreak.clone());
- break;
- }
-
- if (aGraphic != null) {
- LayoutGraphic lg = new LayoutGraphic(aGraphic, this);
- addElement(lg);
- //this.paintGraphics();
- this.repaintNew();
- edit = (new MapLayoutUndoRedo()).new AddElementEdit(this, lg);
- this.fireUndoEditEvent(edit);
- } else {
- //this.repaint();
- this.repaintOld();
- }
- }
- break;
- case New_Freehand:
- if (e.getButton() == MouseEvent.BUTTON1) {
- _startNewGraphic = true;
- if (_graphicPoints.size() < 2) {
- break;
- }
-
- List points = new ArrayList<>();
- for (PointF cPoint : _graphicPoints) {
- PointF dPoint = screenToPage(cPoint.X, cPoint.Y);
- points.add(new PointD(dPoint.X, dPoint.Y));
- }
-
- PolylineShape aPLS = new PolylineShape();
- aPLS.setPoints(points);
- Graphic aGraphic = new Graphic(aPLS, (PolylineBreak) _defPolylineBreak.clone());
- LayoutGraphic lg = new LayoutGraphic(aGraphic, this);
- addElement(lg);
- //this.paintGraphics();
- this.repaintNew();
- edit = (new MapLayoutUndoRedo()).new AddElementEdit(this, lg);
- this.fireUndoEditEvent(edit);
- }
- break;
- case New_Circle:
- if (e.getButton() == MouseEvent.BUTTON1) {
- if (e.getX() - _mouseDownPoint.x < 2 || e.getY() - _mouseDownPoint.y < 2) {
- return;
- }
-
- float radius = (float) Math.sqrt(Math.pow(e.getX() - _mouseDownPoint.x, 2)
- + Math.pow(e.getY() - _mouseDownPoint.y, 2));
- _startNewGraphic = true;
- _graphicPoints = new ArrayList<>();
- _graphicPoints.add(new PointF(_mouseDownPoint.x - radius, _mouseDownPoint.y));
- _graphicPoints.add(new PointF(_mouseDownPoint.x, _mouseDownPoint.y - radius));
- _graphicPoints.add(new PointF(_mouseDownPoint.x + radius, _mouseDownPoint.y));
- _graphicPoints.add(new PointF(_mouseDownPoint.x, _mouseDownPoint.y + radius));
- List points = new ArrayList<>();
- for (PointF cPoint : _graphicPoints) {
- PointF dPoint = screenToPage(cPoint.X, cPoint.Y);
- points.add(new PointD(dPoint.X, dPoint.Y));
- }
-
- CircleShape aPGS = new CircleShape();
- aPGS.setPoints(points);
- Graphic aGraphic = new Graphic(aPGS, (PolygonBreak) _defPolygonBreak.clone());
- LayoutGraphic lg = new LayoutGraphic(aGraphic, this);
- addElement(lg);
- //this.paintGraphics();
- this.repaintNew();
- edit = (new MapLayoutUndoRedo()).new AddElementEdit(this, lg);
- this.fireUndoEditEvent(edit);
- }
- break;
- case InEditingVertices:
- LayoutGraphic lg = (LayoutGraphic) _selectedElements.get(0);
- edit = (new MapLayoutUndoRedo()).new MoveGraphicVerticeEdit(this, lg, _editingVerticeIndex,
- pageP.x, pageP.y);
- this.fireUndoEditEvent(edit);
- lg.verticeEditUpdate(_editingVerticeIndex, pageP.x, pageP.y);
- _mouseMode = MouseMode.EditVertices;
- //this.paintGraphics();
- this.repaintNew();
- break;
- }
- }
- }
-
- void onMouseClicked(MouseEvent e) throws CloneNotSupportedException {
- int clickTimes = e.getClickCount();
- if (clickTimes == 1) {
- Point pageP = screenToPage(e.getX(), e.getY());
- if (e.getButton() == MouseEvent.BUTTON1) {
- switch (_mouseMode) {
- case Map_Identifer:
- MapLayer aMLayer = _currentLayoutMap.getMapFrame().getMapView().getSelectedLayer();
- if (aMLayer == null) {
- return;
- }
- if (aMLayer.getLayerType() == LayerTypes.ImageLayer) {
- return;
- }
-
- PointF mapP = pageToScreen(_currentLayoutMap.getLeft(), _currentLayoutMap.getTop());
- PointF aPoint = new PointF(e.getX() - mapP.X, e.getY() - mapP.Y);
- if (aMLayer.getLayerType() == LayerTypes.VectorLayer) {
- VectorLayer aLayer = (VectorLayer) aMLayer;
- List selectedShapes = _currentLayoutMap.getMapFrame().getMapView().selectShapes(aLayer, aPoint);
- if (selectedShapes.size() > 0) {
- if (frmIdentifier == null) {
- frmIdentifier = new FrmIdentifer((JFrame) SwingUtilities.getWindowAncestor(this), false, _currentLayoutMap.getMapFrame().getMapView());
- frmIdentifier.addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosed(WindowEvent e) {
- _currentLayoutMap.getMapFrame().getMapView().setDrawIdentiferShape(false);
- //repaint();
- repaintOld();
- }
- });
- }
- frmIdentifier.setMapView(_currentLayoutMap.getMapFrame().getMapView());
-
- String[] colNames = {"Field", "Value"};
- String fieldStr, valueStr;
- int shapeIdx = selectedShapes.get(0);
- aLayer.setIdentiferShape(shapeIdx);
- _currentLayoutMap.getMapFrame().getMapView().setDrawIdentiferShape(true);
-
- Object[][] tData = new Object[aLayer.getFieldNumber() + 1][2];
- fieldStr = "Index";
- valueStr = String.valueOf(shapeIdx);
- tData[0][0] = fieldStr;
- tData[0][1] = valueStr;
- if (aLayer.getShapeNum() > 0) {
- for (int i = 0; i < aLayer.getFieldNumber(); i++) {
- fieldStr = aLayer.getFieldName(i);
- valueStr = aLayer.getCellValue(i, shapeIdx).toString();
- tData[i + 1][0] = fieldStr;
- tData[i + 1][1] = valueStr;
- }
- }
- DefaultTableModel dtm = new javax.swing.table.DefaultTableModel(tData, colNames) {
- @Override
- public boolean isCellEditable(int row, int column) {
- return false;
- }
- };
- this.frmIdentifier.getTable().setModel(dtm);
- this.frmIdentifier.repaint();
- if (!this.frmIdentifier.isVisible()) {
- this.frmIdentifier.setLocation(e.getX(), e.getY());
- this.frmIdentifier.setVisible(true);
- }
-
- //this.repaint();
- this.repaintOld();
- //Rectangle rect = getElementViewExtent(_currentLayoutMap);
- //_currentLayoutMap.getMapFrame().getMapView().drawIdShape(this.createGraphics(), aLayer.getShapes().get(shapeIdx), rect);
- }
- } else if (aMLayer.getLayerType() == LayerTypes.RasterLayer) {
- RasterLayer aRLayer = (RasterLayer) aMLayer;
- int[] ijIdx = _currentLayoutMap.getMapFrame().getMapView().selectGridCell(aRLayer, aPoint);
- if (ijIdx != null) {
- int iIdx = ijIdx[0];
- int jIdx = ijIdx[1];
- double aValue = aRLayer.getCellValue(iIdx, jIdx);
- if (frmIdentifierGrid == null) {
- frmIdentifierGrid = new FrmIdentiferGrid((JFrame) SwingUtilities.getWindowAncestor(this), false);
- }
-
- frmIdentifierGrid.setIIndex(iIdx);
- frmIdentifierGrid.setJIndex(jIdx);
- frmIdentifierGrid.setCellValue(aValue);
- if (!this.frmIdentifierGrid.isVisible()) {
- //this._frmIdentiferGrid.setLocation(e.getX(), e.getY());
- this.frmIdentifierGrid.setLocationRelativeTo(this);
- this.frmIdentifierGrid.setVisible(true);
- }
- }
- }
- break;
-// case Map_SelectFeatures_Rectangle:
-// aMLayer = _currentLayoutMap.getMapFrame().getMapView().getSelectedLayer();
-// if (aMLayer == null) {
-// return;
-// }
-//
-// if (aMLayer.getLayerType() != LayerTypes.VectorLayer) {
-// return;
-// }
-//
-// VectorLayer aLayer = (VectorLayer) aMLayer;
-// if (!e.isControlDown() && !e.isShiftDown()) {
-// aLayer.clearSelectedShapes();
-// //_currentLayoutMap.getMapFrame().getMapView().paintLayers();
-// }
-//
-// mapP = pageToScreen(_currentLayoutMap.getLeft(), _currentLayoutMap.getTop());
-// aPoint = new PointF(e.getX() - mapP.X, e.getY() - mapP.Y);
-// List selectedShapes = _currentLayoutMap.getMapFrame().getMapView().selectShapes(aLayer, aPoint);
-// this._layoutBitmap = GlobalUtil.deepCopy(this._tempImage);
-// if (selectedShapes.size() > 0) {
-// int shapeIdx = selectedShapes.get(0);
-// Shape selShape = aLayer.getShapes().get(shapeIdx);
-// Rectangle rect = getElementViewExtent(_currentLayoutMap);
-// if (!e.isControlDown() && !e.isShiftDown()) {
-// selShape.setSelected(true);
-// _currentLayoutMap.getMapFrame().getMapView().drawIdShape((Graphics2D) this._layoutBitmap.getGraphics(), selShape, rect);
-// } else {
-// selShape.setSelected(!selShape.isSelected());
-// for (int sIdx : aLayer.getSelectedShapeIndexes()) {
-// _currentLayoutMap.getMapFrame().getMapView().drawIdShape((Graphics2D) this._layoutBitmap.getGraphics(), aLayer.getShapes().get(sIdx), rect);
-// }
-// }
-// this.repaint();
-// } else {
-// if (!e.isControlDown() && !e.isShiftDown()) {
-// this.repaint();
-// }
-// }
-// break;
- }
- } else if (e.getButton() == MouseEvent.BUTTON3 && _mouseMode == MouseMode.Select) {
- if (_selectedElements.isEmpty()) {
- return;
- }
-
- JPopupMenu jPopupMenu_Element = new JPopupMenu();
- JMenu jMenu_Order = new JMenu("Order");
- jPopupMenu_Element.add(jMenu_Order);
-
- JMenuItem jMenuItem_BTF = new JMenuItem("Bring to Front");
- jMenuItem_BTF.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- onBringToFrontClick(e);
- }
- });
- jMenu_Order.add(jMenuItem_BTF);
-
- JMenuItem jMenuItem_STB = new JMenuItem("Send to Back");
- jMenuItem_STB.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- onSendToBackClick(e);
- }
- });
- jMenu_Order.add(jMenuItem_STB);
-
- JMenuItem jMenuItem_BF = new JMenuItem("Bring Forward");
- jMenuItem_BF.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- onBringForwardClick(e);
- }
- });
- jMenu_Order.add(jMenuItem_BF);
-
- JMenuItem jMenuItem_SB = new JMenuItem("Send Backward");
- jMenuItem_SB.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- onSendBackwardClick(e);
- }
- });
- jMenu_Order.add(jMenuItem_SB);
-
- jPopupMenu_Element.add(new JSeparator());
-
- JMenuItem jMenuItem_Remove = new JMenuItem("Remove");
- jMenuItem_Remove.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- onRemoveElementClick(e);
- }
- });
- jPopupMenu_Element.add(jMenuItem_Remove);
-
- switch (_mouseMode) {
- case Select:
- case MoveSelection:
- case ResizeSelected:
- if (_selectedElements.size() > 0) {
- LayoutElement aElement = _selectedElements.get(0);
- if (MIMath.pointInRectangle(pageP, aElement.getBounds())) {
- if (aElement.getElementType() == ElementType.LayoutGraphic) {
- Graphic aGraphic = ((LayoutGraphic) aElement).getGraphic();
- if (aGraphic.getLegend().getBreakType() == BreakTypes.PolylineBreak || aGraphic.getLegend().getBreakType() == BreakTypes.PolygonBreak) {
- JMenuItem jMenuItem_Reverse = new JMenuItem("Reverse");
- jMenuItem_Reverse.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- onReverseGraphicClick(e);
- }
- });
- jPopupMenu_Element.add(jMenuItem_Reverse);
-
- if (aGraphic.getShape().getShapeType() == ShapeTypes.Polyline || aGraphic.getShape().getShapeType() == ShapeTypes.Polygon) {
- jPopupMenu_Element.add(new JSeparator());
- JMenuItem jMenuItem_Smooth = new JMenuItem("Smooth Graphic");
- jMenuItem_Smooth.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- onGraphicSmoothClick(e);
- }
- });
- jPopupMenu_Element.add(jMenuItem_Smooth);
- }
-
- if (aGraphic.getShape().getShapeType() == ShapeTypes.Ellipse) {
- JMenuItem jMenuItem_Angle = new JMenuItem("Set Angle");
- jMenuItem_Angle.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- onGraphicAngleClick(e);
- }
- });
- jPopupMenu_Element.add(jMenuItem_Angle);
- }
- }
- }
- }
- }
- break;
- }
-
- jPopupMenu_Element.show(this, e.getX(), e.getY());
- }
- } else if (clickTimes == 2) {
- Point pageP = screenToPage(e.getX(), e.getY());
- switch (_mouseMode) {
- case Select:
- case MoveSelection:
- case ResizeSelected:
- if (_selectedElements.isEmpty()) {
- return;
- }
-
- LayoutElement aElement = _selectedElements.get(0);
- _selectedElements = selectElements(pageP, _layoutElements, 0);
- if (_selectedElements.size() > 1) {
- aElement.setSelected(false);
- int idx = _selectedElements.indexOf(aElement);
- idx += 2;
- if (idx > _selectedElements.size() - 1) {
- idx = idx - _selectedElements.size();
- }
- aElement = _selectedElements.get(idx);
- _selectedElements.clear();
- _selectedElements.add(aElement);
- _selectedElements.get(0).setSelected(true);
- }
- //this.paintGraphics();
- this.repaintNew();
-
- if (aElement.getElementType() == ElementType.LayoutGraphic) {
- Graphic aGraphic = ((LayoutGraphic) aElement).getGraphic();
- showSymbolSetForm(aGraphic);
- } else {
- FrmProperty aFrmProperty = new FrmProperty((JFrame) SwingUtilities.getWindowAncestor(this), true, false);
- Object object = aElement;
- switch (aElement.getElementType()) {
- case LayoutLegend:
- object = ((LayoutLegend) aElement).new LayoutLegendBean();
- break;
- case LayoutMap:
- object = ((LayoutMap) aElement).new LayoutMapBean();
- break;
- case LayoutNorthArraw:
- object = ((LayoutNorthArrow) aElement).new LayoutNorthArrowBean();
- break;
- case LayoutScaleBar:
- object = ((LayoutScaleBar) aElement).new LayoutScaleBarBean();
- break;
- }
- aFrmProperty.setObject(object);
- aFrmProperty.setParent(this);
- aFrmProperty.setLocationRelativeTo(this);
- aFrmProperty.setVisible(true);
- }
- setMouseMode(MouseMode.Select);
- this.fireElementSelectedEvent();
- break;
- case New_Polyline:
- case New_Polygon:
- case New_Curve:
- case New_CurvePolygon:
- case New_Freehand:
- case Map_SelectFeatures_Polygon:
- if (!_startNewGraphic) {
- _startNewGraphic = true;
- _graphicPoints.remove(_graphicPoints.size() - 1);
-
- if (_mouseMode == MouseMode.Map_SelectFeatures_Polygon) {
- PointF mapP = pageToScreen(_currentLayoutMap.getLeft(), _currentLayoutMap.getTop());
- List points = new ArrayList<>();
- MapView currentMapView = _currentLayoutMap.getMapFrame().getMapView();
- for (PointF aPoint : _graphicPoints) {
- float[] pXY = currentMapView.screenToProj(aPoint.X - mapP.X, aPoint.Y - mapP.Y);
- points.add(new PointD(pXY[0], pXY[1]));
- }
-
- MapLayer aMLayer = _currentLayoutMap.getMapFrame().getMapView().getSelectedLayer();
- if (aMLayer == null) {
- return;
- }
- if (aMLayer.getLayerType() != LayerTypes.VectorLayer) {
- return;
- }
-
- PolygonShape aPGS = new PolygonShape();
- points.add((PointD) points.get(0).clone());
- aPGS.setPoints(points);
- VectorLayer aLayer = (VectorLayer) aMLayer;
- if (!e.isControlDown() && !e.isShiftDown()) {
- aLayer.clearSelectedShapes();
- }
- aLayer.selectShapes(aPGS);
- _currentLayoutMap.getMapFrame().getMapView().fireShapeSelectedEvent();
- } else {
- List points = new ArrayList<>();
- for (PointF aPoint : _graphicPoints) {
- PointF bPoint = screenToPage(aPoint.X, aPoint.Y);
- points.add(new PointD(bPoint.X, bPoint.Y));
- }
-
- Graphic aGraphic = null;
- switch (_mouseMode) {
- case New_Polyline:
- case New_Freehand:
- PolylineShape aPLS = new PolylineShape();
- aPLS.setPoints(points);
- aGraphic = new Graphic(aPLS, (PolylineBreak) _defPolylineBreak.clone());
- break;
- case New_Polygon:
- if (points.size() > 2) {
- PolygonShape aPGS = new PolygonShape();
- points.add((PointD) points.get(0).clone());
- aPGS.setPoints(points);
- aGraphic = new Graphic(aPGS, (PolygonBreak) _defPolygonBreak.clone());
- }
- break;
- case New_Curve:
- CurveLineShape aCLS = new CurveLineShape();
- aCLS.setPoints(points);
- aGraphic = new Graphic(aCLS, (PolylineBreak) _defPolylineBreak.clone());
- break;
- case New_CurvePolygon:
- if (points.size() > 2) {
- CurvePolygonShape aCPS = new CurvePolygonShape();
- points.add((PointD) points.get(0).clone());
- aCPS.setPoints(points);
- aGraphic = new Graphic(aCPS, (PolygonBreak) _defPolygonBreak.clone());
- }
- break;
- }
-
- if (aGraphic != null) {
- LayoutGraphic lg = new LayoutGraphic(aGraphic, this);
- addElement(lg);
- //this.paintGraphics();
- this.repaintNew();
- UndoableEdit edit = (new MapLayoutUndoRedo()).new AddElementEdit(this, lg);
- this.fireUndoEditEvent(edit);
- } else {
- this.repaint();
- }
- }
- }
- break;
- }
- }
- }
-
- private void onRemoveElementClick(ActionEvent e) {
- this.onRemoveElementClick();
- }
-
- private void onBringToFrontClick(ActionEvent e) {
- LayoutElement aLE = _selectedElements.get(0);
- int idx = _layoutElements.indexOf(aLE);
- if (idx < _layoutElements.size() - 1) {
- _layoutElements.remove(aLE);
- _layoutElements.add(aLE);
- //this.paintGraphics();
- this.repaintNew();
- }
- }
-
- private void onSendToBackClick(ActionEvent e) {
- LayoutElement aLE = _selectedElements.get(0);
- int idx = _layoutElements.indexOf(aLE);
- if (idx > 0) {
- _layoutElements.remove(aLE);
- _layoutElements.add(0, aLE);
- //this.paintGraphics();
- this.repaintNew();
- }
- }
-
- private void onBringForwardClick(ActionEvent e) {
- LayoutElement aLE = _selectedElements.get(0);
- int idx = _layoutElements.indexOf(aLE);
- if (idx < _layoutElements.size() - 1) {
- _layoutElements.remove(aLE);
- _layoutElements.add(idx + 1, aLE);
- //this.paintGraphics();
- this.repaintNew();
- }
- }
-
- private void onSendBackwardClick(ActionEvent e) {
- LayoutElement aLE = _selectedElements.get(0);
- int idx = _layoutElements.indexOf(aLE);
- if (idx > 0) {
- _layoutElements.remove(aLE);
- _layoutElements.add(idx - 1, aLE);
- //this.paintGraphics();
- this.repaintNew();
- }
- }
-
- private void onReverseGraphicClick(ActionEvent e) {
- LayoutElement aElement = _selectedElements.get(0);
- Graphic aGraphic = ((LayoutGraphic) aElement).getGraphic();
- List points = (List) aGraphic.getShape().getPoints();
- Collections.reverse(points);
- aGraphic.getShape().setPoints(points);
-
- //this.paintGraphics();
- this.repaintNew();
- }
-
- private void onGraphicSmoothClick(ActionEvent e) {
- LayoutElement aElement = _selectedElements.get(0);
- Graphic aGraphic = ((LayoutGraphic) aElement).getGraphic();
- List pointList = new ArrayList<>();
- List newPoints = new ArrayList<>();
-
- for (PointD aP : aGraphic.getShape().getPoints()) {
- pointList.add(new wcontour.global.PointD(aP.X, aP.Y));
- }
-
- if (aGraphic.getShape().getShapeType() == ShapeTypes.Polygon) {
- pointList.add(pointList.get(0));
- }
-
- pointList = wcontour.Contour.smoothPoints(pointList);
- for (wcontour.global.PointD aP : pointList) {
- newPoints.add(new PointD(aP.X, aP.Y));
- }
- aGraphic.getShape().setPoints(newPoints);
- ((LayoutGraphic) aElement).updateControlSize();
- //this.paintGraphics();
- this.repaintNew();
- }
-
- private void onGraphicAngleClick(ActionEvent e) {
- LayoutElement aElement = _selectedElements.get(0);
- Graphic aGraphic = ((LayoutGraphic) aElement).getGraphic();
- EllipseShape es = (EllipseShape)aGraphic.getShape();
- String angleStr = JOptionPane.showInputDialog(this, "Ellipse angle:", es.getAngle());
- if (angleStr != null){
- es.setAngle(Float.parseFloat(angleStr));
- //this.paintGraphics();
- this.repaintNew();
- }
- }
-
- private void showSymbolSetForm(ColorBreak aCB) {
- switch (aCB.getBreakType()) {
- case PointBreak:
- PointBreak aPB = (PointBreak) aCB;
-
- if (_frmPointSymbolSet == null) {
- _frmPointSymbolSet = new FrmPointSymbolSet((JFrame) SwingUtilities.getWindowAncestor(this), false, this);
- _frmPointSymbolSet.setLocationRelativeTo(this);
- _frmPointSymbolSet.setVisible(true);
- }
- _frmPointSymbolSet.setPointBreak(aPB);
- _frmPointSymbolSet.setVisible(true);
- break;
- case LabelBreak:
- LabelBreak aLB = (LabelBreak) aCB;
-
- if (_frmLabelSymbolSet == null) {
- _frmLabelSymbolSet = new FrmLabelSymbolSet((JFrame) SwingUtilities.getWindowAncestor(this), false, this);
- _frmLabelSymbolSet.setLocationRelativeTo(this);
- _frmLabelSymbolSet.setVisible(true);
- }
- _frmLabelSymbolSet.setLabelBreak(aLB);
- _frmLabelSymbolSet.setVisible(true);
- break;
- case PolylineBreak:
- PolylineBreak aPLB = (PolylineBreak) aCB;
-
- if (_frmPolylineSymbolSet == null) {
- _frmPolylineSymbolSet = new FrmPolylineSymbolSet((JFrame) SwingUtilities.getWindowAncestor(this), false, this);
- _frmPolylineSymbolSet.setLocationRelativeTo(this);
- _frmPolylineSymbolSet.setVisible(true);
- }
- _frmPolylineSymbolSet.setPolylineBreak(aPLB);
- _frmPolylineSymbolSet.setVisible(true);
- break;
- case PolygonBreak:
- PolygonBreak aPGB = (PolygonBreak) aCB;
-
- if (_frmPolygonSymbolSet == null) {
- _frmPolygonSymbolSet = new FrmPolygonSymbolSet((JFrame) SwingUtilities.getWindowAncestor(this), false, this);
- _frmPolygonSymbolSet.setLocationRelativeTo(this);
- _frmPolygonSymbolSet.setVisible(true);
- }
- _frmPolygonSymbolSet.setPolygonBreak(aPGB);
- _frmPolygonSymbolSet.setVisible(true);
- break;
- }
- }
-
- private void showSymbolSetForm(Graphic graphic) {
- Shape shape = graphic.getShape();
- ColorBreak aCB = graphic.getLegend();
- switch (aCB.getBreakType()) {
- case PointBreak:
- PointBreak aPB = (PointBreak) aCB;
-
- if (_frmPointSymbolSet == null) {
- _frmPointSymbolSet = new FrmPointSymbolSet((JFrame) SwingUtilities.getWindowAncestor(this), false, this);
- _frmPointSymbolSet.setLocationRelativeTo(this);
- _frmPointSymbolSet.setVisible(true);
- }
- _frmPointSymbolSet.setPointBreak(aPB);
- _frmPointSymbolSet.setVisible(true);
- break;
- case LabelBreak:
- LabelBreak aLB = (LabelBreak) aCB;
-
- if (_frmLabelSymbolSet == null) {
- _frmLabelSymbolSet = new FrmLabelSymbolSet((JFrame) SwingUtilities.getWindowAncestor(this), false, this);
- _frmLabelSymbolSet.setLocationRelativeTo(this);
- _frmLabelSymbolSet.setVisible(true);
- }
- _frmLabelSymbolSet.setLabelBreak(aLB);
- _frmLabelSymbolSet.setVisible(true);
- break;
- case PolylineBreak:
- PolylineBreak aPLB = (PolylineBreak) aCB;
-
- if (_frmPolylineSymbolSet == null) {
- _frmPolylineSymbolSet = new FrmPolylineSymbolSet((JFrame) SwingUtilities.getWindowAncestor(this), false, this);
- _frmPolylineSymbolSet.setLocationRelativeTo(this);
- _frmPolylineSymbolSet.setVisible(true);
- }
- _frmPolylineSymbolSet.setPolylineBreak(aPLB);
- _frmPolylineSymbolSet.setVisible(true);
- break;
- case PolygonBreak:
- PolygonBreak aPGB = (PolygonBreak) aCB;
-
- if (_frmPolygonSymbolSet == null) {
- _frmPolygonSymbolSet = new FrmPolygonSymbolSet((JFrame) SwingUtilities.getWindowAncestor(this), false, this);
- _frmPolygonSymbolSet.setLocationRelativeTo(this);
- _frmPolygonSymbolSet.setVisible(true);
- }
- _frmPolygonSymbolSet.setPolygonBreak(aPGB);
- _frmPolygonSymbolSet.setVisible(true);
- break;
- case VectorBreak:
- WindArrow wa = (WindArrow) shape;
- //VectorBreak vb = (VectorBreak) aCB;
- Object[] lens = {5, 10, 15, 20, 25, 30};
- Object lenObj = JOptionPane.showInputDialog((JFrame) SwingUtilities.getWindowAncestor(this),
- "Select wind speed:", "Selection", JOptionPane.PLAIN_MESSAGE, null, lens, (int) wa.length);
- if (lenObj != null) {
- wa.length = Integer.parseInt(lenObj.toString());
- //this.paintGraphics();
- this.repaintNew();
- }
- break;
- }
- }
-
- void onKeyPressed(KeyEvent e) {
- if (_mouseMode == MouseMode.Select) {
- switch (e.getKeyCode()) {
- case KeyEvent.VK_DELETE:
- onRemoveElementClick();
- break;
- case KeyEvent.VK_LEFT:
- case KeyEvent.VK_RIGHT:
- case KeyEvent.VK_UP:
- case KeyEvent.VK_DOWN:
- int x = 0;
- int y = 0;
- int d = 5;
- if (e.isControlDown()) {
- d = 1;
- }
- switch (e.getKeyCode()) {
- case KeyEvent.VK_LEFT:
- x = -d;
- break;
- case KeyEvent.VK_RIGHT:
- x = d;
- break;
- case KeyEvent.VK_UP:
- y = -d;
- break;
- case KeyEvent.VK_DOWN:
- y = d;
- break;
- }
- for (int i = 0; i < _layoutElements.size(); i++) {
- LayoutElement aElement = _layoutElements.get(i);
- if (aElement.isSelected()) {
- if (x != 0) {
- aElement.setLeft(aElement.getLeft() + x);
- }
- if (y != 0) {
- aElement.setTop(aElement.getTop() + y);
- }
- aElement.moveUpdate();
- }
- }
- //this.paintGraphics();
- this.repaintNew();
- break;
- }
- }
- }
-
- private void onRemoveElementClick() {
- UndoableEdit edit = (new MapLayoutUndoRedo()).new RemoveElementsEdit(this, _selectedElements);
- this.fireUndoEditEvent(edit);
- for (LayoutElement element : _selectedElements) {
- removeElement(element);
- }
-
- _selectedElements.clear();
- _startNewGraphic = true;
- //paintGraphics();
- this.repaintNew();
- }
-
- //
- //
- /**
- * Get if using off screen image double buffering.
- * Using double buffering will be faster but lower view quality in
- * high dpi screen computer.
- *
- * @return Boolean
- */
- public boolean isDoubleBuffer() {
- return this.doubleBuffer;
- }
-
- /**
- * Set using off screen image double buffering or not.
- * @param value Boolean
- */
- public void setDoubleBuffer(boolean value) {
- this.doubleBuffer = value;
- }
-
- /**
- * Get if lock view update
- *
- * @return If lock view update
- */
- public boolean isLockViewUpdate() {
- return _lockViewUpdate;
- }
-
- /**
- * Set if lock view update
- *
- * @param istrue If lock view update
- */
- public void setLockViewUpdate(boolean istrue) {
- _lockViewUpdate = istrue;
- }
-
- /**
- * Get map frames
- *
- * @return Map frames
- */
- public List getMapFrames() {
- return _mapFrames;
- }
-
- /**
- * Set map frames
- *
- * @param mfs Map frames
- */
- public void setMapFrames(List mfs) {
- _mapFrames = mfs;
- _mapFrames = new ArrayList<>();
- for (MapFrame mf : mfs) {
- boolean isInsert = false;
- for (int i = 0; i < _mapFrames.size(); i++) {
- MapFrame amf = _mapFrames.get(i);
- if (mf.getOrder() < amf.getOrder()) {
- _mapFrames.add(i, mf);
- isInsert = true;
- break;
- }
- }
-
- if (!isInsert) {
- _mapFrames.add(mf);
- }
- }
- }
-
- /**
- * Get active map frame
- *
- * @return Active map frame
- */
- public MapFrame getActiveMapFrame() {
- for (MapFrame mf : _mapFrames) {
- if (mf.isActive()) {
- return mf;
- }
- }
-
- return null;
- }
-
- /**
- * Get active layout map
- *
- * @return Active layout map
- */
- public LayoutMap getActiveLayoutMap() {
- LayoutMap aLM = null;
- for (LayoutMap lm : this.getLayoutMaps()) {
- if (lm.getMapFrame().isActive()) {
- aLM = lm;
- break;
- }
- }
- return aLM;
- }
-
- /**
- * Get if is landscape
- *
- * @return Boolean
- */
- public boolean isLandscape() {
- return _isLandscape;
- }
-
- /**
- * Set if is landscape
- *
- * @param istrue
- */
- public void setLandscape(boolean istrue) {
- _isLandscape = istrue;
- Rectangle.Float aRect = paperToScreen(new Rectangle.Float(0, 0, this.getPaperWidth(), this.getPaperHeight()));
- _pageBounds.width = (int) aRect.width;
- _pageBounds.height = (int) aRect.height;
- }
-
- /**
- * Get mouse mode
- *
- * @return The mouse mode
- */
- public MouseMode getMouseMode() {
- return _mouseMode;
- }
-
- /**
- * Set mouse mode
- *
- * @param mm The mouse mode
- */
- public void setMouseMode(MouseMode mm) {
- _mouseMode = mm;
- switch (_mouseMode) {
- case New_Label:
- case New_Point:
- case New_Polyline:
- case New_Polygon:
- case New_Rectangle:
- case New_Circle:
- case New_Curve:
- case New_CurvePolygon:
- case New_Ellipse:
- case New_Freehand:
- this.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
- break;
- case Map_Measurement:
- this.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
- break;
- case Map_SelectFeatures_Rectangle:
- case Map_SelectFeatures_Polygon:
- case Map_SelectFeatures_Lasso:
- case Map_SelectFeatures_Circle:
- this.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
- this._tempImage = GlobalUtil.deepCopy(this._layoutBitmap);
- break;
- }
- }
-
- /**
- * Get if antialias
- *
- * @return Boolean
- */
- public boolean isAntiAlias() {
- return _antiAlias;
- }
-
- /**
- * Set if antialias
- *
- * @param istrue Boolean
- */
- public void setAntiAlias(boolean istrue) {
- _antiAlias = istrue;
- }
-
- /**
- * Get page foreground color
- *
- * @return Page foreground color
- */
- public Color getPageForeColor() {
- return this._pageForeColor;
- }
-
- /**
- * Set page foreground color
- *
- * @param c Page foreground color
- */
- public void setPageForeColor(Color c) {
- _pageForeColor = c;
- }
-
- /**
- * Get page background color
- *
- * @return Page background color
- */
- public Color getPageBackColor() {
- return _pageBackColor;
- }
-
- /**
- * Set page background color
- *
- * @param c Page background color
- */
- public void setPageBackColor(Color c) {
- _pageBackColor = c;
-
- if (c == Color.black) {
- _pageForeColor = Color.white;
- } else if (c == Color.white) {
- _pageForeColor = Color.black;
- }
- }
-
- /**
- * Get paper size
- *
- * @return Paper size
- */
- public PaperSize getPaperSize() {
- return _paperSize;
- }
-
- /**
- * Set paper size
- *
- * @param ps Paper size
- */
- public void setPaperSize(PaperSize ps) {
- _paperSize = ps;
- Rectangle.Float aRect = paperToScreen(new Rectangle.Float(0, 0, getPaperWidth(), getPaperHeight()));
- _pageBounds.width = (int) aRect.width;
- _pageBounds.height = (int) aRect.height;
- }
-
- /**
- * Set paper size
- *
- * @param width Width
- * @param height Height
- */
- public void setPaperSize(int width, int height) {
- PaperSize ps = new PaperSize("Custom", width, height);
- setPaperSize(ps);
- }
-
- /**
- * Get the width of the paper in 1/100 of an inch
- */
- private int getPaperWidth() {
- if (_isLandscape) {
- return _paperSize.getHeight();
- }
- return _paperSize.getWidth();
- }
-
- /**
- * Gets the heigh of the paper in 1/100 of an inch
- */
- private int getPaperHeight() {
- if (_isLandscape) {
- return _paperSize.getWidth();
- }
- return _paperSize.getHeight();
- }
-
- /**
- * Get layout map elements
- *
- * @return The layout map elements
- */
- public List getLayoutMaps() {
- List layoutMaps = new ArrayList<>();
- for (LayoutElement aLE : _layoutElements) {
- if (aLE.getElementType() == ElementType.LayoutMap) {
- layoutMaps.add((LayoutMap) aLE);
- }
- }
- return layoutMaps;
- }
-
- /**
- * Get selected elements
- *
- * @return Selected elements
- */
- public List getSelectedElements() {
- return _selectedElements;
- }
-
- ///
- /// Get or set page bounds
- ///
- /**
- * Get page bounds
- *
- * @return Page bounds
- */
- public Rectangle getPageBounds() {
- return _pageBounds;
- }
-
- /**
- * Set page bounds
- *
- * @param pb Page bounds
- */
- public void setPageBounds(Rectangle pb) {
- _pageBounds = pb;
- }
-
- /**
- * Get page location
- *
- * @return Page location
- */
- public PointF getPageLocation() {
- return _pageLocation;
- }
-
- /**
- * Set page location
- *
- * @param p Page location
- */
- public void setPageLocation(PointF p) {
- _pageLocation = p;
- }
-
- /**
- * Get zoom
- *
- * @return Zoom
- */
- public float getZoom() {
- return _zoom;
- }
-
- /**
- * Set zoom
- *
- * @param zoom Zoom
- */
- public void setZoom(float zoom) {
- _zoom = zoom;
- this.fireZoomChangedEvent();
- }
-
- /**
- * Get default point break
- *
- * @return Default point break
- */
- public PointBreak getDefPointBreak() {
- return _defPointBreak;
- }
-
- /**
- * Set default point break
- *
- * @param pb Default point break
- */
- public void setDefPointBreak(PointBreak pb) {
- _defPointBreak = pb;
- }
-
- /**
- * Get default label break
- *
- * @return Default label break
- */
- public LabelBreak getDefLabelBreak() {
- return _defLabelBreak;
- }
-
- /**
- * Set default label break
- *
- * @param lb Default label break
- */
- public void setDefLabelBreak(LabelBreak lb) {
- _defLabelBreak = lb;
- }
-
- /**
- * Get default polyline break
- *
- * @return Default polyline break
- */
- public PolylineBreak getDefPolylineBreak() {
- return _defPolylineBreak;
- }
-
- /**
- * Set default polyline break
- *
- * @param pb Default polyline break
- */
- public void setDefPolylineBreak(PolylineBreak pb) {
- _defPolylineBreak = pb;
- }
-
- /**
- * Get default polygon break
- *
- * @return Default polygon break
- */
- public PolygonBreak getDefPolygonBreak() {
- return _defPolygonBreak;
- }
-
- /**
- * Set default polygon break
- *
- * @param pb Default polygon break
- */
- public void setDefPolygonBreak(PolygonBreak pb) {
- _defPolygonBreak = pb;
- }
-
- /**
- * Get measurement form
- *
- * @return Measurement form
- */
- public FrmMeasurement getMeasurementForm() {
- return _frmMeasure;
- }
-
- /**
- * set measurement form
- *
- * @param form Measurement form
- */
- public void setMeasurementForm(FrmMeasurement form) {
- _frmMeasure = form;
- }
-
- /**
- * Get view image
- *
- * @return View image
- */
- public BufferedImage getViewImage() {
- BufferedImage aImage = new BufferedImage(_pageBounds.width, _pageBounds.height, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = aImage.createGraphics();
- paintGraphics(g);
- return aImage;
- }
-
- //
- //
- //
- @Override
- public int getWebMapZoom(){
- WebMapLayer layer = this.getActiveMapFrame().getMapView().getWebMapLayer();
- if (layer != null){
- return layer.getZoom();
- }
- return 0;
- }
-
- @Override
- public void reDraw(){
- //this.paintGraphics();
- this.repaintNew();
- }
-
- @Override
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
-
- Graphics2D g2 = (Graphics2D) g;
- g2.setColor(this.getBackground());
- g2.clearRect(0, 0, this.getWidth(), this.getHeight());
- g2.fillRect(0, 0, this.getWidth(), this.getHeight());
-
- if (this.newPaint) {
- this.paintGraphicsAll(g2);
- } else {
- //g2.drawImage(this._layoutBitmap, _xShift, _yShift, this.getBackground(), this);
- AffineTransform mx = new AffineTransform();
- mx.translate((float) _xShift, (float) _yShift);
- AffineTransformOp aop = new AffineTransformOp(mx, AffineTransformOp.TYPE_BILINEAR);
- g2.drawImage(this._layoutBitmap, aop, 0, 0);
- }
-
- if (this._dragMode) {
- Rectangle rect = new Rectangle();
- float dash1[] = {2.0f};
- switch (this._mouseMode) {
- case Map_ZoomIn:
- rect.width = Math.abs(_mouseLastPos.x - _mouseDownPoint.x);
- rect.height = Math.abs(_mouseLastPos.y - _mouseDownPoint.y);
- rect.x = Math.min(_mouseLastPos.x, _mouseDownPoint.x);
- rect.y = Math.min(_mouseLastPos.y, _mouseDownPoint.y);
- //g2.setColor(this.getForeground());
- g2.setColor(Color.black);
- g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f));
- g2.draw(rect);
- break;
- case MoveSelection:
- rect.x = _selectedRectangle.x + _mouseLastPos.x - _mouseDownPoint.x;
- rect.y = _selectedRectangle.y + _mouseLastPos.y - _mouseDownPoint.y;
- rect.width = _selectedRectangle.width;
- rect.height = _selectedRectangle.height;
- g2.setColor(Color.red);
- g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f));
- g2.draw(rect);
- break;
- case ResizeSelected:
- g2.setColor(Color.red);
- g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f));
- g2.draw(_selectedRectangle);
- break;
- case CreateSelection:
- case New_Rectangle:
- case New_Ellipse:
- case Map_SelectFeatures_Rectangle:
- int sx = Math.min(_mouseDownPoint.x, _mouseLastPos.x);
- int sy = Math.min(_mouseDownPoint.y, _mouseLastPos.y);
- g2.setColor(this.getForeground());
- g2.draw(new Rectangle(sx, sy, Math.abs(_mouseLastPos.x - _mouseDownPoint.x),
- Math.abs(_mouseLastPos.y - _mouseDownPoint.y)));
- break;
- case New_Freehand:
- case Map_SelectFeatures_Lasso:
- List points = new ArrayList<>(_graphicPoints);
- points.add(new PointF(_mouseLastPos.x, _mouseLastPos.y));
- g2.setColor(this.getForeground());
- _graphicPoints.add(new PointF(_mouseLastPos.x, _mouseLastPos.y));
- Draw.drawPolyline(points, g2);
- break;
- case New_Circle:
- case Map_SelectFeatures_Circle:
- int radius = (int) Math.sqrt(Math.pow(_mouseLastPos.x - _mouseDownPoint.x, 2)
- + Math.pow(_mouseLastPos.y - _mouseDownPoint.y, 2));
- g2.setColor(this.getForeground());
- g2.drawLine(_mouseDownPoint.x, _mouseDownPoint.y, _mouseLastPos.x, _mouseLastPos.y);
- g2.drawOval(_mouseDownPoint.x - radius, _mouseDownPoint.y - radius,
- radius * 2, radius * 2);
- break;
- case InEditingVertices:
- PointF p1 = pageToScreen((float) _editingVertices.get(1).X, (float) _editingVertices.get(1).Y);
- PointF p2 = pageToScreen((float) _editingVertices.get(2).X, (float) _editingVertices.get(2).Y);
- g2.setColor(Color.black);
- g2.drawLine((int) p1.X, (int) p1.Y, _mouseLastPos.x, _mouseLastPos.y);
- if (_editingVertices.size() == 3) {
- g2.drawLine((int) p2.X, (int) p2.Y, _mouseLastPos.x, _mouseLastPos.y);
- }
-
- Rectangle nRect = new Rectangle(_mouseLastPos.x - 3, _mouseLastPos.y - 3, 6, 6);
- g2.setColor(Color.cyan);
- g2.fill(nRect);
- g2.setColor(Color.black);
- g2.draw(nRect);
- break;
- }
- }
-
- switch (this._mouseMode) {
- case New_Polyline:
- case New_Polygon:
- case New_Curve:
- case New_CurvePolygon:
- case Map_SelectFeatures_Polygon:
- if (!_startNewGraphic) {
- List points = new ArrayList<>(_graphicPoints);
- points.add(new PointF(_mouseLastPos.x, _mouseLastPos.y));
- g2.setColor(this.getForeground());
- switch (_mouseMode) {
- case New_Polyline:
- Draw.drawPolyline(points, g2);
- break;
- case New_Polygon:
- points.add(points.get(0));
- Draw.drawPolyline(points, g2);
- break;
- case New_Curve:
- Draw.drawCurveLine(points, g2);
- break;
- case New_CurvePolygon:
- points.add(points.get(0));
- Draw.drawCurveLine(points, g2);
- break;
- }
- }
- break;
- case Map_Measurement:
- if (!_startNewGraphic) {
- //Draw graphic
- //g.SmoothingMode = SmoothingMode.AntiAlias;
- PointF[] fpoints = (PointF[]) _graphicPoints.toArray(new PointF[_graphicPoints.size()]);
- PointF[] points = new PointF[fpoints.length + 1];
- System.arraycopy(fpoints, 0, points, 0, fpoints.length);
- points[_graphicPoints.size()] = new PointF(_mouseLastPos.x, _mouseLastPos.y);
-
- if (_frmMeasure.getMeasureType() == MeasureTypes.Length) {
- g2.setColor(Color.red);
- g2.setStroke(new BasicStroke(2));
- Draw.drawPolyline(points, g2);
- } else {
- PointF[] ppoints = new PointF[points.length + 1];
- System.arraycopy(points, 0, ppoints, 0, points.length);
- ppoints[ppoints.length - 1] = _graphicPoints.get(0);
- Color aColor = new Color(Color.blue.getRed(), Color.blue.getGreen(), Color.blue.getBlue(), 100);
- g2.setColor(aColor);
- PolygonBreak aPB = new PolygonBreak();
- aPB.setColor(aColor);
- Draw.drawPolygon(ppoints, aPB, g2);
- g2.setColor(Color.red);
- Draw.drawPolyline(ppoints, g2);
- }
- }
- break;
- }
-
- if (this._currentLayoutMap != null) {
- if (this._currentLayoutMap.getMapFrame().getMapView().isDrawIdentiferShape()) {
- int selLayerHandle = this._currentLayoutMap.getMapFrame().getMapView().getSelectedLayerHandle();
- if (selLayerHandle >= 0) {
- MapLayer aLayer = this._currentLayoutMap.getMapFrame().getMapView().getLayerByHandle(selLayerHandle);
- if (aLayer.getLayerType() == LayerTypes.VectorLayer) {
- VectorLayer vLayer = (VectorLayer) aLayer;
- Rectangle rect = getElementViewExtent(_currentLayoutMap);
- this._currentLayoutMap.getMapFrame().getMapView().drawIdShape(g2, vLayer.getShapes().get(vLayer.getIdentiferShape()), rect);
- }
- }
- }
- }
- }
-
- /**
- * New paint
- */
- public void repaintNew() {
- if (this.doubleBuffer) {
- this.newPaint = false;
- this.paintGraphics();
- } else {
- this.newPaint = true;
- this.repaint();
- this.updateViewImage();
- }
- }
-
- private void repaintOld() {
- if (this.doubleBuffer) {
- this.repaint();
- } else {
- this.newPaint = false;
- this.repaint();
- }
- }
-
- private void updateViewImage() {
- if (this.getWidth() < 5 || this.getHeight() < 5) {
- return;
- }
-
- int width = this.getWidth();
- int height = this.getHeight();
-
- this._layoutBitmap = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = this._layoutBitmap.createGraphics();
- this.print(g);
- g.dispose();
- }
-
- public void paintGraphicsAll(Graphics2D g) {
- if (this._lockViewUpdate) {
- return;
- }
-
- if (this.getWidth() < 10 || this.getHeight() < 10) {
- return;
- }
-
- if ((this._pageBounds.width < 2) || (this._pageBounds.height < 2)) {
- return;
- }
-
- g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
-
- //Judge if show scroll bar
- int pageHeight = (int) (_pageBounds.height * _zoom);
- int pageWidth = (int) (_pageBounds.width * _zoom);
- if (pageHeight > this.getHeight()) {
- int sHeight = pageHeight - this.getHeight() + 40;
- _vScrollBar.setMinimum(0);
- _vScrollBar.setMaximum(pageHeight);
- _vScrollBar.setVisibleAmount(pageHeight - sHeight);
- _vScrollBar.setUnitIncrement(pageHeight / 10);
- _vScrollBar.setBlockIncrement(pageHeight / 5);
- if (_vScrollBar.getWidth() == 0) {
- _vScrollBar.setSize(21, this._vScrollBar.getHeight());
- }
-
- if (_vScrollBar.isVisible() == false) {
- _vScrollBar.setValue(0);
- _vScrollBar.setVisible(true);
- }
- } else {
- _pageBounds.y = 0;
- this._pageLocation.Y = 0;
- _vScrollBar.setVisible(false);
- }
-
- if (pageWidth > this.getWidth()) {
- int sWidth = pageWidth - this.getWidth() + 40;
- _hScrollBar.setMinimum(0);
- _hScrollBar.setMaximum(pageWidth);
- _hScrollBar.setVisibleAmount(pageWidth - sWidth);
- _hScrollBar.setUnitIncrement(pageWidth / 10);
- _hScrollBar.setBlockIncrement(pageWidth / 5);
- if (this._hScrollBar.getHeight() == 0) {
- this._hScrollBar.setSize(this._hScrollBar.getWidth(), 21);
- }
-
- if (_hScrollBar.isVisible() == false) {
- _hScrollBar.setValue(0);
- _hScrollBar.setVisible(true);
- }
- } else {
- _pageBounds.x = 0;
- this._pageLocation.X = 0;
- _hScrollBar.setVisible(false);
- }
-
- //Draw bound rectangle
- Rectangle.Float aRect = pageToScreen(_pageBounds.x, _pageBounds.y, _pageBounds.width, _pageBounds.height);
- g.setColor(_pageBackColor);
- g.fill(aRect);
-
- //Draw layout elements
- paintGraphicsOnLayout(g);
- }
-
- public void paintGraphics() {
- if (this._lockViewUpdate) {
- return;
- }
-
- if (this.getWidth() < 10 || this.getHeight() < 10) {
- return;
- }
-
- if ((this._pageBounds.width < 2) || (this._pageBounds.height < 2)) {
- return;
- }
-
- _layoutBitmap = new BufferedImage(this.getWidth(),
- this.getHeight(), BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = _layoutBitmap.createGraphics();
- g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
-
- //Judge if show scroll bar
- int pageHeight = (int) (_pageBounds.height * _zoom);
- int pageWidth = (int) (_pageBounds.width * _zoom);
- if (pageHeight > this.getHeight()) {
- int sHeight = pageHeight - this.getHeight() + 40;
- _vScrollBar.setMinimum(0);
- _vScrollBar.setMaximum(pageHeight);
- _vScrollBar.setVisibleAmount(pageHeight - sHeight);
- _vScrollBar.setUnitIncrement(pageHeight / 10);
- _vScrollBar.setBlockIncrement(pageHeight / 5);
- if (_vScrollBar.getWidth() == 0) {
- _vScrollBar.setSize(21, this._vScrollBar.getHeight());
- }
-
- if (_vScrollBar.isVisible() == false) {
- _vScrollBar.setValue(0);
- _vScrollBar.setVisible(true);
- }
- } else {
- _pageBounds.y = 0;
- this._pageLocation.Y = 0;
- _vScrollBar.setVisible(false);
- }
-
- if (pageWidth > this.getWidth()) {
- int sWidth = pageWidth - this.getWidth() + 40;
- _hScrollBar.setMinimum(0);
- _hScrollBar.setMaximum(pageWidth);
- _hScrollBar.setVisibleAmount(pageWidth - sWidth);
- _hScrollBar.setUnitIncrement(pageWidth / 10);
- _hScrollBar.setBlockIncrement(pageWidth / 5);
- if (this._hScrollBar.getHeight() == 0) {
- this._hScrollBar.setSize(this._hScrollBar.getWidth(), 21);
- }
-
- if (_hScrollBar.isVisible() == false) {
- _hScrollBar.setValue(0);
- _hScrollBar.setVisible(true);
- }
- } else {
- _pageBounds.x = 0;
- this._pageLocation.X = 0;
- _hScrollBar.setVisible(false);
- }
-
- //Draw bound rectangle
- Rectangle.Float aRect = pageToScreen(_pageBounds.x, _pageBounds.y, _pageBounds.width, _pageBounds.height);
- g.setColor(_pageBackColor);
- g.fill(aRect);
-
- //Draw layout elements
- paintGraphicsOnLayout(g);
-
- g.dispose();
- this.repaint();
- }
-
- /**
- * Paint graphics on layout
- *
- * @param g Graphics2D
- */
- public void paintGraphicsOnLayout(Graphics2D g) {
- //g.SmoothingMode = _smoothingMode;
- //g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
-
- for (LayoutElement aElement : _layoutElements) {
- if (!aElement.isVisible()) {
- continue;
- }
-
- aElement.paintOnLayout(g, _pageLocation, _zoom);
- }
-
- //Draws the selection rectangle around each selected item
- for (LayoutElement aElement : _layoutElements) {
- if (!aElement.isVisible()) {
- continue;
- }
-
- if (aElement.isSelected()) {
- if (_mouseMode == MouseMode.EditVertices) {
- LayoutGraphic aLG = (LayoutGraphic) aElement;
- List points = (List) aLG.getGraphic().getShape().getPoints();
- drawSelectedVertices(g, points);
- } else {
- float[] dashPattern = new float[]{2.0F, 1.0F};
- Rectangle aRect = pageToScreen(aElement.getBounds());
- g.setColor(Color.cyan);
- g.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f));
- g.draw(aRect);
-
- switch (aElement.getResizeAbility()) {
- case SameWidthHeight:
- drawSelectedConers(g, aElement);
- break;
- case ResizeAll:
- drawSelectedConers(g, aElement);
- drawSelectedEdgeCenters(g, aElement);
- break;
- }
- }
- }
- }
- }
-
- /**
- * Paint graphics
- *
- * @param g Graphics2D
- */
- public void paintGraphics(Graphics2D g) {
- g.setColor(this._pageBackColor);
- g.fillRect(0, 0, _pageBounds.width, _pageBounds.height);
-
- for (LayoutElement aElement : _layoutElements) {
- if (!aElement.isVisible()) {
- continue;
- }
-
- //aElement.Paint(g);
- aElement.paintOnLayout(g, new PointF(0, 0), 1);
- }
- }
-
- private void drawSelectedConers(Graphics2D g, LayoutElement aElement) {
- Rectangle elementRect = pageToScreen(aElement.getBounds());
- int size = 6;
- Rectangle rect = new Rectangle(elementRect.x - size / 2, elementRect.y - size / 2, size, size);
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- rect.y = elementRect.y + elementRect.height - size / 2;
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- rect.x = elementRect.x + elementRect.width - size / 2;
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- rect.y = elementRect.y - size / 2;
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- }
-
- private void drawSelectedEdgeCenters(Graphics2D g, LayoutElement aElement) {
- Rectangle elementRect = pageToScreen(aElement.getBounds());
- int size = 6;
- Rectangle rect = new Rectangle(elementRect.x + elementRect.width / 2 - size / 2, elementRect.y - size / 2, size, size);
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- rect.y = elementRect.y + elementRect.height - size / 2;
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- rect.x = elementRect.x - size / 2;
- rect.y = elementRect.y + elementRect.height / 2 - size / 2;
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- rect.x = elementRect.x + elementRect.width - size / 2;
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- }
-
- private void drawSelectedVertices(Graphics2D g, List points) {
- int size = 6;
- Rectangle rect = new Rectangle(0, 0, size, size);
-
- for (PointD aPoint : points) {
- PointF aP = pageToScreen((float) aPoint.X, (float) aPoint.Y);
- rect.x = (int) aP.X - size / 2;
- rect.y = (int) aP.Y - size / 2;
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- }
- }
-
- /**
- * Export to a picture file
- *
- * @param aFile File path
- * @throws java.io.FileNotFoundException
- * @throws javax.print.PrintException
- */
- public void exportToPicture(String aFile) throws FileNotFoundException, PrintException, IOException {
- if (aFile.endsWith(".ps")) {
- DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
- String mimeType = "application/postscript";
- StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, mimeType);
- FileOutputStream out = new FileOutputStream(aFile);
- if (factories.length > 0) {
- PrintService service = factories[0].getPrintService(out);
- SimpleDoc doc = new SimpleDoc(new Printable() {
- @Override
- public int print(Graphics g, PageFormat pf, int page) {
- if (page >= 1) {
- return Printable.NO_SUCH_PAGE;
- } else {
- double sf1 = pf.getImageableWidth() / (_pageBounds.width + 1);
- double sf2 = pf.getImageableHeight() / (_pageBounds.height + 1);
- double s = Math.min(sf1, sf2);
- Graphics2D g2 = (Graphics2D) g;
- g2.translate((pf.getWidth() - pf.getImageableWidth()) / 2, (pf.getHeight() - pf.getImageableHeight()) / 2);
- g2.scale(s, s);
-
- paintGraphics(g2);
- return Printable.PAGE_EXISTS;
- }
- }
- }, flavor, null);
- DocPrintJob job = service.createPrintJob();
- PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
- job.print(doc, attributes);
- out.close();
- }
- } else if (aFile.endsWith(".eps")) {
- int width = this.getPaperWidth();
- int height = this.getPaperHeight();
-// EPSGraphics2D g = new EPSGraphics2D(0.0, 0.0, width, height);
-// paintGraphics(g);
-// FileOutputStream file = new FileOutputStream(aFile);
-// try {
-// file.write(g.getBytes());
-// } finally {
-// file.close();
-// g.dispose();
-// }
-
- Properties p = new Properties();
- p.setProperty("PageSize", "A5");
- VectorGraphics g = new PSGraphics2D(new File(aFile), new Dimension(width, height));
- //g.setProperties(p);
- g.startExport();
- this.paintGraphics(g);
- g.endExport();
- g.dispose();
- } else if (aFile.endsWith(".pdf")) {
- int width = this.getPaperWidth();
- int height = this.getPaperHeight();
- try {
- com.itextpdf.text.Document document = new com.itextpdf.text.Document(new com.itextpdf.text.Rectangle(width, height));
- PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(aFile));
- document.open();
- PdfContentByte cb = writer.getDirectContent();
- PdfTemplate pdfTemp = cb.createTemplate(width, height);
- Graphics2D g2 = new PdfGraphics2D(pdfTemp, width, height, true);
- this.paintGraphics(g2);
- g2.dispose();
- cb.addTemplate(pdfTemp, 0, 0);
- document.close();
- } catch (DocumentException | FileNotFoundException e) {
- e.printStackTrace();
- }
- } else if (aFile.endsWith(".emf")) {
- int width = this.getPaperWidth();
- int height = this.getPaperHeight();
- VectorGraphics g = new EMFGraphics2D(new File(aFile), new Dimension(width, height));
- //g.setProperties(p);
- g.startExport();
- this.paintGraphics(g);
- g.endExport();
- g.dispose();
- } else {
- String extension = aFile.substring(aFile.lastIndexOf('.') + 1);
- BufferedImage aImage;
- if (extension.equalsIgnoreCase("bmp"))
- aImage = new BufferedImage(_pageBounds.width, _pageBounds.height, BufferedImage.TYPE_INT_RGB);
- else
- aImage = new BufferedImage(_pageBounds.width, _pageBounds.height, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = aImage.createGraphics();
- paintGraphics(g);
- if (extension.equalsIgnoreCase("jpg")) {
- BufferedImage newImage = new BufferedImage(aImage.getWidth(), aImage.getHeight(), BufferedImage.TYPE_INT_RGB);
- newImage.createGraphics().drawImage(aImage, 0, 0, Color.BLACK, null);
- ImageIO.write(newImage, extension, new File(aFile));
- } else {
- ImageIO.write(aImage, extension, new File(aFile));
- }
- }
- }
-
- /**
- * Export to a picture file
- *
- * @param fileName File path
- * @param dpi DPI
- * @throws java.io.FileNotFoundException
- * @throws javax.print.PrintException
- */
- public void exportToPicture(String fileName, Integer dpi) throws FileNotFoundException, PrintException, IOException {
- if (dpi == null) {
- exportToPicture(fileName);
- } else {
- File output = new File(fileName);
- output.delete();
-
- int width = _pageBounds.width;
- int height = _pageBounds.height;
- String formatName = fileName.substring(fileName.lastIndexOf('.') + 1);
- if (formatName.equals("jpg")) {
- formatName = "jpeg";
- saveImage_Jpeg(fileName, width, height, dpi);
- return;
- }
-
- double scaleFactor = dpi / 72.0;
- BufferedImage image = new BufferedImage((int)(width * scaleFactor), (int)(height * scaleFactor), BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = image.createGraphics();
- AffineTransform at = g.getTransform();
- at.scale(scaleFactor, scaleFactor);
- g.setTransform(at);
- paintGraphics(g);
- for (Iterator iw = ImageIO.getImageWritersByFormatName(formatName); iw.hasNext();) {
- ImageWriter writer = iw.next();
- ImageWriteParam writeParam = writer.getDefaultWriteParam();
- ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_ARGB);
- IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);
- if (metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported()) {
- continue;
- }
-
- ImageUtil.setDPI(metadata, dpi);
-
- final ImageOutputStream stream = ImageIO.createImageOutputStream(output);
- try {
- writer.setOutput(stream);
- writer.write(metadata, new IIOImage(image, null, metadata), writeParam);
- } finally {
- stream.close();
- }
- break;
- }
- g.dispose();
- }
- }
-
- private boolean saveImage_Jpeg(String file, int width, int height, int dpi) {
- double scaleFactor = dpi / 72.0;
- BufferedImage bufferedImage = new BufferedImage((int)(width * scaleFactor), (int)(height * scaleFactor), BufferedImage.TYPE_INT_RGB);
- Graphics2D g = bufferedImage.createGraphics();
- AffineTransform at = g.getTransform();
- at.scale(scaleFactor, scaleFactor);
- g.setTransform(at);
- paintGraphics(g);
-
- try {
- // Image writer
- ImageWriter imageWriter = ImageIO.getImageWritersBySuffix("jpeg").next();
- ImageOutputStream ios = ImageIO.createImageOutputStream(new File(file));
- imageWriter.setOutput(ios);
-
- // Compression
- JPEGImageWriteParam jpegParams = (JPEGImageWriteParam) imageWriter.getDefaultWriteParam();
- jpegParams.setCompressionMode(JPEGImageWriteParam.MODE_EXPLICIT);
- jpegParams.setCompressionQuality(0.85f);
-
- // Metadata (dpi)
- IIOMetadata data = imageWriter.getDefaultImageMetadata(new ImageTypeSpecifier(bufferedImage), jpegParams);
- Element tree = (Element) data.getAsTree("javax_imageio_jpeg_image_1.0");
- Element jfif = (Element) tree.getElementsByTagName("app0JFIF").item(0);
- jfif.setAttribute("Xdensity", Integer.toString(dpi));
- jfif.setAttribute("Ydensity", Integer.toString(dpi));
- jfif.setAttribute("resUnits", "1"); // density is dots per inch
- data.setFromTree("javax_imageio_jpeg_image_1.0", tree);
-
- // Write and clean up
- imageWriter.write(null, new IIOImage(bufferedImage, null, data), jpegParams);
- ios.close();
- imageWriter.dispose();
- } catch (Exception e) {
- return false;
- }
- g.dispose();
-
- return true;
- }
-
- //
- //
-
- /**
- * Convert screen coordinate to page coordinate
- *
- * @param screenX Screen x
- * @param screenY Screen y
- * @return Page position
- */
- public Point screenToPage(int screenX, int screenY) {
- float x = (screenX - _pageLocation.X) / _zoom;
- float y = (screenY - _pageLocation.Y) / _zoom;
- return (new Point((int) x, (int) y));
- }
-
- /**
- * Convert screen coordinate to page coordinate
- *
- * @param screenX Screen x
- * @param screenY Screen y
- * @return Page position
- */
- public PointF screenToPage(float screenX, float screenY) {
- float x = (screenX - _pageLocation.X) / _zoom;
- float y = (screenY - _pageLocation.Y) / _zoom;
- return (new PointF(x, y));
- }
-
- private PointF pageToScreen(float pageX, float pageY) {
- float x = pageX * _zoom + _pageLocation.X;
- float y = pageY * _zoom + _pageLocation.Y;
- return (new PointF(x, y));
- }
-
- private Rectangle.Float pageToScreen(float pageX, float pageY, float pageW, float pageH) {
- PointF screenTL = pageToScreen(pageX, pageY);
- PointF screenBR = pageToScreen(pageX + pageW, pageY + pageH);
- return new Rectangle.Float(screenTL.X, screenTL.Y, screenBR.X - screenTL.X, screenBR.Y - screenTL.Y);
- }
-
- private Rectangle pageToScreen(Rectangle rect) {
- PointF screenTL = pageToScreen(rect.x, rect.y);
- PointF screenBR = pageToScreen(rect.x + rect.width, rect.y + rect.height);
- return new Rectangle((int) screenTL.X, (int) screenTL.Y, (int) (screenBR.X - screenTL.X), (int) (screenBR.Y - screenTL.Y));
- }
-
- private Rectangle.Float paperToScreen(Rectangle.Float paper) {
- return paperToScreen(paper.x, paper.y, paper.width, paper.height);
- }
-
- /**
- * Converts a rectangle in paper coordiants in 1/100 of an inch to screen
- * coordinants
- *
- * @param paperX Paper x
- * @param paperY Paper Y
- * @param paperW Paper width
- * @param paperH Paper height
- * @return Screen rectangle
- */
- private Rectangle.Float paperToScreen(float paperX, float paperY, float paperW, float paperH) {
- PointF screenTL = paperToScreen(paperX, paperY);
- PointF screenBR = paperToScreen(paperX + paperW, paperY + paperH);
- return new Rectangle.Float(screenTL.X, screenTL.Y, screenBR.X - screenTL.X, screenBR.Y - screenTL.Y);
- }
-
- /**
- * Converts between a point in paper coordinants in 1/100th of an inch to
- * screen coordinants
- *
- * @param paperX Paper x
- * @param paperY Paper y
- * @return Screen point
- */
- private PointF paperToScreen(float paperX, float paperY) {
- float screenX = (paperX / 100F * 96F * _zoom) + _pageLocation.X;
- float screenY = (paperY / 100F * 96F * _zoom) + _pageLocation.Y;
- return (new PointF(screenX, screenY));
- }
- //
- //
-
- /**
- * Update the order of the map frames
- */
- public void updateMapFrameOrder() {
- List lms = getLayoutMaps();
- for (int i = 0; i < lms.size(); i++) {
- lms.get(i).getMapFrame().setOrder(i);
- }
- }
-
- /**
- * Update map frames
- *
- * @param mapFrames The map frames
- */
- public void updateMapFrames(List mapFrames) {
- for (MapFrame mf : mapFrames) {
- boolean isNew = true;
- for (MapFrame aMF : _mapFrames) {
- if (mf == aMF) {
- isNew = false;
- break;
- }
- }
- if (isNew) {
- LayoutMap aLM = new LayoutMap(mf, this.tileLoadListener);
- addElement(aLM);
- }
- }
-
- for (int i = 0; i < _mapFrames.size(); i++) {
- MapFrame mf = _mapFrames.get(i);
- boolean isNew = true;
- for (MapFrame aMF : mapFrames) {
- if (mf == aMF) {
- isNew = false;
- break;
- }
- }
- if (isNew) {
- LayoutMap aLM = getLayoutMap(mf);
- if (aLM != null) {
- removeElement(aLM);
- i -= 1;
- }
- }
- }
-
- this.setMapFrames(mapFrames);
- }
-
- /**
- * Add a layout element
- *
- * @param aElement The layout element
- */
- public void addElement(LayoutElement aElement) {
- _layoutElements.add(aElement);
- if (aElement.getElementType() == ElementType.LayoutMap) {
- final LayoutMap aLM = (LayoutMap) aElement;
- aLM.addMapViewUpdatedListener(new IMapViewUpdatedListener() {
- @Override
- public void mapViewUpdatedEvent(MapViewUpdatedEvent event) {
- //if (aLM.getMapFrame().isFireMapViewUpdate()) {
- //paintGraphics();
- repaintNew();
- //}
- }
- });
- if (aLM.getMapFrame().isActive()) {
- _currentLayoutMap = aLM;
- }
- }
- }
-
- /**
- * Remove a layout element
- *
- * @param aElement The layout element
- */
- public void removeElement(LayoutElement aElement) {
- switch (aElement.getElementType()) {
- case LayoutMap:
- if (this.getLayoutMaps().size() == 1) {
- JOptionPane.showMessageDialog(this, "There is at least one layout map!");
- return;
- }
-
- LayoutMap aLM = (LayoutMap) aElement;
- for (int i = 0; i < _layoutElements.size(); i++) {
- LayoutElement aLE = _layoutElements.get(i);
- switch (aLE.getElementType()) {
- case LayoutLegend:
- if (((LayoutLegend) aLE).getLayoutMap() == aLM) {
- _layoutElements.remove(aLE);
- i -= 1;
- }
- break;
- case LayoutScaleBar:
- if (((LayoutScaleBar) aLE).getLayoutMap() == aLM) {
- _layoutElements.remove(aLE);
- i -= 1;
- }
- break;
- case LayoutNorthArraw:
- if (((LayoutNorthArrow) aLE).getLayoutMap() == aLM) {
- _layoutElements.remove(aLE);
- i -= 1;
- }
- break;
- }
- }
- _mapFrames.remove(aLM.getMapFrame());
- _layoutElements.remove(aElement);
- if (_mapFrames.size() > 0) {
- setActiveMapFrame(_mapFrames.get(0));
- }
- this.fireMapFramesUpdatedEvent();
- break;
- default:
- _layoutElements.remove(aElement);
- break;
- }
-// if (this._selectedElements.contains(aElement)){
-// this._selectedElements.remove(aElement);
-// }
- }
-
- /**
- * Add a text label element
- *
- * @param text The text
- * @param x Center x
- * @param y Center y
- * @return Text layout graphic
- */
- public LayoutGraphic addText(String text, int x, int y) {
- return addText(text, x, y, _defLabelBreak.getFont().getFontName(), _defLabelBreak.getFont().getSize());
- }
-
- /**
- * Add a text label element
- *
- * @param text The text
- * @param x Center x
- * @param y Center y
- * @param fontSize Font size
- * @return Text layout graphic
- */
- public LayoutGraphic addText(String text, int x, int y, float fontSize) {
- return addText(text, x, y, _defLabelBreak.getFont().getName(), fontSize);
- }
-
- /**
- * Add a text label element
- *
- * @param text The text
- * @param x Center x
- * @param y Center y
- * @param fontName Font name
- * @param fontSize Font size
- * @return Text layout graphic
- */
- public LayoutGraphic addText(String text, int x, int y, String fontName, float fontSize) {
- PointShape aPS = new PointShape();
- aPS.setPoint(new PointD(x, y));
- LabelBreak aLB = (LabelBreak) _defLabelBreak.clone();
- aLB.setText(text);
- aLB.setFont(new Font(fontName, Font.PLAIN, (int) fontSize));
- Graphic aGraphic = new Graphic(aPS, aLB);
- LayoutGraphic aLayoutGraphic = new LayoutGraphic(aGraphic, this);
- addElement(aLayoutGraphic);
-
- return aLayoutGraphic;
- }
-
- public LayoutGraphic addWindArrow(int left, int top) {
- WindArrow aWindArraw = new WindArrow();
- //aWindArraw.setPoint(new PointD(left, top));
- aWindArraw.angle = 270;
- aWindArraw.length = 20;
- VectorBreak aVB = new VectorBreak();
- aVB.setColor(Color.black);
- LayoutGraphic wag = new LayoutGraphic(new Graphic(aWindArraw, aVB), this,
- this.getActiveLayoutMap());
- wag.setLeft(left);
- wag.setTop(top);
- addElement(wag);
-
- return wag;
- }
-
- /**
- * Add a layout legend
- *
- * @param left Left
- * @param top Top
- * @return Layout legend
- */
- public LayoutLegend addLegend(int left, int top) {
- LayoutMap aLM = getActiveLayoutMap();
- LayoutLegend aLL = new LayoutLegend(this, aLM);
- aLL.setLeft(left);
- aLL.setTop(top);
- if (aLM.getMapFrame().getMapView().getLayerNum() > 0) {
- for (MapLayer aLayer : aLM.getMapFrame().getMapView().getLayers()) {
- if (aLayer.getLayerType() != LayerTypes.ImageLayer) {
- aLL.setLegendLayer(aLayer);
- }
- }
- }
-
- addElement(aLL);
-
- return aLL;
- }
-
- /**
- * Add a layout scale bar
- *
- * @param left Left
- * @param top Top
- * @return Layout scale bar
- */
- public LayoutScaleBar addScaleBar(int left, int top) {
- LayoutMap aLM = getActiveLayoutMap();
- LayoutScaleBar aLSB = new LayoutScaleBar(aLM);
- aLSB.setLeft(left);
- aLSB.setTop(top);
- addElement(aLSB);
-
- return aLSB;
- }
-
- /**
- * Add a layout north arrow
- *
- * @param left Left
- * @param top Top
- * @return Layout north arrow
- */
- public LayoutNorthArrow addNorthArrow(int left, int top) {
- LayoutMap aLM = getActiveLayoutMap();
- LayoutNorthArrow aLNA = new LayoutNorthArrow(aLM);
- aLNA.setLeft(left);
- aLNA.setTop(top);
- addElement(aLNA);
-
- return aLNA;
- }
-
- /**
- * Add a layout chart
- *
- * @param left Left
- * @param top Top
- * @return Layout chart
- */
- public LayoutChart addChart(int left, int top) {
- LayoutChart chart = new LayoutChart();
- chart.setLeft(left);
- chart.setTop(top);
- addElement(chart);
-
- return chart;
- }
-
- /**
- * Get layout graphic list
- *
- * @return Layout graphic list
- */
- public List getLayoutGraphics() {
- List graphics = new ArrayList<>();
- for (LayoutElement aLE : _layoutElements) {
- if (aLE.getElementType() == ElementType.LayoutGraphic) {
- graphics.add((LayoutGraphic) aLE);
- }
- }
-
- return graphics;
- }
-
- /**
- * Get text graphic list
- *
- * @return Text graphic list
- */
- public List getTexts() {
- List texts = new ArrayList<>();
- List graphics = getLayoutGraphics();
- for (LayoutGraphic aLG : graphics) {
- if (aLG.getGraphic().getLegend().getBreakType() == BreakTypes.LabelBreak) {
- texts.add(aLG);
- }
- }
-
- return texts;
- }
-
- /**
- * Get a text graphic by text string
- *
- * @param text Text string
- * @return Text graphic
- */
- public LayoutGraphic getText(String text) {
- List texts = getTexts();
- for (LayoutGraphic aLG : texts) {
- if (((LabelBreak) aLG.getGraphic().getLegend()).getText().equals(text)) {
- return aLG;
- }
- }
-
- return null;
- }
-
- /**
- * Get layout legend list
- *
- * @return Layout legend list
- */
- public List getLegends() {
- List legends = new ArrayList<>();
- for (LayoutElement aLE : _layoutElements) {
- if (aLE.getElementType() == ElementType.LayoutLegend) {
- legends.add((LayoutLegend) aLE);
- }
- }
-
- return legends;
- }
-
- /**
- * Set a map frame as active
- *
- * @param mapFrame The map frame
- */
- public void setActiveMapFrame(MapFrame mapFrame) {
- for (MapFrame mf : _mapFrames) {
- mf.setActive(false);
- }
-
- mapFrame.setActive(true);
- this.fireActiveMapFrameChangedEvent();
- }
-
- private LayoutMap getLayoutMap(MapFrame mapFrame) {
- LayoutMap aLM = null;
- for (LayoutMap lm : this.getLayoutMaps()) {
- if (lm.getMapFrame() == mapFrame) {
- aLM = lm;
- break;
- }
- }
-
- return aLM;
- }
-
- private LayoutMap getLayoutMap(Point aPoint) {
- for (int i = getLayoutMaps().size() - 1; i >= 0; i--) {
- LayoutMap aLM = getLayoutMaps().get(i);
- if (MIMath.pointInRectangle(aPoint, aLM.getBounds())) {
- return aLM;
- }
- }
-
- return null;
- }
-
- private int getLayoutMapIndex(LayoutMap aLM) {
- return getLayoutMaps().indexOf(aLM);
- }
-
- /**
- * If has legend element
- *
- * @return Boolean
- */
- public boolean hasLegendElement() {
- for (LayoutElement aLE : _layoutElements) {
- if (aLE.getElementType() == ElementType.LayoutLegend) {
- return true;
- }
- }
- return false;
- }
-
- private List selectElements(Point aPoint, List baseElements, int limit) {
- List selectedElements = new ArrayList<>();
- for (int i = baseElements.size() - 1; i >= 0; i--) {
- LayoutElement element = baseElements.get(i);
- if (element.isVisible()) {
- Rectangle rect = (Rectangle) element.getBounds().clone();
- if (rect.width < 5) {
- rect.width = 5;
- rect.x -= 2.5;
- }
- if (rect.height < 5) {
- rect.height = 5;
- rect.y -= 2.5;
- }
- rect.width += limit;
- rect.height += limit;
- if (MIMath.pointInRectangle(aPoint, rect)) {
- selectedElements.add(element);
- }
- }
- }
-
- return selectedElements;
- }
-
- private Rectangle getElementViewExtent(LayoutElement aLE) {
- PointF aP = aLE.pageToScreen(aLE.getLeft(), aLE.getTop(), _pageLocation, _zoom);
- Rectangle rect = new Rectangle((int) aP.X, (int) aP.Y, (int) (aLE.getWidth() * _zoom), (int) (aLE.getHeight() * _zoom));
-
- return rect;
- }
-
- private int selectEditVertices(Point aPoint, org.meteoinfo.geometry.shape.Shape aShape, List vertices) {
- List points = (List) aShape.getPoints();
- int buffer = 4;
- Rectangle rect = new Rectangle(aPoint.x - buffer / 2, aPoint.y - buffer / 2, buffer, buffer);
- vertices.clear();
- PointD aPD;
- int vIdx = -1;
- for (int i = 0; i < points.size(); i++) {
- if (MIMath.pointInRectangle(points.get(i), rect)) {
- vIdx = i;
- vertices.add(points.get(i));
- switch (aShape.getShapeType()) {
- case Polyline:
- case CurveLine:
- if (i == 0) {
- vertices.add(points.get(i + 1));
- } else if (i == points.size() - 1) {
- vertices.add(points.get(i - 1));
- } else {
- vertices.add(points.get(i - 1));
- vertices.add(points.get(i + 1));
- }
- break;
- default:
- if (i == 0) {
- vertices.add(points.get(i + 1));
- aPD = points.get(points.size() - 1);
- if (aPD.X == points.get(i).X && aPD.Y == points.get(i).Y) {
- vertices.add(points.get(points.size() - 2));
- } else {
- vertices.add(aPD);
- }
- } else if (i == points.size() - 1) {
- vertices.add(points.get(i - 1));
- aPD = points.get(0);
- if (aPD.X == points.get(i).X && aPD.Y == points.get(i).Y) {
- vertices.add(points.get(1));
- } else {
- vertices.add(points.get(0));
- }
- } else {
- vertices.add(points.get(i - 1));
- vertices.add(points.get(i + 1));
- }
- break;
- }
- break;
-// if (aShape.getShapeType() == ShapeTypes.Polyline) {
-// if (i == 0) {
-// vertices.add(points.get(i + 1));
-// } else if (i == points.size() - 1) {
-// vertices.add(points.get(i - 1));
-// } else {
-// vertices.add(points.get(i - 1));
-// vertices.add(points.get(i + 1));
-// }
-// } else {
-// if (i == 0) {
-// vertices.add(points.get(i + 1));
-// aPD = points.get(points.size() - 1);
-// if (aPD.X == points.get(i).X && aPD.Y == points.get(i).Y) {
-// vertices.add(points.get(points.size() - 2));
-// } else {
-// vertices.add(aPD);
-// }
-// } else if (i == points.size() - 1) {
-// vertices.add(points.get(i - 1));
-// aPD = points.get(0);
-// if (aPD.X == points.get(i).X && aPD.Y == points.get(i).Y) {
-// vertices.add(points.get(1));
-// } else {
-// vertices.add(points.get(0));
-// }
-// } else {
-// vertices.add(points.get(i - 1));
-// vertices.add(points.get(i + 1));
-// }
-// }
- }
- }
-
- return vIdx;
- }
-
- private boolean isInLayoutMaps(Point aPoint) {
- for (LayoutMap aLM : getLayoutMaps()) {
- if (MIMath.pointInRectangle(aPoint, aLM.getBounds())) {
- return true;
- }
- }
-
- return false;
- }
-
- private static Edge intersectElementEdge(Rectangle screen, PointF pt, float limit) {
- Rectangle.Float ptRect = new Rectangle.Float(pt.X - limit, pt.Y - limit, 2F * limit, 2F * limit);
- if ((pt.X >= screen.x - limit && pt.X <= screen.x + limit) && (pt.Y >= screen.y - limit && pt.Y <= screen.y + limit)) {
- return Edge.TopLeft;
- }
- if ((pt.X >= screen.x + screen.width - limit && pt.X <= screen.x + screen.width + limit) && (pt.Y >= screen.y - limit && pt.Y <= screen.y + limit)) {
- return Edge.TopRight;
- }
- if ((pt.X >= screen.x + screen.width - limit && pt.X <= screen.x + screen.width + limit) && (pt.Y >= screen.y + screen.height - limit && pt.Y <= screen.y + screen.height + limit)) {
- return Edge.BottomRight;
- }
- if ((pt.X >= screen.x - limit && pt.X <= screen.x + limit) && (pt.Y >= screen.y + screen.height - limit && pt.Y <= screen.y + screen.height + limit)) {
- return Edge.BottomLeft;
- }
- if (ptRect.intersects(new Rectangle.Float(screen.x, screen.y, screen.width, 1F))) {
- return Edge.Top;
- }
- if (ptRect.intersects(new Rectangle.Float(screen.x, screen.y, 1F, screen.height))) {
- return Edge.Left;
- }
- if (ptRect.intersects(new Rectangle.Float(screen.x, screen.y + screen.height, screen.width, 1F))) {
- return Edge.Bottom;
- }
- if (ptRect.intersects(new Rectangle.Float(screen.x + screen.width, screen.y, 1F, screen.height))) {
- return Edge.Right;
- }
- return Edge.None;
- }
- //
-
- //
- private void updatePageSet() {
- Rectangle.Float aRect = paperToScreen(new Rectangle.Float(0, 0, this.getPaperWidth(), this.getPaperHeight()));
- _pageBounds.width = (int) aRect.width;
- _pageBounds.height = (int) aRect.height;
- }
-
- /**
- * Show measurment form
- */
- public void showMeasurementForm() {
- if (_frmMeasure == null) {
- _frmMeasure = new FrmMeasurement((JFrame) SwingUtilities.getWindowAncestor(this), false);
- _frmMeasure.addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosed(WindowEvent e) {
- _currentLayoutMap.getMapFrame().getMapView().setDrawIdentiferShape(false);
- //repaint();
- repaintOld();
- }
- });
- _frmMeasure.setLocationRelativeTo(this);
- _frmMeasure.setVisible(true);
- } else if (!_frmMeasure.isVisible()) {
- _frmMeasure.setVisible(true);
- }
- }
-
- //
- //
- /**
- * Export project XML content
- *
- * @param m_Doc XML document
- * @param parent Parent XML element
- */
- public void exportProjectXML(Document m_Doc, Element parent) {
- exportLayout(m_Doc, parent);
- }
-
- private void exportLayout(Document m_Doc, Element parent) {
- Element layout = m_Doc.createElement("Layout");
-
- //Add attribute
- Attr BackColor = m_Doc.createAttribute("BackColor");
- Attr ForeColor = m_Doc.createAttribute("ForeColor");
- Attr SmoothingMode = m_Doc.createAttribute("SmoothingMode");
- Attr PaperSizeName = m_Doc.createAttribute("PaperSizeName");
- Attr PaperSizeWidth = m_Doc.createAttribute("PaperSizeWidth");
- Attr PaperSizeHeight = m_Doc.createAttribute("PaperSizeHeight");
- Attr Landscape = m_Doc.createAttribute("Landscape");
-
- BackColor.setValue(ColorUtil.toHexEncoding(_pageBackColor));
- ForeColor.setValue(ColorUtil.toHexEncoding(_pageForeColor));
- SmoothingMode.setValue(String.valueOf(_antiAlias));
- PaperSizeName.setValue(_paperSize.getName());
- PaperSizeWidth.setValue(String.valueOf(_paperSize.getWidth()));
- PaperSizeHeight.setValue(String.valueOf(_paperSize.getHeight()));
- Landscape.setValue(String.valueOf(_isLandscape));
-
- layout.setAttributeNode(BackColor);
- layout.setAttributeNode(ForeColor);
- layout.setAttributeNode(SmoothingMode);
- layout.setAttributeNode(PaperSizeName);
- layout.setAttributeNode(PaperSizeWidth);
- layout.setAttributeNode(PaperSizeHeight);
- layout.setAttributeNode(Landscape);
-
- parent.appendChild(layout);
-
- //Add layout elements
- addLayoutElements(m_Doc, layout);
- }
-
- private void addLayoutElements(Document doc, Element parent) {
- Element layoutElements = doc.createElement("LayoutElements");
- for (LayoutElement aElement : _layoutElements) {
- switch (aElement.getElementType()) {
- case LayoutMap:
- addLayoutMapElement(doc, layoutElements, (LayoutMap) aElement);
- break;
- case LayoutIllustration:
- //AddIllustrationElement(ref doc, layoutElements, (LayoutIllustrationMap)aElement);
- break;
- case LayoutLegend:
- addLayoutLegendElement(doc, layoutElements, (LayoutLegend) aElement);
- break;
- case LayoutGraphic:
- addLayoutGraphicElement(doc, layoutElements, (LayoutGraphic) aElement);
- break;
- case LayoutScaleBar:
- addLayoutScaleBarElement(doc, layoutElements, (LayoutScaleBar) aElement);
- break;
- case LayoutNorthArraw:
- addLayoutNorthArrowElement(doc, layoutElements, (LayoutNorthArrow) aElement);
- break;
- }
- }
- parent.appendChild(layoutElements);
- }
-
- private void addLayoutMapElement(Document m_Doc, Element parent, LayoutMap aMap) {
- Element layoutMap = m_Doc.createElement("LayoutMap");
- Attr elementType = m_Doc.createAttribute("ElementType");
- Attr left = m_Doc.createAttribute("Left");
- Attr top = m_Doc.createAttribute("Top");
- Attr width = m_Doc.createAttribute("Width");
- Attr height = m_Doc.createAttribute("Height");
- Attr DrawMapNeatLine = m_Doc.createAttribute("DrawNeatLine");
- Attr MapNeatLineColor = m_Doc.createAttribute("NeatLineColor");
- Attr MapNeatLineSize = m_Doc.createAttribute("NeatLineSize");
- Attr GridLineColor = m_Doc.createAttribute("GridLineColor");
- Attr GridLineSize = m_Doc.createAttribute("GridLineSize");
- Attr GridLineStyle = m_Doc.createAttribute("GridLineStyle");
- Attr DrawGridLine = m_Doc.createAttribute("DrawGridLine");
- Attr DrawGridLabel = m_Doc.createAttribute("DrawGridLabel");
- Attr GridFontName = m_Doc.createAttribute("GridFontName");
- Attr GridFontSize = m_Doc.createAttribute("GridFontSize");
- Attr GridXDelt = m_Doc.createAttribute("GridXDelt");
- Attr GridYDelt = m_Doc.createAttribute("GridYDelt");
- Attr GridXOrigin = m_Doc.createAttribute("GridXOrigin");
- Attr GridYOrigin = m_Doc.createAttribute("GridYOrigin");
- Attr gridLabelPosition = m_Doc.createAttribute("GridLabelPosition");
- Attr drawDegreeSymbol = m_Doc.createAttribute("DrawDegreeSymbol");
- Attr drawBackColor = m_Doc.createAttribute("DrawBackColor");
-
- elementType.setValue(aMap.getElementType().toString());
- left.setValue(String.valueOf(aMap.getLeft()));
- top.setValue(String.valueOf(aMap.getTop()));
- width.setValue(String.valueOf(aMap.getWidth()));
- height.setValue(String.valueOf(aMap.getHeight()));
- DrawMapNeatLine.setValue(String.valueOf(aMap.isDrawNeatLine()));
- MapNeatLineColor.setValue(ColorUtil.toHexEncoding(aMap.getNeatLineColor()));
- MapNeatLineSize.setValue(String.valueOf(aMap.getNeatLineSize()));
- GridLineColor.setValue(ColorUtil.toHexEncoding(aMap.getGridLineColor()));
- GridLineSize.setValue(String.valueOf(aMap.getGridLineSize()));
- GridLineStyle.setValue(aMap.getGridLineStyle().toString());
- DrawGridLine.setValue(String.valueOf(aMap.isDrawGridLine()));
- DrawGridLabel.setValue(String.valueOf(aMap.isDrawGridLabel()));
- GridFontName.setValue(aMap.getGridFont().getFontName());
- GridFontSize.setValue(String.valueOf(aMap.getGridFont().getSize()));
- GridXDelt.setValue(String.valueOf(aMap.getGridXDelt()));
- GridYDelt.setValue(String.valueOf(aMap.getGridYDelt()));
- GridXOrigin.setValue(String.valueOf(aMap.getGridXOrigin()));
- GridYOrigin.setValue(String.valueOf(aMap.getGridYOrigin()));
- gridLabelPosition.setValue(aMap.getGridLabelPosition().toString());
- drawDegreeSymbol.setValue(String.valueOf(aMap.isDrawDegreeSymbol()));
- drawBackColor.setValue(String.valueOf(aMap.isDrawBackColor()));
-
- layoutMap.setAttributeNode(elementType);
- layoutMap.setAttributeNode(left);
- layoutMap.setAttributeNode(top);
- layoutMap.setAttributeNode(width);
- layoutMap.setAttributeNode(height);
- layoutMap.setAttributeNode(DrawMapNeatLine);
- layoutMap.setAttributeNode(MapNeatLineColor);
- layoutMap.setAttributeNode(MapNeatLineSize);
- layoutMap.setAttributeNode(GridLineColor);
- layoutMap.setAttributeNode(GridLineSize);
- layoutMap.setAttributeNode(GridLineStyle);
- layoutMap.setAttributeNode(DrawGridLine);
- layoutMap.setAttributeNode(DrawGridLabel);
- layoutMap.setAttributeNode(GridFontName);
- layoutMap.setAttributeNode(GridFontSize);
- layoutMap.setAttributeNode(GridXDelt);
- layoutMap.setAttributeNode(GridYDelt);
- layoutMap.setAttributeNode(GridXOrigin);
- layoutMap.setAttributeNode(GridYOrigin);
- layoutMap.setAttributeNode(gridLabelPosition);
- layoutMap.setAttributeNode(drawDegreeSymbol);
- layoutMap.setAttributeNode(drawBackColor);
-
- parent.appendChild(layoutMap);
- }
-
- private void addLayoutLegendElement(Document doc, Element parent, LayoutLegend aLegend) {
- Element Legend = doc.createElement("LayoutLegend");
- Attr elementType = doc.createAttribute("ElementType");
- Attr layoutMapIndex = doc.createAttribute("LayoutMapIndex");
- Attr legendLayer = doc.createAttribute("LegendLayer");
- Attr LegendStyle = doc.createAttribute("LegendStyle");
- Attr layerUpdateType = doc.createAttribute("LayerUpdateType");
- Attr BackColor = doc.createAttribute("BackColor");
- Attr DrawNeatLine = doc.createAttribute("DrawNeatLine");
- Attr NeatLineColor = doc.createAttribute("NeatLineColor");
- Attr NeatLineSize = doc.createAttribute("NeatLineSize");
- Attr drawChartBreaks = doc.createAttribute("DrawChartBreaks");
- Attr Left = doc.createAttribute("Left");
- Attr Top = doc.createAttribute("Top");
- Attr Width = doc.createAttribute("Width");
- Attr Height = doc.createAttribute("Height");
- Attr FontName = doc.createAttribute("FontName");
- Attr FontSize = doc.createAttribute("FontSize");
- Attr colNum = doc.createAttribute("ColumnNumber");
- Attr drawBackColor = doc.createAttribute("DrawBackColor");
- Attr forceDrawOutline = doc.createAttribute("ForceDrawOutline");
-
- elementType.setValue(aLegend.getElementType().toString());
- layoutMapIndex.setValue(String.valueOf(getLayoutMapIndex(aLegend.getLayoutMap())));
- legendLayer.setValue(aLegend.getLayerName());
- LegendStyle.setValue(aLegend.getLegendStyle().toString());
- layerUpdateType.setValue(aLegend.getLayerUpdateType().toString());
- BackColor.setValue(ColorUtil.toHexEncoding(aLegend.getBackColor()));
- DrawNeatLine.setValue(String.valueOf(aLegend.isDrawNeatLine()));
- NeatLineColor.setValue(ColorUtil.toHexEncoding(aLegend.getNeatLineColor()));
- NeatLineSize.setValue(String.valueOf(aLegend.getNeatLineSize()));
- drawChartBreaks.setValue(String.valueOf(aLegend.isDrawChartBreaks()));
- Left.setValue(String.valueOf(aLegend.getLeft()));
- Top.setValue(String.valueOf(aLegend.getTop()));
- Width.setValue(String.valueOf(aLegend.getWidth()));
- Height.setValue(String.valueOf(aLegend.getHeight()));
- FontName.setValue(aLegend.getFont().getFontName());
- FontSize.setValue(String.valueOf(aLegend.getFont().getSize()));
- colNum.setValue(String.valueOf(aLegend.getColumnNumber()));
- drawBackColor.setValue(String.valueOf(aLegend.isDrawBackColor()));
- forceDrawOutline.setValue(String.valueOf(aLegend.isForceDrawOutline()));
-
- Legend.setAttributeNode(elementType);
- Legend.setAttributeNode(layoutMapIndex);
- Legend.setAttributeNode(legendLayer);
- Legend.setAttributeNode(LegendStyle);
- Legend.setAttributeNode(layerUpdateType);
- Legend.setAttributeNode(BackColor);
- Legend.setAttributeNode(DrawNeatLine);
- Legend.setAttributeNode(NeatLineColor);
- Legend.setAttributeNode(NeatLineSize);
- Legend.setAttributeNode(drawChartBreaks);
- Legend.setAttributeNode(Left);
- Legend.setAttributeNode(Top);
- Legend.setAttributeNode(Width);
- Legend.setAttributeNode(Height);
- Legend.setAttributeNode(FontName);
- Legend.setAttributeNode(FontSize);
- Legend.setAttributeNode(colNum);
- Legend.setAttributeNode(drawBackColor);
- Legend.setAttributeNode(forceDrawOutline);
-
- parent.appendChild(Legend);
- }
-
- private void addLayoutScaleBarElement(Document doc, Element parent, LayoutScaleBar aScaleBar) {
- Element scaleBar = doc.createElement("LayoutScaleBar");
- Attr elementType = doc.createAttribute("ElementType");
- Attr layoutMapIndex = doc.createAttribute("LayoutMapIndex");
- Attr scaleBarType = doc.createAttribute("ScaleBarType");
- Attr BackColor = doc.createAttribute("BackColor");
- Attr foreColor = doc.createAttribute("ForeColor");
- Attr DrawNeatLine = doc.createAttribute("DrawNeatLine");
- Attr NeatLineColor = doc.createAttribute("NeatLineColor");
- Attr NeatLineSize = doc.createAttribute("NeatLineSize");
- Attr Left = doc.createAttribute("Left");
- Attr Top = doc.createAttribute("Top");
- Attr Width = doc.createAttribute("Width");
- Attr Height = doc.createAttribute("Height");
- Attr FontName = doc.createAttribute("FontName");
- Attr FontSize = doc.createAttribute("FontSize");
- Attr drawScaleText = doc.createAttribute("DrawScaleText");
- Attr drawBackColor = doc.createAttribute("DrawBackColor");
-
- elementType.setValue(aScaleBar.getElementType().toString());
- layoutMapIndex.setValue(String.valueOf(getLayoutMapIndex(aScaleBar.getLayoutMap())));
- scaleBarType.setValue(aScaleBar.getScaleBarType().toString());
- BackColor.setValue(ColorUtil.toHexEncoding(aScaleBar.getBackColor()));
- foreColor.setValue(ColorUtil.toHexEncoding(aScaleBar.getForeColor()));
- DrawNeatLine.setValue(String.valueOf(aScaleBar.isDrawNeatLine()));
- NeatLineColor.setValue(ColorUtil.toHexEncoding(aScaleBar.getNeatLineColor()));
- NeatLineSize.setValue(String.valueOf(aScaleBar.getNeatLineSize()));
- Left.setValue(String.valueOf(aScaleBar.getLeft()));
- Top.setValue(String.valueOf(aScaleBar.getTop()));
- Width.setValue(String.valueOf(aScaleBar.getWidth()));
- Height.setValue(String.valueOf(aScaleBar.getHeight()));
- FontName.setValue(aScaleBar.getFont().getFontName());
- FontSize.setValue(String.valueOf(aScaleBar.getFont().getSize()));
- drawScaleText.setValue(String.valueOf(aScaleBar.isDrawScaleText()));
- drawBackColor.setValue(String.valueOf(aScaleBar.isDrawBackColor()));
-
- scaleBar.setAttributeNode(elementType);
- scaleBar.setAttributeNode(layoutMapIndex);
- scaleBar.setAttributeNode(scaleBarType);
- scaleBar.setAttributeNode(BackColor);
- scaleBar.setAttributeNode(foreColor);
- scaleBar.setAttributeNode(DrawNeatLine);
- scaleBar.setAttributeNode(NeatLineColor);
- scaleBar.setAttributeNode(NeatLineSize);
- scaleBar.setAttributeNode(Left);
- scaleBar.setAttributeNode(Top);
- scaleBar.setAttributeNode(Width);
- scaleBar.setAttributeNode(Height);
- scaleBar.setAttributeNode(FontName);
- scaleBar.setAttributeNode(FontSize);
- scaleBar.setAttributeNode(drawScaleText);
- scaleBar.setAttributeNode(drawBackColor);
-
- parent.appendChild(scaleBar);
- }
-
- private void addLayoutNorthArrowElement(Document doc, Element parent, LayoutNorthArrow aNorthArrow) {
- Element northArrow = doc.createElement("LayoutNorthArrow");
- Attr elementType = doc.createAttribute("ElementType");
- Attr layoutMapIndex = doc.createAttribute("LayoutMapIndex");
- Attr BackColor = doc.createAttribute("BackColor");
- Attr foreColor = doc.createAttribute("ForeColor");
- Attr DrawNeatLine = doc.createAttribute("DrawNeatLine");
- Attr NeatLineColor = doc.createAttribute("NeatLineColor");
- Attr NeatLineSize = doc.createAttribute("NeatLineSize");
- Attr Left = doc.createAttribute("Left");
- Attr Top = doc.createAttribute("Top");
- Attr Width = doc.createAttribute("Width");
- Attr Height = doc.createAttribute("Height");
- Attr angle = doc.createAttribute("Angle");
- Attr drawBackColor = doc.createAttribute("DrawBackColor");
-
- elementType.setValue(aNorthArrow.getElementType().toString());
- layoutMapIndex.setValue(String.valueOf(getLayoutMapIndex(aNorthArrow.getLayoutMap())));
- BackColor.setValue(ColorUtil.toHexEncoding(aNorthArrow.getBackColor()));
- foreColor.setValue(ColorUtil.toHexEncoding(aNorthArrow.getForeColor()));
- DrawNeatLine.setValue(String.valueOf(aNorthArrow.isDrawNeatLine()));
- NeatLineColor.setValue(ColorUtil.toHexEncoding(aNorthArrow.getNeatLineColor()));
- NeatLineSize.setValue(String.valueOf(aNorthArrow.getNeatLineSize()));
- Left.setValue(String.valueOf(aNorthArrow.getLeft()));
- Top.setValue(String.valueOf(aNorthArrow.getTop()));
- Width.setValue(String.valueOf(aNorthArrow.getWidth()));
- Height.setValue(String.valueOf(aNorthArrow.getHeight()));
- angle.setValue(String.valueOf(aNorthArrow.getAngle()));
- drawBackColor.setValue(String.valueOf(aNorthArrow.isDrawBackColor()));
-
- northArrow.setAttributeNode(elementType);
- northArrow.setAttributeNode(layoutMapIndex);
- northArrow.setAttributeNode(BackColor);
- northArrow.setAttributeNode(foreColor);
- northArrow.setAttributeNode(DrawNeatLine);
- northArrow.setAttributeNode(NeatLineColor);
- northArrow.setAttributeNode(NeatLineSize);
- northArrow.setAttributeNode(Left);
- northArrow.setAttributeNode(Top);
- northArrow.setAttributeNode(Width);
- northArrow.setAttributeNode(Height);
- northArrow.setAttributeNode(angle);
- northArrow.setAttributeNode(drawBackColor);
-
- parent.appendChild(northArrow);
- }
-
- private void addLayoutGraphicElement(Document doc, Element parent, LayoutGraphic aLayoutGraphic) {
- Element layoutGraphic = doc.createElement("LayoutGraphic");
- Attr elementType = doc.createAttribute("ElementType");
- Attr isTitle = doc.createAttribute("IsTitle");
- Attr left = doc.createAttribute("Left");
- Attr top = doc.createAttribute("Top");
- Attr width = doc.createAttribute("Width");
- Attr height = doc.createAttribute("Height");
-
- elementType.setValue(aLayoutGraphic.getElementType().toString());
- isTitle.setValue(String.valueOf(aLayoutGraphic.isTitle()));
- left.setValue(String.valueOf(aLayoutGraphic.getLeft()));
- top.setValue(String.valueOf(aLayoutGraphic.getTop()));
- width.setValue(String.valueOf(aLayoutGraphic.getWidth()));
- height.setValue(String.valueOf(aLayoutGraphic.getHeight()));
-
- layoutGraphic.setAttributeNode(elementType);
- layoutGraphic.setAttributeNode(isTitle);
- layoutGraphic.setAttributeNode(left);
- layoutGraphic.setAttributeNode(top);
- layoutGraphic.setAttributeNode(width);
- layoutGraphic.setAttributeNode(height);
-
- //Add graphic
- Graphic aGraphic = aLayoutGraphic.getGraphic();
- aGraphic.exportToXML(doc, layoutGraphic);
-
- //Append in parent
- parent.appendChild(layoutGraphic);
- }
-
- /**
- * Load project file
- *
- * @param aFile The project file
- * @throws javax.xml.parsers.ParserConfigurationException
- * @throws org.xml.sax.SAXException
- * @throws java.io.IOException
- */
- public void loadProjectFile(String aFile) throws ParserConfigurationException, SAXException, IOException {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document doc = db.parse(aFile);
-
- Element root = doc.getDocumentElement();
-
- Properties property = System.getProperties();
- String path = System.getProperty("user.dir");
- property.setProperty("user.dir", new File(aFile).getAbsolutePath());
- String pPath = new File(aFile).getParent();
-
- //Load map frames content
- List mfs = new ArrayList<>();
- Element mapFrames = (Element) root.getElementsByTagName("MapFrames").item(0);
- if (mapFrames == null) {
- MapFrame mf = new MapFrame();
- mf.importProjectXML(pPath, root);
- mf.setActive(true);
- mfs.add(mf);
- } else {
- NodeList mfNodes = mapFrames.getElementsByTagName("MapFrame");
- for (int i = 0; i < mfNodes.getLength(); i++) {
- Node mapFrame = mfNodes.item(i);
- MapFrame mf = new MapFrame();
- mf.importProjectXML(pPath, (Element) mapFrame);
- mfs.add(mf);
- }
- }
-
- this.setMapFrames(mfs);
- //Load MapLayout content
- this.importProjectXML(root);
-
- property.setProperty("user.dir", path);
- }
-
- /**
- * Import project XML element
- *
- * @param parent Parent element
- */
- public void importProjectXML(Element parent) {
- loadLayout(parent);
- }
-
- private void loadLayout(Element parent) {
- Node layout = parent.getElementsByTagName("Layout").item(0);
- try {
- _pageBackColor = ColorUtil.parseToColor(layout.getAttributes().getNamedItem("BackColor").getNodeValue());
- _pageForeColor = ColorUtil.parseToColor(layout.getAttributes().getNamedItem("ForeColor").getNodeValue());
- this.setAntiAlias(Boolean.parseBoolean(layout.getAttributes().getNamedItem("SmoothingMode").getNodeValue()));
- _paperSize.setName(layout.getAttributes().getNamedItem("PaperSizeName").getNodeValue());
- _paperSize.setWidth(Integer.parseInt(layout.getAttributes().getNamedItem("PaperSizeWidth").getNodeValue()));
- _paperSize.setHeight(Integer.parseInt(layout.getAttributes().getNamedItem("PaperSizeHeight").getNodeValue()));
- _isLandscape = Boolean.parseBoolean(layout.getAttributes().getNamedItem("Landscape").getNodeValue());
-
- updatePageSet();
-
- loadLayoutElements((Element) layout);
- } catch (Exception e) {
- }
- }
-
- private void loadLayoutElements(Element parent) {
- _layoutElements.clear();
- _selectedElements.clear();
-
- Node layoutElements = parent.getElementsByTagName("LayoutElements").item(0);
- //Load layout maps
- NodeList layoutNodes = ((Element) layoutElements).getElementsByTagName("LayoutMap");
- for (int i = 0; i < layoutNodes.getLength(); i++) {
- Node elementNode = layoutNodes.item(i);
- MapFrame aMF;
- if (_mapFrames.size() > i) {
- aMF = _mapFrames.get(i);
- } else {
- aMF = new MapFrame();
- }
-
- LayoutMap aLM = new LayoutMap(aMF, this.tileLoadListener);
- loadLayoutMapElement(elementNode, aLM);
- addElement(aLM);
- }
-
- //Load other elements
- for (int i = 0; i < layoutElements.getChildNodes().getLength(); i++) {
- Node elementNode = layoutElements.getChildNodes().item(i);
- if (elementNode.getNodeType() != Node.ELEMENT_NODE) {
- continue;
- }
- ElementType aType = ElementType.valueOf(elementNode.getAttributes().getNamedItem("ElementType").getNodeValue());
- switch (aType) {
- case LayoutIllustration:
- break;
- case LayoutLegend:
- LayoutLegend aLL = loadLayoutLegendElement(elementNode);
- addElement(aLL);
- break;
- case LayoutGraphic:
- LayoutGraphic aLG = loadLayoutGraphicElement(elementNode);
- if (aLG.getGraphic().getShape().getShapeType() == ShapeTypes.WindArraw) {
- ((WindArrow) aLG.getGraphic().getShape()).angle = 270;
- }
- addElement(aLG);
- break;
- case LayoutScaleBar:
- LayoutScaleBar aLSB = loadLayoutScaleBarElement(elementNode);
- if (aLSB != null) {
- addElement(aLSB);
- }
- break;
- case LayoutNorthArraw:
- LayoutNorthArrow aLNA = loadLayoutNorthArrowElement(elementNode);
- if (aLNA != null) {
- addElement(aLNA);
- }
- break;
- }
- }
- }
-
- private void loadLayoutMapElement(Node layoutMap, LayoutMap aLM) {
- try {
- aLM.setLeft(Integer.parseInt(layoutMap.getAttributes().getNamedItem("Left").getNodeValue()));
- aLM.setTop(Integer.parseInt(layoutMap.getAttributes().getNamedItem("Top").getNodeValue()));
- aLM.setWidth(Integer.parseInt(layoutMap.getAttributes().getNamedItem("Width").getNodeValue()));
- aLM.setHeight(Integer.parseInt(layoutMap.getAttributes().getNamedItem("Height").getNodeValue()));
- aLM.setDrawNeatLine(Boolean.parseBoolean(layoutMap.getAttributes().getNamedItem("DrawNeatLine").getNodeValue()));
- aLM.setNeatLineColor(ColorUtil.parseToColor(layoutMap.getAttributes().getNamedItem("NeatLineColor").getNodeValue()));
- aLM.setNeatLineSize(Float.parseFloat(layoutMap.getAttributes().getNamedItem("NeatLineSize").getNodeValue()));
- aLM.setGridLineColor(ColorUtil.parseToColor(layoutMap.getAttributes().getNamedItem("GridLineColor").getNodeValue()));
- aLM.setGridLineSize(Float.parseFloat(layoutMap.getAttributes().getNamedItem("GridLineSize").getNodeValue()));
- aLM.setGridLineStyle(LineStyles.valueOf(layoutMap.getAttributes().getNamedItem("GridLineStyle").getNodeValue()));
- aLM.setDrawGridLine(Boolean.parseBoolean(layoutMap.getAttributes().getNamedItem("DrawGridLine").getNodeValue()));
- aLM.setDrawGridLabel(Boolean.parseBoolean(layoutMap.getAttributes().getNamedItem("DrawGridLabel").getNodeValue()));
- String fontName = layoutMap.getAttributes().getNamedItem("GridFontName").getNodeValue();
- float fontSize = Float.parseFloat(layoutMap.getAttributes().getNamedItem("GridFontSize").getNodeValue());
- aLM.setGridFont(new Font(fontName, Font.PLAIN, (int) fontSize));
- aLM.setGridXDelt(Double.parseDouble(layoutMap.getAttributes().getNamedItem("GridXDelt").getNodeValue()));
- aLM.setGridYDelt(Double.parseDouble(layoutMap.getAttributes().getNamedItem("GridYDelt").getNodeValue()));
- aLM.setGridXOrigin(Float.parseFloat(layoutMap.getAttributes().getNamedItem("GridXOrigin").getNodeValue()));
- aLM.setGridYOrigin(Float.parseFloat(layoutMap.getAttributes().getNamedItem("GridYOrigin").getNodeValue()));
- aLM.setGridLabelPosition(GridLabelPosition.valueOf(layoutMap.getAttributes().getNamedItem("GridLabelPosition").getNodeValue()));
- aLM.setDrawDegreeSymbol(Boolean.parseBoolean(layoutMap.getAttributes().getNamedItem("DrawDegreeSymbol").getNodeValue()));
- aLM.setDrawBackColor(Boolean.parseBoolean(layoutMap.getAttributes().getNamedItem("DrawBackColor").getNodeValue()));
- } catch (Exception e) {
- }
- }
-
- private LayoutLegend loadLayoutLegendElement(Node layoutLegend) {
- LayoutLegend aLL = null;
- try {
- int layoutMapIdx = Integer.parseInt(layoutLegend.getAttributes().getNamedItem("LayoutMapIndex").getNodeValue());
- String legendLayerName = layoutLegend.getAttributes().getNamedItem("LegendLayer").getNodeValue();
- LayoutMap aLM = this.getLayoutMaps().get(layoutMapIdx);
- MapLayer legendLayer = aLM.getMapFrame().getMapView().getLayer(legendLayerName);
- aLL = new LayoutLegend(this, aLM);
- aLL.setLegendLayer(legendLayer);
- } catch (Exception e) {
- aLL = new LayoutLegend(this, this.getLayoutMaps().get(0));
- aLL.setLegendLayer(aLL.getLayoutMap().getMapFrame().getMapView().getLayers().get(0));
- }
-
- try {
- aLL.setLegendStyle(LegendStyles.valueOf(layoutLegend.getAttributes().getNamedItem("LegendStyle").getNodeValue()));
- aLL.setBackColor(ColorUtil.parseToColor(layoutLegend.getAttributes().getNamedItem("BackColor").getNodeValue()));
- aLL.setDrawNeatLine(Boolean.parseBoolean(layoutLegend.getAttributes().getNamedItem("DrawNeatLine").getNodeValue()));
- aLL.setNeatLineColor(ColorUtil.parseToColor(layoutLegend.getAttributes().getNamedItem("NeatLineColor").getNodeValue()));
- aLL.setNeatLineSize(Float.parseFloat(layoutLegend.getAttributes().getNamedItem("NeatLineSize").getNodeValue()));
- aLL.setLeft(Integer.parseInt(layoutLegend.getAttributes().getNamedItem("Left").getNodeValue()));
- aLL.setTop(Integer.parseInt(layoutLegend.getAttributes().getNamedItem("Top").getNodeValue()));
- aLL.setWidth(Integer.parseInt(layoutLegend.getAttributes().getNamedItem("Width").getNodeValue()));
- aLL.setHeight(Integer.parseInt(layoutLegend.getAttributes().getNamedItem("Height").getNodeValue()));
- String fontName = layoutLegend.getAttributes().getNamedItem("FontName").getNodeValue();
- float fontSize = Float.parseFloat(layoutLegend.getAttributes().getNamedItem("FontSize").getNodeValue());
- aLL.setFont(new Font(fontName, Font.PLAIN, (int) fontSize));
- aLL.setLayerUpdateType(LayerUpdateTypes.valueOf(layoutLegend.getAttributes().getNamedItem("LayerUpdateType").getNodeValue()));
- aLL.setColumnNumber(Integer.parseInt(layoutLegend.getAttributes().getNamedItem("ColumnNumber").getNodeValue()));
- aLL.setDrawBackColor(Boolean.parseBoolean(layoutLegend.getAttributes().getNamedItem("DrawBackColor").getNodeValue()));
- aLL.setDrawChartBreaks(Boolean.parseBoolean(layoutLegend.getAttributes().getNamedItem("DrawChartBreaks").getNodeValue()));
- aLL.setForceDrawOutline(Boolean.parseBoolean(layoutLegend.getAttributes().getNamedItem("ForceDrawOutline").getNodeValue()));
- } catch (Exception e) {
- }
-
- return aLL;
- }
-
- private LayoutScaleBar loadLayoutScaleBarElement(Node layoutScaleBar) {
- LayoutScaleBar aLSB = null;
- try {
- int layoutMapIdx = Integer.parseInt(layoutScaleBar.getAttributes().getNamedItem("LayoutMapIndex").getNodeValue());
- LayoutMap aLM = this.getLayoutMaps().get(layoutMapIdx);
- aLSB = new LayoutScaleBar(aLM);
- } catch (Exception e) {
- aLSB = new LayoutScaleBar(this.getLayoutMaps().get(0));
- }
-
- try {
- aLSB.setScaleBarType(ScaleBarType.valueOf(layoutScaleBar.getAttributes().getNamedItem("ScaleBarType").getNodeValue()));
- aLSB.setBackColor(ColorUtil.parseToColor(layoutScaleBar.getAttributes().getNamedItem("BackColor").getNodeValue()));
- aLSB.setForeColor(ColorUtil.parseToColor(layoutScaleBar.getAttributes().getNamedItem("ForeColor").getNodeValue()));
- aLSB.setDrawNeatLine(Boolean.parseBoolean(layoutScaleBar.getAttributes().getNamedItem("DrawNeatLine").getNodeValue()));
- aLSB.setNeatLineColor(ColorUtil.parseToColor(layoutScaleBar.getAttributes().getNamedItem("NeatLineColor").getNodeValue()));
- aLSB.setNeatLineSize(Float.parseFloat(layoutScaleBar.getAttributes().getNamedItem("NeatLineSize").getNodeValue()));
- aLSB.setLeft(Integer.parseInt(layoutScaleBar.getAttributes().getNamedItem("Left").getNodeValue()));
- aLSB.setTop(Integer.parseInt(layoutScaleBar.getAttributes().getNamedItem("Top").getNodeValue()));
- aLSB.setWidth(Integer.parseInt(layoutScaleBar.getAttributes().getNamedItem("Width").getNodeValue()));
- aLSB.setHeight(Integer.parseInt(layoutScaleBar.getAttributes().getNamedItem("Height").getNodeValue()));
- String fontName = layoutScaleBar.getAttributes().getNamedItem("FontName").getNodeValue();
- float fontSize = Float.parseFloat(layoutScaleBar.getAttributes().getNamedItem("FontSize").getNodeValue());
- aLSB.setFont(new Font(fontName, Font.PLAIN, (int) fontSize));
- aLSB.setDrawScaleText(Boolean.parseBoolean(layoutScaleBar.getAttributes().getNamedItem("DrawScaleText").getNodeValue()));
- aLSB.setDrawBackColor(Boolean.parseBoolean(layoutScaleBar.getAttributes().getNamedItem("DrawBackColor").getNodeValue()));
- } catch (Exception e) {
- }
-
- return aLSB;
- }
-
- private LayoutNorthArrow loadLayoutNorthArrowElement(Node layoutNorthArrow) {
- LayoutNorthArrow aLNA = null;
- try {
- int layoutMapIdx = Integer.parseInt(layoutNorthArrow.getAttributes().getNamedItem("LayoutMapIndex").getNodeValue());
- LayoutMap aLM = this.getLayoutMaps().get(layoutMapIdx);
- aLNA = new LayoutNorthArrow(aLM);
- } catch (Exception e) {
- aLNA = new LayoutNorthArrow(this.getLayoutMaps().get(0));
- }
-
- try {
- aLNA.setBackColor(ColorUtil.parseToColor(layoutNorthArrow.getAttributes().getNamedItem("BackColor").getNodeValue()));
- aLNA.setForeColor(ColorUtil.parseToColor(layoutNorthArrow.getAttributes().getNamedItem("ForeColor").getNodeValue()));
- aLNA.setDrawNeatLine(Boolean.parseBoolean(layoutNorthArrow.getAttributes().getNamedItem("DrawNeatLine").getNodeValue()));
- aLNA.setNeatLineColor(ColorUtil.parseToColor(layoutNorthArrow.getAttributes().getNamedItem("NeatLineColor").getNodeValue()));
- aLNA.setNeatLineSize(Float.parseFloat(layoutNorthArrow.getAttributes().getNamedItem("NeatLineSize").getNodeValue()));
- aLNA.setLeft(Integer.parseInt(layoutNorthArrow.getAttributes().getNamedItem("Left").getNodeValue()));
- aLNA.setTop(Integer.parseInt(layoutNorthArrow.getAttributes().getNamedItem("Top").getNodeValue()));
- aLNA.setWidth(Integer.parseInt(layoutNorthArrow.getAttributes().getNamedItem("Width").getNodeValue()));
- aLNA.setHeight(Integer.parseInt(layoutNorthArrow.getAttributes().getNamedItem("Height").getNodeValue()));
- aLNA.setAngle(Float.parseFloat(layoutNorthArrow.getAttributes().getNamedItem("Angle").getNodeValue()));
- aLNA.setDrawBackColor(Boolean.parseBoolean(layoutNorthArrow.getAttributes().getNamedItem("DrawBackColor").getNodeValue()));
- } catch (Exception e) {
- }
-
- return aLNA;
- }
-
- private LayoutGraphic loadLayoutGraphicElement(Node layoutGraphic) {
- Graphic aGraphic = new Graphic();
- Node graphicNode = ((Element) layoutGraphic).getElementsByTagName("Graphic").item(0);
- aGraphic.importFromXML((Element) graphicNode);
-
- LayoutGraphic aLG;
- if (aGraphic.getShape().getShapeType() == ShapeTypes.WindArraw) {
- aLG = new LayoutGraphic(aGraphic, this, this.getActiveLayoutMap());
- } else {
- aLG = new LayoutGraphic(aGraphic, this);
- }
-
- aLG.setIsTitle(Boolean.parseBoolean(layoutGraphic.getAttributes().getNamedItem("IsTitle").getNodeValue()));
-
- return aLG;
- }
- //
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmColorSymbolSet.form b/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmColorSymbolSet.form
deleted file mode 100644
index 41176a29..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmColorSymbolSet.form
+++ /dev/null
@@ -1,97 +0,0 @@
-
-
-
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmLabelSymbolSet.form b/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmLabelSymbolSet.form
deleted file mode 100644
index 6bc20e96..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmLabelSymbolSet.form
+++ /dev/null
@@ -1,181 +0,0 @@
-
-
-
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmLabelSymbolSet.java b/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmLabelSymbolSet.java
deleted file mode 100644
index 51b289e2..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmLabelSymbolSet.java
+++ /dev/null
@@ -1,310 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.legend;
-
-import org.meteoinfo.geometry.legend.LabelBreak;
-import org.meteoinfo.layout.MapLayout;
-import org.meteoinfo.map.MapView;
-import com.l2fprod.common.swing.JFontChooser;
-import java.awt.Color;
-import java.awt.Font;
-import javax.swing.JColorChooser;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class FrmLabelSymbolSet extends javax.swing.JDialog {
-
- private Object _parent = null;
- private LabelBreak _labelBreak = null;
- private boolean _isLoading = false;
-
- /**
- * Creates new form FrmLabelSymbolSet
- * @param parent
- * @param modal
- */
- public FrmLabelSymbolSet(java.awt.Frame parent, boolean modal) {
- super(parent, modal);
- initComponents();
- }
-
- /**
- * Creates new form FrmLabelSymbolSet
- * @param parent
- * @param modal
- * @param tparent
- */
- public FrmLabelSymbolSet(java.awt.Frame parent, boolean modal, Object tparent) {
- super(parent, modal);
- initComponents();
-
- _parent = tparent;
- }
-
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // //GEN-BEGIN:initComponents
- private void initComponents() {
-
- jScrollPane1 = new javax.swing.JScrollPane();
- jTextArea_Text = new javax.swing.JTextArea();
- jPanel1 = new javax.swing.JPanel();
- jButton_Font = new javax.swing.JButton();
- jLabel1 = new javax.swing.JLabel();
- jSpinner_Angle = new javax.swing.JSpinner();
- jLabel_Color = new javax.swing.JLabel();
- jButton_OK = new javax.swing.JButton();
- jButton_Apply = new javax.swing.JButton();
-
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
-
- jTextArea_Text.setColumns(20);
- jTextArea_Text.setRows(5);
- jTextArea_Text.setWrapStyleWord(true);
- jScrollPane1.setViewportView(jTextArea_Text);
-
- jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
-
- jButton_Font.setText("Font");
- jButton_Font.setPreferredSize(new java.awt.Dimension(81, 30));
- jButton_Font.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton_FontActionPerformed(evt);
- }
- });
-
- jLabel1.setText("Angle:");
-
- jSpinner_Angle.setModel(new javax.swing.SpinnerNumberModel(Float.valueOf(0.0f), Float.valueOf(-360.0f), Float.valueOf(360.0f), Float.valueOf(1.0f)));
- jSpinner_Angle.addChangeListener(new javax.swing.event.ChangeListener() {
- public void stateChanged(javax.swing.event.ChangeEvent evt) {
- jSpinner_AngleStateChanged(evt);
- }
- });
-
- jLabel_Color.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
- jLabel_Color.setText("Color");
- jLabel_Color.setBorder(javax.swing.BorderFactory.createEtchedBorder());
- jLabel_Color.setOpaque(true);
- jLabel_Color.setPreferredSize(new java.awt.Dimension(34, 22));
- jLabel_Color.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jLabel_ColorMouseClicked(evt);
- }
- });
-
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jButton_Font, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
- .addComponent(jLabel_Color, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jSpinner_Angle, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap())
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton_Font, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jLabel_Color, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel1)
- .addComponent(jSpinner_Angle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap())
- );
-
- jButton_OK.setText("OK");
- jButton_OK.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton_OKActionPerformed(evt);
- }
- });
-
- jButton_Apply.setText("Apply");
- jButton_Apply.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton_ApplyActionPerformed(evt);
- }
- });
-
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addContainerGap())
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jButton_OK, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(58, 58, 58)
- .addComponent(jButton_Apply, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(49, 49, 49))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton_OK)
- .addComponent(jButton_Apply))
- .addContainerGap(17, Short.MAX_VALUE))
- );
-
- pack();
- }// //GEN-END:initComponents
-
- private void jButton_OKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_OKActionPerformed
- // TODO add your handling code here:
- _labelBreak.setText(this.jTextArea_Text.getText());
- if (_parent.getClass() == MapView.class) {
- ((MapView) _parent).setDefLabelBreak(_labelBreak);
- ((MapView) _parent).paintLayers();
- } else if (_parent.getClass() == MapLayout.class) {
- ((MapLayout) _parent).setDefLabelBreak(_labelBreak);
- ((MapLayout) _parent).paintGraphics();
- }
-
- this.dispose();
- }//GEN-LAST:event_jButton_OKActionPerformed
-
- private void jButton_ApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_ApplyActionPerformed
- // TODO add your handling code here:
- _labelBreak.setText(this.jTextArea_Text.getText());
- if (_parent.getClass() == MapView.class) {
- ((MapView) _parent).paintLayers();
- } else if (_parent.getClass() == MapLayout.class) {
- ((MapLayout) _parent).paintGraphics();
- }
- }//GEN-LAST:event_jButton_ApplyActionPerformed
-
- private void jLabel_ColorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel_ColorMouseClicked
- // TODO add your handling code here:
- Color aColor = JColorChooser.showDialog(this, null, this.jLabel_Color.getBackground());
- this.jLabel_Color.setBackground(aColor);
- this.jTextArea_Text.setForeground(aColor);
- _labelBreak.setColor(aColor);
- }//GEN-LAST:event_jLabel_ColorMouseClicked
-
- private void jButton_FontActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_FontActionPerformed
- // TODO add your handling code here:
- //FontChooser fontChooser = new FontChooser(this, true, _labelBreak.getFont());
- //fontChooser.setVisible(true);
- Font aFont = JFontChooser.showDialog(this, null, _labelBreak.getFont());
- if (aFont != null) {
- this.jTextArea_Text.setFont(aFont);
- _labelBreak.setFont(aFont);
- }
- }//GEN-LAST:event_jButton_FontActionPerformed
-
- private void jSpinner_AngleStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner_AngleStateChanged
- // TODO add your handling code here:
- if (_isLoading) {
- return;
- }
-
- float angle = Float.parseFloat(this.jSpinner_Angle.getValue().toString());
- _labelBreak.setAngle(angle);
- }//GEN-LAST:event_jSpinner_AngleStateChanged
-
- /**
- * Set label break
- *
- * @param lb The label break
- */
- public void setLabelBreak(LabelBreak lb) {
- _labelBreak = lb;
-
- _isLoading = true;
- this.jTextArea_Text.setText(_labelBreak.getText());
- this.jTextArea_Text.setForeground(_labelBreak.getColor());
- this.jTextArea_Text.setFont(_labelBreak.getFont());
- this.jLabel_Color.setBackground(_labelBreak.getColor());
- this.jSpinner_Angle.setValue(_labelBreak.getAngle());
- _isLoading = false;
- }
-
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(FrmLabelSymbolSet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(FrmLabelSymbolSet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(FrmLabelSymbolSet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(FrmLabelSymbolSet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //
-
- /* Create and display the dialog */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- FrmLabelSymbolSet dialog = new FrmLabelSymbolSet(new javax.swing.JFrame(), true);
- dialog.addWindowListener(new java.awt.event.WindowAdapter() {
- @Override
- public void windowClosing(java.awt.event.WindowEvent e) {
- System.exit(0);
- }
- });
- dialog.setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton jButton_Apply;
- private javax.swing.JButton jButton_Font;
- private javax.swing.JButton jButton_OK;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel_Color;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JSpinner jSpinner_Angle;
- private javax.swing.JTextArea jTextArea_Text;
- // End of variables declaration//GEN-END:variables
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmLegendBreaks.form b/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmLegendBreaks.form
deleted file mode 100644
index f3ddf23f..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmLegendBreaks.form
+++ /dev/null
@@ -1,303 +0,0 @@
-
-
-
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmLegendSet.form b/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmLegendSet.form
deleted file mode 100644
index 1917ecbb..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmLegendSet.form
+++ /dev/null
@@ -1,233 +0,0 @@
-
-
-
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmPointSymbolSet.form b/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmPointSymbolSet.form
deleted file mode 100644
index e555d098..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmPointSymbolSet.form
+++ /dev/null
@@ -1,356 +0,0 @@
-
-
-
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmPolygonSymbolSet.form b/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmPolygonSymbolSet.form
deleted file mode 100644
index d02b186b..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmPolygonSymbolSet.form
+++ /dev/null
@@ -1,291 +0,0 @@
-
-
-
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmPolylineSymbolSet.form b/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmPolylineSymbolSet.form
deleted file mode 100644
index 1f6dea22..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmPolylineSymbolSet.form
+++ /dev/null
@@ -1,362 +0,0 @@
-
-
-
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmPolylineSymbolSet.java b/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmPolylineSymbolSet.java
deleted file mode 100644
index f2df10b4..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/FrmPolylineSymbolSet.java
+++ /dev/null
@@ -1,602 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.legend;
-
-import org.meteoinfo.geometry.legend.LineStyles;
-import org.meteoinfo.geometry.legend.PointStyle;
-import org.meteoinfo.geometry.legend.PolylineBreak;
-import org.meteoinfo.ui.event.ISelectedCellChangedListener;
-import org.meteoinfo.ui.event.SelectedCellChangedEvent;
-import org.meteoinfo.layout.MapLayout;
-import org.meteoinfo.map.MapView;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.util.Arrays;
-import javax.swing.JColorChooser;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class FrmPolylineSymbolSet extends javax.swing.JDialog {
-
- private Object _parent = null;
- private PolylineBreak _polylineBreak = null;
- private boolean isLoading = false;
-
- /**
- * Creates new form FrmPolylineSymbolSet
- * @param parent
- * @param modal
- */
- public FrmPolylineSymbolSet(java.awt.Frame parent, boolean modal) {
- super(parent, modal);
- initComponents();
-
- this.setTitle("Polyline Symbol Set");
- }
-
- /**
- * Creates new form FrmPolylineSymbolSet
- * @param parent
- * @param modal
- * @param tparent
- */
- public FrmPolylineSymbolSet(java.awt.Dialog parent, boolean modal, Object tparent) {
- super(parent, modal);
- initComponents();
-
- this.setTitle("Polyline Symbol Set");
- if (tparent.getClass() == LegendView.class){
- this.jButton_Apply.setVisible(false);
- this.jButton_OK.setVisible(false);
- this.setPreferredSize(new Dimension(this.getWidth(), this.getHeight() - 40));
- }
-
- this.symbolControl1.addSelectedCellChangedListener(new ISelectedCellChangedListener() {
- @Override
- public void selectedCellChangedEvent(SelectedCellChangedEvent event) {
- onSelectedCellChanged(event);
- }
- });
-
- this._parent = tparent;
- }
-
- /**
- * Creates new form FrmPolylineSymbolSet
- * @param parent
- * @param modal
- * @param tparent
- */
- public FrmPolylineSymbolSet(java.awt.Frame parent, boolean modal, Object tparent) {
- super(parent, modal);
- initComponents();
-
- this.setTitle("Polyline Symbol Set");
- if (tparent.getClass() == LegendView.class){
- this.jButton_Apply.setVisible(false);
- this.jButton_OK.setVisible(false);
- this.setPreferredSize(new Dimension(this.getWidth(), this.getHeight() - 40));
- }
-
- this.symbolControl1.addSelectedCellChangedListener(new ISelectedCellChangedListener() {
- @Override
- public void selectedCellChangedEvent(SelectedCellChangedEvent event) {
- onSelectedCellChanged(event);
- }
- });
-
- this._parent = tparent;
- }
-
- private void onSelectedCellChanged(SelectedCellChangedEvent event) {
- if (isLoading) {
- return;
- }
-
- _polylineBreak.setStyle(LineStyles.values()[symbolControl1.getSelectedCell()]);
- if (_parent.getClass() == LegendView.class) {
- ((LegendView) _parent).setLegendBreak_PolylineStyle(_polylineBreak.getStyle());
- }
- }
-
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // //GEN-BEGIN:initComponents
- private void initComponents() {
-
- symbolControl1 = new org.meteoinfo.legend.SymbolControl();
- jLabel1 = new javax.swing.JLabel();
- jSpinner_Size = new javax.swing.JSpinner();
- jLabel2 = new javax.swing.JLabel();
- jLabel_Color = new javax.swing.JLabel();
- jCheckBox_DrawShape = new javax.swing.JCheckBox();
- jCheckBox_DrawPointSymbol = new javax.swing.JCheckBox();
- jPanel1 = new javax.swing.JPanel();
- jLabel3 = new javax.swing.JLabel();
- jSpinner_SymbolSize = new javax.swing.JSpinner();
- jLabel4 = new javax.swing.JLabel();
- jLabel_SymbolColor = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- jSpinner_SymbolInterval = new javax.swing.JSpinner();
- jComboBox_SymbolStyle = new javax.swing.JComboBox();
- jCheckBox_DrawFill = new javax.swing.JCheckBox();
- jLabel6 = new javax.swing.JLabel();
- jLabel_FillColor = new javax.swing.JLabel();
- jButton_Apply = new javax.swing.JButton();
- jButton_OK = new javax.swing.JButton();
-
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- setResizable(false);
-
- symbolControl1.setCellSize(new java.awt.Dimension(50, 40));
- symbolControl1.setPreferredSize(new java.awt.Dimension(200, 50));
- symbolControl1.setShapeType(org.meteoinfo.geometry.shape.ShapeTypes.Polyline);
-
- jLabel1.setText("Size:");
-
- jSpinner_Size.setModel(new javax.swing.SpinnerNumberModel(Float.valueOf(1.0f), Float.valueOf(1.0f), Float.valueOf(100.0f), Float.valueOf(0.5f)));
- jSpinner_Size.addChangeListener(new javax.swing.event.ChangeListener() {
- public void stateChanged(javax.swing.event.ChangeEvent evt) {
- jSpinner_SizeStateChanged(evt);
- }
- });
-
- jLabel2.setText("Color:");
-
- jLabel_Color.setBorder(javax.swing.BorderFactory.createEtchedBorder());
- jLabel_Color.setOpaque(true);
- jLabel_Color.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jLabel_ColorMouseClicked(evt);
- }
- });
-
- jCheckBox_DrawShape.setText("Draw Shape");
- jCheckBox_DrawShape.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jCheckBox_DrawShapeActionPerformed(evt);
- }
- });
-
- jCheckBox_DrawPointSymbol.setText("Draw Point Symbol");
- jCheckBox_DrawPointSymbol.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jCheckBox_DrawPointSymbolActionPerformed(evt);
- }
- });
-
- jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Point Symbol"));
- jPanel1.setToolTipText("Outline");
- jPanel1.setName("Outline"); // NOI18N
-
- jLabel3.setText("Size:");
-
- jSpinner_SymbolSize.setModel(new javax.swing.SpinnerNumberModel(Float.valueOf(1.0f), Float.valueOf(1.0f), Float.valueOf(100.0f), Float.valueOf(0.5f)));
- jSpinner_SymbolSize.addChangeListener(new javax.swing.event.ChangeListener() {
- public void stateChanged(javax.swing.event.ChangeEvent evt) {
- jSpinner_SymbolSizeStateChanged(evt);
- }
- });
-
- jLabel4.setText("Outline Color:");
-
- jLabel_SymbolColor.setBorder(javax.swing.BorderFactory.createEtchedBorder());
- jLabel_SymbolColor.setOpaque(true);
- jLabel_SymbolColor.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jLabel_SymbolColorMouseClicked(evt);
- }
- });
-
- jLabel5.setText("Interval:");
-
- jSpinner_SymbolInterval.setModel(new javax.swing.SpinnerNumberModel(1, 1, 100, 1));
- jSpinner_SymbolInterval.addChangeListener(new javax.swing.event.ChangeListener() {
- public void stateChanged(javax.swing.event.ChangeEvent evt) {
- jSpinner_SymbolIntervalStateChanged(evt);
- }
- });
-
- jComboBox_SymbolStyle.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
- jComboBox_SymbolStyle.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jComboBox_SymbolStyleActionPerformed(evt);
- }
- });
-
- jCheckBox_DrawFill.setText("Draw Fill");
- jCheckBox_DrawFill.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jCheckBox_DrawFillActionPerformed(evt);
- }
- });
-
- jLabel6.setText("Fill Color:");
-
- jLabel_FillColor.setBorder(javax.swing.BorderFactory.createEtchedBorder());
- jLabel_FillColor.setOpaque(true);
- jLabel_FillColor.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jLabel_FillColorMouseClicked(evt);
- }
- });
-
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jComboBox_SymbolStyle, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addGap(0, 5, Short.MAX_VALUE)
- .addComponent(jLabel3)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jSpinner_SymbolSize, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(0, 0, Short.MAX_VALUE)
- .addComponent(jCheckBox_DrawFill)))
- .addGap(18, 18, 18)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel5)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jSpinner_SymbolInterval, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel4)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jLabel_SymbolColor, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel6)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jLabel_FillColor, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap())
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel_SymbolColor, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel3)
- .addComponent(jSpinner_SymbolSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel4)))
- .addGap(18, 18, 18)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jCheckBox_DrawFill)
- .addComponent(jLabel6))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel_FillColor, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(2, 2, 2)))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel5)
- .addComponent(jSpinner_SymbolInterval, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jComboBox_SymbolStyle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap())
- );
-
- jButton_Apply.setText("Apply");
- jButton_Apply.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton_ApplyActionPerformed(evt);
- }
- });
-
- jButton_OK.setText("OK");
- jButton_OK.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton_OKActionPerformed(evt);
- }
- });
-
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(symbolControl1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addGap(31, 31, 31)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jSpinner_Size, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(jCheckBox_DrawShape))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jLabel_Color, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(jCheckBox_DrawPointSymbol))))
- .addContainerGap())
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGap(0, 0, Short.MAX_VALUE)
- .addComponent(jButton_OK, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(58, 58, 58)
- .addComponent(jButton_Apply, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(52, 52, 52))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(symbolControl1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(jSpinner_Size, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jCheckBox_DrawShape))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel2)
- .addComponent(jLabel_Color, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jCheckBox_DrawPointSymbol)))
- .addGap(18, 18, 18)
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton_Apply)
- .addComponent(jButton_OK, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addContainerGap())
- );
-
- pack();
- }// //GEN-END:initComponents
-
- private void jSpinner_SizeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner_SizeStateChanged
- // TODO add your handling code here:
- float size = Float.parseFloat(this.jSpinner_Size.getValue().toString());
- _polylineBreak.setWidth(size);
- if (_parent.getClass() == LegendView.class) {
- ((LegendView) _parent).setLegendBreak_Size(size);
- }
- }//GEN-LAST:event_jSpinner_SizeStateChanged
-
- private void jLabel_ColorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel_ColorMouseClicked
- // TODO add your handling code here:
- Color aColor = JColorChooser.showDialog(rootPane, null, this.jLabel_Color.getBackground());
- this.jLabel_Color.setBackground(aColor);
- _polylineBreak.setColor(aColor);
- if (_parent.getClass() == LegendView.class) {
- ((LegendView) _parent).setLegendBreak_Color(aColor);
- }
- }//GEN-LAST:event_jLabel_ColorMouseClicked
-
- private void jCheckBox_DrawShapeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_DrawShapeActionPerformed
- // TODO add your handling code here:
- _polylineBreak.setDrawShape(this.jCheckBox_DrawShape.isSelected());
- if (_parent.getClass() == LegendView.class) {
- ((LegendView) _parent).setLegendBreak_DrawShape(this.jCheckBox_DrawShape.isSelected());
- }
- }//GEN-LAST:event_jCheckBox_DrawShapeActionPerformed
-
- private void jCheckBox_DrawPointSymbolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_DrawPointSymbolActionPerformed
- // TODO add your handling code here:
- _polylineBreak.setDrawSymbol(this.jCheckBox_DrawPointSymbol.isSelected());
- if (_parent.getClass() == LegendView.class) {
- ((LegendView) _parent).setLegendBreak_DrawSymbol(this.jCheckBox_DrawPointSymbol.isSelected());
- }
- }//GEN-LAST:event_jCheckBox_DrawPointSymbolActionPerformed
-
- private void jSpinner_SymbolSizeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner_SymbolSizeStateChanged
- // TODO add your handling code here:
- float size = Float.parseFloat(this.jSpinner_SymbolSize.getValue().toString());
- _polylineBreak.setSymbolSize(size);
- if (_parent.getClass() == LegendView.class) {
- ((LegendView) _parent).setLegendBreak_SymbolSize(size);
- }
- }//GEN-LAST:event_jSpinner_SymbolSizeStateChanged
-
- private void jLabel_SymbolColorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel_SymbolColorMouseClicked
- // TODO add your handling code here:
- Color aColor = JColorChooser.showDialog(rootPane, null, this.jLabel_SymbolColor.getBackground());
- this.jLabel_SymbolColor.setBackground(aColor);
- _polylineBreak.setSymbolColor(aColor);
- if (_parent.getClass() == LegendView.class) {
- ((LegendView) _parent).setLegendBreak_SymbolColor(aColor);
- }
- }//GEN-LAST:event_jLabel_SymbolColorMouseClicked
-
- private void jSpinner_SymbolIntervalStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner_SymbolIntervalStateChanged
- // TODO add your handling code here:
- int interval = Integer.parseInt(this.jSpinner_SymbolInterval.getValue().toString());
- _polylineBreak.setSymbolInterval(interval);
- if (_parent.getClass() == LegendView.class) {
- ((LegendView) _parent).setLegendBreak_SymbolInterval(interval);
- }
- }//GEN-LAST:event_jSpinner_SymbolIntervalStateChanged
-
- private void jComboBox_SymbolStyleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox_SymbolStyleActionPerformed
- // TODO add your handling code here:
- if (isLoading){
- return;
- }
-
- _polylineBreak.setSymbolStyle(PointStyle.valueOf(this.jComboBox_SymbolStyle.getSelectedItem().toString()));
- if (_parent.getClass() == LegendView.class) {
- ((LegendView)_parent).setLegendBreak_SymbolStyle(_polylineBreak.getSymbolStyle());
- }
- }//GEN-LAST:event_jComboBox_SymbolStyleActionPerformed
-
- private void jButton_ApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_ApplyActionPerformed
- // TODO add your handling code here:
- if (_parent.getClass() == MapView.class) {
- ((MapView) _parent).paintLayers();
- } else if (_parent.getClass() == MapLayout.class) {
- ((MapLayout) _parent).paintGraphics();
- }
- }//GEN-LAST:event_jButton_ApplyActionPerformed
-
- private void jButton_OKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_OKActionPerformed
- // TODO add your handling code here:
- if (_parent.getClass() == MapView.class) {
- ((MapView) _parent).setDefPolylineBreak(_polylineBreak);
- ((MapView) _parent).paintLayers();
- } else if (_parent.getClass() == MapLayout.class) {
- ((MapLayout) _parent).setDefPolylineBreak(_polylineBreak);
- ((MapLayout) _parent).paintGraphics();
- }
-
- this.dispose();
- }//GEN-LAST:event_jButton_OKActionPerformed
-
- private void jCheckBox_DrawFillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_DrawFillActionPerformed
- // TODO add your handling code here:
- _polylineBreak.setFillSymbol(this.jCheckBox_DrawFill.isSelected());
- if (_parent.getClass() == LegendView.class) {
- //((LegendView) _parent).setLegendBreak_DrawFill(this.jCheckBox_DrawFill.isSelected());
- ((LegendView) _parent).repaint();
- }
- }//GEN-LAST:event_jCheckBox_DrawFillActionPerformed
-
- private void jLabel_FillColorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel_FillColorMouseClicked
- // TODO add your handling code here:
- Color c = JColorChooser.showDialog(rootPane, null, this.jLabel_FillColor.getBackground());
- if (c == null)
- return;
-
- Color aColor = new Color(c.getRed(), c.getGreen(), c.getBlue());
- this.jLabel_FillColor.setBackground(aColor);
- _polylineBreak.setSymbolFillColor(aColor);
- if (_parent.getClass() == LegendView.class) {
- //((LegendView) _parent).setLegendBreak_Color(aColor);
- ((LegendView) _parent).repaint();
- }
- }//GEN-LAST:event_jLabel_FillColorMouseClicked
-
- /**
- * Set polyline break
- *
- * @param plb The polyline break
- */
- public void setPolylineBreak(PolylineBreak plb) {
- _polylineBreak = plb;
- updateProperties();
- }
-
- private void updateProperties() {
- isLoading = true;
-
- this.jLabel_Color.setBackground(_polylineBreak.getColor());
- this.jSpinner_Size.setValue(_polylineBreak.getWidth());
- this.jCheckBox_DrawShape.setSelected(_polylineBreak.isDrawShape());
- this.jCheckBox_DrawPointSymbol.setSelected(_polylineBreak.getDrawSymbol());
- this.jSpinner_SymbolSize.setValue(_polylineBreak.getSymbolSize());
- this.jLabel_SymbolColor.setBackground(_polylineBreak.getSymbolColor());
- this.jSpinner_SymbolInterval.setValue(_polylineBreak.getSymbolInterval());
- this.jComboBox_SymbolStyle.removeAllItems();
- for (PointStyle sName : PointStyle.values()) {
- this.jComboBox_SymbolStyle.addItem(sName);
- }
- this.jComboBox_SymbolStyle.setSelectedItem(_polylineBreak.getSymbolStyle());
- this.jCheckBox_DrawFill.setSelected(_polylineBreak.isFillSymbol());
- this.jLabel_FillColor.setBackground(_polylineBreak.getSymbolFillColor());
-
- //symbolControl1.setSymbolNumber(LineStyles.values().length);
- if (_parent.getClass() == LegendView.class) {
- symbolControl1.setSymbolNumber(5);
- } else {
- symbolControl1.setSymbolNumber(LineStyles.values().length);
- }
-
- symbolControl1.setSelectedCell(Arrays.asList(LineStyles.values()).indexOf(_polylineBreak.getStyle()));
-
- isLoading = false;
- }
-
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(FrmPolylineSymbolSet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(FrmPolylineSymbolSet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(FrmPolylineSymbolSet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(FrmPolylineSymbolSet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //
-
- /* Create and display the dialog */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- FrmPolylineSymbolSet dialog = new FrmPolylineSymbolSet(new javax.swing.JFrame(), true);
- dialog.addWindowListener(new java.awt.event.WindowAdapter() {
- @Override
- public void windowClosing(java.awt.event.WindowEvent e) {
- System.exit(0);
- }
- });
- dialog.setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton jButton_Apply;
- private javax.swing.JButton jButton_OK;
- private javax.swing.JCheckBox jCheckBox_DrawFill;
- private javax.swing.JCheckBox jCheckBox_DrawPointSymbol;
- private javax.swing.JCheckBox jCheckBox_DrawShape;
- private javax.swing.JComboBox jComboBox_SymbolStyle;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JLabel jLabel6;
- private javax.swing.JLabel jLabel_Color;
- private javax.swing.JLabel jLabel_FillColor;
- private javax.swing.JLabel jLabel_SymbolColor;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JSpinner jSpinner_Size;
- private javax.swing.JSpinner jSpinner_SymbolInterval;
- private javax.swing.JSpinner jSpinner_SymbolSize;
- private org.meteoinfo.legend.SymbolControl symbolControl1;
- // End of variables declaration//GEN-END:variables
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/LegendNode.java b/MeteoInfoLib/src/main/java/org/meteoinfo/legend/LegendNode.java
deleted file mode 100644
index 793e4c3c..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/LegendNode.java
+++ /dev/null
@@ -1,95 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.legend;
-
-import org.meteoinfo.geometry.legend.ColorBreak;
-import org.meteoinfo.geometry.shape.ShapeTypes;
-
-/**
- *
- * @author yaqiang
- */
-public class LegendNode extends ItemNode {
- //
-
- private ShapeTypes _shapeType;
- private ColorBreak _legendBreak;
- //
- //
- //
- //
-
- /**
- * Get shape type
- *
- * @return The shape type
- */
- public ShapeTypes getShapeType() {
- return _shapeType;
- }
-
- /**
- * Set shape type
- *
- * @param type The shape type
- */
- public void setShapeType(ShapeTypes type) {
- _shapeType = type;
- }
-
- /**
- * Get legend break
- *
- * @return The legend break
- */
- public ColorBreak getLegendBreak() {
- return _legendBreak;
- }
-
- /**
- * Set legend break
- *
- * @param aCB The legend break
- */
- public void setLegendBreak(ColorBreak aCB) {
- _legendBreak = aCB;
- }
- //
- //
-
- /**
- * Clone
- *
- * @return LegendNode object
- */
- @Override
- public Object clone() {
- LegendNode aLN = new LegendNode();
- aLN.setShapeType(_shapeType);
- aLN.setLegendBreak(_legendBreak);
-
- return aLN;
- }
-
- @Override
- public int getDrawHeight() {
- return this.getHeight();
- }
-
- @Override
- public int getExpandedHeight() {
- return this.getHeight();
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/LegendSchemeControl.java b/MeteoInfoLib/src/main/java/org/meteoinfo/legend/LegendSchemeControl.java
deleted file mode 100644
index 24a1ad84..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/legend/LegendSchemeControl.java
+++ /dev/null
@@ -1,67 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.legend;
-
-import org.meteoinfo.geometry.legend.LegendScheme;
-import org.meteoinfo.global.FrmProperty;
-import org.meteoinfo.layer.MapLayer;
-import javax.swing.JPanel;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class LegendSchemeControl extends JPanel {
- //
-
- public FrmProperty m_FrmSS = null;
- private MapLayer _mapLayer;
- //Form m_FrmMeteoData = new Form();
- LegendScheme _legendScheme = null;
- LayersLegend m_LayersTV = new LayersLegend();
- boolean m_IfFrmMeteoData = false;
- boolean _ifCreateLegendScheme = false;
- //
- //
-
- /**
- * Constructor
- */
- public LegendSchemeControl() {
- initComponents();
- }
-
- /**
- * Constructor
- *
- * @param ifFrmMeteoData If is from meteo data
- * @param mapLayer The map layer
- * @param aLayersTV The layersLegend
- */
- public LegendSchemeControl(boolean ifFrmMeteoData, MapLayer mapLayer, LayersLegend aLayersTV) {
- initComponents();
-
- m_IfFrmMeteoData = ifFrmMeteoData;
- _mapLayer = mapLayer;
- m_LayersTV = aLayersTV;
- }
-
- private void initComponents() {
- }
- //
- //
- //
- //
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/map/FrmIdentifer.form b/MeteoInfoLib/src/main/java/org/meteoinfo/map/FrmIdentifer.form
deleted file mode 100644
index 3bec417b..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/map/FrmIdentifer.form
+++ /dev/null
@@ -1,59 +0,0 @@
-
-
-
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/map/FrmIdentifer.java b/MeteoInfoLib/src/main/java/org/meteoinfo/map/FrmIdentifer.java
deleted file mode 100644
index a4a52132..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/map/FrmIdentifer.java
+++ /dev/null
@@ -1,174 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.map;
-
-import javax.swing.JTable;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class FrmIdentifer extends javax.swing.JDialog {
-
- private MapView _mapView;
-
- /**
- * Creates new form FrmIdentifer
- */
- public FrmIdentifer(java.awt.Frame parent, boolean modal, MapView mapView) {
- super(parent, modal);
- _mapView = mapView;
- initComponents();
- }
-
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // //GEN-BEGIN:initComponents
- private void initComponents() {
-
- jScrollPane1 = new javax.swing.JScrollPane();
- jTable1 = new javax.swing.JTable();
-
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- addWindowListener(new java.awt.event.WindowAdapter() {
- public void windowClosed(java.awt.event.WindowEvent evt) {
- formWindowClosed(evt);
- }
- });
-
- jTable1.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- {null, null},
- {null, null},
- {null, null},
- {null, null}
- },
- new String [] {
- "Field", "Value"
- }
- ) {
- Class[] types = new Class [] {
- java.lang.String.class, java.lang.String.class
- };
-
- public Class getColumnClass(int columnIndex) {
- return types [columnIndex];
- }
- });
- jScrollPane1.setViewportView(jTable1);
-
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)
- );
-
- pack();
- }// //GEN-END:initComponents
-
- private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
- // TODO add your handling code here:
-// if (_mapView != null){
-// _mapView.setDrawIdentiferShape(false);
-// _mapView.repaint();
-// }
- }//GEN-LAST:event_formWindowClosed
-
- /**
- * Set map view
- * @return Map view
- */
- public MapView getMapView(){
- return _mapView;
- }
-
- /**
- * Set map view
- * @param mapView Map view
- */
- public void setMapView(MapView mapView){
- _mapView = mapView;
- }
-
- /**
- * Get JTable
- * @return JTable
- */
- public JTable getTable(){
- return this.jTable1;
- }
-
- /**
- * Set JTable
- * @param table JTable
- */
- public void setTable(JTable table){
- this.jTable1 = table;
- }
-
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(FrmIdentifer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(FrmIdentifer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(FrmIdentifer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(FrmIdentifer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //
-
- /* Create and display the dialog */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- FrmIdentifer dialog = new FrmIdentifer(new javax.swing.JFrame(), true, new MapView());
- dialog.addWindowListener(new java.awt.event.WindowAdapter() {
- @Override
- public void windowClosing(java.awt.event.WindowEvent e) {
- System.exit(0);
- }
- });
- dialog.setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTable jTable1;
- // End of variables declaration//GEN-END:variables
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/map/FrmIdentiferGrid.form b/MeteoInfoLib/src/main/java/org/meteoinfo/map/FrmIdentiferGrid.form
deleted file mode 100644
index 965b4420..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/map/FrmIdentiferGrid.form
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
-
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/map/FrmVerticeEdit.form b/MeteoInfoLib/src/main/java/org/meteoinfo/map/FrmVerticeEdit.form
deleted file mode 100644
index 916b4f9f..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/map/FrmVerticeEdit.form
+++ /dev/null
@@ -1,117 +0,0 @@
-
-
-
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/map/MapViewBeanInfo.java b/MeteoInfoLib/src/main/java/org/meteoinfo/map/MapViewBeanInfo.java
deleted file mode 100644
index 341b85af..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/map/MapViewBeanInfo.java
+++ /dev/null
@@ -1,34 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.map;
-
-import com.l2fprod.common.beans.BaseBeanInfo;
-
-/**
- *
- * @author Yaqiang
- */
-public class MapViewBeanInfo extends BaseBeanInfo {
- public MapViewBeanInfo(){
- super(MapView.class);
- addProperty("antiAlias").setCategory("General").setDisplayName("AntiAlias");
- addProperty("background").setCategory("General").setDisplayName("Background");
- addProperty("foreground").setCategory("General").setDisplayName("Foreground");
- addProperty("xYScaleFactor").setCategory("General").setDisplayName("XYScaleFactor");
- addProperty("selectColor").setCategory("General").setDisplayName("Select Color");
- addProperty("multiGlobalDraw").setCategory("General").setDisplayName("MultiGlobalDraw");
- addProperty("pointAntiAlias").setCategory("General").setDisplayName("Point AntiAlias");
- addProperty("highSpeedWheelZoom").setCategory("General").setDisplayName("HighSpeedWheelZoom");
- }
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/map/MaskOut.java b/MeteoInfoLib/src/main/java/org/meteoinfo/map/MaskOut.java
deleted file mode 100644
index 3d0228ba..00000000
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/map/MaskOut.java
+++ /dev/null
@@ -1,209 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.map;
-
-import com.l2fprod.common.beans.BaseBeanInfo;
-import com.l2fprod.common.beans.ExtendedPropertyDescriptor;
-import com.l2fprod.common.beans.editor.ComboBoxPropertyEditor;
-import java.util.ArrayList;
-import java.util.List;
-import org.meteoinfo.layer.LayerTypes;
-import org.meteoinfo.layer.MapLayer;
-import org.meteoinfo.geometry.shape.ShapeTypes;
-
-/**
- *
- * @author yaqiang
- */
-public class MaskOut {
- //
-
- private static MapView _mapView;
- private boolean _setMaskLayer;
- private String _maskLayer;
- private List _layerList;
- //
- //
-
- /**
- * Constructor
- *
- * @param aMapView
- */
- public MaskOut(MapView aMapView) {
- _mapView = aMapView;
- _setMaskLayer = false;
- _maskLayer = "";
- }
- //
- //
-
- /**
- * Set map view
- * @param mapView Map view
- */
- public void setMapView(MapView mapView){
- _mapView = mapView;
- }
-
- /**
- * Get polygon map layers
- *
- * @return The polygon layer names
- */
- public List getPolygonMapLayers() {
- return _layerList;
- }
-
- /**
- * Set polygon map layers
- *
- * @param layers The polygon layer names
- */
- public void setPolygonMapLayers(List layers) {
- _layerList = layers;
- }
-
- /**
- * Get if is mask out
- *
- * @return Boolean
- */
- public boolean isMask() {
- return _setMaskLayer;
- }
-
- /**
- * Set if is mask out
- *
- * @param istrue Boolean
- */
- public void setMask(boolean istrue) {
- _setMaskLayer = istrue;
- _mapView.paintLayers();
- }
-
- /**
- * Get mask layer name
- *
- * @return The mask layer name
- */
- public String getMaskLayer() {
- return _maskLayer;
- }
-
- /**
- * Set mask layer name
- *
- * @param lname The layer name
- */
- public void setMaskLayer(String lname) {
- _maskLayer = lname;
- _mapView.paintLayers();
- }
- //
- //
-
- /**
- * Get layer names
- *
- * @return Layer names
- */
- public static List getLayerNames() {
- List layerNames = new ArrayList<>();
- for (MapLayer aLayer : _mapView.getLayers()) {
- if (aLayer.getLayerType() == LayerTypes.VectorLayer) {
- if (aLayer.getShapeType() == ShapeTypes.Polygon) {
- layerNames.add(aLayer.getLayerName());
- }
- }
- }
-
- return layerNames;
- }
- //
-
- //
- public class MaskOutBean {
-
- public MaskOutBean() {
- }
-
- //
- /**
- * Get if is mask out
- *
- * @return Boolean
- */
- public boolean isMask() {
- return _setMaskLayer;
- }
-
- /**
- * Set if is mask out
- *
- * @param istrue Boolean
- */
- public void setMask(boolean istrue) {
- _setMaskLayer = istrue;
- _mapView.paintLayers();
- }
-
- /**
- * Get mask layer name
- *
- * @return The mask layer name
- */
- public String getMaskLayer() {
- return _maskLayer;
- }
-
- /**
- * Set mask layer name
- *
- * @param lname The layer name
- */
- public void setMaskLayer(String lname) {
- _maskLayer = lname;
- _mapView.paintLayers();
- }
- //
- }
-
- public static class MaskOutBeanBeanInfo extends BaseBeanInfo {
-
- public MaskOutBeanBeanInfo() {
- super(MaskOut.MaskOutBean.class);
- ExtendedPropertyDescriptor e = addProperty("maskLayer");
- e.setCategory("General").setPropertyEditorClass(MaskOut.LayerNameEditor.class);
- e.setDisplayName("Layer Name");
- e.setShortDescription("The name of the layers can be used as maskout");
- e = addProperty("mask");
- e.setCategory("General").setDisplayName("Is Maskout");
- }
- }
-
- public static class LayerNameEditor extends ComboBoxPropertyEditor {
-
- public LayerNameEditor() {
- super();
- String[] names = (String[]) getLayerNames().toArray(new String[0]);
- setAvailableValues(names);
-// Icon[] icons = new Icon[4];
-// Arrays.fill(icons, UIManager.getIcon("Tree.openIcon"));
-// setAvailableIcons(icons);
- }
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/script/MapForm.java b/MeteoInfoLib/src/main/java/org/meteoinfo/script/MapForm.java
index 87d2ac0c..9246949a 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/script/MapForm.java
+++ b/MeteoInfoLib/src/main/java/org/meteoinfo/script/MapForm.java
@@ -8,8 +8,8 @@ package org.meteoinfo.script;
import java.awt.BorderLayout;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
-import org.meteoinfo.layout.MapLayout;
-import org.meteoinfo.layout.MouseMode;
+import org.meteoinfo.geo.layout.MapLayout;
+import org.meteoinfo.geo.layout.MouseMode;
/**
*
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/script/MeteoInfoMap.java b/MeteoInfoLib/src/main/java/org/meteoinfo/script/MeteoInfoMap.java
index 82c15490..56ae1047 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/script/MeteoInfoMap.java
+++ b/MeteoInfoLib/src/main/java/org/meteoinfo/script/MeteoInfoMap.java
@@ -11,14 +11,14 @@ import java.util.logging.Logger;
import javax.swing.WindowConstants;
import org.meteoinfo.data.GridData;
-import org.meteoinfo.data.mapdata.MapDataManage;
-import org.meteoinfo.data.meteodata.DrawMeteoData;
+import org.meteoinfo.geo.mapdata.MapDataManage;
+import org.meteoinfo.geo.meteodata.DrawMeteoData;
import org.meteoinfo.data.meteodata.DrawType2D;
import org.meteoinfo.geometry.legend.PolygonBreak;
-import org.meteoinfo.layer.MapLayer;
-import org.meteoinfo.layout.MapLayout;
-import org.meteoinfo.legend.MapFrame;
-import org.meteoinfo.map.MapView;
+import org.meteoinfo.geo.layer.MapLayer;
+import org.meteoinfo.geo.layout.MapLayout;
+import org.meteoinfo.geo.legend.MapFrame;
+import org.meteoinfo.geo.mapview.MapView;
/**
*
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/script/MeteoInfoScript.java b/MeteoInfoLib/src/main/java/org/meteoinfo/script/MeteoInfoScript.java
index 3ee9a397..38641d1d 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/script/MeteoInfoScript.java
+++ b/MeteoInfoLib/src/main/java/org/meteoinfo/script/MeteoInfoScript.java
@@ -17,15 +17,16 @@ import org.meteoinfo.chart.ChartText;
import org.meteoinfo.chart.plot.XY1DPlot;
import org.meteoinfo.common.Extent;
import org.meteoinfo.data.GridData;
-import org.meteoinfo.data.mapdata.MapDataManage;
+import org.meteoinfo.geo.mapdata.MapDataManage;
import org.meteoinfo.data.meteodata.*;
+import org.meteoinfo.geo.meteodata.DrawMeteoData;
import org.meteoinfo.geometry.legend.LineStyles;
import org.meteoinfo.geometry.legend.PointStyle;
import org.meteoinfo.geometry.legend.PolygonBreak;
-import org.meteoinfo.layer.MapLayer;
-import org.meteoinfo.layout.MapLayout;
-import org.meteoinfo.legend.MapFrame;
-import org.meteoinfo.map.MapView;
+import org.meteoinfo.geo.layer.MapLayer;
+import org.meteoinfo.geo.layout.MapLayout;
+import org.meteoinfo.geo.legend.MapFrame;
+import org.meteoinfo.geo.mapview.MapView;
/**
*
diff --git a/MeteoInfoLib/src/test/java/map/frmMap.java b/MeteoInfoLib/src/test/java/map/frmMap.java
index 7ea8471f..6b129ad8 100644
--- a/MeteoInfoLib/src/test/java/map/frmMap.java
+++ b/MeteoInfoLib/src/test/java/map/frmMap.java
@@ -1,12 +1,12 @@
package map;
import org.meteoinfo.common.GenericFileFilter;
-import org.meteoinfo.data.mapdata.MapDataManage;
-import org.meteoinfo.layer.MapLayer;
-import org.meteoinfo.layout.MapLayout;
-import org.meteoinfo.legend.LayersLegend;
-import org.meteoinfo.map.MapView;
-import org.meteoinfo.map.MouseTools;
+import org.meteoinfo.geo.mapdata.MapDataManage;
+import org.meteoinfo.geo.layer.MapLayer;
+import org.meteoinfo.geo.layout.MapLayout;
+import org.meteoinfo.geo.legend.LayersLegend;
+import org.meteoinfo.geo.mapview.MapView;
+import org.meteoinfo.geo.mapview.MouseTools;
import javax.swing.*;
import java.awt.*;
diff --git a/hs_err_pid31056.log b/hs_err_pid31056.log
index b7cef7dd..383b5155 100644
--- a/hs_err_pid31056.log
+++ b/hs_err_pid31056.log
@@ -18,7 +18,7 @@
--------------- S U M M A R Y ------------
-Command Line: -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:53660,suspend=y,server=n -javaagent:C:\Users\dell\AppData\Local\JetBrains\IdeaIC2020.1\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8 org.meteoinfo.laboratory.MeteoInfoLab
+Command Line: -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:53660,suspend=y,server=n -javaagent:C:\Users\dell\AppData\Local\JetBrains\IdeaIC2020.1\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8 org.meteoinfo.lab.MeteoInfoLab
Host: Intel(R) Xeon(R) Silver 4210 CPU @ 2.20GHz, 40 cores, 63G, Windows 10 , 64 bit Build 18362 (10.0.18362.329)
Time: Sat Apr 18 10:19:59 2020 ?D1��������?����?? elapsed time: 51 seconds (0d 0h 0m 51s)
@@ -64,9 +64,9 @@ j org.python.core.PyCode.call(Lorg/python/core/ThreadState;Lorg/python/core/PyF
j org.python.core.Py.runCode(Lorg/python/core/PyCode;Lorg/python/core/PyObject;Lorg/python/core/PyObject;)Lorg/python/core/PyObject;+156
j org.python.core.__builtin__.execfile_flags(Ljava/lang/String;Lorg/python/core/PyObject;Lorg/python/core/PyObject;Lorg/python/core/CompilerFlags;)V+86
j org.python.util.PythonInterpreter.execfile(Ljava/lang/String;)V+16
-j org.meteoinfo.laboratory.gui.PythonInteractiveInterpreter.execfile(Ljava/lang/String;)V+10
-j org.meteoinfo.laboratory.gui.ConsoleDockable$3.doInBackground()Ljava/lang/String;+102
-j org.meteoinfo.laboratory.gui.ConsoleDockable$3.doInBackground()Ljava/lang/Object;+1
+j org.meteoinfo.lab.gui.PythonInteractiveInterpreter.execfile(Ljava/lang/String;)V+10
+j org.meteoinfo.lab.gui.ConsoleDockable$3.doInBackground()Ljava/lang/String;+102
+j org.meteoinfo.lab.gui.ConsoleDockable$3.doInBackground()Ljava/lang/Object;+1
j javax.swing.SwingWorker$1.call()Ljava/lang/Object;+14 java.desktop@11.0.5
j java.util.concurrent.FutureTask.run$$$capture()V+39 java.base@11.0.5
j java.util.concurrent.FutureTask.run()V+5 java.base@11.0.5
@@ -843,7 +843,7 @@ symbol engine: initialized successfully - sym options: 0x614 - pdb path: .;C:\Pr
VM Arguments:
jvm_args: -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:53660,suspend=y,server=n -javaagent:C:\Users\dell\AppData\Local\JetBrains\IdeaIC2020.1\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8
-java_command: org.meteoinfo.laboratory.MeteoInfoLab
+java_command: org.meteoinfo.lab.MeteoInfoLab
java_class_path (initial): D:\MyProgram\java\MeteoInfoDev\MeteoInfo\MeteoInfoLab\target\classes;D:\MyProgram\java\MeteoInfoDev\MeteoInfo\MeteoInfoLib\target\classes;C:\Users\dell\.m2\repository\edu\ucar\netcdfAll\5.1.0\netcdfAll-5.1.0.jar;C:\Users\dell\.m2\repository\com\l2fprod\l2fprod-common-all\0.1\l2fprod-common-all-0.1.jar;C:\Users\dell\.m2\repository\org\freehep\freehep-graphics2d\2.4\freehep-graphics2d-2.4.jar;C:\Users\dell\.m2\repository\org\freehep\freehep-graphicsbase\2.4\freehep-graphicsbase-2.4.jar;C:\Users\dell\.m2\repository\org\freehep\freehep-io\2.2.2\freehep-io-2.2.2.jar;C:\Users\dell\.m2\repository\junit\junit\4.10\junit-4.10.jar;C:\Users\dell\.m2\repository\org\hamcrest\hamcrest-core\1.1\hamcrest-core-1.1.jar;C:\Users\dell\.m2\repository\org\freehep\freehep-graphicsio-ps\2.4\freehep-graphicsio-ps-2.4.jar;C:\Users\dell\.m2\repository\org\freehep\freehep-graphicsio\2.4\freehep-graphicsio-2.4.jar;C:\Users\dell\.m2\repository\org\freehep\freehep-graphicsio-tests\2.4\freehep-graphicsio-tests-2.4.jar;C:\Users\dell\.m2\repository\org\scilab\forge\jlatexmath\1.0.7\jlatexmath-1.0.7.jar;C:\Users\dell\.m2\repository\org\scilab\forge\jlatexmath-font-greek\1.0.7\jlatexmath-font-greek-1.0.7.jar;C:\Users\dell\.m2\repository\org\scilab\forge\jlatexmath-font-cyrillic\1.0.7\jlatexmath-font-cyrillic-1.0.7.jar;C:\Users\dell\.m2\repository\org\python\jython-standalone\2.7.2\jython-standalone-2.7.2.jar;C:\Users\dell\.m2\repository\org\freehep\freehep-graphicsio-emf\2.4\freehep-graphicsio-emf-2.4.jar;C:\Users\dell\.m2\repository\org\freehep\freehep-graphicsio-pdf\2.4\freehep-graphicsio-pdf-2.4.jar;C:\Users\dell\.m2\repository\org\apache\commons\commons-imaging\1.0-alpha1\commons-imaging-1.0-alpha1.jar;C:\Users\dell\.m2\repository\com\toedter\jcalendar\1.4\jcalendar-1.4.jar;C:\Users\dell\.m2\repository\org\ejml\ejml-experimental\0.32\ejml-experimental-0.32.jar;C:\Users\dell\.m2\repository\org\ejml\ejml-core\0.32\ejml-core-0.32.jar;C:\Users\dell\.m2\repository\org\ejml\
Launcher Type: SUN_STANDARD
diff --git a/meteoinfo-chart/meteoinfo-chart.iml b/meteoinfo-chart/meteoinfo-chart.iml
index c16c9a62..6576bbf2 100644
--- a/meteoinfo-chart/meteoinfo-chart.iml
+++ b/meteoinfo-chart/meteoinfo-chart.iml
@@ -36,13 +36,17 @@
+
+
+
+
+
+
+
-
-
-
@@ -63,5 +67,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/meteoinfo-chart/pom.xml b/meteoinfo-chart/pom.xml
index 10268258..4ed930d7 100644
--- a/meteoinfo-chart/pom.xml
+++ b/meteoinfo-chart/pom.xml
@@ -92,6 +92,16 @@
freehep-graphicsio-ps
2.4
+
+ org.jogamp.gluegen
+ gluegen-rt-main
+ 2.3.2
+
+
+ org.jogamp.jogl
+ jogl-all-main
+ 2.3.2
+
\ No newline at end of file
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/Chart.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/Chart.java
deleted file mode 100644
index 66b3c7f8..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/Chart.java
+++ /dev/null
@@ -1,902 +0,0 @@
-/* This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-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.RenderingHints;
-import java.awt.Stroke;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
-import java.util.ArrayList;
-import java.util.List;
-import org.meteoinfo.chart.plot.MapPlot;
-import org.meteoinfo.chart.plot.Plot;
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.chart.drawing.Draw;
-
-/**
- *
- * @author Yaqiang Wang
- * yaqiang.wang@gmail.com
- */
-public class Chart {
-
- //
- private List plots;
- private int currentPlot;
- private int rowNum;
- private int columnNum;
- private ChartText title;
- private ChartText subTitle;
- private List texts;
- private ChartLegend legend;
- private Color background;
- //private boolean drawBackground;
- private boolean drawLegend;
- private Rectangle2D plotArea;
- private boolean antiAlias;
- private boolean symbolAntialias;
- private ChartPanel parent;
-
- //
- //
- /**
- * Constructor
- */
- public Chart() {
- this.drawLegend = false;
- this.background = Color.white;
- //this.drawBackground = true;
- this.antiAlias = false;
- this.symbolAntialias = true;
- this.rowNum = 1;
- this.columnNum = 1;
- this.plots = new ArrayList<>();
- this.currentPlot = -1;
- this.texts = new ArrayList<>();
- }
-
- /**
- * Constructor
- *
- * @param parent ChartPanel parent
- */
- public Chart(ChartPanel parent) {
- this();
- this.parent = parent;
- }
-
- /**
- * Constructor
- *
- * @param plot Plot
- * @param parent ChartPanel
- */
- public Chart(Plot plot, ChartPanel parent) {
- this(parent);
- this.plots.add(plot);
- }
-
- /**
- * Constructor
- *
- * @param plot Plot
- */
- public Chart(Plot plot) {
- this(plot, null);
- }
-
- /**
- * Constructor
- *
- * @param title Title
- * @param plot Plot
- * @param parent ChartPanel
- */
- public Chart(String title, Plot plot, ChartPanel parent) {
- this(plot, parent);
- if (title == null) {
- this.title = null;
- } else {
- this.title = new ChartText(title);
- }
- }
-
- /**
- * Constructor
- *
- * @param title Title
- * @param plot Plot
- */
- public Chart(String title, Plot plot) {
- this(title, plot, null);
- }
-
- //
- //
- /**
- * Set ChartPanel parent
- *
- * @param value ChartPanel
- */
- public void setParent(ChartPanel value) {
- this.parent = value;
- for (Plot plot : this.plots) {
- if (plot instanceof MapPlot) {
- ((MapPlot) plot).setParent(value);
- }
- }
- }
-
- /**
- * Get plot
- *
- * @return Plot
- */
- public List getPlots() {
- return plots;
- }
-
- /**
- * Get current plot
- *
- * @return Current plot
- */
- public Plot getCurrentPlot() {
- if (this.plots.isEmpty()) {
- return null;
- }
-
- if (this.currentPlot < 0 || this.currentPlot >= this.plots.size()) {
- this.currentPlot = this.plots.size() - 1;
- }
- return this.plots.get(this.currentPlot);
- }
-
- /**
- * Set current plot
- *
- * @param value Current plot
- */
- public void setCurrentPlot(Plot value) {
- if (this.plots.isEmpty()) {
- this.addPlot(value);
- //this.currentPlot = 0;
- } else if (this.currentPlot == -1) {
- this.plots.add(value);
- } else {
- if (this.currentPlot >= this.plots.size()) {
- this.currentPlot = this.plots.size() - 1;
- }
- Plot plot = this.plots.get(this.currentPlot);
- value.isSubPlot = plot.isSubPlot;
- value.columnIndex = plot.columnIndex;
- value.rowIndex = plot.rowIndex;
- this.plots.set(this.currentPlot, value);
- }
- }
-
- /**
- * Set current plot index
- *
- * @param value Current plot index
- */
- public void setCurrentPlot(int value) {
- this.currentPlot = value;
- }
-
- /**
- * Get the first plot
- *
- * @return Plot
- */
- public Plot getPlot() {
- if (this.plots.isEmpty()) {
- return null;
- }
-
- return this.plots.get(0);
- }
-
- /**
- * Get row number of sub plots
- *
- * @return Row number of sub plots
- */
- public int getRowNum() {
- return this.rowNum;
- }
-
- /**
- * Set row number of sub plots
- *
- * @param value Row number of sub plots
- */
- public void setRowNum(int value) {
- this.rowNum = value;
- }
-
- /**
- * Get column number of sub plots
- *
- * @return Column number of sub plots
- */
- public int getColumnNum() {
- return this.columnNum;
- }
-
- /**
- * Set column number of sub plots
- *
- * @param value Column number of sub plots
- */
- public void setColumnNum(int value) {
- this.columnNum = value;
- }
-
- /**
- * Get title
- *
- * @return Title
- */
- public ChartText getTitle() {
- return title;
- }
-
- /**
- * Set title
- *
- * @param value Title
- */
- public void setTitle(ChartText value) {
- title = value;
- }
-
- /**
- * Get sub title
- *
- * @return Sub title
- */
- public ChartText getSubTitle() {
- return subTitle;
- }
-
- /**
- * Set sub title
- *
- * @param value Sub title
- */
- public void setSubTitle(ChartText value) {
- subTitle = value;
- }
-
- /**
- * Get background
- *
- * @return Background
- */
- public Color getBackground() {
- return this.background;
- }
-
- /**
- * Set background
- *
- * @param value Background
- */
- public void setBackground(Color value) {
- this.background = value;
- }
-
-// /**
-// * Get if draw background
-// *
-// * @return Boolean
-// */
-// public boolean isDrawBackground() {
-// return this.drawBackground;
-// }
-
-// /**
-// * Set if draw background
-// *
-// * @param value Boolean
-// */
-// public void setDrawBackground(boolean value) {
-// this.drawBackground = value;
-// }
-
- /**
- * Get chart legend
- *
- * @return Chart legend
- */
- public ChartLegend getLegend() {
- return this.legend;
- }
-
- /**
- * Get if draw legend
- *
- * @return If draw legend
- */
- public boolean isDrawLegend() {
- return this.drawLegend;
- }
-
- /**
- * Set if draw legend
- *
- * @param value Boolean
- */
- public void setDrawLegend(boolean value) {
- this.drawLegend = value;
- }
-
- /**
- * Get plot area
- *
- * @return Plot area
- */
- public Rectangle2D getPlotArea() {
- return this.plotArea;
- }
-
- /**
- * Get if is anti-alias
- *
- * @return Boolean
- */
- public boolean isAntiAlias() {
- return this.antiAlias;
- }
-
- /**
- * Set if is anti-alias
- *
- * @param value Boolean
- */
- public void setAntiAlias(boolean value) {
- this.antiAlias = value;
- }
-
- /**
- * Get symbol antialias
- * @return Boolean
- */
- public boolean isSymbolAntialias() {
- return this.symbolAntialias;
- }
-
- /**
- * Set symbol antialias
- * @param value Boolean
- */
- public void setSymbolAntialias(boolean value) {
- this.symbolAntialias = value;
- }
-
- //
- //
- /**
- * Draw plot
- *
- * @param g Graphics2D
- * @param area Drawing area
- */
- public void draw(Graphics2D g, Rectangle2D area) {
- g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
- if (antiAlias) {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- //g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_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_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
- 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_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_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_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
- g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT);
- }
-
- AffineTransform oldMatrix = g.getTransform();
- Rectangle oldRegion = g.getClipBounds();
- g.setClip(area);
- g.translate(area.getX(), area.getY());
-
- //Draw background
- if (this.background != null) {
- g.setColor(background);
- g.fill(new Rectangle2D.Double(0, 0, area.getWidth(), area.getHeight()));
- }
-
- //Draw title
- float y = 5;
- if (title != null) {
- g.setColor(title.getColor());
- g.setFont(title.getFont());
- float x = (float) area.getWidth() / 2;
- //y -= this.title.getHeight(g) - 5;
- //FontMetrics metrics = g.getFontMetrics(title.getFont());
- //x -= metrics.stringWidth(title.getText()) / 2;
- //y += metrics.getHeight();
- int i = 0;
- for (String text : title.getTexts()) {
- Dimension dim = Draw.getStringDimension(text, g);
- if (i == 0) {
- y += dim.getHeight();
- }
- Draw.drawString(g, text, x - dim.width / 2, y);
- g.setFont(title.getFont());
- y += dim.height + title.getLineSpace();
- i += 1;
- }
- y += 5;
- }
-
- //Draw plot
- plotArea = this.getPlotArea(g, area);
- //plotArea = area;
- if (plotArea.getWidth() < 20 || plotArea.getHeight() < 20) {
- g.setTransform(oldMatrix);
- g.setClip(oldRegion);
- return;
- }
-
- if (this.plots.size() > 0) {
- //double zoom = this.getPositionAreaZoom(g, plotArea);
- //Margin tightInset = this.getPlotsTightInset(g, plotArea);
- Margin shrink = this.getPlotsShrink(g, plotArea);
- for (int i = 0; i < this.plots.size(); i++) {
- Plot plot = this.plots.get(i);
- plot.setSymbolAntialias(this.symbolAntialias);
- if (plot.isOuterPosActive()){
- if (plot.isSubPlot || plot.isSameShrink()) {
- plot.setPlotShrink(shrink);
- } else {
- //plot.setPlotShrink(this.getPlotShrink(g, area, plot));
- plot.setPlotShrink(this.getPlotShrink(g, plotArea, plot));
- }
- }
- if (plot instanceof MapPlot) {
- ((MapPlot) plot).setAntialias(this.antiAlias);
- }
- plot.draw(g, plotArea);
- }
- }
-
- //Draw text
- drawText(g, area);
-
- //Draw legend
- if (this.drawLegend) {
- Dimension dim = this.legend.getLegendDimension(g, new Dimension((int) area.getWidth(), (int) area.getHeight()));
- float x = 0;
- switch (this.legend.getPosition()) {
- case UPPER_CENTER_OUTSIDE:
- x = (float) area.getWidth() / 2 - dim.width / 2;
- y += 5;
- break;
- case LOWER_CENTER_OUTSIDE:
- x = (float) area.getWidth() / 2 - dim.width / 2;
- y += plotArea.getHeight() + 5;
- break;
- case LEFT_OUTSIDE:
- x = 10;
- y = (float) area.getHeight() / 2 - dim.height / 2;
- break;
- case RIGHT_OUTSIDE:
- x = (float) plotArea.getWidth() + 10;
- y = (float) area.getHeight() / 2 - dim.height / 2;
- break;
- }
- this.legend.draw(g, new PointF(x, y));
- }
-
- g.setTransform(oldMatrix);
- g.setClip(oldRegion);
- }
-
- void drawText(Graphics2D g, Rectangle2D area) {
- float x, y;
- for (ChartText text : this.texts) {
- x = (float) (area.getWidth() * text.getX());
- y = (float) (area.getHeight() * (1 - text.getY()));
- Dimension dim = Draw.getStringDimension(text.getText(), g);
- Rectangle.Double rect = new Rectangle.Double(x, y, dim.getWidth(), dim.getHeight());
- if (text.isFill()) {
- g.setColor(text.getBackground());
- g.fill(rect);
- }
- if (text.isDrawNeatline()) {
- g.setColor(text.getNeatlineColor());
- Stroke oldStroke = g.getStroke();
- g.setStroke(new BasicStroke(text.getNeatlineSize()));
- g.draw(rect);
- g.setStroke(oldStroke);
- }
- g.setFont(text.getFont());
- g.setColor(text.getColor());
- Draw.drawString(g, text.getText(), x, y);
- }
- }
-
- private Rectangle2D getPlotArea(Graphics2D g, Rectangle2D area) {
- Rectangle2D pArea = new Rectangle2D.Double();
- int edge = 0;
- int top = edge;
- int left = edge;
- int right = edge;
- int bottom = edge;
- if (this.title != null) {
- top += this.title.getTrueDimension(g).height + 12;
- }
- pArea.setRect(left, top, area.getWidth() - left - right, area.getHeight() - top - bottom);
-
- return pArea;
- }
-
- private Rectangle2D getPlotArea_bak(Graphics2D g, Rectangle2D area) {
- Rectangle2D pArea = new Rectangle2D.Double();
- int edge = 2;
- int top = edge;
- int left = edge;
- int right = edge;
- int bottom = edge;
- if (this.title != null) {
- top += this.title.getTrueDimension(g).height + 10;
- }
- if (this.drawLegend) {
- Dimension dim = this.legend.getLegendDimension(g, new Dimension((int) area.getWidth(), (int) area.getHeight()));
- switch (this.legend.getPosition()) {
- case UPPER_CENTER_OUTSIDE:
- top += dim.height + 10;
- break;
- case LOWER_CENTER_OUTSIDE:
- bottom += dim.height + 10;
- break;
- case LEFT_OUTSIDE:
- left += dim.width + 10;
- break;
- case RIGHT_OUTSIDE:
- right += dim.width + 10;
- break;
- }
- }
- pArea.setRect(left, top, area.getWidth() - left - right, area.getHeight() - top - bottom);
-
- return pArea;
- }
-
- private Margin getPlotShrink(Graphics2D g, Rectangle2D area, Plot plot) {
- Margin shrink;
- if (plot.isSubPlot) {
- double rowHeight = area.getHeight() / this.rowNum;
- double colWidth = area.getWidth() / this.columnNum;
- double x = area.getX() + plot.columnIndex * colWidth;
- double y = area.getY() + plot.rowIndex * rowHeight;
- Rectangle2D subPlotArea = new Rectangle2D.Double(x, y, colWidth, rowHeight);
- plot.setOuterPositionArea(subPlotArea);
- plot.updatePosition(area, subPlotArea);
- Rectangle2D positionArea = plot.getPositionArea(area);
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- shrink = plot.getPlotShrink();
- } else {
- plot.setOuterPositionArea(area);
- Rectangle2D positionArea = plot.getPositionArea(area);
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- shrink = plot.getPlotShrink();
- //shrink = tightInset;
- }
-
- return shrink;
- }
-
- private Margin getPlotsShrink(Graphics2D g, Rectangle2D area) {
- Margin pshrink = null, shrink;
- for (int i = 0; i < this.plots.size(); i++) {
- Plot plot = this.plots.get(i);
- plot.setOuterPositionArea(plot.getOuterPositionArea(area));
- Rectangle2D positionArea = plot.getPositionArea(area);
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- shrink = plot.getPlotShrink();
- if (i == 0) {
- pshrink = shrink;
- } else if (pshrink != null) {
- pshrink = pshrink.extend(shrink);
- }
- }
-
- return pshrink;
- }
-
- private Margin getPlotsShrink_bak(Graphics2D g, Rectangle2D area) {
- Margin pshrink = null, shrink;
- for (int i = 0; i < this.plots.size(); i++) {
- Plot plot = this.plots.get(i);
- if (plot.isSubPlot) {
- double rowHeight = area.getHeight() / this.rowNum;
- double colWidth = area.getWidth() / this.columnNum;
- double x = area.getX() + plot.columnIndex * colWidth;
- double y = area.getY() + plot.rowIndex * rowHeight;
- Rectangle2D subPlotArea = new Rectangle2D.Double(x, y, colWidth, rowHeight);
- plot.setOuterPositionArea(subPlotArea);
- plot.updatePosition(area, subPlotArea);
- Rectangle2D positionArea = plot.getPositionArea(area);
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- shrink = plot.getPlotShrink();
- } else {
- plot.setOuterPositionArea(area);
- Rectangle2D positionArea = plot.getPositionArea(area);
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- shrink = plot.getPlotShrink();
- }
- if (i == 0) {
- pshrink = shrink;
- } else if (pshrink != null) {
- pshrink = pshrink.extend(shrink);
- }
- }
-
- return pshrink;
- }
-
- private Margin getPlotsTightInset(Graphics2D g, Rectangle2D area) {
- int i = 0;
- Margin pti = null, tightInset;
- for (Plot plot : this.plots) {
- if (plot.isSubPlot) {
- double rowHeight = area.getHeight() / this.rowNum;
- double colWidth = area.getWidth() / this.columnNum;
- double x = area.getX() + plot.columnIndex * colWidth;
- double y = area.getY() + plot.rowIndex * rowHeight;
- Rectangle2D subPlotArea = new Rectangle2D.Double(x, y, colWidth, rowHeight);
- plot.setOuterPositionArea(subPlotArea);
- plot.updatePosition(area, subPlotArea);
- Rectangle2D positionArea = plot.getPositionArea();
- plot.setPositionArea(positionArea);
- tightInset = plot.getTightInset(g, positionArea);
- } else {
- plot.setOuterPositionArea(area);
- Rectangle2D positionArea = plot.getPositionArea();
- plot.setPositionArea(positionArea);
- tightInset = plot.getTightInset(g, positionArea);
- }
- if (i == 0) {
- pti = tightInset;
- } else if (pti != null) {
- pti = pti.extend(tightInset);
- }
- i += 1;
- }
-
- return pti;
- }
-
- private double getPositionAreaZoom(Graphics2D g, Rectangle2D area) {
- double zoom = 1.0;
- for (Plot plot : this.plots) {
- if (plot.isSubPlot) {
- double rowHeight = area.getHeight() / this.rowNum;
- double colWidth = area.getWidth() / this.columnNum;
- double x = area.getX() + plot.columnIndex * colWidth;
- double y = area.getY() + plot.rowIndex * rowHeight;
- Rectangle2D subPlotArea = new Rectangle2D.Double(x, y, colWidth, rowHeight);
- plot.setOuterPositionArea(subPlotArea);
- plot.updatePosition(area, subPlotArea);
- Rectangle2D positionArea = plot.getPositionArea();
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- double zoom1 = plot.updatePostionAreaZoom();
- if (zoom1 < zoom) {
- zoom = zoom1;
- }
- } else {
- plot.setOuterPositionArea(area);
- Rectangle2D positionArea = plot.getPositionArea();
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- double zoom1 = plot.updatePostionAreaZoom();
- if (zoom1 < zoom) {
- zoom = zoom1;
- }
- }
- }
-
- return zoom;
- }
-
- private Rectangle2D getSubPlotArea(Graphics2D g, Plot plot, Rectangle2D area) {
- if (plot.isSubPlot) {
- double rowHeight = area.getHeight() / this.rowNum;
- double colWidth = area.getWidth() / this.columnNum;
- double x = area.getX() + plot.columnIndex * colWidth;
- double y = area.getY() + plot.rowIndex * rowHeight;
- Rectangle2D subPlotArea = new Rectangle2D.Double(x, y, colWidth, rowHeight);
- plot.setOuterPositionArea(subPlotArea);
- plot.updatePosition(area, subPlotArea);
- Rectangle2D positionArea = plot.getPositionArea();
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- double zoom = plot.updatePostionAreaZoom();
- plot.setPositionAreaZoom(zoom);
- return subPlotArea;
- } else {
- plot.setOuterPositionArea(area);
- Rectangle2D positionArea = plot.getPositionArea();
- plot.setPositionArea(positionArea);
- Margin tightInset = plot.getTightInset(g, positionArea);
- plot.setTightInset(tightInset);
- double zoom = plot.updatePostionAreaZoom();
- plot.setPositionAreaZoom(zoom);
- //return tightInset.getArea(positionArea);
- return area;
- }
- }
-
- /**
- * Get graph area
- *
- * @return Get graph area
- */
- public Rectangle2D getGraphArea() {
- Rectangle2D rect = this.plots.get(0).getPositionArea();
- double left = rect.getX() + this.plotArea.getX();
- double top = rect.getY() + this.plotArea.getY();
- return new Rectangle2D.Double(left, top, rect.getWidth(), rect.getHeight());
- }
-
- /**
- * Find a plot by point
- *
- * @param x X
- * @param y Y
- * @return Plot
- */
- public Plot findPlot(int x, int y) {
- for (Plot plot : this.plots) {
- Rectangle2D area = plot.getPositionArea();
- if (area.contains(x, y)) {
- return plot;
- }
- }
-
- return null;
- }
-
- /**
- * Clear plots
- */
- public void clearPlots() {
- this.plots.clear();
- }
-
- /**
- * Clear texts
- */
- public void clearTexts() {
- this.texts.clear();
- }
-
- /**
- * Remove a plot
- *
- * @param plot The plot
- */
- public void removePlot(Plot plot) {
- this.plots.remove(plot);
- }
-
- /**
- * Add a plot
- *
- * @param plot Plot
- */
- public void addPlot(Plot plot) {
- if (plot instanceof MapPlot) {
- ((MapPlot) plot).setParent(parent);
- }
- this.plots.add(plot);
- }
-
- /**
- * Set plot
- *
- * @param plot Plot
- */
- public void setPlot(Plot plot) {
- if (plot instanceof MapPlot) {
- ((MapPlot) plot).setParent(parent);
- }
- this.plots.clear();
- this.plots.add(plot);
- }
-
- /**
- * Get plot by plot index
- *
- * @param plotIdx Plot index - begin with 1
- * @return Plot index
- */
- public Plot getPlot(int plotIdx) {
- for (Plot plot : this.plots) {
- int pIdx = plot.rowIndex * this.columnNum + plot.columnIndex + 1;
- if (pIdx == plotIdx) {
- return plot;
- }
- }
-
- if (plotIdx > 0 && plotIdx <= this.plots.size())
- return this.plots.get(plotIdx - 1);
- else
- return null;
- }
-
- /**
- * Get plot index
- * @param plot The plot
- * @return Plot index
- */
- public int getPlotIndex(Plot plot){
- return this.plots.indexOf(plot);
- }
-
- /**
- * Check if has web map layer
- *
- * @return Boolean
- */
- public boolean hasWebMap() {
- for (Plot plot : this.plots) {
- if (plot instanceof MapPlot) {
- MapPlot mp = (MapPlot) plot;
- if (mp.hasWebMapLayer()) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- /**
- * Add text
- *
- * @param text Text
- */
- public void addText(ChartText text) {
- this.texts.add(text);
- }
- //
-
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartColorBar.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartColorBar.java
deleted file mode 100644
index 3e715c75..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartColorBar.java
+++ /dev/null
@@ -1,1046 +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;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Line2D;
-import java.awt.geom.Path2D;
-import java.util.ArrayList;
-import java.util.List;
-import org.meteoinfo.chart.plot.XAlign;
-import org.meteoinfo.chart.plot.YAlign;
-import org.meteoinfo.common.PointD;
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.chart.drawing.Draw;
-import org.meteoinfo.common.DataConvert;
-import org.meteoinfo.chart.legend.ColorBreak;
-import org.meteoinfo.chart.legend.LegendScheme;
-import org.meteoinfo.chart.legend.LegendType;
-import org.meteoinfo.chart.legend.PointBreak;
-import org.meteoinfo.chart.legend.PolygonBreak;
-import org.meteoinfo.chart.legend.PolylineBreak;
-import org.meteoinfo.geometry.shape.ShapeTypes;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class ChartColorBar extends ChartLegend {
-
- //
- private List tickLocations;
- private List tickLabels;
- private boolean autoTick;
- private boolean insideTick;
- private float tickLength;
- private boolean tickVisible;
- private float tickWidth;
- private Color tickColor;
- private boolean drawMinLabel;
- private boolean drawMaxLabel;
-
- //
- //
- /**
- * Constructor
- *
- * @param ls LegendScheme
- */
- public ChartColorBar(LegendScheme ls) {
- super(ls);
-
- this.tickLocations = new ArrayList<>();
- this.tickLabels = new ArrayList<>();
- this.autoTick = true;
- this.insideTick = true;
- this.tickLength = 5;
- this.tickVisible = true;
- this.tickWidth = 1;
- this.tickColor = Color.black;
- this.drawMinLabel = false;
- this.drawMaxLabel = false;
- }
-
- //
- //
- /**
- * Tick locations
- *
- * @return Tick locations
- */
- public List getTickLocations() {
- return this.tickLocations;
- }
-
- /**
- * Set tick locations
- *
- * @param value Tick locations
- */
- public void setTickLocations(List value) {
- this.tickLocations.clear();
- this.tickLabels.clear();
- for (Number v : value) {
- this.tickLocations.add(v.doubleValue());
- this.tickLabels.add(new ChartText(DataConvert.removeTailingZeros(String.valueOf(v))));
- }
- this.autoTick = false;
- }
-
- /**
- * Set tick locations
- *
- * @param value Tick locations
- */
- public void setTickLocations(double[] value) {
- this.tickLocations.clear();
- this.tickLabels.clear();
- for (double v : value) {
- this.tickLocations.add(v);
- this.tickLabels.add(new ChartText(DataConvert.removeTailingZeros(String.valueOf(v))));
- }
- this.autoTick = false;
- }
-
- /**
- * Get tick labels
- *
- * @return Tick labels
- */
- public List getTickLabels() {
- return this.tickLabels;
- }
-
- /**
- * Get tick label text
- *
- * @return Tick label text
- */
- public List getTickLabelText() {
- List strs = new ArrayList<>();
- for (ChartText ct : this.tickLabels) {
- strs.add(ct.toString());
- }
-
- return strs;
- }
-
- /**
- * Set tick label text
- *
- * @param value Tick label text
- */
- public void setTickLabelText(List value) {
- this.tickLabels = new ArrayList<>();
- for (String v : value) {
- this.tickLabels.add(new ChartText(v));
- }
- this.autoTick = false;
- }
-
- /**
- * Set tick labels.
- *
- * @param value Tick labels
- */
- public void setTickLabels(List value) {
- this.tickLabels = value;
- }
-
- /**
- * Set tick labels
- *
- * @param value Tick labels
- */
- public void setTickLabels_Number(List value) {
- this.tickLabels = new ArrayList<>();
- for (Number v : value) {
- this.tickLabels.add(new ChartText(v.toString()));
- }
- this.autoTick = false;
- }
-
- /**
- * Get if is auto tick labels
- *
- * @return Boolean
- */
- public boolean isAutoTick() {
- return this.autoTick;
- }
-
- /**
- * Set if auto tick labels
- *
- * @param value Boolean
- */
- public void setAutoTick(boolean value) {
- this.autoTick = value;
- }
-
- /**
- * Get tick length
- *
- * @return Tick length
- */
- public float getTickLength() {
- return this.tickLength;
- }
-
- /**
- * Set tick length
- *
- * @param value Tick length
- */
- public void setTickLength(int value) {
- this.tickLength = value;
- }
-
- /**
- * Get if is inside tick
- *
- * @return Boolean
- */
- public boolean isInsideTick() {
- return this.insideTick;
- }
-
- /**
- * Set if is inside tick
- *
- * @param value Boolean
- */
- public void setInsideTick(boolean value) {
- this.insideTick = value;
- }
-
- /**
- * Get if is tick visible
- * @return Boolean
- */
- public boolean isTickVisible() {
- return this.tickVisible;
- }
-
- /**
- * Set if is tick visible
- * @param value Boolean
- */
- public void setTickVisible(boolean value) {
- this.tickVisible = value;
- }
-
- /**
- * Get tick line width
- * @return Tick line width
- */
- public float getTickWidth() {
- return this.tickWidth;
- }
-
- /**
- * Set tick line width
- * @param value Tick line width
- */
- public void setTickWidth(float value) {
- this.tickWidth = value;
- }
-
- /**
- * Get tick color
- * @return Tick color
- */
- public Color getTickColor() {
- return this.tickColor;
- }
-
- /**
- * Set tick color
- * @param value Tick color
- */
- public void setTickColor(Color value) {
- this.tickColor = value;
- }
-
- /**
- * Get if draw minimum value label
- *
- * @return Boolean
- */
- public boolean isDrawMinLabel() {
- return this.drawMinLabel;
- }
-
- /**
- * Set if draw minimum value label
- *
- * @param value Boolean
- */
- public void setDrawMinLabel(boolean value) {
- this.drawMinLabel = value;
- }
-
- /**
- * Get if draw maximum value label
- *
- * @return Boolean
- */
- public boolean isDrawMaxLabel() {
- return this.drawMaxLabel;
- }
-
- /**
- * Set if draw maximum value label
- *
- * @param value Boolean
- */
- public void setDrawMaxLabel(boolean value) {
- this.drawMaxLabel = value;
- }
-
- //
- //
- /**
- * Draw legend
- *
- * @param g Graphics2D
- * @param point Start point
- */
- @Override
- public void draw(Graphics2D g, PointF point) {
-
- AffineTransform oldMatrix = g.getTransform();
- g.translate(point.X + this.xshift, point.Y + this.yshift);
-
- //Draw background color
- if (this.drawBackground) {
- g.setColor(this.background);
- g.fill(new Rectangle.Float(0, 0, this.width, this.height));
- }
-
- //Draw legend
- g.setStroke(new BasicStroke(1));
- switch (this.orientation) {
- case HORIZONTAL:
- this.drawHorizontalBarLegend(g, legendScheme);
- break;
- case VERTICAL:
- this.drawVerticalBarLegend(g, legendScheme);
- break;
- }
-
- //Draw neatline
- if (drawNeatLine) {
- Rectangle.Float mapRect = new Rectangle.Float(0, 0, this.width, this.height);
- g.setColor(neatLineColor);
- g.setStroke(new BasicStroke(neatLineSize));
- g.draw(mapRect);
- }
-
- g.setTransform(oldMatrix);
- }
-
- private void drawTickLine(Graphics2D g, PointF sP, float tickLen, boolean vertical, float shift) {
- if (vertical) {
- if (this.insideTick) {
- g.draw(new Line2D.Float(sP.X + shift, sP.Y, sP.X + shift, sP.Y - tickLen));
- } else {
- g.draw(new Line2D.Float(sP.X + shift, sP.Y, sP.X + shift, sP.Y + tickLen));
- sP.Y += tickLen;
- }
- sP.Y += 5;
- } else {
- if (this.insideTick) {
- g.draw(new Line2D.Float(sP.X - tickLen, sP.Y + shift, sP.X, sP.Y + shift));
- } else {
- g.draw(new Line2D.Float(sP.X, sP.Y + shift, sP.X + tickLen, sP.Y + shift));
- sP.X += tickLen;
- }
- sP.X += 5;
- }
- }
-
- private void drawTickLine(Graphics2D g, PointD sP, float tickLen, boolean vertical, double shift) {
- if (vertical) {
- if (this.insideTick) {
- g.draw(new Line2D.Double(sP.X + shift, sP.Y, sP.X + shift, sP.Y - tickLen));
- } else {
- g.draw(new Line2D.Double(sP.X + shift, sP.Y, sP.X + shift, sP.Y + tickLen));
- sP.Y += tickLen;
- }
- sP.Y += 5;
- } else {
- if (this.insideTick) {
- g.draw(new Line2D.Double(sP.X - tickLen, sP.Y + shift, sP.X, sP.Y + shift));
- } else {
- g.draw(new Line2D.Double(sP.X, sP.Y + shift, sP.X + tickLen, sP.Y + shift));
- sP.X += tickLen;
- }
- sP.X += 5;
- }
- }
-
- private void drawHorizontalBarLegend(Graphics2D g, LegendScheme aLS) {
- PointD aP = new PointD(0, 0);
- PointD sP = new PointD(0, 0);
- boolean DrawShape = true, DrawFill = true, DrawOutline = false;
- Color FillColor = Color.red, OutlineColor = Color.black;
- String caption;
-
- int bNum = aLS.getBreakNum();
- if (aLS.getLegendBreaks().get(bNum - 1).isNoData()) {
- bNum -= 1;
- }
-
- List labelIdxs = new ArrayList<>();
- List tLabels = new ArrayList<>();
- if (this.autoTick) {
- int tickGap = this.getTickGap(g);
- int sIdx = (bNum % tickGap) / 2;
- int labNum = bNum - 1;
- if (aLS.getLegendType() == LegendType.UniqueValue) {
- labNum += 1;
- } else if (this.drawMinLabel) {
- sIdx = 0;
- labNum = bNum;
- }
- while (sIdx < labNum) {
- labelIdxs.add(sIdx);
- sIdx += tickGap;
- }
- } else {
- int tickIdx;
- for (int i = 0; i < bNum; i++) {
- ColorBreak cb = aLS.getLegendBreaks().get(i);
- if (i == bNum - 1) {
- if (cb.getStartValue().equals(cb.getEndValue()))
- continue;
- }
- double v = Double.parseDouble(cb.getEndValue().toString());
- if (this.tickLocations.contains(v)) {
- labelIdxs.add(i);
- tickIdx = this.tickLocations.indexOf(v);
- tLabels.add(this.tickLabels.get(tickIdx).getText());
- }
- }
- }
-
- this._hBarHeight = (double) this.legendWidth / this.aspect;
- _vBarWidth = (double) this.legendWidth / bNum;
- float y_shift = 0;
- if (this.label != null){
- switch (this.labelLocation){
- case "top":
- case "in":
- y_shift = this.label.getDimension(g).height + 5;
- break;
- }
- }
- int idx;
- aP.Y = y_shift;
- for (int i = 0; i < bNum; i++) {
- idx = i;
- switch (aLS.getShapeType()) {
- case Point:
- PointBreak aPB = (PointBreak) aLS.getLegendBreaks().get(idx);
- DrawShape = aPB.isDrawShape();
- DrawFill = aPB.isDrawFill();
- FillColor = aPB.getColor();
- break;
- case Polyline:
- PolylineBreak aPLB = (PolylineBreak) aLS.getLegendBreaks().get(idx);
- DrawShape = aPLB.getDrawPolyline();
- FillColor = aPLB.getColor();
- break;
- case Polygon:
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx);
- DrawShape = aPGB.isDrawShape();
- DrawFill = aPGB.isDrawFill();
- FillColor = aPGB.getColor();
- break;
- case Image:
- ColorBreak aCB = aLS.getLegendBreaks().get(idx);
- DrawShape = true;
- DrawFill = true;
- FillColor = aCB.getColor();
- break;
- }
-
- if (DrawShape) {
- if (this.extendRect) {
- if (aLS.getShapeType() == ShapeTypes.Polygon) {
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx).clone();
- aPGB.setDrawOutline(false);
- Draw.drawPolygonSymbol(aP.X, aP.Y, _vBarWidth, _hBarHeight, aPGB, g);
- } else {
- Draw.drawPolygonSymbol(aP.X, aP.Y, FillColor, OutlineColor, _vBarWidth,
- _hBarHeight, DrawFill, DrawOutline, g);
- }
- } else {
- double extendw = _vBarWidth;
- if (this.autoExtendFrac) {
- extendw = _hBarHeight;
- }
- if (i == 0) {
- PointD[] Points = new PointD[4];
- Points[0] = new PointD();
- Points[0].X = _vBarWidth - extendw;
- Points[0].Y = aP.Y + _hBarHeight * 0.5;
- Points[1] = new PointD();
- Points[1].X = _vBarWidth;
- Points[1].Y = aP.Y;
- Points[2] = new PointD();
- Points[2].X = _vBarWidth;
- Points[2].Y = aP.Y + _hBarHeight;
- Points[3] = new PointD();
- Points[3].X = _vBarWidth - extendw;
- Points[3].Y = aP.Y + _hBarHeight * 0.5;
- if (aLS.getShapeType() == ShapeTypes.Polygon) {
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx).clone();
- aPGB.setDrawOutline(false);
- Draw.drawPolygon(Points, aPGB, g);
- } else {
- Draw.drawPolygon(Points, FillColor, OutlineColor, DrawFill, DrawOutline, g);
- }
- } else if (i == bNum - 1) {
- PointD[] Points = new PointD[4];
- Points[0] = new PointD();
- Points[0].X = i * _vBarWidth - 1.0f;
- Points[0].Y = aP.Y + _hBarHeight;
- Points[1] = new PointD();
- Points[1].X = i * _vBarWidth - 1.0f;
- Points[1].Y = aP.Y;
- Points[2] = new PointD();
- Points[2].X = i * _vBarWidth + extendw;
- Points[2].Y = aP.Y + _hBarHeight * 0.5;
- Points[3] = new PointD();
- Points[3].X = i * _vBarWidth - 1.0f;
- Points[3].Y = aP.Y + _hBarHeight;
- if (aLS.getShapeType() == ShapeTypes.Polygon) {
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx).clone();
- aPGB.setDrawOutline(false);
- Draw.drawPolygon(Points, aPGB, g);
- } else {
- Draw.drawPolygon(Points, FillColor, OutlineColor, DrawFill, DrawOutline, g);
- }
- } else if (aLS.getShapeType() == ShapeTypes.Polygon) {
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx).clone();
- aPGB.setDrawOutline(false);
- Draw.drawPolygonSymbol(aP.X, aP.Y, _vBarWidth, _hBarHeight, aPGB, g);
- } else {
- Draw.drawPolygonSymbol(aP.X, aP.Y, FillColor, OutlineColor, _vBarWidth,
- _hBarHeight, DrawFill, DrawOutline, g);
- }
- }
- }
- aP.X += _vBarWidth;
- }
- //Draw neatline
- g.setStroke(new BasicStroke(this.neatLineSize));
- g.setColor(this.neatLineColor);
- if (this.extendRect) {
- g.draw(new Rectangle.Double(0, y_shift, this._vBarWidth * bNum, this._hBarHeight));
- } else {
- double extendw = _vBarWidth;
- if (this.autoExtendFrac) {
- extendw = _hBarHeight;
- }
- Path2D p = new Path2D.Double();
- p.moveTo(_vBarWidth - extendw, this._hBarHeight / 2 + y_shift);
- p.lineTo(this._vBarWidth, y_shift);
- p.lineTo(this._vBarWidth * (bNum - 1), y_shift);
- p.lineTo(this._vBarWidth * (bNum - 1) + extendw, this._hBarHeight / 2 + y_shift);
- p.lineTo(this._vBarWidth * (bNum - 1), this._hBarHeight + y_shift);
- p.lineTo(this._vBarWidth, this._hBarHeight + y_shift);
- p.closePath();
- g.draw(p);
- }
- //Draw tick and label
- aP.X = -_vBarWidth / 2;
- float tickLen = this.tickLength;
- if (this.insideTick) {
- if (this._hBarHeight < tickLen) {
- tickLen = (int) this._hBarHeight;
- }
- }
- g.setStroke(new BasicStroke(this.tickWidth));
- g.setFont(tickLabelFont);
- g.setColor(this.tickColor);
- idx = 0;
- for (int i = 0; i < bNum; i++) {
- aP.X += _vBarWidth;
- aP.Y = _hBarHeight / 2 + y_shift;
- if (labelIdxs.contains(i)) {
- ColorBreak cb = aLS.getLegendBreaks().get(i);
- if (this.autoTick) {
- if (aLS.getLegendType() == LegendType.UniqueValue) {
- caption = cb.getCaption();
- } else {
- caption = DataConvert.removeTailingZeros(cb.getEndValue().toString());
- }
- } else {
- caption = tLabels.get(idx);
- }
-
- if (aLS.getLegendType() == LegendType.UniqueValue) {
- sP.X = aP.X;
- sP.Y = aP.Y + _hBarHeight / 2 + 5;
- g.setColor(this.tickLabelColor);
- if (this.tickLabelAngle == 0) {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.CENTER, YAlign.TOP, this.tickLabelAngle, true);
- } else if (this.tickLabelAngle < 45) {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.RIGHT, YAlign.TOP, this.tickLabelAngle, true);
- } else {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.RIGHT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- } else {
- sP.X = aP.X + _vBarWidth / 2;
- sP.Y = aP.Y + _hBarHeight / 2;
- PointD ssP = (PointD)sP.clone();
- if (this.autoTick) {
- if (i < bNum - 1) {
- g.setColor(this.tickColor);
- this.drawTickLine(g, sP, tickLen, true, 0);
- g.setColor(this.tickLabelColor);
- if (this.tickLabelAngle == 0) {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.CENTER, YAlign.TOP, this.tickLabelAngle, true);
- } else if (this.tickLabelAngle < 45) {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.RIGHT, YAlign.TOP, this.tickLabelAngle, true);
- } else {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.RIGHT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- if (this.drawMinLabel && i == 0) {
- g.setColor(this.tickColor);
- this.drawTickLine(g, ssP, tickLen, true, -this._vBarWidth);
- caption = DataConvert.removeTailingZeros(cb.getStartValue().toString());
- g.setColor(this.tickLabelColor);
- //Draw.drawString(g, ssP.X - this._vBarWidth, ssP.Y, caption, XAlign.CENTER, YAlign.TOP, this.tickLabelAngle, true);
- if (this.tickLabelAngle == 0) {
- Draw.drawString(g, ssP.X - this._vBarWidth, ssP.Y, caption, XAlign.CENTER, YAlign.TOP, this.tickLabelAngle, true);
- } else if (this.tickLabelAngle < 45) {
- Draw.drawString(g, ssP.X - this._vBarWidth, ssP.Y, caption, XAlign.RIGHT, YAlign.TOP, this.tickLabelAngle, true);
- } else {
- Draw.drawString(g, ssP.X - this._vBarWidth, ssP.Y, caption, XAlign.RIGHT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- }
- } else if (this.drawMaxLabel) {
- g.setColor(this.tickColor);
- this.drawTickLine(g, sP, tickLen, true, 0);
- g.setColor(this.tickLabelColor);
- if (this.tickLabelAngle == 0) {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.CENTER, YAlign.TOP, this.tickLabelAngle, true);
- } else if (this.tickLabelAngle < 45) {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.RIGHT, YAlign.TOP, this.tickLabelAngle, true);
- } else {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.RIGHT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- }
- } else {
- if (i == 0 && this.tickLocations.get(idx) == Double.parseDouble(cb.getStartValue().toString())) {
- g.setColor(this.tickColor);
- this.drawTickLine(g, sP, tickLen, true, -this._vBarWidth);
- g.setColor(this.tickLabelColor);
- //Draw.drawString(g, sP.X - this._vBarWidth, sP.Y, caption, XAlign.CENTER, YAlign.TOP, this.tickLabelAngle, true);
- if (this.tickLabelAngle == 0) {
- Draw.drawString(g, sP.X - this._vBarWidth, sP.Y, caption, XAlign.CENTER, YAlign.TOP, this.tickLabelAngle, true);
- } else if (this.tickLabelAngle < 45) {
- Draw.drawString(g, sP.X - this._vBarWidth, sP.Y, caption, XAlign.RIGHT, YAlign.TOP, this.tickLabelAngle, true);
- } else {
- Draw.drawString(g, sP.X - this._vBarWidth, sP.Y, caption, XAlign.RIGHT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- } else {
- g.setColor(this.tickColor);
- this.drawTickLine(g, sP, tickLen, true, 0);
- g.setColor(this.tickLabelColor);
- if (this.tickLabelAngle == 0) {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.CENTER, YAlign.TOP, this.tickLabelAngle, true);
- } else if (this.tickLabelAngle < 45) {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.RIGHT, YAlign.TOP, this.tickLabelAngle, true);
- } else {
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.RIGHT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- }
- }
- }
- idx += 1;
- }
- }
-
- //Draw label
- double sx, sy;
- if (this.label != null) {
- g.setFont(this.label.getFont());
- g.setColor(this.label.getColor());
- switch (this.labelLocation) {
- case "top":
- case "in":
- sx = this.legendWidth * 0.5;
- sy = 2;
- Draw.drawString(g, sx, sy, label.getText(), XAlign.CENTER, YAlign.TOP, label.isUseExternalFont());
- break;
- case "right":
- sx = this.legendWidth + 5;
- sy = this._hBarHeight * 0.5;
- Draw.drawString(g, sx, sy, label.getText(), XAlign.LEFT, YAlign.CENTER, label.isUseExternalFont());
- break;
- case "left":
- sx = -5;
- sy = this._hBarHeight * 0.5;
- Draw.drawString(g, sx, sy, label.getText(), XAlign.RIGHT, YAlign.CENTER, label.isUseExternalFont());
- break;
- default:
- sx = this.legendWidth * 0.5;
- sy = this.height - 2;
- Draw.drawString(g, sx, sy, label.getText(), XAlign.CENTER, YAlign.BOTTOM, label.isUseExternalFont());
- break;
- }
- }
- }
-
- private void drawVerticalBarLegend(Graphics2D g, LegendScheme aLS) {
- PointD aP = new PointD(0, 0);
- PointD sP = new PointD(0, 0);
- boolean DrawShape = true, DrawFill = true, DrawOutline = false;
- Color FillColor = Color.red, OutlineColor = Color.black;
- String caption;
-
- int bNum = aLS.getBreakNum();
- if (aLS.getLegendBreaks().get(bNum - 1).isNoData()) {
- bNum -= 1;
- }
-
- List labelIdxs = new ArrayList<>();
- List tLabels = new ArrayList<>();
- if (this.autoTick) {
- int tickGap = this.getTickGap(g);
- int sIdx = (bNum % tickGap) / 2;
- int labNum = bNum - 1;
- if (aLS.getLegendType() == LegendType.UniqueValue) {
- labNum += 1;
- } else if (this.drawMinLabel) {
- sIdx = 0;
- labNum = bNum;
- }
- while (sIdx < labNum) {
- labelIdxs.add(sIdx);
- sIdx += tickGap;
- }
- } else {
- int tickIdx;
- for (int i = 0; i < bNum; i++) {
- ColorBreak cb = aLS.getLegendBreaks().get(i);
- if (i == bNum - 1) {
- if (cb.getStartValue().equals(cb.getEndValue()))
- continue;
- }
- double v = Double.parseDouble(cb.getEndValue().toString());
- if (this.tickLocations.contains(v)) {
- labelIdxs.add(i);
- tickIdx = this.tickLocations.indexOf(v);
- tLabels.add(this.tickLabels.get(tickIdx).getText());
- }
- if (i == 0) {
- v = Double.parseDouble(cb.getStartValue().toString());
- if (this.tickLocations.contains(v)) {
- labelIdxs.add(i);
- tickIdx = this.tickLocations.indexOf(v);
- tLabels.add(this.tickLabels.get(tickIdx).getText());
- }
- }
- }
- }
-
- this._vBarWidth = (double) this.legendHeight / this.aspect;
- _hBarHeight = (double) this.legendHeight / bNum;
- aP.Y = this.legendHeight;
- float x_shift = 0;
- if (this.label != null){
- switch (this.labelLocation){
- case "left":
- case "in":
- x_shift = this.label.getDimension(g).height + 5;
- break;
- }
- }
- int idx;
- aP.X = x_shift;
- for (int i = 0; i < bNum; i++) {
- idx = i;
- switch (aLS.getShapeType()) {
- case Point:
- PointBreak aPB = (PointBreak) aLS.getLegendBreaks().get(idx);
- DrawShape = aPB.isDrawShape();
- DrawFill = aPB.isDrawFill();
- FillColor = aPB.getColor();
- break;
- case Polyline:
- PolylineBreak aPLB = (PolylineBreak) aLS.getLegendBreaks().get(idx);
- DrawShape = aPLB.getDrawPolyline();
- FillColor = aPLB.getColor();
- break;
- case Polygon:
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx);
- DrawShape = aPGB.isDrawShape();
- DrawFill = aPGB.isDrawFill();
- FillColor = aPGB.getColor();
- break;
- case Image:
- ColorBreak aCB = aLS.getLegendBreaks().get(idx);
- DrawShape = true;
- DrawFill = true;
- FillColor = aCB.getColor();
- break;
- }
-
- aP.Y = aP.Y - _hBarHeight;
-
- if (DrawShape) {
- if (this.extendRect) {
- if (aLS.getShapeType() == ShapeTypes.Polygon) {
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx).clone();
- aPGB.setDrawOutline(false);
- Draw.drawPolygonSymbol(aP.X, aP.Y, _vBarWidth, _hBarHeight, aPGB, g);
- } else {
- Draw.drawPolygonSymbol(aP.X, aP.Y, FillColor, OutlineColor, _vBarWidth,
- _hBarHeight, DrawFill, DrawOutline, g);
- }
- } else if (i == 0) {
- PointD[] Points = new PointD[4];
- Points[0] = new PointD();
- Points[0].X = aP.X + _vBarWidth * 0.5;
- Points[0].Y = this.legendHeight;
- Points[1] = new PointD();
- Points[1].X = aP.X;
- Points[1].Y = aP.Y;
- Points[2] = new PointD();
- Points[2].X = aP.X + _vBarWidth;
- Points[2].Y = aP.Y;
- Points[3] = new PointD();
- Points[3].X = aP.X + _vBarWidth * 0.5;
- Points[3].Y = this.legendHeight;
- if (aLS.getShapeType() == ShapeTypes.Polygon) {
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx).clone();
- aPGB.setDrawOutline(false);
- Draw.drawPolygon(Points, aPGB, g);
- } else {
- Draw.drawPolygon(Points, FillColor, OutlineColor, DrawFill, DrawOutline, g);
- }
- } else if (i == bNum - 1) {
- PointD[] Points = new PointD[4];
- Points[0] = new PointD();
- Points[0].X = aP.X;
- Points[0].Y = _hBarHeight;
- Points[1] = new PointD();
- Points[1].X = aP.X + _vBarWidth;
- Points[1].Y = _hBarHeight;
- Points[2] = new PointD();
- Points[2].X = aP.X + _vBarWidth * 0.5;
- Points[2].Y = 0;
- Points[3] = new PointD();
- Points[3].X = aP.X;
- Points[3].Y = _hBarHeight;
- if (aLS.getShapeType() == ShapeTypes.Polygon) {
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx).clone();
- aPGB.setDrawOutline(false);
- Draw.drawPolygon(Points, aPGB, g);
- } else {
- Draw.drawPolygon(Points, FillColor, OutlineColor, DrawFill, DrawOutline, g);
- }
- } else if (aLS.getShapeType() == ShapeTypes.Polygon) {
- PolygonBreak aPGB = (PolygonBreak) aLS.getLegendBreaks().get(idx).clone();
- aPGB.setDrawOutline(false);
- Draw.drawPolygonSymbol(aP.X, aP.Y, _vBarWidth, _hBarHeight, aPGB, g);
- } else {
- Draw.drawPolygonSymbol(aP.X, aP.Y, FillColor, OutlineColor, _vBarWidth,
- _hBarHeight, DrawFill, DrawOutline, g);
- }
- }
- }
- //Draw neatline
- g.setStroke(new BasicStroke(this.neatLineSize));
- g.setColor(this.neatLineColor);
- if (this.extendRect) {
- g.draw(new Rectangle.Double(x_shift, 0, this._vBarWidth, this._hBarHeight * bNum));
- } else {
- Path2D p = new Path2D.Double();
- p.moveTo(this._vBarWidth / 2 + x_shift, 0);
- p.lineTo(x_shift, this._hBarHeight);
- p.lineTo(x_shift, (this._hBarHeight * (bNum - 1)));
- p.lineTo(this._vBarWidth / 2 + x_shift, this._hBarHeight * bNum);
- p.lineTo(this._vBarWidth + x_shift, this._hBarHeight * (bNum - 1));
- p.lineTo(this._vBarWidth + x_shift, this._hBarHeight);
- p.closePath();
- g.draw(p);
- }
- //Draw ticks
- g.setStroke(new BasicStroke(this.tickWidth));
- aP.Y = this.legendHeight + _hBarHeight / 2;
- float tickLen = this.tickLength;
- if (this.insideTick) {
- if (this._vBarWidth < tickLen) {
- tickLen = (int) this._vBarWidth;
- }
- }
- g.setFont(tickLabelFont);
- idx = 0;
- for (int i = 0; i < bNum; i++) {
- aP.X = _vBarWidth / 2 + x_shift;
- aP.Y = aP.Y - _hBarHeight;
- if (labelIdxs.contains(i)) {
- ColorBreak cb = aLS.getLegendBreaks().get(i);
- if (this.autoTick) {
- if (aLS.getLegendType() == LegendType.UniqueValue) {
- caption = cb.getCaption();
- } else {
- caption = DataConvert.removeTailingZeros(cb.getEndValue().toString());
- }
- } else {
- caption = tLabels.get(idx);
- }
-
- if (aLS.getLegendType() == LegendType.UniqueValue) {
- sP.X = aP.X + _vBarWidth / 2 + 5;
- sP.Y = aP.Y;
- g.setColor(this.tickLabelColor);
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.LEFT, YAlign.CENTER, this.tickLabelAngle, true);
- } else {
- sP.X = aP.X + _vBarWidth / 2;
- sP.Y = aP.Y - _hBarHeight / 2;
- PointD ssP = (PointD)sP.clone();
- if (this.autoTick) {
- if (i < bNum - 1) {
- g.setColor(this.tickColor);
- this.drawTickLine(g, sP, tickLen, false, 0);
- g.setColor(this.tickLabelColor);
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.LEFT, YAlign.CENTER, this.tickLabelAngle, true);
- if (this.drawMinLabel && i == 0) {
- g.setColor(this.tickColor);
- this.drawTickLine(g, ssP, tickLen, false, this._hBarHeight);
- caption = DataConvert.removeTailingZeros(cb.getStartValue().toString());
- g.setColor(this.tickLabelColor);
- Draw.drawString(g, ssP.X, ssP.Y + this._hBarHeight, caption, XAlign.LEFT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- } else if (this.drawMaxLabel) {
- g.setColor(this.tickColor);
- this.drawTickLine(g, sP, tickLen, false, 0);
- g.setColor(this.tickLabelColor);
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.LEFT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- } else {
- if (i == 0 && this.tickLocations.get(idx) == Double.parseDouble(cb.getStartValue().toString())) {
- g.setColor(this.tickColor);
- this.drawTickLine(g, sP, tickLen, false, this._hBarHeight);
- g.setColor(this.tickLabelColor);
- Draw.drawString(g, sP.X, sP.Y + this._hBarHeight, caption, XAlign.LEFT, YAlign.CENTER, this.tickLabelAngle, true);
- } else {
- g.setColor(this.tickColor);
- this.drawTickLine(g, sP, tickLen, false, 0);
- g.setColor(this.tickLabelColor);
- Draw.drawString(g, sP.X, sP.Y, caption, XAlign.LEFT, YAlign.CENTER, this.tickLabelAngle, true);
- }
- }
- }
- idx += 1;
- }
- }
- //Draw label
- double sx, sy;
- if (this.label != null) {
- g.setFont(this.label.getFont());
- g.setColor(this.label.getColor());
- Dimension dim = Draw.getStringDimension(this.label.getText(), g);
- switch (this.labelLocation) {
- case "top":
- sx = 0;
- sy = -5;
- Draw.drawString(g, sx, sy, label.getText(), XAlign.LEFT, YAlign.BOTTOM, label.isUseExternalFont());
- break;
- case "bottom":
- sx = 0;
- sy = this.legendHeight + 5;
- Draw.drawString(g, sx, sy, label.getText(), XAlign.LEFT, YAlign.TOP, label.isUseExternalFont());
- break;
- case "left":
- case "in":
- sx = 0;
- sy = this.legendHeight * 0.5;
- Draw.drawString(g, sx, sy, label.getText(), XAlign.CENTER, YAlign.TOP, 90, label.isUseExternalFont());
- break;
- default:
- sx = this.width - dim.height;
- sy = this.legendHeight * 0.5;
- Draw.drawString(g, sx, sy, label.getText(), XAlign.CENTER, YAlign.TOP, 90, label.isUseExternalFont());
- break;
- }
- }
- }
-
- /**
- * Get legend dimension
- *
- * @param g Graphics2D
- * @param limitDim Limit dimension
- * @return Legend dimension
- */
- @Override
- public Dimension getLegendDimension(Graphics2D g, Dimension limitDim) {
- if (legendScheme != null) {
- switch (this.orientation) {
- case VERTICAL:
- this.width = (int) (this.getTickWidth(g) + limitDim.height * this.shrink / this.aspect + 5);
- if (!this.insideTick){
- this.width += this.tickLength;
- }
- this.legendWidth = this.width;
- this.legendHeight = this.height;
- if (this.label != null) {
- g.setFont(this.label.getFont());
- Dimension dim = Draw.getStringDimension(label.getText(), g);
- switch (this.labelLocation) {
- case "top":
- case "bottom":
- //this.height += dim.height + 10;
- this.width = Math.max(this.width, dim.width);
- break;
- default:
- this.width += dim.height + 5;
- break;
- }
- }
- break;
- default:
- g.setFont(this.tickLabelFont);
- this.height = (int) (this.getTickHeight(g) + limitDim.width * this.shrink / this.aspect + 5);
- if (!this.insideTick){
- this.height += this.tickLength;
- }
- this.legendWidth = this.width;
- this.legendHeight = this.height;
- if (this.label != null) {
- g.setFont(this.label.getFont());
- Dimension dim = Draw.getStringDimension(label.getText(), g);
- switch (this.labelLocation) {
- case "right":
- case "left":
- //this.width += dim.width + 10;
- break;
- default:
- this.height += dim.height + 5;
- break;
- }
- }
- }
- }
-
- return new Dimension(this.width, this.height);
- }
- //
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartLegend.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartLegend.java
deleted file mode 100644
index ef6b1889..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartLegend.java
+++ /dev/null
@@ -1,1441 +0,0 @@
-/* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.chart;
-
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.chart.drawing.Draw;
-import org.meteoinfo.chart.legend.ColorBreak;
-import org.meteoinfo.chart.legend.LegendScheme;
-import org.meteoinfo.chart.legend.PointBreak;
-import org.meteoinfo.chart.legend.PolygonBreak;
-import org.meteoinfo.chart.legend.PolylineBreak;
-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.geom.AffineTransform;
-import java.util.List;
-import org.meteoinfo.chart.plot.PlotOrientation;
-import org.meteoinfo.chart.plot.XAlign;
-import org.meteoinfo.chart.plot.YAlign;
-import org.meteoinfo.common.DataConvert;
-import org.meteoinfo.chart.legend.LegendType;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class ChartLegend {
- //
-
- //private final XY1DPlot plot;
- protected LegendScheme legendScheme;
- private LegendPosition position;
- protected float shrink;
- protected int aspect;
- private boolean colorBar;
- protected float x;
- protected float y;
- protected PlotOrientation orientation;
- protected Color background;
- protected boolean drawBackground;
- protected int width;
- protected int height;
- protected int legendWidth;
- protected int legendHeight;
- protected ChartText label;
- protected String labelLocation;
- protected Font tickLabelFont;
- protected Color tickLabelColor;
- protected float tickLabelAngle;
- protected boolean drawNeatLine;
- protected Color neatLineColor;
- protected float neatLineSize;
- private float breakSpace;
- private float topSpace;
- private float leftSpace;
- protected double _vBarWidth;
- protected double _hBarHeight;
- private int rowColNum = 1;
- private boolean autoRowColNum = true;
- private Dimension symbolDimension;
- protected boolean extendRect;
- protected boolean autoExtendFrac;
- protected float xshift;
- protected float yshift;
- //
- //
-
- /**
- * Constructor
- *
- * @param ls LegendScheme
- */
- public ChartLegend(LegendScheme ls) {
- //this.plot = plot;
- this.legendScheme = ls;
- this.colorBar = false;
- this.position = LegendPosition.LOWER_CENTER_OUTSIDE;
- this.orientation = PlotOrientation.HORIZONTAL;
- this.shrink = 1.0f;
- this.aspect = 20;
- this.background = Color.white;
- this.drawBackground = false;
- drawNeatLine = true;
- neatLineColor = Color.black;
- neatLineSize = 1;
- breakSpace = 3;
- topSpace = 5;
- leftSpace = 5;
- _vBarWidth = 10;
- _hBarHeight = 10;
- this.labelLocation = "out";
- tickLabelFont = new Font("Arial", Font.PLAIN, 14);
- this.tickLabelColor = Color.black;
- this.tickLabelAngle = 0;
- this.symbolDimension = new Dimension(16, 10);
- this.extendRect = true;
- this.autoExtendFrac = false;
- this.xshift = 0;
- this.yshift = 0;
- }
-
- //
- //
- //
- //
- /**
- * Get legend scheme
- *
- * @return Legend scheme
- */
- public LegendScheme getLegendScheme() {
- return this.legendScheme;
- }
-
- /**
- * Set legend scheme
- *
- * @param value Legend scheme
- */
- public void setLegendScheme(LegendScheme value) {
- this.legendScheme = value;
- }
-
- /**
- * Get if is color bar
- *
- * @return Boolean
- */
- public boolean isColorbar() {
- return this.colorBar;
- }
-
- /**
- * Set if is color bar
- *
- * @param value Boolean
- */
- public void setColorbar(boolean value) {
- this.colorBar = value;
- }
-
- /**
- * Get legend position
- *
- * @return Legend position
- */
- public LegendPosition getPosition() {
- return this.position;
- }
-
- /**
- * Set legend position
- *
- * @param value Legend position
- */
- public void setPosition(LegendPosition value) {
- this.position = value;
- }
-
- /**
- * Get shrink
- *
- * @return Shrink
- */
- public float getShrink() {
- return this.shrink;
- }
-
- /**
- * Set shrink
- *
- * @param value Shrink
- */
- public void setShrink(float value) {
- this.shrink = value;
- }
-
- /**
- * Get aspect
- *
- * @return Aspect
- */
- public int getAspect() {
- return this.aspect;
- }
-
- /**
- * Set aspect
- *
- * @param value Aspect
- */
- public void setAspect(int value) {
- this.aspect = value;
- }
-
- /**
- * Get X
- *
- * @return X value
- */
- public float getX() {
- return this.x;
- }
-
- /**
- * Set X
- *
- * @param value X value
- */
- public void setX(float value) {
- x = value;
- }
-
- /**
- * Get Y
- *
- * @return Y value
- */
- public float getY() {
- return this.y;
- }
-
- /**
- * Set Y
- *
- * @param value Y value
- */
- public void setY(float value) {
- y = value;
- }
-
- /**
- * Get width
- *
- * @return Width
- */
- public int getWidth() {
- return this.width;
- }
-
- /**
- * Set width
- *
- * @param value Width
- */
- public void setWidth(int value) {
- this.width = value;
- }
-
- /**
- * Get height
- *
- * @return Height
- */
- public int getHeight() {
- return this.height;
- }
-
- /**
- * Set height
- *
- * @param value Height
- */
- public void setHeight(int value) {
- this.height = value;
- }
-
- /**
- * Get legend width
- *
- * @return Legend width
- */
- public int getLegendWidth() {
- return this.legendWidth;
- }
-
- /**
- * Set legend width
- *
- * @param value Legend width
- */
- public void setLegendWidth(int value) {
- this.legendWidth = value;
- }
-
- /**
- * Get legend height
- *
- * @return Legend height
- */
- public int getLegendHeight() {
- return this.legendHeight;
- }
-
- /**
- * Set legend height
- *
- * @param value Legend height
- */
- public void setLegendHeight(int value) {
- this.legendHeight = value;
- }
-
- /**
- * Get plot orientation
- *
- * @return Plot orientation
- */
- public PlotOrientation getPlotOrientation() {
- return this.orientation;
- }
-
- /**
- * Set plot orientation
- *
- * @param value Plot orientation
- */
- public void setPlotOrientation(PlotOrientation value) {
- this.orientation = value;
- }
-
- /**
- * Get background
- *
- * @return Background
- */
- public Color getBackground() {
- return this.background;
- }
-
- /**
- * Set background
- *
- * @param value Background
- */
- public void setBackground(Color value) {
- this.background = value;
- }
-
- /**
- * Get if draw background
- *
- * @return Boolean
- */
- public boolean isDrawBackground() {
- return this.drawBackground;
- }
-
- /**
- * Set if draw background
- *
- * @param value Boolean
- */
- public void setDrawBackground(boolean value) {
- this.drawBackground = value;
- }
-
- /**
- * Get if draw neat line
- *
- * @return If draw neat line
- */
- public boolean isDrawNeatLine() {
- return drawNeatLine;
- }
-
- /**
- * Set if draw neat line
- *
- * @param istrue If draw neat line
- */
- public void setDrawNeatLine(boolean istrue) {
- drawNeatLine = istrue;
- }
-
- /**
- * Get neat line color
- *
- * @return Neat line color
- */
- public Color getNeatLineColor() {
- return neatLineColor;
- }
-
- /**
- * Set neat line color
- *
- * @param color Neat line color
- */
- public void setNeatLineColor(Color color) {
- neatLineColor = color;
- }
-
- /**
- * Get neat line size
- *
- * @return Neat line size
- */
- public float getNeatLineSize() {
- return neatLineSize;
- }
-
- /**
- * Set neat line size
- *
- * @param size Neat line size
- */
- public void setNeatLineSize(float size) {
- neatLineSize = size;
- }
-
- /**
- * Get break space
- * @return Break space
- */
- public float getBreakSpace() {
- return this.breakSpace;
- }
-
- /**
- * Set break space
- * @param value Break space
- */
- public void setBreakSpace(float value) {
- this.breakSpace = value;
- }
-
- /**
- * Get label
- *
- * @return Label
- */
- public ChartText getLabel() {
- return this.label;
- }
-
- /**
- * Set label
- *
- * @param value Label
- */
- public void setLabel(ChartText value) {
- this.label = value;
- }
-
- /**
- * Get label font
- *
- * @return Label font
- */
- public Font getLabelFont() {
- return this.label.getFont();
- }
-
- /**
- * Set label font
- *
- * @param value Label font
- */
- public void setLabelFont(Font value) {
- this.label.setFont(value);
- }
-
- /**
- * Get label color
- *
- * @return Label color
- */
- public Color getLabelColor() {
- return this.label.getColor();
- }
-
- /**
- * Set label color
- *
- * @param value Label color
- */
- public void setLabelColor(Color value) {
- this.label.setColor(value);
- }
-
- /**
- * Get label location (in, out, top, bottom, left, right)
- *
- * @return Label location
- */
- public String getLabelLocation() {
- return this.labelLocation;
- }
-
- /**
- * Set label location
- *
- * @param value Label location
- */
- public void setLabelLocation(String value) {
- this.labelLocation = value;
- }
-
- /**
- * Get Tick label font
- *
- * @return The Tick label font
- */
- public Font getTickLabelFont() {
- return tickLabelFont;
- }
-
- /**
- * Set Tick label font
- *
- * @param font The Tick label font
- */
- public void setTickLabelFont(Font font) {
- tickLabelFont = font;
- }
-
- /**
- * Get tick label color
- *
- * @return Tick label color
- */
- public Color getTickLabelColor() {
- return this.tickLabelColor;
- }
-
- /**
- * Set tick label color
- *
- * @param value Tick label color
- */
- public void setTickLabelColor(Color value) {
- this.tickLabelColor = value;
- }
-
- /**
- * Get tick lable angle
- *
- * @return Tick label angle
- */
- public float getTickLabelAngle() {
- return this.tickLabelAngle;
- }
-
- /**
- * Set tick label angle
- *
- * @param value Tick label angle
- */
- public void setTickLabelAngle(float value) {
- this.tickLabelAngle = value;
- }
-
- /**
- * Get column number
- *
- * @return Column number
- */
- public int getColumnNumber() {
- return rowColNum;
- }
-
- /**
- * Set column number
- *
- * @param value Column number
- */
- public void setColumnNumber(int value) {
- rowColNum = value;
- }
-
- /**
- * Get if automatic set row/col number
- *
- * @return Boolean
- */
- public boolean isAutoRowColNum() {
- return this.autoRowColNum;
- }
-
- /**
- * Set if automatic set row/col number
- *
- * @param value Boolean
- */
- public void setAutoRowColNum(boolean value) {
- this.autoRowColNum = value;
- }
-
- /**
- * Get symbol dimension
- *
- * @return Symbol dimension
- */
- public Dimension getSymbolDimension() {
- return this.symbolDimension;
- }
-
- /**
- * Set symbol dimension
- *
- * @param value Symbol dimension
- */
- public void setSymbolDimension(Dimension value) {
- this.symbolDimension = value;
- }
-
- /**
- * Set symbol width
- *
- * @param value Width
- */
- public void setSymbolWidth(int value) {
- this.symbolDimension.width = value;
- }
-
- /**
- * Set symbol height
- *
- * @param value height
- */
- public void setSymbolHeight(int value) {
- this.symbolDimension.height = value;
- }
-
- /**
- * Set symbol scale
- *
- * @param value Symble scale
- */
- public void setSymbolScale(float value) {
- double w = this.symbolDimension.getWidth() * value;
- double h = this.symbolDimension.getHeight() * value;
- this.symbolDimension.setSize(w, h);
- }
-
- /**
- * Get if extend rectangle - or triangle
- *
- * @return Boolean
- */
- public boolean isExtendRect() {
- return this.extendRect;
- }
-
- /**
- * Set if extend rectangle - or triangle
- *
- * @param value Boolean
- */
- public void setExtendRect(boolean value) {
- this.extendRect = value;
- }
-
- /**
- * Get if auto set extend fraction - extend has save width and height Only
- * valid for colorbar
- *
- * @return Boolean
- */
- public boolean isAutoExtendFrac() {
- return this.autoExtendFrac;
- }
-
- /**
- * Set if auto set extend fraction - extend has save width and height Only
- * valid for colorbar
- *
- * @param value
- */
- public void setAutoExtendFrac(boolean value) {
- this.autoExtendFrac = value;
- }
-
- /**
- * Set tick labels
- *
- * @param value Tick labels
- */
- public void setTickCaptions(List value) {
- for (int i = 0; i < this.legendScheme.getBreakNum(); i++) {
- if (i < value.size()) {
- this.legendScheme.getLegendBreaks().get(i).setCaption(value.get(i));
- } else {
- break;
- }
- }
- }
-
- /**
- * Get x shift - pixel unit
- *
- * @return X shift
- */
- public float getXShift() {
- return this.xshift;
- }
-
- /**
- * Set x shift
- *
- * @param value X shift
- */
- public void setXShift(float value) {
- this.xshift = value;
- }
-
- /**
- * Get y shift - pixel unit
- *
- * @return Y shift
- */
- public float getYShift() {
- return this.yshift;
- }
-
- /**
- * Set y shift
- *
- * @param value Y shift
- */
- public void setYShift(float value) {
- this.yshift = value;
- }
-
- //
- //
- /**
- * Draw legend
- *
- * @param g Graphics2D
- * @param point Start point
- */
- public void draw(Graphics2D g, PointF point) {
-
- AffineTransform oldMatrix = g.getTransform();
- g.translate(point.X + this.xshift, point.Y + this.yshift);
-
- //Draw background color
- if (this.drawBackground) {
- g.setColor(this.background);
- g.fill(new Rectangle.Float(0, 0, this.width, this.height));
- }
-
- //Draw legend
- g.setStroke(new BasicStroke(1));
- switch (this.orientation) {
- case HORIZONTAL:
- drawHorizontalLegend(g, legendScheme);
- break;
- case VERTICAL:
- this.drawVerticalLegend(g, legendScheme);
- break;
- }
-
- //Draw neatline
- if (drawNeatLine) {
- Rectangle.Float mapRect = new Rectangle.Float(0, 0, this.width, this.height);
- g.setColor(neatLineColor);
- g.setStroke(new BasicStroke(neatLineSize));
- g.draw(mapRect);
- }
-
- g.setTransform(oldMatrix);
- }
-
- private void drawVerticalLegend(Graphics2D g, LegendScheme aLS) {
- String caption;
- float breakHeight = this.getBreakHeight(g);
- float symbolHeight = this.symbolDimension.height;
- float symbolWidth = this.symbolDimension.width;
- float colWidth = symbolWidth + getMaxLabelWidth(g) + 10;
-
- //Set columns
- int[] rowNums = new int[rowColNum];
- int ave = aLS.getVisibleBreakNum() / rowColNum;
- if (ave * rowColNum < aLS.getBreakNum()) {
- ave += 1;
- }
- int num = 0;
- int i;
- for (i = 1; i < rowColNum; i++) {
- rowNums[i] = ave;
- num += ave;
- }
- rowNums[0] = aLS.getVisibleBreakNum() - num;
-
- //Draw title
- float y0 = 0;
- if (this.label != null) {
- float x0 = (float) (this.width / 2.);
- y0 += this.breakSpace * 2;
- this.label.draw(g, x0, y0);
- y0 += this.label.getDimension(g).height + this.breakSpace * 2;
- }
-
- //Draw legend
- float x, y;
- i = 0;
- for (int col = 0; col < rowColNum; col++) {
- x = symbolWidth / 2 + leftSpace + col * colWidth;
- y = y0 + breakHeight / 2 + breakSpace * 2;
- for (int row = 0; row < rowNums[col]; row++) {
- if (!aLS.getLegendBreaks().get(i).isDrawShape()) {
- continue;
- }
-
- //y += breakHeight + breakSpace;
- ColorBreak cb = aLS.getLegendBreaks().get(i);
- if (!cb.isDrawShape()) {
- continue;
- }
- caption = aLS.getLegendBreaks().get(i).getCaption();
- if (cb instanceof PointBreak) {
- PointBreak aPB = (PointBreak) cb.clone();
- ((PointBreak) aPB).setSize(((PointBreak) cb).getSize() * (symbolHeight / 10.f));
- Draw.drawPoint(new PointF(x, y), aPB, g);
- } else if (cb instanceof PolylineBreak) {
- PolylineBreak aPLB = (PolylineBreak) cb;
- Draw.drawPolylineSymbol_S(new PointF(x, y), symbolWidth, symbolHeight, aPLB, g);
- } else if (cb instanceof PolygonBreak) {
- Draw.drawPolygonSymbol(new PointF(x, y), symbolWidth, symbolHeight, (PolygonBreak) cb, g);
- } else {
- PolygonBreak pgb = new PolygonBreak();
- pgb.setColor(cb.getColor());
- pgb.setOutlineColor(Color.black);
- Draw.drawPolygonSymbol(new PointF(x, y), symbolWidth, symbolHeight, pgb, g);
- }
-
- PointF sP = new PointF(0, 0);
- sP.X = x + symbolWidth / 2;
- sP.Y = y;
- g.setColor(this.tickLabelColor);
- g.setFont(this.tickLabelFont);
- Draw.drawString(g, sP.X + 5, sP.Y, caption, XAlign.LEFT, YAlign.CENTER, true);
- y += breakHeight + breakSpace;
-
- i += 1;
- }
- }
- }
-
- private void drawHorizontalLegend(Graphics2D g, LegendScheme aLS) {
- String caption;
- float breakHeight = this.getBreakHeight(g);
- float symbolHeight = this.symbolDimension.height;
- float symbolWidth = this.symbolDimension.width;
-
- //Set columns
- int[] colNums = new int[rowColNum];
- int ave = aLS.getVisibleBreakNum() / rowColNum;
- if (ave * rowColNum < aLS.getBreakNum()) {
- ave += 1;
- }
- int num = 0;
- int i;
- for (i = 0; i < rowColNum - 1; i++) {
- colNums[i] = ave;
- num += ave;
- }
- colNums[rowColNum - 1] = aLS.getVisibleBreakNum() - num;
-
- //Draw legend
- float x, y;
- y = this.breakSpace + breakHeight / 2;
- i = 0;
- for (int row = 0; row < rowColNum; row++) {
- x = this.symbolDimension.width / 2 + 5;
- for (int col = 0; col < colNums[row]; col++) {
- if (i >= aLS.getBreakNum()) {
- break;
- }
-
- ColorBreak cb = aLS.getLegendBreaks().get(i);
- if (!cb.isDrawShape()) {
- continue;
- }
- caption = aLS.getLegendBreaks().get(i).getCaption();
- if (cb instanceof PointBreak) {
- PointBreak aPB = (PointBreak) cb;
- Draw.drawPoint(new PointF(x, y), aPB, g);
- } else if (cb instanceof PolylineBreak) {
- PolylineBreak aPLB = (PolylineBreak) cb;
- Draw.drawPolylineSymbol_S(new PointF(x, y), symbolWidth, symbolHeight, aPLB, g);
- } else if (cb instanceof PolygonBreak) {
- Draw.drawPolygonSymbol(new PointF(x, y), symbolWidth, symbolHeight, (PolygonBreak) cb, g);
- }
-
- PointF sP = new PointF(0, 0);
- sP.X = x + symbolWidth / 2;
- sP.Y = y;
- g.setColor(this.tickLabelColor);
- g.setFont(this.tickLabelFont);
- Draw.drawString(g, sP.X + 5, sP.Y, caption, XAlign.LEFT, YAlign.CENTER, true);
- Dimension dim = Draw.getStringDimension(caption, g);
- x += this.symbolDimension.width + dim.width + 15;
- i += 1;
- }
- y += breakHeight + this.breakSpace * 2;
- }
- }
-
- private int getMaxLabelWidth(Graphics2D g) {
- String caption;
- Dimension aSF;
- int bNum = legendScheme.getBreakNum();
- int labWidth = 0;
- g.setFont(this.tickLabelFont);
- for (int i = 0; i < bNum; i++) {
- caption = legendScheme.getLegendBreaks().get(i).getCaption();
- boolean isValid = true;
- if (isValid) {
- aSF = Draw.getStringDimension(caption, this.tickLabelAngle, g);
- int labwidth = aSF.width;
- if (labWidth < labwidth) {
- labWidth = labwidth;
- }
- }
- }
-
- return labWidth;
- }
-
- private int getBreakHeight(Graphics2D g) {
- g.setFont(tickLabelFont);
- Dimension dim = Draw.getStringDimension(this.legendScheme.getLegendBreak(0).getCaption(), g);
- return Math.max(dim.height, this.symbolDimension.height);
- }
-
- /**
- * Get legend dimension
- *
- * @param g Graphics2D
- * @param limitDim Limit dimension
- * @return Legend dimension
- */
- public Dimension getLegendDimension(Graphics2D g, Dimension limitDim) {
- if (legendScheme != null) {
- if (this.colorBar) {
- switch (this.orientation) {
- case VERTICAL:
- this.width = (int) (this.getTickWidth(g) + limitDim.height * this.shrink / this.aspect + 5);
- if (this.label != null) {
- g.setFont(this.label.getFont());
- this.width += (int) Draw.getStringDimension(label.getText(), g).height + 5;
- }
- break;
- default:
- g.setFont(this.tickLabelFont);
- this.height = (int) (Draw.getStringDimension("test", g).height + limitDim.width * this.shrink / this.aspect + 5);
- if (this.label != null) {
- g.setFont(this.label.getFont());
- Dimension dim = Draw.getStringDimension(label.getText(), g);
- switch (this.labelLocation) {
- case "top":
- case "right":
- this.width += dim.width + 10;
- break;
- default:
- this.height += (int) Draw.getStringDimension(label.getText(), g).height + 5;
- break;
- }
- }
- }
- } else {
- int breakHeight = getBreakHeight(g);
- int titleHeight = 0;
- int titleWidth = 0;
- if (this.label != null) {
- Dimension dim = this.label.getDimension(g);
- titleHeight = dim.height + (int) (this.breakSpace * 4);
- titleWidth = dim.width;
- }
- switch (this.orientation) {
- case VERTICAL:
- //Get column number
- if (this.autoRowColNum) {
- int tHeight = (int) (legendScheme.getBreakNum() * (breakHeight + breakSpace)
- + breakSpace * 2 + breakHeight / 2 + 5);
- rowColNum = 1;
- if (tHeight > limitDim.height * 10 / 8) {
- rowColNum = tHeight / (limitDim.height * 10 / 8) + 1;
- if (rowColNum == 1) {
- rowColNum = 2;
- } else {
- int n = legendScheme.getBreakNum() / rowColNum;
- int m = legendScheme.getBreakNum() % rowColNum;
- if (m != 0) {
- if (m <= n) {
- rowColNum += 1;
- } else {
- rowColNum += 2;
- }
- } else if (rowColNum * (limitDim.width * 8 / 10) < tHeight) {
- rowColNum += 1;
- }
- }
- }
- }
-
- //Get width
- int colWidth = this.symbolDimension.width + getMaxLabelWidth(g) + 15;
- this.width = colWidth * rowColNum;
-
- //Get height
- int[] rowNums = new int[rowColNum];
- int ave = legendScheme.getBreakNum() / rowColNum;
- if (ave * rowColNum < legendScheme.getBreakNum()) {
- ave += 1;
- }
- int num = 0;
- int i;
- for (i = 0; i < rowColNum - 1; i++) {
- rowNums[i] = ave;
- num += ave;
- }
- rowNums[rowColNum - 1] = legendScheme.getBreakNum() - num;
-
-// this.height = (int) (rowNums[0] * (breakHeight + _breakSpace)
-// + _breakSpace * 2 + breakHeight / 2 + 5);
- this.height = (int) (rowNums[0] * (breakHeight + breakSpace)
- + breakSpace * 3);
- break;
- case HORIZONTAL:
- //Get row number
- if (this.autoRowColNum) {
- int breakWidth = this.symbolDimension.width + this.getMaxLabelWidth(g) + 15;
- int tWidth = breakWidth * legendScheme.getBreakNum();
- rowColNum = 1;
- if (tWidth > limitDim.width * 8 / 10) {
- rowColNum = tWidth / (limitDim.width * 8 / 10);
- if (rowColNum == 1) {
- rowColNum = 2;
- } else {
- int n = legendScheme.getBreakNum() / rowColNum;
- int m = legendScheme.getBreakNum() % rowColNum;
- if (m != 0) {
- if (m <= n) {
- rowColNum += 1;
- } else {
- rowColNum += 2;
- }
- } else if (rowColNum * (limitDim.width * 8 / 10) < tWidth) {
- rowColNum += 1;
- }
- }
- }
- }
-
- //Get height
- this.height = (int) (breakHeight + this.breakSpace * 2) * this.rowColNum;
-
- //Get width
- //FontMetrics metrics = g.getFontMetrics(tickFont);
- ave = legendScheme.getBreakNum() / rowColNum;
- if (ave * rowColNum < legendScheme.getBreakNum()) {
- ave += 1;
- }
- num = 0;
- int maxWidth = 0;
- int tempWidth = 0;
- for (i = 0; i < legendScheme.getBreakNum(); i++) {
- if (num < ave) {
- //tempWidth += this.symbolDimension.width + 15
- // + metrics.stringWidth(legendScheme.getLegendBreaks().get(i).getCaption());
- tempWidth += this.symbolDimension.width + 15
- + Draw.getStringDimension(legendScheme.getLegendBreaks().get(i).getCaption(), g).width;
- num += 1;
- } else {
- if (maxWidth < tempWidth) {
- maxWidth = tempWidth;
- }
- //tempWidth = metrics.stringWidth(legendScheme.getLegendBreaks().get(i).getCaption()) + 15;
- tempWidth = Draw.getStringDimension(legendScheme.getLegendBreaks().get(i).getCaption(), g).width;
- num = 1;
- }
- }
- if (maxWidth < tempWidth) {
- maxWidth = tempWidth;
- }
- if (maxWidth > limitDim.width) {
- maxWidth = limitDim.width * 8 / 10;
- }
- this.width = maxWidth;
- break;
- }
- this.height += titleHeight;
- this.width = Math.max(this.width, titleWidth);
- }
- }
-
- return new Dimension(this.width, this.height);
- }
-
- protected int getTickWidth(Graphics2D g) {
- float rwidth = 0;
- String caption = "";
- int bNum = this.legendScheme.getBreakNum();
- //FontMetrics metrics = g.getFontMetrics(this.tickFont);
- g.setFont(this.tickLabelFont);
- if (this.legendScheme.getLegendBreaks().get(bNum - 1).isNoData()) {
- bNum -= 1;
- }
- for (int i = 0; i < bNum; i++) {
- switch (this.legendScheme.getShapeType()) {
- case Point:
- PointBreak aPB = (PointBreak) legendScheme.getLegendBreaks().get(i);
- if (legendScheme.getLegendType() == LegendType.GraduatedColor) {
- caption = DataConvert.removeTailingZeros(aPB.getEndValue().toString());
- } else {
- caption = aPB.getCaption();
- }
- break;
- case Polyline:
- PolylineBreak aPLB = (PolylineBreak) legendScheme.getLegendBreaks().get(i);
- if (legendScheme.getLegendType() == LegendType.GraduatedColor) {
- caption = DataConvert.removeTailingZeros(aPLB.getEndValue().toString());
- } else {
- caption = aPLB.getCaption();
- }
- break;
- case Polygon:
- PolygonBreak aPGB = (PolygonBreak) legendScheme.getLegendBreaks().get(i);
- if (legendScheme.getLegendType() == LegendType.GraduatedColor) {
- caption = DataConvert.removeTailingZeros(aPGB.getEndValue().toString());
- } else {
- caption = aPGB.getCaption();
- }
- break;
- case Image:
- ColorBreak aCB = legendScheme.getLegendBreaks().get(i);
- if (legendScheme.getLegendType() == LegendType.GraduatedColor) {
- caption = DataConvert.removeTailingZeros(aCB.getEndValue().toString());
- } else {
- caption = aCB.getCaption();
- }
- break;
- }
-
- boolean isValid = true;
- switch (legendScheme.getLegendType()) {
- case GraduatedColor:
- if (i == bNum - 1) {
- isValid = false;
- }
- break;
- }
- if (isValid) {
- //float labwidth = metrics.stringWidth(caption);
- float labwidth = (float) Draw.getStringDimension(caption, this.tickLabelAngle, g).getWidth();
- if (rwidth < labwidth) {
- rwidth = labwidth;
- }
- }
- }
-
- return (int) rwidth;
- }
-
- protected int getTickHeight(Graphics2D g) {
- float rheight = 0;
- String caption = "";
- int bNum = this.legendScheme.getBreakNum();
- //FontMetrics metrics = g.getFontMetrics(this.tickFont);
- g.setFont(this.tickLabelFont);
- if (this.legendScheme.getLegendBreaks().get(bNum - 1).isNoData()) {
- bNum -= 1;
- }
- for (int i = 0; i < bNum; i++) {
- switch (this.legendScheme.getShapeType()) {
- case Point:
- PointBreak aPB = (PointBreak) legendScheme.getLegendBreaks().get(i);
- if (legendScheme.getLegendType() == LegendType.GraduatedColor) {
- caption = DataConvert.removeTailingZeros(aPB.getEndValue().toString());
- } else {
- caption = aPB.getCaption();
- }
- break;
- case Polyline:
- PolylineBreak aPLB = (PolylineBreak) legendScheme.getLegendBreaks().get(i);
- if (legendScheme.getLegendType() == LegendType.GraduatedColor) {
- caption = DataConvert.removeTailingZeros(aPLB.getEndValue().toString());
- } else {
- caption = aPLB.getCaption();
- }
- break;
- case Polygon:
- PolygonBreak aPGB = (PolygonBreak) legendScheme.getLegendBreaks().get(i);
- if (legendScheme.getLegendType() == LegendType.GraduatedColor) {
- caption = DataConvert.removeTailingZeros(aPGB.getEndValue().toString());
- } else {
- caption = aPGB.getCaption();
- }
- break;
- case Image:
- ColorBreak aCB = legendScheme.getLegendBreaks().get(i);
- if (legendScheme.getLegendType() == LegendType.GraduatedColor) {
- caption = DataConvert.removeTailingZeros(aCB.getEndValue().toString());
- } else {
- caption = aCB.getCaption();
- }
- break;
- }
-
- boolean isValid = true;
- switch (legendScheme.getLegendType()) {
- case GraduatedColor:
- if (i == bNum - 1) {
- isValid = false;
- }
- break;
- }
- if (isValid) {
- float labheight = (float) Draw.getStringDimension(caption, 90 - Math.abs(this.tickLabelAngle), g).getWidth();
- if (rheight < labheight) {
- rheight = labheight;
- }
- }
- }
-
- return (int) rheight;
- }
-
- /**
- * Update tick gap
- *
- * @param g Graphics2D
- * @return Ticks gap
- */
- protected int getTickGap(Graphics2D g) {
- if (this.tickLabelAngle != 0) {
- return 1;
- }
-
- double len;
- int n = this.legendScheme.getBreakNum();
- int nn;
- if (this.orientation == PlotOrientation.HORIZONTAL) {
- len = this.width;
- int labLen = this.getTickWidth(g);
- nn = (int) ((len * 0.8) / labLen);
- } else {
- len = this.height;
- FontMetrics metrics = g.getFontMetrics(tickLabelFont);
- nn = (int) (len / metrics.getHeight());
- }
- if (nn == 0) {
- nn = 1;
- }
- return n / nn + 1;
- }
-
- //
- //
- public class LayoutLegendBean {
-
- LayoutLegendBean() {
- }
-
- //
- /**
- * Get if draw neat line
- *
- * @return If draw neat line
- */
- public boolean isDrawNeatLine() {
- return drawNeatLine;
- }
-
- /**
- * Set if draw neat line
- *
- * @param istrue If draw neat line
- */
- public void setDrawNeatLine(boolean istrue) {
- drawNeatLine = istrue;
- }
-
- /**
- * Get neat line color
- *
- * @return Neat line color
- */
- public Color getNeatLineColor() {
- return neatLineColor;
- }
-
- /**
- * Set neat line color
- *
- * @param color Neat line color
- */
- public void setNeatLineColor(Color color) {
- neatLineColor = color;
- }
-
- /**
- * Get neat line size
- *
- * @return Neat line size
- */
- public float getNeatLineSize() {
- return neatLineSize;
- }
-
- /**
- * Set neat line size
- *
- * @param size Neat line size
- */
- public void setNeatLineSize(float size) {
- neatLineSize = size;
- }
-
- /**
- * Get tick label font
- *
- * @return The tick label font
- */
- public Font getTickLabelFont() {
- return tickLabelFont;
- }
-
- /**
- * Set tick label font
- *
- * @param font The tick label font
- */
- public void setTickLabelFont(Font font) {
- tickLabelFont = font;
- }
-
- /**
- * Get column number
- *
- * @return Column number
- */
- public int getColumnNumber() {
- return rowColNum;
- }
-
- /**
- * Set column number
- *
- * @param value Column number
- */
- public void setColumnNumber(int value) {
- rowColNum = value;
- }
-
- /**
- * Get is draw background
- *
- * @return Boolean
- */
- public boolean isDrawBackground() {
- return drawBackground;
- }
-
- /**
- * Set is draw background
- *
- * @param value Boolean
- */
- public void setDrawBackground(boolean value) {
- drawBackground = value;
- }
-
- /**
- * Get background color
- *
- * @return Background color
- */
- public Color getBackground() {
- return background;
- }
-
- /**
- * Set background color
- *
- * @param c Background color
- */
- public void setBackground(Color c) {
- background = c;
- }
-
- //
- }
-
- public static class LayoutLegendBeanBeanInfo extends BaseBeanInfo {
-
- public LayoutLegendBeanBeanInfo() {
- super(LayoutLegendBean.class);
- ExtendedPropertyDescriptor e = addProperty("plotOrientation");
- e.setCategory("General").setDisplayName("Plot orientation");
- e.setPropertyEditorClass(PlotOrientationEditor.class);
- addProperty("tickFont").setCategory("General").setDisplayName("Tick Font");
- addProperty("drawBackground").setCategory("General").setDisplayName("Draw Background");
- addProperty("background").setCategory("General").setDisplayName("Background");
- addProperty("columnNumber").setCategory("General").setDisplayName("Column Number");
- addProperty("drawNeatLine").setCategory("Neat Line").setDisplayName("Draw Neat Line");
- addProperty("neatLineColor").setCategory("Neat Line").setDisplayName("Neat Line Color");
- addProperty("neatLineSize").setCategory("Neat Line").setDisplayName("Neat Line Size");
- }
- }
-
- public static class PlotOrientationEditor extends ComboBoxPropertyEditor {
-
- public PlotOrientationEditor() {
- super();
- PlotOrientation[] orientations = PlotOrientation.values();
- String[] types = new String[orientations.length];
- int i = 0;
- for (PlotOrientation type : orientations) {
- types[i] = type.toString();
- i += 1;
- }
- setAvailableValues(types);
- }
- }
-
- //
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartNorthArrow.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartNorthArrow.java
deleted file mode 100644
index 13dcd4e5..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartNorthArrow.java
+++ /dev/null
@@ -1,297 +0,0 @@
-/* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.chart;
-
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.chart.drawing.Draw;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.awt.RenderingHints;
-import java.awt.geom.AffineTransform;
-import org.meteoinfo.chart.plot.MapPlot;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class ChartNorthArrow extends ChartElement {
-//
-
- private MapPlot mapPlot;
- private boolean _antiAlias;
- private float lineWidth;
- private boolean _drawNeatLine;
- private Color _neatLineColor;
- private float _neatLineSize;
- private NorthArrowType _northArrowType;
- private float _angle;
- //
- //
-
- /**
- * Constructor
- *
- * @param mapPlot The map plot
- */
- public ChartNorthArrow(MapPlot mapPlot) {
- super();
-
- this.setWidth(50);
- this.setHeight(50);
-
- this.mapPlot = mapPlot;
- this.lineWidth = 1;
- _antiAlias = true;
- _drawNeatLine = false;
- _neatLineColor = Color.black;
- _neatLineSize = 1;
- _northArrowType = NorthArrowType.NORTHARROW_1;
- _angle = 0;
- }
- //
- //
-
- /**
- * Get map plot
- *
- * @return The map plot
- */
- public MapPlot getMapPlot() {
- return this.mapPlot;
- }
-
- /**
- * Get line widht
- * @return Line width
- */
- public float getLineWidth() {
- return this.lineWidth;
- }
-
- /**
- * Set line width
- * @param value Line width
- */
- public void setLineWidth(float value) {
- this.lineWidth = value;
- }
-
- /**
- * Get if draw neat line
- *
- * @return If draw neat line
- */
- public boolean isDrawNeatLine() {
- return _drawNeatLine;
- }
-
- /**
- * Set if draw neat line
- *
- * @param istrue If draw neat line
- */
- public void setDrawNeatLine(boolean istrue) {
- _drawNeatLine = istrue;
- }
-
- /**
- * Get neat line color
- *
- * @return Neat line color
- */
- public Color getNeatLineColor() {
- return _neatLineColor;
- }
-
- /**
- * Set neat line color
- *
- * @param color Neat line color
- */
- public void setNeatLineColor(Color color) {
- _neatLineColor = color;
- }
-
- /**
- * Get neat line size
- *
- * @return Neat line size
- */
- public float getNeatLineSize() {
- return _neatLineSize;
- }
-
- /**
- * Set neat line size
- *
- * @param size Neat line size
- */
- public void setNeatLineSize(float size) {
- _neatLineSize = size;
- }
-
- /**
- * Get angle
- *
- * @return Angle
- */
- public float getAngle() {
- return _angle;
- }
-
- /**
- * Set angle
- *
- * @param angle The angle
- */
- public void setAngle(float angle) {
- _angle = angle;
- }
-
- //
- //
- /**
- * Draw text
- *
- * @param g Graphics2D
- * @param x X
- * @param y Y
- */
- public void draw(Graphics2D g, float x, float y) {
- AffineTransform oldMatrix = g.getTransform();
- g.translate(x, y);
- if (_angle != 0) {
- g.rotate(_angle);
- }
- if (_antiAlias) {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- } else {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
- }
-
- //Draw background color
- if (this.isDrawBackColor()){
- g.setColor(this.getBackground());
- g.fill(new Rectangle.Float(0, 0, this.getWidth(), this.getHeight()));
- }
-
- drawNorthArrow(g);
-
- //Draw neatline
- if (_drawNeatLine) {
- Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
- (this.getWidth() - _neatLineSize), (this.getHeight() - _neatLineSize));
- g.setColor(_neatLineColor);
- g.setStroke(new BasicStroke(_neatLineSize));
- g.draw(mapRect);
- }
-
- g.setTransform(oldMatrix);
- }
-
- /**
- * Paint graphics
- *
- * @param g Graphics
- * @param pageLocation Page location
- * @param zoom Zoom
- */
- public void paintGraphics(Graphics2D g, PointF pageLocation, float zoom) {
- AffineTransform oldMatrix = g.getTransform();
- PointF aP = pageToScreen(this.getX(), this.getY(), pageLocation, zoom);
- g.translate(aP.X, aP.Y);
- g.scale(zoom, zoom);
- if (_angle != 0) {
- g.rotate(_angle);
- }
- if (_antiAlias) {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- } else {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
- }
-
- //Draw background color
- if (this.isDrawBackColor()){
- g.setColor(this.getBackground());
- g.fill(new Rectangle.Float(0, 0, this.getWidth() * zoom, this.getHeight() * zoom));
- }
-
- drawNorthArrow(g);
-
- //Draw neatline
- if (_drawNeatLine) {
- Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
- (this.getWidth() - _neatLineSize) * zoom, (this.getHeight() - _neatLineSize) * zoom);
- g.setColor(_neatLineColor);
- g.setStroke(new BasicStroke(_neatLineSize));
- g.draw(mapRect);
- }
-
- g.setTransform(oldMatrix);
- }
-
- private void drawNorthArrow(Graphics2D g) {
- switch (_northArrowType) {
- case NORTHARROW_1:
- drawNorthArrow1(g);
- break;
- }
- }
-
- private void drawNorthArrow1(Graphics2D g) {
- g.setColor(this.getForeground());
- g.setStroke(new BasicStroke(this.lineWidth));
-
- //Draw N symbol
- PointF[] points = new PointF[4];
- float x = this.getWidth() / 2;
- float y = this.getHeight() / 6;
- float w = this.getWidth() / 6;
- float h = this.getHeight() / 4;
- points[0] = new PointF(x - w / 2, y + h / 2);
- points[1] = new PointF(x - w / 2, y - h / 2);
- points[2] = new PointF(x + w / 2, y + h / 2);
- points[3] = new PointF(x + w / 2, y - h / 2);
- Draw.drawPolyline(points, g);
-
- //Draw arrow
- w = this.getWidth() / 2;
- h = this.getHeight() * 2 / 3;
- points = new PointF[3];
- points[0] = new PointF(x - w / 2, this.getHeight());
- points[1] = new PointF(x, this.getHeight() - h / 2);
- points[2] = new PointF(x, this.getHeight() - h);
- Draw.fillPolygon(points, g, null);
- Draw.drawPolyline(points, g);
-
- points = new PointF[4];
- points[0] = new PointF(x + w / 2, this.getHeight());
- points[1] = new PointF(x, this.getHeight() - h / 2);
- points[2] = new PointF(x, this.getHeight() - h);
- points[3] = points[0];
- Draw.drawPolyline(points, g);
- }
-
- @Override
- public void moveUpdate() {
- }
-
- @Override
- public void resizeUpdate() {
- }
- //
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartPanel.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartPanel.java
deleted file mode 100644
index 260674b3..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartPanel.java
+++ /dev/null
@@ -1,1689 +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;
-
-import com.itextpdf.awt.PdfGraphics2D;
-import com.itextpdf.text.Document;
-import com.itextpdf.text.DocumentException;
-import com.itextpdf.text.pdf.PdfContentByte;
-import com.itextpdf.text.pdf.PdfTemplate;
-import com.itextpdf.text.pdf.PdfWriter;
-
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.ComponentEvent;
-import java.awt.event.MouseAdapter;
-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;
-import java.awt.image.BufferedImage;
-import java.awt.print.PageFormat;
-import java.awt.print.Printable;
-import java.io.File;
-import java.io.FileNotFoundException;
-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;
-import java.util.logging.Logger;
-import javax.imageio.IIOImage;
-import javax.imageio.ImageIO;
-import javax.imageio.ImageTypeSpecifier;
-import javax.imageio.ImageWriteParam;
-import javax.imageio.ImageWriter;
-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.DocFlavor;
-import javax.print.DocPrintJob;
-import javax.print.PrintException;
-import javax.print.PrintService;
-import javax.print.SimpleDoc;
-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;
-import javax.swing.JPopupMenu;
-import javax.swing.SwingUtilities;
-import javax.swing.Timer;
-import javax.swing.event.EventListenerList;
-import javax.swing.table.DefaultTableModel;
-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.plot.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.GenericFileFilter;
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.ndarray.DataType;
-import org.meteoinfo.table.Field;
-import org.meteoinfo.image.ImageUtil;
-import org.meteoinfo.layer.LayerTypes;
-import org.meteoinfo.layer.MapLayer;
-import org.meteoinfo.layer.RasterLayer;
-import org.meteoinfo.layer.VectorLayer;
-import org.meteoinfo.map.FrmIdentifer;
-import org.meteoinfo.map.FrmIdentiferGrid;
-import org.meteoinfo.map.MapView;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- *
- * @author yaqiang
- */
-public class ChartPanel extends JPanel implements IChartPanel{
-
- //
- private final EventListenerList listeners = new EventListenerList();
- private BufferedImage mapBitmap = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
- private BufferedImage tempImage = null;
- private boolean newPaint = false;
- private boolean doubleBuffer = true;
- private Chart chart;
- private Plot currentPlot;
- private Dimension chartSize;
- private Point mouseDownPoint = new Point(0, 0);
- private Point mouseLastPos = new Point(0, 0);
- private boolean dragMode = false;
- private JPopupMenu popupMenu;
- private MouseMode mouseMode;
- private List selectedPoints;
- private int xShift = 0;
- private int yShift = 0;
- private double paintScale = 1.0;
- private LocalDateTime lastMouseWheelTime;
- private Timer mouseWheelDetctionTimer;
- //
-
- //
- /**
- * Constructor
- */
- public ChartPanel() {
- super();
- //this.setBackground(Color.white);
- this.setBackground(Color.lightGray);
- this.setSize(200, 200);
- this.addComponentListener(new ComponentAdapter() {
- @Override
- public void componentResized(ComponentEvent e) {
- onComponentResized(e);
- }
- });
- this.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- onMouseClicked(e);
- }
-
- @Override
- public void mousePressed(MouseEvent e) {
- onMousePressed(e);
- }
-
- @Override
- public void mouseReleased(MouseEvent e) {
- onMouseReleased(e);
- }
- });
- this.addMouseMotionListener(new MouseMotionAdapter() {
- @Override
- public void mouseMoved(MouseEvent e) {
- onMouseMoved(e);
- }
-
- @Override
- public void mouseDragged(MouseEvent e) {
- onMouseDragged(e);
- }
- });
- this.addMouseWheelListener(new MouseWheelListener() {
- @Override
- public void mouseWheelMoved(MouseWheelEvent e) {
- onMouseWheelMoved(e);
- }
- });
-
- this.mouseWheelDetctionTimer = new Timer(100, new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- LocalDateTime now = LocalDateTime.now();
- if (Duration.between(lastMouseWheelTime, now).toMillis() > 200) {
- xShift = 0;
- yShift = 0;
- paintScale = 1.0;
- //paintGraphics();
- repaintNew();
- mouseWheelDetctionTimer.stop();
- }
- }
- });
-
- popupMenu = new JPopupMenu();
- JMenuItem undoZoom = new JMenuItem("Undo zoom");
- undoZoom.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- onUndoZoomClick();
- }
- });
- popupMenu.add(undoZoom);
- popupMenu.addSeparator();
-
- JMenuItem saveFigure = new JMenuItem("Save figure");
- saveFigure.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- onSaveFigureClick(e);
- }
- });
- popupMenu.add(saveFigure);
-
- this.chart = null;
- this.mouseMode = MouseMode.DEFAULT;
- //this.setMouseMode(mouseMode.ZOOM_IN);
- }
-
- /**
- * Constructor
- *
- * @param chart Chart
- */
- public ChartPanel(Chart chart) {
- this();
- this.chart = chart;
- if (this.chart != null) {
- this.chart.setParent(this);
- }
- }
-
- /**
- * Constructor
- *
- * @param chart Chart
- * @param width Chart width
- * @param height Chart height
- */
- public ChartPanel(Chart chart, int width, int height) {
- this(chart);
- this.chartSize = new Dimension(width, height);
- this.setPreferredSize(chartSize);
- }
-
- //
- //
- /**
- * Get chart
- *
- * @return Chart
- */
- public Chart getChart() {
- return chart;
- }
-
- /**
- * Set chart
- *
- * @param value
- */
- public void setChart(Chart value) {
- chart = value;
- if (this.chart != null) {
- chart.setParent(this);
- }
- }
-
- /**
- * Get if using off screen image double buffering.
- * Using double buffering will be faster but lower view quality in
- * high dpi screen computer.
- *
- * @return Boolean
- */
- public boolean isDoubleBuffer() {
- return this.doubleBuffer;
- }
-
- /**
- * Set using off screen image double buffering or not.
- * @param value Boolean
- */
- public void setDoubleBuffer(boolean value) {
- this.doubleBuffer = value;
- }
-
- /**
- * Get popup menu
- *
- * @return Popup menu
- */
- public JPopupMenu getPopupMenu() {
- return this.popupMenu;
- }
-
- /**
- * Get mouse mode
- *
- * @return Mouse mode
- */
- public MouseMode getMouseMode() {
- return this.mouseMode;
- }
-
- /**
- * Set mouse mode
- *
- * @param value Mouse mode
- */
- @Override
- public void setMouseMode(MouseMode value) {
- this.mouseMode = value;
- Image image;
- Toolkit toolkit = Toolkit.getDefaultToolkit();
- Cursor customCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
- switch (this.mouseMode) {
- case SELECT:
- customCursor = Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
- break;
- case ZOOM_IN:
- image = toolkit.getImage(this.getClass().getResource("/images/zoom_in_32x32x32.png"));
- customCursor = toolkit.createCustomCursor(image, new Point(8, 8), "Zoom In");
- break;
- case ZOOM_OUT:
- image = toolkit.getImage(this.getClass().getResource("/images/zoom_out_32x32x32.png"));
- customCursor = toolkit.createCustomCursor(image, new Point(8, 8), "Zoom In");
- break;
- case PAN:
- image = toolkit.getImage(this.getClass().getResource("/images/Pan_Open_32x32x32.png"));
- customCursor = toolkit.createCustomCursor(image, new Point(8, 8), "Pan");
- break;
- case IDENTIFER:
- image = toolkit.getImage(this.getClass().getResource("/images/identifer_32x32x32.png"));
- customCursor = toolkit.createCustomCursor(image, new Point(8, 8), "Identifer");
- break;
- case ROTATE:
- image = toolkit.getImage(this.getClass().getResource("/images/rotate.png"));
- customCursor = toolkit.createCustomCursor(image, new Point(8, 8), "Identifer");
- break;
- }
- this.setCursor(customCursor);
- }
-
- /**
- * Get selected chart points
- *
- * @return Selected chart points
- */
- public List getSelectedPoints() {
- return this.selectedPoints;
- }
- //
-
- //
- public void addPointSelectedListener(IPointSelectedListener listener) {
- this.listeners.add(IPointSelectedListener.class, listener);
- }
-
- public void removePointSelectedListener(IPointSelectedListener listener) {
- this.listeners.remove(IPointSelectedListener.class, listener);
- }
-
- public void firePointSelectedEvent() {
- firePointSelectedEvent(new PointSelectedEvent(this));
- }
-
- private void firePointSelectedEvent(PointSelectedEvent event) {
- Object[] listeners = this.listeners.getListenerList();
- for (int i = 0; i < listeners.length; i = i + 2) {
- if (listeners[i] == IPointSelectedListener.class) {
- ((IPointSelectedListener) listeners[i + 1]).pointSelectedEvent(event);
- }
- }
- }
- //
-
- //
- /**
- * Get figure width
- *
- * @return Figure width
- */
- public int getFigureWidth() {
- int width;
- if (this.chartSize != null) {
- width = this.chartSize.width;
- } else {
- width = this.getWidth();
- }
-
- return width;
- }
-
- /**
- * Get Figure height
- *
- * @return Figure height
- */
- public int getFigureHeight() {
- int height;
- if (this.chartSize != null) {
- height = this.chartSize.height;
- } else {
- height = this.getHeight();
- }
-
- return height;
- }
-
- /**
- * Select a plot by point
- *
- * @param x X
- * @param y Y
- * @return Selected plot
- */
- public Plot selPlot(int x, int y) {
- if (this.chart == null) {
- return null;
- }
-
- int n = this.chart.getPlots().size();
- for (int i = n - 1; i >= 0; i--) {
- Plot plot = this.chart.getPlots().get(i);
- Rectangle2D rect = plot.getGraphArea();
- if (rect.contains(x, y)) {
- return plot;
- }
- }
- return null;
- }
-
- /**
- * Paint component
- *
- * @param g Graphics
- */
- @Override
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
-
- if (this.getWidth() < 5 || this.getHeight() < 5) {
- return;
- }
-
- //this.setBackground(Color.white);
- Graphics2D g2 = (Graphics2D) g;
-
- if (this.newPaint) {
- this.paintGraphics(g2);
- } else {
- AffineTransform mx = new AffineTransform();
- AffineTransformOp aop = new AffineTransformOp(mx, AffineTransformOp.TYPE_BICUBIC);
- g2.drawImage(mapBitmap, aop, 0, 0);
- }
-
- //Draw dynamic graphics
- if (this.dragMode) {
- switch (this.mouseMode) {
- case ZOOM_IN:
- case SELECT:
- int aWidth = Math.abs(mouseLastPos.x - mouseDownPoint.x);
- int aHeight = Math.abs(mouseLastPos.y - mouseDownPoint.y);
- int aX = Math.min(mouseLastPos.x, mouseDownPoint.x);
- int aY = Math.min(mouseLastPos.y, mouseDownPoint.y);
- g2.setColor(this.getForeground());
- float dash1[] = {2.0f};
- g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f));
- g2.draw(new Rectangle(aX, aY, aWidth, aHeight));
- break;
- }
- }
-
- //Draw identifer shape
- if (this.currentPlot != null) {
- if (this.currentPlot instanceof MapPlot) {
- MapPlot plot = (MapPlot) this.currentPlot;
- if (plot.getMapView().isDrawIdentiferShape()) {
- if (plot.getSelectedLayer() != null) {
- if (plot.getSelectedLayer().getLayerType() == LayerTypes.VectorLayer) {
- VectorLayer layer = (VectorLayer) plot.getSelectedLayer();
- Rectangle2D rect = plot.getGraphArea();
- Rectangle rr = new Rectangle((int) rect.getX(), (int) rect.getY(),
- (int) rect.getWidth(), (int) rect.getHeight());
- plot.getMapView().drawIdShape(g2, layer.getShapes().get(layer.getIdentiferShape()), rr);
- }
- }
- }
- }
- }
-
- g2.dispose();
- }
-
- /**
- * New paint
- */
- public void repaintNew() {
- if (this.doubleBuffer) {
- this.paintGraphics();
- } else {
- this.newPaint = true;
- this.repaint();
- this.updateViewImage();
- }
- }
-
- private void repaintOld() {
- if (this.doubleBuffer) {
- this.repaint();
- } else {
- this.newPaint = false;
- this.repaint();
- }
- }
-
- private void updateViewImage() {
- if (this.getWidth() < 5 || this.getHeight() < 5) {
- return;
- }
-
- int width, height;
- if (this.chartSize != null) {
- height = this.chartSize.height;
- width = this.chartSize.width;
- } else {
- width = this.getWidth();
- height = this.getHeight();
- }
-
- this.mapBitmap = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = this.mapBitmap.createGraphics();
- this.print(g);
- g.dispose();
- }
-
- /**
- * Paint graphics
- */
- @Override
- public void paintGraphics() {
- if (this.getWidth() < 5 || this.getHeight() < 5) {
- return;
- }
-
- int width, height;
- if (this.chartSize != null) {
- height = this.chartSize.height;
- width = this.chartSize.width;
- } else {
- width = this.getWidth();
- height = this.getHeight();
- }
-
- this.mapBitmap = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
-
- if (this.chart != null) {
- Graphics2D g = this.mapBitmap.createGraphics();
- Rectangle2D chartArea;
- if (this.chartSize == null) {
- chartArea = new Rectangle2D.Double(0.0, 0.0, this.mapBitmap.getWidth(), this.mapBitmap.getHeight());
- } else {
- chartArea = new Rectangle2D.Double(0.0, 0.0, this.chartSize.width, this.chartSize.height);
- }
- this.chart.draw(g, chartArea);
- }
- this.repaint();
- }
-
- public void paintGraphics(Graphics2D g) {
- if (this.chart != null) {
- Rectangle2D chartArea;
- if (this.chartSize == null) {
- chartArea = new Rectangle2D.Double(0.0, 0.0, this.getWidth(), this.getHeight());
- } else {
- chartArea = new Rectangle2D.Double(0.0, 0.0, this.chartSize.width, this.chartSize.height);
- }
- this.chart.draw(g, chartArea);
- }
- }
-
- public void paintGraphics(Graphics2D g, int width, int height) {
- if (this.chart != null) {
- Rectangle2D chartArea;
- chartArea = new Rectangle2D.Double(0.0, 0.0, width, height);
- this.chart.draw(g, chartArea);
- }
- }
-
- void onComponentResized(ComponentEvent e) {
- if (this.getWidth() > 0 && this.getHeight() > 0) {
- if (this.chart != null) {
- //this.paintGraphics();
- this.repaintNew();
- }
- }
- }
-
- void onMousePressed(MouseEvent e) {
- mouseDownPoint.x = e.getX();
- mouseDownPoint.y = e.getY();
- mouseLastPos = (Point) mouseDownPoint.clone();
- switch (this.mouseMode) {
- case PAN:
- Plot plot = selPlot(e.getX(), e.getY());
- if (plot != null) {
- Rectangle2D mapRect = plot.getGraphArea();
- tempImage = new BufferedImage((int) mapRect.getWidth() - 2,
- (int) mapRect.getHeight() - 2, BufferedImage.TYPE_INT_ARGB);
- Graphics2D tg = tempImage.createGraphics();
- tg.setColor(Color.white);
- tg.fill(mapRect);
- tg.drawImage(this.mapBitmap, -(int) mapRect.getX() - 1, -(int) mapRect.getY() - 1, this);
- tg.dispose();
- }
- break;
- }
- }
-
- void onMouseMoved(MouseEvent e) {
- this.dragMode = false;
-// switch (this.mouseMode) {
-// case PAN:
-// Plot plot = selPlot(e.getX(), e.getY());
-// if (plot != null) {
-// Rectangle2D mapRect = plot.getGraphArea();
-// tempImage = new BufferedImage((int) mapRect.getWidth() - 2,
-// (int) mapRect.getHeight() - 2, BufferedImage.TYPE_INT_ARGB);
-// Graphics2D tg = tempImage.createGraphics();
-// tg.setColor(Color.white);
-// tg.fill(mapRect);
-// tg.drawImage(this.mapBitmap, -(int) mapRect.getX() - 1, -(int) mapRect.getY() - 1, this);
-// tg.dispose();
-// }
-// break;
-// }
- }
-
- void onMouseReleased(MouseEvent e) {
- this.dragMode = false;
- Plot plt = this.chart.findPlot(mouseDownPoint.x, mouseDownPoint.y);
- if (!(plt instanceof AbstractPlot2D)) {
- return;
- }
-
- AbstractPlot2D xyplot = (AbstractPlot2D) plt;
- this.currentPlot = xyplot;
- switch (this.mouseMode) {
- case ZOOM_IN:
- if (Math.abs(mouseLastPos.x - mouseDownPoint.x) > 5) {
- if (xyplot instanceof MapPlot) {
- MapPlot plot = (MapPlot) xyplot;
- Rectangle2D graphArea = xyplot.getGraphArea();
- double[] xy1 = plot.screenToProj(mouseDownPoint.x - graphArea.getX(), mouseDownPoint.y - graphArea.getY(), graphArea);
- double[] xy2 = plot.screenToProj(mouseLastPos.x - graphArea.getX(), mouseLastPos.y - graphArea.getY(), graphArea);
- Extent extent = new Extent();
- extent.minX = Math.min(xy1[0], xy2[0]);
- extent.maxX = Math.max(xy1[0], xy2[0]);
- extent.minY = Math.min(xy1[1], xy2[1]);
- extent.maxY = Math.max(xy1[1], xy2[1]);
- plot.setDrawExtent(extent);
- //this.paintGraphics();
- this.repaintNew();
- } else {
- Rectangle2D graphArea = xyplot.getGraphArea();
- double[] xy1 = xyplot.screenToProj(mouseDownPoint.x - graphArea.getX(), mouseDownPoint.y - graphArea.getY(), graphArea);
- double[] xy2 = xyplot.screenToProj(mouseLastPos.x - graphArea.getX(), mouseLastPos.y - graphArea.getY(), graphArea);
- Extent extent = new Extent();
- extent.minX = Math.min(xy1[0], xy2[0]);
- extent.maxX = Math.max(xy1[0], xy2[0]);
- extent.minY = Math.min(xy1[1], xy2[1]);
- extent.maxY = Math.max(xy1[1], xy2[1]);
- if (xyplot.getXAxis().isInverse()) {
- Extent drawExtent = xyplot.getDrawExtent();
- double minx, maxx;
- minx = drawExtent.getWidth() - (extent.maxX - drawExtent.minX) + drawExtent.minX;
- maxx = drawExtent.getWidth() - (extent.minX - drawExtent.minX) + drawExtent.minX;
- extent.minX = minx;
- extent.maxX = maxx;
- }
- if (xyplot.getYAxis().isInverse()) {
- Extent drawExtent = xyplot.getDrawExtent();
- double miny, maxy;
- miny = drawExtent.getHeight() - (extent.maxY - drawExtent.minY) + drawExtent.minY;
- maxy = drawExtent.getHeight() - (extent.minY - drawExtent.minY) + drawExtent.minY;
- extent.minY = miny;
- extent.maxY = maxy;
- }
- xyplot.setDrawExtent(extent);
- //this.paintGraphics();
- this.repaintNew();
- }
- }
- break;
- case ZOOM_OUT:
- if (e.getButton() == MouseEvent.BUTTON1) {
- double zoom = 1.5;
- Extent extent = xyplot.getDrawExtent();
- double owidth = extent.getWidth();
- double oheight = extent.getHeight();
- double width = owidth * zoom;
- double height = oheight * zoom;
- double xshift = (owidth - width) * 0.5;
- double yshift = (oheight - height) * 0.5;
- extent.minX += xshift;
- extent.maxX -= xshift;
- extent.minY += yshift;
- extent.maxY -= yshift;
- xyplot.setDrawExtent(extent);
- //this.paintGraphics();
- this.repaintNew();
- }
- break;
- case SELECT:
- if (Math.abs(mouseLastPos.x - mouseDownPoint.x) > 5) {
- if (xyplot instanceof XY1DPlot) {
- XY1DPlot plot = (XY1DPlot) xyplot;
- Rectangle2D graphArea = plot.getGraphArea();
- if (graphArea.contains(mouseDownPoint.x, mouseDownPoint.y) || graphArea.contains(mouseLastPos.x, mouseLastPos.y)) {
- double[] xy1 = plot.screenToProj(mouseDownPoint.x - graphArea.getX(), mouseDownPoint.y - graphArea.getY(), graphArea);
- double[] xy2 = plot.screenToProj(mouseLastPos.x - graphArea.getX(), mouseLastPos.y - graphArea.getY(), graphArea);
- Extent extent = new Extent();
- extent.minX = Math.min(xy1[0], xy2[0]);
- extent.maxX = Math.max(xy1[0], xy2[0]);
- extent.minY = Math.min(xy1[1], xy2[1]);
- extent.maxY = Math.max(xy1[1], xy2[1]);
- this.selectedPoints = plot.getDataset().selectPoints(extent);
- this.firePointSelectedEvent();
- //this.paintGraphics();
- this.repaintNew();
- }
- }
- }
- break;
- case PAN:
- if (e.getButton() == MouseEvent.BUTTON1) {
- int deltaX = e.getX() - mouseDownPoint.x;
- int deltaY = e.getY() - mouseDownPoint.y;
- double minX = -deltaX;
- double minY = -deltaY;
- double maxX = xyplot.getGraphArea().getWidth() - deltaX;
- double maxY = xyplot.getGraphArea().getHeight() - deltaY;
- xyplot.zoomToExtentScreen(minX, maxX, minY, maxY);
- //this.paintGraphics();
- this.repaintNew();
- }
- break;
- }
- }
-
- void onMouseDragged(MouseEvent e) {
- this.dragMode = true;
- int x = e.getX();
- int y = e.getY();
- switch (this.mouseMode) {
- case ZOOM_IN:
- case SELECT:
- this.repaintOld();
- break;
- case PAN:
- Plot plot = selPlot(e.getX(), e.getY());
- if (plot != null) {
- Graphics2D g = (Graphics2D) this.getGraphics();
- Rectangle2D mapRect = plot.getGraphArea();
- g.setClip(mapRect);
- g.setColor(Color.white);
- int aX = e.getX() - mouseDownPoint.x;
- int aY = e.getY() - mouseDownPoint.y;
- if (aX > 0) {
- if (mapRect.getX() >= 0) {
- g.fillRect((int) mapRect.getX(), (int) mapRect.getY(), aX, (int) mapRect.getHeight());
- } else {
- g.fillRect(0, (int) mapRect.getY(), aX, (int) mapRect.getHeight());
- }
- } else if (mapRect.getX() <= this.getWidth()) {
- g.fillRect((int) (mapRect.getX() + mapRect.getWidth() + aX), (int) mapRect.getY(), Math.abs(aX), (int) mapRect.getHeight());
- } else {
- g.fillRect(this.getWidth() + aX, (int) mapRect.getY(), Math.abs(aX), (int) mapRect.getHeight());
- }
- if (aY > 0) {
- if (mapRect.getY() >= 0) {
- g.fillRect((int) mapRect.getX(), (int) mapRect.getY(), (int) mapRect.getWidth(), aY);
- } else {
- g.fillRect((int) mapRect.getX(), 0, (int) mapRect.getWidth(), aY);
- }
- } else if (mapRect.getY() + mapRect.getHeight() <= this.getX() + this.getHeight()) {
- g.fillRect((int) mapRect.getX(), (int) mapRect.getY() + (int) mapRect.getHeight() + aY, (int) mapRect.getWidth(), Math.abs(aY));
- } else {
- g.fillRect((int) mapRect.getX(), this.getY() + this.getHeight() + aY, (int) mapRect.getWidth(), Math.abs(aY));
- }
- int startX = (int) mapRect.getX() + aX;
- int startY = (int) mapRect.getY() + aY;
- g.drawImage(tempImage, startX, startY, this);
- g.setColor(this.getForeground());
- g.draw(mapRect);
- }
- break;
- case ROTATE:
- plot = selPlot(this.mouseDownPoint.x, this.mouseDownPoint.y);
- if (plot != null && plot.getPlotType() == PlotType.XYZ) {
- Plot3D plot3d = (Plot3D) plot;
- Projector projector = plot3d.getProjector();
- float new_value = 0.0f;
- // if (!thread.isAlive() || !data_available) {
- if (e.isControlDown()) {
- projector.set2D_xTranslation(projector.get2D_xTranslation() + (x - this.mouseLastPos.x));
- projector.set2D_yTranslation(projector.get2D_yTranslation() + (y - this.mouseLastPos.y));
- } else if (e.isShiftDown()) {
- new_value = projector.getY2DScaling() + (y - this.mouseLastPos.y) * 0.5f;
- if (new_value > 60.0f) {
- new_value = 60.0f;
- }
- if (new_value < 2.0f) {
- new_value = 2.0f;
- }
- projector.set2DScaling(new_value);
- } else {
- new_value = projector.getRotationAngle() + (x - this.mouseLastPos.x);
- while (new_value > 360) {
- new_value -= 360;
- }
- while (new_value < 0) {
- new_value += 360;
- }
- projector.setRotationAngle(new_value);
- new_value = projector.getElevationAngle() + (y - this.mouseLastPos.y);
- if (new_value > 90) {
- new_value = 90;
- } else if (new_value < 0) {
- new_value = 0;
- }
- projector.setElevationAngle(new_value);
- }
- this.repaintNew();
- //this.paintGraphics();
-// if (!model.isExpectDelay()) {
-// repaint();
-// } else {
-// if (!dragged) {
-// is_data_available = data_available;
-// dragged = true;
-// }
-// data_available = false;
-// repaint();
-// }
- }
- break;
- }
- mouseLastPos.x = x;
- mouseLastPos.y = y;
- }
-
- void onMouseClicked(MouseEvent e) {
- int clickTimes = e.getClickCount();
- if (clickTimes == 1) {
- if (e.getButton() == MouseEvent.BUTTON1) {
- switch (this.mouseMode) {
- case IDENTIFER:
- Plot plot = selPlot(e.getX(), e.getY());
- if (plot == null) {
- return;
- }
-
- if (!(plot instanceof MapPlot)) {
- return;
- }
-
- this.currentPlot = plot;
- MapPlot mplot = (MapPlot) plot;
- final MapView mapView = mplot.getMapView();
- MapLayer aMLayer = mplot.getSelectedLayer();
- if (aMLayer == null) {
- return;
- }
- if (aMLayer.getLayerType() == LayerTypes.ImageLayer) {
- return;
- }
-
- Rectangle2D rect = mplot.getGraphArea();
- PointF aPoint = new PointF(e.getX() - (float) rect.getX(), e.getY() - (float) rect.getY());
- if (aMLayer.getLayerType() == LayerTypes.VectorLayer) {
- VectorLayer aLayer = (VectorLayer) aMLayer;
- List selectedShapes = mapView.selectShapes(aLayer, aPoint, true, false);
- if (selectedShapes.size() > 0) {
- if (mapView.frmIdentifer == null) {
- mapView.frmIdentifer = new FrmIdentifer((JFrame) SwingUtilities.getWindowAncestor(this), false, mapView);
- mapView.frmIdentifer.addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosed(WindowEvent e) {
- mapView.setDrawIdentiferShape(false);
- ChartPanel.this.repaintOld();
- }
- });
- }
- String[] colNames = {"Field", "Value"};
- String fieldStr, valueStr;
- int shapeIdx = selectedShapes.get(0);
- aLayer.setIdentiferShape(shapeIdx);
- mapView._drawIdentiferShape = true;
-
- Object[][] tData = new Object[aLayer.getFieldNumber() + 1][2];
- fieldStr = "Index";
- valueStr = String.valueOf(shapeIdx);
- tData[0][0] = fieldStr;
- tData[0][1] = valueStr;
- Object value;
- if (aLayer.getShapeNum() > 0) {
- for (int i = 0; i < aLayer.getFieldNumber(); i++) {
- Field field = aLayer.getField(i);
- fieldStr = field.getColumnName();
- value = aLayer.getCellValue(i, shapeIdx);
- if (value == null) {
- valueStr = "";
- } else if (field.getDataType() == DataType.DATE) {
- DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd");
- valueStr = format.format((LocalDateTime) value);
- } else {
- valueStr = value.toString();
- }
- tData[i + 1][0] = fieldStr;
- tData[i + 1][1] = valueStr;
- }
- }
- DefaultTableModel dtm = new DefaultTableModel(tData, colNames) {
- @Override
- public boolean isCellEditable(int row, int column) {
- return false;
- }
- };
- mapView.frmIdentifer.getTable().setModel(dtm);
- mapView.frmIdentifer.repaint();
- if (!mapView.frmIdentifer.isVisible()) {
- //this._frmIdentifer.setLocation(e.getX(), e.getY());
- mapView.frmIdentifer.setLocationRelativeTo(this);
- mapView.frmIdentifer.setVisible(true);
- }
-
- mapView.setDrawIdentiferShape(true);
- this.repaintOld();
- }
- } else if (aMLayer.getLayerType() == LayerTypes.RasterLayer) {
- RasterLayer aRLayer = (RasterLayer) aMLayer;
- int[] ijIdx = mapView.selectGridCell(aRLayer, aPoint);
- if (ijIdx != null) {
- int iIdx = ijIdx[0];
- int jIdx = ijIdx[1];
- double aValue = aRLayer.getCellValue(iIdx, jIdx);
- if (mapView._frmIdentiferGrid == null) {
- mapView._frmIdentiferGrid = new FrmIdentiferGrid((JFrame) SwingUtilities.getWindowAncestor(this), false);
- }
-
- mapView._frmIdentiferGrid.setIIndex(iIdx);
- mapView._frmIdentiferGrid.setJIndex(jIdx);
- mapView._frmIdentiferGrid.setCellValue(aValue);
- if (!mapView._frmIdentiferGrid.isVisible()) {
- //this._frmIdentiferGrid.setLocation(e.getX(), e.getY());
- mapView._frmIdentiferGrid.setLocationRelativeTo(this);
- mapView._frmIdentiferGrid.setVisible(true);
- }
- }
- }
- break;
- }
- } else if (e.getButton() == MouseEvent.BUTTON3) {
- popupMenu.show(this, e.getX(), e.getY());
- }
- }
- }
-
- void onMouseWheelMoved(MouseWheelEvent e) {
- Plot plt = selPlot(e.getX(), e.getY());
- if (!(plt instanceof AbstractPlot2D)) {
- return;
- }
-
- double minX, maxX, minY, maxY, lonRan, latRan, zoomF;
- double mouseLon, mouseLat;
- Extent drawExtent = ((AbstractPlot2D) plt).getDrawExtent();
- lonRan = drawExtent.maxX - drawExtent.minX;
- latRan = drawExtent.maxY - drawExtent.minY;
- mouseLon = drawExtent.minX + lonRan / 2;
- mouseLat = drawExtent.minY + latRan / 2;
-
- zoomF = 1 + e.getWheelRotation() / 10.0f;
-
- minX = mouseLon - (lonRan / 2 * zoomF);
- maxX = mouseLon + (lonRan / 2 * zoomF);
- minY = mouseLat - (latRan / 2 * zoomF);
- maxY = mouseLat + (latRan / 2 * zoomF);
- switch (this.mouseMode) {
- case PAN:
- if (plt instanceof MapPlot) {
- MapPlot mplt = (MapPlot) plt;
- Graphics2D g = (Graphics2D) this.getGraphics();
- Rectangle2D mapRect = mplt.getGraphArea();
-
- this.lastMouseWheelTime = LocalDateTime.now();
- if (!this.mouseWheelDetctionTimer.isRunning()) {
- this.mouseWheelDetctionTimer.start();
- tempImage = new BufferedImage((int) mapRect.getWidth() - 2,
- (int) mapRect.getHeight() - 2, BufferedImage.TYPE_INT_ARGB);
- Graphics2D tg = tempImage.createGraphics();
- tg.setColor(Color.white);
- tg.fill(mapRect);
- tg.drawImage(this.mapBitmap, -(int) mapRect.getX() - 1, -(int) mapRect.getY() - 1, this);
- tg.dispose();
- }
-
- g.setClip(mapRect);
- g.setColor(Color.white);
- //g.clearRect((int)mapRect.getX(), (int)mapRect.getY(), (int)mapRect.getWidth(), (int)mapRect.getHeight());
- paintScale = paintScale / zoomF;
- float nWidth = (float)mapRect.getWidth() * (float) paintScale;
- float nHeight = (float)mapRect.getHeight() * (float) paintScale;
- float nx = ((float)mapRect.getWidth() - nWidth) / 2;
- float ny = ((float)mapRect.getHeight() - nHeight) / 2;
- if (nx > 0) {
- g.fillRect((int) mapRect.getX(), (int) mapRect.getY(), (int)nx, (int) mapRect.getHeight());
- g.fillRect((int) (mapRect.getMaxX() - nx), (int) mapRect.getY(), (int)nx, (int) mapRect.getHeight());
- }
- if (ny > 0) {
- g.fillRect((int) mapRect.getX(), (int) mapRect.getY(), (int) mapRect.getWidth(), (int)ny);
- g.fillRect((int) mapRect.getX(), (int) (mapRect.getMaxY() - ny), (int) mapRect.getWidth(), (int)ny);
- }
- g.drawImage(tempImage, (int)(mapRect.getX() + nx), (int)(mapRect.getY() + ny),
- (int)nWidth, (int)nHeight, null);
- g.setColor(this.getForeground());
- g.draw(mapRect);
- mplt.setDrawExtent(new Extent(minX, maxX, minY, maxY));
- } else {
- ((AbstractPlot2D) plt).setDrawExtent(new Extent(minX, maxX, minY, maxY));
- //this.paintGraphics();
- this.repaintNew();
- }
- break;
- }
- }
-
- /**
- * Zoom back to full extent
- */
- @Override
- public void onUndoZoomClick() {
- AbstractPlot2D xyplot;
- if (this.currentPlot == null) {
- xyplot = (AbstractPlot2D) this.chart.getPlots().get(0);
- } else {
- xyplot = (AbstractPlot2D) this.currentPlot;
- }
- xyplot.setDrawExtent((Extent) xyplot.getExtent().clone());
-// if (xyplot instanceof MapPlot) {
-// MapPlot plot = (MapPlot) xyplot;
-// plot.setDrawExtent(plot.getMapView().getLastAddedLayer().getExtent());
-// } else {
-// xyplot.setAutoExtent();
-// }
- //this.paintGraphics();
- this.repaintNew();
- }
-
- private void onSaveFigureClick(ActionEvent e) {
- String path = System.getProperty("user.dir");
- File pathDir = new File(path);
- JFileChooser aDlg = new JFileChooser();
- aDlg.setCurrentDirectory(pathDir);
- String[] fileExts = new String[]{"png"};
- GenericFileFilter pngFileFilter = new GenericFileFilter(fileExts, "Png Image (*.png)");
- aDlg.addChoosableFileFilter(pngFileFilter);
- fileExts = new String[]{"gif"};
- GenericFileFilter mapFileFilter = new GenericFileFilter(fileExts, "Gif Image (*.gif)");
- aDlg.addChoosableFileFilter(mapFileFilter);
- fileExts = new String[]{"jpg"};
- mapFileFilter = new GenericFileFilter(fileExts, "Jpeg Image (*.jpg)");
- aDlg.addChoosableFileFilter(mapFileFilter);
- fileExts = new String[]{"eps"};
- mapFileFilter = new GenericFileFilter(fileExts, "EPS file (*.eps)");
- aDlg.addChoosableFileFilter(mapFileFilter);
- fileExts = new String[]{"pdf"};
- mapFileFilter = new GenericFileFilter(fileExts, "PDF file (*.pdf)");
- aDlg.addChoosableFileFilter(mapFileFilter);
- fileExts = new String[]{"emf"};
- mapFileFilter = new GenericFileFilter(fileExts, "EMF file (*.emf)");
- aDlg.addChoosableFileFilter(mapFileFilter);
- aDlg.setFileFilter(pngFileFilter);
- aDlg.setAcceptAllFileFilterUsed(false);
- if (JFileChooser.APPROVE_OPTION == aDlg.showSaveDialog(this)) {
- File aFile = aDlg.getSelectedFile();
- System.setProperty("user.dir", aFile.getParent());
- String extent = ((GenericFileFilter) aDlg.getFileFilter()).getFileExtent();
- String fileName = aFile.getAbsolutePath();
- if (!fileName.substring(fileName.length() - extent.length()).equals(extent)) {
- fileName = fileName + "." + extent;
- }
- if (new File(fileName).exists()) {
- int overwrite = JOptionPane.showConfirmDialog(this, "File exists! Overwrite it?");
- if (overwrite == JOptionPane.YES_OPTION) {
- this.saveImage(fileName);
- }
- } else {
- this.saveImage(fileName);
- }
- }
- }
-
- /**
- * Save image to a picture file
- *
- * @param aFile File path
- */
- @Override
- public void saveImage(String aFile) {
- try {
- saveImage(aFile, null);
- } catch (PrintException | IOException | InterruptedException ex) {
- Logger.getLogger(ChartPanel.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
-
- /**
- * Save image to a picture file
- *
- * @param aFile File path
- * @param sleep Sleep seconds for web map layer
- * @throws FileNotFoundException
- * @throws PrintException
- * @throws InterruptedException
- */
- public void saveImage(String aFile, Integer sleep) throws FileNotFoundException, PrintException, IOException, InterruptedException {
- int w, h;
- if (this.chartSize == null) {
- w = this.getWidth();
- h = this.getHeight();
- } else {
- w = this.chartSize.width;
- h = this.chartSize.height;
- }
- this.saveImage(aFile, w, h, sleep);
- }
-
- /**
- * Save image to a picture file
- *
- * @param aFile File path
- * @param width Width
- * @param height Height
- * @param sleep Sleep seconds for web map layer
- * @throws FileNotFoundException
- * @throws PrintException
- * @throws InterruptedException
- */
- public void saveImage(String aFile, int width, int height, Integer sleep) throws FileNotFoundException, PrintException, IOException, InterruptedException {
- if (aFile.endsWith(".ps")) {
- DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
- String mimeType = "application/postscript";
- StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, mimeType);
- FileOutputStream out = new FileOutputStream(aFile);
- if (factories.length > 0) {
- PrintService service = factories[0].getPrintService(out);
- SimpleDoc doc = new SimpleDoc(new Printable() {
- @Override
- public int print(Graphics g, PageFormat pf, int page) {
- if (page >= 1) {
- return Printable.NO_SUCH_PAGE;
- } else {
- double sf1 = pf.getImageableWidth() / (getWidth() + 1);
- double sf2 = pf.getImageableHeight() / (getHeight() + 1);
- double s = Math.min(sf1, sf2);
- Graphics2D g2 = (Graphics2D) g;
- g2.translate((pf.getWidth() - pf.getImageableWidth()) / 2, (pf.getHeight() - pf.getImageableHeight()) / 2);
- g2.scale(s, s);
-
- paintGraphics(g2);
- return Printable.PAGE_EXISTS;
- }
- }
- }, flavor, null);
- DocPrintJob job = service.createPrintJob();
- PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
- job.print(doc, attributes);
- out.close();
- }
- } else if (aFile.endsWith(".eps")) {
- Properties p = new Properties();
- p.setProperty("PageSize", "A5");
- VectorGraphics g = new PSGraphics2D(new File(aFile), new Dimension(width, height));
- //g.setProperties(p);
- g.startExport();
- //this.paintGraphics(g);
- this.paintGraphics(g, width, height);
- g.endExport();
- g.dispose();
- } else if (aFile.endsWith(".pdf")) {
- try {
- Document document = new Document(new com.itextpdf.text.Rectangle(width, height));
- PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(aFile));
- document.open();
- PdfContentByte cb = writer.getDirectContent();
- PdfTemplate pdfTemp = cb.createTemplate(width, height);
- Graphics2D g2 = new PdfGraphics2D(pdfTemp, width, height, true);
- this.paintGraphics(g2, width, height);
- g2.dispose();
- cb.addTemplate(pdfTemp, 0, 0);
- document.close();
- } catch (DocumentException | FileNotFoundException e) {
- e.printStackTrace();
- }
- } else if (aFile.endsWith(".emf")) {
- VectorGraphics g = new EMFGraphics2D(new File(aFile), new Dimension(width, height));
- //g.setProperties(p);
- g.startExport();
- //this.paintGraphics(g);
- this.paintGraphics(g, width, height);
- g.endExport();
- g.dispose();
- } else {
- //String extension = aFile.substring(aFile.lastIndexOf('.') + 1);
- //ImageIO.write(this.mapBitmap, extension, new File(aFile));
-
- String extension = aFile.substring(aFile.lastIndexOf('.') + 1);
- BufferedImage aImage;
- if (extension.equalsIgnoreCase("bmp")) {
- aImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
- } else {
- aImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- }
- Graphics2D g = aImage.createGraphics();
- paintGraphics(g, width, height);
-
- if (sleep != null) {
- Thread.sleep(sleep * 1000);
- }
-
- if (extension.equalsIgnoreCase("jpg")) {
- BufferedImage newImage = new BufferedImage(aImage.getWidth(), aImage.getHeight(), BufferedImage.TYPE_INT_RGB);
- newImage.createGraphics().drawImage(aImage, 0, 0, Color.BLACK, null);
- ImageIO.write(newImage, extension, new File(aFile));
- } else {
- ImageIO.write(aImage, extension, new File(aFile));
- }
- }
- }
-
- /**
- * Save image to a picture file
- *
- * @param aFile File path
- * @param width Width
- * @param height Height
- * @param sleep Sleep seconds for web map layer
- * @throws FileNotFoundException
- * @throws PrintException
- * @throws InterruptedException
- */
- public void saveImage_bak(String aFile, int width, int height, Integer sleep) throws FileNotFoundException, PrintException, IOException, InterruptedException {
- if (aFile.endsWith(".ps")) {
- DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
- String mimeType = "application/postscript";
- StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, mimeType);
- FileOutputStream out = new FileOutputStream(aFile);
- if (factories.length > 0) {
- PrintService service = factories[0].getPrintService(out);
- SimpleDoc doc = new SimpleDoc(new Printable() {
- @Override
- public int print(Graphics g, PageFormat pf, int page) {
- if (page >= 1) {
- return Printable.NO_SUCH_PAGE;
- } else {
- double sf1 = pf.getImageableWidth() / (getWidth() + 1);
- double sf2 = pf.getImageableHeight() / (getHeight() + 1);
- double s = Math.min(sf1, sf2);
- Graphics2D g2 = (Graphics2D) g;
- g2.translate((pf.getWidth() - pf.getImageableWidth()) / 2, (pf.getHeight() - pf.getImageableHeight()) / 2);
- g2.scale(s, s);
-
- paintGraphics(g2);
- return Printable.PAGE_EXISTS;
- }
- }
- }, flavor, null);
- DocPrintJob job = service.createPrintJob();
- PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
- job.print(doc, attributes);
- out.close();
- }
- } else if (aFile.endsWith(".eps")) {
-// EPSGraphics2D g = new EPSGraphics2D(0.0, 0.0, width, height);
-// paintGraphics(g);
-// FileOutputStream file = new FileOutputStream(aFile);
-// try {
-// file.write(g.getBytes());
-// } finally {
-// file.close();
-// g.dispose();
-// }
-
- Properties p = new Properties();
- p.setProperty("PageSize", "A5");
- VectorGraphics g = new PSGraphics2D(new File(aFile), new Dimension(width, height));
- //g.setProperties(p);
- g.startExport();
- //this.paintGraphics(g);
- this.paintGraphics(g, width, height);
- g.endExport();
- g.dispose();
- } else if (aFile.endsWith(".pdf")) {
- VectorGraphics g = new PDFGraphics2D(new File(aFile), new Dimension(width, height));
- //g.setProperties(p);
- g.startExport();
- this.paintGraphics(g, width, height);
- g.endExport();
- g.dispose();
- } else if (aFile.endsWith(".emf")) {
- VectorGraphics g = new EMFGraphics2D(new File(aFile), new Dimension(width, height));
- //g.setProperties(p);
- g.startExport();
- //this.paintGraphics(g);
- this.paintGraphics(g, width, height);
- g.endExport();
- g.dispose();
- } else {
- //String extension = aFile.substring(aFile.lastIndexOf('.') + 1);
- //ImageIO.write(this.mapBitmap, extension, new File(aFile));
-
- String extension = aFile.substring(aFile.lastIndexOf('.') + 1);
- BufferedImage aImage;
- if (extension.equalsIgnoreCase("bmp")) {
- aImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
- } else {
- aImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- }
- Graphics2D g = aImage.createGraphics();
- paintGraphics(g, width, height);
-
- if (sleep != null) {
- Thread.sleep(sleep * 1000);
- }
-
- if (extension.equalsIgnoreCase("jpg")) {
- BufferedImage newImage = new BufferedImage(aImage.getWidth(), aImage.getHeight(), BufferedImage.TYPE_INT_RGB);
- newImage.createGraphics().drawImage(aImage, 0, 0, Color.BLACK, null);
- ImageIO.write(newImage, extension, new File(aFile));
- } else {
- ImageIO.write(aImage, extension, new File(aFile));
- }
- }
- }
-
- /**
- * Save image to Jpeg file
- *
- * @param fileName File name
- * @param dpi DPI
- * @throws IOException
- */
- public void saveImage_Jpeg_old(String fileName, int dpi) throws IOException {
- BufferedImage image = this.mapBitmap;
- Iterator i = ImageIO.getImageWritersByFormatName("jpeg");
- //are there any jpeg encoders available?
-
- if (i.hasNext()) //there's at least one ImageWriter, just use the first one
- {
- ImageWriter imageWriter = (ImageWriter) i.next();
- //get the param
- ImageWriteParam param = imageWriter.getDefaultWriteParam();
- ImageTypeSpecifier its = new ImageTypeSpecifier(image.getColorModel(), image.getSampleModel());
-
- //get metadata
- IIOMetadata iomd = imageWriter.getDefaultImageMetadata(its,
- param);
-
- String formatName = "javax_imageio_jpeg_image_1.0";//this is the DOCTYPE of the metadata we need
-
- Node node = iomd.getAsTree(formatName);
- //what are child nodes?
- NodeList nl = node.getChildNodes();
- for (int j = 0; j < nl.getLength(); j++) {
- Node n = nl.item(j);
- System.out.println("node from IOMetadata is : "
- + n.getNodeName());
-
- if (n.getNodeName().equals("JPEGvariety")) {
- NodeList childNodes = n.getChildNodes();
-
- for (int k = 0; k < childNodes.getLength(); k++) {
- System.out.println("node #" + k + " is "
- + childNodes.item(k).getNodeName());
- if (childNodes.item(k).getNodeName().equals("app0JFIF")) {
- NamedNodeMap nnm = childNodes.item(k).getAttributes();
- //get the resUnits, Xdensity, and Ydensity attribuutes
- Node resUnitsNode = getAttributeByName(childNodes.item(k), "resUnits");
- Node XdensityNode = getAttributeByName(childNodes.item(k), "Xdensity");
- Node YdensityNode = getAttributeByName(childNodes.item(k), "Ydensity");
-
- //reset values for nodes
- resUnitsNode.setNodeValue("1"); //indicate DPI mode
- XdensityNode.setNodeValue(String.valueOf(dpi));
- YdensityNode.setNodeValue(String.valueOf(dpi));
-
- System.out.println("name="
- + resUnitsNode.getNodeName() + ", value=" + resUnitsNode.getNodeValue());
- System.out.println("name="
- + XdensityNode.getNodeName() + ", value=" + XdensityNode.getNodeValue());
- System.out.println("name="
- + YdensityNode.getNodeName() + ", value=" + YdensityNode.getNodeValue());
-
- } //end if (childNodes.item(k).getNodeName().equals("app0JFIF"))
- } //end if (n.getNodeName().equals("JPEGvariety")
- break; //we don't care about the rest of the children
- } //end if (n.getNodeName().equals("JPEGvariety"))
-
- } //end for (int j = 0; j < nl.getLength(); j++)
-
- try {
- iomd.setFromTree(formatName, node);
- } catch (IIOInvalidTreeException e) {
- e.printStackTrace(); //To change body of catch statement use Options | File Templates.
- }
- //attach the metadata to an image
- IIOImage iioimage = new IIOImage(image, null, iomd);
- FileImageOutputStream stream = new FileImageOutputStream(new File(fileName));
- try {
- imageWriter.setOutput(stream);
- imageWriter.write(iioimage);
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- stream.close();
- }
- } //end if (i.hasNext()) //there's at least one ImageWriter, just use the first one
- }
-
- /**
- * @param node
- * @param attributeName - name of child node to return
- * @return Node
- */
- private Node getAttributeByName(Node node, String attributeName) {
- if (node == null) {
- return null;
- }
- NamedNodeMap nnm = node.getAttributes();
- for (int i = 0; i < nnm.getLength(); i++) {
- Node n = nnm.item(i);
- if (n.getNodeName().equals(attributeName)) {
- return n;
- }
- }
- return null; // no such attribute was found
- }
-
- public boolean saveImage_Jpeg(String file, int dpi) {
- int w, h;
- if (this.chartSize == null) {
- w = this.getWidth();
- h = this.getHeight();
- } else {
- w = this.chartSize.width;
- h = this.chartSize.height;
- }
- return this.saveImage_Jpeg(file, w, h, dpi);
- }
-
- public boolean saveImage_Jpeg(String file, int width, int height, int dpi) {
- double scaleFactor = dpi / 72.0;
- BufferedImage bufferedImage = new BufferedImage((int)(width * scaleFactor), (int)(height * scaleFactor), BufferedImage.TYPE_INT_RGB);
- Graphics2D g = bufferedImage.createGraphics();
- AffineTransform at = g.getTransform();
- at.scale(scaleFactor, scaleFactor);
- g.setTransform(at);
- paintGraphics(g, width, height);
-
- try {
- // Image writer
- ImageWriter imageWriter = ImageIO.getImageWritersBySuffix("jpeg").next();
- ImageOutputStream ios = ImageIO.createImageOutputStream(new File(file));
- imageWriter.setOutput(ios);
-
- // Compression
- JPEGImageWriteParam jpegParams = (JPEGImageWriteParam) imageWriter.getDefaultWriteParam();
- jpegParams.setCompressionMode(JPEGImageWriteParam.MODE_EXPLICIT);
- jpegParams.setCompressionQuality(0.85f);
-
- // Metadata (dpi)
- IIOMetadata data = imageWriter.getDefaultImageMetadata(new ImageTypeSpecifier(bufferedImage), jpegParams);
- Element tree = (Element) data.getAsTree("javax_imageio_jpeg_image_1.0");
- Element jfif = (Element) tree.getElementsByTagName("app0JFIF").item(0);
- jfif.setAttribute("Xdensity", Integer.toString(dpi));
- jfif.setAttribute("Ydensity", Integer.toString(dpi));
- jfif.setAttribute("resUnits", "1"); // density is dots per inch
- data.setFromTree("javax_imageio_jpeg_image_1.0", tree);
-
- // Write and clean up
- imageWriter.write(null, new IIOImage(bufferedImage, null, data), jpegParams);
- ios.close();
- imageWriter.dispose();
- } catch (Exception e) {
- return false;
- }
- g.dispose();
-
- return true;
- }
-
- /**
- * Save image
- *
- * @param fileName File name
- * @param dpi DPI
- * @throws IOException
- * @throws InterruptedException
- */
- public void saveImage(String fileName, int dpi) throws IOException, InterruptedException {
- saveImage(fileName, dpi, null);
- }
-
- /**
- * Save image
- *
- * @param fileName File name
- * @param dpi DPI
- * @param sleep Sleep seconds for web map layer
- * @throws IOException
- * @throws InterruptedException
- */
- public void saveImage(String fileName, int dpi, Integer sleep) throws IOException, InterruptedException {
- int width, height;
- if (this.chartSize != null) {
- height = this.chartSize.height;
- width = this.chartSize.width;
- } else {
- width = this.getWidth();
- height = this.getHeight();
- }
-
- this.saveImage(fileName,dpi, width, height, sleep);
- }
-
- /**
- * Save image
- *
- * @param fileName File name
- * @param dpi DPI
- * @param width Width
- * @param height Height
- * @param sleep Sleep seconds for web map layer
- * @throws IOException
- * @throws InterruptedException
- */
- public void saveImage(String fileName, int dpi, int width, int height, Integer sleep) throws IOException, InterruptedException {
- File output = new File(fileName);
- output.delete();
-
- String formatName = fileName.substring(fileName.lastIndexOf('.') + 1);
- if (formatName.equals("jpg")) {
- formatName = "jpeg";
- saveImage_Jpeg(fileName, width, height, dpi);
- return;
- }
-
- double scaleFactor = dpi / 72.0;
- BufferedImage image = new BufferedImage((int)(width * scaleFactor), (int)(height * scaleFactor), BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = image.createGraphics();
- AffineTransform at = g.getTransform();
- at.scale(scaleFactor, scaleFactor);
- g.setTransform(at);
- paintGraphics(g, width, height);
- for (Iterator iw = ImageIO.getImageWritersByFormatName(formatName); iw.hasNext();) {
- ImageWriter writer = iw.next();
- ImageWriteParam writeParam = writer.getDefaultWriteParam();
- ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_ARGB);
- IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);
- if (metadata == null) {
- metadata = writer.getDefaultImageMetadata(typeSpecifier, null);
- }
- if (metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported()) {
- continue;
- }
-
- ImageUtil.setDPI(metadata, dpi);
-
- if (sleep != null) {
- Thread.sleep(sleep * 1000);
- }
- final ImageOutputStream stream = ImageIO.createImageOutputStream(output);
- try {
- writer.setOutput(stream);
- writer.write(metadata, new IIOImage(image, null, metadata), writeParam);
- } finally {
- stream.close();
- }
- break;
- }
- g.dispose();
- }
-
- /**
- * Get view image
- *
- * @return View image
- */
- public BufferedImage getViewImage() {
- return this.mapBitmap;
- }
-
- /**
- * Paint view image
- *
- * @return View image
- */
- public BufferedImage paintViewImage() {
- int w, h;
- if (this.chartSize == null) {
- w = this.getWidth();
- h = this.getHeight();
- } else {
- w = this.chartSize.width;
- h = this.chartSize.height;
- }
- return paintViewImage(w, h);
- }
-
- /**
- * Paint view image
- *
- * @param width Image width
- * @param height Image height
- * @return View image
- */
- public BufferedImage paintViewImage(int width, int height) {
- BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = image.createGraphics();
- paintGraphics(g);
-
- return image;
- }
-
- /**
- * Paint view image
- *
- * @param dpi Image resolution
- * @return View image
- */
- public BufferedImage paintViewImage(int dpi) {
- int w, h;
- if (this.chartSize == null) {
- w = this.getWidth();
- h = this.getHeight();
- } else {
- w = this.chartSize.width;
- h = this.chartSize.height;
- }
- return paintViewImage(w, h, dpi);
- }
-
- /**
- * Paint view image
- *
- * @param width Image width
- * @param height Image height
- * @param dpi Image resolution
- * @return View image
- */
- public BufferedImage paintViewImage(int width, int height, int dpi) {
- double scaleFactor = dpi / 72.0;
- BufferedImage image = new BufferedImage((int)(width * scaleFactor), (int)(height * scaleFactor),
- BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = image.createGraphics();
- AffineTransform at = g.getTransform();
- at.scale(scaleFactor, scaleFactor);
- g.setTransform(at);
- paintGraphics(g, width, height);
-
- return image;
- }
-
- /**
- * Check if has web map layer
- *
- * @return Boolean
- */
- public boolean hasWebMap() {
- if (this.chart != null) {
- return this.chart.hasWebMap();
- }
-
- return false;
- }
- //
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartScaleBar.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartScaleBar.java
deleted file mode 100644
index 4e813f5d..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartScaleBar.java
+++ /dev/null
@@ -1,457 +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;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.FontMetrics;
-import java.awt.Graphics2D;
-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.common.PointF;
-import org.meteoinfo.layout.ScaleBarType;
-import org.meteoinfo.layout.ScaleBarUnits;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class ChartScaleBar extends ChartElement {
- //
-
- private MapPlot mapPlot;
- private boolean _antiAlias;
- private float lineWidth;
- private Font _font;
- private ScaleBarType _scaleBarType;
- private ScaleBarUnits _unit;
- private String _unitText;
- private int _numBreaks;
- private boolean _drawNeatLine;
- private Color _neatLineColor;
- private float _neatLineSize;
- private boolean _drawScaleText;
- private float _yShiftScale = 2.0f;
- //
- //
-
- /**
- * Constructor
- *
- * @param mapPlot The map plot
- */
- public ChartScaleBar(MapPlot mapPlot) {
- super();
- //this.setElementType(ElementType.LayoutScaleBar);
- //this.setResizeAbility(ResizeAbility.ResizeAll);
-
- this.width = 200;
- this.height = 50;
- this.mapPlot = mapPlot;
- _antiAlias = true;
- _scaleBarType = ScaleBarType.SCALELINE_1;
- lineWidth = 1;
- _drawNeatLine = false;
- _neatLineColor = Color.black;
- _neatLineSize = 1;
- _font = new Font("Arial", Font.PLAIN, 12);
- _unit = ScaleBarUnits.KILOMETERS;
- _unitText = "km";
- _numBreaks = 4;
- _drawScaleText = false;
- }
- //
- //
-
- /**
- * Get map plot
- *
- * @return The map plot
- */
- public MapPlot getMapPlot() {
- return mapPlot;
- }
-
- /**
- * Get line widht
- * @return Line width
- */
- public float getLineWidth() {
- return this.lineWidth;
- }
-
- /**
- * Set line width
- * @param value Line width
- */
- public void setLineWidth(float value) {
- this.lineWidth = value;
- }
-
- /**
- * Get scale bar type
- *
- * @return Scale bar type
- */
- public ScaleBarType getScaleBarType() {
- return _scaleBarType;
- }
-
- /**
- * Set scale bar type
- *
- * @param type Scale bar type
- */
- public void setScaleBarType(ScaleBarType type) {
- _scaleBarType = type;
- }
-
- /**
- * Get if draw neat line
- *
- * @return If draw neat line
- */
- public boolean isDrawNeatLine() {
- return _drawNeatLine;
- }
-
- /**
- * Set if draw neat line
- *
- * @param istrue If draw neat line
- */
- public void setDrawNeatLine(boolean istrue) {
- _drawNeatLine = istrue;
- }
-
- /**
- * Get neat line color
- *
- * @return Neat line color
- */
- public Color getNeatLineColor() {
- return _neatLineColor;
- }
-
- /**
- * Set neat line color
- *
- * @param color Neat line color
- */
- public void setNeatLineColor(Color color) {
- _neatLineColor = color;
- }
-
- /**
- * Get neat line size
- *
- * @return Neat line size
- */
- public float getNeatLineSize() {
- return _neatLineSize;
- }
-
- /**
- * Set neat line size
- *
- * @param size Neat line size
- */
- public void setNeatLineSize(float size) {
- _neatLineSize = size;
- }
-
- /**
- * Get font
- *
- * @return The font
- */
- public Font getFont() {
- return _font;
- }
-
- /**
- * Set font
- *
- * @param font The font
- */
- public void setFont(Font font) {
- _font = font;
- }
-
- /**
- * Get break number
- *
- * @return The break number
- */
- public int getBreakNumber() {
- return _numBreaks;
- }
-
- /**
- * Set break number
- *
- * @param num Break number
- */
- public void setBreakNumber(int num) {
- _numBreaks = num;
- }
-
- /**
- * Get if draw scale text
- *
- * @return If draw scale text
- */
- public boolean isDrawScaleText() {
- return _drawScaleText;
- }
-
- /**
- * Set if draw scale text
- *
- * @param istrue If draw scale text
- */
- public void setDrawScaleText(boolean istrue) {
- _drawScaleText = istrue;
- }
- //
- //
- /**
- * Draw text
- *
- * @param g Graphics2D
- * @param x X
- * @param y Y
- */
- public void draw(Graphics2D g, float x, float y) {
- AffineTransform oldMatrix = g.getTransform();
- g.translate(x, y);
- if (_antiAlias) {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- } else {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
- }
-
- //Draw background color
- if (this.isDrawBackColor()){
- g.setColor(this.getBackground());
- g.fill(new Rectangle.Float(0, 0, this.getWidth(), this.getHeight()));
- }
-
- drawScaleBar(g);
-
- //Draw neatline
- if (_drawNeatLine) {
- Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
- (this.getWidth() - _neatLineSize), (this.getHeight() - _neatLineSize));
- g.setColor(_neatLineColor);
- g.setStroke(new BasicStroke(_neatLineSize));
- g.draw(mapRect);
- }
-
- g.setTransform(oldMatrix);
- }
-
- /**
- * Paint graphics
- *
- * @param g Graphics
- * @param pageLocation Page location
- * @param zoom Zoom
- */
- public void paintGraphics(Graphics2D g, PointF pageLocation) {
- AffineTransform oldMatrix = g.getTransform();
- PointF aP = pageToScreen(this.getX(), this.getY(), pageLocation, 1);
- g.translate(aP.X, aP.Y);
- if (_antiAlias) {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- } else {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
- }
-
- //Draw background color
- if (this.isDrawBackColor()){
- g.setColor(this.getBackground());
- g.fill(new Rectangle.Float(0, 0, this.getWidth(), this.getHeight()));
- }
-
- drawScaleBar(g);
-
- //Draw neatline
- if (_drawNeatLine) {
- Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
- (this.getWidth() - _neatLineSize), (this.getHeight() - _neatLineSize));
- g.setColor(_neatLineColor);
- g.setStroke(new BasicStroke(_neatLineSize));
- g.draw(mapRect);
- }
-
- g.setTransform(oldMatrix);
- }
-
- private void drawScaleBar(Graphics2D g) {
- //Calculates the width of one break in greographic units
- FontMetrics metrics = g.getFontMetrics(this._font);
- float unitLegnth = metrics.stringWidth(_unitText) * 2;
- float widthNoUnit = (this.getWidth() - unitLegnth);
- long geoBreakWidth = (long) (getGeoWidth(widthNoUnit / _numBreaks));
-
- //If the geobreakWidth is less than 1 we return and don't draw anything
- if (geoBreakWidth < 1) {
- return;
- }
-
- double n = Math.pow(10, String.valueOf(geoBreakWidth).length() - 1);
- geoBreakWidth = (long) (Math.floor(geoBreakWidth / n) * n);
-
- long breakWidth = (long) (getWidth(geoBreakWidth));
- FontMetrics metrics1 = g.getFontMetrics(_font);
- float fontHeight = metrics1.getHeight();
- float leftStart = metrics1.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
-
- //Draw scale text
- double scale = geoBreakWidth * getConversionFactor(_unit) * 100 / (breakWidth / 96 * 2.539999918);
- if (_drawScaleText) {
- g.setFont(this._font);
- g.setColor(this.getForeground());
- g.drawString("1 : " + String.format("{0:0,0}", scale),
- leftStart - (metrics.stringWidth(String.valueOf(Math.abs(0))) / 2), fontHeight * 2.5F);
- }
-
- //Draw scale bar
- switch (_scaleBarType) {
- case SCALELINE_1:
- drawScaleLine1(g, breakWidth, geoBreakWidth);
- break;
- case SCALELINE_2:
- drawScaleLine2(g, breakWidth, geoBreakWidth);
- break;
- case ALTERNATING_BAR:
- drawAlternatingBar(g, breakWidth, geoBreakWidth);
- break;
- }
- }
-
- private double getConversionFactor(ScaleBarUnits unit) {
- switch (unit) {
- case KILOMETERS:
- return 1000;
- default:
- return 1;
- }
- }
-
- private double getGeoWidth(double width) {
- double geoWidth = width / mapPlot.getMapFrame().getMapView().getXScale() / getConversionFactor(_unit);
- if (mapPlot.getMapFrame().getMapView().getProjection().isLonLatMap()) {
- geoWidth = geoWidth * getLonDistScale();
- }
-
- return geoWidth;
- }
-
- private double getWidth(double geoWidth) {
- double width = geoWidth * mapPlot.getMapFrame().getMapView().getXScale() * getConversionFactor(_unit);
- if (mapPlot.getMapFrame().getMapView().getProjection().isLonLatMap()) {
- width = width / getLonDistScale();
- }
-
- return width;
- }
-
- private double getLonDistScale() {
- //Get meters of one longitude degree
- double pY = (mapPlot.getMapFrame().getMapView().getViewExtent().maxY + mapPlot.getMapFrame().getMapView().getViewExtent().minY) / 2;
- double ProjX = 0, ProjY = pY, pProjX = 1, pProjY = pY;
- double dx = Math.abs(ProjX - pProjX);
- double dy = Math.abs(ProjY - pProjY);
- double dist;
- double y = (ProjY + pProjY) / 2;
- double factor = Math.cos(y * Math.PI / 180);
- dx *= factor;
- dist = Math.sqrt(dx * dx + dy * dy);
- dist = dist * 111319.5;
-
- return dist;
- }
-
- private void drawScaleLine1(Graphics2D g, long breakWidth, long geoBreakWidth) {
- FontMetrics metrics = g.getFontMetrics(_font);
- float fontHeight = metrics.getHeight();
- float leftStart = metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
- int yShift = 10;
-
- g.setColor(this.getForeground());
- g.setStroke(new BasicStroke(this.lineWidth));
- g.draw(new Line2D.Float(leftStart, fontHeight * 1.6f + yShift, leftStart + (breakWidth * _numBreaks), fontHeight * 1.6f + yShift));
- g.setFont(this._font);
- for (int i = 0; i <= _numBreaks; i++) {
- g.draw(new Line2D.Float(leftStart, fontHeight * 1.1f + yShift, leftStart, fontHeight * 1.6f + yShift));
- g.drawString(String.valueOf(Math.abs(geoBreakWidth * i)),
- leftStart - (metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth * i))) / 2), yShift * _yShiftScale);
- leftStart = leftStart + breakWidth;
- }
- g.drawString(_unitText, leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f + yShift * _yShiftScale);
- }
-
- private void drawScaleLine2(Graphics2D g, long breakWidth, long geoBreakWidth) {
- FontMetrics metrics = g.getFontMetrics(_font);
- float fontHeight = metrics.getHeight();
- float leftStart = metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
- int yShift = 5;
-
- g.setColor(this.getForeground());
- g.setStroke(new BasicStroke(this.lineWidth));
- g.draw(new Line2D.Float(leftStart, fontHeight * 1.6f + yShift, leftStart + (breakWidth * _numBreaks), fontHeight * 1.6f + yShift));
- g.setFont(this._font);
- for (int i = 0; i <= _numBreaks; i++) {
- g.draw(new Line2D.Float(leftStart, fontHeight * 1.1f + yShift, leftStart, fontHeight + (fontHeight * 1.1f) + yShift));
- g.drawString(String.valueOf(Math.abs(geoBreakWidth * i)),
- leftStart - (metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth * i))) / 2), yShift * _yShiftScale);
- leftStart = leftStart + breakWidth;
- }
- g.drawString(_unitText, leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f + yShift * _yShiftScale);
- }
-
- private void drawAlternatingBar(Graphics2D g, long breakWidth, long geoBreakWidth) {
- FontMetrics metrics = g.getFontMetrics(_font);
- float fontHeight = metrics.getHeight();
- float leftStart = metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
- int yShift = 5;
- float rHeight = fontHeight / 2;
-
- boolean isFill = false;
- g.setStroke(new BasicStroke(this.lineWidth));
- g.setColor(this.getForeground());
- g.setFont(this._font);
- for (int i = 0; i <= _numBreaks; i++) {
- if (i < _numBreaks) {
- if (isFill) {
- g.fill(new Rectangle.Float(leftStart, fontHeight * 1.1f + yShift, breakWidth, rHeight));
- }
- g.draw(new Rectangle.Float(leftStart, fontHeight * 1.1f + yShift, breakWidth, rHeight));
- }
- g.drawString(String.valueOf(Math.abs(geoBreakWidth * i)),
- leftStart - (metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth * i))) / 2), yShift * _yShiftScale);
- leftStart = leftStart + breakWidth;
- isFill = !isFill;
- }
- g.setColor(this.getForeground());
- g.drawString(_unitText, leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f + yShift * _yShiftScale);
- }
-
- @Override
- public void moveUpdate() {
- }
-
- @Override
- public void resizeUpdate() {
- }
- //
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartText.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartText.java
deleted file mode 100644
index 03151a78..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartText.java
+++ /dev/null
@@ -1,740 +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;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.awt.Stroke;
-import java.awt.geom.AffineTransform;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import org.meteoinfo.chart.plot.XAlign;
-import org.meteoinfo.chart.plot.YAlign;
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.chart.drawing.Draw;
-import org.locationtech.jts.geom.Geometry;
-import org.locationtech.jts.geom.GeometryFactory;
-import org.meteoinfo.geometry.shape.Shape;
-import org.meteoinfo.geometry.shape.ShapeTypes;
-
-/**
- *
- * @author yaqiang
- */
-public class ChartText extends Shape {
-
- //
- protected double x;
- protected double y;
- private Font font;
- private List text;
- private Color color;
- private int lineSpace;
- private CoordinateType coordinates;
- private Color background;
- private boolean drawBackground;
- private boolean drawNeatline;
- private Color neatLineColor;
- private float neatLineSize;
- private float gap;
- protected float angle;
- private XAlign xAlign;
- private YAlign yAlign;
- private boolean useExternalFont;
- protected double xShift;
- protected double yShift;
-
- //
- //
- /**
- * Constructor
- */
- public ChartText() {
- font = new Font("Arial", Font.PLAIN, 14);
- color = Color.black;
- lineSpace = 5;
- coordinates = CoordinateType.DATA;
- this.background = Color.white;
- this.drawBackground = false;
- this.drawNeatline = false;
- this.neatLineColor = Color.black;
- this.neatLineSize = 1.0f;
- this.gap = 3.0f;
- this.angle = 0.0f;
- this.xAlign = XAlign.LEFT;
- this.yAlign = YAlign.BOTTOM;
- this.useExternalFont = false;
- this.xShift = 0;
- this.yShift = 0;
- }
-
- /**
- * Constructor
- *
- * @param text Text
- */
- public ChartText(String text) {
- this();
- this.text = new ArrayList<>();
- String[] lines = text.split("\n");
- this.text.addAll(Arrays.asList(lines));
- }
-
- /**
- * Constructor
- *
- * @param text Text
- */
- public ChartText(List text) {
- this();
- this.text = text;
- }
-
- /**
- * Constructor
- *
- * @param text Text
- * @param font Font
- */
- public ChartText(String text, Font font) {
- this();
- this.text = new ArrayList<>();
- String[] lines = text.split("\n");
- this.text.addAll(Arrays.asList(lines));
- this.font = font;
- }
-
- /**
- * Constructor
- *
- * @param text Text
- * @param font Font
- */
- public ChartText(List text, Font font) {
- this();
- this.text = text;
- this.font = font;
- }
- //
- //
-
- /**
- * Get text
- *
- * @return Text
- */
- public String getText() {
- return text.get(0);
- }
-
- /**
- * Set text
- *
- * @param value Text
- */
- public void setText(String value) {
- text = new ArrayList<>();
- String[] lines = value.split("\n");
- this.text.addAll(Arrays.asList(lines));
- }
-
- /**
- * Get texts
- *
- * @return Text list
- */
- public List getTexts() {
- return text;
- }
-
- /**
- * Set texts
- *
- * @param value Text list
- */
- public void setTexts(List value) {
- text = value;
- }
-
- /**
- * Get font
- *
- * @return Font
- */
- public Font getFont() {
- return font;
- }
-
- /**
- * Set font
- *
- * @param value Font
- */
- public void setFont(Font value) {
- font = value;
- }
-
- /**
- * Get title color
- *
- * @return Title color
- */
- public Color getColor() {
- return color;
- }
-
- /**
- * Set title color
- *
- * @param value Title color
- */
- public void setColor(Color value) {
- this.color = value;
- }
-
- /**
- * Get x
- *
- * @return X
- */
- public double getX() {
- return this.x;
- }
-
- /**
- * Set x
- *
- * @param value X
- */
- public void setX(double value) {
- this.x = value;
- }
-
- /**
- * Get y
- *
- * @return Y
- */
- public double getY() {
- return this.y;
- }
-
- /**
- * Set y
- *
- * @param value Y
- */
- public void setY(double value) {
- this.y = value;
- }
-
- /**
- * Get line space
- *
- * @return Line space
- */
- public int getLineSpace() {
- return this.lineSpace;
- }
-
- /**
- * Set line space
- *
- * @param value Line space
- */
- public void setLineSpace(int value) {
- this.lineSpace = value;
- }
-
- /**
- * Get coordinates
- *
- * @return Coordinates
- */
- public CoordinateType getCoordinates() {
- return this.coordinates;
- }
-
- /**
- * Set coordinates
- *
- * @param value Coordinates
- */
- public void setCoordinates(CoordinateType value) {
- this.coordinates = value;
- }
-
- /**
- * Set coordinates
- *
- * @param value Coordinates
- */
- public void setCoordinates(String value) {
- switch (value) {
- case "axes":
- this.coordinates = CoordinateType.AXES;
- break;
- case "figure":
- this.coordinates = CoordinateType.FIGURE;
- break;
- case "data":
- this.coordinates = CoordinateType.DATA;
- break;
- case "inches":
- this.coordinates = CoordinateType.INCHES;
- break;
- }
- }
-
- /**
- * Get background color
- *
- * @return Background color
- */
- public Color getBackground() {
- return this.background;
- }
-
- /**
- * Set background color
- *
- * @param value Background color
- */
- public void setBackground(Color value) {
- this.background = value;
- }
-
- /**
- * Get if is fill background
- *
- * @return Boolean
- */
- public boolean isFill() {
- return this.drawBackground;
- }
-
- /**
- * Set fill background or not
- *
- * @param value Boolean
- */
- public void setFill(boolean value) {
- this.drawBackground = value;
- }
-
- /**
- * Get draw neatline or not
- *
- * @return Boolean
- */
- public boolean isDrawNeatline() {
- return this.drawNeatline;
- }
-
- /**
- * Set draw neatline or not
- *
- * @param value Boolean
- */
- public void setDrawNeatline(boolean value) {
- this.drawNeatline = value;
- }
-
- /**
- * Get neatline color
- *
- * @return Neatline color
- */
- public Color getNeatlineColor() {
- return this.neatLineColor;
- }
-
- /**
- * Set neatline color
- *
- * @param value Neatline color
- */
- public void setNeatlineColor(Color value) {
- this.neatLineColor = value;
- }
-
- /**
- * Get neatline size
- *
- * @return Neatline size
- */
- public float getNeatlineSize() {
- return this.neatLineSize;
- }
-
- /**
- * Set neatline size
- *
- * @param value Neatline size
- */
- public void setNeatlineSize(float value) {
- this.neatLineSize = value;
- }
-
- /**
- * Get gap
- *
- * @return Gap
- */
- public float getGap() {
- return this.gap;
- }
-
- /**
- * Set gap
- *
- * @param value Gap
- */
- public void setGap(float value) {
- this.gap = value;
- }
-
- /**
- * Get angle
- *
- * @return Angle
- */
- public float getAngle() {
- return this.angle;
- }
-
- /**
- * Set angle
- *
- * @param value Angle
- */
- public void setAngle(float value) {
- this.angle = value;
- }
-
- /**
- * Get x align
- *
- * @return X align
- */
- public XAlign getXAlign() {
- return this.xAlign;
- }
-
- /**
- * Set x align
- *
- * @param value X align
- */
- public void setXAlign(XAlign value) {
- this.xAlign = value;
- }
-
- /**
- * Set x align
- *
- * @param value X align string
- */
- public void setXAlign(String value) {
- this.xAlign = XAlign.valueOf(value.toUpperCase());
- }
-
- /**
- * Get y align
- *
- * @return Y align
- */
- public YAlign getYAlign() {
- return this.yAlign;
- }
-
- /**
- * Set y align
- *
- * @param value Y align
- */
- public void setYAlign(YAlign value) {
- this.yAlign = value;
- }
-
- /**
- * Set y align
- *
- * @param value Y align string
- */
- public void setYAlign(String value) {
- this.yAlign = YAlign.valueOf(value.toUpperCase());
- }
-
- /**
- * Get if use external font - only for LaTeX string
- *
- * @return Boolean
- */
- public boolean isUseExternalFont() {
- return this.useExternalFont;
- }
-
- /**
- * Set if use external font - only for LaTeX string
- *
- * @param value Boolean
- */
- public void setUseExternalFont(boolean value) {
- this.useExternalFont = value;
- }
-
- /**
- * Get x shift
- * @return X shift
- */
- public double getXShift() {
- return this.xShift;
- }
-
- /**
- * Set x shift
- * @param value X shift
- */
- public void setXShift(double value) {
- this.xShift = value;
- }
-
- /**
- * Get y shift
- * @return Y shift
- */
- public double getYShift() {
- return this.yShift;
- }
-
- /**
- * Set y shift
- * @param value Y shift
- */
- public void setYShift(double value) {
- this.yShift = value;
- }
-
- //
- //
- /**
- * Add text in new line
- *
- * @param value The text string
- */
- public void addText(String value) {
- this.text.add(value);
- }
-
- @Override
- public ShapeTypes getShapeType() {
- return ShapeTypes.TEXT;
- }
-
- /**
- * Get text line number
- *
- * @return Text line number
- */
- public int getLineNum() {
- return this.text.size();
- }
-
- /**
- * Get text dimension with angle
- *
- * @param g Graphics2D
- * @return Dimension
- */
- public Dimension getTrueDimension(Graphics2D g) {
- Dimension dim = getDimension(g);
- if (this.angle != 0) {
- int width = dim.width;
- int height = dim.height;
- int temp;
- if (angle == 90 || angle == -90) {
- temp = width;
- width = height;
- height = temp;
- } else {
- width = (int) ((width * Math.cos(Math.toRadians(angle))) + (height * Math.sin(Math.toRadians(angle))));
- height = (int) ((width * Math.sin(Math.toRadians(angle))) + (height * Math.cos(Math.toRadians(angle))));
- }
- return new Dimension(width, height);
- } else {
- return dim;
- }
- }
-
- /**
- * Get text dimension
- *
- * @param g Graphics2D
- * @return Dimension
- */
- public Dimension getDimension(Graphics2D g) {
- g.setFont(font);
- int width = 0, height = 0;
- for (String line : this.text) {
- Dimension dim = Draw.getStringDimension(line, g);
- if (width < dim.width) {
- width = dim.width;
- }
- height += dim.height + this.lineSpace;
- }
- height -= this.lineSpace;
-
- return new Dimension(width, height);
- }
-
- /**
- * To geometry method
- *
- * @param factory GeometryFactory
- * @return Geometry
- */
- @Override
- public Geometry toGeometry(GeometryFactory factory) {
- return null;
- }
-
- /**
- * Set point
- *
- * @param x X
- * @param y Y
- */
- public void setPoint(double x, double y) {
- this.x = x;
- this.y = y;
- Extent aExtent = new Extent();
- aExtent.minX = x;
- aExtent.maxX = x;
- aExtent.minY = y;
- aExtent.maxY = y;
- this.setExtent(aExtent);
- }
-
- /**
- * To string
- *
- * @return String
- */
- @Override
- public String toString() {
- if (this.text.size() == 1) {
- return this.text.get(0);
- } else {
- String r = "";
- for (int i = 0; i < this.text.size(); i++) {
- if (i == 0) {
- r = this.text.get(i);
- } else {
- r = r + "\n" + this.text.get(i);
- }
- }
- return r;
- }
- }
-
- /**
- * Draw text
- *
- * @param g Graphics2D
- * @param x X
- * @param y Y
- */
- public void draw(Graphics2D g, float x, float y) {
- Dimension dim = this.getDimension(g);
- x += this.xShift;
- y += this.yShift;
-
- AffineTransform tempTrans = g.getTransform();
- if (this.angle != 0) {
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- myTrans.translate(x, y);
- //myTrans.translate(tempTrans.getTranslateX() + x, tempTrans.getTranslateY() + y);
- myTrans.rotate(-angle * Math.PI / 180);
- g.setTransform(myTrans);
- x = 0;
- y = 0;
- }
-
- Rectangle.Double rect = new Rectangle.Double(x, y - dim.getHeight(), dim.getWidth(), dim.getHeight());
- rect.setRect(rect.x - gap, rect.y - gap, rect.width + gap * 2,
- rect.height + gap * 2);
- if (this.drawBackground) {
- g.setColor(this.background);
- g.fill(rect);
- }
- if (this.drawNeatline) {
- g.setColor(this.neatLineColor);
- Stroke oldStroke = g.getStroke();
- g.setStroke(new BasicStroke(neatLineSize));
- g.draw(rect);
- g.setStroke(oldStroke);
- }
-
- g.setColor(this.color);
- g.setFont(font);
- switch (this.yAlign) {
- case BOTTOM:
- y = y - dim.height;
- break;
- case CENTER:
- y = y - dim.height * 0.5f;
- break;
- }
-
- for (String str : this.text) {
- dim = Draw.getStringDimension(str, g);
- Draw.drawString(g, x, y, str, xAlign, YAlign.TOP, useExternalFont);
- y += dim.height;
- y += this.lineSpace;
- }
-
- if (this.angle != 0) {
- g.setTransform(tempTrans);
- }
- }
-
- /**
- * Clone
- *
- * @return Cloned object
- */
- @Override
- public Object clone() {
- ChartText ct = new ChartText();
- ct.angle = this.angle;
- ct.background = this.background;
- ct.color = this.color;
- ct.coordinates = this.coordinates;
- ct.drawBackground = this.drawBackground;
- ct.drawNeatline = this.drawNeatline;
- ct.font = this.font;
- ct.gap = this.gap;
- ct.lineSpace = this.lineSpace;
- ct.neatLineColor = this.neatLineColor;
- ct.neatLineSize = this.neatLineSize;
- ct.text = this.text;
- ct.useExternalFont = this.useExternalFont;
- ct.x = this.x;
- ct.xAlign = this.xAlign;
- ct.y = this.y;
- ct.yAlign = this.yAlign;
-
- return ct;
- }
- //
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartText3D.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartText3D.java
deleted file mode 100644
index 9f1bdd42..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartText3D.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/* This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.chart;
-
-import java.awt.Point;
-import org.meteoinfo.chart.plot3d.Projector;
-import org.meteoinfo.common.Extent3D;
-import org.meteoinfo.data.DataMath;
-import org.meteoinfo.shape.PointZ;
-
-/**
- *
- * @author Yaqiang Wang
- * yaqiang.wang@gmail.com
- */
-public class ChartText3D extends ChartText {
- private double z;
- private PointZ zdir = null;
-
- /**
- * Get z coordinate value
- * @return Z coordinate value
- */
- public double getZ(){
- return this.z;
- }
-
- /**
- * Set z coordinate value
- * @param value Z coordinate value
- */
- public void setZ(double value){
- this.z = value;
- }
-
- /**
- * Get zdir point
- * @return ZDir point
- */
- public PointZ getZDir(){
- return zdir;
- }
-
- /**
- * Set zdir point
- * @param value ZDir point
- */
- public void setZDir(PointZ value){
- this.zdir = value;
- }
-
- /**
- * Set zdir point
- * @param x X coordinate value
- * @param y Y coordinate value
- * @param z Z coordinate value
- */
- public void setZDir(float x, float y, float z){
- if (x == 0 && y == 0 && z == 0)
- this.zdir = null;
- else
- this.zdir = new PointZ(x, y, z);
- }
-
- /**
- * Set zdir point
- * @param value ZDir point
- */
- public void setZDir(String value){
- float x1 = 0, y1 = 0, z1 = 0;
- switch(value.toLowerCase()){
- case "x":
- x1 = 1;
- break;
- case "y":
- y1 = 1;
- break;
- case "z":
- z1 = 1;
- break;
- }
- this.setZDir(x1, y1, z1);
- }
-
- /**
- * Set point
- *
- * @param x X
- * @param y Y
- * @param z Z
- */
- public void setPoint(double x, double y, double z) {
- this.x = x;
- this.y = y;
- this.z = z;
- Extent3D aExtent = new Extent3D();
- aExtent.minX = x;
- aExtent.maxX = x;
- aExtent.minY = y;
- aExtent.maxY = y;
- aExtent.minZ = z;
- aExtent.maxZ = z;
- this.setExtent(aExtent);
- }
-
- /**
- * Update angle
- * @param projector Projector
- */
- public void updateAngle(Projector projector){
- if (this.zdir == null)
- return;
-
- Point p0 = projector.project(0, 0, 0);
- Point p1 = projector.project((float)this.zdir.X, (float)this.zdir.Y, (float)this.zdir.Z);
- double[] value = DataMath.getDSFromUV(p1.x - p0.x, p1.y - p0.y);
- this.angle = (float)value[0];
- }
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartWindArrow.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartWindArrow.java
deleted file mode 100644
index bb279fcc..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/ChartWindArrow.java
+++ /dev/null
@@ -1,391 +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;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.geom.Rectangle2D;
-
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.drawing.Draw;
-import org.meteoinfo.global.DataConvert;
-import org.meteoinfo.layer.VectorLayer;
-import org.meteoinfo.legend.ArrowBreak;
-import org.meteoinfo.shape.GraphicCollection;
-import org.meteoinfo.shape.WindArrow;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class ChartWindArrow {
-
- //
- private final WindArrow windArrow;
- private ArrowBreak arrowBreak;
- private Font font;
- //private Color color;
- private Color labelColor;
- private float x;
- private float y;
- private String label;
- private int labelSep;
- private Object layer;
- private Color background;
- private boolean drawBackground;
- private boolean drawNeatline;
- private Color neatLineColor;
- private float neatLineSize;
-
- //
- //
- /**
- * Constructor
- */
- public ChartWindArrow() {
- this.windArrow = new WindArrow();
- this.windArrow.angle = 270;
- this.windArrow.length = 20;
- this.arrowBreak = new ArrowBreak();
- this.font = new Font("Arial", Font.PLAIN, 12);
- //this.color = Color.black;
- this.labelColor = Color.black;
- this.labelSep = 5;
- this.background = Color.white;
- this.drawBackground = false;
- this.drawNeatline = false;
- this.neatLineColor = Color.black;
- this.neatLineSize = 1.0f;
- }
-
- //
- //
- /**
- * Get wind arrow
- *
- * @return Wind arrow
- */
- public WindArrow getWindArrow() {
- return this.windArrow;
- }
-
- /**
- * Get arrow break
- * @return Arrow break
- */
- public ArrowBreak getArrowBreak() {
- return this.arrowBreak;
- }
-
- /**
- * Set arrow break
- * @param value Arrow break
- */
- public void setArrowBreak(ArrowBreak value) {
- this.arrowBreak = value;
- }
-
- /**
- * Get length
- *
- * @return Length
- */
- public float getLength() {
- return this.windArrow.length;
- }
-
- /**
- * Set length
- *
- * @param value Length
- */
- public void setLength(float value) {
- this.windArrow.length = value;
- this.label = String.valueOf(value);
- this.label = DataConvert.removeTailingZeros(this.label);
- }
-
- /**
- * Get angle
- *
- * @return Angle
- */
- public double getAngle() {
- return this.windArrow.angle;
- }
-
- /**
- * Set angle
- *
- * @param value Angle
- */
- public void setAngle(double value) {
- this.windArrow.angle = value;
- }
-
- /**
- * Get layer
- *
- * @return Layer
- */
- public Object getLayer() {
- return this.layer;
- }
-
- /**
- * Set layer
- *
- * @param value Layer
- */
- public void setLayer(Object value) {
- this.layer = value;
- }
-
- /**
- * Get font
- *
- * @return Font
- */
- public Font getFont() {
- return font;
- }
-
- /**
- * Set font
- *
- * @param value Font
- */
- public void setFont(Font value) {
- font = value;
- }
-
- /**
- * Get label color
- *
- * @return Label color
- */
- public Color getLabelColor() {
- return this.labelColor;
- }
-
- /**
- * Set label color
- *
- * @param value Label color
- */
- public void setLabelColor(Color value) {
- this.labelColor = value;
- }
-
- /**
- * Get the distance between arrow and label
- * @return Distance between arrow and label
- */
- public int getLabelSep(){
- return this.labelSep;
- }
-
- /**
- * Set the distance between arrow and label
- * @param value Distance between arrow and label
- */
- public void setLabelSep(int value) {
- this.labelSep = value;
- }
-
- /**
- * Get x
- *
- * @return X
- */
- public float getX() {
- return this.x;
- }
-
- /**
- * Set x
- *
- * @param value X
- */
- public void setX(float value) {
- this.x = value;
- }
-
- /**
- * Get y
- *
- * @return Y
- */
- public float getY() {
- return this.y;
- }
-
- /**
- * Set y
- *
- * @param value Y
- */
- public void setY(float value) {
- this.y = value;
- }
-
- /**
- * Get label
- *
- * @return Label
- */
- public String getLabel() {
- return this.label;
- }
-
- /**
- * Set label
- *
- * @param value Label
- */
- public void setLabel(String value) {
- this.label = value;
- }
-
- /**
- * Get background color
- *
- * @return Background color
- */
- public Color getBackground() {
- return this.background;
- }
-
- /**
- * Set background color
- *
- * @param value Background color
- */
- public void setBackground(Color value) {
- this.background = value;
- }
-
- /**
- * Get if is fill background
- *
- * @return Boolean
- */
- public boolean isFill() {
- return this.drawBackground;
- }
-
- /**
- * Set fill background or not
- *
- * @param value Boolean
- */
- public void setFill(boolean value) {
- this.drawBackground = value;
- }
-
- /**
- * Get draw neatline or not
- *
- * @return Boolean
- */
- public boolean isDrawNeatline() {
- return this.drawNeatline;
- }
-
- /**
- * Set draw neatline or not
- *
- * @param value Boolean
- */
- public void setDrawNeatline(boolean value) {
- this.drawNeatline = value;
- }
-
- /**
- * Get neatline color
- *
- * @return Neatline color
- */
- public Color getNeatlineColor() {
- return this.neatLineColor;
- }
-
- /**
- * Set neatline color
- *
- * @param value Neatline color
- */
- public void setNeatlineColor(Color value) {
- this.neatLineColor = value;
- }
-
- /**
- * Get neatline size
- *
- * @return Neatline size
- */
- public float getNeatlineSize() {
- return this.neatLineSize;
- }
-
- /**
- * Set neatline size
- *
- * @param value Neatline size
- */
- public void setNeatlineSize(float value) {
- this.neatLineSize = value;
- }
-
- //
- //
- /**
- * Draw text
- *
- * @param g Graphics2D
- * @param x X
- * @param y Y
- */
- public void draw(Graphics2D g, float x, float y) {
- Object rendering = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- float zoom = 1.0f;
- if (this.layer != null) {
- if (this.layer instanceof VectorLayer) {
- zoom = ((VectorLayer) this.layer).getDrawingZoom();
- } else if (this.layer instanceof GraphicCollection) {
- zoom = ((GraphicCollection) this.layer).getArrowZoom();
- }
- }
- g.setFont(this.font);
- //String drawStr = this.label wa.getLabel();
- Dimension dim = Draw.getStringDimension(this.label, g);
- if (this.drawBackground || this.drawNeatline) {
- Rectangle2D rect = Draw.getArrawBorder(new PointF(x, y), this.windArrow, g, zoom);
- double gap = 5;
- double width = Math.max(rect.getWidth(), dim.getWidth());
- rect.setRect(rect.getX() - gap, rect.getY() - gap - 2, width + gap * 2,
- rect.getHeight() + dim.height + this.labelSep + gap + 2);
- if (this.drawBackground) {
- g.setColor(this.background);
- g.fill(rect);
- }
- if (this.drawNeatline) {
- g.setColor(this.neatLineColor);
- g.draw(rect);
- }
- }
- //Draw.drawArraw(this.color, new PointF(x, y), this.windArrow, g, zoom);
- Draw.drawArraw(new PointF(x, y), windArrow, arrowBreak, g, zoom);
- g.setColor(this.labelColor);
- Draw.drawString(g, this.label, x, y + dim.height + this.labelSep);
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, rendering);
- }
- //
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/CoordinateType.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/CoordinateType.java
deleted file mode 100644
index 99ee5c46..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/CoordinateType.java
+++ /dev/null
@@ -1,17 +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;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public enum CoordinateType {
- AXES,
- FIGURE,
- DATA,
- INCHES
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/IChartPanel.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/IChartPanel.java
deleted file mode 100644
index 5e786ab0..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/IChartPanel.java
+++ /dev/null
@@ -1,34 +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;
-
-/**
- *
- * @author yaqiang
- */
-public interface IChartPanel {
- /**
- * Save image
- * @param fn Image file name
- */
- public abstract void saveImage(String fn);
-
- /**
- * Set mouse mode
- * @param value Mouse mode
- */
- public abstract void setMouseMode(MouseMode value);
-
- /**
- * Zoom back to full extent
- */
- public abstract void onUndoZoomClick();
-
- /**
- * Paint graphics
- */
- public abstract void paintGraphics();
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/IPointSelectedListener.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/IPointSelectedListener.java
deleted file mode 100644
index b4bd5c4a..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/IPointSelectedListener.java
+++ /dev/null
@@ -1,24 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.chart;
-
-import java.util.EventListener;
-
- /**
- *
- * @author yaqiang
- */
- public interface IPointSelectedListener extends EventListener {
- public void pointSelectedEvent(PointSelectedEvent event);
- }
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/LegendPosition.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/LegendPosition.java
deleted file mode 100644
index 8257f958..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/LegendPosition.java
+++ /dev/null
@@ -1,99 +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;
-
-/**
- *
- * @author yaqiang
- */
-public enum LegendPosition {
- UPPER_RIGHT,
- UPPER_LEFT,
- UPPER_CENTER,
- LOWER_LEFT,
- LOWER_RIGHT,
- LOWER_CENTER,
- RIGHT,
- CENTER_LEFT,
- CENTER_RIGHT,
- CENTER,
- LEFT,
- UPPER_RIGHT_OUTSIDE,
- UPPER_LEFT_OUTSIDE,
- UPPER_CENTER_OUTSIDE,
- LOWER_LEFT_OUTSIDE,
- LOWER_RIGHT_OUTSIDE,
- LOWER_CENTER_OUTSIDE,
- LEFT_OUTSIDE,
- RIGHT_OUTSIDE,
- CUSTOM;
-
- /**
- * If the position is custom
- * @return Boolean
- */
- public boolean isCustom(){
- switch (this){
- case CUSTOM:
- return true;
- default:
- return false;
- }
- }
-
- /**
- * Get LegendPostion from string
- * @param loc Location string
- * @return LegenPosition
- */
- public static LegendPosition fromString(String loc){
- LegendPosition lp = LegendPosition.UPPER_RIGHT;
- loc = loc.toLowerCase();
- switch (loc){
- case "upper left":
- lp = LegendPosition.UPPER_LEFT;
- break;
- case "upper right":
- lp = LegendPosition.UPPER_RIGHT;
- break;
- case "upper center":
- lp = LegendPosition.UPPER_CENTER;
- break;
- case "upper center outside":
- lp = LegendPosition.UPPER_CENTER_OUTSIDE;
- break;
- case "lower left":
- lp = LegendPosition.LOWER_LEFT;
- break;
- case "lower right":
- lp = LegendPosition.LOWER_RIGHT;
- break;
- case "lower center":
- lp = LegendPosition.LOWER_CENTER;
- break;
- case "lower center outside":
- lp = LegendPosition.LOWER_CENTER_OUTSIDE;
- break;
- case "left":
- lp = LegendPosition.LEFT;
- break;
- case "left outside":
- lp = LegendPosition.LEFT_OUTSIDE;
- break;
- case "right":
- lp = LegendPosition.RIGHT;
- break;
- case "right outside":
- lp = LegendPosition.RIGHT_OUTSIDE;
- break;
- case "custom":
- lp = LegendPosition.CUSTOM;
- break;
- }
-
- return lp;
- }
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/Location.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/Location.java
deleted file mode 100644
index 5187ee5f..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/Location.java
+++ /dev/null
@@ -1,17 +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;
-
-/**
- *
- * @author yaqiang
- */
-public enum Location {
- LEFT,
- RIGHT,
- TOP,
- BOTTOM
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/Margin.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/Margin.java
deleted file mode 100644
index ab51f796..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/Margin.java
+++ /dev/null
@@ -1,138 +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;
-
-import java.awt.geom.Rectangle2D;
-
-/**
- *
- * @author wyq
- */
-public class Margin {
- //
- private double left;
- private double right;
- private double top;
- private double bottom;
- //
- //
- /**
- * Constructor
- */
- public Margin(){
-
- }
-
- /**
- * Constructor
- * @param left Left
- * @param right Right
- * @param top Top
- * @param bottom Bottom
- */
- public Margin(double left, double right, double top, double bottom){
- this.left = left;
- this.right = right;
- this.top = top;
- this.bottom = bottom;
- }
- //
- //
- /**
- * Get left
- * @return Left
- */
- public double getLeft(){
- return this.left;
- }
-
- /**
- * Set left
- * @param value Left
- */
- public void setLeft(double value){
- this.left = value;
- }
-
- /**
- * Get right
- * @return Right
- */
- public double getRight(){
- return this.right;
- }
-
- /**
- * Set right
- * @param value Right
- */
- public void setRight(double value){
- this.right = value;
- }
-
- /**
- * Get top
- * @return Top
- */
- public double getTop(){
- return this.top;
- }
-
- /**
- * Set top
- * @param value Top
- */
- public void setTop(double value){
- this.top = value;
- }
-
- /**
- * Get bottom
- * @return Bottom
- */
- public double getBottom(){
- return this.bottom;
- }
-
- /**
- * Set bottom
- * @param value Bottom
- */
- public void setBottom(double value){
- this.bottom = value;
- }
- //
- //
- /**
- * Get margin area
- * @param inArea Inside area
- * @return Margin area
- */
- public Rectangle2D getArea(Rectangle2D inArea){
- double x = inArea.getX() - this.left;
- double y = inArea.getY() - this.top;
- double w = inArea.getWidth() + this.left + this.right;
- double h = inArea.getHeight() + this.top + this.bottom;
-
- return new Rectangle2D.Double(x, y, w, h);
- }
-
- /**
- * Extent
- * @param a Margin
- * @return Extented margin
- */
- public Margin extend(Margin a){
- Margin r = new Margin();
- r.setLeft(Math.max(this.left, a.left));
- r.setRight(Math.max(this.right, a.right));
- r.setTop(Math.max(this.top, a.top));
- r.setBottom(Math.max(this.bottom, a.bottom));
-
- return r;
- }
- //
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/MouseMode.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/MouseMode.java
deleted file mode 100644
index baf59dbd..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/MouseMode.java
+++ /dev/null
@@ -1,20 +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;
-
-/**
- *
- * @author yaqiang
- */
-public enum MouseMode {
- DEFAULT,
- ZOOM_IN,
- ZOOM_OUT,
- SELECT,
- PAN,
- IDENTIFER,
- ROTATE
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/NorthArrowType.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/NorthArrowType.java
deleted file mode 100644
index 7eaf5236..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/NorthArrowType.java
+++ /dev/null
@@ -1,30 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.chart;
-
-/**
- * North arrow types
- *
- * @author Yaqiang Wang
- */
-public enum NorthArrowType {
- ///
- /// North arrow 1
- ///
- NORTHARROW_1,
- ///
- /// North arrow 2
- ///
- NORTHARROW_2,
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/PointSelectedEvent.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/PointSelectedEvent.java
deleted file mode 100644
index 38628745..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/PointSelectedEvent.java
+++ /dev/null
@@ -1,31 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.chart;
-
-import java.util.EventObject;
-
- /**
- * Size changed event
- *
- * @author Yaqiang Wang
- */
- public class PointSelectedEvent extends EventObject {
- /**
- * Constructor
- * @param source Source object
- */
- public PointSelectedEvent(Object source){
- super(source);
- }
- }
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 62f1fc0e..bd90c3bb 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
@@ -8,13 +8,13 @@ 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.XAlign;
-import org.meteoinfo.chart.plot.YAlign;
+import org.meteoinfo.common.DataConvert;
import org.meteoinfo.common.MIMath;
+import org.meteoinfo.common.XAlign;
+import org.meteoinfo.common.YAlign;
import org.meteoinfo.common.util.JDateUtil;
-import org.meteoinfo.drawing.Draw;
-import org.meteoinfo.global.DataConvert;
-import org.meteoinfo.legend.LineStyles;
+import org.meteoinfo.geo.drawing.Draw;
+import org.meteoinfo.geometry.legend.LineStyles;
import org.meteoinfo.ndarray.util.BigDecimalUtil;
import java.awt.*;
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/LogAxis.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/LogAxis.java
index de9d11a4..8ce84053 100644
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/LogAxis.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/LogAxis.java
@@ -6,8 +6,8 @@
package org.meteoinfo.chart.axis;
import org.meteoinfo.chart.ChartText;
+import org.meteoinfo.common.DataConvert;
import org.meteoinfo.common.MIMath;
-import org.meteoinfo.global.DataConvert;
import java.util.ArrayList;
import java.util.List;
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 d1638eb5..e74f6160 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
@@ -6,11 +6,11 @@
package org.meteoinfo.chart.axis;
import org.meteoinfo.chart.ChartText;
+import org.meteoinfo.common.DataConvert;
import org.meteoinfo.common.MIMath;
-import org.meteoinfo.global.DataConvert;
import org.meteoinfo.projection.KnownCoordinateSystems;
+import org.meteoinfo.projection.ProjectionInfo;
import org.meteoinfo.projection.Reproject;
-import org.meteoinfo.projection.info.ProjectionInfo;
import java.util.ArrayList;
import java.util.List;
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/drawing/Draw.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/drawing/Draw.java
deleted file mode 100644
index c41f25b6..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/drawing/Draw.java
+++ /dev/null
@@ -1,4587 +0,0 @@
-/* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.chart.drawing;
-
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.common.MIMath;
-import org.meteoinfo.common.PointD;
-import org.meteoinfo.common.PointF;
-import org.meteoinfo.chart.legend.MarkerType;
-import org.meteoinfo.chart.legend.PointStyle;
-import org.meteoinfo.geometry.geoprocess.Spline;
-import org.meteoinfo.common.colors.ColorUtil;
-import org.meteoinfo.chart.legend.BreakTypes;
-import org.meteoinfo.chart.legend.ChartBreak;
-import org.meteoinfo.chart.legend.LabelBreak;
-import org.meteoinfo.chart.legend.LineStyles;
-import org.meteoinfo.chart.legend.PointBreak;
-import org.meteoinfo.chart.legend.PolygonBreak;
-import org.meteoinfo.chart.legend.PolylineBreak;
-import org.meteoinfo.chart.graphic.Graphic;
-import org.meteoinfo.geometry.shape.Polyline;
-import org.meteoinfo.geometry.shape.WindArrow;
-import org.meteoinfo.geometry.shape.WindBarb;
-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.Image;
-import java.awt.Insets;
-import java.awt.Rectangle;
-import java.awt.RenderingHints;
-import java.awt.TexturePaint;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Arc2D;
-import java.awt.geom.Area;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Line2D;
-import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
-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;
-import javax.imageio.ImageIO;
-import org.meteoinfo.chart.plot.XAlign;
-import org.meteoinfo.chart.plot.YAlign;
-import org.meteoinfo.chart.legend.ArrowBreak;
-import org.meteoinfo.chart.legend.ArrowLineBreak;
-import org.meteoinfo.chart.legend.ColorBreakCollection;
-import org.meteoinfo.chart.legend.HatchStyle;
-import org.meteoinfo.chart.legend.StreamlineBreak;
-import org.meteoinfo.geometry.shape.EllipseShape;
-import org.meteoinfo.geometry.shape.Polygon;
-import org.meteoinfo.geometry.shape.PolygonShape;
-import org.meteoinfo.geometry.shape.StationModelShape;
-import org.scilab.forge.jlatexmath.TeXConstants;
-import org.scilab.forge.jlatexmath.TeXFormula;
-import org.scilab.forge.jlatexmath.TeXIcon;
-
-/**
- * Draw class with some drawing methods
- *
- * @author Yaqiang Wang
- */
-public class Draw {
-
- //
-// /**
-// * Determine if the string is a LaTeX string
-// *
-// * @param str String
-// * @return Boolean
-// */
-// public static boolean isLaTeX(String str) {
-// if (str.length() < 2) {
-// return false;
-// }
-//
-// String str1 = str.substring(0, 1);
-// String str2 = str.substring(str.length() - 1);
-// return str1.equals("$") && str2.equals("$");
-// }
- /**
- * Get string type [NORMAL | LATEX | MIXING].
- *
- * @param str The string
- * @return String type
- */
- public static StringType getStringType(String str) {
- if (str.length() < 2 || !str.contains("$")) {
- return StringType.NORMAL;
- }
-
- if (str.contains("$")) {
- int n = str.length() - str.replace("$", "").length();
- int n1 = str.length() - str.replace("\\$", "").length();
- int n2 = n - n1;
- if (n2 < 2) {
- return StringType.NORMAL;
- } else if (n2 == 2) {
- if (str.startsWith("$") && str.endsWith("$") && !str.endsWith("\\$")) {
- return StringType.LATEX;
- } else {
- return StringType.MIXING;
- }
- } else {
- return StringType.MIXING;
- }
- } else {
- return StringType.NORMAL;
- }
- }
-
- /**
- * Split mixing string by $
- *
- * @param str The mixing string
- * @return String list
- */
- public static List splitMixingString(String str) {
- List strs = new ArrayList<>();
- StringBuilder sb = new StringBuilder();
- for (char c : str.toCharArray()) {
- if (c == '$') {
- if (sb.length() == 0) {
- sb.append(c);
- } else {
- if (sb.substring(sb.length() - 1).equals("\\")) {
- sb.append(c);
- } else {
- if (sb.substring(0, 1).equals("$")) {
- sb.append(c);
- strs.add(sb.toString());
- sb = new StringBuilder();
- } else {
- strs.add(sb.toString());
- sb = new StringBuilder();
- sb.append(c);
- }
- }
- }
- } else {
- sb.append(c);
- }
- }
- if (sb.length() > 0) {
- strs.add(sb.toString());
- }
-
- return strs;
- }
-
- /**
- * Get string dimension
- *
- * @param str String
- * @param g Graphics2D
- * @param isLaTeX Is LaTeX or not
- * @return String dimension
- */
- public static Dimension getStringDimension(String str, Graphics2D g, boolean isLaTeX) {
- if (isLaTeX) {
- float size = g.getFont().getSize2D();
- // create a formula
- TeXFormula formula = new TeXFormula(str);
-
- // render the formla to an icon of the same size as the formula.
- TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_TEXT, size);
-
- // insert a border
- //icon.setInsets(new Insets(5, 5, 5, 5));
- //return new Dimension(icon.getIconWidth(), icon.getIconHeight());
- int width = (int) icon.getTrueIconWidth() + 10;
- int height = (int) icon.getTrueIconHeight();
- //int height = icon.getIconHeight();
- return new Dimension(width, height);
- } else {
- FontMetrics metrics = g.getFontMetrics();
- //int height = (int) (metrics.getAscent() * 5.f / 6.f);
- int height = metrics.getAscent();
- //return new Dimension(metrics.stringWidth(str), metrics.getHeight());
- return new Dimension(metrics.stringWidth(str), height);
- }
- }
-
- /**
- * Get string dimension
- *
- * @param str String
- * @param angle Angle
- * @param g Graphics2D
- * @param isLaTeX Is LaTeX or not
- * @return String dimension
- */
- public static Dimension getStringDimension(String str, float angle, Graphics2D g, boolean isLaTeX) {
- float width, height;
- if (isLaTeX) {
- float size = g.getFont().getSize2D();
- // create a formula
- TeXFormula formula = new TeXFormula(str);
-
- // render the formla to an icon of the same size as the formula.
- TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_TEXT, size);
-
- // insert a border
- //icon.setInsets(new Insets(5, 5, 5, 5));
- //return new Dimension(icon.getIconWidth(), icon.getIconHeight());
- width = (int) icon.getTrueIconWidth() + 10;
- height = (int) icon.getTrueIconHeight();
- //height = icon.getIconHeight();
- } else {
- FontMetrics metrics = g.getFontMetrics();
- width = metrics.stringWidth(str);
- height = metrics.getAscent();
- }
- float temp;
- if (angle == 90 || angle == -90) {
- temp = width;
- width = height;
- height = temp;
- } else {
- width = (float) (width * Math.cos(Math.toRadians(angle))) + (float) (height * Math.sin(Math.toRadians(angle)));
- height = (float) (width * Math.sin(Math.toRadians(angle))) + (float) (height * Math.cos(Math.toRadians(angle)));
- }
- return new Dimension((int) width, (int) height);
- }
-
- /**
- * Get string dimension
- *
- * @param str String
- * @param g Graphics2D
- * @return String dimension
- */
- public static Dimension getStringDimension(String str, Graphics2D g) {
- AffineTransform at = g.getTransform();
- if (at.getShearX() != 0 || at.getShearY() != 0) {
- g.setTransform(new AffineTransform());
- }
- Dimension dim;
- switch (getStringType(str)) {
- case LATEX:
- dim = getStringDimension(str, g, true);
- break;
- case MIXING:
- List strs = splitMixingString(str);
- dim = new Dimension(0, 0);
- for (String s : strs) {
- Dimension dim1 = getStringDimension(s, g, s.startsWith("$") && s.endsWith("$"));
- dim.setSize(dim.getWidth() + dim1.getWidth(), Math.max(dim.getHeight(), dim1.getHeight()));
- }
- break;
- default:
- dim = getStringDimension(str, g, false);
- break;
- }
- if (at.getShearX() != 0 || at.getShearY() != 0) {
- g.setTransform(at);
- }
- return dim;
- }
-
- /**
- * Get string dimension
- *
- * @param str String
- * @param angle Angle
- * @param g Graphics2D
- * @return String dimension
- */
- public static Dimension getStringDimension(String str, float angle, Graphics2D g) {
- if (angle == 0) {
- return getStringDimension(str, g);
- } else {
- switch (getStringType(str)) {
- case LATEX:
- return getStringDimension(str, angle, g, true);
- case MIXING:
- List strs = splitMixingString(str);
- Dimension dim = new Dimension(0, 0);
- for (String s : strs) {
- Dimension dim1 = getStringDimension(s, angle, g, s.startsWith("$") && s.endsWith("$"));
- dim.setSize(dim.getWidth() + dim1.getWidth(), Math.max(dim.getHeight(), dim1.getHeight()));
- }
- return dim;
- default:
- return getStringDimension(str, angle, g, false);
- }
- }
- }
-
- /**
- * Draw string
- *
- * @param g Graphics2D
- * @param str String
- * @param x X
- * @param y Y
- */
- public static void drawString(Graphics2D g, String str, float x, float y) {
- drawString(g, str, x, y, true);
- }
-
- /**
- * Draw string
- *
- * @param g Graphics2D
- * @param str String
- * @param x X
- * @param y Y
- */
- public static void drawString(Graphics2D g, String str, double x, double y) {
- drawString(g, str, x, y, true);
- }
-
- /**
- * Draw string
- *
- * @param g Graphics2D
- * @param str String
- * @param x X
- * @param y Y
- * @param useExternalFont If use external font
- */
- public static void drawString(Graphics2D g, String str, float x, float y, boolean useExternalFont) {
- switch (getStringType(str)) {
- case LATEX:
- drawLaTeX(g, str, x, y, useExternalFont);
- break;
- case MIXING:
- List strs = splitMixingString(str);
- Dimension dim;
- for (String s : strs) {
- if (s.startsWith("$") && s.endsWith("$")) {
- drawLaTeX(g, s, x, y, useExternalFont);
- dim = getStringDimension(s, g, true);
- x += dim.width;
- } else {
- dim = getStringDimension(s, g, false);
- g.drawString(s, x, y - (float) (dim.getHeight() * 0.2));
- x += dim.width - 5;
- }
- }
- break;
- default:
- FontMetrics fm = g.getFontMetrics();
- g.drawString(str, x, y - fm.getDescent());
- break;
- }
- }
-
- /**
- * Draw string
- *
- * @param g Graphics2D
- * @param str String
- * @param x X
- * @param y Y
- * @param useExternalFont If use external font
- */
- public static void drawString(Graphics2D g, String str, double x, double y, boolean useExternalFont) {
- switch (getStringType(str)) {
- case LATEX:
- drawLaTeX(g, str, (float) x, (float) y, useExternalFont);
- break;
- case MIXING:
- List strs = splitMixingString(str);
- Dimension dim;
- for (String s : strs) {
- if (s.startsWith("$") && s.endsWith("$")) {
- drawLaTeX(g, s, (float) x, (float) y, useExternalFont);
- dim = getStringDimension(s, g, true);
- x += dim.width;
- } else {
- dim = getStringDimension(s, g, false);
- g.drawString(s, (float) x, (float) (y - dim.getHeight() * 0.2));
- x += dim.width - 5;
- }
- }
- break;
- default:
- FontMetrics fm = g.getFontMetrics();
- g.drawString(str, (float) x, (float) (y - fm.getDescent()));
- break;
- }
- }
-
-// /**
-// * Draw string
-// *
-// * @param g Graphics2D
-// * @param str String
-// * @param x X
-// * @param y Y
-// * @param isLaTeX If is LaTeX
-// */
-// public static void drawString(Graphics2D g, String str, float x, float y, boolean isLaTeX) {
-// if (isLaTeX) {
-// drawLaTeX(g, str, x, y);
-// } else {
-// g.drawString(str, x, y);
-// }
-// }
- /**
- * Draw LaTeX string
- *
- * @param g Graphics2D
- * @param str String
- * @param x X
- * @param y Y
- * @param useExternalFont If use external font
- */
- public static void drawLaTeX(Graphics2D g, String str, float x, float y, boolean useExternalFont) {
- float size = g.getFont().getSize2D();
- drawLaTeX(g, str, size, x, y, useExternalFont);
- }
-
- /**
- * Draw LaTeX string
- *
- * @param g Graphics2D
- * @param str String
- * @param size Size
- * @param x X
- * @param y Y
- * @param useExternalFont If use external font
- */
- public static void drawLaTeX(Graphics2D g, String str, float size, float x, float y, boolean useExternalFont) {
- if (useExternalFont) {
- //Set font
- TeXFormula.registerExternalFont(Character.UnicodeBlock.BASIC_LATIN, g.getFont().getName());
- } else {
- TeXFormula.registerExternalFont(Character.UnicodeBlock.BASIC_LATIN, null, null);
- }
-
- // create a formula
- TeXFormula formula = new TeXFormula(str);
-
- // render the formla to an icon of the same size as the formula.
- TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_TEXT, size);
-
- // insert a border
- icon.setInsets(new Insets(5, 5, 5, 5));
- icon.setForeground(g.getColor());
- y = y - icon.getIconHeight() + (icon.getIconHeight() - icon.getTrueIconHeight()) * 0.6f;
- //y = y - icon.getIconHeight() + size * 0.7f;
- //y = y - icon.getTrueIconHeight() * 1.f;
- Font font = g.getFont();
- icon.paintIcon(null, g, (int) x, (int) y);
- g.setFont(font);
- }
-
- //
- //
- /**
- * Create wind barb from wind direction/speed
- *
- * @param windDir Wind direction
- * @param windSpeed Wind speed
- * @param value Value
- * @param size Size
- * @param sPoint Start point
- * @return WindBarb
- */
- public static WindBarb calWindBarb(float windDir, float windSpeed, double value,
- float size, PointD sPoint) {
- WindBarb aWB = new WindBarb();
-
- windSpeed += 1;
- aWB.windSpeed = windSpeed;
- aWB.angle = windDir;
- aWB.setValue(value);
- aWB.size = size;
- aWB.setPoint(sPoint);
- aWB.windSpeesLine.W20 = (int) (windSpeed / 20);
- aWB.windSpeesLine.W4 = (int) ((windSpeed - aWB.windSpeesLine.W20 * 20) / 4);
- aWB.windSpeesLine.W2 = (int) ((windSpeed - aWB.windSpeesLine.W20 * 20
- - aWB.windSpeesLine.W4 * 4) / 2);
-
- return aWB;
- }
-
- /**
- * Create station model shape
- *
- * @param windDir Wind direction
- * @param windSpeed Wind speed
- * @param value Value
- * @param size Size
- * @param sPoint Location point
- * @param weather Weather
- * @param temp Temperature
- * @param dewPoint Dew point
- * @param pressure Pressure
- * @param cloudCover Cloud cover
- * @return Station model shape
- */
- public static StationModelShape calStationModel(float windDir, float windSpeed, double value,
- float size, PointD sPoint, int weather, int temp, int dewPoint, int pressure, int cloudCover) {
- StationModelShape aSM = new StationModelShape();
- aSM.setPoint(sPoint);
- aSM.setValue(value);
- aSM.size = size;
- aSM.temperature = temp;
- aSM.dewPoint = dewPoint;
- aSM.pressure = pressure;
- aSM.windBarb = calWindBarb(windDir, windSpeed, value, size, sPoint);
- aSM.weatherSymbol.size = size / 4 * 3;
- //sPoint.X = sPoint.X - size / 2;
- PointD aPoint = new PointD(sPoint.X - size / 2, sPoint.Y);
- aSM.weatherSymbol.setPoint(aPoint);
- aSM.weatherSymbol.weather = weather;
- aSM.cloudCoverage.cloudCover = cloudCover;
- aSM.cloudCoverage.size = size / 4 * 3;
- aSM.cloudCoverage.sPoint = aPoint;
-
- return aSM;
- }
-
- /**
- * Draw wind arrow
- *
- * @param sP Start point
- * @param aArraw The arrow
- * @param g Graphics2D
- * @param zoom Zoom
- * @return Border rectangle
- */
- public static Rectangle2D getArrawBorder(PointF sP, WindArrow aArraw, Graphics2D g, double zoom) {
- PointF eP = new PointF(0, 0);
- //PointF eP1 = new PointF(0, 0);
- double len = aArraw.length;
- double angle = aArraw.angle + 180;
- if (angle >= 360) {
- angle -= 360;
- }
-
- len = len * zoom;
-
- eP.X = (int) (sP.X + len * Math.sin(angle * Math.PI / 180));
- eP.Y = (int) (sP.Y - len * Math.cos(angle * Math.PI / 180));
-
- if (angle == 90) {
- eP.Y = sP.Y;
- }
-
- return new Rectangle2D.Double(Math.min(sP.X, eP.X), Math.min(sP.Y, eP.Y),
- Math.abs(eP.X - sP.X), Math.abs(eP.Y - sP.Y));
- }
-
- /**
- * Draw arrow line
- *
- * @param points Line points
- * @param pb Legend
- * @param arrowSize ArrowSize
- * @param g Graphics2D
- */
- public static void drawArrow(PointF[] points, PointBreak pb, int arrowSize, Graphics2D g) {
- g.setColor(pb.getColor());
- g.setStroke(new BasicStroke(pb.getOutlineSize()));
- drawPolyline(points, g);
-
- int n = points.length;
- PointF aPoint = points[n - 2];
- PointF bPoint = points[n - 1];
- double U = bPoint.X - aPoint.X;
- double V = bPoint.Y - aPoint.Y;
- double angle = Math.atan((V) / (U)) * 180 / Math.PI;
- angle = angle + 90;
- if (U < 0) {
- angle = angle + 180;
- }
-
- if (angle >= 360) {
- angle = angle - 360;
- }
-
- Draw.drawArraw(g, bPoint, angle, arrowSize);
- }
-
- /**
- * Draw wind arrow
- *
- * @param aColor The color
- * @param sP Start point
- * @param aArraw The arrow
- * @param g Graphics2D
- * @param zoom Zoom
- * @return Border rectangle
- */
- public static Rectangle2D drawArraw(Color aColor, PointF sP, WindArrow aArraw, Graphics2D g, double zoom) {
- PointF eP = new PointF(0, 0);
- //PointF eP1 = new PointF(0, 0);
- double len = aArraw.length;
- double angle = aArraw.angle + 180;
- if (angle >= 360) {
- angle -= 360;
- }
-
- len = len * zoom;
-
- eP.X = (int) (sP.X + len * Math.sin(angle * Math.PI / 180));
- eP.Y = (int) (sP.Y - len * Math.cos(angle * Math.PI / 180));
-
- if (angle == 90) {
- eP.Y = sP.Y;
- }
-
- g.setColor(aColor);
- g.draw(new Line2D.Float(sP.X, sP.Y, eP.X, eP.Y));
- drawArraw(g, eP, angle);
- return new Rectangle2D.Double(Math.min(sP.X, eP.X), Math.min(sP.Y, eP.Y),
- Math.abs(eP.X - sP.X), Math.abs(eP.Y - sP.Y));
-
-// GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 5);
-// path.moveTo(sP.X, sP.Y);
-// path.lineTo(eP.X, eP.Y);
-//
-// eP1.X = (int) (eP.X - aArraw.size * Math.sin((angle + 20.0) * Math.PI / 180));
-// eP1.Y = (int) (eP.Y + aArraw.size * Math.cos((angle + 20.0) * Math.PI / 180));
-// //g.draw(new Line2D.Float(eP.X, eP.Y, eP1.X, eP1.Y));
-// path.moveTo(eP1.X, eP1.Y);
-// path.lineTo(eP.X, eP.Y);
-//
-// eP1.X = (int) (eP.X - aArraw.size * Math.sin((angle - 20.0) * Math.PI / 180));
-// eP1.Y = (int) (eP.Y + aArraw.size * Math.cos((angle - 20.0) * Math.PI / 180));
-// //g.draw(new Line2D.Float(eP.X, eP.Y, eP1.X, eP1.Y));
-// path.lineTo(eP1.X, eP1.Y);
-// g.draw(path);
- }
-
- /**
- * Draw wind arrow
- *
- * @param sP Start point
- * @param aArraw The arrow
- * @param pb PointBreak
- * @param g Graphics2D
- * @param zoom Zoom
- * @return Border rectangle
- */
- public static Rectangle2D drawArraw(PointF sP, WindArrow aArraw, ArrowBreak pb, Graphics2D g, double zoom) {
- PointF eP = new PointF(0, 0);
- //PointF eP1 = new PointF(0, 0);
- double len = aArraw.length;
- double angle = aArraw.angle + 180;
- if (angle >= 360) {
- angle -= 360;
- }
-
- len = len * zoom;
-
- eP.X = (int) (sP.X + len * Math.sin(angle * Math.PI / 180));
- eP.Y = (int) (sP.Y - len * Math.cos(angle * Math.PI / 180));
-
- if (angle == 90) {
- eP.Y = sP.Y;
- }
-
- g.setColor(pb.getColor());
- float width = pb.getWidth();
- g.setStroke(new BasicStroke(width));
- g.draw(new Line2D.Float(sP.X, sP.Y, eP.X, eP.Y));
- float headWidth = pb.getHeadWidth();
- float headLength = pb.getHeadLength();
- drawArraw(g, eP, angle, headLength, headWidth, pb.getOverhang());
- return new Rectangle2D.Double(Math.min(sP.X, eP.X), Math.min(sP.Y, eP.Y),
- Math.abs(eP.X - sP.X), Math.abs(eP.Y - sP.Y));
- }
-
- /**
- * Draw arraw
- *
- * @param g Graphics2D
- * @param sP Start point
- * @param angle Angle
- */
- public static void drawArraw(Graphics2D g, PointF sP, double angle) {
- GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 5);
- Rectangle.Float rect = new Rectangle.Float(-4, -4, 8, 8);
- PointF[] pt = new PointF[5];
- pt[0] = new PointF(rect.x, rect.y);
- pt[1] = new PointF(rect.x + rect.width, rect.y + (rect.height / 2));
- pt[2] = new PointF(rect.x, rect.y + rect.height);
- pt[3] = new PointF(rect.x + rect.width / 2, pt[1].Y);
- pt[4] = pt[0];
- path.moveTo(pt[0].X, pt[0].Y);
- for (int i = 1; i < 5; i++) {
- path.lineTo(pt[i].X, pt[i].Y);
- }
-
- AffineTransform tempTrans = g.getTransform();
- if (angle != 0) {
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- //myTrans.translate(tempTrans.getTranslateX() + sP.X, tempTrans.getTranslateY() + sP.Y);
- myTrans.translate(sP.X, sP.Y);
- double angle1 = angle - 90;
- myTrans.rotate(angle1 * Math.PI / 180);
- g.setTransform(myTrans);
- }
- path.closePath();
- g.fill(path);
-
- if (angle != 0) {
- g.setTransform(tempTrans);
- }
- }
-
- /**
- * Draw arraw
- *
- * @param g Graphics2D
- * @param sP Start point
- * @param angle Angle
- * @param size Arrow size
- */
- public static void drawArraw(Graphics2D g, PointF sP, double angle, int size) {
- GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 5);
- Rectangle.Float rect = new Rectangle.Float(-size, -size, size * 2, size * 2);
- PointF[] pt = new PointF[5];
- pt[0] = new PointF(rect.x, rect.y);
- pt[1] = new PointF(rect.x + rect.width, rect.y + (rect.height / 2));
- pt[2] = new PointF(rect.x, rect.y + rect.height);
- pt[3] = new PointF(rect.x + rect.width / 2, pt[1].Y);
- pt[4] = pt[0];
- path.moveTo(pt[0].X, pt[0].Y);
- for (int i = 1; i < 5; i++) {
- path.lineTo(pt[i].X, pt[i].Y);
- }
-
- AffineTransform tempTrans = g.getTransform();
- if (angle != 0) {
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- //myTrans.translate(tempTrans.getTranslateX() + sP.X, tempTrans.getTranslateY() + sP.Y);
- myTrans.translate(sP.X, sP.Y);
- double angle1 = angle - 90;
- myTrans.rotate(angle1 * Math.PI / 180);
- g.setTransform(myTrans);
- }
- path.closePath();
- g.fill(path);
-
- if (angle != 0) {
- g.setTransform(tempTrans);
- }
- }
-
- /**
- * Draw arraw
- *
- * @param g Graphics2D
- * @param sP Start point
- * @param angle Angle
- * @param length Arrow length
- * @param width Arrow width
- * @param overhang Overhang
- */
- public static void drawArraw(Graphics2D g, PointF sP, double angle, float length, float width,
- float overhang) {
- PointF[] pt;
- float x = -length;
- float y = -width * 0.5f;
- //Rectangle.Float rect = new Rectangle.Float(x, y, length, width);
- if (overhang == 1) {
- pt = new PointF[3];
- pt[0] = new PointF(x, y);
- pt[1] = new PointF(x + length, y + (width / 2));
- pt[2] = new PointF(x, y + width);
- } else {
- x += length * (1 - overhang);
- pt = new PointF[5];
- pt[0] = new PointF(x, y);
- pt[1] = new PointF(x + length, y + (width / 2));
- pt[2] = new PointF(x, y + width);
- pt[3] = new PointF(x + length * overhang, pt[1].Y);
- pt[4] = pt[0];
- }
- GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, pt.length);
- path.moveTo(pt[0].X, pt[0].Y);
- for (int i = 1; i < pt.length; i++) {
- path.lineTo(pt[i].X, pt[i].Y);
- }
-
- AffineTransform tempTrans = g.getTransform();
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- //myTrans.translate(tempTrans.getTranslateX() + sP.X, tempTrans.getTranslateY() + sP.Y);
- myTrans.translate(sP.X, sP.Y);
- double angle1 = angle - 90;
- if (angle1 != 0) {
- myTrans.rotate(angle1 * Math.PI / 180);
- }
- g.setTransform(myTrans);
- if (overhang == 1) {
- g.draw(path);
- } else {
- path.closePath();
- g.fill(path);
- }
-
- g.setTransform(tempTrans);
- }
-
- /**
- * Draw arraw
- *
- * @param g Graphics2D
- * @param sP Start point
- * @param angle Angle
- * @param length Arrow length
- * @param width Arrow width
- * @param overhang Overhang
- * @param fillColor Arrow fill color
- * @param outlineColor Arrow outline color
- */
- public static void drawArraw(Graphics2D g, PointF sP, double angle, float length, float width,
- float overhang, Color fillColor, Color outlineColor) {
- PointF[] pt;
- float x = -length;
- float y = -width * 0.5f;
- //Rectangle.Float rect = new Rectangle.Float(x, y, length, width);
- if (overhang == 1) {
- pt = new PointF[3];
- pt[0] = new PointF(x, y);
- pt[1] = new PointF(x + length, 0);
- pt[2] = new PointF(x, y + width);
- } else {
- pt = new PointF[5];
- pt[0] = new PointF(x, y);
- pt[1] = new PointF(x + length, 0);
- pt[2] = new PointF(x, y + width);
- pt[3] = new PointF(x + length * overhang, pt[1].Y);
- pt[4] = pt[0];
- }
- GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, pt.length);
- path.moveTo(pt[0].X, pt[0].Y);
- for (int i = 1; i < pt.length; i++) {
- path.lineTo(pt[i].X, pt[i].Y);
- }
-
- AffineTransform tempTrans = g.getTransform();
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- //myTrans.translate(tempTrans.getTranslateX() + sP.X, tempTrans.getTranslateY() + sP.Y);
- myTrans.translate(sP.X, sP.Y);
- double angle1 = angle - 90;
- if (angle1 != 0) {
- myTrans.rotate(angle1 * Math.PI / 180);
- }
- g.setTransform(myTrans);
- if (overhang == 1) {
- g.setColor(fillColor);
- g.draw(path);
- } else {
- if (fillColor != null) {
- path.closePath();
- g.setColor(fillColor);
- g.fill(path);
- }
- if (outlineColor != null) {
- g.setColor(outlineColor);
- g.draw(path);
- }
- }
-
- g.setTransform(tempTrans);
- }
-
- /**
- * Draw wind barb
- *
- * @param aColor Color
- * @param sP Point
- * @param aWB WindBarb
- * @param g Grahics2D
- * @param size Size
- */
- public static void drawWindBarb(Color aColor, PointF sP, WindBarb aWB, Graphics2D g, float size) {
- PointF eP;
- PointF eP1;
- double len = size * 2;
- int i;
-
- double aLen = len;
-
- eP = new PointF();
- eP.X = (float) (sP.X + len * Math.sin(aWB.angle * Math.PI / 180));
- eP.Y = (float) (sP.Y - len * Math.cos(aWB.angle * Math.PI / 180));
- g.setColor(aColor);
- g.draw(new Line2D.Float(sP.X, sP.Y, eP.X, eP.Y));
-
- len = len / 2;
- if (aWB.windSpeesLine.W20 > 0) {
- for (i = 0; i < aWB.windSpeesLine.W20; i++) {
- eP1 = new PointF();
- eP1.X = (float) (eP.X - len * Math.sin((aWB.angle - 105) * Math.PI / 180));
- eP1.Y = (float) (eP.Y + len * Math.cos((aWB.angle - 105) * Math.PI / 180));
- g.draw(new Line2D.Float(eP.X, eP.Y, eP1.X, eP1.Y));
- eP.X = (float) (eP.X - aLen / 8 * Math.sin((aWB.angle) * Math.PI / 180));
- eP.Y = (float) (eP.Y + aLen / 8 * Math.cos((aWB.angle) * Math.PI / 180));
- g.draw(new Line2D.Float(eP.X, eP.Y, eP1.X, eP1.Y));
- }
- eP.X = (float) (eP.X - aLen / 8 * Math.sin((aWB.angle) * Math.PI / 180));
- eP.Y = (float) (eP.Y + aLen / 8 * Math.cos((aWB.angle) * Math.PI / 180));
- }
- if (aWB.windSpeesLine.W4 > 0) {
- for (i = 0; i < aWB.windSpeesLine.W4; i++) {
- eP1 = new PointF();
- eP1.X = (float) (eP.X - len * Math.sin((aWB.angle - 120) * Math.PI / 180));
- eP1.Y = (float) (eP.Y + len * Math.cos((aWB.angle - 120) * Math.PI / 180));
- g.draw(new Line2D.Float(eP.X, eP.Y, eP1.X, eP1.Y));
- eP.X = (float) (eP.X - aLen / 8 * Math.sin((aWB.angle) * Math.PI / 180));
- eP.Y = (float) (eP.Y + aLen / 8 * Math.cos((aWB.angle) * Math.PI / 180));
- }
- }
- if (aWB.windSpeesLine.W2 > 0) {
- len = len / 2;
- eP1 = new PointF();
- eP1.X = (float) (eP.X - len * Math.sin((aWB.angle - 120) * Math.PI / 180));
- eP1.Y = (float) (eP.Y + len * Math.cos((aWB.angle - 120) * Math.PI / 180));
- g.draw(new Line2D.Float(eP.X, eP.Y, eP1.X, eP1.Y));
- }
- }
-
- /**
- * Draw wind barb
- *
- * @param sP Point
- * @param aWB WindBarb
- * @param pb PointBreak
- * @param g Grahics2D
- */
- public static void drawWindBarb(PointF sP, WindBarb aWB, PointBreak pb, Graphics2D g) {
- PointF eP;
- PointF eP1;
- double len = pb.getSize() * 2;
- int i;
-
- double aLen = len;
-
- eP = new PointF();
- eP.X = (float) (sP.X + len * Math.sin(aWB.angle * Math.PI / 180));
- eP.Y = (float) (sP.Y - len * Math.cos(aWB.angle * Math.PI / 180));
- g.setColor(pb.getColor());
- g.setStroke(new BasicStroke(pb.getOutlineSize()));
- g.draw(new Line2D.Float(sP.X, sP.Y, eP.X, eP.Y));
-
- len = len / 2;
- if (aWB.windSpeesLine.W20 > 0) {
- for (i = 0; i < aWB.windSpeesLine.W20; i++) {
- eP1 = new PointF();
- eP1.X = (float) (eP.X - len * Math.sin((aWB.angle - 105) * Math.PI / 180));
- eP1.Y = (float) (eP.Y + len * Math.cos((aWB.angle - 105) * Math.PI / 180));
- g.draw(new Line2D.Float(eP.X, eP.Y, eP1.X, eP1.Y));
- eP.X = (float) (eP.X - aLen / 8 * Math.sin((aWB.angle) * Math.PI / 180));
- eP.Y = (float) (eP.Y + aLen / 8 * Math.cos((aWB.angle) * Math.PI / 180));
- g.draw(new Line2D.Float(eP.X, eP.Y, eP1.X, eP1.Y));
- }
- eP.X = (float) (eP.X - aLen / 8 * Math.sin((aWB.angle) * Math.PI / 180));
- eP.Y = (float) (eP.Y + aLen / 8 * Math.cos((aWB.angle) * Math.PI / 180));
- }
- if (aWB.windSpeesLine.W4 > 0) {
- for (i = 0; i < aWB.windSpeesLine.W4; i++) {
- eP1 = new PointF();
- eP1.X = (float) (eP.X - len * Math.sin((aWB.angle - 120) * Math.PI / 180));
- eP1.Y = (float) (eP.Y + len * Math.cos((aWB.angle - 120) * Math.PI / 180));
- g.draw(new Line2D.Float(eP.X, eP.Y, eP1.X, eP1.Y));
- eP.X = (float) (eP.X - aLen / 8 * Math.sin((aWB.angle) * Math.PI / 180));
- eP.Y = (float) (eP.Y + aLen / 8 * Math.cos((aWB.angle) * Math.PI / 180));
- }
- }
- if (aWB.windSpeesLine.W2 > 0) {
- len = len / 2;
- eP1 = new PointF();
- eP1.X = (float) (eP.X - len * Math.sin((aWB.angle - 120) * Math.PI / 180));
- eP1.Y = (float) (eP.Y + len * Math.cos((aWB.angle - 120) * Math.PI / 180));
- g.draw(new Line2D.Float(eP.X, eP.Y, eP1.X, eP1.Y));
- }
- }
-
- /**
- * Draw wind barb
- *
- * @param aColor Color
- * @param sP Point
- * @param aWB WindBarb
- * @param g Grahics2D
- * @param size Size
- * @param cut Cut
- */
- public static void drawWindBarb(Color aColor, PointF sP, WindBarb aWB, Graphics2D g, float size, float cut) {
- PointF eP;
- PointF eP1;
- double len = size * 2;
- int i;
-
- double aLen = len;
-
- eP = new PointF();
- eP.X = (float) (sP.X + len * Math.sin(aWB.angle * Math.PI / 180));
- eP.Y = (float) (sP.Y - len * Math.cos(aWB.angle * Math.PI / 180));
- PointF cutSP = new PointF(0, 0);
- cutSP.X = (float) (sP.X + cut * Math.sin(aWB.angle * Math.PI / 180));
- cutSP.Y = (float) (sP.Y - cut * Math.cos(aWB.angle * Math.PI / 180));
- g.setColor(aColor);
- g.draw(new Line2D.Float(cutSP.X, cutSP.Y, eP.X, eP.Y));
-
- len = len / 2;
- if (aWB.windSpeesLine.W20 > 0) {
- for (i = 0; i < aWB.windSpeesLine.W20; i++) {
- eP1 = new PointF();
- eP1.X = (float) (eP.X - len * Math.sin((aWB.angle - 105) * Math.PI / 180));
- eP1.Y = (float) (eP.Y + len * Math.cos((aWB.angle - 105) * Math.PI / 180));
- g.draw(new Line2D.Float(eP.X, eP.Y, eP1.X, eP1.Y));
- eP.X = (float) (eP.X - aLen / 8 * Math.sin((aWB.angle) * Math.PI / 180));
- eP.Y = (float) (eP.Y + aLen / 8 * Math.cos((aWB.angle) * Math.PI / 180));
- g.draw(new Line2D.Float(eP.X, eP.Y, eP1.X, eP1.Y));
- }
- eP.X = (float) (eP.X - aLen / 8 * Math.sin((aWB.angle) * Math.PI / 180));
- eP.Y = (float) (eP.Y + aLen / 8 * Math.cos((aWB.angle) * Math.PI / 180));
- }
- if (aWB.windSpeesLine.W4 > 0) {
- for (i = 0; i < aWB.windSpeesLine.W4; i++) {
- eP1 = new PointF();
- eP1.X = (float) (eP.X - len * Math.sin((aWB.angle - 120) * Math.PI / 180));
- eP1.Y = (float) (eP.Y + len * Math.cos((aWB.angle - 120) * Math.PI / 180));
- g.draw(new Line2D.Float(eP.X, eP.Y, eP1.X, eP1.Y));
- eP.X = (float) (eP.X - aLen / 8 * Math.sin((aWB.angle) * Math.PI / 180));
- eP.Y = (float) (eP.Y + aLen / 8 * Math.cos((aWB.angle) * Math.PI / 180));
- }
- }
- if (aWB.windSpeesLine.W2 > 0) {
- len = len / 2;
- eP1 = new PointF();
- eP1.X = (float) (eP.X - len * Math.sin((aWB.angle - 120) * Math.PI / 180));
- eP1.Y = (float) (eP.Y + len * Math.cos((aWB.angle - 120) * Math.PI / 180));
- g.draw(new Line2D.Float(eP.X, eP.Y, eP1.X, eP1.Y));
- }
- }
-
- /**
- * Draw point
- *
- * @param aPS Point style
- * @param aP The point position
- * @param color The color
- * @param outlineColor Outline color
- * @param aSize size
- * @param drawOutline If draw outline
- * @param drawFill If draw fill
- * @param g Graphics2D
- */
- public static void drawPoint(PointStyle aPS, PointF aP, Color color, Color outlineColor,
- float aSize, Boolean drawOutline, Boolean drawFill, Graphics2D g) {
- PointBreak aPB = new PointBreak();
- aPB.setMarkerType(MarkerType.Simple);
- aPB.setStyle(aPS);
- aPB.setColor(color);
- aPB.setOutlineColor(outlineColor);
- aPB.setSize(aSize);
- aPB.setDrawOutline(drawOutline);
- aPB.setDrawFill(drawFill);
-
- drawPoint(aP, aPB, g);
- }
-
- /**
- * Draw point
- *
- * @param aP Position
- * @param aPB Point break
- * @param g Graphics
- */
- public static void drawPoint(PointF aP, PointBreak aPB, Graphics2D g) {
- Rectangle clip = g.getClipBounds();
- if (clip != null) {
- g.setClip(null);
- if (aP.X >= clip.x && aP.X <= clip.x + clip.width && aP.Y >= clip.y
- && aP.Y <= clip.y + clip.height) {
- switch (aPB.getMarkerType()) {
- case Simple:
- drawPoint_Simple(aP, aPB, g);
- break;
- case Character:
- drawPoint_Character(aP, aPB, g);
- break;
- case Image:
- drawPoint_Image(aP, aPB, g);
- break;
- }
- }
- g.setClip(clip);
- } else {
- switch (aPB.getMarkerType()) {
- case Simple:
- drawPoint_Simple(aP, aPB, g);
- break;
- case Character:
- drawPoint_Character(aP, aPB, g);
- break;
- case Image:
- drawPoint_Image(aP, aPB, g);
- break;
- }
- }
- }
-
- /**
- * Draw point
- *
- * @param aP Position
- * @param aPB Point break
- * @param g Graphics
- */
- public static void drawMapPoint(PointF aP, PointBreak aPB, Graphics2D g) {
- switch (aPB.getMarkerType()) {
- case Simple:
- drawPoint_Simple(aP, aPB, g);
- break;
- case Character:
- drawPoint_Character(aP, aPB, g);
- break;
- case Image:
- drawPoint_Image(aP, aPB, g);
- break;
- }
- }
-
- private static void drawPoint_Simple(PointF aP, PointBreak aPB, Graphics2D g) {
- AffineTransform tempTrans = g.getTransform();
- if (aPB.getAngle() != 0) {
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- myTrans.translate(aP.X, aP.Y);
- //myTrans.translate(tempTrans.getTranslateX() + aP.X, tempTrans.getTranslateY() + aP.Y);
- myTrans.rotate(aPB.getAngle() * Math.PI / 180);
- g.setTransform(myTrans);
- aP.X = 0;
- aP.Y = 0;
- }
-
- g.setStroke(new BasicStroke(1.0f));
- int[] xPoints;
- int[] yPoints;
- float aSize = aPB.getSize();
- boolean drawFill = aPB.isDrawFill();
- boolean drawOutline = aPB.isDrawOutline();
- Color color = aPB.getColor();
- Color outlineColor = aPB.getOutlineColor();
- float outlineSize = aPB.getOutlineSize();
-
- GeneralPath path = new GeneralPath();
-
- switch (aPB.getStyle()) {
- case Circle:
- aP.X = aP.X - aSize / 2.f;
- aP.Y = aP.Y - aSize / 2.f;
- Ellipse2D ellipse = new Ellipse2D.Float(aP.X, aP.Y, aSize, aSize);
- if (drawFill) {
- g.setColor(color);
- g.fill(ellipse);
- //g.fillOval((int) aP.X, (int) aP.Y, (int) aSize, (int) aSize);
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(outlineSize));
- g.draw(ellipse);
- //g.drawOval((int) aP.X, (int) aP.Y, (int) aSize, (int) aSize);
- }
- break;
- case DOUBLE_CIRCLE:
- float x,
- y;
- x = aP.X - aSize / 2.f;
- y = aP.Y - aSize / 2.f;
- ellipse = new Ellipse2D.Float(x, y, aSize, aSize);
- if (drawFill) {
- g.setColor(color);
- g.fill(ellipse);
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(outlineSize));
- g.draw(ellipse);
- x = aP.X - aSize * 0.3f;
- y = aP.Y - aSize * 0.3f;
- ellipse = new Ellipse2D.Float(x, y, aSize * 0.6f, aSize * 0.6f);
- g.draw(ellipse);
- }
- break;
- case Square:
- aP.X = aP.X - aSize / 2.f;
- aP.Y = aP.Y - aSize / 2.f;
- Rectangle2D rect = new Rectangle2D.Float(aP.X, aP.Y, aSize, aSize);
- if (drawFill) {
- g.setColor(color);
- g.fill(rect);
- //g.fillRect((int) aP.X, (int) aP.Y, (int) aSize, (int) aSize);
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(outlineSize));
- g.draw(rect);
- //g.drawRect((int) aP.X, (int) aP.Y, (int) aSize, (int) aSize);
- }
- break;
- case Diamond:
- xPoints = new int[4];
- yPoints = new int[4];
- xPoints[0] = (int) (aP.X - aSize / 2);
- yPoints[0] = (int) aP.Y;
- xPoints[1] = (int) aP.X;
- yPoints[1] = (int) (aP.Y - aSize / 2);
- xPoints[2] = (int) (aP.X + aSize / 2);
- yPoints[2] = (int) aP.Y;
- xPoints[3] = (int) aP.X;
- yPoints[3] = (int) (aP.Y + aSize / 2);
- if (drawFill) {
- g.setColor(color);
- g.fillPolygon(xPoints, yPoints, xPoints.length);
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(outlineSize));
- g.drawPolygon(xPoints, yPoints, xPoints.length);
- }
- break;
- case UpTriangle:
- xPoints = new int[3];
- yPoints = new int[3];
- xPoints[0] = (int) aP.X;
- yPoints[0] = (int) (aP.Y - aSize / 2);
- xPoints[1] = (int) (aP.X + aSize / 4 * Math.sqrt(3));
- yPoints[1] = (int) (aP.Y + aSize / 4);
- xPoints[2] = (int) (aP.X - aSize / 4 * Math.sqrt(3));
- yPoints[2] = (int) (aP.Y + aSize / 4);
- if (drawFill) {
- g.setColor(color);
- g.fillPolygon(xPoints, yPoints, xPoints.length);
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(outlineSize));
- g.drawPolygon(xPoints, yPoints, xPoints.length);
- }
- break;
- case DownTriangle:
- xPoints = new int[3];
- yPoints = new int[3];
- xPoints[0] = (int) aP.X;
- yPoints[0] = (int) (aP.Y + aSize / 2);
- xPoints[1] = (int) (aP.X - aSize / 4 * Math.sqrt(3));
- yPoints[1] = (int) (aP.Y - aSize / 4);
- xPoints[2] = (int) (aP.X + aSize / 4 * Math.sqrt(3));
- yPoints[2] = (int) (aP.Y - aSize / 4);
- if (drawFill) {
- g.setColor(color);
- g.fillPolygon(xPoints, yPoints, xPoints.length);
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(outlineSize));
- g.drawPolygon(xPoints, yPoints, xPoints.length);
- }
- break;
- case XCross:
- path.moveTo(aP.X - aSize / 2, aP.Y - aSize / 2);
- path.lineTo(aP.X + aSize / 2, aP.Y + aSize / 2);
- path.moveTo(aP.X - aSize / 2, aP.Y + aSize / 2);
- path.lineTo(aP.X + aSize / 2, aP.Y - aSize / 2);
- path.closePath();
- if (drawFill || drawOutline) {
- g.setColor(color);
- g.setStroke(new BasicStroke(outlineSize));
- g.draw(path);
- }
- break;
- case Plus:
- path.moveTo(aP.X, aP.Y - aSize / 2);
- path.lineTo(aP.X, aP.Y + aSize / 2);
- path.moveTo(aP.X - aSize / 2, aP.Y);
- path.lineTo(aP.X + aSize / 2, aP.Y);
- path.closePath();
- if (drawFill || drawOutline) {
- g.setColor(color);
- g.setStroke(new BasicStroke(outlineSize));
- g.draw(path);
- }
- break;
- case Minus:
- path.moveTo(aP.X - aSize / 2, aP.Y);
- path.lineTo(aP.X + aSize / 2, aP.Y);
- path.closePath();
- if (drawFill || drawOutline) {
- g.setColor(color);
- g.setStroke(new BasicStroke(outlineSize));
- g.draw(path);
- }
- break;
- case StarLines:
- path.moveTo(aP.X - aSize / 2, aP.Y - aSize / 2);
- path.lineTo(aP.X + aSize / 2, aP.Y + aSize / 2);
- path.moveTo(aP.X - aSize / 2, aP.Y + aSize / 2);
- path.lineTo(aP.X + aSize / 2, aP.Y - aSize / 2);
- path.moveTo(aP.X, aP.Y - aSize / 2);
- path.lineTo(aP.X, aP.Y + aSize / 2);
- path.moveTo(aP.X - aSize / 2, aP.Y);
- path.lineTo(aP.X + aSize / 2, aP.Y);
- path.closePath();
- if (drawFill || drawOutline) {
- g.setColor(color);
- g.setStroke(new BasicStroke(outlineSize));
- g.draw(path);
- }
- break;
- case Star:
- float vRadius = aSize / 2;
- //Calculate 5 end points
- PointF[] vPoints = new PointF[5];
- double vAngle = 2.0 * Math.PI / 4 + Math.PI;
- for (int i = 0; i < vPoints.length; i++) {
- vAngle += 2.0 * Math.PI / (double) vPoints.length;
- vPoints[i] = new PointF(
- (float) (Math.cos(vAngle) * vRadius) + aP.X,
- (float) (Math.sin(vAngle) * vRadius) + aP.Y);
- }
- //Calculate 5 cross points
- PointF[] cPoints = new PointF[5];
- cPoints[0] = MIMath.getCrossPoint(vPoints[0], vPoints[2], vPoints[1], vPoints[4]);
- cPoints[1] = MIMath.getCrossPoint(vPoints[1], vPoints[3], vPoints[0], vPoints[2]);
- cPoints[2] = MIMath.getCrossPoint(vPoints[1], vPoints[3], vPoints[2], vPoints[4]);
- cPoints[3] = MIMath.getCrossPoint(vPoints[0], vPoints[3], vPoints[2], vPoints[4]);
- cPoints[4] = MIMath.getCrossPoint(vPoints[0], vPoints[3], vPoints[1], vPoints[4]);
- //New points
- xPoints = new int[10];
- yPoints = new int[10];
- for (int i = 0; i < 5; i++) {
- xPoints[i * 2] = (int) vPoints[i].X;
- yPoints[i * 2] = (int) vPoints[i].Y;
- xPoints[i * 2 + 1] = (int) cPoints[i].X;
- yPoints[i * 2 + 1] = (int) cPoints[i].Y;
- }
- if (drawFill) {
- g.setColor(color);
- g.fillPolygon(xPoints, yPoints, xPoints.length);
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(outlineSize));
- g.drawPolygon(xPoints, yPoints, xPoints.length);
- }
- break;
- case CIRCLE_STAR:
- vRadius = aSize * 0.4f;
- //Calculate 5 end points
- vPoints = new PointF[5];
- vAngle = 2.0 * Math.PI / 4 + Math.PI;
- for (int i = 0; i < vPoints.length; i++) {
- vAngle += 2.0 * Math.PI / (double) vPoints.length;
- vPoints[i] = new PointF(
- (float) (Math.cos(vAngle) * vRadius) + aP.X,
- (float) (Math.sin(vAngle) * vRadius) + aP.Y);
- }
- //Calculate 5 cross points
- cPoints = new PointF[5];
- cPoints[0] = MIMath.getCrossPoint(vPoints[0], vPoints[2], vPoints[1], vPoints[4]);
- cPoints[1] = MIMath.getCrossPoint(vPoints[1], vPoints[3], vPoints[0], vPoints[2]);
- cPoints[2] = MIMath.getCrossPoint(vPoints[1], vPoints[3], vPoints[2], vPoints[4]);
- cPoints[3] = MIMath.getCrossPoint(vPoints[0], vPoints[3], vPoints[2], vPoints[4]);
- cPoints[4] = MIMath.getCrossPoint(vPoints[0], vPoints[3], vPoints[1], vPoints[4]);
- //New points
- xPoints = new int[10];
- yPoints = new int[10];
- for (int i = 0; i < 5; i++) {
- xPoints[i * 2] = (int) vPoints[i].X;
- yPoints[i * 2] = (int) vPoints[i].Y;
- xPoints[i * 2 + 1] = (int) cPoints[i].X;
- yPoints[i * 2 + 1] = (int) cPoints[i].Y;
- }
- if (drawFill) {
- g.setColor(color);
- g.fillPolygon(xPoints, yPoints, xPoints.length);
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(outlineSize));
- //g.drawPolygon(xPoints, yPoints, xPoints.length);
- x = aP.X - aSize * 0.5f;
- y = aP.Y - aSize * 0.5f;
- ellipse = new Ellipse2D.Float(x, y, aSize, aSize);
- g.draw(ellipse);
- }
- break;
- case Pentagon:
- vRadius = aSize / 2;
- //Calculate 5 end points
- xPoints = new int[5];
- yPoints = new int[5];
- vAngle = 2.0 * Math.PI / 4 + Math.PI;
- for (int i = 0; i < 5; i++) {
- vAngle += 2.0 * Math.PI / (double) 5;
- xPoints[i] = (int) (Math.cos(vAngle) * vRadius + aP.X);
- yPoints[i] = (int) (Math.sin(vAngle) * vRadius + aP.Y);
- }
- if (drawFill) {
- g.setColor(color);
- g.fillPolygon(xPoints, yPoints, xPoints.length);
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(outlineSize));
- g.drawPolygon(xPoints, yPoints, xPoints.length);
- }
- break;
- case UpSemiCircle:
- aP.X = aP.X - aSize / 2;
- aP.Y = aP.Y - aSize / 2;
- if (drawFill) {
- g.setColor(color);
- g.fill(new Arc2D.Float(aP.X, aP.Y, aSize, aSize, 180, 180, Arc2D.CHORD));
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(outlineSize));
- g.draw(new Arc2D.Float(aP.X, aP.Y, aSize, aSize, 180, 180, Arc2D.CHORD));
- }
- break;
- case DownSemiCircle:
- aP.X = aP.X - aSize / 2;
- aP.Y = aP.Y - aSize / 2;
- if (drawFill) {
- g.setColor(color);
- g.fill(new Arc2D.Float(aP.X, aP.Y, aSize, aSize, 0, 180, Arc2D.CHORD));
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(outlineSize));
- g.draw(new Arc2D.Float(aP.X, aP.Y, aSize, aSize, 0, 180, Arc2D.CHORD));
- }
- break;
- }
-
- if (aPB.getAngle() != 0) {
- g.setTransform(tempTrans);
- }
- }
-
- private static void drawPoint_Simple_Up(PointF aP, PointBreak aPB, Graphics2D g) {
- AffineTransform tempTrans = g.getTransform();
- if (aPB.getAngle() != 0) {
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- myTrans.translate(aP.X, aP.Y);
- //myTrans.translate(tempTrans.getTranslateX() + aP.X, tempTrans.getTranslateY() + aP.Y);
- myTrans.rotate(aPB.getAngle() * Math.PI / 180);
- g.setTransform(myTrans);
- aP.X = 0;
- aP.Y = 0;
- }
-
- int[] xPoints;
- int[] yPoints;
- float aSize = aPB.getSize();
- boolean drawFill = aPB.isDrawFill();
- boolean drawOutline = aPB.isDrawOutline();
- Color color = aPB.getColor();
- Color outlineColor = aPB.getOutlineColor();
- float outlineSize = aPB.getOutlineSize();
-
- GeneralPath path = new GeneralPath();
-
- switch (aPB.getStyle()) {
- case Circle:
- aP.X = aP.X - aSize / 2;
- aP.Y = aP.Y - aSize;
-
- if (drawFill) {
- g.setColor(color);
- g.fillOval((int) aP.X, (int) aP.Y, (int) aSize, (int) aSize);
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(outlineSize));
- g.drawOval((int) aP.X, (int) aP.Y, (int) aSize, (int) aSize);
- }
- break;
- case Square:
- aP.X = aP.X - aSize / 2;
- aP.Y = aP.Y - aSize;
-
- if (drawFill) {
- g.setColor(color);
- g.fillRect((int) aP.X, (int) aP.Y, (int) aSize, (int) aSize);
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(outlineSize));
- g.drawRect((int) aP.X, (int) aP.Y, (int) aSize, (int) aSize);
- }
- break;
- case Diamond:
- xPoints = new int[4];
- yPoints = new int[4];
- xPoints[0] = (int) (aP.X - aSize / 2);
- yPoints[0] = (int) aP.Y;
- xPoints[1] = (int) aP.X;
- yPoints[1] = (int) (aP.Y - aSize / 2);
- xPoints[2] = (int) (aP.X + aSize / 2);
- yPoints[2] = (int) aP.Y;
- xPoints[3] = (int) aP.X;
- yPoints[3] = (int) (aP.Y + aSize / 2);
- if (drawFill) {
- g.setColor(color);
- g.fillPolygon(xPoints, yPoints, xPoints.length);
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(outlineSize));
- g.drawPolygon(xPoints, yPoints, xPoints.length);
- }
- case UpTriangle:
- xPoints = new int[3];
- yPoints = new int[3];
- xPoints[0] = (int) aP.X;
- yPoints[0] = (int) (aP.Y - aSize * 3 / 4);
- xPoints[1] = (int) (aP.X + aSize / 4 * Math.sqrt(3));
- yPoints[1] = (int) (aP.Y);
- xPoints[2] = (int) (aP.X - aSize / 4 * Math.sqrt(3));
- yPoints[2] = (int) (aP.Y);
- if (drawFill) {
- g.setColor(color);
- g.fillPolygon(xPoints, yPoints, xPoints.length);
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(outlineSize));
- g.drawPolygon(xPoints, yPoints, xPoints.length);
- }
- break;
- }
-
- if (aPB.getAngle() != 0) {
- g.setTransform(tempTrans);
- }
- }
-
- private static void drawPoint_Character(PointF aP, PointBreak aPB, Graphics2D g) {
- AffineTransform tempTrans = g.getTransform();
- if (aPB.getAngle() != 0) {
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- myTrans.translate(aP.X, aP.Y);
- myTrans.rotate(aPB.getAngle() * Math.PI / 180);
- g.setTransform(myTrans);
- aP.X = 0;
- aP.Y = 0;
- }
-
- String text = String.valueOf((char) aPB.getCharIndex());
- Font wFont = new Font(aPB.getFontName(), Font.PLAIN, (int) aPB.getSize());
- g.setFont(wFont);
- FontMetrics metrics = g.getFontMetrics();
- PointF sPoint = (PointF) aP.clone();
- sPoint.X = sPoint.X - metrics.stringWidth(text) / 2;
- sPoint.Y = sPoint.Y + metrics.getHeight() / 4;
- //sPoint.X = sPoint.X - aPB.getSize() / 2;
- //sPoint.Y = sPoint.Y + aPB.getSize() / 2;
-
- g.setColor(aPB.getColor());
- g.drawString(text, sPoint.X, sPoint.Y);
-
- if (aPB.getAngle() != 0) {
- g.setTransform(tempTrans);
- }
- }
-
- private static void drawPoint_Image(PointF aP, PointBreak aPB, Graphics2D g) {
- AffineTransform tempTrans = g.getTransform();
- if (aPB.getAngle() != 0) {
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- myTrans.translate(aP.X, aP.Y);
- myTrans.rotate(aPB.getAngle() * Math.PI / 180);
- g.setTransform(myTrans);
- aP.X = 0;
- aP.Y = 0;
- }
-
- File imgFile = new File(aPB.getImagePath());
- if (!imgFile.exists()) {
- //String path = System.getProperty("user.dir");
- File directory = new File(".");
- String path = null;
- try {
- path = directory.getCanonicalPath();
- } catch (IOException ex) {
- Logger.getLogger(Draw.class.getName()).log(Level.SEVERE, null, ex);
- }
- path = path + File.separator + "Image";
- aPB.setImagePath(path + File.separator + imgFile.getName());
- }
- if (imgFile.exists()) {
- Image image = null;
- try {
- image = ImageIO.read(imgFile);
- } catch (IOException ex) {
- Logger.getLogger(Draw.class.getName()).log(Level.SEVERE, null, ex);
- }
-
- if (image != null) {
- //((Bitmap)image).MakeTransparent(Color.White);
- int width = (int) aPB.getSize();
- int height = width * image.getHeight(null) / image.getWidth(null);
- PointF sPoint = aP;
- sPoint.X = sPoint.X - width / 2;
- sPoint.Y = sPoint.Y - height / 2;
- g.drawImage(image, (int) sPoint.X, (int) sPoint.Y, width, height, null);
- }
- }
-
- if (aPB.getAngle() != 0) {
- g.setTransform(tempTrans);
- }
- }
-
- /**
- * Draws string at the specified coordinates with the specified alignment.
- *
- * @param g graphics context to draw
- * @param x the x coordinate
- * @param y the y coordinate
- * @param s the string to draw
- * @param x_align the alignment in x direction
- * @param y_align the alignment in y direction
- * @param useExternalFont Use external font or not
- */
- public static void drawString(Graphics2D g, float x, float y, String s, XAlign x_align, YAlign y_align, boolean useExternalFont) {
- Dimension dim = Draw.getStringDimension(s, g);
- switch (y_align) {
- case TOP:
- y += dim.getHeight();
- break;
- case CENTER:
- y += dim.getHeight() / 2;
- break;
- }
- switch (x_align) {
- case LEFT:
- drawString(g, s, x, y, useExternalFont);
- break;
- case RIGHT:
- drawString(g, s, x - (float) dim.getWidth(), y, useExternalFont);
- break;
- case CENTER:
- drawString(g, s, x - (float) dim.getWidth() / 2, y, useExternalFont);
- break;
- }
- }
-
- /**
- * Draws string at the specified coordinates with the specified alignment.
- *
- * @param g graphics context to draw
- * @param x the x coordinate
- * @param y the y coordinate
- * @param s the string to draw
- * @param x_align the alignment in x direction
- * @param y_align the alignment in y direction
- * @param useExternalFont Use external font or not
- */
- public static void drawString(Graphics2D g, double x, double y, String s, XAlign x_align, YAlign y_align, boolean useExternalFont) {
- Dimension dim = Draw.getStringDimension(s, g);
- switch (y_align) {
- case TOP:
- y += dim.getHeight();
- break;
- case CENTER:
- y += dim.getHeight() / 2;
- break;
- }
- switch (x_align) {
- case LEFT:
- drawString(g, s, x, y, useExternalFont);
- break;
- case RIGHT:
- drawString(g, s, x - (float) dim.getWidth(), y, useExternalFont);
- break;
- case CENTER:
- drawString(g, s, x - (float) dim.getWidth() / 2, y, useExternalFont);
- break;
- }
- }
-
- /**
- * Draw out string
- *
- * @param g Graphics2D
- * @param x X location
- * @param y Y location
- * @param s String
- * @param x_align X align
- * @param y_align Y align
- * @param angle Angle
- * @param useExternalFont Use external font or not
- */
- public static void drawString(Graphics2D g, float x, float y, String s, XAlign x_align, YAlign y_align, float angle, boolean useExternalFont) {
- if (angle == 0) {
- drawString(g, x, y, s, x_align, y_align, useExternalFont);
- } else {
- /*AffineTransform tempTrans = g.getTransform();
- AffineTransform myTrans = transform(g, x, y, s, x_align, y_align, angle);
- g.setTransform(myTrans);
- Draw.drawString(g, s, 0, 0, useExternalFont);
- g.setTransform(tempTrans);*/
-
- AffineTransform tempTrans = g.getTransform();
- AffineTransform myTrans = (AffineTransform)tempTrans.clone();
- myTrans.translate(x, y);
- myTrans.rotate(-angle * Math.PI / 180);
- g.setTransform(myTrans);
- x = 0; y = 0;
- Dimension labSize = Draw.getStringDimension(s, g);
- switch (y_align) {
- case TOP:
- y += labSize.height;
- break;
- case CENTER:
- y += labSize.height / 2.0f;
- break;
- }
- switch (x_align) {
- case RIGHT:
- x = x - labSize.width;
- break;
- case CENTER:
- x = x - labSize.width / 2.0f;
- break;
- }
- Draw.drawString(g, s, x, y, useExternalFont);
- g.setTransform(tempTrans);
- }
- }
-
- /**
- * Draw out string
- *
- * @param g Graphics2D
- * @param x X location
- * @param y Y location
- * @param s String
- * @param x_align X align
- * @param y_align Y align
- * @param angle Angle
- * @param useExternalFont Use external font or not
- */
- public static void drawString(Graphics2D g, double x, double y, String s, XAlign x_align, YAlign y_align, float angle, boolean useExternalFont) {
- drawString(g, (float)x, (float)y, s, x_align, y_align, angle, useExternalFont);
- }
-
- /**
- * Graphics transform
- *
- * @param g Graphics2D
- * @param x X location
- * @param y Y location
- * @param s String
- * @param x_align X align
- * @param y_align Y align
- * @param angle Angle
- * @return AffineTransform
- */
- public static AffineTransform transform_bak(Graphics2D g, float x, float y, String s, XAlign x_align, YAlign y_align, float angle) {
- Dimension dim = getStringDimension(s, g);
- AffineTransform tempTrans = g.getTransform();
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- switch (x_align) {
- case CENTER:
- x -= (float)(dim.getWidth() * 0.5);
- break;
- case RIGHT:
- x -= (float)dim.getWidth();
- break;
- }
- switch (y_align) {
- case TOP:
- y += (float)dim.getHeight();
- break;
- case CENTER:
- y += (float)(dim.getHeight() * 0.5);
- break;
- }
- //myTrans.translate(tempTrans.getTranslateX() + x, tempTrans.getTranslateY() + y);
- myTrans.translate(x, y);
- myTrans.rotate(-angle * Math.PI / 180);
-
- return myTrans;
- }
-
- /**
- * Graphics transform
- *
- * @param g Graphics2D
- * @param x X location
- * @param y Y location
- * @param s String
- * @param x_align X align
- * @param y_align Y align
- * @param angle Angle
- * @return AffineTransform
- */
- public static AffineTransform transform(Graphics2D g, float x, float y, String s, XAlign x_align, YAlign y_align, float angle) {
- Dimension dim = getStringDimension(s, g);
- AffineTransform tempTrans = g.getTransform();
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- switch (x_align) {
- case LEFT:
- switch (y_align) {
- case CENTER:
- if (angle == 90) {
- x += (float) (dim.getHeight());
- y += (float) (dim.getWidth() * 0.5);
- } else if (angle == -90) {
- y -= (float) (dim.getWidth() * 0.5);
- } else if (angle > 0) {
- x += (float) (dim.getHeight() * Math.abs(Math.sin(Math.toRadians(angle))));
- y += (float) (dim.getHeight() * Math.cos(Math.toRadians(angle)) * 0.5);
- } else {
- y += (float) (dim.getHeight() * Math.cos(Math.toRadians(angle)) * 0.5);
- }
- break;
- }
- break;
- case CENTER:
- switch (y_align) {
- case TOP:
- if (angle == 90) {
- x += (float) (dim.getHeight() * 0.5);
- y += (float) (dim.getWidth());
- } else if (angle == -90) {
- x -= (float) (dim.getHeight() * 0.5);
- } else if (angle > 0) {
- //x -= (float) (dim.getWidth() * Math.abs(Math.cos(Math.toRadians(angle))));
- //y += (float) (dim.getWidth() * Math.sin(Math.toRadians(angle))) + dim.getHeight();
- x -= (float) (dim.getWidth() * Math.abs(Math.cos(Math.toRadians(angle))));
- y += (float) (dim.getWidth() * Math.sin(Math.toRadians(angle))) + dim.getHeight() * 0.5 * Math.cos(Math.toRadians(angle));
- } else {
- //y += (float) (dim.getHeight() * Math.cos(Math.toRadians(angle)) * 0.5);
- y += (float) (dim.getHeight() * Math.abs(Math.cos(Math.toRadians(angle))));
- }
- break;
- }
- break;
- case RIGHT:
- switch (y_align) {
- case CENTER:
- if (angle == 90) {
- x -= (float) (dim.getHeight());
- y += (float) (dim.getWidth() * 0.5);
- } else if (angle == -90) {
- x -= (float) (dim.getHeight());
- y -= (float) (dim.getWidth() * 0.5);
- } else if (angle > 0) {
- x -= (float) (dim.getWidth() * Math.abs(Math.cos(Math.toRadians(angle))));
- y += (float) (dim.getHeight() * Math.cos(Math.toRadians(angle)) * 0.5);
- } else {
- y += (float) (dim.getHeight() * Math.cos(Math.toRadians(angle)) * 0.5);
- }
- break;
- }
- break;
- }
- //myTrans.translate(tempTrans.getTranslateX() + x, tempTrans.getTranslateY() + y);
- myTrans.translate(x, y);
- myTrans.rotate(-angle * Math.PI / 180);
-
- return myTrans;
- }
-
- /**
- * Graphics transform
- *
- * @param g Graphics2D
- * @param x X location
- * @param y Y location
- * @param s String
- * @param x_align X align
- * @param y_align Y align
- * @param angle Angle
- * @return AffineTransform
- */
- public static AffineTransform transform(Graphics2D g, double x, double y, String s, XAlign x_align, YAlign y_align, float angle) {
- return transform(g, (float)x, (float)y, s, x_align, y_align, angle);
- }
-
- /**
- * Draw label point
- *
- * @param aPoint The screen point
- * @param aLB The label break
- * @param g Graphics2D
- * @param rect The extent rectangle
- */
- public static void drawLabelPoint(PointF aPoint, LabelBreak aLB, Graphics2D g, Rectangle rect) {
- g.setColor(aLB.getColor());
- g.setFont(aLB.getFont());
- Dimension labSize = Draw.getStringDimension(aLB.getText(), g);
- //FontMetrics metrics = g.getFontMetrics(aLB.getFont());
- //Dimension labSize = new Dimension(metrics.stringWidth(aLB.getText()), metrics.getHeight());
- switch (aLB.getAlignType()) {
- case Center:
- aPoint.X = aPoint.X - (float) labSize.getWidth() / 2;
- break;
- case Left:
- aPoint.X = aPoint.X - (float) labSize.getWidth();
- break;
- }
- aLB.setYShift((float) labSize.getHeight() / 2);
- aPoint.Y -= aLB.getYShift();
- aPoint.X += aLB.getXShift();
- float inx = aPoint.X;
- float iny = aPoint.Y;
-
- AffineTransform tempTrans = g.getTransform();
- if (aLB.getAngle() != 0) {
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- myTrans.translate(aPoint.X, aPoint.Y);
- myTrans.rotate(aLB.getAngle() * Math.PI / 180);
- g.setTransform(myTrans);
- aPoint.X = 0;
- aPoint.Y = 0;
- }
-
- //g.drawString(aLB.getText(), aPoint.X, aPoint.Y + metrics.getHeight() / 2);
- Draw.drawString(g, aLB.getText(), aPoint.X, aPoint.Y + labSize.height / 2);
-
- rect.x = (int) aPoint.X;
- rect.y = (int) aPoint.Y - labSize.height / 2;
- rect.width = (int) labSize.getWidth();
- rect.height = (int) labSize.getHeight();
-
- if (aLB.getAngle() != 0) {
- g.setTransform(tempTrans);
- rect.x = (int) inx;
- rect.y = (int) iny;
- }
- }
-
- /**
- * Draw label point
- *
- * @param x X
- * @param y Y
- * @param font Font
- * @param text Text
- * @param color Color
- * @param g Graphics2D
- * @param rect The extent rectangle
- * @param angle Angle
- */
- public static void drawLabelPoint(float x, float y, Font font, String text, Color color, float angle, Graphics2D g, Rectangle rect) {
- g.setColor(color);
- g.setFont(font);
- Dimension labSize = Draw.getStringDimension(text, g);
- //FontMetrics metrics = g.getFontMetrics(font);
- //Dimension labSize = new Dimension(metrics.stringWidth(text), metrics.getHeight());
- x = x - (float) labSize.getWidth() / 2;
- y -= (float) labSize.getHeight() / 2;
-
- float inx = x;
- float iny = y;
-
- AffineTransform tempTrans = g.getTransform();
- if (angle != 0) {
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- myTrans.translate(x, y);
- myTrans.rotate(angle * Math.PI / 180);
- g.setTransform(myTrans);
- x = 0;
- y = 0;
- }
-
- //g.drawString(text, x, y + metrics.getHeight() / 2);
- Draw.drawString(g, text, x, y + labSize.height / 2);
-
- if (rect != null) {
- rect.x = (int) x;
- rect.y = (int) y - labSize.height / 2;
- rect.width = (int) labSize.getWidth();
- rect.height = (int) labSize.getHeight();
- }
-
- if (angle != 0) {
- g.setTransform(tempTrans);
- if (rect != null) {
- rect.x = (int) inx;
- rect.y = (int) iny;
- }
- }
- }
-
- /**
- * Draw label point
- *
- * @param x X
- * @param y Y
- * @param font Font
- * @param text Text
- * @param color Color
- * @param g Graphics2D
- * @param rect The extent rectangle
- * @param angle Angle
- * @param useExternalFont If use external font
- */
- public static void drawLabelPoint(float x, float y, Font font, String text, Color color, float angle,
- Graphics2D g, Rectangle rect, boolean useExternalFont) {
- g.setColor(color);
- g.setFont(font);
- Dimension labSize = Draw.getStringDimension(text, g);
- //FontMetrics metrics = g.getFontMetrics(font);
- //Dimension labSize = new Dimension(metrics.stringWidth(text), metrics.getHeight());
- x = x - (float) labSize.getWidth() / 2;
- y -= (float) labSize.getHeight() / 2;
-
- float inx = x;
- float iny = y;
-
- AffineTransform tempTrans = g.getTransform();
- if (angle != 0) {
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- myTrans.translate(x, y);
- myTrans.rotate(angle * Math.PI / 180);
- g.setTransform(myTrans);
- x = 0;
- y = 0;
- }
-
- //g.drawString(text, x, y + metrics.getHeight() / 2);
- Draw.drawString(g, text, x, y + labSize.height / 2, useExternalFont);
-
- if (rect != null) {
- rect.x = (int) x;
- rect.y = (int) y - labSize.height / 2;
- rect.width = (int) labSize.getWidth();
- rect.height = (int) labSize.getHeight();
- }
-
- if (angle != 0) {
- g.setTransform(tempTrans);
- if (rect != null) {
- rect.x = (int) inx;
- rect.y = (int) iny;
- }
- }
- }
-
- /**
- * Draw label point
- *
- * @param x X
- * @param y Y
- * @param font Font
- * @param text Text
- * @param color Color
- * @param g Graphics2D
- * @param angle Angle
- */
- public static void drawTickLabel(float x, float y, Font font, String text, Color color, float angle, Graphics2D g) {
- g.setColor(color);
- g.setFont(font);
- Dimension labSize = Draw.getStringDimension(text, g);
- if (angle == 0) {
- x = x - (float) labSize.getWidth() / 2;
- y -= (float) labSize.getHeight() / 2;
- Draw.drawString(g, text, x, y + labSize.height / 2);
- } else {
- AffineTransform tempTrans = g.getTransform();
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- myTrans.translate(x, y);
- myTrans.translate(tempTrans.getTranslateX() + x, tempTrans.getTranslateY() + y);
- myTrans.rotate(-angle * Math.PI / 180);
- g.setTransform(myTrans);
- if (angle == 90) {
- x = -(float) (labSize.getWidth() - 10);
- y = (float) (labSize.getHeight() / 3);
- } else {
- x = -(float) (labSize.getWidth() - 5);
- y = 0;
- }
- Draw.drawString(g, text, x, y);
- g.setTransform(tempTrans);
- }
- }
-
- /**
- * Draw label point
- *
- * @param x X
- * @param y Y
- * @param font Font
- * @param text Text
- * @param color Color
- * @param g Graphics2D
- * @param angle Angle
- */
- public static void drawTickLabel_Y(float x, float y, Font font, String text, Color color, float angle, Graphics2D g) {
- g.setColor(color);
- g.setFont(font);
- Dimension labSize = Draw.getStringDimension(text, g);
- if (angle == 0) {
- //x = x - (float) labSize.getWidth() / 2;
- //y -= (float) labSize.getHeight() / 2;
- Draw.drawString(g, text, x, y);
- } else {
- AffineTransform tempTrans = g.getTransform();
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- myTrans.translate(x, y);
- myTrans.translate(tempTrans.getTranslateX() + x, tempTrans.getTranslateY() + y);
- myTrans.rotate(-angle * Math.PI / 180);
- g.setTransform(myTrans);
- if (angle == 90) {
- x = -(float) (labSize.getWidth() - 10);
- y = (float) (labSize.getHeight() / 3);
- } else {
- x = -(float) (labSize.getWidth() - 5);
- y = 0;
- }
- Draw.drawString(g, text, x, y);
- g.setTransform(tempTrans);
- }
- }
-
- /**
- * Draw label point
- *
- * @param x X
- * @param y Y
- * @param font Font
- * @param text Text
- * @param color Color
- * @param g Graphics2D
- * @param angle Angle
- */
- public static void drawTickLabel_YRight(float x, float y, Font font, String text, Color color, float angle, Graphics2D g) {
- g.setColor(color);
- g.setFont(font);
- Dimension labSize = Draw.getStringDimension(text, g);
- if (angle == 0) {
- y += (float) labSize.getHeight() * 0.5f;
- Draw.drawString(g, text, x, y);
- } else {
- AffineTransform tempTrans = g.getTransform();
- //AffineTransform myTrans = new AffineTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- if (angle == 90) {
- x += (float) (labSize.getHeight());
- y += (float) (labSize.getWidth() * 0.5);
- } else if (angle == -90) {
- y -= (float) (labSize.getWidth() * 0.5);
- } else if (angle > 0) {
- x += (float) (labSize.getHeight() * Math.abs(Math.sin(Math.toRadians(angle))));
- y += (float) (labSize.getHeight() * Math.cos(Math.toRadians(angle)) * 0.5);
- } else {
- y += (float) (labSize.getHeight() * Math.cos(Math.toRadians(angle)) * 0.5);
- }
- //myTrans.translate(tempTrans.getTranslateX() + x, tempTrans.getTranslateY() + y);
- myTrans.translate(x, y);
- myTrans.rotate(-angle * Math.PI / 180);
- g.setTransform(myTrans);
- Draw.drawString(g, text, 0, 0);
- g.setTransform(tempTrans);
- }
- }
-
-// /**
-// * Draw label point (270 degress)
-// *
-// * @param x X
-// * @param y Y
-// * @param font Font
-// * @param text Text
-// * @param color Color
-// * @param g Graphics2D
-// * @param rect The extent rectangle
-// */
-// public static void drawLabelPoint_270(float x, float y, Font font, String text, Color color, Graphics2D g, Rectangle rect) {
-// //FontMetrics metrics = g.getFontMetrics(font);
-// //Dimension labSize = new Dimension(metrics.stringWidth(text), metrics.getHeight());
-// g.setFont(font);
-// Dimension labSize = Draw.getStringDimension(text, g);
-//
-// float inx = x;
-// float iny = y;
-//
-// AffineTransform tempTrans = g.getTransform();
-// float angle = 270;
-// g.translate(x, y);
-// g.rotate(angle * Math.PI / 180);
-// x = 0;
-// y = 0;
-//
-// g.setColor(color);
-// //g.setFont(font);
-// if (Draw.isLaTeX(text)) {
-// //Draw.drawLaTeX(g, text, x - labSize.width / 2, y - labSize.height);
-// Draw.drawLaTeX(g, text, x - labSize.width / 2, y + labSize.height / 2, true);
-// } else {
-// g.drawString(text, x - labSize.width / 2, y + labSize.height * 3 / 4);
-// }
-//
-// if (rect != null) {
-// rect.x = (int) x;
-// rect.y = (int) y - labSize.height / 2;
-// rect.width = (int) labSize.getWidth();
-// rect.height = (int) labSize.getHeight();
-// }
-//
-// g.setTransform(tempTrans);
-// if (rect != null) {
-// rect.x = (int) inx;
-// rect.y = (int) iny;
-// }
-// }
-// /**
-// * Draw label point (270 degress)
-// *
-// * @param x X
-// * @param y Y
-// * @param font Font
-// * @param text Text
-// * @param color Color
-// * @param g Graphics2D
-// * @param rect The extent rectangle
-// * @param useExternalFont If use external font
-// */
-// public static void drawLabelPoint_270(float x, float y, Font font, String text, Color color,
-// Graphics2D g, Rectangle rect, boolean useExternalFont) {
-// //FontMetrics metrics = g.getFontMetrics(font);
-// //Dimension labSize = new Dimension(metrics.stringWidth(text), metrics.getHeight());
-// g.setFont(font);
-// Dimension labSize = Draw.getStringDimension(text, g);
-//
-// float inx = x;
-// float iny = y;
-//
-// AffineTransform tempTrans = g.getTransform();
-// float angle = 270;
-// g.translate(x, y);
-// g.rotate(angle * Math.PI / 180);
-// x = 0;
-// y = 0;
-//
-// g.setColor(color);
-// //g.setFont(font);
-// if (Draw.isLaTeX(text)) {
-// //Draw.drawLaTeX(g, text, x - labSize.width / 2, y - labSize.height);
-// Draw.drawLaTeX(g, text, x - labSize.width / 2, y + labSize.height / 2, useExternalFont);
-// } else {
-// g.drawString(text, x - labSize.width / 2, y + labSize.height * 3 / 4);
-// }
-//
-// if (rect != null) {
-// rect.x = (int) x;
-// rect.y = (int) y - labSize.height / 2;
-// rect.width = (int) labSize.getWidth();
-// rect.height = (int) labSize.getHeight();
-// }
-//
-// g.setTransform(tempTrans);
-// if (rect != null) {
-// rect.x = (int) inx;
-// rect.y = (int) iny;
-// }
-// }
- /**
- * Draw station model shape
- *
- * @param aColor Color
- * @param foreColor Foreground color
- * @param sP Start point
- * @param aSM Station model shape
- * @param g Graphics2D
- * @param size Size
- * @param cut Cut
- */
- public static void drawStationModel(Color aColor, Color foreColor, PointF sP, StationModelShape aSM, Graphics2D g,
- float size, float cut) {
- PointF sPoint = new PointF(0, 0);
- g.setColor(aColor);
- Font wFont;
- String text;
-
- //Draw cloud coverage
- if (aSM.cloudCoverage.cloudCover >= 0 && aSM.cloudCoverage.cloudCover <= 9) {
- //Draw wind barb
- drawWindBarb(aColor, sP, aSM.windBarb, g, size, cut);
- text = String.valueOf((char) (aSM.cloudCoverage.cloudCover + 197));
- wFont = new Font("Weather", Font.PLAIN, (int) size);
- FontMetrics metrics = g.getFontMetrics(wFont);
- Dimension textSize = new Dimension(metrics.stringWidth(text), metrics.getHeight());
- sPoint.X = sP.X - (float) textSize.getWidth() / 2;
- sPoint.Y = sP.Y - (float) textSize.getHeight() / 2;
- g.setFont(wFont);
- g.drawString(text, sPoint.X, sPoint.Y + metrics.getHeight() * 3 / 4);
- } else {
- //Draw wind barb
- drawWindBarb(aColor, sP, aSM.windBarb, g, size);
-
- wFont = new Font("Arial", Font.PLAIN, (int) (size / 4 * 3));
- text = "M";
- FontMetrics metrics = g.getFontMetrics(wFont);
- Dimension textSize = new Dimension(metrics.stringWidth(text), metrics.getHeight());
- sPoint.X = sP.X - (float) textSize.getWidth() / 2;
- sPoint.Y = sP.Y - (float) textSize.getHeight() / 3 * 2;
- g.setFont(wFont);
- g.drawString(text, sPoint.X, sPoint.Y + metrics.getHeight() * 3 / 4);
- wFont = new Font("Weather", Font.PLAIN, (int) size);
- text = String.valueOf((char) 197);
- metrics = g.getFontMetrics(wFont);
- textSize = new Dimension(metrics.stringWidth(text), metrics.getHeight());
- sPoint.X = sP.X - (float) textSize.getWidth() / 2;
- sPoint.Y = sP.Y - (float) textSize.getHeight() / 2;
- g.setFont(wFont);
- g.drawString(text, sPoint.X, sPoint.Y + metrics.getHeight() * 3 / 4);
- }
-
- //Draw weather
- if (aSM.weatherSymbol.weather >= 4 && aSM.weatherSymbol.weather <= 99) {
- wFont = new Font("Weather", Font.PLAIN, (int) size);
- text = String.valueOf((char) (aSM.weatherSymbol.weather + 100));
- FontMetrics metrics = g.getFontMetrics(wFont);
- Dimension textSize = new Dimension(metrics.stringWidth(text), metrics.getHeight());
- sPoint.X = sP.X - (float) textSize.getHeight() - aSM.size / 2;
- sPoint.Y = sP.Y - (float) textSize.getHeight() / 2;
- text = String.valueOf((char) (aSM.weatherSymbol.weather + 28));
- if (aSM.weatherSymbol.weather == 99) {
- text = String.valueOf((char) (aSM.weatherSymbol.weather + 97));
- }
- g.setFont(wFont);
- g.drawString(text, sPoint.X, sPoint.Y + metrics.getHeight() * 3 / 4);
- }
-
- wFont = new Font("Arial", Font.PLAIN, (int) (size / 4 * 3));
- g.setFont(wFont);
- FontMetrics metrics = g.getFontMetrics(wFont);
- //Draw temperature
- if (Math.abs(aSM.temperature) < 1000) {
- g.setColor(Color.red);
- text = String.valueOf(aSM.temperature);
- Dimension textSize = new Dimension(metrics.stringWidth(text), metrics.getHeight());
- sPoint.X = sP.X - (float) textSize.getWidth() - size / 3;
- sPoint.Y = sP.Y - (float) textSize.getHeight() - size / 3;
- g.drawString(text, sPoint.X, sPoint.Y + metrics.getHeight() * 3 / 4);
- }
-
- //Draw dew point
- if (Math.abs(aSM.dewPoint) < 1000) {
- g.setColor(Color.green);
- text = String.valueOf(aSM.dewPoint);
- Dimension textSize = new Dimension(metrics.stringWidth(text), metrics.getHeight());
- sPoint.X = sP.X - (float) textSize.getWidth() - size / 3;
- sPoint.Y = sP.Y + size / 3;
- g.drawString(text, sPoint.X, sPoint.Y + metrics.getHeight() * 3 / 4);
- }
-
- //Draw pressure
- if (Math.abs(aSM.pressure) < 1000) {
- g.setColor(foreColor);
- text = String.format("%1$03d", aSM.pressure);
- sPoint.X = sP.X + size / 3;
- sPoint.Y = sP.Y - metrics.getHeight() - size / 3;
- g.drawString(text, sPoint.X, sPoint.Y + metrics.getHeight() * 3 / 4);
- }
- }
-
- //
- //
- /**
- * Draw graphic
- *
- * @param points The points
- * @param aGraphic The graphic
- * @param g Graphics2D
- * @param isEditingVertice Is editing vertice
- */
- public static void drawGrahpic(PointF[] points, Graphic aGraphic, Graphics2D g, boolean isEditingVertice) {
- Rectangle rect = new Rectangle();
- Extent aExtent = MIMath.getPointFsExtent(points);
- rect.x = (int) aExtent.minX;
- rect.y = (int) aExtent.minY;
- rect.width = (int) aExtent.getWidth();
- rect.height = (int) aExtent.getHeight();
-
- switch (aGraphic.getShape().getShapeType()) {
- case Point:
- switch (aGraphic.getLegend().getBreakType()) {
- case PointBreak:
- drawPoint((PointF) points[0].clone(), (PointBreak) aGraphic.getLegend(), g);
- int aSize = (int) ((PointBreak) aGraphic.getLegend()).getSize() / 2 + 2;
- rect.x = (int) points[0].X - aSize;
- rect.y = (int) points[0].Y - aSize;
- rect.width = aSize * 2;
- rect.height = aSize * 2;
- break;
- case LabelBreak:
- drawLabelPoint((PointF) points[0].clone(), (LabelBreak) aGraphic.getLegend(), g, rect);
- break;
- }
- break;
- case Polyline:
- if (aGraphic.getLegend().getBreakType() == BreakTypes.ColorBreakCollection) {
- drawPolyline(points, (ColorBreakCollection) aGraphic.getLegend(), g);
- } else {
- drawPolyline(points, (PolylineBreak) aGraphic.getLegend(), g);
- }
- break;
- case Polygon:
- PolygonShape pgs = (PolygonShape) aGraphic.getShape().clone();
- pgs.setPoints_keep(points);
- drawPolygonShape(pgs, (PolygonBreak) aGraphic.getLegend(), g);
- break;
- case Rectangle:
- drawPolygon(points, (PolygonBreak) aGraphic.getLegend(), g);
- break;
- case CurveLine:
- drawCurveLine(points, (PolylineBreak) aGraphic.getLegend(), g);
- break;
- case CurvePolygon:
- drawCurvePolygon(points, (PolygonBreak) aGraphic.getLegend(), g);
- break;
- case Circle:
- drawCircle(points, (PolygonBreak) aGraphic.getLegend(), g);
- break;
- case Ellipse:
- EllipseShape eshape = (EllipseShape) aGraphic.getShape();
- drawEllipse(points, eshape.getAngle(), (PolygonBreak) aGraphic.getLegend(), g);
- break;
- }
-
- //Draw selected rectangle
- if (aGraphic.getShape().isSelected()) {
- if (isEditingVertice) {
- drawSelectedVertices(g, points);
- } else {
- float[] dashPattern = new float[]{2.0F, 1.0F};
- g.setColor(Color.cyan);
- g.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f));
- g.draw(rect);
- switch (aGraphic.getShape().getShapeType()) {
- case Point:
- if (aGraphic.getLegend().getBreakType() == BreakTypes.PointBreak) {
- drawSelectedCorners(g, rect);
- }
- break;
- case Polyline:
- case CurveLine:
- case Polygon:
- case Rectangle:
- case Ellipse:
- case CurvePolygon:
- drawSelectedCorners(g, rect);
- drawSelectedEdgeCenters(g, rect);
- break;
- case Circle:
- drawSelectedCorners(g, rect);
- break;
- }
- }
- }
- }
-
- /**
- * Draw polyline
- *
- * @param points Points list
- * @param g Graphics2D
- */
- public static void drawPolyline(List points, Graphics2D g) {
- GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, points.size());
- for (int i = 0; i < points.size(); i++) {
- if (i == 0) {
- path.moveTo(points.get(i).X, points.get(i).Y);
- } else {
- path.lineTo(points.get(i).X, points.get(i).Y);
- }
- }
-
- g.draw(path);
- }
-
- /**
- * Draw polyline
- *
- * @param points The points array
- * @param g Graphics2D
- */
- public static void drawPolyline(PointF[] points, Graphics2D g) {
- GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, points.length);
- for (int i = 0; i < points.length; i++) {
- if (i == 0) {
- path.moveTo(points[i].X, points[i].Y);
- } else {
- path.lineTo(points[i].X, points[i].Y);
- }
- }
-
- g.draw(path);
- }
-
- /**
- * Draw polyline
- *
- * @param points The points array
- * @param g Graphics2D
- */
- public static void drawPolyline(PointD[] points, Graphics2D g) {
- GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, points.length);
- for (int i = 0; i < points.length; i++) {
- if (i == 0) {
- path.moveTo(points[i].X, points[i].Y);
- } else {
- path.lineTo(points[i].X, points[i].Y);
- }
- }
-
- g.draw(path);
- }
-
- /**
- * Draw polyline
- *
- * @param points The points array
- * @param g Graphics2D
- * @param mvIdx Missing value index list
- */
- public static void drawPolyline(PointF[] points, Graphics2D g, List mvIdx) {
- GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, points.length - mvIdx.size());
- boolean isNew = true;
- for (int i = 0; i < points.length; i++) {
- if (mvIdx.contains(i)) {
- isNew = true;
- continue;
- }
- if (isNew) {
- path.moveTo(points[i].X, points[i].Y);
- isNew = false;
- } else {
- path.lineTo(points[i].X, points[i].Y);
- }
- }
-
- g.draw(path);
- }
-
- /**
- * Fill polygon
- *
- * @param points The points array
- * @param g Graphics2D
- * @param aPGB Polygon break
- */
- public static void fillPolygon(PointF[] points, Graphics2D g, PolygonBreak aPGB) {
- GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, points.length);
- for (int i = 0; i < points.length; i++) {
- if (i == 0) {
- path.moveTo(points[i].X, points[i].Y);
- } else {
- path.lineTo(points[i].X, points[i].Y);
- }
- }
- path.closePath();
-
- if (aPGB != null) {
- if (aPGB.isUsingHatchStyle()) {
- int size = aPGB.getStyleSize();
- BufferedImage bi = getHatchImage(aPGB.getStyle(), size, aPGB.getColor(), aPGB.getBackColor());
- Rectangle2D rect = new Rectangle2D.Double(0, 0, size, size);
- g.setPaint(new TexturePaint(bi, rect));
- g.fill(path);
- } else {
- g.fill(path);
- }
- } else {
- g.fill(path);
- }
- }
-
- /**
- * Fill polygon
- *
- * @param points The points array
- * @param g Graphics2D
- * @param aPGB Polygon break
- */
- public static void fillPolygon(PointD[] points, Graphics2D g, PolygonBreak aPGB) {
- GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, points.length);
- for (int i = 0; i < points.length; i++) {
- if (i == 0) {
- path.moveTo(points[i].X, points[i].Y);
- } else {
- path.lineTo(points[i].X, points[i].Y);
- }
- }
- path.closePath();
-
- if (aPGB != null) {
- if (aPGB.isUsingHatchStyle()) {
- int size = aPGB.getStyleSize();
- BufferedImage bi = getHatchImage(aPGB.getStyle(), size, aPGB.getColor(), aPGB.getBackColor());
- Rectangle2D rect = new Rectangle2D.Double(0, 0, size, size);
- g.setPaint(new TexturePaint(bi, rect));
- g.fill(path);
- } else {
- g.fill(path);
- }
- } else {
- g.fill(path);
- }
- }
-
- /**
- * Draw polygon shape with screen coordinates
- *
- * @param pgs Polygon shape
- * @param pgb Polygon break
- * @param g Graphics2D
- */
- public static void drawPolygonShape(PolygonShape pgs, PolygonBreak pgb, Graphics2D g) {
- for (Polygon polygon : pgs.getPolygons()) {
- drawPolygon(polygon, pgb, g);
- }
- }
-
- /**
- * Draw polygon with screen coordinate
- *
- * @param aPG Polygon shape
- * @param aPGB Polygon break
- * @param g Graphics2D
- */
- public static void drawPolygon(Polygon aPG, PolygonBreak aPGB, Graphics2D g) {
- int len = aPG.getOutLine().size();
- GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, len);
- path.moveTo(0, 0);
- PointD wPoint;
- for (int i = 0; i < aPG.getOutLine().size(); i++) {
- wPoint = aPG.getOutLine().get(i);
- if (i == 0) {
- path.moveTo(wPoint.X, wPoint.Y);
- } else {
- path.lineTo(wPoint.X, wPoint.Y);
- }
- }
-
- List newPList;
- if (aPG.hasHole()) {
- for (int h = 0; h < aPG.getHoleLines().size(); h++) {
- newPList = (List) aPG.getHoleLines().get(h);
- for (int j = 0; j < newPList.size(); j++) {
- wPoint = newPList.get(j);
- if (j == 0) {
- path.moveTo(wPoint.X, wPoint.Y);
- } else {
- path.lineTo(wPoint.X, wPoint.Y);
- }
- }
- }
- }
- path.closePath();
-
- if (aPGB.isDrawFill()) {
- //int alpha = (int)((1 - (double)transparencyPerc / 100.0) * 255);
- //Color aColor = Color.FromArgb(alpha, aPGB.Color);
- Color aColor = aPGB.getColor();
- if (aPGB.isUsingHatchStyle()) {
- int size = aPGB.getStyleSize();
- BufferedImage bi = getHatchImage(aPGB.getStyle(), size, aPGB.getColor(), aPGB.getBackColor());
- Rectangle2D rect = new Rectangle2D.Double(0, 0, size, size);
- g.setPaint(new TexturePaint(bi, rect));
- g.fill(path);
- } else {
- g.setColor(aColor);
- g.fill(path);
- }
- }
-
- if (aPGB.isDrawOutline()) {
- BasicStroke pen = new BasicStroke(aPGB.getOutlineSize());
- g.setStroke(pen);
- g.setColor(aPGB.getOutlineColor());
- g.draw(path);
- }
- }
-
- /**
- * Draw polygon
- *
- * @param points The points
- * @param aPGB The polygon break
- * @param g Graphics2D
- */
- public static void drawPolygon(PointF[] points, PolygonBreak aPGB, Graphics2D g) {
- if (aPGB.isDrawFill()) {
- g.setColor(aPGB.getColor());
- fillPolygon(points, g, aPGB);
- }
- if (aPGB.isDrawOutline()) {
- g.setColor(aPGB.getOutlineColor());
- g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
- drawPolyline(points, g);
- }
- }
-
- /**
- * Draw polygon
- *
- * @param points The points
- * @param aPGB The polygon break
- * @param g Graphics2D
- */
- public static void drawPolygon(PointD[] points, PolygonBreak aPGB, Graphics2D g) {
- if (aPGB.isDrawFill()) {
- g.setColor(aPGB.getColor());
- fillPolygon(points, g, aPGB);
- }
- if (aPGB.isDrawOutline()) {
- g.setColor(aPGB.getOutlineColor());
- g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
- drawPolyline(points, g);
- }
- }
-
- /**
- * Draw polygon
- *
- * @param points The points
- * @param aColor Fill oclor
- * @param outlineColor Outline color
- * @param drawFill
- * @param drawOutline
- * @param g
- */
- public static void drawPolygon(PointF[] points, Color aColor, Color outlineColor,
- boolean drawFill, boolean drawOutline, Graphics2D g) {
- if (drawFill) {
- g.setColor(aColor);
- fillPolygon(points, g, null);
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- drawPolyline(points, g);
- }
- }
-
- /**
- * Draw polygon
- *
- * @param points The points
- * @param aColor Fill oclor
- * @param outlineColor Outline color
- * @param drawFill
- * @param drawOutline
- * @param g
- */
- public static void drawPolygon(PointD[] points, Color aColor, Color outlineColor,
- boolean drawFill, boolean drawOutline, Graphics2D g) {
- if (drawFill) {
- g.setColor(aColor);
- fillPolygon(points, g, null);
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- drawPolyline(points, g);
- }
- }
-
- /**
- * Get hatch style image
- *
- * @param style Hatch style
- * @param size
- * @param stripeColor Stripe color
- * @param backColor Background color
- * @return Hatch style image
- */
- public static BufferedImage getHatchImage(HatchStyle style, int size, Color stripeColor, Color backColor) {
- BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g2 = bi.createGraphics();
- int alpha = backColor.getAlpha();
- if (alpha > 0) {
- g2.setColor(backColor);
- g2.fillRect(0, 0, size, size);
- }
- g2.setColor(stripeColor);
- switch (style) {
- case HORIZONTAL:
- g2.drawLine(0, size / 2, size, size / 2);
- break;
- case VERTICAL:
- g2.drawLine(size / 2, 0, size / 2, size);
- break;
- case FORWARD_DIAGONAL:
- g2.drawLine(0, 0, size, size);
- break;
- case BACKWARD_DIAGONAL:
- //g2.drawLine(size, 0, 0, size);
- g2.draw(new Line2D.Float(0, size, size, 0));
- break;
- case CROSS:
- g2.drawLine(0, size / 2, size, size / 2);
- g2.drawLine(size / 2, 0, size / 2, size);
- break;
- case DIAGONAL_CROSS:
- g2.drawLine(0, 0, size, size);
- g2.drawLine(0, size, size, 0);
- break;
- case DOT:
- g2.fill(new Ellipse2D.Float(size / 2, size / 2, 2, 2));
- break;
- }
- return bi;
- }
-
- /**
- * Get dash pattern from LineStyle
- *
- * @param style The line style
- * @return Dash pattern array
- */
- public static float[] getDashPattern(LineStyles style) {
- float[] dashPattern = {4.0f};
- switch (style) {
- case SOLID:
- dashPattern = null;
- break;
- case DASH:
- dashPattern = new float[]{4.0f};
- break;
- case DOT:
- dashPattern = new float[]{2.0f};
- break;
- case DASHDOT:
- dashPattern = new float[]{10, 6, 2, 6};
- break;
- case DASHDOTDOT:
- dashPattern = new float[]{10, 6, 2, 6, 2, 6};
- break;
- }
-
- return dashPattern;
- }
-
- /**
- * Draw arrow polyline
- *
- * @param points The points
- * @param alb The arrow line break
- * @param g Graphics2D
- */
- public static void drawArrowLine(PointF[] points, ArrowLineBreak alb, Graphics2D g) {
- int n = points.length;
- PointF aPoint = points[n - 2];
- PointF bPoint = points[n - 1];
- double U = bPoint.X - aPoint.X;
- double V = bPoint.Y - aPoint.Y;
- double radian = Math.atan(V / U);
- double angle = radian * 180 / Math.PI;
- angle = angle + 90;
- if (U < 0) {
- angle = angle + 180;
- }
- if (angle >= 360) {
- angle = angle - 360;
- }
- double dx = alb.getArrowHeadLength() * Math.cos(radian) * (1 - alb.getArrowOverhang());
- double dy = alb.getArrowHeadLength() * Math.sin(radian) * (1 - alb.getArrowOverhang());
- if (angle > 180) {
- dx = -dx;
- dy = -dy;
- }
- points[n - 1] = new PointF(bPoint.X - (float) dx, bPoint.Y - (float) dy);
-
- g.setColor(alb.getColor());
- float[] dashPattern = getDashPattern(alb.getStyle());
- g.setStroke(new BasicStroke(alb.getWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f));
- drawPolyline(points, g);
-
- //Draw symbol
- if (alb.getDrawSymbol()) {
- Object rend = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- Rectangle clip = g.getClipBounds();
- PointF p;
- if (clip != null) {
- g.setClip(null);
- for (int i = 0; i < points.length; i++) {
- p = new PointF(points[i].X, points[i].Y);
- if (p.X >= clip.x && p.X <= clip.x + clip.width && p.Y >= clip.y && p.Y <= clip.y + clip.height) {
- if (i % alb.getSymbolInterval() == 0) {
- drawPoint(alb.getSymbolStyle(), p, alb.getSymbolFillColor(), alb.getSymbolColor(),
- alb.getSymbolSize(), true, alb.isFillSymbol(), g);
- }
- }
- }
- g.setClip(clip);
- } else {
- for (int i = 0; i < points.length; i++) {
- if (i % alb.getSymbolInterval() == 0) {
- p = new PointF(points[i].X, points[i].Y);
- drawPoint(alb.getSymbolStyle(), p, alb.getSymbolFillColor(), alb.getSymbolColor(),
- alb.getSymbolSize(), true, alb.isFillSymbol(), g);
- }
- }
- }
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, rend);
- }
-
- //Draw arrow
- Draw.drawArraw(g, bPoint, angle, alb.getArrowHeadLength(), alb.getArrowHeadWidth(),
- alb.getArrowOverhang(), alb.getArrowFillColor(), alb.getArrowOutlineColor());
- }
-
- /**
- * Draw streamline
- *
- * @param points The points
- * @param alb The streamline break
- * @param g Graphics2D
- */
- public static void drawStreamline(PointF[] points, StreamlineBreak alb, Graphics2D g) {
- g.setColor(alb.getColor());
- float[] dashPattern = getDashPattern(alb.getStyle());
- g.setStroke(new BasicStroke(alb.getWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f));
- drawPolyline(points, g);
-
- PointF p1, p2;
- double u, v, radian, angle;
- int interval = alb.getInterval() * 3;
- for (int i = 0; i < points.length; i++) {
- if (i > 0 && i < points.length - 2 && i % interval == 0) {
- //Draw arraw
- p1 = points[i];
- p2 = points[i + 1];
- u = p2.X - p1.X;
- v = p2.Y - p1.Y;
- radian = Math.atan(v / u);
- angle = radian * 180 / Math.PI;
- angle = angle + 90;
- if (u < 0) {
- angle = angle + 180;
- }
- if (angle >= 360) {
- angle = angle - 360;
- }
-
- //Draw arrow
- Draw.drawArraw(g, p1, angle, alb.getArrowHeadLength(), alb.getArrowHeadWidth(),
- alb.getArrowOverhang(), alb.getArrowFillColor(), alb.getArrowOutlineColor());
- }
- }
-
- //Draw symbol
- if (alb.getDrawSymbol()) {
- Object rend = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- Rectangle clip = g.getClipBounds();
- PointF p;
- if (clip != null) {
- g.setClip(null);
- for (int i = 0; i < points.length; i++) {
- p = new PointF(points[i].X, points[i].Y);
- if (p.X >= clip.x && p.X <= clip.x + clip.width && p.Y >= clip.y && p.Y <= clip.y + clip.height) {
- if (i % alb.getSymbolInterval() == 0) {
- drawPoint(alb.getSymbolStyle(), p, alb.getSymbolFillColor(), alb.getSymbolColor(),
- alb.getSymbolSize(), true, alb.isFillSymbol(), g);
- }
- }
- }
- g.setClip(clip);
- } else {
- for (int i = 0; i < points.length; i++) {
- if (i % alb.getSymbolInterval() == 0) {
- p = new PointF(points[i].X, points[i].Y);
- drawPoint(alb.getSymbolStyle(), p, alb.getSymbolFillColor(), alb.getSymbolColor(),
- alb.getSymbolSize(), true, alb.isFillSymbol(), g);
- }
- }
- }
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, rend);
- }
- }
-
- /**
- * Draw polyline
- *
- * @param points The points
- * @param aPLB The polyline break
- * @param g Graphics2D
- */
- public static void drawPolyline(PointF[] points, PolylineBreak aPLB, Graphics2D g) {
- if (aPLB instanceof StreamlineBreak) {
- drawStreamline(points, (StreamlineBreak) aPLB, g);
- } else if (aPLB instanceof ArrowLineBreak) {
- drawArrowLine(points, (ArrowLineBreak) aPLB, g);
- } else {
- if (aPLB.isUsingDashStyle()) {
- g.setColor(aPLB.getColor());
- float[] dashPattern = getDashPattern(aPLB.getStyle());
- g.setStroke(new BasicStroke(aPLB.getWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f));
- drawPolyline(points, g);
-
- //Draw symbol
- if (aPLB.getDrawSymbol()) {
- Object rend = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- Rectangle clip = g.getClipBounds();
- PointF p;
- if (clip != null) {
- g.setClip(null);
- for (int i = 0; i < points.length; i++) {
- p = new PointF(points[i].X, points[i].Y);
- if (p.X >= clip.x && p.X <= clip.x + clip.width && p.Y >= clip.y && p.Y <= clip.y + clip.height) {
- if (i % aPLB.getSymbolInterval() == 0) {
- drawPoint(aPLB.getSymbolStyle(), p, aPLB.getSymbolFillColor(), aPLB.getSymbolColor(),
- aPLB.getSymbolSize(), true, aPLB.isFillSymbol(), g);
- }
- }
- }
- g.setClip(clip);
- } else {
- for (int i = 0; i < points.length; i++) {
- if (i % aPLB.getSymbolInterval() == 0) {
- p = new PointF(points[i].X, points[i].Y);
- drawPoint(aPLB.getSymbolStyle(), p, aPLB.getSymbolFillColor(), aPLB.getSymbolColor(),
- aPLB.getSymbolSize(), true, aPLB.isFillSymbol(), g);
- }
- }
- }
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, rend);
- }
- } else {
- Polyline aPLine = new Polyline();
- aPLine.setPoints(points);
- List pos = aPLine.getPositions(30);
- float aSize = 16;
- int i;
- switch (aPLB.getStyle()) {
- case COLDFRONT:
- if (pos != null) {
- PointBreak aPB = new PointBreak();
- aPB.setSize(aSize);
- aPB.setColor(Color.blue);
- aPB.setStyle(PointStyle.UpTriangle);
- aPB.setOutlineColor(Color.blue);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- for (i = 0; i < pos.size(); i++) {
- aPB.setAngle((float) pos.get(i)[2]);
- drawPoint_Simple_Up(new PointF((float) pos.get(i)[0], (float) pos.get(i)[1]), aPB, g);
- }
- }
-
- g.setColor(Color.blue);
- g.setStroke(new BasicStroke(aPLB.getWidth()));
- drawPolyline(points, g);
- break;
- case WARMFRONT:
- if (pos != null) {
- PointBreak aPB = new PointBreak();
- aPB.setSize(aSize);
- aPB.setColor(Color.red);
- aPB.setStyle(PointStyle.UpSemiCircle);
- aPB.setOutlineColor(Color.red);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- for (i = 0; i < pos.size(); i++) {
- aPB.setAngle((float) pos.get(i)[2]);
- drawPoint_Simple(new PointF((float) pos.get(i)[0], (float) pos.get(i)[1]), aPB, g);
- }
- }
-
- g.setColor(Color.red);
- g.setStroke(new BasicStroke(aPLB.getWidth()));
- drawPolyline(points, g);
- break;
- case OCCLUDEDFRONT:
- Color aColor = new Color(255, 0, 255);
- if (pos != null) {
- PointBreak aPB = new PointBreak();
- aPB.setSize(aSize);
- aPB.setColor(aColor);
- aPB.setStyle(PointStyle.UpTriangle);
- aPB.setOutlineColor(aColor);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- for (i = 0; i < pos.size(); i += 2) {
- aPB.setAngle((float) pos.get(i)[2]);
- drawPoint_Simple_Up(new PointF((float) pos.get(i)[0], (float) pos.get(i)[1]), aPB, g);
- }
-
- aPB = new PointBreak();
- aPB.setSize(aSize);
- aPB.setColor(aColor);
- aPB.setStyle(PointStyle.UpSemiCircle);
- aPB.setOutlineColor(aColor);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- for (i = 1; i < pos.size(); i += 2) {
- aPB.setAngle((float) pos.get(i)[2]);
- drawPoint_Simple(new PointF((float) pos.get(i)[0], (float) pos.get(i)[1]), aPB, g);
- }
- }
-
- g.setColor(aColor);
- g.setStroke(new BasicStroke(aPLB.getWidth()));
- drawPolyline(points, g);
- break;
- case STATIONARYFRONT:
- if (pos != null) {
- PointBreak aPB = new PointBreak();
- aPB.setSize(aSize);
- aPB.setColor(Color.blue);
- aPB.setStyle(PointStyle.UpTriangle);
- aPB.setOutlineColor(Color.blue);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- for (i = 0; i < pos.size(); i += 2) {
- aPB.setAngle((float) pos.get(i)[2]);
- drawPoint_Simple_Up(new PointF((float) pos.get(i)[0], (float) pos.get(i)[1]), aPB, g);
- }
-
- aPB = new PointBreak();
- aPB.setSize(aSize);
- aPB.setColor(Color.red);
- aPB.setStyle(PointStyle.DownSemiCircle);
- aPB.setOutlineColor(Color.red);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- for (i = 1; i < pos.size(); i += 2) {
- aPB.setAngle((float) pos.get(i)[2]);
- drawPoint_Simple(new PointF((float) pos.get(i)[0], (float) pos.get(i)[1]), aPB, g);
- }
- }
-
- g.setColor(Color.blue);
- g.setStroke(new BasicStroke(aPLB.getWidth()));
- drawPolyline(points, g);
- break;
- case ARROWLINE:
- g.setColor(aPLB.getColor());
- g.setStroke(new BasicStroke(aPLB.getWidth()));
- //float[] dashPattern = getDashPattern(aPLB.getStyle());
- //g.setStroke(new BasicStroke(aPLB.getSize(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f));
- drawPolyline(points, g);
-
- int n = points.length;
- PointF aPoint = points[n - 2];
- PointF bPoint = points[n - 1];
- double U = bPoint.X - aPoint.X;
- double V = bPoint.Y - aPoint.Y;
- double angle = Math.atan((V) / (U)) * 180 / Math.PI;
- angle = angle + 90;
- if (U < 0) {
- angle = angle + 180;
- }
-
- if (angle >= 360) {
- angle = angle - 360;
- }
-
- Draw.drawArraw(g, bPoint, angle, 8);
- break;
- }
- }
- }
- }
-
- /**
- * Draw polyline
- *
- * @param points The points
- * @param pbc The polyline break collection
- * @param g Graphics2D
- */
- public static void drawPolyline(PointF[] points, ColorBreakCollection pbc, Graphics2D g) {
- GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, points.length);
- PointF p;
- PolylineBreak aPLB;
- List drawPs = new ArrayList<>();
- for (int i = 0; i < points.length; i++) {
- p = points[i];
- if (i == 0) {
- path.moveTo(p.X, p.Y);
- } else {
- path.lineTo(p.X, p.Y);
-
- aPLB = (PolylineBreak) pbc.get(i);
- Color aColor = aPLB.getColor();
- Float size = aPLB.getWidth();
- float[] dashPattern = getDashPattern(aPLB.getStyle());
- BasicStroke pen = new BasicStroke(size, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f);
- g.setColor(aColor);
- g.setStroke(pen);
- g.draw(path);
- path.reset();
- path.moveTo(p.X, p.Y);
- //Draw symbol
- if (aPLB.getDrawSymbol()) {
- Object rend = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- for (int j = 0; j < drawPs.size(); j++) {
- Draw.drawPoint(aPLB.getSymbolStyle(), p, aPLB.getSymbolFillColor(), aPLB.getSymbolColor(),
- aPLB.getSymbolSize(), true, aPLB.isFillSymbol(), g);
- }
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, rend);
- }
- }
- drawPs.add(p);
- }
- }
-
- /**
- * Draw polyline
- *
- * @param points The points
- * @param aPLB The polyline break
- * @param g Graphics2D
- * @param mvIdx Missing value index list
- */
- public static void drawPolyline(PointF[] points, PolylineBreak aPLB, Graphics2D g, List mvIdx) {
- if (aPLB.isUsingDashStyle()) {
- g.setColor(aPLB.getColor());
- float[] dashPattern = getDashPattern(aPLB.getStyle());
- g.setStroke(new BasicStroke(aPLB.getWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f));
- if (mvIdx.size() > 0) {
- drawPolyline(points, g, mvIdx);
- } else {
- drawPolyline(points, g);
- }
-
- //Draw symbol
- if (aPLB.getDrawSymbol()) {
- Object rend = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-
- Rectangle clip = g.getClipBounds();
- PointF p;
- if (clip != null) {
- g.setClip(null);
- for (int i = 0; i < points.length; i++) {
- p = new PointF(points[i].X, points[i].Y);
- if (p.X >= clip.x && p.X <= clip.x + clip.width && p.Y >= clip.y && p.Y <= clip.y + clip.height) {
- if (mvIdx.contains(i)) {
- continue;
- }
- if (i % aPLB.getSymbolInterval() == 0) {
- drawPoint(aPLB.getSymbolStyle(), p, aPLB.getSymbolFillColor(), aPLB.getSymbolColor(),
- aPLB.getSymbolSize(), true, aPLB.isFillSymbol(), g);
- }
- }
- }
- g.setClip(clip);
- } else {
- for (int i = 0; i < points.length; i++) {
- if (mvIdx.contains(i)) {
- continue;
- }
-
- if (i % aPLB.getSymbolInterval() == 0) {
- p = new PointF(points[i].X, points[i].Y);
- drawPoint(aPLB.getSymbolStyle(), p, aPLB.getSymbolFillColor(), aPLB.getSymbolColor(),
- aPLB.getSymbolSize(), true, aPLB.isFillSymbol(), g);
- }
- }
- }
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, rend);
- }
- } else {
- Polyline aPLine = new Polyline();
- aPLine.setPoints(points);
- List pos = aPLine.getPositions(30);
- float aSize = 16;
- int i;
- switch (aPLB.getStyle()) {
- case COLDFRONT:
- if (pos != null) {
- PointBreak aPB = new PointBreak();
- aPB.setSize(aSize);
- aPB.setColor(Color.blue);
- aPB.setStyle(PointStyle.UpTriangle);
- aPB.setOutlineColor(Color.blue);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- for (i = 0; i < pos.size(); i++) {
- aPB.setAngle((float) pos.get(i)[2]);
- drawPoint_Simple_Up(new PointF((float) pos.get(i)[0], (float) pos.get(i)[1]), aPB, g);
- }
- }
-
- g.setColor(Color.blue);
- g.setStroke(new BasicStroke(aPLB.getWidth()));
- drawPolyline(points, g);
- break;
- case WARMFRONT:
- if (pos != null) {
- PointBreak aPB = new PointBreak();
- aPB.setSize(aSize);
- aPB.setColor(Color.red);
- aPB.setStyle(PointStyle.UpSemiCircle);
- aPB.setOutlineColor(Color.red);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- for (i = 0; i < pos.size(); i++) {
- aPB.setAngle((float) pos.get(i)[2]);
- drawPoint_Simple(new PointF((float) pos.get(i)[0], (float) pos.get(i)[1]), aPB, g);
- }
- }
-
- g.setColor(Color.red);
- g.setStroke(new BasicStroke(aPLB.getWidth()));
- drawPolyline(points, g);
- break;
- case OCCLUDEDFRONT:
- Color aColor = new Color(255, 0, 255);
- if (pos != null) {
- PointBreak aPB = new PointBreak();
- aPB.setSize(aSize);
- aPB.setColor(aColor);
- aPB.setStyle(PointStyle.UpTriangle);
- aPB.setOutlineColor(aColor);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- for (i = 0; i < pos.size(); i += 2) {
- aPB.setAngle((float) pos.get(i)[2]);
- drawPoint_Simple_Up(new PointF((float) pos.get(i)[0], (float) pos.get(i)[1]), aPB, g);
- }
-
- aPB = new PointBreak();
- aPB.setSize(aSize);
- aPB.setColor(aColor);
- aPB.setStyle(PointStyle.UpSemiCircle);
- aPB.setOutlineColor(aColor);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- for (i = 1; i < pos.size(); i += 2) {
- aPB.setAngle((float) pos.get(i)[2]);
- drawPoint_Simple(new PointF((float) pos.get(i)[0], (float) pos.get(i)[1]), aPB, g);
- }
- }
-
- g.setColor(aColor);
- g.setStroke(new BasicStroke(aPLB.getWidth()));
- drawPolyline(points, g);
- break;
- case STATIONARYFRONT:
- if (pos != null) {
- PointBreak aPB = new PointBreak();
- aPB.setSize(aSize);
- aPB.setColor(Color.blue);
- aPB.setStyle(PointStyle.UpTriangle);
- aPB.setOutlineColor(Color.blue);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- for (i = 0; i < pos.size(); i += 2) {
- aPB.setAngle((float) pos.get(i)[2]);
- drawPoint_Simple_Up(new PointF((float) pos.get(i)[0], (float) pos.get(i)[1]), aPB, g);
- }
-
- aPB = new PointBreak();
- aPB.setSize(aSize);
- aPB.setColor(Color.red);
- aPB.setStyle(PointStyle.DownSemiCircle);
- aPB.setOutlineColor(Color.red);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- for (i = 1; i < pos.size(); i += 2) {
- aPB.setAngle((float) pos.get(i)[2]);
- drawPoint_Simple(new PointF((float) pos.get(i)[0], (float) pos.get(i)[1]), aPB, g);
- }
- }
-
- g.setColor(Color.blue);
- g.setStroke(new BasicStroke(aPLB.getWidth()));
- drawPolyline(points, g);
- break;
- }
- }
- }
-
- /**
- * Draw polyline symbol
- *
- * @param aP The point
- * @param width The width
- * @param height The height
- * @param aPLB The polyline break
- * @param g Graphics2D
- */
- public static void drawPolylineSymbol(PointF aP, float width, float height, PolylineBreak aPLB, Graphics2D g) {
- if (aPLB.isUsingDashStyle()) {
- PointF[] points = new PointF[4];
- PointF aPoint = new PointF(0, 0);
- aPoint.X = aP.X - width / 2;
- aPoint.Y = aP.Y + height / 2;
- points[0] = aPoint;
- aPoint = new PointF();
- aPoint.X = aP.X - width / 6;
- aPoint.Y = aP.Y - height / 2;
- points[1] = aPoint;
- aPoint = new PointF();
- aPoint.X = aP.X + width / 6;
- aPoint.Y = aP.Y + height / 2;
- points[2] = aPoint;
- aPoint = new PointF();
- aPoint.X = aP.X + width / 2;
- aPoint.Y = aP.Y - height / 2;
- points[3] = aPoint;
-
- g.setColor(aPLB.getColor());
- float[] dashPattern = getDashPattern(aPLB.getStyle());
- g.setStroke(new BasicStroke(aPLB.getWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f));
-
- if (aPLB.getDrawPolyline()) {
- drawPolyline(points, g);
- }
- g.setStroke(new BasicStroke());
-
- //Draw symbol
- if (aPLB.getDrawSymbol()) {
- drawPoint(aPLB.getSymbolStyle(), points[1], aPLB.getSymbolFillColor(), aPLB.getSymbolColor(), aPLB.getSymbolSize(), true, aPLB.isFillSymbol(), g);
- drawPoint(aPLB.getSymbolStyle(), points[2], aPLB.getSymbolFillColor(), aPLB.getSymbolColor(), aPLB.getSymbolSize(), true, aPLB.isFillSymbol(), g);
- }
- } else {
- PointF[] points = new PointF[2];
- PointF aPoint = new PointF(0, 0);
- aPoint.X = aP.X - width / 2;
- aPoint.Y = aP.Y;
- points[0] = aPoint;
- aPoint = new PointF();
- aPoint.X = aP.X + width / 2;
- aPoint.Y = aP.Y;
- points[1] = aPoint;
- float lineWidth = 2.0f;
- switch (aPLB.getStyle()) {
- case COLDFRONT:
- PointBreak aPB = new PointBreak();
- aPB.setSize(14);
- aPB.setColor(Color.blue);
- aPB.setStyle(PointStyle.UpTriangle);
- aPB.setOutlineColor(Color.blue);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- drawPoint_Simple(new PointF(aP.X - aPB.getSize() * 2 / 3, aP.Y - aPB.getSize() / 4), aPB, g);
- drawPoint_Simple(new PointF(aP.X + aPB.getSize() * 2 / 3, aP.Y - aPB.getSize() / 4), aPB, g);
-
- g.setColor(Color.blue);
- g.setStroke(new BasicStroke(lineWidth));
- drawPolyline(points, g);
- break;
- case WARMFRONT:
- aPB = new PointBreak();
- aPB.setSize(14);
- aPB.setColor(Color.red);
- aPB.setStyle(PointStyle.UpSemiCircle);
- aPB.setOutlineColor(Color.red);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- drawPoint_Simple(new PointF(aP.X - aPB.getSize() * 2 / 3, aP.Y), aPB, g);
- drawPoint_Simple(new PointF(aP.X + aPB.getSize() * 2 / 3, aP.Y), aPB, g);
-
- g.setColor(Color.red);
- g.setStroke(new BasicStroke(lineWidth));
- drawPolyline(points, g);
- break;
- case OCCLUDEDFRONT:
- Color aColor = new Color(255, 0, 255);
- aPB = new PointBreak();
- aPB.setSize(14);
- aPB.setColor(aColor);
- aPB.setStyle(PointStyle.UpTriangle);
- aPB.setOutlineColor(aColor);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- drawPoint_Simple(new PointF(aP.X - aPB.getSize() * 2 / 3, aP.Y - aPB.getSize() / 4), aPB, g);
- aPB = new PointBreak();
- aPB.setSize(14);
- aPB.setColor(aColor);
- aPB.setStyle(PointStyle.UpSemiCircle);
- aPB.setOutlineColor(aColor);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- drawPoint_Simple(new PointF(aP.X + aPB.getSize() * 2 / 3, aP.Y), aPB, g);
-
- g.setColor(aColor);
- g.setStroke(new BasicStroke(lineWidth));
- drawPolyline(points, g);
- break;
- case STATIONARYFRONT:
- aPB = new PointBreak();
- aPB.setSize(14);
- aPB.setColor(Color.blue);
- aPB.setStyle(PointStyle.UpTriangle);
- aPB.setOutlineColor(Color.blue);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- drawPoint_Simple(new PointF(aP.X - aPB.getSize() * 2 / 3, aP.Y - aPB.getSize() / 4), aPB, g);
- aPB = new PointBreak();
- aPB.setSize(14);
- aPB.setColor(Color.red);
- aPB.setStyle(PointStyle.DownSemiCircle);
- aPB.setOutlineColor(Color.red);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- drawPoint_Simple(new PointF(aP.X + aPB.getSize() * 2 / 3, aP.Y), aPB, g);
-
- g.setColor(Color.blue);
- g.setStroke(new BasicStroke(lineWidth));
- drawPolyline(points, g);
- break;
- case ARROWLINE:
- g.setColor(aPLB.getColor());
- g.setStroke(new BasicStroke(lineWidth));
- //float[] dashPattern = getDashPattern(aPLB.getStyle());
- //g.setStroke(new BasicStroke(aPLB.getSize(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f));
- drawPolyline(points, g);
-
- int n = points.length;
- aPoint = points[n - 2];
- PointF bPoint = points[n - 1];
- double U = bPoint.X - aPoint.X;
- double V = bPoint.Y - aPoint.Y;
- double angle = Math.atan((V) / (U)) * 180 / Math.PI;
- angle = angle + 90;
- if (U < 0) {
- angle = angle + 180;
- }
-
- if (angle >= 360) {
- angle = angle - 360;
- }
-
- Draw.drawArraw(g, bPoint, angle, 8);
- break;
- }
- }
- }
-
- /**
- * Draw polyline symbol
- *
- * @param aP The point
- * @param width The width
- * @param height The height
- * @param aPLB The polyline break
- * @param g Graphics2D
- */
- public static void drawPolylineSymbol_S(PointF aP, float width, float height, PolylineBreak aPLB, Graphics2D g) {
- if (aPLB.isUsingDashStyle()) {
- PointF[] points = new PointF[2];
- PointF aPoint = new PointF(0, 0);
- aPoint.X = aP.X - width / 2;
- aPoint.Y = aP.Y;
- points[0] = aPoint;
- aPoint = new PointF();
- aPoint.X = aP.X + width / 2;
- aPoint.Y = aP.Y;
- points[1] = aPoint;
-
- g.setColor(aPLB.getColor());
- float[] dashPattern = getDashPattern(aPLB.getStyle());
- g.setStroke(new BasicStroke(aPLB.getWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f));
-
- if (aPLB.getDrawPolyline()) {
- drawPolyline(points, g);
- }
- g.setStroke(new BasicStroke());
-
- //Draw symbol
- if (aPLB.getDrawSymbol()) {
- drawPoint(aPLB.getSymbolStyle(), aP, aPLB.getSymbolFillColor(), aPLB.getSymbolColor(), aPLB.getSymbolSize(), true, aPLB.isFillSymbol(), g);
- }
- } else {
- PointF[] points = new PointF[2];
- PointF aPoint = new PointF(0, 0);
- aPoint.X = aP.X - width / 2;
- aPoint.Y = aP.Y;
- points[0] = aPoint;
- aPoint = new PointF();
- aPoint.X = aP.X + width / 2;
- aPoint.Y = aP.Y;
- points[1] = aPoint;
- float lineWidth = 2.0f;
- switch (aPLB.getStyle()) {
- case COLDFRONT:
- PointBreak aPB = new PointBreak();
- aPB.setSize(14);
- aPB.setColor(Color.blue);
- aPB.setStyle(PointStyle.UpTriangle);
- aPB.setOutlineColor(Color.blue);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- drawPoint_Simple(new PointF(aP.X - aPB.getSize() * 2 / 3, aP.Y - aPB.getSize() / 4), aPB, g);
- drawPoint_Simple(new PointF(aP.X + aPB.getSize() * 2 / 3, aP.Y - aPB.getSize() / 4), aPB, g);
-
- g.setColor(Color.blue);
- g.setStroke(new BasicStroke(lineWidth));
- drawPolyline(points, g);
- break;
- case WARMFRONT:
- aPB = new PointBreak();
- aPB.setSize(14);
- aPB.setColor(Color.red);
- aPB.setStyle(PointStyle.UpSemiCircle);
- aPB.setOutlineColor(Color.red);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- drawPoint_Simple(new PointF(aP.X - aPB.getSize() * 2 / 3, aP.Y), aPB, g);
- drawPoint_Simple(new PointF(aP.X + aPB.getSize() * 2 / 3, aP.Y), aPB, g);
-
- g.setColor(Color.red);
- g.setStroke(new BasicStroke(lineWidth));
- drawPolyline(points, g);
- break;
- case OCCLUDEDFRONT:
- Color aColor = new Color(255, 0, 255);
- aPB = new PointBreak();
- aPB.setSize(14);
- aPB.setColor(aColor);
- aPB.setStyle(PointStyle.UpTriangle);
- aPB.setOutlineColor(aColor);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- drawPoint_Simple(new PointF(aP.X - aPB.getSize() * 2 / 3, aP.Y - aPB.getSize() / 4), aPB, g);
- aPB = new PointBreak();
- aPB.setSize(14);
- aPB.setColor(aColor);
- aPB.setStyle(PointStyle.UpSemiCircle);
- aPB.setOutlineColor(aColor);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- drawPoint_Simple(new PointF(aP.X + aPB.getSize() * 2 / 3, aP.Y), aPB, g);
-
- g.setColor(aColor);
- g.setStroke(new BasicStroke(lineWidth));
- drawPolyline(points, g);
- break;
- case STATIONARYFRONT:
- aPB = new PointBreak();
- aPB.setSize(14);
- aPB.setColor(Color.blue);
- aPB.setStyle(PointStyle.UpTriangle);
- aPB.setOutlineColor(Color.blue);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- drawPoint_Simple(new PointF(aP.X - aPB.getSize() * 2 / 3, aP.Y - aPB.getSize() / 4), aPB, g);
- aPB = new PointBreak();
- aPB.setSize(14);
- aPB.setColor(Color.red);
- aPB.setStyle(PointStyle.DownSemiCircle);
- aPB.setOutlineColor(Color.red);
- aPB.setDrawFill(true);
- aPB.setDrawOutline(true);
- drawPoint_Simple(new PointF(aP.X + aPB.getSize() * 2 / 3, aP.Y), aPB, g);
-
- g.setColor(Color.blue);
- g.setStroke(new BasicStroke(lineWidth));
- drawPolyline(points, g);
- break;
- case ARROWLINE:
- g.setColor(aPLB.getColor());
- g.setStroke(new BasicStroke(lineWidth));
- //float[] dashPattern = getDashPattern(aPLB.getStyle());
- //g.setStroke(new BasicStroke(aPLB.getSize(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f));
- drawPolyline(points, g);
-
- int n = points.length;
- aPoint = points[n - 2];
- PointF bPoint = points[n - 1];
- double U = bPoint.X - aPoint.X;
- double V = bPoint.Y - aPoint.Y;
- double angle = Math.atan((V) / (U)) * 180 / Math.PI;
- angle = angle + 90;
- if (U < 0) {
- angle = angle + 180;
- }
-
- if (angle >= 360) {
- angle = angle - 360;
- }
-
- Draw.drawArraw(g, bPoint, angle, 8);
- break;
- }
- }
- }
-
-// /**
-// * Draw polygon symbol
-// *
-// * @param aP The point
-// * @param width The width
-// * @param height The height
-// * @param aPGB The polygon break
-// * @param transparencyPerc Transparency percent
-// * @param g Graphics2D
-// */
-// public static void drawPolygonSymbol(PointF aP, float width, float height, PolygonBreak aPGB,
-// int transparencyPerc, Graphics2D g) {
-// int alpha = (int) ((1 - (double) transparencyPerc / 100.0) * 255);
-// Color c = aPGB.getColor();
-// Color aColor = new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha);
-//// Brush aBrush;
-//// if (aPGB.UsingHatchStyle)
-//// aBrush = new HatchBrush(aPGB.Style, aColor, aPGB.BackColor);
-//// else
-//// aBrush = new SolidBrush(aColor);
-//
-// aP.X = aP.X - width / 2;
-// aP.Y = aP.Y - height / 2;
-// if (aPGB.getDrawFill()) {
-// g.setColor(aColor);
-// g.fill(new Rectangle.Float(aP.X, aP.Y, width, height));
-// }
-// if (aPGB.getDrawOutline()) {
-// g.setColor(aPGB.getOutlineColor());
-// g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
-// g.draw(new Rectangle.Float(aP.X, aP.Y, width, height));
-// }
-// }
- /**
- * Draw polygon symbol
- *
- * @param x X
- * @param y Y
- * @param width The width
- * @param height The height
- * @param aPGB The polygon break
- * @param g Graphics2D
- */
- public static void drawPolygonSymbol(double x, double y, double width, double height, PolygonBreak aPGB,
- Graphics2D g) {
- if (aPGB.isDrawFill()) {
- if (aPGB.isUsingHatchStyle()) {
- int size = aPGB.getStyleSize();
- BufferedImage bi = getHatchImage(aPGB.getStyle(), size, aPGB.getColor(), aPGB.getBackColor());
- Rectangle2D rect = new Rectangle2D.Double(0, 0, size, size);
- g.setPaint(new TexturePaint(bi, rect));
- g.fill(new Rectangle.Double(x, y, width, height));
- } else {
- g.setColor(aPGB.getColor());
- g.fill(new Rectangle.Double(x, y, width, height));
- g.draw(new Rectangle.Double(x, y, width, height));
- }
- }
- if (aPGB.isDrawOutline()) {
- g.setColor(aPGB.getOutlineColor());
- g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
- g.draw(new Rectangle.Double(x, y, width, height));
- }
- }
-
- /**
- * Draw polygon symbol
- *
- * @param aP The center point
- * @param width The width
- * @param height The height
- * @param aPGB The polygon break
- * @param g Graphics2D
- */
- public static void drawPolygonSymbol(PointF aP, float width, float height, PolygonBreak aPGB,
- Graphics2D g) {
- aP.X = aP.X - width / 2;
- aP.Y = aP.Y - height / 2;
- if (aPGB.isDrawFill()) {
- if (aPGB.isUsingHatchStyle()) {
- int size = aPGB.getStyleSize();
- BufferedImage bi = getHatchImage(aPGB.getStyle(), size, aPGB.getColor(), aPGB.getBackColor());
- Rectangle2D rect = new Rectangle2D.Double(0, 0, size, size);
- g.setPaint(new TexturePaint(bi, rect));
- g.fill(new Rectangle.Float(aP.X, aP.Y, width, height));
- } else {
- g.setColor(aPGB.getColor());
- g.fill(new Rectangle.Float(aP.X, aP.Y, width, height));
- }
- }
- if (aPGB.isDrawOutline()) {
- g.setColor(aPGB.getOutlineColor());
- g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
- g.draw(new Rectangle.Float(aP.X, aP.Y, width, height));
- }
- }
-
- /**
- * Draw polygon symbol
- *
- * @param x X
- * @param y Y
- * @param aColor Fill color
- * @param outlineColor Outline color
- * @param width Width
- * @param height Height
- * @param drawFill If draw fill
- * @param drawOutline If draw outline
- * @param g Grahics2D
- */
- public static void drawPolygonSymbol(double x, double y, Color aColor, Color outlineColor,
- double width, double height, Boolean drawFill, Boolean drawOutline, Graphics2D g) {
- if (drawFill) {
- g.setColor(aColor);
- g.fill(new Rectangle.Double(x, y, width, height));
- g.draw(new Rectangle.Double(x, y, width, height));
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.draw(new Rectangle.Double(x, y, width, height));
- }
- }
-
- /**
- * Draw polygon symbol
- *
- * @param aP The center point
- * @param aColor Fill color
- * @param outlineColor Outline color
- * @param width Width
- * @param height Height
- * @param drawFill If draw fill
- * @param drawOutline If draw outline
- * @param g Grahics2D
- */
- public static void drawPolygonSymbol(PointF aP, Color aColor, Color outlineColor,
- float width, float height, Boolean drawFill, Boolean drawOutline, Graphics2D g) {
- aP.X = aP.X - width / 2;
- aP.Y = aP.Y - height / 2;
- if (drawFill) {
- g.setColor(aColor);
- g.fill(new Rectangle.Float(aP.X, aP.Y, width, height));
- }
- if (drawOutline) {
- g.setColor(outlineColor);
- g.draw(new Rectangle.Float(aP.X, aP.Y, width, height));
- }
- }
-
- /**
- * Draw rectangle
- *
- * @param aPoint Start point
- * @param width Width
- * @param height Height
- * @param aPGB Polygon break
- * @param g Graphics2D
- */
- public static void drawRectangle(PointF aPoint, float width, float height, PolygonBreak aPGB, Graphics2D g) {
- Color aColor = aPGB.getColor();
- if (aPGB.isDrawFill()) {
- if (aPGB.isUsingHatchStyle()) {
- int size = aPGB.getStyleSize();
- BufferedImage bi = getHatchImage(aPGB.getStyle(), size, aPGB.getColor(), aPGB.getBackColor());
- Rectangle2D rect = new Rectangle2D.Double(0, 0, size, size);
- g.setPaint(new TexturePaint(bi, rect));
- g.fill(new Rectangle.Float(aPoint.X, aPoint.Y, width, height));
- } else {
- g.setColor(aColor);
- g.fill(new Rectangle.Float(aPoint.X, aPoint.Y, width, height));
- }
- }
- if (aPGB.isDrawOutline()) {
- g.setColor(aPGB.getOutlineColor());
- g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
- g.draw(new Rectangle.Float(aPoint.X, aPoint.Y, width, height));
- }
- }
-
- /**
- * Draw pie
- *
- * @param aPoint Start point
- * @param width Width
- * @param height Height
- * @param startAngle Start angle
- * @param sweepAngle Sweep angle
- * @param aPGB Polygon break
- * @param g Graphics2D
- */
- public static void drawPie(PointF aPoint, float width, float height, float startAngle, float sweepAngle, PolygonBreak aPGB, Graphics2D g) {
- Color aColor = aPGB.getColor();
- if (aPGB.isDrawFill()) {
- g.setColor(aColor);
- g.fill(new Arc2D.Float(aPoint.X, aPoint.Y, width, height, startAngle, sweepAngle, Arc2D.PIE));
- }
- if (aPGB.isDrawOutline()) {
- g.setColor(aPGB.getOutlineColor());
- g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
- g.draw(new Arc2D.Float(aPoint.X, aPoint.Y, width, height, startAngle, sweepAngle, Arc2D.PIE));
- }
- }
-
- /**
- * Draw pie
- *
- * @param aPoint Start point
- * @param width Width
- * @param height Height
- * @param startAngle Start angle
- * @param sweepAngle Sweep angle
- * @param aPGB Polygon break
- * @param wedgeWidth Wedge width
- * @param g Graphics2D
- */
- public static void drawPie(PointF aPoint, float width, float height, float startAngle,
- float sweepAngle, PolygonBreak aPGB, float wedgeWidth, Graphics2D g) {
- Color aColor = aPGB.getColor();
- Arc2D.Float arc2D = new Arc2D.Float(aPoint.X, aPoint.Y, width, height, startAngle, sweepAngle, Arc2D.PIE);
- Area area1 = new Area(arc2D);
- Ellipse2D e2 = new Ellipse2D.Float(aPoint.X + wedgeWidth, aPoint.Y + wedgeWidth, width - wedgeWidth * 2,
- height - wedgeWidth * 2);
- Area area2 = new Area(e2);
- area1.subtract(area2);
- if (aPGB.isDrawFill()) {
- g.setColor(aColor);
- g.fill(area1);
- }
- if (aPGB.isDrawOutline()) {
- g.setColor(aPGB.getOutlineColor());
- g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
- g.draw(area1);
- }
- }
-
- /**
- * Draw curve line
- *
- * @param points The points
- * @param aPLB The polyline break
- * @param g Graphics2D
- */
- public static void drawCurveLine(PointF[] points, PolylineBreak aPLB, Graphics2D g) {
- List opoints = new ArrayList<>();
- int i;
- for (i = 0; i < points.length; i++) {
- opoints.add(new PointD(points[i].X, points[i].Y));
- }
-
- PointD[] rPoints = Spline.cardinalSpline((PointD[]) opoints.toArray(new PointD[opoints.size()]), 5);
- PointF[] dPoints = new PointF[rPoints.length];
- for (i = 0; i < dPoints.length; i++) {
- dPoints[i] = new PointF((float) rPoints[i].X, (float) rPoints[i].Y);
- }
-
- drawPolyline(dPoints, aPLB, g);
- }
-
- /**
- * Draw curve line
- *
- * @param points The points list
- * @param g Graphics2D
- */
- public static void drawCurveLine(List points, Graphics2D g) {
- PointD[] opoints = new PointD[points.size()];
- int i;
- for (i = 0; i < points.size(); i++) {
- opoints[i] = new PointD(points.get(i).X, points.get(i).Y);
- }
-
- PointD[] rPoints = Spline.cardinalSpline(opoints, 5);
- PointF[] dPoints = new PointF[rPoints.length];
- for (i = 0; i < dPoints.length; i++) {
- dPoints[i] = new PointF((float) rPoints[i].X, (float) rPoints[i].Y);
- }
-
- drawPolyline(dPoints, g);
- }
-
- /**
- * Draw curve line
- *
- * @param points The points
- * @param g Graphics2D
- */
- public static void drawCurveLine(PointF[] points, Graphics2D g) {
- List opoints = new ArrayList<>();
- int i;
- for (i = 0; i < points.length; i++) {
- opoints.add(new PointD(points[i].X, points[i].Y));
- }
-
- PointD[] rPoints = Spline.cardinalSpline((PointD[]) opoints.toArray(), 5);
- PointF[] dPoints = new PointF[rPoints.length];
- for (i = 0; i < dPoints.length; i++) {
- dPoints[i] = new PointF((float) rPoints[i].X, (float) rPoints[i].Y);
- }
-
- drawPolyline(dPoints, g);
- }
-
- /**
- * Draw curve polygon
- *
- * @param points The points
- * @param aPGB Polygon break
- * @param g Graphics2D
- */
- public static void drawCurvePolygon(PointF[] points, PolygonBreak aPGB, Graphics2D g) {
- List opoints = new ArrayList<>();
- int i;
- for (i = 0; i < points.length; i++) {
- opoints.add(new PointD(points[i].X, points[i].Y));
- }
-
- PointD[] rPoints = Spline.cardinalSpline((PointD[]) opoints.toArray(new PointD[opoints.size()]), 5);
- PointF[] dPoints = new PointF[rPoints.length];
- for (i = 0; i < dPoints.length; i++) {
- dPoints[i] = new PointF((float) rPoints[i].X, (float) rPoints[i].Y);
- }
-
- drawPolygon(dPoints, aPGB, g);
- }
-
- /**
- * Draw circle
- *
- * @param points The points
- * @param aPGB The polygon break
- * @param g Graphics2D
- */
- public static void drawCircle(PointF[] points, PolygonBreak aPGB, Graphics2D g) {
- float radius = Math.abs(points[1].X - points[0].X);
-
- if (aPGB.isDrawFill()) {
- g.setColor(aPGB.getColor());
- g.fill(new Ellipse2D.Float(points[0].X, points[0].Y - radius, radius * 2, radius * 2));
- }
- if (aPGB.isDrawOutline()) {
- g.setColor(aPGB.getOutlineColor());
- g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
- g.draw(new Ellipse2D.Float(points[0].X, points[0].Y - radius, radius * 2, radius * 2));
- }
- }
-
- /**
- * Draw ellipse
- *
- * @param points The points
- * @param angle The angle
- * @param aPGB The polygon break
- * @param g Grahpics2D
- */
- public static void drawEllipse(PointF[] points, float angle, PolygonBreak aPGB, Graphics2D g) {
- float sx = Math.min(points[0].X, points[2].X);
- float sy = Math.min(points[0].Y, points[2].Y);
- float width = Math.abs(points[2].X - points[0].X);
- float height = Math.abs(points[2].Y - points[0].Y);
-
- if (angle != 0) {
- AffineTransform tempTrans = g.getTransform();
- AffineTransform myTrans = (AffineTransform) tempTrans.clone();
- myTrans.translate(sx + width / 2, sy + height / 2);
- myTrans.rotate(Math.toRadians(angle));
- //AffineTransform myTrans = AffineTransform.getRotateInstance(Math.toRadians(angle),
- // sx + width / 2 + tempTrans.getTranslateX(), sy + height / 2 + tempTrans.getTranslateY());
- g.setTransform(myTrans);
- //sx += tempTrans.getTranslateX();
- //sy += tempTrans.getTranslateY();
-
- if (aPGB.isDrawFill()) {
- g.setColor(aPGB.getColor());
- g.fill(new Ellipse2D.Float(-width / 2, -height / 2, width, height));
- }
- if (aPGB.isDrawOutline()) {
- g.setColor(aPGB.getOutlineColor());
- g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
- g.draw(new Ellipse2D.Float(-width / 2, -height / 2, width, height));
- }
-
- g.setTransform(tempTrans);
- } else {
-
- if (aPGB.isDrawFill()) {
- g.setColor(aPGB.getColor());
- g.fill(new Ellipse2D.Float(sx, sy, width, height));
- }
- if (aPGB.isDrawOutline()) {
- g.setColor(aPGB.getOutlineColor());
- g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
- g.draw(new Ellipse2D.Float(sx, sy, width, height));
- }
- }
- }
-
- /**
- * Draw ellipse
- *
- * @param points The points
- * @param aPGB The polygon break
- * @param g Grahpics2D
- */
- public static void drawEllipse(PointF[] points, PolygonBreak aPGB, Graphics2D g) {
- float sx = Math.min(points[0].X, points[2].X);
- float sy = Math.min(points[0].Y, points[2].Y);
- float width = Math.abs(points[2].X - points[0].X);
- float height = Math.abs(points[2].Y - points[0].Y);
-
- if (aPGB.isDrawFill()) {
- g.setColor(aPGB.getColor());
- g.fill(new Ellipse2D.Float(sx, sy, width, height));
- }
- if (aPGB.isDrawOutline()) {
- g.setColor(aPGB.getOutlineColor());
- g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
- g.draw(new Ellipse2D.Float(sx, sy, width, height));
- }
- }
-
- /**
- * Draw selected vertices rectangles
- *
- * @param g Graphics2D
- * @param points The points
- */
- public static void drawSelectedVertices(Graphics2D g, PointF[] points) {
- drawSelectedVertices(g, points, 6, Color.black, Color.cyan);
- }
-
- /**
- * Draw selected vertices rectangles
- *
- * @param g Graphics2D
- * @param points The points
- * @param size The size
- * @param outlineColor Outline coloe
- * @param fillColor Fill color
- */
- public static void drawSelectedVertices(Graphics2D g, PointF[] points, float size, Color outlineColor, Color fillColor) {
- Rectangle.Float rect = new Rectangle.Float(0, 0, size, size);
-
- for (PointF aPoint : points) {
- rect.x = aPoint.X - size / 2;
- rect.y = aPoint.Y - size / 2;
- g.setColor(fillColor);
- g.fill(rect);
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(1));
- g.draw(rect);
- }
- }
-
- /**
- * Draw selected vertice rectangles
- *
- * @param g Graphics2D
- * @param point The point
- * @param size The size
- * @param outlineColor Outline coloe
- * @param fillColor Fill color
- */
- public static void drawSelectedVertice(Graphics2D g, PointF point, float size, Color outlineColor, Color fillColor) {
- Rectangle.Float rect = new Rectangle.Float(0, 0, size, size);
-
- rect.x = point.X - size / 2;
- rect.y = point.Y - size / 2;
- g.setColor(fillColor);
- g.fill(rect);
- g.setColor(outlineColor);
- g.setStroke(new BasicStroke(1));
- g.draw(rect);
- }
-
- /**
- * Draw selected four corner rectangles
- *
- * @param g Graphics2D
- * @param gRect The rectangle
- */
- public static void drawSelectedCorners(Graphics2D g, Rectangle gRect) {
- int size = 6;
- Rectangle rect = new Rectangle(gRect.x - size / 2, gRect.y - size / 2, size, size);
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- rect.y = gRect.y + gRect.height - size / 2;
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- rect.x = gRect.x + gRect.width - size / 2;
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- rect.y = gRect.y - size / 2;
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- }
-
- /**
- * Draw selected four bouder edge center rectangles
- *
- * @param g Graphics2D
- * @param gRect The rectangle
- */
- public static void drawSelectedEdgeCenters(Graphics2D g, Rectangle gRect) {
- int size = 6;
- Rectangle rect = new Rectangle(gRect.x + gRect.width / 2 - size / 2, gRect.y - size / 2, size, size);
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- rect.y = gRect.y + gRect.height - size / 2;
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- rect.x = gRect.x - size / 2;
- rect.y = gRect.y + gRect.height / 2 - size / 2;
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- rect.x = gRect.x + gRect.width - size / 2;
- g.setColor(Color.cyan);
- g.fill(rect);
- g.setColor(Color.black);
- g.draw(rect);
- }
- //
-
- //
- /**
- * Draw chart point
- *
- * @param aPoint Screen point
- * @param aCB Chart break
- * @param g Graphics2D
- */
- public static void drawChartPoint(PointF aPoint, ChartBreak aCB, Graphics2D g) {
- switch (aCB.getChartType()) {
- case BarChart:
- drawBarChartSymbol(aPoint, aCB, g);
- break;
- case PieChart:
- List rStrs = null;
- if (aCB.isDrawLabel()) {
- List ratios = aCB.getPieRatios();
- rStrs = new ArrayList<>();
- for (float r : ratios) {
- rStrs.add(String.valueOf((int) (r * 100)) + "%");
- }
- }
- drawPieChartSymbol(aPoint, aCB, g, rStrs);
- break;
- }
-
- }
-
- /**
- * Draw bar chart symbol
- *
- * @param aPoint Start point
- * @param aCB Chart break
- * @param g Graphics2D
- */
- public static void drawBarChartSymbol(PointF aPoint, ChartBreak aCB, Graphics2D g) {
- Font font = new Font("Arial", Font.PLAIN, 8);
- drawBarChartSymbol(aPoint, aCB, g, false, font);
- }
-
- /**
- * Draw bar chart symbol
- *
- * @param aPoint Start point
- * @param aCB Chart break
- * @param g Graphics2D
- * @param drawValue If draw value
- */
- public static void drawBarChartSymbol(PointF aPoint, ChartBreak aCB, Graphics2D g, boolean drawValue) {
- drawBarChartSymbol(aPoint, aCB, g, drawValue, g.getFont());
- }
-
- /**
- * Draw bar chart symbol
- *
- * @param sPoint Start point
- * @param aCB Chart break
- * @param g Graphics2D
- * @param drawValue If draw value
- * @param font Value font
- */
- public static void drawBarChartSymbol(PointF sPoint, ChartBreak aCB, Graphics2D g, boolean drawValue, Font font) {
- PointF aPoint = (PointF) sPoint.clone();
- List heights = aCB.getBarHeights();
- float y = aPoint.Y;
- for (int i = 0; i < heights.size(); i++) {
- if (heights.get(i) <= 0) {
- aPoint.X += aCB.getBarWidth();
- continue;
- }
-
- aPoint.Y = y - heights.get(i);
- PolygonBreak aPGB = (PolygonBreak) aCB.getLegendScheme().getLegendBreaks().get(i);
- if (aCB.isView3D()) {
- Color aColor = ColorUtil.modifyBrightness(aPGB.getColor(), 0.5f);
- PointF[] points = new PointF[4];
- points[0] = new PointF(aPoint.X, aPoint.Y);
- points[1] = new PointF(aPoint.X + aCB.getBarWidth(), aPoint.Y);
- points[2] = new PointF(points[1].X + aCB.getThickness(), points[1].Y - aCB.getThickness());
- points[3] = new PointF(points[0].X + aCB.getThickness(), points[0].Y - aCB.getThickness());
- g.setColor(aColor);
- Draw.fillPolygon(points, g, aPGB);
- g.setColor(aPGB.getOutlineColor());
- Draw.drawPolyline(points, g);
-
- points[0] = new PointF(aPoint.X + aCB.getBarWidth(), aPoint.Y);
- points[1] = new PointF(aPoint.X + aCB.getBarWidth(), aPoint.Y + heights.get(i));
- points[2] = new PointF(points[1].X + aCB.getThickness(), points[1].Y - aCB.getThickness());
- points[3] = new PointF(points[0].X + aCB.getThickness(), points[0].Y - aCB.getThickness());
- g.setColor(aColor);
- Draw.fillPolygon(points, g, aPGB);
- g.setColor(aPGB.getOutlineColor());
- Draw.drawPolyline(points, g);
- }
- drawRectangle(aPoint, aCB.getBarWidth(), heights.get(i), aPGB, g);
-
- aPoint.X += aCB.getBarWidth();
-
- if (i == heights.size() - 1) {
- if (drawValue) {
- //String vstr = String.valueOf(aCB.getChartData().get(i));
- String formatStr = "%1$." + String.valueOf(aCB.getDecimalDigits()) + "f";
- String vstr = String.format(formatStr, aCB.getChartData().get(i));
- FontMetrics metrics = g.getFontMetrics(font);
- Dimension labSize = new Dimension(metrics.stringWidth(vstr), metrics.getHeight());
- aPoint.X += 5;
- aPoint.Y = (float) (y - heights.get(i) / 2);
- g.setColor(Color.black);
- g.setFont(font);
- g.drawString(vstr, aPoint.X, aPoint.Y + metrics.getHeight() / 2);
- }
- }
- }
- }
-
- /**
- * Draw bar chart symbol
- *
- * @param aPoint Start point
- * @param width Width
- * @param height Height
- * @param g Graphics2D
- * @param aPGB Polygon beak
- * @param isView3D Is view as 3D
- * @param thickness 3D thickness
- */
- public static void drawBar(PointF aPoint, int width, int height, PolygonBreak aPGB, Graphics2D g, boolean isView3D,
- int thickness) {
-// float y = aPoint.Y;
-// aPoint.Y = y - height;
-// if (isView3D) {
-// Color aColor = ColorUtil.modifyBrightness(aPGB.getColor(), 0.5f);
-// PointF[] points = new PointF[4];
-// points[0] = new PointF(aPoint.X, aPoint.Y);
-// points[1] = new PointF(aPoint.X + width, aPoint.Y);
-// points[2] = new PointF(points[1].X + thickness, points[1].Y - thickness);
-// points[3] = new PointF(points[0].X + thickness, points[0].Y - thickness);
-// g.setColor(aColor);
-// Draw.fillPolygon(points, g);
-// g.setColor(aPGB.getOutlineColor());
-// Draw.drawPolyline(points, g);
-//
-// points[0] = new PointF(aPoint.X + width, aPoint.Y);
-// points[1] = new PointF(aPoint.X + width, aPoint.Y + height);
-// points[2] = new PointF(points[1].X + thickness, points[1].Y - thickness);
-// points[3] = new PointF(points[0].X + thickness, points[0].Y - thickness);
-// g.setColor(aColor);
-// Draw.fillPolygon(points, g);
-// g.setColor(aPGB.getOutlineColor());
-// Draw.drawPolyline(points, g);
-// }
-// drawRectangle(aPoint, width, height, aPGB, g);
- drawBar(aPoint, (float) width, (float) height, aPGB, g, isView3D, thickness);
- }
-
- /**
- * Draw bar chart symbol
- *
- * @param aPoint Start point
- * @param width Width
- * @param height Height
- * @param g Graphics2D
- * @param aPGB Polygon beak
- * @param isView3D Is view as 3D
- * @param thickness 3D thickness
- */
- public static void drawBar(PointF aPoint, float width, float height, PolygonBreak aPGB, Graphics2D g, boolean isView3D,
- int thickness) {
- float y = aPoint.Y;
- aPoint.Y = y - height;
- if (isView3D) {
- Color aColor = ColorUtil.modifyBrightness(aPGB.getColor(), 0.5f);
- PointF[] points = new PointF[4];
- points[0] = new PointF(aPoint.X, aPoint.Y);
- points[1] = new PointF(aPoint.X + width, aPoint.Y);
- points[2] = new PointF(points[1].X + thickness, points[1].Y - thickness);
- points[3] = new PointF(points[0].X + thickness, points[0].Y - thickness);
- g.setColor(aColor);
- Draw.fillPolygon(points, g, aPGB);
- g.setColor(aPGB.getOutlineColor());
- Draw.drawPolyline(points, g);
-
- points[0] = new PointF(aPoint.X + width, aPoint.Y);
- points[1] = new PointF(aPoint.X + width, aPoint.Y + height);
- points[2] = new PointF(points[1].X + thickness, points[1].Y - thickness);
- points[3] = new PointF(points[0].X + thickness, points[0].Y - thickness);
- g.setColor(aColor);
- Draw.fillPolygon(points, g, aPGB);
- g.setColor(aPGB.getOutlineColor());
- Draw.drawPolyline(points, g);
- }
- drawRectangle(aPoint, width, height, aPGB, g);
- }
-
- /**
- * Draw pie chart symbol
- *
- * @param aPoint Start point
- * @param aCB Chart break
- * @param g Graphics2D
- * @param labels Labels
- */
- public static void drawPieChartSymbol(PointF aPoint, ChartBreak aCB, Graphics2D g, List labels) {
- int width = aCB.getWidth();
- int height = aCB.getHeight();
- if (width <= 0 || height <= 0) {
- return;
- }
-
- PointF sPoint = new PointF(aPoint.X + width / 2, aPoint.Y - height / 2);
- aPoint.Y -= height;
- List> angles = aCB.getPieAngles();
- float startAngle, sweepAngle;
- int i;
- if (aCB.isView3D()) {
- aPoint.Y = aPoint.Y + width / 6 - aCB.getThickness();
- for (i = 0; i < angles.size(); i++) {
- startAngle = angles.get(i).get(0);
- sweepAngle = angles.get(i).get(1);
- PolygonBreak aPGB = (PolygonBreak) aCB.getLegendScheme().getLegendBreaks().get(i);
- if (startAngle + sweepAngle > 180) {
- PointF bPoint = new PointF(aPoint.X, aPoint.Y + aCB.getThickness());
- Color aColor = ColorUtil.modifyBrightness(aPGB.getColor(), 0.5f);
-
- g.setColor(aColor);
- g.fill(new Arc2D.Float(bPoint.X, bPoint.Y, width, width * 2 / 3, startAngle, sweepAngle, Arc2D.PIE));
- g.setColor(aPGB.getOutlineColor());
- g.draw(new Arc2D.Float(bPoint.X, bPoint.Y, width, width * 2 / 3, startAngle, sweepAngle, Arc2D.PIE));
- }
- }
- float a = (float) width / 2;
- float b = (float) width / 3;
- float x0 = aPoint.X + a;
- float y0 = aPoint.Y + b;
- double sA, eA;
- for (i = 0; i < angles.size(); i++) {
- startAngle = angles.get(i).get(0);
- sweepAngle = angles.get(i).get(1);
- if (startAngle + sweepAngle > 180) {
- sA = (360 - startAngle) / 180 * Math.PI;
- eA = (360 - (startAngle + sweepAngle)) / 180 * Math.PI;
- PolygonBreak aPGB = (PolygonBreak) aCB.getLegendScheme().getLegendBreaks().get(i);
- PointF bPoint = MIMath.calEllipseCoordByAngle(x0, y0, a, b, eA);
- PointF cPoint = new PointF(x0 - a, y0);
- if (sA < Math.PI) {
- cPoint = MIMath.calEllipseCoordByAngle(x0, y0, a, b, sA);
- }
-
- Color aColor = ColorUtil.modifyBrightness(aPGB.getColor(), 0.5f);
- PointF[] points = new PointF[5];
- points[0] = cPoint;
- points[1] = new PointF(cPoint.X, cPoint.Y + aCB.getThickness());
- points[2] = new PointF(bPoint.X, bPoint.Y + aCB.getThickness());
- points[3] = bPoint;
- points[4] = cPoint;
- g.setColor(aColor);
- Draw.fillPolygon(points, g, aPGB);
- g.setColor(aPGB.getOutlineColor());
- g.draw(new Line2D.Float(points[0].X, points[0].Y, points[1].X, points[1].Y));
- g.draw(new Line2D.Float(points[2].X, points[2].Y, points[3].X, points[3].Y));
- }
- }
- for (i = 0; i < angles.size(); i++) {
- startAngle = angles.get(i).get(0);
- sweepAngle = angles.get(i).get(1);
- PolygonBreak aPGB = (PolygonBreak) aCB.getLegendScheme().getLegendBreaks().get(i);
- drawPie(aPoint, width, width * 2 / 3, startAngle, sweepAngle, aPGB, g);
- }
- } else {
- for (i = 0; i < angles.size(); i++) {
- startAngle = angles.get(i).get(0);
- sweepAngle = angles.get(i).get(1);
- PolygonBreak aPGB = (PolygonBreak) aCB.getLegendScheme().getLegendBreaks().get(i);
- drawPie(aPoint, width, width, startAngle, sweepAngle, aPGB, g);
- }
- if (labels != null) {
- FontMetrics metrics = g.getFontMetrics();
- float x, y, angle, w, h;
- for (i = 0; i < angles.size(); i++) {
- String label = labels.get(i);
- if (label.equals("0%")) {
- continue;
- }
-
- startAngle = angles.get(i).get(0);
- sweepAngle = angles.get(i).get(1);
- angle = startAngle + sweepAngle / 2;
- PointF lPoint = getPieLabelPoint(sPoint, width / 2, angle);
- x = lPoint.X;
- y = lPoint.Y;
- h = metrics.getHeight();
- w = metrics.stringWidth(label);
- if ((angle >= 0 && angle < 45) || (angle >= 315 && angle <= 360)) {
- x = x + 3;
- y = y + h / 2;
- } else if (angle >= 45 && angle < 90) {
- y = y - 3;
- } else if (angle >= 90 && angle < 135) {
- x = x - w - 3;
- y = y - 3;
- } else if (angle >= 135 && angle < 225) {
- x = x - w - 3;
- y = y + h / 2;
- } else if (angle >= 225 && angle < 270) {
- x = x - w - 3;
- y = y + h / 2;
- } else {
- y = y + h;
- }
- g.drawString(label, x, y);
- }
- }
- }
- }
-
- /**
- * Get pie wedge label point
- *
- * @param sPoint Center point
- * @param r Radius
- * @param angle Angle
- * @return Label point
- */
- public static PointF getPieLabelPoint(PointF sPoint, float r, float angle) {
- float x = (float) (sPoint.X + r * Math.cos(angle * Math.PI / 180));
- float y = (float) (sPoint.Y - r * Math.sin(angle * Math.PI / 180));
- return new PointF(x, y);
- }
- //
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/form/ChartForm.form b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/form/ChartForm.form
new file mode 100644
index 00000000..08ed8b15
--- /dev/null
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/form/ChartForm.form
@@ -0,0 +1,25 @@
+
+
+
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/form/ChartForm.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/form/ChartForm.java
new file mode 100644
index 00000000..d9dfe1a2
--- /dev/null
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/form/ChartForm.java
@@ -0,0 +1,95 @@
+/*
+ * 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.form;
+
+import org.meteoinfo.chart.ChartPanel;
+import org.meteoinfo.chart.MouseMode;
+
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+
+/**
+ *
+ * @author wyq
+ */
+public class ChartForm extends javax.swing.JFrame {
+
+ private ChartPanel chartPanel;
+
+ /**
+ * Creates new form ChartForm
+ * @param chartPanel Chart panel
+ */
+ public ChartForm(ChartPanel chartPanel) {
+ initComponents();
+
+ this.chartPanel = chartPanel;
+ this.chartPanel.setMouseMode(MouseMode.ZOOM_IN);
+ this.getContentPane().add(this.chartPanel, BorderLayout.CENTER);
+
+ BufferedImage image = null;
+ try {
+ image = ImageIO.read(this.getClass().getResource("/images/MeteoInfo.png"));
+ } catch (Exception e) {
+ }
+ this.setIconImage(image);
+ this.setTitle("MeteoInfo Chart Form");
+ }
+
+ /**
+ * This method is called from within the constructor to initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is always
+ * regenerated by the Form Editor.
+ */
+ @SuppressWarnings("unchecked")
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+
+ pack();
+ }// //GEN-END:initComponents
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[]) {
+ /* Set the Nimbus look and feel */
+ //
+ /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
+ * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
+ */
+ try {
+ for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
+ if ("Nimbus".equals(info.getName())) {
+ javax.swing.UIManager.setLookAndFeel(info.getClassName());
+ break;
+ }
+ }
+ } catch (ClassNotFoundException ex) {
+ java.util.logging.Logger.getLogger(ChartForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (InstantiationException ex) {
+ java.util.logging.Logger.getLogger(ChartForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (IllegalAccessException ex) {
+ java.util.logging.Logger.getLogger(ChartForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+ java.util.logging.Logger.getLogger(ChartForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ }
+ //
+
+ /* Create and display the form */
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ new ChartForm(new ChartPanel()).setVisible(true);
+ }
+ });
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/ChartGraphic.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/ChartGraphic.java
deleted file mode 100644
index 25addd77..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/ChartGraphic.java
+++ /dev/null
@@ -1,144 +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.graphic;
-
-import org.meteoinfo.common.PointD;
-import org.meteoinfo.geometry.shape.PointShape;
-import org.meteoinfo.chart.legend.ChartBreak;
-import org.w3c.dom.Attr;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class ChartGraphic extends Graphic {
-
- //
- private PointD startPosition;
-
- //
- //
- /**
- * Constructor
- */
- public ChartGraphic() {
-
- }
-
- /**
- * Constructor
- *
- * @param shape Point shape
- * @param legend Chart break
- */
- public ChartGraphic(PointShape shape, ChartBreak legend) {
- super(shape, legend);
- startPosition = (PointD) shape.getPoint().clone();
- }
-
- //
- //
- /**
- * Get start position
- *
- * @return Start position
- */
- public PointD getStartPosition() {
- return startPosition;
- }
-
- /**
- * Set start postion
- *
- * @param value Start position
- */
- public void setStartPosition(PointD value) {
- startPosition = value;
- }
-
- /**
- * Set point shape
- *
- * @param aShape Point shape
- */
- public void setShape(PointShape aShape) {
- super.setShape(aShape);
- startPosition = (PointD) aShape.getPoint().clone();
- }
-
- //
- //
- /**
- * Export to XML document
- *
- * @param doc XML document
- * @param parent Parent XML element
- */
- @Override
- public void exportToXML(Document doc, Element parent) {
- Element graphic = doc.createElement("Graphic");
- this.addShape(doc, graphic, this.getShape());
- this.addLegend(doc, graphic, this.getLegend(), this.getShape().getShapeType());
- this.addStartPosition(doc, graphic, startPosition);
-
- parent.appendChild(graphic);
- }
-
- private void addStartPosition(Document doc, Element parent, PointD pos) {
- Element startPos = doc.createElement("StartPosition");
-
- Attr xAttr = doc.createAttribute("X");
- Attr yAttr = doc.createAttribute("Y");
-
- xAttr.setValue(String.valueOf(pos.X));
- yAttr.setValue(String.valueOf(pos.Y));
-
- startPos.setAttributeNode(xAttr);
- startPos.setAttributeNode(yAttr);
-
- parent.appendChild(startPos);
- }
-
- /**
- * Import from xml node
- *
- * @param graphicNode Graphic xml node
- */
- @Override
- public void importFromXML(Element graphicNode) {
- Node shape = graphicNode.getElementsByTagName("Shape").item(0);
- this.setShape((PointShape)loadShape(shape));
-
- Node legend = graphicNode.getElementsByTagName("Legend").item(0);
- this.setLegend(loadLegend(legend, this.getShape().getShapeType()));
-
- Node startPos = graphicNode.getElementsByTagName("StartPosition").item(0);
- if (startPos != null) {
- PointD sP = this.loadStartPosition(startPos);
- if (sP != null) {
- this.startPosition = sP;
- }
- }
- }
-
- private PointD loadStartPosition(Node startPosNode) {
- PointD sP = null;
- try {
- double x = Double.parseDouble(startPosNode.getAttributes().getNamedItem("X").getNodeValue());
- double y = Double.parseDouble(startPosNode.getAttributes().getNamedItem("Y").getNodeValue());
- sP = new PointD(x, y);
- } catch (DOMException e) {
- } catch (NumberFormatException e) {
- }
-
- return sP;
- }
- //
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/Graphic.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/Graphic.java
deleted file mode 100644
index 529c2c74..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/Graphic.java
+++ /dev/null
@@ -1,713 +0,0 @@
- /* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.chart.graphic;
-
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.common.PointD;
-import org.meteoinfo.geo.shape.*;
-import org.meteoinfo.chart.legend.MarkerType;
-import org.meteoinfo.chart.legend.PointStyle;
-import org.meteoinfo.common.colors.ColorUtil;
-import org.meteoinfo.chart.legend.BreakTypes;
-import org.meteoinfo.chart.legend.ChartBreak;
-import org.meteoinfo.chart.legend.ChartTypes;
-import org.meteoinfo.chart.legend.ColorBreak;
-import org.meteoinfo.chart.legend.LabelBreak;
-import org.meteoinfo.chart.legend.LineStyles;
-import org.meteoinfo.chart.legend.PointBreak;
-import org.meteoinfo.chart.legend.PolygonBreak;
-import org.meteoinfo.chart.legend.PolylineBreak;
-import org.meteoinfo.chart.legend.VectorBreak;
-import java.awt.Color;
-import java.awt.Font;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.meteoinfo.geometry.shape.*;
-import org.meteoinfo.ui.resize.ResizeAbility;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
- /**
- * Graphic class
- *
- * @author Yaqiang Wang
- */
- public class Graphic {
- //
-
- private Shape _shape = null;
- private ColorBreak _legend = null;
- private ResizeAbility _resizeAbility = ResizeAbility.ResizeAll;
- //
- //
-
- /**
- * Constructor
- */
- public Graphic() {
- }
-
- /**
- * Constructor
- *
- * @param shape a shape
- * @param legend a legend
- */
- public Graphic(Shape shape, ColorBreak legend) {
- _shape = shape;
- _legend = legend;
- updateResizeAbility();
- }
- //
- //
-
- /**
- * Get shape
- *
- * @return Shape
- */
- public Shape getShape() {
- return _shape;
- }
-
- /**
- * Set shape
- *
- * @param aShape a shape
- */
- public void setShape(Shape aShape) {
- _shape = aShape;
- updateResizeAbility();
- }
-
- /**
- * Get legend
- *
- * @return Legend
- */
- public ColorBreak getLegend() {
- return _legend;
- }
-
- public void setLegend(ColorBreak legend) {
- _legend = legend;
- updateResizeAbility();
- updateResizeAbility();
- }
-
- /**
- * Get resize ability
- *
- * @return Resize ability
- */
- public ResizeAbility getResizeAbility() {
- return _resizeAbility;
- }
-
- /**
- * Get extent
- *
- * @return The extent
- */
- public Extent getExtent() {
- return this._shape.getExtent();
- }
-
- /**
- * Set extent
- * @param value The extent
- */
- public void setExtent(Extent value){
- this._shape.setExtent(value);
- }
-
- /**
- * Get is single legend or not
- * @return Boolean
- */
- public boolean isSingleLegend(){
- return true;
- }
-
- /**
- * Get if is GraphicCollection
- * @return Boolean
- */
- public boolean isCollection(){
- return false;
- }
-
- //
- //
- /**
- * Get graphics number
- * @return 1
- */
- public int getNumGraphics(){
- return 1;
- }
-
- /**
- * Get Graphic by index
- * @param idx Index
- * @return Graphic
- */
- public Graphic getGraphicN(int idx){
- return this;
- }
-
- /**
- * Get graphic list
- * @return Graphic list
- */
- public List getGraphics(){
- List gs = new ArrayList<>();
- gs.add(this);
- return gs;
- }
-
- private void updateResizeAbility() {
- if (_shape != null && _legend != null) {
- switch (_shape.getShapeType()) {
- case Point:
- switch (_legend.getBreakType()) {
- case PointBreak:
- _resizeAbility = ResizeAbility.SameWidthHeight;
- break;
- case LabelBreak:
- case ChartBreak:
- _resizeAbility = ResizeAbility.None;
- break;
- }
- break;
- case Circle:
- _resizeAbility = ResizeAbility.SameWidthHeight;
- break;
- default:
- _resizeAbility = ResizeAbility.ResizeAll;
- break;
- }
- }
- }
-
- /**
- * Vertice edited update
- *
- * @param vIdx Vertice index
- * @param newX New X
- * @param newY New Y
- */
- public void verticeMoveUpdate(int vIdx, double newX, double newY) {
- List points = (List)_shape.getPoints();
- switch (_shape.getShapeType()){
- case Polygon:
- case CurvePolygon:
- case Rectangle:
- int last = points.size() - 1;
- if (vIdx == 0) {
- if (points.get(0).X == points.get(last).X && points.get(0).Y == points.get(last).Y) {
- points.get(last).X = newX;
- points.get(last).Y = newY;
- }
- } else if (vIdx == last){
- if (points.get(0).X == points.get(last).X && points.get(0).Y == points.get(last).Y) {
- points.get(0).X = newX;
- points.get(0).Y = newY;
- }
- }
- break;
- }
-
- PointD aP = points.get(vIdx);
- aP.X = newX;
- aP.Y = newY;
- //points.set(vIdx, aP);
- _shape.setPoints(points);
- }
-
- /**
- * Vertice edited update
- *
- * @param vIdx Vertice index
- * @param point The add vertice
- */
- public void verticeAddUpdate(int vIdx, PointD point) {
- List points = (List)_shape.getPoints();
- points.add(vIdx, point);
- _shape.setPoints(points);
- }
-
- /**
- * Vertice edited update
- *
- * @param vIdx Vertice index
- */
- public void verticeRemoveUpdate(int vIdx) {
- List points = (List)_shape.getPoints();
- points.remove(vIdx);
- _shape.setPoints(points);
- }
-
- /**
- * Export to XML document
- * @param doc XML document
- * @param parent Parent XML element
- */
- public void exportToXML(Document doc, Element parent) {
- Element graphic = doc.createElement("Graphic");
- addShape(doc, graphic, _shape);
- addLegend(doc, graphic, _legend, _shape.getShapeType());
-
- parent.appendChild(graphic);
- }
-
- /**
- * Add shape to XML document
- * @param doc XML document
- * @param parent Parent XML element
- * @param aShape The shape
- */
- protected void addShape(Document doc, Element parent, Shape aShape) {
- Element shape = doc.createElement("Shape");
- boolean hasAngle = aShape.getShapeType() == ShapeTypes.Ellipse;
-
- //Add general attribute
- Attr shapeType = doc.createAttribute("ShapeType");
- Attr visible = doc.createAttribute("Visible");
- Attr selected = doc.createAttribute("Selected");
-
- //shapeType.InnerText = Enum.GetName(typeof(ShapeTypes), aShape.ShapeType);
- shapeType.setValue(aShape.getShapeType().toString());
- visible.setValue(String.valueOf(aShape.isVisible()));
- selected.setValue(String.valueOf(aShape.isSelected()));
-
- shape.setAttributeNode(shapeType);
- shape.setAttributeNode(visible);
- shape.setAttributeNode(selected);
-
- if (hasAngle){
- Attr angle = doc.createAttribute("Angle");
- angle.setValue(String.valueOf(((EllipseShape)aShape).getAngle()));
- shape.setAttributeNode(angle);
- }
-
- //Add points
- Element points = doc.createElement("Points");
- List pointList = (List)aShape.getPoints();
- for (PointD aPoint : pointList) {
- Element point = doc.createElement("Point");
- Attr x = doc.createAttribute("X");
- Attr y = doc.createAttribute("Y");
- x.setValue(String.valueOf(aPoint.X));
- y.setValue(String.valueOf(aPoint.Y));
- point.setAttributeNode(x);
- point.setAttributeNode(y);
-
- points.appendChild(point);
- }
-
- shape.appendChild(points);
-
- parent.appendChild(shape);
- }
-
- /**
- * Add legend to XML document
- * @param doc XML document
- * @param parent Parent XML element
- * @param aLegend The legend
- * @param shapeType The shape type
- */
- protected void addLegend(Document doc, Element parent, ColorBreak aLegend, ShapeTypes shapeType) {
- Element legend = doc.createElement("Legend");
- Attr color = doc.createAttribute("Color");
- color.setValue(ColorUtil.toHexEncoding(aLegend.getColor()));
- legend.setAttributeNode(color);
-
- Attr legendType = doc.createAttribute("LegendType");
- Attr size;
- Attr style;
- Attr outlineColor;
- Attr drawOutline;
- Attr drawFill;
- legendType.setValue(aLegend.getBreakType().toString());
- switch (aLegend.getBreakType()) {
- case PointBreak:
- PointBreak aPB = (PointBreak) aLegend;
- outlineColor = doc.createAttribute("OutlineColor");
- size = doc.createAttribute("Size");
- style = doc.createAttribute("Style");
- drawOutline = doc.createAttribute("DrawOutline");
- drawFill = doc.createAttribute("DrawFill");
- Attr markerType = doc.createAttribute("MarkerType");
- Attr fontName = doc.createAttribute("FontName");
- Attr charIndex = doc.createAttribute("CharIndex");
- Attr imagePath = doc.createAttribute("ImagePath");
- Attr angle = doc.createAttribute("Angle");
-
- //legendType.InnerText = "PointBreak";
- outlineColor.setValue(ColorUtil.toHexEncoding(aPB.getOutlineColor()));
- size.setValue(String.valueOf(aPB.getSize()));
- style.setValue(aPB.getStyle().toString());
- drawOutline.setValue(String.valueOf(aPB.isDrawOutline()));
- drawFill.setValue(String.valueOf(aPB.isDrawFill()));
- markerType.setValue(aPB.getMarkerType().toString());
- fontName.setValue(aPB.getFontName());
- charIndex.setValue(String.valueOf(aPB.getCharIndex()));
- imagePath.setValue(aPB.getImagePath());
- angle.setValue(String.valueOf(aPB.getAngle()));
-
- legend.setAttributeNode(legendType);
- legend.setAttributeNode(outlineColor);
- legend.setAttributeNode(size);
- legend.setAttributeNode(style);
- legend.setAttributeNode(drawOutline);
- legend.setAttributeNode(drawFill);
- legend.setAttributeNode(markerType);
- legend.setAttributeNode(fontName);
- legend.setAttributeNode(charIndex);
- legend.setAttributeNode(imagePath);
- legend.setAttributeNode(angle);
- break;
- case LabelBreak:
- LabelBreak aLB = (LabelBreak) aLegend;
- Attr text = doc.createAttribute("Text");
- angle = doc.createAttribute("Angle");
- fontName = doc.createAttribute("FontName");
- Attr fontSize = doc.createAttribute("FontSize");
- Attr fontBold = doc.createAttribute("FontBold");
- Attr yShift = doc.createAttribute("YShift");
-
- //legendType.InnerText = "LabelBreak";
- text.setValue(aLB.getText());
- angle.setValue(String.valueOf(aLB.getAngle()));
- fontName.setValue(aLB.getFont().getName());
- fontSize.setValue(String.valueOf(aLB.getFont().getSize()));
- fontBold.setValue(String.valueOf(aLB.getFont().isBold()));
- yShift.setValue(String.valueOf(aLB.getYShift()));
-
- legend.setAttributeNode(legendType);
- legend.setAttributeNode(text);
- legend.setAttributeNode(angle);
- legend.setAttributeNode(fontName);
- legend.setAttributeNode(fontSize);
- legend.setAttributeNode(fontBold);
- legend.setAttributeNode(yShift);
- break;
- case ChartBreak:
- ChartBreak aChB = (ChartBreak) aLegend;
- Attr shapeIndex = doc.createAttribute("ShapeIndex");
- Attr chartType = doc.createAttribute("ChartType");
- Attr chartData = doc.createAttribute("ChartData");
- Attr xShift = doc.createAttribute("XShift");
- yShift = doc.createAttribute("YShift");
- fontName = doc.createAttribute("FontName");
- fontSize = doc.createAttribute("FontSize");
- Attr labelColor = doc.createAttribute("LabelColor");
-
- shapeIndex.setValue(String.valueOf(aChB.getShapeIndex()));
- //legendType.InnerText = "ChartBreak";
- chartType.setValue(aChB.getChartType().toString());
- String cdata = "";
- for (int i = 0; i < aChB.getItemNum(); i++) {
- if (i == 0) {
- cdata = String.valueOf(aChB.getChartData().get(i));
- } else {
- cdata += "," + String.valueOf(aChB.getChartData().get(i));
- }
- }
- chartData.setValue(cdata);
- xShift.setValue(String.valueOf(aChB.getXShift()));
- yShift.setValue(String.valueOf(aChB.getYShift()));
- fontName.setValue(aChB.getLabelFont().getFontName());
- fontSize.setValue(String.valueOf(aChB.getLabelFont().getSize()));
- labelColor.setValue(ColorUtil.toHexEncoding(aChB.getLabelColor()));
-
- legend.setAttributeNode(legendType);
- legend.setAttributeNode(shapeIndex);
- legend.setAttributeNode(chartType);
- legend.setAttributeNode(chartData);
- legend.setAttributeNode(xShift);
- legend.setAttributeNode(yShift);
- legend.setAttributeNode(fontName);
- legend.setAttributeNode(fontSize);
- legend.setAttributeNode(labelColor);
- break;
- case VectorBreak:
- //legendType.InnerText = "VectorBreak";
- legend.setAttributeNode(legendType);
- break;
- case PolylineBreak:
- PolylineBreak aPLB = (PolylineBreak) aLegend;
- size = doc.createAttribute("Size");
- style = doc.createAttribute("Style");
- Attr drawSymbol = doc.createAttribute("DrawSymbol");
- Attr symbolSize = doc.createAttribute("SymbolSize");
- Attr symbolStyle = doc.createAttribute("SymbolStyle");
- Attr symbolColor = doc.createAttribute("SymbolColor");
- Attr symbolInterval = doc.createAttribute("SymbolInterval");
-
- //legendType.InnerText = "PolylineBreak";
- size.setValue(String.valueOf(aPLB.getWidth()));
- style.setValue(aPLB.getStyle().toString());
- drawSymbol.setValue(String.valueOf(aPLB.getDrawSymbol()));
- symbolSize.setValue(String.valueOf(aPLB.getSymbolSize()));
- symbolStyle.setValue(String.valueOf(aPLB.getSymbolStyle()));
- symbolColor.setValue(ColorUtil.toHexEncoding(aPLB.getSymbolColor()));
- symbolInterval.setValue(String.valueOf(aPLB.getSymbolInterval()));
-
- legend.setAttributeNode(legendType);
- legend.setAttributeNode(size);
- legend.setAttributeNode(style);
- legend.setAttributeNode(drawSymbol);
- legend.setAttributeNode(symbolSize);
- legend.setAttributeNode(symbolStyle);
- legend.setAttributeNode(symbolColor);
- legend.setAttributeNode(symbolInterval);
- break;
- case PolygonBreak:
- PolygonBreak aPGB = (PolygonBreak) aLegend;
- outlineColor = doc.createAttribute("OutlineColor");
- drawOutline = doc.createAttribute("DrawOutline");
- drawFill = doc.createAttribute("DrawFill");
- Attr outlineSize = doc.createAttribute("OutlineSize");
- //Attr usingHatchStyle = doc.createAttribute("UsingHatchStyle");
- //style = doc.createAttribute("Style");
- Attr backColor = doc.createAttribute("BackColor");
- //Attr transparencyPer = doc.createAttribute("TransparencyPercent");
- Attr isMaskout = doc.createAttribute("IsMaskout");
-
- //legendType.InnerText = "PolygonBreak";
- outlineColor.setValue(ColorUtil.toHexEncoding(aPGB.getOutlineColor()));
- drawOutline.setValue(String.valueOf(aPGB.isDrawOutline()));
- drawFill.setValue(String.valueOf(aPGB.isDrawFill()));
- outlineSize.setValue(String.valueOf(aPGB.getOutlineSize()));
- //usingHatchStyle.setValue(String.valueOf(aPGB.getUsingHatchStyle()));
- //style.setValue(String.valueOf(aPGB.getStyle()));
- backColor.setValue(ColorUtil.toHexEncoding(aPGB.getBackColor()));
- //transparencyPer.InnerText = aPGB.TransparencyPercent.ToString();
- isMaskout.setValue(String.valueOf(aPGB.isMaskout()));
-
- legend.setAttributeNode(legendType);
- legend.setAttributeNode(outlineColor);
- legend.setAttributeNode(drawOutline);
- legend.setAttributeNode(drawFill);
- legend.setAttributeNode(outlineSize);
- //legend.setAttributeNode(usingHatchStyle);
- //legend.setAttributeNode(style);
- legend.setAttributeNode(backColor);
- //legend.setAttributeNode(transparencyPer);
- legend.setAttributeNode(isMaskout);
- break;
- }
-
- parent.appendChild(legend);
- }
-
- /**
- * Import from xml node
- *
- * @param graphicNode Graphic xml node
- */
- public void importFromXML(Element graphicNode) {
- Node shape = graphicNode.getElementsByTagName("Shape").item(0);
- _shape = loadShape(shape);
-
- Node legend = graphicNode.getElementsByTagName("Legend").item(0);
- _legend = loadLegend(legend, _shape.getShapeType());
-
- updateResizeAbility();
- }
-
- protected Shape loadShape(Node shapeNode) {
- Shape aShape = null;
- try {
- ShapeTypes shapeType = ShapeTypes.valueOf(shapeNode.getAttributes().getNamedItem("ShapeType").getNodeValue());
- switch (shapeType) {
- case Point:
- aShape = new PointShape();
- break;
- case WindArraw:
- aShape = new WindArrow();
- break;
- case Polyline:
- aShape = new PolylineShape();
- break;
- case CurveLine:
- aShape = new CurveLineShape();
- break;
- case Circle:
- aShape = new CircleShape();
- break;
- case Polygon:
- case Rectangle:
- aShape = new PolygonShape();
- break;
- case CurvePolygon:
- aShape = new CurvePolygonShape();
- break;
- case Ellipse:
- aShape = new EllipseShape();
- break;
- }
-
- aShape.setVisible(Boolean.parseBoolean(shapeNode.getAttributes().getNamedItem("Visible").getNodeValue()));
- aShape.setSelected(Boolean.parseBoolean(shapeNode.getAttributes().getNamedItem("Selected").getNodeValue()));
- if (aShape.getShapeType() == ShapeTypes.Ellipse){
- Node angleNode = shapeNode.getAttributes().getNamedItem("Angle");
- if (angleNode != null)
- ((EllipseShape)aShape).setAngle(Float.parseFloat(angleNode.getNodeValue()));
- }
-
- List pointList = new ArrayList<>();
- Node pointsNode = ((Element)shapeNode).getElementsByTagName("Points").item(0);
- NodeList nl = ((Element)pointsNode).getElementsByTagName("Point");
- for (int i = 0; i < nl.getLength(); i++) {
- Node pNode = nl.item(i);
- PointD aPoint = new PointD(Double.parseDouble(pNode.getAttributes().getNamedItem("X").getNodeValue()),
- Double.parseDouble(pNode.getAttributes().getNamedItem("Y").getNodeValue()));
- pointList.add(aPoint);
- }
- aShape.setPoints(pointList);
- } catch (Exception e) {
- }
-
- return aShape;
- }
-
- protected ColorBreak loadLegend(Node legendNode, ShapeTypes shapeType) {
- ColorBreak legend = new ColorBreak();
- try {
- Color color = ColorUtil.parseToColor(legendNode.getAttributes().getNamedItem("Color").getNodeValue());
- String legendType = legendNode.getAttributes().getNamedItem("LegendType").getNodeValue();
- BreakTypes breakType = BreakTypes.valueOf(legendType);
- switch (breakType) {
- case PointBreak:
- PointBreak aPB = new PointBreak();
- try {
- aPB.setColor(color);
- aPB.setDrawFill(Boolean.parseBoolean(legendNode.getAttributes().getNamedItem("DrawFill").getNodeValue()));
- aPB.setDrawOutline(Boolean.parseBoolean(legendNode.getAttributes().getNamedItem("DrawOutline").getNodeValue()));
- aPB.setOutlineColor(ColorUtil.parseToColor(legendNode.getAttributes().getNamedItem("OutlineColor").getNodeValue()));
- aPB.setSize(Float.parseFloat(legendNode.getAttributes().getNamedItem("Size").getNodeValue()));
- aPB.setStyle(PointStyle.valueOf(legendNode.getAttributes().getNamedItem("Style").getNodeValue()));
- aPB.setMarkerType(MarkerType.valueOf(legendNode.getAttributes().getNamedItem("MarkerType").getNodeValue()));
- aPB.setFontName(legendNode.getAttributes().getNamedItem("FontName").getNodeValue());
- aPB.setCharIndex(Integer.parseInt(legendNode.getAttributes().getNamedItem("CharIndex").getNodeValue()));
- aPB.setImagePath(legendNode.getAttributes().getNamedItem("ImagePath").getNodeValue());
- aPB.setAngle(Float.parseFloat(legendNode.getAttributes().getNamedItem("Angle").getNodeValue()));
- } catch (Exception e) {
- } finally {
- legend = aPB;
- }
- break;
- case LabelBreak:
- LabelBreak aLB = new LabelBreak();
- try {
- aLB.setColor(color);
- aLB.setAngle(Float.parseFloat(legendNode.getAttributes().getNamedItem("Angle").getNodeValue()));
- aLB.setText(legendNode.getAttributes().getNamedItem("Text").getNodeValue());
- String fontName = legendNode.getAttributes().getNamedItem("FontName").getNodeValue();
- float fontSize = Float.parseFloat(legendNode.getAttributes().getNamedItem("FontSize").getNodeValue());
- boolean fontBold = Boolean.parseBoolean(legendNode.getAttributes().getNamedItem("FontBold").getNodeValue());
- if (fontBold) {
- aLB.setFont(new Font(fontName, Font.BOLD, (int) fontSize));
- } else {
- aLB.setFont(new Font(fontName, Font.PLAIN, (int) fontSize));
- }
-
- aLB.setYShift(Float.parseFloat(legendNode.getAttributes().getNamedItem("YShift").getNodeValue()));
- } catch (Exception e) {
- } finally {
- legend = aLB;
- }
- break;
- case ChartBreak:
- ChartBreak aChB = new ChartBreak(ChartTypes.BarChart);
- try {
- ChartTypes chartType = ChartTypes.valueOf(legendNode.getAttributes().getNamedItem("ChartType").getNodeValue());
- aChB = new ChartBreak(chartType);
- aChB.setShapeIndex(Integer.parseInt(legendNode.getAttributes().getNamedItem("ShapeIndex").getNodeValue()));
- List cData = new ArrayList();
- String[] cDataStr = legendNode.getAttributes().getNamedItem("ChartData").getNodeValue().split(",");
- for (int i = 0; i < cDataStr.length; i++) {
- cData.add(Float.parseFloat(cDataStr[i]));
- }
-
- aChB.setChartData(cData);
- aChB.setXShift(Integer.parseInt(legendNode.getAttributes().getNamedItem("XShift").getNodeValue()));
- aChB.setYShift(Integer.parseInt(legendNode.getAttributes().getNamedItem("YShift").getNodeValue()));
- String fontName = legendNode.getAttributes().getNamedItem("FontName").getNodeValue();
- float fontSize = Float.parseFloat(legendNode.getAttributes().getNamedItem("FontSize").getNodeValue());
- aChB.setLabelFont(new Font(fontName, Font.PLAIN, (int)fontSize));
- aChB.setLabelColor(ColorUtil.parseToColor(legendNode.getAttributes().getNamedItem("LabelColor").getNodeValue()));
- } catch (Exception e) {
- } finally {
- legend = aChB;
- }
- break;
- case VectorBreak:
- VectorBreak aVB = new VectorBreak();
- try {
- aVB.setColor(color);
- } catch (Exception e) {
- } finally {
- legend = aVB;
- }
- break;
- case PolylineBreak:
- PolylineBreak aPLB = new PolylineBreak();
- try {
- aPLB.setColor(color);
- aPLB.setWidth(Float.parseFloat(legendNode.getAttributes().getNamedItem("Size").getNodeValue()));
- aPLB.setStyle(LineStyles.valueOf(legendNode.getAttributes().getNamedItem("Style").getNodeValue()));
- aPLB.setDrawSymbol(Boolean.parseBoolean(legendNode.getAttributes().getNamedItem("DrawSymbol").getNodeValue()));
- aPLB.setSymbolSize(Float.parseFloat(legendNode.getAttributes().getNamedItem("SymbolSize").getNodeValue()));
- aPLB.setSymbolStyle(PointStyle.valueOf(legendNode.getAttributes().getNamedItem("SymbolStyle").getNodeValue()));
- aPLB.setSymbolColor(ColorUtil.parseToColor(legendNode.getAttributes().getNamedItem("SymbolColor").getNodeValue()));
- aPLB.setSymbolInterval(Integer.parseInt(legendNode.getAttributes().getNamedItem("SymbolInterval").getNodeValue()));
- } catch (Exception e) {
- } finally {
- legend = aPLB;
- }
- break;
- case PolygonBreak:
- PolygonBreak aPGB = new PolygonBreak();
- try {
- aPGB.setColor(color);
- aPGB.setDrawFill(Boolean.parseBoolean(legendNode.getAttributes().getNamedItem("DrawFill").getNodeValue()));
- aPGB.setDrawOutline(Boolean.parseBoolean(legendNode.getAttributes().getNamedItem("DrawOutline").getNodeValue()));
- aPGB.setOutlineSize(Float.parseFloat(legendNode.getAttributes().getNamedItem("OutlineSize").getNodeValue()));
- aPGB.setOutlineColor(ColorUtil.parseToColor(legendNode.getAttributes().getNamedItem("OutlineColor").getNodeValue()));
- //aPGB.UsingHatchStyle = bool.Parse(legendNode.Attributes["UsingHatchStyle"].InnerText);
- //aPGB.Style = (HatchStyle)Enum.Parse(typeof(HatchStyle), legendNode.Attributes["Style"].InnerText, true);
- aPGB.setBackColor(ColorUtil.parseToColor(legendNode.getAttributes().getNamedItem("BackColor").getNodeValue()));
- //aPGB.TransparencyPercent = int.Parse(legendNode.Attributes["TransparencyPercent"].InnerText);
- aPGB.setMaskout(Boolean.parseBoolean(legendNode.getAttributes().getNamedItem("IsMaskout").getNodeValue()));
- } catch (Exception e) {
- } {
- legend = aPGB;
- }
- break;
- }
- } catch (Exception e) {
- }
- return legend;
- }
- //
- }
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/GraphicCollection.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/GraphicCollection.java
deleted file mode 100644
index cb038eb3..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/GraphicCollection.java
+++ /dev/null
@@ -1,692 +0,0 @@
-/* Copyright 2012 Yaqiang Wang,
- * yaqiang.wang@gmail.com
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- */
-package org.meteoinfo.chart.graphic;
-
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.common.MIMath;
-import org.meteoinfo.common.PointD;
-import org.meteoinfo.geometry.geoprocess.GeoComputation;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-import org.meteoinfo.geo.shape.*;
-import org.meteoinfo.chart.legend.LabelSet;
-import org.meteoinfo.chart.legend.BreakTypes;
-import org.meteoinfo.chart.legend.ColorBreak;
-import org.meteoinfo.chart.legend.LabelBreak;
-import org.meteoinfo.chart.legend.LegendScheme;
-import org.meteoinfo.chart.legend.PointBreak;
-import org.meteoinfo.geometry.shape.*;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class GraphicCollection extends Graphic implements Iterator {
-
- //
- private List graphics = new ArrayList<>();
- private Extent _extent = new Extent();
- protected boolean singleLegend = true;
- private int index;
- private LabelSet labelSet;
- private List labelPoints;
- protected LegendScheme legendScheme;
- protected ColorBreak legendBreak;
- //
- //
-
- /**
- * Constructor
- */
- public GraphicCollection() {
- this.index = 0;
- labelSet = new LabelSet();
- labelPoints = new ArrayList<>();
- }
-
- //
- //
- /**
- * Get graphic list
- *
- * @return Graphic list
- */
- @Override
- public List getGraphics() {
- return this.graphics;
- }
-
- /**
- * Set graphic list
- *
- * @param value Graphic list
- */
- public void setGraphics(List value) {
- this.graphics = value;
- }
-
- /**
- * Get extent
- *
- * @return The extent
- */
- @Override
- public Extent getExtent() {
- return _extent;
- }
-
- /**
- * Set extent
- *
- * @param value Extent
- */
- @Override
- public void setExtent(Extent value) {
- this._extent = value;
- }
-
- /**
- * Get is single legend or not
- *
- * @return Boolean
- */
- @Override
- public boolean isSingleLegend() {
- return this.singleLegend;
- }
-
- /**
- * Set is single legend or not
- *
- * @param value Boolean
- */
- public void setSingleLegend(boolean value) {
- this.singleLegend = value;
- }
-
- /**
- * Get label set
- *
- * @return Label set
- */
- public LabelSet getLabelSet() {
- return labelSet;
- }
-
- /**
- * Set label set
- *
- * @param ls Label set
- */
- public void setLabelSet(LabelSet ls) {
- labelSet = ls;
- }
-
- /**
- * Get label points
- *
- * @return The lable points
- */
- public List getLabelPoints() {
- return this.labelPoints;
- }
-
- /**
- * Set label points
- *
- * @param lps The lable points
- */
- public void setLabelPoints(List lps) {
- this.labelPoints = lps;
- }
-
- /**
- * Get legend scheme
- *
- * @return Legend scheme
- */
- public LegendScheme getLegendScheme() {
- return this.legendScheme;
- }
-
- /**
- * Set legend scheme
- *
- * @param value Legend scheme
- */
- public void setLegendScheme(LegendScheme value) {
- this.legendScheme = value;
- }
-
- /**
- * Get legend break
- *
- * @return Legend break
- */
- public ColorBreak getLegendBreak() {
- return this.legendBreak;
- }
-
- /**
- * Set legend break
- *
- * @param value Legend break
- */
- public void setLegendBreak(ColorBreak value) {
- this.legendBreak = value;
- }
-
- /**
- * Get is 3D or not
- *
- * @return Boolean
- */
- public boolean is3D() {
- return false;
- }
-
- /**
- * Get if is GraphicCollection
- *
- * @return Boolean
- */
- @Override
- public boolean isCollection() {
- return true;
- }
-
- //
- //
- /**
- * Update extent
- */
- public void updateExtent() {
- int i = 0;
- Extent extent;
- for (Graphic g : this.graphics) {
- if (g instanceof GraphicCollection) {
- extent = g.getExtent();
- } else {
- extent = g.getShape().getExtent();
- }
- if (i == 0) {
- _extent = extent;
- } else {
- _extent = MIMath.getLagerExtent(_extent, extent);
- }
-
- i += 1;
- }
- }
-
- /**
- * Add a graphic
- *
- * @param aGraphic The graphic
- * @return Boolean
- */
- public boolean add(Graphic aGraphic) {
- boolean istrue = this.graphics.add(aGraphic);
-
- //Update extent
- if (this.graphics.size() == 1) {
- _extent = aGraphic.getExtent();
- } else {
- _extent = MIMath.getLagerExtent(_extent, aGraphic.getExtent());
- }
-
- return istrue;
- }
-
- /**
- * Inset a graphic
- *
- * @param index Index
- * @param aGraphic The graphic
- */
- public void add(int index, Graphic aGraphic) {
- this.graphics.add(index, aGraphic);
-
- //Update extent
- if (this.graphics.size() == 1) {
- _extent = aGraphic.getShape().getExtent();
- } else {
- _extent = MIMath.getLagerExtent(_extent, aGraphic.getShape().getExtent());
- }
- }
-
- /**
- * Get a graphic by index
- *
- * @param idx Index
- * @return Graphic
- */
- public Graphic get(int idx) {
- return this.graphics.get(idx);
- }
-
- /**
- * Index of
- *
- * @param g Graphic
- * @return Index
- */
- public int indexOf(Graphic g) {
- return this.graphics.indexOf(g);
- }
-
- /**
- * Contains or not
- *
- * @param g Graphic
- * @return Boolean
- */
- public boolean contains(Graphic g) {
- return this.graphics.contains(g);
- }
-
- /**
- * Get graphic list size
- *
- * @return Gaphic list size
- */
- public int size() {
- return this.graphics.size();
- }
-
- /**
- * Get is empty or not
- *
- * @return Boolean
- */
- public boolean isEmpty() {
- return this.graphics.isEmpty();
- }
-
- /**
- * Get graphics number
- *
- * @return 1
- */
- @Override
- public int getNumGraphics() {
- return this.size();
- }
-
- /**
- * Get Graphic by index
- *
- * @param idx Index
- * @return Graphic
- */
- @Override
- public Graphic getGraphicN(int idx) {
- return this.get(idx);
- }
-
- /**
- * Remove a graphic
- *
- * @param aGraphic The graphic
- * @return Boolean
- */
- public boolean remove(Graphic aGraphic) {
- boolean istrue = this.graphics.remove(aGraphic);
- this.updateExtent();
-
- return istrue;
- }
-
- /**
- * Remove a graphic by index
- *
- * @param index The index
- * @return The removed graphic
- */
- public Graphic remove(int index) {
- Graphic ag = this.graphics.remove(index);
- this.updateExtent();
-
- return ag;
- }
-
- /**
- * Clear graphics
- */
- public void clear() {
- this.graphics.clear();
- }
-
- /**
- * Add all
- *
- * @param gs Graphic list
- */
- public void addAll(List gs) {
- this.graphics.addAll(gs);
- }
-
- /**
- * Join this graphics with other graphics
- *
- * @param graphic Other graphics
- */
- public void join(Graphic graphic) {
- if (graphic.isCollection()) {
- //Update extent
- if (this.isEmpty()) {
- _extent = graphic.getExtent();
- } else {
- _extent = MIMath.getLagerExtent(_extent, graphic.getExtent());
- }
- for (int i = 0; i < graphic.getNumGraphics(); i++) {
- this.graphics.add(graphic.getGraphicN(i));
- }
- } else {
- this.add(graphic);
- }
- }
-
- /**
- * Remove all
- *
- * @param gs Graphic list
- */
- public void removeAll(List gs) {
- this.graphics.removeAll(gs);
- }
-
- /**
- * Get legend
- *
- * @return Legend
- */
- @Override
- public ColorBreak getLegend() {
- if (this.legendBreak != null) {
- return this.legendBreak;
- } else {
- return this.graphics.get(0).getLegend();
- }
- }
-
- /**
- * Select graphics by an extent
- *
- * @param aExtent The extent
- * @return Selected graphics
- */
- public GraphicCollection selectGraphics(Extent aExtent) {
- GraphicCollection selectedGraphics = new GraphicCollection();
- int i, j;
- PointD aPoint = new PointD();
- aPoint.X = (aExtent.minX + aExtent.maxX) / 2;
- aPoint.Y = (aExtent.minY + aExtent.maxY) / 2;
-
- for (Graphic aGraphic : this.graphics) {
- switch (aGraphic.getShape().getShapeType()) {
- case Point:
- PointShape aPS = (PointShape) aGraphic.getShape();
- if (MIMath.pointInExtent(aPS.getPoint(), aExtent)) {
- selectedGraphics.add(aGraphic);
- }
- break;
- case Polyline:
- case PolylineZ:
- PolylineShape aPLS = (PolylineShape) aGraphic.getShape();
- if (MIMath.isExtentCross(aExtent, aPLS.getExtent())) {
- for (j = 0; j < aPLS.getPoints().size(); j++) {
- aPoint = aPLS.getPoints().get(j);
- if (MIMath.pointInExtent(aPoint, aExtent)) {
- selectedGraphics.add(aGraphic);
- break;
- }
- }
- }
- break;
- case Polygon:
- case Rectangle:
- PolygonShape aPGS = (PolygonShape) aGraphic.getShape();
- if (!(aPGS.getPartNum() > 1)) {
- if (GeoComputation.pointInPolygon((List) aPGS.getPoints(), aPoint)) {
- selectedGraphics.add(aGraphic);
- }
- } else {
- for (int p = 0; p < aPGS.getPartNum(); p++) {
- ArrayList pList = new ArrayList();
- if (p == aPGS.getPartNum() - 1) {
- for (int pp = aPGS.parts[p]; pp < aPGS.getPointNum(); pp++) {
- pList.add(aPGS.getPoints().get(pp));
- }
- } else {
- for (int pp = aPGS.parts[p]; pp < aPGS.parts[p + 1]; pp++) {
- pList.add(aPGS.getPoints().get(pp));
- }
- }
- if (GeoComputation.pointInPolygon(pList, aPoint)) {
- selectedGraphics.add(aGraphic);
- break;
- }
- }
- }
- break;
- }
- }
-
- return selectedGraphics;
- }
-
- @Override
- public boolean hasNext() {
- return index <= this.size() - 1;
- }
-
- @Override
- public Object next() {
- if (index >= this.size()) {
- throw new NoSuchElementException();
- }
-
- return this.get(index++);
- }
-
- /**
- * Add labels
- */
- public void addLabels() {
- addLabelsByColor();
-
- labelSet.setDrawLabels(true);
- }
-
- /**
- * Get shapes
- *
- * @return Shapes
- */
- public List getShapes() {
- List shapes = new ArrayList<>();
- for (Graphic g : this.graphics) {
- shapes.add(g.getShape());
- }
- return shapes;
- }
-
- /**
- * Get shape type
- *
- * @return Shape type
- */
- public ShapeTypes getShapeType() {
- return this.graphics.get(0).getShape().getShapeType();
- }
-
- private double getMinValue() {
- double min = Double.MAX_VALUE;
- for (Graphic graphic : this.graphics) {
- Shape shape = graphic.getShape();
- if (min > shape.getValue()) {
- min = shape.getValue();
- }
- }
- return min;
- }
-
- /**
- * Add labels
- */
- private void addLabelsByColor() {
- if (labelSet.isAutoDecimal()) {
- double min = getMinValue();
- labelSet.setDecimalDigits(MIMath.getDecimalNum(min));
- }
- String dFormat = "%1$." + String.valueOf(labelSet.getDecimalDigits()) + "f";
- PointD aPoint;
- for (Graphic graphic : this.graphics) {
- ColorBreak cb = graphic.getLegend();
- Shape shape = graphic.getShape();
- PointShape aPS = new PointShape();
- switch (shape.getShapeType()) {
- case Point:
- case PointM:
- case PointZ:
- aPS.setPoint((PointD) ((PointShape) shape).getPoint().clone());
- break;
- case Polyline:
- case PolylineM:
- case PolylineZ:
- int pIdx = ((PolylineShape) shape).getPoints().size() / 2;
- aPS.setPoint((PointD) ((PolylineShape) shape).getPoints().get(pIdx - 1).clone());
- break;
- case Polygon:
- case PolygonM:
- 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();
- //aLP.setText(DataConvert.removeTailingZeros(String.valueOf(shape.getValue())));
- aLP.setText(String.format(dFormat, shape.getValue()));
- if (labelSet.isColorByLegend()) {
- aLP.setColor(cb.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);
- }
- }
-
- /**
- * Add label point
- *
- * @param aLP Label point
- */
- public void addLabel(Graphic aLP) {
- labelPoints.add(aLP);
- }
-
- /**
- * Add labels of contour layer dynamicly
- *
- * @param sExtent View extent of MapView
- */
- public void addLabelsContourDynamic(Extent sExtent) {
- if (labelSet.isAutoDecimal()) {
- double min = getMinValue();
- labelSet.setDecimalDigits(MIMath.getDecimalNum(min));
- }
- String dFormat = "%1$." + String.valueOf(labelSet.getDecimalDigits()) + "f";
- String text;
- for (Graphic graphic : this.graphics) {
- Shape shape = graphic.getShape();
- ColorBreak cb = graphic.getLegend();
- PolylineShape aPLS = (PolylineShape) shape;
- Extent IExtent = aPLS.getExtent();
- if (IExtent.maxX - IExtent.minX > (sExtent.maxX - sExtent.minX) / 10
- || IExtent.maxY - IExtent.minY > (sExtent.maxY - sExtent.minY) / 10) {
- LabelBreak aLP = new LabelBreak();
- int pIdx = aPLS.getPoints().size() / 2;
- //PointF aPoint = new PointF(0, 0);
- PointShape aPS = new PointShape();
- aPS.setPoint(aPLS.getPoints().get(pIdx - 1));
- //text = DataConvert.removeTailingZeros(String.valueOf(aPLS.getValue()));
- text = String.format(dFormat, aPLS.getValue());
- aLP.setText(text);
- aLP.setFont(labelSet.getLabelFont());
- aLP.setAlignType(labelSet.getLabelAlignType());
- aLP.setYShift(labelSet.getYOffset());
- if (labelSet.isColorByLegend()) {
- aLP.setColor(cb.getColor());
- } else {
- aLP.setColor(labelSet.getLabelColor());
- }
- Graphic aGraphic = new Graphic(aPS, aLP);
- addLabel(aGraphic);
- }
- }
-
- labelSet.setDrawLabels(true);
- }
-
- /**
- * Get arrow zoom
- *
- * @return Arrow zoom
- */
- public float getArrowZoom() {
- if (this.getLegend().getBreakType() == BreakTypes.PointBreak) {
- float size = ((PointBreak) this.getLegend()).getSize();
- return size / 10;
- }
-
- return 1.0f;
- }
-
- /**
- * Clip
- *
- * @param clipPolys Clipping polygons
- * @return Clipped graphics
- */
- public GraphicCollection clip(List clipPolys) {
- GraphicCollection cgraphics = new GraphicCollection();
- for (PolygonShape aPGS : clipPolys) {
- for (int i = 0; i < this.graphics.size(); i++) {
- Shape bShape = this.graphics.get(i).getShape();
- Shape clipShape = bShape.intersection(aPGS);
- if (clipShape != null) {
- cgraphics.add(new Graphic(clipShape, this.graphics.get(i).getLegend()));
- }
- }
- }
- cgraphics.setSingleLegend(this.singleLegend);
- cgraphics.setLegendScheme((LegendScheme) this.getLegendScheme().clone());
-
- return cgraphics;
- }
- //
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/ImageGraphic.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/ImageGraphic.java
deleted file mode 100644
index ca4bbc4b..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/ImageGraphic.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package org.meteoinfo.chart.graphic;
-
-import org.meteoinfo.geometry.shape.ImageShape;
-import org.meteoinfo.chart.legend.ColorBreak;
-import org.meteoinfo.chart.legend.LegendScheme;
-
-public class ImageGraphic extends Graphic{
- protected LegendScheme legendScheme;
-
- /**
- * Constructor
- */
- public ImageGraphic() {
- super();
- }
-
- /**
- * Constructor
- * @param shape The image shape
- * @param ls
- */
- public ImageGraphic(ImageShape shape, LegendScheme ls) {
- super(shape, new ColorBreak());
- this.legendScheme = ls;
- }
-
- /**
- * Get legend scheme
- *
- * @return Legend scheme
- */
- public LegendScheme getLegendScheme() {
- return this.legendScheme;
- }
-
- /**
- * Set legend scheme
- *
- * @param value Legend scheme
- */
- public void setLegendScheme(LegendScheme value) {
- this.legendScheme = value;
- }
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/PolylineErrorShape.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/PolylineErrorShape.java
deleted file mode 100644
index 9b3c2f9b..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/graphic/PolylineErrorShape.java
+++ /dev/null
@@ -1,195 +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.graphic;
-
-import org.meteoinfo.geometry.shape.PolylineShape;
-import org.meteoinfo.geometry.shape.ShapeTypes;
-import org.meteoinfo.ndarray.Array;
-
-import java.util.List;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public class PolylineErrorShape extends PolylineShape {
- //
- private double[] xerror;
- private double[] yerror;
- //
- //
- //
- //
- /**
- * Get X error data
- * @return X error data
- */
- public double[] getXerror(){
- return this.xerror;
- }
-
- /**
- * Set X error data
- * @param value X error data
- */
- public void setXerror(double[] value){
- this.xerror = value;
- }
-
- /**
- * Set x error data
- * @param value X error data
- */
- public void setXerror(double value){
- this.xerror = new double[this.getPointNum()];
- for (int i = 0; i < this.xerror.length; i++){
- this.xerror[i] = value;
- }
- }
-
- /**
- * Set X error data
- * @param value X error data
- */
- public void setXerror(List value){
- this.xerror = new double[value.size()];
- double v;
- for (int i = 0; i < value.size(); i++){
- v = value.get(i).doubleValue();
- xerror[i] = v;
- }
- }
-
- /**
- * Set X error data
- * @param value X error data
- */
- public void setXerror(Array value){
- this.xerror = new double[(int)value.getSize()];
- double v;
- for (int i = 0; i < xerror.length; i++){
- v = value.getDouble(i);
- xerror[i] = v;
- }
- }
-
- /**
- * Get Y error data
- * @return Y error data
- */
- public double[] getYerror(){
- return this.yerror;
- }
-
- /**
- * Set Y error data
- * @param value Y error data
- */
- public void setYerror(double[] value){
- this.yerror = value;
- }
-
- /**
- * Set y error data
- * @param value Y error data
- */
- public void setYerror(double value){
- this.yerror = new double[this.getPointNum()];
- for (int i = 0; i < this.yerror.length; i++){
- this.yerror[i] = value;
- }
- }
-
- /**
- * Set Y error data
- * @param value Y error data
- */
- public void setYerror(List value){
- this.yerror = new double[value.size()];
- double v;
- for (int i = 0; i < value.size(); i++){
- v = value.get(i).doubleValue();
- yerror[i] = v;
- }
- }
-
- /**
- * Set Y error data
- * @param value Y error data
- */
- public void setYerror(Array value){
- this.yerror = new double[(int)value.getSize()];
- double v;
- for (int i = 0; i < yerror.length; i++){
- v = value.getDouble(i);
- yerror[i] = v;
- }
- }
- //
- //
- @Override
- public ShapeTypes getShapeType(){
- return ShapeTypes.PolylineError;
- }
-
- /**
- * Get y error
- * @param idx Index
- * @return Y error
- */
- public double getYerror(int idx){
- return this.yerror[idx];
- }
-
- /**
- * Get x error
- * @param idx Index
- * @return X error
- */
- public double getXerror(int idx){
- return this.xerror[idx];
- }
-
- /**
- * Update extent
- */
- public void updateExtent(){
- double min = 0, max = 0, v;
- if (this.xerror != null){
- for (int i = 0; i < this.xerror.length; i++){
- v = this.xerror[i];
- if (i == 0){
- min = v;
- max = v;
- } else {
- if (v < min)
- min = v;
- else if (v > max)
- max = v;
- }
- }
- this.getExtent().minX -= max;
- this.getExtent().maxX += max;
- }
- if (this.yerror != null){
- for (int i = 0; i < this.yerror.length; i++){
- v = this.yerror[i];
- if (i == 0){
- min = v;
- max = v;
- } else {
- if (v < min)
- min = v;
- else if (v > max)
- max = v;
- }
- }
- this.getExtent().minY -= max;
- this.getExtent().maxY += max;
- }
- }
- //
-}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/GLChartPanel.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/GLChartPanel.java
similarity index 99%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/GLChartPanel.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/GLChartPanel.java
index 46276ab1..bbf7f4cc 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/GLChartPanel.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/GLChartPanel.java
@@ -8,7 +8,17 @@ package org.meteoinfo.chart.jogl;
import com.jogamp.opengl.*;
import com.jogamp.opengl.awt.GLJPanel;
import com.jogamp.opengl.util.FPSAnimator;
+import org.meteoinfo.chart.IChartPanel;
+import org.meteoinfo.chart.MouseMode;
+import org.meteoinfo.common.Extent3D;
+import org.meteoinfo.image.ImageUtil;
+import org.w3c.dom.Element;
+import javax.imageio.*;
+import javax.imageio.metadata.IIOMetadata;
+import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
+import javax.imageio.stream.ImageOutputStream;
+import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
@@ -17,17 +27,6 @@ import java.io.IOException;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.imageio.*;
-import javax.imageio.metadata.IIOMetadata;
-import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
-import javax.imageio.stream.ImageOutputStream;
-import javax.swing.*;
-
-import org.meteoinfo.chart.IChartPanel;
-import org.meteoinfo.chart.MouseMode;
-import org.meteoinfo.common.Extent3D;
-import org.meteoinfo.image.ImageUtil;
-import org.w3c.dom.Element;
/**
*
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/GLForm.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/GLForm.java
similarity index 93%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/GLForm.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/GLForm.java
index 0c86ca4f..04e310d2 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/GLForm.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/GLForm.java
@@ -1,42 +1,43 @@
-/*
- * 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.jogl;
-
-import com.jogamp.opengl.GLCapabilities;
-import com.jogamp.opengl.GLProfile;
-import javax.swing.JFrame;
-
-/**
- *
- * @author yaqiang
- */
-public class GLForm extends JFrame{
- private Plot3DGL plt;
- private GLChartPanel glcp;
-
- public GLForm(Plot3DGL plt) {
- this.plt = plt;
- final GLProfile gp = GLProfile.get(GLProfile.GL2);
- GLCapabilities cap = new GLCapabilities(gp);
-
- glcp = new GLChartPanel(cap, plt);
- glcp.setSize(400, 400);
-
- this.getContentPane().add(glcp);
-
- addWindowListener(new java.awt.event.WindowAdapter() {
- public void windowClosing(java.awt.event.WindowEvent evt) {
- formWindowClosing();
- }
- });
-
- glcp.animator_start();
- }
-
- private void formWindowClosing() {
- glcp.animator_stop();
- }
-}
+/*
+ * 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.jogl;
+
+import com.jogamp.opengl.GLCapabilities;
+import com.jogamp.opengl.GLProfile;
+
+import javax.swing.*;
+
+/**
+ *
+ * @author yaqiang
+ */
+public class GLForm extends JFrame{
+ private Plot3DGL plt;
+ private GLChartPanel glcp;
+
+ public GLForm(Plot3DGL plt) {
+ this.plt = plt;
+ final GLProfile gp = GLProfile.get(GLProfile.GL2);
+ GLCapabilities cap = new GLCapabilities(gp);
+
+ glcp = new GLChartPanel(cap, plt);
+ glcp.setSize(400, 400);
+
+ this.getContentPane().add(glcp);
+
+ addWindowListener(new java.awt.event.WindowAdapter() {
+ public void windowClosing(java.awt.event.WindowEvent evt) {
+ formWindowClosing();
+ }
+ });
+
+ glcp.animator_start();
+ }
+
+ private void formWindowClosing() {
+ glcp.animator_stop();
+ }
+}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/IsosurfaceGraphics.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/IsosurfaceGraphics.java
similarity index 96%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/IsosurfaceGraphics.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/IsosurfaceGraphics.java
index 9136e4c6..667914e5 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/IsosurfaceGraphics.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/IsosurfaceGraphics.java
@@ -5,13 +5,14 @@
*/
package org.meteoinfo.chart.jogl;
-import java.util.ArrayList;
-import java.util.List;
import org.meteoinfo.chart.plot3d.GraphicCollection3D;
import org.meteoinfo.common.Extent3D;
import org.meteoinfo.common.MIMath;
-import org.meteoinfo.geoprocess.GeometryUtil;
import org.meteoinfo.geometry.shape.PointZ;
+import org.meteoinfo.geometry.geoprocess.GeometryUtil;
+
+import java.util.ArrayList;
+import java.util.List;
/**
*
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/JOGLUtil.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/JOGLUtil.java
similarity index 99%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/JOGLUtil.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/JOGLUtil.java
index 07464e06..c98784e0 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/JOGLUtil.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/JOGLUtil.java
@@ -6,30 +6,29 @@
package org.meteoinfo.chart.jogl;
import com.jogamp.opengl.GL2;
+import org.meteoinfo.chart.jogl.mc.CallbackMC;
+import org.meteoinfo.chart.jogl.mc.MarchingCubes;
+import org.meteoinfo.chart.plot3d.GraphicCollection3D;
+import org.meteoinfo.common.Extent;
+import org.meteoinfo.common.Extent3D;
+import org.meteoinfo.geo.layer.ImageLayer;
+import org.meteoinfo.geometry.graphic.Graphic;
+import org.meteoinfo.geometry.graphic.GraphicCollection;
+import org.meteoinfo.geometry.legend.ColorBreak;
+import org.meteoinfo.geometry.legend.LegendScheme;
+import org.meteoinfo.geometry.legend.PolygonBreak;
+import org.meteoinfo.geometry.shape.ImageShape;
+import org.meteoinfo.geometry.shape.PointZ;
+import org.meteoinfo.ndarray.Array;
+import org.meteoinfo.ndarray.Index;
+import org.meteoinfo.ndarray.InvalidRangeException;
+import org.meteoinfo.ndarray.math.ArrayUtil;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
-import org.meteoinfo.chart.jogl.mc.MarchingCubes;
-import org.meteoinfo.chart.jogl.mc.CallbackMC;
-import org.meteoinfo.chart.plot3d.GraphicCollection3D;
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.common.Extent3D;
-import org.meteoinfo.geometry.legend.ColorBreak;
-import org.meteoinfo.geometry.legend.LegendScheme;
-import org.meteoinfo.geometry.legend.PolygonBreak;
-import org.meteoinfo.layer.ImageLayer;
-import org.meteoinfo.ndarray.math.ArrayUtil;
-import org.meteoinfo.ndarray.Array;
-import org.meteoinfo.ndarray.Index;
-import org.meteoinfo.ndarray.InvalidRangeException;
-import org.meteoinfo.geometry.graphic.Graphic;
-import org.meteoinfo.geometry.graphic.GraphicCollection;
-import org.meteoinfo.geometry.shape.ImageShape;
-import org.meteoinfo.geometry.shape.PointZ;
-
/**
*
* @author yaqiang
@@ -157,7 +156,7 @@ public class JOGLUtil {
* for map in 180 - 360 degree east
* @param interpolation Interpolation
* @return Graphics
- * @throws java.io.IOException
+ * @throws IOException
*/
public static GraphicCollection createTexture(GL2 gl, ImageLayer layer, double offset, double xshift,
String interpolation) throws IOException {
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/Lighting.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/Lighting.java
similarity index 99%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/Lighting.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/Lighting.java
index d952b93b..7ed467f4 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/Lighting.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/Lighting.java
@@ -6,9 +6,8 @@
package org.meteoinfo.chart.jogl;
import com.jogamp.opengl.GL2;
-import com.jogamp.opengl.fixedfunc.GLLightingFunc;
-import java.awt.Color;
+import java.awt.*;
import java.util.List;
/**
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/ParticleGraphics.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/ParticleGraphics.java
similarity index 100%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/ParticleGraphics.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/ParticleGraphics.java
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/Plot3DGL.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/Plot3DGL.java
similarity index 99%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/Plot3DGL.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/Plot3DGL.java
index f99de3da..d3fece94 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/Plot3DGL.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/Plot3DGL.java
@@ -9,15 +9,33 @@ import com.jogamp.opengl.*;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.glu.GLUquadric;
import com.jogamp.opengl.glu.GLUtessellator;
+import com.jogamp.opengl.math.VectorUtil;
import com.jogamp.opengl.util.awt.AWTGLReadBufferUtil;
import com.jogamp.opengl.util.awt.TextRenderer;
+import com.jogamp.opengl.util.gl2.GLUT;
import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
-import com.jogamp.opengl.util.gl2.GLUT;
-import com.jogamp.opengl.math.VectorUtil;
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.Graphics2D;
+import org.meteoinfo.chart.*;
+import org.meteoinfo.chart.axis.Axis;
+import org.meteoinfo.chart.jogl.tessellator.Primitive;
+import org.meteoinfo.chart.jogl.tessellator.TessPolygon;
+import org.meteoinfo.chart.plot.GridLine;
+import org.meteoinfo.chart.plot.Plot;
+import org.meteoinfo.chart.plot.PlotType;
+import org.meteoinfo.chart.plot3d.GraphicCollection3D;
+import org.meteoinfo.common.*;
+import org.meteoinfo.data.Dataset;
+import org.meteoinfo.geometry.graphic.Graphic;
+import org.meteoinfo.geometry.graphic.GraphicCollection;
+import org.meteoinfo.geometry.legend.*;
+import org.meteoinfo.geometry.shape.Shape;
+import org.meteoinfo.geometry.shape.*;
+import org.meteoinfo.geometry.geoprocess.GeometryUtil;
+import org.meteoinfo.math.meteo.MeteoMath;
+
+import javax.imageio.ImageIO;
+import javax.swing.*;
+import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
@@ -27,27 +45,6 @@ import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.imageio.ImageIO;
-import javax.swing.JFrame;
-
-import org.meteoinfo.chart.ChartColorBar;
-import org.meteoinfo.chart.ChartLegend;
-import org.meteoinfo.chart.ChartText;
-import org.meteoinfo.chart.ChartText3D;
-import org.meteoinfo.chart.Margin;
-import org.meteoinfo.chart.axis.Axis;
-import org.meteoinfo.chart.jogl.tessellator.Primitive;
-import org.meteoinfo.chart.jogl.tessellator.TessPolygon;
-import org.meteoinfo.chart.plot.*;
-import org.meteoinfo.chart.plot3d.GraphicCollection3D;
-import org.meteoinfo.common.*;
-import org.meteoinfo.data.Dataset;
-import org.meteoinfo.geometry.graphic.GraphicCollection;
-import org.meteoinfo.geometry.legend.*;
-import org.meteoinfo.geoprocess.GeometryUtil;
-import org.meteoinfo.math.meteo.MeteoMath;
-import org.meteoinfo.geometry.shape.*;
-import org.meteoinfo.geometry.graphic.Graphic;
/**
*
@@ -878,8 +875,8 @@ public class Plot3DGL extends Plot implements GLEventListener {
if (this.sampleBuffers)
gl.glEnable(GL2.GL_MULTISAMPLE);
else {
- gl.glEnable(GL.GL_LINE_SMOOTH);
- gl.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST);
+ gl.glEnable(GL2.GL_LINE_SMOOTH);
+ gl.glHint(GL2.GL_LINE_SMOOTH_HINT, GL2.GL_NICEST);
gl.glEnable(GL2.GL_POINT_SMOOTH);
gl.glHint(GL2.GL_POINT_SMOOTH_HINT, GL2.GL_NICEST);
//gl.glEnable(GL2.GL_POLYGON_SMOOTH);
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/SurfaceGraphics.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/SurfaceGraphics.java
similarity index 100%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/SurfaceGraphics.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/SurfaceGraphics.java
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/TextureShape.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/TextureShape.java
similarity index 99%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/TextureShape.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/TextureShape.java
index b2d8342b..d696163e 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/TextureShape.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/TextureShape.java
@@ -7,11 +7,12 @@ package org.meteoinfo.chart.jogl;
import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureIO;
-import java.io.File;
-import java.io.IOException;
import org.meteoinfo.geometry.shape.ImageShape;
import org.meteoinfo.geometry.shape.ShapeTypes;
+import java.io.File;
+import java.io.IOException;
+
/**
*
* @author yaqiang
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/Transform.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/Transform.java
similarity index 100%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/Transform.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/Transform.java
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/Triangle.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/Triangle.java
similarity index 100%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/Triangle.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/Triangle.java
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/BenchmarkHandler.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/BenchmarkHandler.java
similarity index 97%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/BenchmarkHandler.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/BenchmarkHandler.java
index cd9bc85e..47430ec1 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/BenchmarkHandler.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/BenchmarkHandler.java
@@ -1,799 +1,799 @@
-/*
- * 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.jogl.mc;
-
-import java.io.*;
-import java.util.ArrayList;
-
-/**
- * Created by Primoz on 11. 07. 2016.
- */
-public class BenchmarkHandler {
-
- public static void benchmarkChar(File inputFile, File outFile, final int[] size, final float voxSize[], final char isoValue, int nThreadsMin, int nThreadsMax, int iterations) {
- char[] scalarField;
-
- if (inputFile != null) {
- System.out.println("PROGRESS: Reading input data.");
- try {
- int idx = 0;
- scalarField = new char[size[0] * size[1] * size[2]];
-
- DataInputStream in = new DataInputStream(new FileInputStream(inputFile));
- while (in.available() > 0) {
- // Size does not match
- if (idx >= scalarField.length) {
- in.close();
- System.out.println("Invalid volume size was specified.");
- return;
- }
-
- scalarField[idx++] = (char) in.readByte();
- }
-
- in.close();
-
- // Size does not match
- if (idx != scalarField.length) {
- System.out.println("Invalid volume size was specified.");
- return;
- }
- }
- catch (Exception e) {
- System.out.println("Something went wrong while reading the volume");
- return;
- }
- }
- else {
- System.out.println("PROGRESS: Generating volume data.");
- scalarField = VolumeGenerator.generateScalarFieldChar(size);
- }
-
- final char[] finalScalarField = scalarField;
-
- System.out.println("PROGRESS: Performing benchmark.");
- StringBuilder benchmarkResults = new StringBuilder();
-
- for (int nThreads = nThreadsMin; nThreads <= nThreadsMax; nThreads++) {
-
- final ArrayList times = new ArrayList<>();
-
- for (int it = 0; it < iterations; it++) {
-
- // TIMER
- final long start = System.currentTimeMillis();
-
- ArrayList threads = new ArrayList<>();
- final ArrayList> results = new ArrayList<>();
-
-
- // Thread work distribution
- int remainder = size[2] % nThreads;
- int segment = size[2] / nThreads;
-
- // Z axis offset for vertice position calculation
- int zAxisOffset = 0;
-
-
- for (int i = 0; i < nThreads; i++) {
- // Distribute remainder among first (remainder) threads
- int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
-
- // Padding needs to be added to correctly close the gaps between segments
- final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
-
-
- // Finished callback
- final CallbackMC callback = new CallbackMC() {
- @Override
- public void run() {
- results.add(getVertices());
- }
- };
-
- // Java...
- final int finalZAxisOffset = zAxisOffset;
-
- // Start the thread
- Thread t = new Thread() {
- public void run() {
- MarchingCubes.marchingCubesChar(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
- }
- };
-
- threads.add(t);
- t.start();
-
- // Correct offsets for next iteration
- zAxisOffset += segmentSize;
- }
-
- // Join the threads
- for (int i = 0; i 0) {
- // Size does not match
- if (idx >= scalarField.length) {
- in.close();
- System.out.println("Invalid volume size was specified.");
- return;
- }
-
- scalarField[idx++] = in.readShort();
- }
-
- in.close();
-
- // Size does not match
- if (idx != scalarField.length) {
- System.out.println("Invalid volume size was specified.");
- return;
- }
- }
- catch (Exception e) {
- System.out.println("Something went wrong while reading the volume");
- return;
- }
- }
- else {
- System.out.println("PROGRESS: Generating volume data.");
- scalarField = VolumeGenerator.generateScalarFieldShort(size);
- }
-
- final short[] finalScalarField = scalarField;
-
- System.out.println("PROGRESS: Performing benchmark.");
- StringBuilder benchmarkResults = new StringBuilder();
-
- for (int nThreads = nThreadsMin; nThreads <= nThreadsMax; nThreads++) {
-
- final ArrayList times = new ArrayList<>();
-
- for (int it = 0; it < iterations; it++) {
-
- // TIMER
- final long start = System.currentTimeMillis();
-
- ArrayList threads = new ArrayList<>();
- final ArrayList> results = new ArrayList<>();
-
-
- // Thread work distribution
- int remainder = size[2] % nThreads;
- int segment = size[2] / nThreads;
-
- // Z axis offset for vertice position calculation
- int zAxisOffset = 0;
-
-
- for (int i = 0; i < nThreads; i++) {
- // Distribute remainder among first (remainder) threads
- int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
-
- // Padding needs to be added to correctly close the gaps between segments
- final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
-
-
- // Finished callback
- final CallbackMC callback = new CallbackMC() {
- @Override
- public void run() {
- results.add(getVertices());
- }
- };
-
- // Java...
- final int finalZAxisOffset = zAxisOffset;
-
- // Start the thread
- Thread t = new Thread() {
- public void run() {
- MarchingCubes.marchingCubesShort(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
- }
- };
-
- threads.add(t);
- t.start();
-
- // Correct offsets for next iteration
- zAxisOffset += segmentSize;
- }
-
- // Join the threads
- for (int i = 0; i 0) {
- // Size does not match
- if (idx >= scalarField.length) {
- in.close();
- System.out.println("Invalid volume size was specified.");
- return;
- }
-
- scalarField[idx++] = in.readInt();
- }
-
- in.close();
-
- // Size does not match
- if (idx != scalarField.length) {
- System.out.println("Invalid volume size was specified.");
- return;
- }
- }
- catch (Exception e) {
- System.out.println("Something went wrong while reading the volume");
- return;
- }
- }
- else {
- System.out.println("PROGRESS: Generating volume data.");
- scalarField = VolumeGenerator.generateScalarFieldInt(size);
- }
-
- final int[] finalScalarField = scalarField;
-
- System.out.println("PROGRESS: Performing benchmark.");
- StringBuilder benchmarkResults = new StringBuilder();
-
- for (int nThreads = nThreadsMin; nThreads <= nThreadsMax; nThreads++) {
-
- final ArrayList times = new ArrayList<>();
-
- for (int it = 0; it < iterations; it++) {
-
- // TIMER
- final long start = System.currentTimeMillis();
-
- ArrayList threads = new ArrayList<>();
- final ArrayList> results = new ArrayList<>();
-
-
- // Thread work distribution
- int remainder = size[2] % nThreads;
- int segment = size[2] / nThreads;
-
- // Z axis offset for vertice position calculation
- int zAxisOffset = 0;
-
-
- for (int i = 0; i < nThreads; i++) {
- // Distribute remainder among first (remainder) threads
- int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
-
- // Padding needs to be added to correctly close the gaps between segments
- final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
-
-
- // Finished callback
- final CallbackMC callback = new CallbackMC() {
- @Override
- public void run() {
- results.add(getVertices());
- }
- };
-
- // Java...
- final int finalZAxisOffset = zAxisOffset;
-
- // Start the thread
- Thread t = new Thread() {
- public void run() {
- MarchingCubes.marchingCubesInt(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
- }
- };
-
- threads.add(t);
- t.start();
-
- // Correct offsets for next iteration
- zAxisOffset += segmentSize;
- }
-
- // Join the threads
- for (int i = 0; i 0) {
- // Size does not match
- if (idx >= scalarField.length) {
- in.close();
- System.out.println("Invalid volume size was specified.");
- return;
- }
-
- scalarField[idx++] = in.readFloat();
- }
-
- in.close();
-
- // Size does not match
- if (idx != scalarField.length) {
- System.out.println("Invalid volume size was specified.");
- return;
- }
- }
- catch (Exception e) {
- System.out.println("Something went wrong while reading the volume");
- return;
- }
- }
- else {
- System.out.println("PROGRESS: Generating volume data.");
- scalarField = VolumeGenerator.generateScalarFieldFloat(size);
- }
-
- final float[] finalScalarField = scalarField;
-
- System.out.println("PROGRESS: Performing benchmark.");
- StringBuilder benchmarkResults = new StringBuilder();
-
- for (int nThreads = nThreadsMin; nThreads <= nThreadsMax; nThreads++) {
-
- final ArrayList times = new ArrayList<>();
-
- for (int it = 0; it < iterations; it++) {
-
- // TIMER
- final long start = System.currentTimeMillis();
-
- ArrayList threads = new ArrayList<>();
- final ArrayList> results = new ArrayList<>();
-
-
- // Thread work distribution
- int remainder = size[2] % nThreads;
- int segment = size[2] / nThreads;
-
- // Z axis offset for vertice position calculation
- int zAxisOffset = 0;
-
-
- for (int i = 0; i < nThreads; i++) {
- // Distribute remainder among first (remainder) threads
- int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
-
- // Padding needs to be added to correctly close the gaps between segments
- final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
-
-
- // Finished callback
- final CallbackMC callback = new CallbackMC() {
- @Override
- public void run() {
- results.add(getVertices());
- }
- };
-
- // Java...
- final int finalZAxisOffset = zAxisOffset;
-
- // Start the thread
- Thread t = new Thread() {
- public void run() {
- MarchingCubes.marchingCubesFloat(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
- }
- };
-
- threads.add(t);
- t.start();
-
- // Correct offsets for next iteration
- zAxisOffset += segmentSize;
- }
-
- // Join the threads
- for (int i = 0; i 0) {
- // Size does not match
- if (idx >= scalarField.length) {
- in.close();
- System.out.println("Invalid volume size was specified.");
- return;
- }
-
- scalarField[idx++] = in.readDouble();
- }
-
- in.close();
-
- // Size does not match
- if (idx != scalarField.length) {
- System.out.println("Invalid volume size was specified.");
- return;
- }
- }
- catch (Exception e) {
- System.out.println("Something went wrong while reading the volume");
- return;
- }
- }
- else {
- System.out.println("PROGRESS: Generating volume data.");
- scalarField = VolumeGenerator.generateScalarFieldDouble(size);
- }
-
- final double[] finalScalarField = scalarField;
-
- System.out.println("PROGRESS: Performing benchmark.");
- StringBuilder benchmarkResults = new StringBuilder();
-
- for (int nThreads = nThreadsMin; nThreads <= nThreadsMax; nThreads++) {
-
- final ArrayList times = new ArrayList<>();
-
- for (int it = 0; it < iterations; it++) {
-
- // TIMER
- final long start = System.currentTimeMillis();
-
- ArrayList threads = new ArrayList<>();
- final ArrayList> results = new ArrayList<>();
-
-
- // Thread work distribution
- int remainder = size[2] % nThreads;
- int segment = size[2] / nThreads;
-
- // Z axis offset for vertice position calculation
- int zAxisOffset = 0;
-
-
- for (int i = 0; i < nThreads; i++) {
- // Distribute remainder among first (remainder) threads
- int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
-
- // Padding needs to be added to correctly close the gaps between segments
- final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
-
-
- // Finished callback
- final CallbackMC callback = new CallbackMC() {
- @Override
- public void run() {
- results.add(getVertices());
- }
- };
-
- // Java...
- final int finalZAxisOffset = zAxisOffset;
-
- // Start the thread
- Thread t = new Thread() {
- public void run() {
- MarchingCubes.marchingCubesDouble(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
- }
- };
-
- threads.add(t);
- t.start();
-
- // Correct offsets for next iteration
- zAxisOffset += segmentSize;
- }
-
- // Join the threads
- for (int i = 0; i 0) {
+ // Size does not match
+ if (idx >= scalarField.length) {
+ in.close();
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+
+ scalarField[idx++] = (char) in.readByte();
+ }
+
+ in.close();
+
+ // Size does not match
+ if (idx != scalarField.length) {
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+ }
+ catch (Exception e) {
+ System.out.println("Something went wrong while reading the volume");
+ return;
+ }
+ }
+ else {
+ System.out.println("PROGRESS: Generating volume data.");
+ scalarField = VolumeGenerator.generateScalarFieldChar(size);
+ }
+
+ final char[] finalScalarField = scalarField;
+
+ System.out.println("PROGRESS: Performing benchmark.");
+ StringBuilder benchmarkResults = new StringBuilder();
+
+ for (int nThreads = nThreadsMin; nThreads <= nThreadsMax; nThreads++) {
+
+ final ArrayList times = new ArrayList<>();
+
+ for (int it = 0; it < iterations; it++) {
+
+ // TIMER
+ final long start = System.currentTimeMillis();
+
+ ArrayList threads = new ArrayList<>();
+ final ArrayList> results = new ArrayList<>();
+
+
+ // Thread work distribution
+ int remainder = size[2] % nThreads;
+ int segment = size[2] / nThreads;
+
+ // Z axis offset for vertice position calculation
+ int zAxisOffset = 0;
+
+
+ for (int i = 0; i < nThreads; i++) {
+ // Distribute remainder among first (remainder) threads
+ int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
+
+ // Padding needs to be added to correctly close the gaps between segments
+ final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
+
+
+ // Finished callback
+ final CallbackMC callback = new CallbackMC() {
+ @Override
+ public void run() {
+ results.add(getVertices());
+ }
+ };
+
+ // Java...
+ final int finalZAxisOffset = zAxisOffset;
+
+ // Start the thread
+ Thread t = new Thread() {
+ public void run() {
+ MarchingCubes.marchingCubesChar(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
+ }
+ };
+
+ threads.add(t);
+ t.start();
+
+ // Correct offsets for next iteration
+ zAxisOffset += segmentSize;
+ }
+
+ // Join the threads
+ for (int i = 0; i 0) {
+ // Size does not match
+ if (idx >= scalarField.length) {
+ in.close();
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+
+ scalarField[idx++] = in.readShort();
+ }
+
+ in.close();
+
+ // Size does not match
+ if (idx != scalarField.length) {
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+ }
+ catch (Exception e) {
+ System.out.println("Something went wrong while reading the volume");
+ return;
+ }
+ }
+ else {
+ System.out.println("PROGRESS: Generating volume data.");
+ scalarField = VolumeGenerator.generateScalarFieldShort(size);
+ }
+
+ final short[] finalScalarField = scalarField;
+
+ System.out.println("PROGRESS: Performing benchmark.");
+ StringBuilder benchmarkResults = new StringBuilder();
+
+ for (int nThreads = nThreadsMin; nThreads <= nThreadsMax; nThreads++) {
+
+ final ArrayList times = new ArrayList<>();
+
+ for (int it = 0; it < iterations; it++) {
+
+ // TIMER
+ final long start = System.currentTimeMillis();
+
+ ArrayList threads = new ArrayList<>();
+ final ArrayList> results = new ArrayList<>();
+
+
+ // Thread work distribution
+ int remainder = size[2] % nThreads;
+ int segment = size[2] / nThreads;
+
+ // Z axis offset for vertice position calculation
+ int zAxisOffset = 0;
+
+
+ for (int i = 0; i < nThreads; i++) {
+ // Distribute remainder among first (remainder) threads
+ int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
+
+ // Padding needs to be added to correctly close the gaps between segments
+ final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
+
+
+ // Finished callback
+ final CallbackMC callback = new CallbackMC() {
+ @Override
+ public void run() {
+ results.add(getVertices());
+ }
+ };
+
+ // Java...
+ final int finalZAxisOffset = zAxisOffset;
+
+ // Start the thread
+ Thread t = new Thread() {
+ public void run() {
+ MarchingCubes.marchingCubesShort(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
+ }
+ };
+
+ threads.add(t);
+ t.start();
+
+ // Correct offsets for next iteration
+ zAxisOffset += segmentSize;
+ }
+
+ // Join the threads
+ for (int i = 0; i 0) {
+ // Size does not match
+ if (idx >= scalarField.length) {
+ in.close();
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+
+ scalarField[idx++] = in.readInt();
+ }
+
+ in.close();
+
+ // Size does not match
+ if (idx != scalarField.length) {
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+ }
+ catch (Exception e) {
+ System.out.println("Something went wrong while reading the volume");
+ return;
+ }
+ }
+ else {
+ System.out.println("PROGRESS: Generating volume data.");
+ scalarField = VolumeGenerator.generateScalarFieldInt(size);
+ }
+
+ final int[] finalScalarField = scalarField;
+
+ System.out.println("PROGRESS: Performing benchmark.");
+ StringBuilder benchmarkResults = new StringBuilder();
+
+ for (int nThreads = nThreadsMin; nThreads <= nThreadsMax; nThreads++) {
+
+ final ArrayList times = new ArrayList<>();
+
+ for (int it = 0; it < iterations; it++) {
+
+ // TIMER
+ final long start = System.currentTimeMillis();
+
+ ArrayList threads = new ArrayList<>();
+ final ArrayList> results = new ArrayList<>();
+
+
+ // Thread work distribution
+ int remainder = size[2] % nThreads;
+ int segment = size[2] / nThreads;
+
+ // Z axis offset for vertice position calculation
+ int zAxisOffset = 0;
+
+
+ for (int i = 0; i < nThreads; i++) {
+ // Distribute remainder among first (remainder) threads
+ int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
+
+ // Padding needs to be added to correctly close the gaps between segments
+ final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
+
+
+ // Finished callback
+ final CallbackMC callback = new CallbackMC() {
+ @Override
+ public void run() {
+ results.add(getVertices());
+ }
+ };
+
+ // Java...
+ final int finalZAxisOffset = zAxisOffset;
+
+ // Start the thread
+ Thread t = new Thread() {
+ public void run() {
+ MarchingCubes.marchingCubesInt(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
+ }
+ };
+
+ threads.add(t);
+ t.start();
+
+ // Correct offsets for next iteration
+ zAxisOffset += segmentSize;
+ }
+
+ // Join the threads
+ for (int i = 0; i 0) {
+ // Size does not match
+ if (idx >= scalarField.length) {
+ in.close();
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+
+ scalarField[idx++] = in.readFloat();
+ }
+
+ in.close();
+
+ // Size does not match
+ if (idx != scalarField.length) {
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+ }
+ catch (Exception e) {
+ System.out.println("Something went wrong while reading the volume");
+ return;
+ }
+ }
+ else {
+ System.out.println("PROGRESS: Generating volume data.");
+ scalarField = VolumeGenerator.generateScalarFieldFloat(size);
+ }
+
+ final float[] finalScalarField = scalarField;
+
+ System.out.println("PROGRESS: Performing benchmark.");
+ StringBuilder benchmarkResults = new StringBuilder();
+
+ for (int nThreads = nThreadsMin; nThreads <= nThreadsMax; nThreads++) {
+
+ final ArrayList times = new ArrayList<>();
+
+ for (int it = 0; it < iterations; it++) {
+
+ // TIMER
+ final long start = System.currentTimeMillis();
+
+ ArrayList threads = new ArrayList<>();
+ final ArrayList> results = new ArrayList<>();
+
+
+ // Thread work distribution
+ int remainder = size[2] % nThreads;
+ int segment = size[2] / nThreads;
+
+ // Z axis offset for vertice position calculation
+ int zAxisOffset = 0;
+
+
+ for (int i = 0; i < nThreads; i++) {
+ // Distribute remainder among first (remainder) threads
+ int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
+
+ // Padding needs to be added to correctly close the gaps between segments
+ final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
+
+
+ // Finished callback
+ final CallbackMC callback = new CallbackMC() {
+ @Override
+ public void run() {
+ results.add(getVertices());
+ }
+ };
+
+ // Java...
+ final int finalZAxisOffset = zAxisOffset;
+
+ // Start the thread
+ Thread t = new Thread() {
+ public void run() {
+ MarchingCubes.marchingCubesFloat(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
+ }
+ };
+
+ threads.add(t);
+ t.start();
+
+ // Correct offsets for next iteration
+ zAxisOffset += segmentSize;
+ }
+
+ // Join the threads
+ for (int i = 0; i 0) {
+ // Size does not match
+ if (idx >= scalarField.length) {
+ in.close();
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+
+ scalarField[idx++] = in.readDouble();
+ }
+
+ in.close();
+
+ // Size does not match
+ if (idx != scalarField.length) {
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+ }
+ catch (Exception e) {
+ System.out.println("Something went wrong while reading the volume");
+ return;
+ }
+ }
+ else {
+ System.out.println("PROGRESS: Generating volume data.");
+ scalarField = VolumeGenerator.generateScalarFieldDouble(size);
+ }
+
+ final double[] finalScalarField = scalarField;
+
+ System.out.println("PROGRESS: Performing benchmark.");
+ StringBuilder benchmarkResults = new StringBuilder();
+
+ for (int nThreads = nThreadsMin; nThreads <= nThreadsMax; nThreads++) {
+
+ final ArrayList times = new ArrayList<>();
+
+ for (int it = 0; it < iterations; it++) {
+
+ // TIMER
+ final long start = System.currentTimeMillis();
+
+ ArrayList threads = new ArrayList<>();
+ final ArrayList> results = new ArrayList<>();
+
+
+ // Thread work distribution
+ int remainder = size[2] % nThreads;
+ int segment = size[2] / nThreads;
+
+ // Z axis offset for vertice position calculation
+ int zAxisOffset = 0;
+
+
+ for (int i = 0; i < nThreads; i++) {
+ // Distribute remainder among first (remainder) threads
+ int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
+
+ // Padding needs to be added to correctly close the gaps between segments
+ final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
+
+
+ // Finished callback
+ final CallbackMC callback = new CallbackMC() {
+ @Override
+ public void run() {
+ results.add(getVertices());
+ }
+ };
+
+ // Java...
+ final int finalZAxisOffset = zAxisOffset;
+
+ // Start the thread
+ Thread t = new Thread() {
+ public void run() {
+ MarchingCubes.marchingCubesDouble(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
+ }
+ };
+
+ threads.add(t);
+ t.start();
+
+ // Correct offsets for next iteration
+ zAxisOffset += segmentSize;
+ }
+
+ // Join the threads
+ for (int i = 0; i vertices;
-
- void setVertices(ArrayList vertices) {
- this.vertices = vertices;
- }
-
- public ArrayList getVertices() {
- return this.vertices;
- }
-}
+/*
+ * 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.jogl.mc;
+
+import java.util.ArrayList;
+
+/**
+ * Created by Primoz on 8.7.2016.
+ */
+public abstract class CallbackMC implements Runnable {
+ private ArrayList vertices;
+
+ void setVertices(ArrayList vertices) {
+ this.vertices = vertices;
+ }
+
+ public ArrayList getVertices() {
+ return this.vertices;
+ }
+}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/ExtractHandler.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/ExtractHandler.java
similarity index 97%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/ExtractHandler.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/ExtractHandler.java
index 48c28a5d..afabc5ae 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/ExtractHandler.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/ExtractHandler.java
@@ -1,537 +1,537 @@
-/*
- * 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.jogl.mc;
-
-import java.io.*;
-import java.util.ArrayList;
-
-/**
- * Created by Primoz on 11. 07. 2016.
- */
-public class ExtractHandler {
- public static void extractHandlerChar(File inputFile, File outFile, final int[] size, final float voxSize[], final char isoValue, int nThreads) {
- char[] scalarField;
-
- if (inputFile != null) {
- System.out.println("PROGRESS: Reading input data.");
- try {
- int idx = 0;
- scalarField = new char[size[0] * size[1] * size[2]];
-
- DataInputStream in = new DataInputStream(new FileInputStream(inputFile));
- while (in.available() > 0) {
- // Size does not match
- if (idx >= scalarField.length) {
- in.close();
- System.out.println("Invalid volume size was specified.");
- return;
- }
-
- scalarField[idx++] = (char) in.readByte();
- }
-
- in.close();
-
- // Size does not match
- if (idx != scalarField.length) {
- System.out.println("Invalid volume size was specified.");
- return;
- }
- }
- catch (Exception e) {
- System.out.println("Something went wrong while reading the volume");
- return;
- }
- }
- else {
- System.out.println("PROGRESS: Generating volume data.");
- scalarField = VolumeGenerator.generateScalarFieldChar(size);
- }
-
- final char[] finalScalarField = scalarField;
-
- ArrayList threads = new ArrayList<>();
- final ArrayList> results = new ArrayList<>();
-
- // Thread work distribution
- int remainder = size[2] % nThreads;
- int segment = size[2] / nThreads;
-
- // Z axis offset for vertice position calculation
- int zAxisOffset = 0;
-
- System.out.println("PROGRESS: Executing marching cubes.");
-
- for (int i = 0; i < nThreads; i++) {
- // Distribute remainder among first (remainder) threads
- int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
-
- // Padding needs to be added to correctly close the gaps between segments
- final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
-
-
- // Finished callback
- final CallbackMC callback = new CallbackMC() {
- @Override
- public void run() {
- results.add(getVertices());
- }
- };
-
- // Java...
- final int finalZAxisOffset = zAxisOffset;
-
- // Start the thread
- Thread t = new Thread() {
- public void run() {
- MarchingCubes.marchingCubesChar(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
- }
- };
-
- threads.add(t);
- t.start();
-
- // Correct offsets for next iteration
- zAxisOffset += segmentSize;
- }
-
- // Join the threads
- for (int i = 0; i 0) {
- // Size does not match
- if (idx >= scalarField.length) {
- in.close();
- System.out.println("Invalid volume size was specified.");
- return;
- }
-
- scalarField[idx++] = in.readShort();
- }
-
- in.close();
-
- // Size does not match
- if (idx != scalarField.length) {
- System.out.println("Invalid volume size was specified.");
- return;
- }
- }
- catch (Exception e) {
- System.out.println("Something went wrong while reading the volume");
- return;
- }
- }
- else {
- System.out.println("PROGRESS: Generating volume data.");
- scalarField = VolumeGenerator.generateScalarFieldShort(size);
- }
-
- final short[] finalScalarField = scalarField;
-
- ArrayList threads = new ArrayList<>();
- final ArrayList> results = new ArrayList<>();
-
- // Thread work distribution
- int remainder = size[2] % nThreads;
- int segment = size[2] / nThreads;
-
- // Z axis offset for vertice position calculation
- int zAxisOffset = 0;
-
- System.out.println("PROGRESS: Executing marching cubes.");
-
- for (int i = 0; i < nThreads; i++) {
- // Distribute remainder among first (remainder) threads
- int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
-
- // Padding needs to be added to correctly close the gaps between segments
- final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
-
-
- // Finished callback
- final CallbackMC callback = new CallbackMC() {
- @Override
- public void run() {
- results.add(getVertices());
- }
- };
-
- // Java...
- final int finalZAxisOffset = zAxisOffset;
-
- // Start the thread
- Thread t = new Thread() {
- public void run() {
- MarchingCubes.marchingCubesShort(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
- }
- };
-
- threads.add(t);
- t.start();
-
- // Correct offsets for next iteration
- zAxisOffset += segmentSize;
- }
-
- // Join the threads
- for (int i = 0; i 0) {
- // Size does not match
- if (idx >= scalarField.length) {
- in.close();
- System.out.println("Invalid volume size was specified.");
- return;
- }
-
- scalarField[idx++] = in.readInt();
- }
-
- in.close();
-
- // Size does not match
- if (idx != scalarField.length) {
- System.out.println("Invalid volume size was specified.");
- return;
- }
- }
- catch (Exception e) {
- System.out.println("Something went wrong while reading the volume");
- return;
- }
- }
- else {
- System.out.println("PROGRESS: Generating volume data.");
- scalarField = VolumeGenerator.generateScalarFieldInt(size);
- }
-
- final int[] finalScalarField = scalarField;
-
- ArrayList threads = new ArrayList<>();
- final ArrayList> results = new ArrayList<>();
-
- // Thread work distribution
- int remainder = size[2] % nThreads;
- int segment = size[2] / nThreads;
-
- // Z axis offset for vertice position calculation
- int zAxisOffset = 0;
-
- System.out.println("PROGRESS: Executing marching cubes.");
-
- for (int i = 0; i < nThreads; i++) {
- // Distribute remainder among first (remainder) threads
- int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
-
- // Padding needs to be added to correctly close the gaps between segments
- final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
-
-
- // Finished callback
- final CallbackMC callback = new CallbackMC() {
- @Override
- public void run() {
- results.add(getVertices());
- }
- };
-
- // Java...
- final int finalZAxisOffset = zAxisOffset;
-
- // Start the thread
- Thread t = new Thread() {
- public void run() {
- MarchingCubes.marchingCubesInt(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
- }
- };
-
- threads.add(t);
- t.start();
-
- // Correct offsets for next iteration
- zAxisOffset += segmentSize;
- }
-
- // Join the threads
- for (int i = 0; i 0) {
- // Size does not match
- if (idx >= scalarField.length) {
- in.close();
- System.out.println("Invalid volume size was specified.");
- return;
- }
-
- scalarField[idx++] = in.readFloat();
- }
-
- in.close();
-
- // Size does not match
- if (idx != scalarField.length) {
- System.out.println("Invalid volume size was specified.");
- return;
- }
- }
- catch (Exception e) {
- System.out.println("Something went wrong while reading the volume");
- return;
- }
- }
- else {
- System.out.println("PROGRESS: Generating volume data.");
- scalarField = VolumeGenerator.generateScalarFieldFloat(size);
- }
-
- final float[] finalScalarField = scalarField;
-
- // TIMER
- ArrayList threads = new ArrayList<>();
- final ArrayList> results = new ArrayList<>();
-
- // Thread work distribution
- int remainder = size[2] % nThreads;
- int segment = size[2] / nThreads;
-
- // Z axis offset for vertice position calculation
- int zAxisOffset = 0;
-
- System.out.println("PROGRESS: Executing marching cubes.");
-
- for (int i = 0; i < nThreads; i++) {
- // Distribute remainder among first (remainder) threads
- int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
-
- // Padding needs to be added to correctly close the gaps between segments
- final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
-
-
- // Finished callback
- final CallbackMC callback = new CallbackMC() {
- @Override
- public void run() {
- results.add(getVertices());
- }
- };
-
- // Java...
- final int finalZAxisOffset = zAxisOffset;
-
- // Start the thread
- Thread t = new Thread() {
- public void run() {
- MarchingCubes.marchingCubesFloat(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
- }
- };
-
- threads.add(t);
- t.start();
-
- // Correct offsets for next iteration
- zAxisOffset += segmentSize;
- }
-
- // Join the threads
- for (int i = 0; i 0) {
- // Size does not match
- if (idx >= scalarField.length) {
- in.close();
- System.out.println("Invalid volume size was specified.");
- return;
- }
-
- scalarField[idx++] = in.readDouble();
- }
-
- in.close();
-
- // Size does not match
- if (idx != scalarField.length) {
- System.out.println("Invalid volume size was specified.");
- return;
- }
- }
- catch (Exception e) {
- System.out.println("Something went wrong while reading the volume");
- return;
- }
- }
- else {
- System.out.println("PROGRESS: Generating volume data.");
- scalarField = VolumeGenerator.generateScalarFieldDouble(size);
- }
-
- final double[] finalScalarField = scalarField;
-
- // TIMER
- ArrayList threads = new ArrayList<>();
- final ArrayList> results = new ArrayList<>();
-
- // Thread work distribution
- int remainder = size[2] % nThreads;
- int segment = size[2] / nThreads;
-
- // Z axis offset for vertice position calculation
- int zAxisOffset = 0;
-
- System.out.println("PROGRESS: Executing marching cubes.");
- for (int i = 0; i < nThreads; i++) {
- // Distribute remainder among first (remainder) threads
- int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
-
- // Padding needs to be added to correctly close the gaps between segments
- final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
-
-
- // Finished callback
- final CallbackMC callback = new CallbackMC() {
- @Override
- public void run() {
- results.add(getVertices());
- }
- };
-
- // Java...
- final int finalZAxisOffset = zAxisOffset;
-
- // Start the thread
- Thread t = new Thread() {
- public void run() {
- MarchingCubes.marchingCubesDouble(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
- }
- };
-
- threads.add(t);
- t.start();
-
- // Correct offsets for next iteration
- zAxisOffset += segmentSize;
- }
-
- // Join the threads
- for (int i = 0; i > results, File outFile) {
- try {
- BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(outFile));
-
- int idx = 0;
- for (int i = 0; i < results.size(); i++) {
- ArrayList resSeg = results.get(i);
-
- for (int j = 0; j < resSeg.size(); j++) {
- if (idx % 3 == 0) {
- stream.write(("f " + (idx + 1) + " " + (idx + 2) + " " + (idx + 3) + "\n").getBytes());
- }
- idx ++;
-
- stream.write(("v " + resSeg.get(j)[0] + " " + resSeg.get(j)[1] + " " + resSeg.get(j)[2] + "\n").getBytes());
- }
- }
-
- stream.flush();
- stream.close();
- }
- catch (Exception e) {
- System.out.println("Something went wrong while writing to the output file");
- return;
- }
- }
-}
+/*
+ * 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.jogl.mc;
+
+import java.io.*;
+import java.util.ArrayList;
+
+/**
+ * Created by Primoz on 11. 07. 2016.
+ */
+public class ExtractHandler {
+ public static void extractHandlerChar(File inputFile, File outFile, final int[] size, final float voxSize[], final char isoValue, int nThreads) {
+ char[] scalarField;
+
+ if (inputFile != null) {
+ System.out.println("PROGRESS: Reading input data.");
+ try {
+ int idx = 0;
+ scalarField = new char[size[0] * size[1] * size[2]];
+
+ DataInputStream in = new DataInputStream(new FileInputStream(inputFile));
+ while (in.available() > 0) {
+ // Size does not match
+ if (idx >= scalarField.length) {
+ in.close();
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+
+ scalarField[idx++] = (char) in.readByte();
+ }
+
+ in.close();
+
+ // Size does not match
+ if (idx != scalarField.length) {
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+ }
+ catch (Exception e) {
+ System.out.println("Something went wrong while reading the volume");
+ return;
+ }
+ }
+ else {
+ System.out.println("PROGRESS: Generating volume data.");
+ scalarField = VolumeGenerator.generateScalarFieldChar(size);
+ }
+
+ final char[] finalScalarField = scalarField;
+
+ ArrayList threads = new ArrayList<>();
+ final ArrayList> results = new ArrayList<>();
+
+ // Thread work distribution
+ int remainder = size[2] % nThreads;
+ int segment = size[2] / nThreads;
+
+ // Z axis offset for vertice position calculation
+ int zAxisOffset = 0;
+
+ System.out.println("PROGRESS: Executing marching cubes.");
+
+ for (int i = 0; i < nThreads; i++) {
+ // Distribute remainder among first (remainder) threads
+ int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
+
+ // Padding needs to be added to correctly close the gaps between segments
+ final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
+
+
+ // Finished callback
+ final CallbackMC callback = new CallbackMC() {
+ @Override
+ public void run() {
+ results.add(getVertices());
+ }
+ };
+
+ // Java...
+ final int finalZAxisOffset = zAxisOffset;
+
+ // Start the thread
+ Thread t = new Thread() {
+ public void run() {
+ MarchingCubes.marchingCubesChar(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
+ }
+ };
+
+ threads.add(t);
+ t.start();
+
+ // Correct offsets for next iteration
+ zAxisOffset += segmentSize;
+ }
+
+ // Join the threads
+ for (int i = 0; i 0) {
+ // Size does not match
+ if (idx >= scalarField.length) {
+ in.close();
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+
+ scalarField[idx++] = in.readShort();
+ }
+
+ in.close();
+
+ // Size does not match
+ if (idx != scalarField.length) {
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+ }
+ catch (Exception e) {
+ System.out.println("Something went wrong while reading the volume");
+ return;
+ }
+ }
+ else {
+ System.out.println("PROGRESS: Generating volume data.");
+ scalarField = VolumeGenerator.generateScalarFieldShort(size);
+ }
+
+ final short[] finalScalarField = scalarField;
+
+ ArrayList threads = new ArrayList<>();
+ final ArrayList> results = new ArrayList<>();
+
+ // Thread work distribution
+ int remainder = size[2] % nThreads;
+ int segment = size[2] / nThreads;
+
+ // Z axis offset for vertice position calculation
+ int zAxisOffset = 0;
+
+ System.out.println("PROGRESS: Executing marching cubes.");
+
+ for (int i = 0; i < nThreads; i++) {
+ // Distribute remainder among first (remainder) threads
+ int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
+
+ // Padding needs to be added to correctly close the gaps between segments
+ final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
+
+
+ // Finished callback
+ final CallbackMC callback = new CallbackMC() {
+ @Override
+ public void run() {
+ results.add(getVertices());
+ }
+ };
+
+ // Java...
+ final int finalZAxisOffset = zAxisOffset;
+
+ // Start the thread
+ Thread t = new Thread() {
+ public void run() {
+ MarchingCubes.marchingCubesShort(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
+ }
+ };
+
+ threads.add(t);
+ t.start();
+
+ // Correct offsets for next iteration
+ zAxisOffset += segmentSize;
+ }
+
+ // Join the threads
+ for (int i = 0; i 0) {
+ // Size does not match
+ if (idx >= scalarField.length) {
+ in.close();
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+
+ scalarField[idx++] = in.readInt();
+ }
+
+ in.close();
+
+ // Size does not match
+ if (idx != scalarField.length) {
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+ }
+ catch (Exception e) {
+ System.out.println("Something went wrong while reading the volume");
+ return;
+ }
+ }
+ else {
+ System.out.println("PROGRESS: Generating volume data.");
+ scalarField = VolumeGenerator.generateScalarFieldInt(size);
+ }
+
+ final int[] finalScalarField = scalarField;
+
+ ArrayList threads = new ArrayList<>();
+ final ArrayList> results = new ArrayList<>();
+
+ // Thread work distribution
+ int remainder = size[2] % nThreads;
+ int segment = size[2] / nThreads;
+
+ // Z axis offset for vertice position calculation
+ int zAxisOffset = 0;
+
+ System.out.println("PROGRESS: Executing marching cubes.");
+
+ for (int i = 0; i < nThreads; i++) {
+ // Distribute remainder among first (remainder) threads
+ int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
+
+ // Padding needs to be added to correctly close the gaps between segments
+ final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
+
+
+ // Finished callback
+ final CallbackMC callback = new CallbackMC() {
+ @Override
+ public void run() {
+ results.add(getVertices());
+ }
+ };
+
+ // Java...
+ final int finalZAxisOffset = zAxisOffset;
+
+ // Start the thread
+ Thread t = new Thread() {
+ public void run() {
+ MarchingCubes.marchingCubesInt(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
+ }
+ };
+
+ threads.add(t);
+ t.start();
+
+ // Correct offsets for next iteration
+ zAxisOffset += segmentSize;
+ }
+
+ // Join the threads
+ for (int i = 0; i 0) {
+ // Size does not match
+ if (idx >= scalarField.length) {
+ in.close();
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+
+ scalarField[idx++] = in.readFloat();
+ }
+
+ in.close();
+
+ // Size does not match
+ if (idx != scalarField.length) {
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+ }
+ catch (Exception e) {
+ System.out.println("Something went wrong while reading the volume");
+ return;
+ }
+ }
+ else {
+ System.out.println("PROGRESS: Generating volume data.");
+ scalarField = VolumeGenerator.generateScalarFieldFloat(size);
+ }
+
+ final float[] finalScalarField = scalarField;
+
+ // TIMER
+ ArrayList threads = new ArrayList<>();
+ final ArrayList> results = new ArrayList<>();
+
+ // Thread work distribution
+ int remainder = size[2] % nThreads;
+ int segment = size[2] / nThreads;
+
+ // Z axis offset for vertice position calculation
+ int zAxisOffset = 0;
+
+ System.out.println("PROGRESS: Executing marching cubes.");
+
+ for (int i = 0; i < nThreads; i++) {
+ // Distribute remainder among first (remainder) threads
+ int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
+
+ // Padding needs to be added to correctly close the gaps between segments
+ final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
+
+
+ // Finished callback
+ final CallbackMC callback = new CallbackMC() {
+ @Override
+ public void run() {
+ results.add(getVertices());
+ }
+ };
+
+ // Java...
+ final int finalZAxisOffset = zAxisOffset;
+
+ // Start the thread
+ Thread t = new Thread() {
+ public void run() {
+ MarchingCubes.marchingCubesFloat(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
+ }
+ };
+
+ threads.add(t);
+ t.start();
+
+ // Correct offsets for next iteration
+ zAxisOffset += segmentSize;
+ }
+
+ // Join the threads
+ for (int i = 0; i 0) {
+ // Size does not match
+ if (idx >= scalarField.length) {
+ in.close();
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+
+ scalarField[idx++] = in.readDouble();
+ }
+
+ in.close();
+
+ // Size does not match
+ if (idx != scalarField.length) {
+ System.out.println("Invalid volume size was specified.");
+ return;
+ }
+ }
+ catch (Exception e) {
+ System.out.println("Something went wrong while reading the volume");
+ return;
+ }
+ }
+ else {
+ System.out.println("PROGRESS: Generating volume data.");
+ scalarField = VolumeGenerator.generateScalarFieldDouble(size);
+ }
+
+ final double[] finalScalarField = scalarField;
+
+ // TIMER
+ ArrayList threads = new ArrayList<>();
+ final ArrayList> results = new ArrayList<>();
+
+ // Thread work distribution
+ int remainder = size[2] % nThreads;
+ int segment = size[2] / nThreads;
+
+ // Z axis offset for vertice position calculation
+ int zAxisOffset = 0;
+
+ System.out.println("PROGRESS: Executing marching cubes.");
+ for (int i = 0; i < nThreads; i++) {
+ // Distribute remainder among first (remainder) threads
+ int segmentSize = (remainder-- > 0) ? segment + 1 : segment;
+
+ // Padding needs to be added to correctly close the gaps between segments
+ final int paddedSegmentSize = (i != nThreads - 1) ? segmentSize + 1 : segmentSize;
+
+
+ // Finished callback
+ final CallbackMC callback = new CallbackMC() {
+ @Override
+ public void run() {
+ results.add(getVertices());
+ }
+ };
+
+ // Java...
+ final int finalZAxisOffset = zAxisOffset;
+
+ // Start the thread
+ Thread t = new Thread() {
+ public void run() {
+ MarchingCubes.marchingCubesDouble(finalScalarField, new int[]{size[0], size[1], paddedSegmentSize}, size[2], voxSize, isoValue, finalZAxisOffset, callback);
+ }
+ };
+
+ threads.add(t);
+ t.start();
+
+ // Correct offsets for next iteration
+ zAxisOffset += segmentSize;
+ }
+
+ // Join the threads
+ for (int i = 0; i > results, File outFile) {
+ try {
+ BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(outFile));
+
+ int idx = 0;
+ for (int i = 0; i < results.size(); i++) {
+ ArrayList resSeg = results.get(i);
+
+ for (int j = 0; j < resSeg.size(); j++) {
+ if (idx % 3 == 0) {
+ stream.write(("f " + (idx + 1) + " " + (idx + 2) + " " + (idx + 3) + "\n").getBytes());
+ }
+ idx ++;
+
+ stream.write(("v " + resSeg.get(j)[0] + " " + resSeg.get(j)[1] + " " + resSeg.get(j)[2] + "\n").getBytes());
+ }
+ }
+
+ stream.flush();
+ stream.close();
+ }
+ catch (Exception e) {
+ System.out.println("Something went wrong while writing to the output file");
+ return;
+ }
+ }
+}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/Main.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/Main.java
similarity index 97%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/Main.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/Main.java
index 2507adac..198c8c17 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/Main.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/Main.java
@@ -1,287 +1,287 @@
-/*
- * 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.jogl.mc;
-
-import java.io.File;
-
-public class Main {
-
- private static String usage = "This script may be executed in either benchmark or extract mode. Mode is specified by the first parameter [benchmark, extract].\nParameters: \n\t-input-vol\t Specifies path to the input volume. If this parameter is set volume dimensions(-vol-dim), data type(-data-type) and iso value(-iso) must also be given.\n\t-vol-dim\t Specifies the generated/read volume dimensions. Dimensions should be given as unsigned integers in format; -vol-dim X Y Z.\n\t-data-type\t Specifies the input file or generated data type. Options [char, uchar, short, ushort, int, uint, float, double].\n\t-vox-dim\t Specifies voxel dimensions used in mesh construction. Dimensions should be given as floating point numbers in format: -vox-dim X Y Z.\n\t-nThread\t Number of threads used in Marching cubes algorithm.This parameter can be either given as a single unsigned integer value or two unsigned integer values in benchmark mode, specifying the range of thread executions that will be tested.\n\t-iter\t\t Used only in benchmark mode to determine how many iterations should be executed for each configuration.\n\t-iso\t\t Isovalue that is used as a threshold for determining active voxels. Type should match the data type.\n\t-o\t\t Path to output file. In extract mode the mesh is written to file in .obj format [required]. In benchmark mode the results are written to file.\n";;
-
- private static boolean isUint (String input) {
- try {
- return (Integer.parseInt(input) >= 0);
- } catch (NumberFormatException e) {
- return false;
- }
- }
-
- private static boolean isFloat (String input) {
- try {
- Float.parseFloat(input);
- return true;
- } catch (NumberFormatException e) {
- return false;
- }
- }
-
- public static void main(String[] args) {
-
- if (args.length < 1) {
- System.out.println(usage);
- return;
- } else if (args[0].equals("-help")) {
- System.out.println(usage);
- }
-
- // Benchmark or extract mode
- boolean benchmark = false;
-
- // Default num of threads is max available
- int nThreadsMin = java.lang.Thread.activeCount();
- if (nThreadsMin == 0) {
- nThreadsMin = 1;
- }
- int nThreadsMax = nThreadsMin;
-
- File inputFile = null;
- File outFile = null;
- String type = null;
- String isoValueStr = null;
- int iterations = 10; // Default 10 iterations per benchmark
-
- boolean customSizeSpecified = false;
- int[] size = {64, 64, 64};
- float[] voxSize = {1.0f, 1.0f, 1.0f};
-
- //region PARAMETER PARSING
- // Read execution type
- if (args[0].equals("benchmark")) {
- benchmark = true;
- } else if (!args[0].equals("extract")) {
- System.out.println("Invalid execution type. Valid options [extract, benchmark]");
- return;
- }
-
- // Flag parsing
- for (int i = 1; i < args.length; i++) {
- if (args[i].equals("-input-vol")) {
- // Volume path specified
- // Output file path is specified
- if (i + 1 >= args.length || args[i + 1].charAt(0) == '-') {
- System.out.println("Missing file path after -input-vol flag.");
- return;
- }
-
- // Store the file name and offset iterator
- inputFile = new File(args[++i]);
-
- if (!inputFile.exists() || inputFile.isDirectory()) {
- System.out.println("Specified volume file does not exist.");
- return;
- }
- } else if (args[i].equals("-vol-dim")) {
- // Volume dimensions are given
- if (i + 3 >= args.length || args[i + 1].charAt(0) == '-' || args[i + 2].charAt(0) == '-' || args[i + 3].charAt(0) == '-') {
- System.out.println("Missing volume dimensions after -vol-dim flag.");
- return;
- }
-
- String x = (args[++i]);
- String y = (args[++i]);
- String z = (args[++i]);
-
- if (!isUint(x) || !isUint(y) || !isUint(z)) {
- System.out.println("Invalid volume dimensions format. Specify dimensions as three unsigned integers.");
- return;
- }
-
- customSizeSpecified = true;
- size[0] = Integer.parseInt(x);
- size[1] = Integer.parseInt(y);
- size[2] = Integer.parseInt(z);
- } else if (args[i].equals("-vox-dim")) {
- // Voxel dimensions are given
- if (i + 3 >= args.length) {
- System.out.println("Missing voxel dimensions after -vox-dim flag.");
- return;
- }
-
- String x = args[++i];
- String y = args[++i];
- String z = args[++i];
-
- if (!isFloat(x) || !isFloat(y) || !isFloat(z)) {
- System.out.println("Invalid voxel dimensions format. Specify voxel dimensions as three positive floats.");
- return;
- }
-
- voxSize[0] = Float.parseFloat(x);
- voxSize[0] = Float.parseFloat(y);
- voxSize[0] = Float.parseFloat(z);
- } else if (args[i].equals("-nThread")) {
- // Number of threads is given
- // FIRST VALUE
- if (i + 1 >= args.length || args[i + 1].charAt(0) == '-') {
- System.out.println("Missing number or range of threads after -nThread flag.");
- return;
- }
-
- // Validate first number
- String tmp = args[++i];
-
- if (!isUint(tmp)) {
- System.out.println("Invalid nThread value format. Specify unsigned integer value or two if range.");
- return;
- }
-
- // Parse C-str
- nThreadsMin = Integer.parseInt(tmp);
-
- // SECOND VALUE (If given)
- if (i + 1 < args.length && args[i + 1].charAt(0) != '-') {
- // Validate second number
- tmp = args[++i];
- if (!isUint(tmp)) {
- System.out.println("Invalid nThread value format. Specify unsigned integer value or two if range.");
- return;
- }
-
- // Parse C-str
- nThreadsMax = Integer.parseInt(tmp);
- } else {
- nThreadsMax = nThreadsMin;
- }
-
- } else if (args[i].equals("-iso")) {
- // ISO value is given
- if (i + 1 >= args.length) {
- System.out.println("Missing iso value after -iso flag.");
- return;
- }
-
- isoValueStr = args[++i];
-
- if (!isFloat(isoValueStr)) {
- System.out.println("Invalid iso value format. Please specify float.");
- return;
- }
- } else if (args[i].equals("-iter")) {
- // ISO value is given
- if (i + 1 >= args.length) {
- System.out.println("Missing number of iterations after -iter flag.");
- return;
- }
-
- String iterationsStr = args[++i];
-
- if (!isUint(iterationsStr)) {
- System.out.println("Invalid iterations value format. Please specify unsigned integer.");
- return;
- }
-
- iterations = Integer.parseInt(iterationsStr);
- } else if (args[i].equals("-o")) {
- // Output file path is specified
- if (i + 1 >= args.length || args[i + 1].charAt(0) == '-') {
- System.out.println("Missing file path after -o flag.");
- return;
- }
-
- // Store the file name and offset iterator
- outFile = new File(args[++i]);
-
- if (outFile.getParentFile() != null && !outFile.getParentFile().exists()) {
- System.out.println("Specified output file path is invaild.");
- }
- } else if (args[i].equals("-data-type")) {
- // Volume data type is specified
- if (i + 1 >= args.length || args[i + 1].charAt(0) == '-') {
- System.out.println("Missing type after -data-type flag.");
- return;
- }
-
- // Data type is specified (char, uchar, short, ushort, int, uint, float, double)
- if (!args[i + 1].equals("char") && !args[i + 1].equals("uchar") && !args[i + 1].equals("short") && !args[i + 1].equals("ushort") && args[i + 1].equals("uint") && args[i + 1].equals("float") && args[i + 1].equals("double")) {
- System.out.println("Invalid data type. Available data types: char, uchar, short, ushort, int, uint, float, double.");
- return;
- }
-
- type = args[++i];
- } else {
- System.out.println("Unknown parameter: " + args[i]);
- return;
- }
- }
-
- if (inputFile != null && (!customSizeSpecified || type == null || isoValueStr == null)) {
- System.out.println("If custom volume is imported, you must input volume dimensions(-vol-dim), data type (-data-type) and iso value (-iso).");
- return;
- }
- //endregion
-
- if (benchmark) {
- switch (type) {
- case "char":
- BenchmarkHandler.benchmarkChar(inputFile, outFile, size, voxSize, (char) ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0.5), nThreadsMin, nThreadsMax, iterations);
- break;
- case "uchar":
- BenchmarkHandler.benchmarkChar(inputFile, outFile, size, voxSize, (char) ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0.5), nThreadsMin, nThreadsMax, iterations);
- break;
- case "short":
- BenchmarkHandler.benchmarkShort(inputFile, outFile, size, voxSize, (short) ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0.5), nThreadsMin, nThreadsMax, iterations);
- break;
- case "ushort":
- BenchmarkHandler.benchmarkShort(inputFile, outFile, size, voxSize, (short) ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0.5), nThreadsMin, nThreadsMax, iterations);
- break;
- case "int":
- BenchmarkHandler.benchmarkInt(inputFile, outFile, size, voxSize, ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0), nThreadsMin, nThreadsMax, iterations);
- break;
- case "uint":
- BenchmarkHandler.benchmarkInt(inputFile, outFile, size, voxSize, ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0), nThreadsMin, nThreadsMax, iterations);
- break;
- case "float":
- BenchmarkHandler.benchmarkFloat(inputFile, outFile, size, voxSize, ((isoValueStr != null) ? Float.parseFloat(isoValueStr) : 0.5f), nThreadsMin, nThreadsMax, iterations);
- break;
- case "double":
- BenchmarkHandler.benchmarkDouble(inputFile, outFile, size, voxSize, ((isoValueStr != null) ? Double.parseDouble(isoValueStr) : 0.5), nThreadsMin, nThreadsMax, iterations);
- break;
- }
- } else {
- if (outFile == null) {
- System.out.println("To extract the data the output file path is needed (-o).");
- return;
- }
-
- switch (type) {
- case "char":
- ExtractHandler.extractHandlerChar(inputFile, outFile, size, voxSize, (char) ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0.5), nThreadsMax);
- break;
- case "uchar":
- ExtractHandler.extractHandlerChar(inputFile, outFile, size, voxSize, (char) ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0.5), nThreadsMax);
- break;
- case "short":
- ExtractHandler.extractHandlerShort(inputFile, outFile, size, voxSize, (short) ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0.5), nThreadsMax);
- break;
- case "ushort":
- ExtractHandler.extractHandlerShort(inputFile, outFile, size, voxSize, (short) ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0.5), nThreadsMax);
- break;
- case "int":
- ExtractHandler.extractHandlerInt(inputFile, outFile, size, voxSize, ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0), nThreadsMax);
- break;
- case "uint":
- ExtractHandler.extractHandlerInt(inputFile, outFile, size, voxSize, ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0), nThreadsMax);
- break;
- case "float":
- ExtractHandler.extractHandlerFloat(inputFile, outFile, size, voxSize, ((isoValueStr != null) ? Float.parseFloat(isoValueStr) : 0.5f), nThreadsMax);
- break;
- case "double":
- ExtractHandler.extractHandlerDouble(inputFile, outFile, size, voxSize, ((isoValueStr != null) ? Double.parseDouble(isoValueStr) : 0.5), nThreadsMax);
- break;
- }
- }
- }
-}
+/*
+ * 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.jogl.mc;
+
+import java.io.File;
+
+public class Main {
+
+ private static String usage = "This script may be executed in either benchmark or extract mode. Mode is specified by the first parameter [benchmark, extract].\nParameters: \n\t-input-vol\t Specifies path to the input volume. If this parameter is set volume dimensions(-vol-dim), data type(-data-type) and iso value(-iso) must also be given.\n\t-vol-dim\t Specifies the generated/read volume dimensions. Dimensions should be given as unsigned integers in format; -vol-dim X Y Z.\n\t-data-type\t Specifies the input file or generated data type. Options [char, uchar, short, ushort, int, uint, float, double].\n\t-vox-dim\t Specifies voxel dimensions used in mesh construction. Dimensions should be given as floating point numbers in format: -vox-dim X Y Z.\n\t-nThread\t Number of threads used in Marching cubes algorithm.This parameter can be either given as a single unsigned integer value or two unsigned integer values in benchmark mode, specifying the range of thread executions that will be tested.\n\t-iter\t\t Used only in benchmark mode to determine how many iterations should be executed for each configuration.\n\t-iso\t\t Isovalue that is used as a threshold for determining active voxels. Type should match the data type.\n\t-o\t\t Path to output file. In extract mode the mesh is written to file in .obj format [required]. In benchmark mode the results are written to file.\n";;
+
+ private static boolean isUint (String input) {
+ try {
+ return (Integer.parseInt(input) >= 0);
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
+ private static boolean isFloat (String input) {
+ try {
+ Float.parseFloat(input);
+ return true;
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
+ public static void main(String[] args) {
+
+ if (args.length < 1) {
+ System.out.println(usage);
+ return;
+ } else if (args[0].equals("-help")) {
+ System.out.println(usage);
+ }
+
+ // Benchmark or extract mode
+ boolean benchmark = false;
+
+ // Default num of threads is max available
+ int nThreadsMin = Thread.activeCount();
+ if (nThreadsMin == 0) {
+ nThreadsMin = 1;
+ }
+ int nThreadsMax = nThreadsMin;
+
+ File inputFile = null;
+ File outFile = null;
+ String type = null;
+ String isoValueStr = null;
+ int iterations = 10; // Default 10 iterations per benchmark
+
+ boolean customSizeSpecified = false;
+ int[] size = {64, 64, 64};
+ float[] voxSize = {1.0f, 1.0f, 1.0f};
+
+ //region PARAMETER PARSING
+ // Read execution type
+ if (args[0].equals("benchmark")) {
+ benchmark = true;
+ } else if (!args[0].equals("extract")) {
+ System.out.println("Invalid execution type. Valid options [extract, benchmark]");
+ return;
+ }
+
+ // Flag parsing
+ for (int i = 1; i < args.length; i++) {
+ if (args[i].equals("-input-vol")) {
+ // Volume path specified
+ // Output file path is specified
+ if (i + 1 >= args.length || args[i + 1].charAt(0) == '-') {
+ System.out.println("Missing file path after -input-vol flag.");
+ return;
+ }
+
+ // Store the file name and offset iterator
+ inputFile = new File(args[++i]);
+
+ if (!inputFile.exists() || inputFile.isDirectory()) {
+ System.out.println("Specified volume file does not exist.");
+ return;
+ }
+ } else if (args[i].equals("-vol-dim")) {
+ // Volume dimensions are given
+ if (i + 3 >= args.length || args[i + 1].charAt(0) == '-' || args[i + 2].charAt(0) == '-' || args[i + 3].charAt(0) == '-') {
+ System.out.println("Missing volume dimensions after -vol-dim flag.");
+ return;
+ }
+
+ String x = (args[++i]);
+ String y = (args[++i]);
+ String z = (args[++i]);
+
+ if (!isUint(x) || !isUint(y) || !isUint(z)) {
+ System.out.println("Invalid volume dimensions format. Specify dimensions as three unsigned integers.");
+ return;
+ }
+
+ customSizeSpecified = true;
+ size[0] = Integer.parseInt(x);
+ size[1] = Integer.parseInt(y);
+ size[2] = Integer.parseInt(z);
+ } else if (args[i].equals("-vox-dim")) {
+ // Voxel dimensions are given
+ if (i + 3 >= args.length) {
+ System.out.println("Missing voxel dimensions after -vox-dim flag.");
+ return;
+ }
+
+ String x = args[++i];
+ String y = args[++i];
+ String z = args[++i];
+
+ if (!isFloat(x) || !isFloat(y) || !isFloat(z)) {
+ System.out.println("Invalid voxel dimensions format. Specify voxel dimensions as three positive floats.");
+ return;
+ }
+
+ voxSize[0] = Float.parseFloat(x);
+ voxSize[0] = Float.parseFloat(y);
+ voxSize[0] = Float.parseFloat(z);
+ } else if (args[i].equals("-nThread")) {
+ // Number of threads is given
+ // FIRST VALUE
+ if (i + 1 >= args.length || args[i + 1].charAt(0) == '-') {
+ System.out.println("Missing number or range of threads after -nThread flag.");
+ return;
+ }
+
+ // Validate first number
+ String tmp = args[++i];
+
+ if (!isUint(tmp)) {
+ System.out.println("Invalid nThread value format. Specify unsigned integer value or two if range.");
+ return;
+ }
+
+ // Parse C-str
+ nThreadsMin = Integer.parseInt(tmp);
+
+ // SECOND VALUE (If given)
+ if (i + 1 < args.length && args[i + 1].charAt(0) != '-') {
+ // Validate second number
+ tmp = args[++i];
+ if (!isUint(tmp)) {
+ System.out.println("Invalid nThread value format. Specify unsigned integer value or two if range.");
+ return;
+ }
+
+ // Parse C-str
+ nThreadsMax = Integer.parseInt(tmp);
+ } else {
+ nThreadsMax = nThreadsMin;
+ }
+
+ } else if (args[i].equals("-iso")) {
+ // ISO value is given
+ if (i + 1 >= args.length) {
+ System.out.println("Missing iso value after -iso flag.");
+ return;
+ }
+
+ isoValueStr = args[++i];
+
+ if (!isFloat(isoValueStr)) {
+ System.out.println("Invalid iso value format. Please specify float.");
+ return;
+ }
+ } else if (args[i].equals("-iter")) {
+ // ISO value is given
+ if (i + 1 >= args.length) {
+ System.out.println("Missing number of iterations after -iter flag.");
+ return;
+ }
+
+ String iterationsStr = args[++i];
+
+ if (!isUint(iterationsStr)) {
+ System.out.println("Invalid iterations value format. Please specify unsigned integer.");
+ return;
+ }
+
+ iterations = Integer.parseInt(iterationsStr);
+ } else if (args[i].equals("-o")) {
+ // Output file path is specified
+ if (i + 1 >= args.length || args[i + 1].charAt(0) == '-') {
+ System.out.println("Missing file path after -o flag.");
+ return;
+ }
+
+ // Store the file name and offset iterator
+ outFile = new File(args[++i]);
+
+ if (outFile.getParentFile() != null && !outFile.getParentFile().exists()) {
+ System.out.println("Specified output file path is invaild.");
+ }
+ } else if (args[i].equals("-data-type")) {
+ // Volume data type is specified
+ if (i + 1 >= args.length || args[i + 1].charAt(0) == '-') {
+ System.out.println("Missing type after -data-type flag.");
+ return;
+ }
+
+ // Data type is specified (char, uchar, short, ushort, int, uint, float, double)
+ if (!args[i + 1].equals("char") && !args[i + 1].equals("uchar") && !args[i + 1].equals("short") && !args[i + 1].equals("ushort") && args[i + 1].equals("uint") && args[i + 1].equals("float") && args[i + 1].equals("double")) {
+ System.out.println("Invalid data type. Available data types: char, uchar, short, ushort, int, uint, float, double.");
+ return;
+ }
+
+ type = args[++i];
+ } else {
+ System.out.println("Unknown parameter: " + args[i]);
+ return;
+ }
+ }
+
+ if (inputFile != null && (!customSizeSpecified || type == null || isoValueStr == null)) {
+ System.out.println("If custom volume is imported, you must input volume dimensions(-vol-dim), data type (-data-type) and iso value (-iso).");
+ return;
+ }
+ //endregion
+
+ if (benchmark) {
+ switch (type) {
+ case "char":
+ BenchmarkHandler.benchmarkChar(inputFile, outFile, size, voxSize, (char) ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0.5), nThreadsMin, nThreadsMax, iterations);
+ break;
+ case "uchar":
+ BenchmarkHandler.benchmarkChar(inputFile, outFile, size, voxSize, (char) ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0.5), nThreadsMin, nThreadsMax, iterations);
+ break;
+ case "short":
+ BenchmarkHandler.benchmarkShort(inputFile, outFile, size, voxSize, (short) ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0.5), nThreadsMin, nThreadsMax, iterations);
+ break;
+ case "ushort":
+ BenchmarkHandler.benchmarkShort(inputFile, outFile, size, voxSize, (short) ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0.5), nThreadsMin, nThreadsMax, iterations);
+ break;
+ case "int":
+ BenchmarkHandler.benchmarkInt(inputFile, outFile, size, voxSize, ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0), nThreadsMin, nThreadsMax, iterations);
+ break;
+ case "uint":
+ BenchmarkHandler.benchmarkInt(inputFile, outFile, size, voxSize, ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0), nThreadsMin, nThreadsMax, iterations);
+ break;
+ case "float":
+ BenchmarkHandler.benchmarkFloat(inputFile, outFile, size, voxSize, ((isoValueStr != null) ? Float.parseFloat(isoValueStr) : 0.5f), nThreadsMin, nThreadsMax, iterations);
+ break;
+ case "double":
+ BenchmarkHandler.benchmarkDouble(inputFile, outFile, size, voxSize, ((isoValueStr != null) ? Double.parseDouble(isoValueStr) : 0.5), nThreadsMin, nThreadsMax, iterations);
+ break;
+ }
+ } else {
+ if (outFile == null) {
+ System.out.println("To extract the data the output file path is needed (-o).");
+ return;
+ }
+
+ switch (type) {
+ case "char":
+ ExtractHandler.extractHandlerChar(inputFile, outFile, size, voxSize, (char) ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0.5), nThreadsMax);
+ break;
+ case "uchar":
+ ExtractHandler.extractHandlerChar(inputFile, outFile, size, voxSize, (char) ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0.5), nThreadsMax);
+ break;
+ case "short":
+ ExtractHandler.extractHandlerShort(inputFile, outFile, size, voxSize, (short) ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0.5), nThreadsMax);
+ break;
+ case "ushort":
+ ExtractHandler.extractHandlerShort(inputFile, outFile, size, voxSize, (short) ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0.5), nThreadsMax);
+ break;
+ case "int":
+ ExtractHandler.extractHandlerInt(inputFile, outFile, size, voxSize, ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0), nThreadsMax);
+ break;
+ case "uint":
+ ExtractHandler.extractHandlerInt(inputFile, outFile, size, voxSize, ((isoValueStr != null) ? Integer.parseInt(isoValueStr) : 0), nThreadsMax);
+ break;
+ case "float":
+ ExtractHandler.extractHandlerFloat(inputFile, outFile, size, voxSize, ((isoValueStr != null) ? Float.parseFloat(isoValueStr) : 0.5f), nThreadsMax);
+ break;
+ case "double":
+ ExtractHandler.extractHandlerDouble(inputFile, outFile, size, voxSize, ((isoValueStr != null) ? Double.parseDouble(isoValueStr) : 0.5), nThreadsMax);
+ break;
+ }
+ }
+ }
+}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/MarchingCubes.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/MarchingCubes.java
similarity index 98%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/MarchingCubes.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/MarchingCubes.java
index 843d15b6..fb6ae306 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/MarchingCubes.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/MarchingCubes.java
@@ -1,1080 +1,1081 @@
-/*
- * 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.jogl.mc;
-
-import java.util.ArrayList;
-import org.meteoinfo.ndarray.Array;
-
-/**
- * Created by Primoz on 11. 07. 2016.
- */
-public class MarchingCubes {
- static float[] lerp(float[] vec1, float[] vec2, float alpha){
- return new float[]{vec1[0] + (vec2[0] - vec1[0]) * alpha, vec1[1] + (vec2[1] - vec1[1]) * alpha, vec1[2] + (vec2[2] - vec1[2]) * alpha};
- }
-
- static void marchingCubesChar(char[] values, int[] volDim, int volZFull, float[] voxDim, char isoLevel, int offset, CallbackMC callback) {
-
- ArrayList vertices = new ArrayList<>();
- // Actual position along edge weighted according to function values.
- float vertList[][] = new float[12][3];
-
-
- // Calculate maximal possible axis value (used in vertice normalization)
- float maxX = voxDim[0] * (volDim[0] - 1);
- float maxY = voxDim[1] * (volDim[1] - 1);
- float maxZ = voxDim[2] * (volZFull - 1);
- float maxAxisVal = Math.max(maxX, Math.max(maxY, maxZ));
-
- // Volume iteration
- for (int z = 0; z < volDim[2] - 1; z++) {
- for (int y = 0; y < volDim[1] - 1; y++) {
- for (int x = 0; x < volDim[0] - 1; x++) {
-
- // Indices pointing to cube vertices
- // pyz ___________________ pxyz
- // /| /|
- // / | / |
- // / | / |
- // pz /___|______________/pxz|
- // | | | |
- // | | | |
- // | py |______________|___| pxy
- // | / | /
- // | / | /
- // | / | /
- // |/__________________|/
- // p px
-
- int p = x + (volDim[0] * y) + (volDim[0] * volDim[1] * (z + offset)),
- px = p + 1,
- py = p + volDim[0],
- pxy = py + 1,
- pz = p + volDim[0] * volDim[1],
- pxz = px + volDim[0] * volDim[1],
- pyz = py + volDim[0] * volDim[1],
- pxyz = pxy + volDim[0] * volDim[1];
-
- // X Y Z
- float position[] = new float[]{x * voxDim[0], y * voxDim[1], (z + offset) * voxDim[2]};
-
- // Voxel intensities
- char value0 = values[p],
- value1 = values[px],
- value2 = values[py],
- value3 = values[pxy],
- value4 = values[pz],
- value5 = values[pxz],
- value6 = values[pyz],
- value7 = values[pxyz];
-
- // Voxel is active if its intensity is above isolevel
- int cubeindex = 0;
- if (value0 > isoLevel) cubeindex |= 1;
- if (value1 > isoLevel) cubeindex |= 2;
- if (value2 > isoLevel) cubeindex |= 8;
- if (value3 > isoLevel) cubeindex |= 4;
- if (value4 > isoLevel) cubeindex |= 16;
- if (value5 > isoLevel) cubeindex |= 32;
- if (value6 > isoLevel) cubeindex |= 128;
- if (value7 > isoLevel) cubeindex |= 64;
-
- // Fetch the triggered edges
- int bits = TablesMC.MC_EDGE_TABLE[cubeindex];
-
- // If no edge is triggered... skip
- if (bits == 0) continue;
-
- // Interpolate the positions based od voxel intensities
- float mu = 0.5f;
-
- // bottom of the cube
- if ((bits & 1) != 0) {
- mu = (isoLevel - value0) / (value1 - value0);
- vertList[0] = lerp(position, new float[]{position[0] + voxDim[0], position[1], position[2]}, mu);
- }
- if ((bits & 2) != 0) {
- mu = (isoLevel - value1) / (value3 - value1);
- vertList[1] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
- }
- if ((bits & 4) != 0) {
- mu = (isoLevel - value2) / (value3 - value2);
- vertList[2] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
- }
- if ((bits & 8) != 0) {
- mu = (isoLevel - value0) / (value2 - value0);
- vertList[3] = lerp(position, new float[]{position[0], position[1] + voxDim[1], position[2]}, mu);
- }
- // top of the cube
- if ((bits & 16) != 0) {
- mu = (isoLevel - value4) / (value5 - value4);
- vertList[4] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 32) != 0) {
- mu = (isoLevel - value5) / (value7 - value5);
- vertList[5] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 64) != 0) {
- mu = (isoLevel - value6) / (value7 - value6);
- vertList[6] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 128) != 0) {
- mu = (isoLevel - value4) / (value6 - value4);
- vertList[7] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
- // vertical lines of the cube
- if ((bits & 256) != 0) {
- mu = (isoLevel - value0) / (value4 - value0);
- vertList[8] = lerp(position, new float[]{position[0], position[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 512) != 0) {
- mu = (isoLevel - value1) / (value5 - value1);
- vertList[9] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 1024) != 0) {
- mu = (isoLevel - value3) / (value7 - value3);
- vertList[10] = lerp(new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1]+ voxDim[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 2048) != 0) {
- mu = (isoLevel - value2) / (value6 - value2);
- vertList[11] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
-
- // construct triangles -- get correct vertices from triTable.
- int i = 0;
- // "Re-purpose cubeindex into an offset into triTable."
- cubeindex <<= 4;
-
- while (TablesMC.MC_TRI_TABLE[cubeindex + i] != -1) {
- int index1 = TablesMC.MC_TRI_TABLE[cubeindex + i];
- int index2 = TablesMC.MC_TRI_TABLE[cubeindex + i + 1];
- int index3 = TablesMC.MC_TRI_TABLE[cubeindex + i + 2];
-
- // Add triangles vertices normalized with the maximal possible value
- vertices.add(new float[] {vertList[index3][0] / maxAxisVal - 0.5f, vertList[index3][1] / maxAxisVal - 0.5f, vertList[index3][2] / maxAxisVal - 0.5f});
- vertices.add(new float[] {vertList[index2][0] / maxAxisVal - 0.5f, vertList[index2][1] / maxAxisVal - 0.5f, vertList[index2][2] / maxAxisVal - 0.5f});
- vertices.add(new float[] {vertList[index1][0] / maxAxisVal - 0.5f, vertList[index1][1] / maxAxisVal - 0.5f, vertList[index1][2] / maxAxisVal - 0.5f});
-
- i += 3;
- }
- }
- }
- }
-
- callback.setVertices(vertices);
- callback.run();
- }
-
- static void marchingCubesShort(short[] values, int[] volDim, int volZFull, float[] voxDim, short isoLevel, int offset, CallbackMC callback) {
-
- ArrayList vertices = new ArrayList<>();
- // Actual position along edge weighted according to function values.
- float vertList[][] = new float[12][3];
-
-
- // Calculate maximal possible axis value (used in vertice normalization)
- float maxX = voxDim[0] * (volDim[0] - 1);
- float maxY = voxDim[1] * (volDim[1] - 1);
- float maxZ = voxDim[2] * (volZFull - 1);
- float maxAxisVal = Math.max(maxX, Math.max(maxY, maxZ));
-
- // Volume iteration
- for (int z = 0; z < volDim[2] - 1; z++) {
- for (int y = 0; y < volDim[1] - 1; y++) {
- for (int x = 0; x < volDim[0] - 1; x++) {
-
- // Indices pointing to cube vertices
- // pyz ___________________ pxyz
- // /| /|
- // / | / |
- // / | / |
- // pz /___|______________/pxz|
- // | | | |
- // | | | |
- // | py |______________|___| pxy
- // | / | /
- // | / | /
- // | / | /
- // |/__________________|/
- // p px
-
- int p = x + (volDim[0] * y) + (volDim[0] * volDim[1] * (z + offset)),
- px = p + 1,
- py = p + volDim[0],
- pxy = py + 1,
- pz = p + volDim[0] * volDim[1],
- pxz = px + volDim[0] * volDim[1],
- pyz = py + volDim[0] * volDim[1],
- pxyz = pxy + volDim[0] * volDim[1];
-
- // X Y Z
- float position[] = new float[]{x * voxDim[0], y * voxDim[1], (z + offset) * voxDim[2]};
-
- // Voxel intensities
- short value0 = values[p],
- value1 = values[px],
- value2 = values[py],
- value3 = values[pxy],
- value4 = values[pz],
- value5 = values[pxz],
- value6 = values[pyz],
- value7 = values[pxyz];
-
- // Voxel is active if its intensity is above isolevel
- int cubeindex = 0;
- if (value0 > isoLevel) cubeindex |= 1;
- if (value1 > isoLevel) cubeindex |= 2;
- if (value2 > isoLevel) cubeindex |= 8;
- if (value3 > isoLevel) cubeindex |= 4;
- if (value4 > isoLevel) cubeindex |= 16;
- if (value5 > isoLevel) cubeindex |= 32;
- if (value6 > isoLevel) cubeindex |= 128;
- if (value7 > isoLevel) cubeindex |= 64;
-
- // Fetch the triggered edges
- int bits = TablesMC.MC_EDGE_TABLE[cubeindex];
-
- // If no edge is triggered... skip
- if (bits == 0) continue;
-
- // Interpolate the positions based od voxel intensities
- float mu = 0.5f;
-
- // bottom of the cube
- if ((bits & 1) != 0) {
- mu = (isoLevel - value0) / (value1 - value0);
- vertList[0] = lerp(position, new float[]{position[0] + voxDim[0], position[1], position[2]}, mu);
- }
- if ((bits & 2) != 0) {
- mu = (isoLevel - value1) / (value3 - value1);
- vertList[1] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
- }
- if ((bits & 4) != 0) {
- mu = (isoLevel - value2) / (value3 - value2);
- vertList[2] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
- }
- if ((bits & 8) != 0) {
- mu = (isoLevel - value0) / (value2 - value0);
- vertList[3] = lerp(position, new float[]{position[0], position[1] + voxDim[1], position[2]}, mu);
- }
- // top of the cube
- if ((bits & 16) != 0) {
- mu = (isoLevel - value4) / (value5 - value4);
- vertList[4] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 32) != 0) {
- mu = (isoLevel - value5) / (value7 - value5);
- vertList[5] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 64) != 0) {
- mu = (isoLevel - value6) / (value7 - value6);
- vertList[6] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 128) != 0) {
- mu = (isoLevel - value4) / (value6 - value4);
- vertList[7] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
- // vertical lines of the cube
- if ((bits & 256) != 0) {
- mu = (isoLevel - value0) / (value4 - value0);
- vertList[8] = lerp(position, new float[]{position[0], position[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 512) != 0) {
- mu = (isoLevel - value1) / (value5 - value1);
- vertList[9] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 1024) != 0) {
- mu = (isoLevel - value3) / (value7 - value3);
- vertList[10] = lerp(new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1]+ voxDim[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 2048) != 0) {
- mu = (isoLevel - value2) / (value6 - value2);
- vertList[11] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
-
- // construct triangles -- get correct vertices from triTable.
- int i = 0;
- // "Re-purpose cubeindex into an offset into triTable."
- cubeindex <<= 4;
-
- while (TablesMC.MC_TRI_TABLE[cubeindex + i] != -1) {
- int index1 = TablesMC.MC_TRI_TABLE[cubeindex + i];
- int index2 = TablesMC.MC_TRI_TABLE[cubeindex + i + 1];
- int index3 = TablesMC.MC_TRI_TABLE[cubeindex + i + 2];
-
- // Add triangles vertices normalized with the maximal possible value
- vertices.add(new float[] {vertList[index3][0] / maxAxisVal - 0.5f, vertList[index3][1] / maxAxisVal - 0.5f, vertList[index3][2] / maxAxisVal - 0.5f});
- vertices.add(new float[] {vertList[index2][0] / maxAxisVal - 0.5f, vertList[index2][1] / maxAxisVal - 0.5f, vertList[index2][2] / maxAxisVal - 0.5f});
- vertices.add(new float[] {vertList[index1][0] / maxAxisVal - 0.5f, vertList[index1][1] / maxAxisVal - 0.5f, vertList[index1][2] / maxAxisVal - 0.5f});
-
- i += 3;
- }
- }
- }
- }
-
- callback.setVertices(vertices);
- callback.run();
- }
-
- static void marchingCubesInt(int[] values, int[] volDim, int volZFull, float[] voxDim, int isoLevel, int offset, CallbackMC callback) {
-
- ArrayList vertices = new ArrayList<>();
- // Actual position along edge weighted according to function values.
- float vertList[][] = new float[12][3];
-
-
- // Calculate maximal possible axis value (used in vertice normalization)
- float maxX = voxDim[0] * (volDim[0] - 1);
- float maxY = voxDim[1] * (volDim[1] - 1);
- float maxZ = voxDim[2] * (volZFull - 1);
- float maxAxisVal = Math.max(maxX, Math.max(maxY, maxZ));
-
- // Volume iteration
- for (int z = 0; z < volDim[2] - 1; z++) {
- for (int y = 0; y < volDim[1] - 1; y++) {
- for (int x = 0; x < volDim[0] - 1; x++) {
-
- // Indices pointing to cube vertices
- // pyz ___________________ pxyz
- // /| /|
- // / | / |
- // / | / |
- // pz /___|______________/pxz|
- // | | | |
- // | | | |
- // | py |______________|___| pxy
- // | / | /
- // | / | /
- // | / | /
- // |/__________________|/
- // p px
-
- int p = x + (volDim[0] * y) + (volDim[0] * volDim[1] * (z + offset)),
- px = p + 1,
- py = p + volDim[0],
- pxy = py + 1,
- pz = p + volDim[0] * volDim[1],
- pxz = px + volDim[0] * volDim[1],
- pyz = py + volDim[0] * volDim[1],
- pxyz = pxy + volDim[0] * volDim[1];
-
- // X Y Z
- float position[] = new float[]{x * voxDim[0], y * voxDim[1], (z + offset) * voxDim[2]};
-
- // Voxel intensities
- int value0 = values[p],
- value1 = values[px],
- value2 = values[py],
- value3 = values[pxy],
- value4 = values[pz],
- value5 = values[pxz],
- value6 = values[pyz],
- value7 = values[pxyz];
-
- // Voxel is active if its intensity is above isolevel
- int cubeindex = 0;
- if (value0 > isoLevel) cubeindex |= 1;
- if (value1 > isoLevel) cubeindex |= 2;
- if (value2 > isoLevel) cubeindex |= 8;
- if (value3 > isoLevel) cubeindex |= 4;
- if (value4 > isoLevel) cubeindex |= 16;
- if (value5 > isoLevel) cubeindex |= 32;
- if (value6 > isoLevel) cubeindex |= 128;
- if (value7 > isoLevel) cubeindex |= 64;
-
- // Fetch the triggered edges
- int bits = TablesMC.MC_EDGE_TABLE[cubeindex];
-
- // If no edge is triggered... skip
- if (bits == 0) continue;
-
- // Interpolate the positions based od voxel intensities
- float mu = 0.5f;
-
- // bottom of the cube
- if ((bits & 1) != 0) {
- mu = (isoLevel - value0) / (value1 - value0);
- vertList[0] = lerp(position, new float[]{position[0] + voxDim[0], position[1], position[2]}, mu);
- }
- if ((bits & 2) != 0) {
- mu = (isoLevel - value1) / (value3 - value1);
- vertList[1] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
- }
- if ((bits & 4) != 0) {
- mu = (isoLevel - value2) / (value3 - value2);
- vertList[2] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
- }
- if ((bits & 8) != 0) {
- mu = (isoLevel - value0) / (value2 - value0);
- vertList[3] = lerp(position, new float[]{position[0], position[1] + voxDim[1], position[2]}, mu);
- }
- // top of the cube
- if ((bits & 16) != 0) {
- mu = (isoLevel - value4) / (value5 - value4);
- vertList[4] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 32) != 0) {
- mu = (isoLevel - value5) / (value7 - value5);
- vertList[5] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 64) != 0) {
- mu = (isoLevel - value6) / (value7 - value6);
- vertList[6] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 128) != 0) {
- mu = (isoLevel - value4) / (value6 - value4);
- vertList[7] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
- // vertical lines of the cube
- if ((bits & 256) != 0) {
- mu = (isoLevel - value0) / (value4 - value0);
- vertList[8] = lerp(position, new float[]{position[0], position[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 512) != 0) {
- mu = (isoLevel - value1) / (value5 - value1);
- vertList[9] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 1024) != 0) {
- mu = (isoLevel - value3) / (value7 - value3);
- vertList[10] = lerp(new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1]+ voxDim[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 2048) != 0) {
- mu = (isoLevel - value2) / (value6 - value2);
- vertList[11] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
-
- // construct triangles -- get correct vertices from triTable.
- int i = 0;
- // "Re-purpose cubeindex into an offset into triTable."
- cubeindex <<= 4;
-
- while (TablesMC.MC_TRI_TABLE[cubeindex + i] != -1) {
- int index1 = TablesMC.MC_TRI_TABLE[cubeindex + i];
- int index2 = TablesMC.MC_TRI_TABLE[cubeindex + i + 1];
- int index3 = TablesMC.MC_TRI_TABLE[cubeindex + i + 2];
-
- // Add triangles vertices normalized with the maximal possible value
- vertices.add(new float[] {vertList[index3][0] / maxAxisVal - 0.5f, vertList[index3][1] / maxAxisVal - 0.5f, vertList[index3][2] / maxAxisVal - 0.5f});
- vertices.add(new float[] {vertList[index2][0] / maxAxisVal - 0.5f, vertList[index2][1] / maxAxisVal - 0.5f, vertList[index2][2] / maxAxisVal - 0.5f});
- vertices.add(new float[] {vertList[index1][0] / maxAxisVal - 0.5f, vertList[index1][1] / maxAxisVal - 0.5f, vertList[index1][2] / maxAxisVal - 0.5f});
-
- i += 3;
- }
- }
- }
- }
-
- callback.setVertices(vertices);
- callback.run();
- }
-
- static void marchingCubesFloat(float[] values, int[] volDim, int volZFull, float[] voxDim, float isoLevel, int offset, CallbackMC callback) {
-
- ArrayList vertices = new ArrayList<>();
- // Actual position along edge weighted according to function values.
- float vertList[][] = new float[12][3];
-
-
- // Calculate maximal possible axis value (used in vertice normalization)
- float maxX = voxDim[0] * (volDim[0] - 1);
- float maxY = voxDim[1] * (volDim[1] - 1);
- float maxZ = voxDim[2] * (volZFull - 1);
- float maxAxisVal = Math.max(maxX, Math.max(maxY, maxZ));
-
- // Volume iteration
- for (int z = 0; z < volDim[2] - 1; z++) {
- for (int y = 0; y < volDim[1] - 1; y++) {
- for (int x = 0; x < volDim[0] - 1; x++) {
-
- // Indices pointing to cube vertices
- // pyz ___________________ pxyz
- // /| /|
- // / | / |
- // / | / |
- // pz /___|______________/pxz|
- // | | | |
- // | | | |
- // | py |______________|___| pxy
- // | / | /
- // | / | /
- // | / | /
- // |/__________________|/
- // p px
-
- int p = x + (volDim[0] * y) + (volDim[0] * volDim[1] * (z + offset)),
- px = p + 1,
- py = p + volDim[0],
- pxy = py + 1,
- pz = p + volDim[0] * volDim[1],
- pxz = px + volDim[0] * volDim[1],
- pyz = py + volDim[0] * volDim[1],
- pxyz = pxy + volDim[0] * volDim[1];
-
- // X Y Z
- float position[] = new float[]{x * voxDim[0], y * voxDim[1], (z + offset) * voxDim[2]};
-
- // Voxel intensities
- float value0 = values[p],
- value1 = values[px],
- value2 = values[py],
- value3 = values[pxy],
- value4 = values[pz],
- value5 = values[pxz],
- value6 = values[pyz],
- value7 = values[pxyz];
-
- // Voxel is active if its intensity is above isolevel
- int cubeindex = 0;
- if (value0 > isoLevel) cubeindex |= 1;
- if (value1 > isoLevel) cubeindex |= 2;
- if (value2 > isoLevel) cubeindex |= 8;
- if (value3 > isoLevel) cubeindex |= 4;
- if (value4 > isoLevel) cubeindex |= 16;
- if (value5 > isoLevel) cubeindex |= 32;
- if (value6 > isoLevel) cubeindex |= 128;
- if (value7 > isoLevel) cubeindex |= 64;
-
- // Fetch the triggered edges
- int bits = TablesMC.MC_EDGE_TABLE[cubeindex];
-
- // If no edge is triggered... skip
- if (bits == 0) continue;
-
- // Interpolate the positions based od voxel intensities
- float mu = 0.5f;
-
- // bottom of the cube
- if ((bits & 1) != 0) {
- mu = (float) ((isoLevel - value0) / (value1 - value0));
- vertList[0] = lerp(position, new float[]{position[0] + voxDim[0], position[1], position[2]}, mu);
- }
- if ((bits & 2) != 0) {
- mu = (float) ((isoLevel - value1) / (value3 - value1));
- vertList[1] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
- }
- if ((bits & 4) != 0) {
- mu = (float) ((isoLevel - value2) / (value3 - value2));
- vertList[2] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
- }
- if ((bits & 8) != 0) {
- mu = (float) ((isoLevel - value0) / (value2 - value0));
- vertList[3] = lerp(position, new float[]{position[0], position[1] + voxDim[1], position[2]}, mu);
- }
- // top of the cube
- if ((bits & 16) != 0) {
- mu = (float) ((isoLevel - value4) / (value5 - value4));
- vertList[4] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 32) != 0) {
- mu = (float) ((isoLevel - value5) / (value7 - value5));
- vertList[5] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 64) != 0) {
- mu = (float) ((isoLevel - value6) / (value7 - value6));
- vertList[6] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 128) != 0) {
- mu = (float) ((isoLevel - value4) / (value6 - value4));
- vertList[7] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
- // vertical lines of the cube
- if ((bits & 256) != 0) {
- mu = (float) ((isoLevel - value0) / (value4 - value0));
- vertList[8] = lerp(position, new float[]{position[0], position[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 512) != 0) {
- mu = (float) ((isoLevel - value1) / (value5 - value1));
- vertList[9] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 1024) != 0) {
- mu = (float) ((isoLevel - value3) / (value7 - value3));
- vertList[10] = lerp(new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1]+ voxDim[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 2048) != 0) {
- mu = (float) ((isoLevel - value2) / (value6 - value2));
- vertList[11] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
-
- // construct triangles -- get correct vertices from triTable.
- int i = 0;
- // "Re-purpose cubeindex into an offset into triTable."
- cubeindex <<= 4;
-
- while (TablesMC.MC_TRI_TABLE[cubeindex + i] != -1) {
- int index1 = TablesMC.MC_TRI_TABLE[cubeindex + i];
- int index2 = TablesMC.MC_TRI_TABLE[cubeindex + i + 1];
- int index3 = TablesMC.MC_TRI_TABLE[cubeindex + i + 2];
-
- // Add triangles vertices normalized with the maximal possible value
- vertices.add(new float[] {vertList[index3][0] / maxAxisVal - 0.5f, vertList[index3][1] / maxAxisVal - 0.5f, vertList[index3][2] / maxAxisVal - 0.5f});
- vertices.add(new float[] {vertList[index2][0] / maxAxisVal - 0.5f, vertList[index2][1] / maxAxisVal - 0.5f, vertList[index2][2] / maxAxisVal - 0.5f});
- vertices.add(new float[] {vertList[index1][0] / maxAxisVal - 0.5f, vertList[index1][1] / maxAxisVal - 0.5f, vertList[index1][2] / maxAxisVal - 0.5f});
-
- i += 3;
- }
- }
- }
- }
-
- callback.setVertices(vertices);
- callback.run();
- }
-
- static void marchingCubesDouble(double[] values, int[] volDim, int volZFull, float[] voxDim, double isoLevel, int offset, CallbackMC callback) {
-
- ArrayList vertices = new ArrayList<>();
- // Actual position along edge weighted according to function values.
- float vertList[][] = new float[12][3];
-
-
- // Calculate maximal possible axis value (used in vertice normalization)
- float maxX = voxDim[0] * (volDim[0] - 1);
- float maxY = voxDim[1] * (volDim[1] - 1);
- float maxZ = voxDim[2] * (volZFull - 1);
- float maxAxisVal = Math.max(maxX, Math.max(maxY, maxZ));
-
- // Volume iteration
- for (int z = 0; z < volDim[2] - 1; z++) {
- for (int y = 0; y < volDim[1] - 1; y++) {
- for (int x = 0; x < volDim[0] - 1; x++) {
-
- // Indices pointing to cube vertices
- // pyz ___________________ pxyz
- // /| /|
- // / | / |
- // / | / |
- // pz /___|______________/pxz|
- // | | | |
- // | | | |
- // | py |______________|___| pxy
- // | / | /
- // | / | /
- // | / | /
- // |/__________________|/
- // p px
-
- int p = x + (volDim[0] * y) + (volDim[0] * volDim[1] * (z + offset)),
- px = p + 1,
- py = p + volDim[0],
- pxy = py + 1,
- pz = p + volDim[0] * volDim[1],
- pxz = px + volDim[0] * volDim[1],
- pyz = py + volDim[0] * volDim[1],
- pxyz = pxy + volDim[0] * volDim[1];
-
- // X Y Z
- float position[] = new float[]{x * voxDim[0], y * voxDim[1], (z + offset) * voxDim[2]};
-
- // Voxel intensities
- double value0 = values[p],
- value1 = values[px],
- value2 = values[py],
- value3 = values[pxy],
- value4 = values[pz],
- value5 = values[pxz],
- value6 = values[pyz],
- value7 = values[pxyz];
-
- // Voxel is active if its intensity is above isolevel
- int cubeindex = 0;
- if (value0 > isoLevel) cubeindex |= 1;
- if (value1 > isoLevel) cubeindex |= 2;
- if (value2 > isoLevel) cubeindex |= 8;
- if (value3 > isoLevel) cubeindex |= 4;
- if (value4 > isoLevel) cubeindex |= 16;
- if (value5 > isoLevel) cubeindex |= 32;
- if (value6 > isoLevel) cubeindex |= 128;
- if (value7 > isoLevel) cubeindex |= 64;
-
- // Fetch the triggered edges
- int bits = TablesMC.MC_EDGE_TABLE[cubeindex];
-
- // If no edge is triggered... skip
- if (bits == 0) continue;
-
- // Interpolate the positions based od voxel intensities
- float mu = 0.5f;
-
- // bottom of the cube
- if ((bits & 1) != 0) {
- mu = (float) ((isoLevel - value0) / (value1 - value0));
- vertList[0] = lerp(position, new float[]{position[0] + voxDim[0], position[1], position[2]}, mu);
- }
- if ((bits & 2) != 0) {
- mu = (float) ((isoLevel - value1) / (value3 - value1));
- vertList[1] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
- }
- if ((bits & 4) != 0) {
- mu = (float) ((isoLevel - value2) / (value3 - value2));
- vertList[2] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
- }
- if ((bits & 8) != 0) {
- mu = (float) ((isoLevel - value0) / (value2 - value0));
- vertList[3] = lerp(position, new float[]{position[0], position[1] + voxDim[1], position[2]}, mu);
- }
- // top of the cube
- if ((bits & 16) != 0) {
- mu = (float) ((isoLevel - value4) / (value5 - value4));
- vertList[4] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 32) != 0) {
- mu = (float) ((isoLevel - value5) / (value7 - value5));
- vertList[5] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 64) != 0) {
- mu = (float) ((isoLevel - value6) / (value7 - value6));
- vertList[6] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 128) != 0) {
- mu = (float) ((isoLevel - value4) / (value6 - value4));
- vertList[7] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
- // vertical lines of the cube
- if ((bits & 256) != 0) {
- mu = (float) ((isoLevel - value0) / (value4 - value0));
- vertList[8] = lerp(position, new float[]{position[0], position[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 512) != 0) {
- mu = (float) ((isoLevel - value1) / (value5 - value1));
- vertList[9] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 1024) != 0) {
- mu = (float) ((isoLevel - value3) / (value7 - value3));
- vertList[10] = lerp(new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1]+ voxDim[1], position[2] + voxDim[2]}, mu);
- }
- if ((bits & 2048) != 0) {
- mu = (float) ((isoLevel - value2) / (value6 - value2));
- vertList[11] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
- }
-
- // construct triangles -- get correct vertices from triTable.
- int i = 0;
- // "Re-purpose cubeindex into an offset into triTable."
- cubeindex <<= 4;
-
- while (TablesMC.MC_TRI_TABLE[cubeindex + i] != -1) {
- int index1 = TablesMC.MC_TRI_TABLE[cubeindex + i];
- int index2 = TablesMC.MC_TRI_TABLE[cubeindex + i + 1];
- int index3 = TablesMC.MC_TRI_TABLE[cubeindex + i + 2];
-
- // Add triangles vertices normalized with the maximal possible value
- vertices.add(new float[] {vertList[index3][0] / maxAxisVal - 0.5f, vertList[index3][1] / maxAxisVal - 0.5f, vertList[index3][2] / maxAxisVal - 0.5f});
- vertices.add(new float[] {vertList[index2][0] / maxAxisVal - 0.5f, vertList[index2][1] / maxAxisVal - 0.5f, vertList[index2][2] / maxAxisVal - 0.5f});
- vertices.add(new float[] {vertList[index1][0] / maxAxisVal - 0.5f, vertList[index1][1] / maxAxisVal - 0.5f, vertList[index1][2] / maxAxisVal - 0.5f});
-
- i += 3;
- }
- }
- }
- }
-
- callback.setVertices(vertices);
- callback.run();
- }
-
- public static ArrayList marchingCubes(Array values, Array xc, Array yc, Array zc, float isoLevel) {
-
- ArrayList vertices = new ArrayList<>();
- // Actual position along edge weighted according to function values.
- float vertList[][] = new float[12][3];
-
- int[] shape = values.getShape();
- int[] volDim = new int[]{shape[2], shape[1], shape[0]};
-
- // Volume iteration
- float xx, yy, zz;
- for (int z = 0; z < volDim[2] - 1; z++) {
- zz = zc.getFloat(z);
- for (int y = 0; y < volDim[1] - 1; y++) {
- yy = yc.getFloat(y);
- for (int x = 0; x < volDim[0] - 1; x++) {
- xx = xc.getFloat(x);
- // Indices pointing to cube vertices
- // pyz ___________________ pxyz
- // /| /|
- // / | / |
- // / | / |
- // pz /___|______________/pxz|
- // | | | |
- // | | | |
- // | py |______________|___| pxy
- // | / | /
- // | / | /
- // | / | /
- // |/__________________|/
- // p px
-
- int p = x + (volDim[0] * y) + (volDim[0] * volDim[1] * z),
- px = p + 1,
- py = p + volDim[0],
- pxy = py + 1,
- pz = p + volDim[0] * volDim[1],
- pxz = px + volDim[0] * volDim[1],
- pyz = py + volDim[0] * volDim[1],
- pxyz = pxy + volDim[0] * volDim[1];
-
- // X, Y, Z position
- //float position[] = new float[]{xx, yy, zz};
-
- // Voxel intensities
- float value0 = values.getFloat(p),
- value1 = values.getFloat(px),
- value2 = values.getFloat(py),
- value3 = values.getFloat(pxy),
- value4 = values.getFloat(pz),
- value5 = values.getFloat(pxz),
- value6 = values.getFloat(pyz),
- value7 = values.getFloat(pxyz);
-
- // Voxel is active if its intensity is above isolevel
- int cubeindex = 0;
- if (value0 > isoLevel) cubeindex |= 1;
- if (value1 > isoLevel) cubeindex |= 2;
- if (value2 > isoLevel) cubeindex |= 8;
- if (value3 > isoLevel) cubeindex |= 4;
- if (value4 > isoLevel) cubeindex |= 16;
- if (value5 > isoLevel) cubeindex |= 32;
- if (value6 > isoLevel) cubeindex |= 128;
- if (value7 > isoLevel) cubeindex |= 64;
-
- // Fetch the triggered edges
- int bits = TablesMC.MC_EDGE_TABLE[cubeindex];
-
- // If no edge is triggered... skip
- if (bits == 0) continue;
-
- // Interpolate the positions based od voxel intensities
- float mu = 0.5f;
-
- // bottom of the cube
- if ((bits & 1) != 0) {
- mu = (float) ((isoLevel - value0) / (value1 - value0));
- vertList[0] = lerp(new float[]{xx, yy, zz}, new float[]{xc.getFloat(x + 1), yy, zz}, mu);
- }
- if ((bits & 2) != 0) {
- mu = (float) ((isoLevel - value1) / (value3 - value1));
- vertList[1] = lerp(new float[]{xc.getFloat(x + 1), yy, zz}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zz}, mu);
- }
- if ((bits & 4) != 0) {
- mu = (float) ((isoLevel - value2) / (value3 - value2));
- vertList[2] = lerp(new float[]{xx, yc.getFloat(y + 1), zz}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zz}, mu);
- }
- if ((bits & 8) != 0) {
- mu = (float) ((isoLevel - value0) / (value2 - value0));
- vertList[3] = lerp(new float[]{xx, yy, zz}, new float[]{xx, yc.getFloat(y + 1), zz}, mu);
- }
- // top of the cube
- if ((bits & 16) != 0) {
- mu = (float) ((isoLevel - value4) / (value5 - value4));
- vertList[4] = lerp(new float[]{xx, yy, zc.getFloat(z + 1)}, new float[]{xc.getFloat(x + 1), yy, zc.getFloat(z + 1)}, mu);
- }
- if ((bits & 32) != 0) {
- mu = (float) ((isoLevel - value5) / (value7 - value5));
- vertList[5] = lerp(new float[]{xc.getFloat(x + 1), yy, zc.getFloat(z + 1)}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
- }
- if ((bits & 64) != 0) {
- mu = (float) ((isoLevel - value6) / (value7 - value6));
- vertList[6] = lerp(new float[]{xx, yc.getFloat(y + 1), zc.getFloat(z + 1)}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
- }
- if ((bits & 128) != 0) {
- mu = (float) ((isoLevel - value4) / (value6 - value4));
- vertList[7] = lerp(new float[]{xx, yy, zc.getFloat(z + 1)}, new float[]{xx, yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
- }
- // vertical lines of the cube
- if ((bits & 256) != 0) {
- mu = (float) ((isoLevel - value0) / (value4 - value0));
- vertList[8] = lerp(new float[]{xx, yy, zz}, new float[]{xx, yy, zc.getFloat(z + 1)}, mu);
- }
- if ((bits & 512) != 0) {
- mu = (float) ((isoLevel - value1) / (value5 - value1));
- vertList[9] = lerp(new float[]{xc.getFloat(x + 1), yy, zz}, new float[]{xc.getFloat(x + 1), yy, zc.getFloat(z + 1)}, mu);
- }
- if ((bits & 1024) != 0) {
- mu = (float) ((isoLevel - value3) / (value7 - value3));
- vertList[10] = lerp(new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zz}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
- }
- if ((bits & 2048) != 0) {
- mu = (float) ((isoLevel - value2) / (value6 - value2));
- vertList[11] = lerp(new float[]{xx, yc.getFloat(y + 1), zz}, new float[]{xx, yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
- }
-
- // construct triangles -- get correct vertices from triTable.
- int i = 0;
- // "Re-purpose cubeindex into an offset into triTable."
- cubeindex <<= 4;
-
- while (TablesMC.MC_TRI_TABLE[cubeindex + i] != -1) {
- int index1 = TablesMC.MC_TRI_TABLE[cubeindex + i];
- int index2 = TablesMC.MC_TRI_TABLE[cubeindex + i + 1];
- int index3 = TablesMC.MC_TRI_TABLE[cubeindex + i + 2];
-
- // Add triangles vertices
- vertices.add(new float[] {vertList[index3][0], vertList[index3][1], vertList[index3][2]});
- vertices.add(new float[] {vertList[index2][0], vertList[index2][1], vertList[index2][2]});
- vertices.add(new float[] {vertList[index1][0], vertList[index1][1], vertList[index1][2]});
-
- i += 3;
- }
- }
- }
- }
-
- return vertices;
- }
-
- public static void marchingCubes(Array values, Array xc, Array yc, Array zc, float isoLevel,
- int len, int offset, CallbackMC callback) {
-
- ArrayList vertices = new ArrayList<>();
- // Actual position along edge weighted according to function values.
- float vertList[][] = new float[12][3];
-
- int[] shape = values.getShape();
- int[] volDim = new int[]{shape[2], shape[1], len};
-
- // Volume iteration
- float xx, yy, zz;
- for (int z = offset; z < volDim[2] - 1 + offset; z++) {
- zz = zc.getFloat(z);
- for (int y = 0; y < volDim[1] - 1; y++) {
- yy = yc.getFloat(y);
- for (int x = 0; x < volDim[0] - 1; x++) {
- xx = xc.getFloat(x);
- // Indices pointing to cube vertices
- // pyz ___________________ pxyz
- // /| /|
- // / | / |
- // / | / |
- // pz /___|______________/pxz|
- // | | | |
- // | | | |
- // | py |______________|___| pxy
- // | / | /
- // | / | /
- // | / | /
- // |/__________________|/
- // p px
-
- int p = x + (volDim[0] * y) + (volDim[0] * volDim[1] * z),
- px = p + 1,
- py = p + volDim[0],
- pxy = py + 1,
- pz = p + volDim[0] * volDim[1],
- pxz = px + volDim[0] * volDim[1],
- pyz = py + volDim[0] * volDim[1],
- pxyz = pxy + volDim[0] * volDim[1];
-
- // X, Y, Z position
- //float position[] = new float[]{xx, yy, zz};
-
- // Voxel intensities
- float value0 = values.getFloat(p),
- value1 = values.getFloat(px),
- value2 = values.getFloat(py),
- value3 = values.getFloat(pxy),
- value4 = values.getFloat(pz),
- value5 = values.getFloat(pxz),
- value6 = values.getFloat(pyz),
- value7 = values.getFloat(pxyz);
-
- // Voxel is active if its intensity is above isolevel
- int cubeindex = 0;
- if (value0 > isoLevel) cubeindex |= 1;
- if (value1 > isoLevel) cubeindex |= 2;
- if (value2 > isoLevel) cubeindex |= 8;
- if (value3 > isoLevel) cubeindex |= 4;
- if (value4 > isoLevel) cubeindex |= 16;
- if (value5 > isoLevel) cubeindex |= 32;
- if (value6 > isoLevel) cubeindex |= 128;
- if (value7 > isoLevel) cubeindex |= 64;
-
- // Fetch the triggered edges
- int bits = TablesMC.MC_EDGE_TABLE[cubeindex];
-
- // If no edge is triggered... skip
- if (bits == 0) continue;
-
- // Interpolate the positions based od voxel intensities
- float mu = 0.5f;
-
- // bottom of the cube
- if ((bits & 1) != 0) {
- mu = (float) ((isoLevel - value0) / (value1 - value0));
- vertList[0] = lerp(new float[]{xx, yy, zz}, new float[]{xc.getFloat(x + 1), yy, zz}, mu);
- }
- if ((bits & 2) != 0) {
- mu = (float) ((isoLevel - value1) / (value3 - value1));
- vertList[1] = lerp(new float[]{xc.getFloat(x + 1), yy, zz}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zz}, mu);
- }
- if ((bits & 4) != 0) {
- mu = (float) ((isoLevel - value2) / (value3 - value2));
- vertList[2] = lerp(new float[]{xx, yc.getFloat(y + 1), zz}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zz}, mu);
- }
- if ((bits & 8) != 0) {
- mu = (float) ((isoLevel - value0) / (value2 - value0));
- vertList[3] = lerp(new float[]{xx, yy, zz}, new float[]{xx, yc.getFloat(y + 1), zz}, mu);
- }
- // top of the cube
- if ((bits & 16) != 0) {
- mu = (float) ((isoLevel - value4) / (value5 - value4));
- vertList[4] = lerp(new float[]{xx, yy, zc.getFloat(z + 1)}, new float[]{xc.getFloat(x + 1), yy, zc.getFloat(z + 1)}, mu);
- }
- if ((bits & 32) != 0) {
- mu = (float) ((isoLevel - value5) / (value7 - value5));
- vertList[5] = lerp(new float[]{xc.getFloat(x + 1), yy, zc.getFloat(z + 1)}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
- }
- if ((bits & 64) != 0) {
- mu = (float) ((isoLevel - value6) / (value7 - value6));
- vertList[6] = lerp(new float[]{xx, yc.getFloat(y + 1), zc.getFloat(z + 1)}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
- }
- if ((bits & 128) != 0) {
- mu = (float) ((isoLevel - value4) / (value6 - value4));
- vertList[7] = lerp(new float[]{xx, yy, zc.getFloat(z + 1)}, new float[]{xx, yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
- }
- // vertical lines of the cube
- if ((bits & 256) != 0) {
- mu = (float) ((isoLevel - value0) / (value4 - value0));
- vertList[8] = lerp(new float[]{xx, yy, zz}, new float[]{xx, yy, zc.getFloat(z + 1)}, mu);
- }
- if ((bits & 512) != 0) {
- mu = (float) ((isoLevel - value1) / (value5 - value1));
- vertList[9] = lerp(new float[]{xc.getFloat(x + 1), yy, zz}, new float[]{xc.getFloat(x + 1), yy, zc.getFloat(z + 1)}, mu);
- }
- if ((bits & 1024) != 0) {
- mu = (float) ((isoLevel - value3) / (value7 - value3));
- vertList[10] = lerp(new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zz}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
- }
- if ((bits & 2048) != 0) {
- mu = (float) ((isoLevel - value2) / (value6 - value2));
- vertList[11] = lerp(new float[]{xx, yc.getFloat(y + 1), zz}, new float[]{xx, yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
- }
-
- // construct triangles -- get correct vertices from triTable.
- int i = 0;
- // "Re-purpose cubeindex into an offset into triTable."
- cubeindex <<= 4;
-
- while (TablesMC.MC_TRI_TABLE[cubeindex + i] != -1) {
- int index1 = TablesMC.MC_TRI_TABLE[cubeindex + i];
- int index2 = TablesMC.MC_TRI_TABLE[cubeindex + i + 1];
- int index3 = TablesMC.MC_TRI_TABLE[cubeindex + i + 2];
-
- // Add triangles vertices
- vertices.add(new float[] {vertList[index3][0], vertList[index3][1], vertList[index3][2]});
- vertices.add(new float[] {vertList[index2][0], vertList[index2][1], vertList[index2][2]});
- vertices.add(new float[] {vertList[index1][0], vertList[index1][1], vertList[index1][2]});
-
- i += 3;
- }
- }
- }
- }
-
- callback.setVertices(vertices);
- callback.run();
- }
-}
+/*
+ * 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.jogl.mc;
+
+import org.meteoinfo.ndarray.Array;
+
+import java.util.ArrayList;
+
+/**
+ * Created by Primoz on 11. 07. 2016.
+ */
+public class MarchingCubes {
+ static float[] lerp(float[] vec1, float[] vec2, float alpha){
+ return new float[]{vec1[0] + (vec2[0] - vec1[0]) * alpha, vec1[1] + (vec2[1] - vec1[1]) * alpha, vec1[2] + (vec2[2] - vec1[2]) * alpha};
+ }
+
+ static void marchingCubesChar(char[] values, int[] volDim, int volZFull, float[] voxDim, char isoLevel, int offset, CallbackMC callback) {
+
+ ArrayList vertices = new ArrayList<>();
+ // Actual position along edge weighted according to function values.
+ float vertList[][] = new float[12][3];
+
+
+ // Calculate maximal possible axis value (used in vertice normalization)
+ float maxX = voxDim[0] * (volDim[0] - 1);
+ float maxY = voxDim[1] * (volDim[1] - 1);
+ float maxZ = voxDim[2] * (volZFull - 1);
+ float maxAxisVal = Math.max(maxX, Math.max(maxY, maxZ));
+
+ // Volume iteration
+ for (int z = 0; z < volDim[2] - 1; z++) {
+ for (int y = 0; y < volDim[1] - 1; y++) {
+ for (int x = 0; x < volDim[0] - 1; x++) {
+
+ // Indices pointing to cube vertices
+ // pyz ___________________ pxyz
+ // /| /|
+ // / | / |
+ // / | / |
+ // pz /___|______________/pxz|
+ // | | | |
+ // | | | |
+ // | py |______________|___| pxy
+ // | / | /
+ // | / | /
+ // | / | /
+ // |/__________________|/
+ // p px
+
+ int p = x + (volDim[0] * y) + (volDim[0] * volDim[1] * (z + offset)),
+ px = p + 1,
+ py = p + volDim[0],
+ pxy = py + 1,
+ pz = p + volDim[0] * volDim[1],
+ pxz = px + volDim[0] * volDim[1],
+ pyz = py + volDim[0] * volDim[1],
+ pxyz = pxy + volDim[0] * volDim[1];
+
+ // X Y Z
+ float position[] = new float[]{x * voxDim[0], y * voxDim[1], (z + offset) * voxDim[2]};
+
+ // Voxel intensities
+ char value0 = values[p],
+ value1 = values[px],
+ value2 = values[py],
+ value3 = values[pxy],
+ value4 = values[pz],
+ value5 = values[pxz],
+ value6 = values[pyz],
+ value7 = values[pxyz];
+
+ // Voxel is active if its intensity is above isolevel
+ int cubeindex = 0;
+ if (value0 > isoLevel) cubeindex |= 1;
+ if (value1 > isoLevel) cubeindex |= 2;
+ if (value2 > isoLevel) cubeindex |= 8;
+ if (value3 > isoLevel) cubeindex |= 4;
+ if (value4 > isoLevel) cubeindex |= 16;
+ if (value5 > isoLevel) cubeindex |= 32;
+ if (value6 > isoLevel) cubeindex |= 128;
+ if (value7 > isoLevel) cubeindex |= 64;
+
+ // Fetch the triggered edges
+ int bits = TablesMC.MC_EDGE_TABLE[cubeindex];
+
+ // If no edge is triggered... skip
+ if (bits == 0) continue;
+
+ // Interpolate the positions based od voxel intensities
+ float mu = 0.5f;
+
+ // bottom of the cube
+ if ((bits & 1) != 0) {
+ mu = (isoLevel - value0) / (value1 - value0);
+ vertList[0] = lerp(position, new float[]{position[0] + voxDim[0], position[1], position[2]}, mu);
+ }
+ if ((bits & 2) != 0) {
+ mu = (isoLevel - value1) / (value3 - value1);
+ vertList[1] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
+ }
+ if ((bits & 4) != 0) {
+ mu = (isoLevel - value2) / (value3 - value2);
+ vertList[2] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
+ }
+ if ((bits & 8) != 0) {
+ mu = (isoLevel - value0) / (value2 - value0);
+ vertList[3] = lerp(position, new float[]{position[0], position[1] + voxDim[1], position[2]}, mu);
+ }
+ // top of the cube
+ if ((bits & 16) != 0) {
+ mu = (isoLevel - value4) / (value5 - value4);
+ vertList[4] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 32) != 0) {
+ mu = (isoLevel - value5) / (value7 - value5);
+ vertList[5] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 64) != 0) {
+ mu = (isoLevel - value6) / (value7 - value6);
+ vertList[6] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 128) != 0) {
+ mu = (isoLevel - value4) / (value6 - value4);
+ vertList[7] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ // vertical lines of the cube
+ if ((bits & 256) != 0) {
+ mu = (isoLevel - value0) / (value4 - value0);
+ vertList[8] = lerp(position, new float[]{position[0], position[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 512) != 0) {
+ mu = (isoLevel - value1) / (value5 - value1);
+ vertList[9] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 1024) != 0) {
+ mu = (isoLevel - value3) / (value7 - value3);
+ vertList[10] = lerp(new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1]+ voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 2048) != 0) {
+ mu = (isoLevel - value2) / (value6 - value2);
+ vertList[11] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+
+ // construct triangles -- get correct vertices from triTable.
+ int i = 0;
+ // "Re-purpose cubeindex into an offset into triTable."
+ cubeindex <<= 4;
+
+ while (TablesMC.MC_TRI_TABLE[cubeindex + i] != -1) {
+ int index1 = TablesMC.MC_TRI_TABLE[cubeindex + i];
+ int index2 = TablesMC.MC_TRI_TABLE[cubeindex + i + 1];
+ int index3 = TablesMC.MC_TRI_TABLE[cubeindex + i + 2];
+
+ // Add triangles vertices normalized with the maximal possible value
+ vertices.add(new float[] {vertList[index3][0] / maxAxisVal - 0.5f, vertList[index3][1] / maxAxisVal - 0.5f, vertList[index3][2] / maxAxisVal - 0.5f});
+ vertices.add(new float[] {vertList[index2][0] / maxAxisVal - 0.5f, vertList[index2][1] / maxAxisVal - 0.5f, vertList[index2][2] / maxAxisVal - 0.5f});
+ vertices.add(new float[] {vertList[index1][0] / maxAxisVal - 0.5f, vertList[index1][1] / maxAxisVal - 0.5f, vertList[index1][2] / maxAxisVal - 0.5f});
+
+ i += 3;
+ }
+ }
+ }
+ }
+
+ callback.setVertices(vertices);
+ callback.run();
+ }
+
+ static void marchingCubesShort(short[] values, int[] volDim, int volZFull, float[] voxDim, short isoLevel, int offset, CallbackMC callback) {
+
+ ArrayList vertices = new ArrayList<>();
+ // Actual position along edge weighted according to function values.
+ float vertList[][] = new float[12][3];
+
+
+ // Calculate maximal possible axis value (used in vertice normalization)
+ float maxX = voxDim[0] * (volDim[0] - 1);
+ float maxY = voxDim[1] * (volDim[1] - 1);
+ float maxZ = voxDim[2] * (volZFull - 1);
+ float maxAxisVal = Math.max(maxX, Math.max(maxY, maxZ));
+
+ // Volume iteration
+ for (int z = 0; z < volDim[2] - 1; z++) {
+ for (int y = 0; y < volDim[1] - 1; y++) {
+ for (int x = 0; x < volDim[0] - 1; x++) {
+
+ // Indices pointing to cube vertices
+ // pyz ___________________ pxyz
+ // /| /|
+ // / | / |
+ // / | / |
+ // pz /___|______________/pxz|
+ // | | | |
+ // | | | |
+ // | py |______________|___| pxy
+ // | / | /
+ // | / | /
+ // | / | /
+ // |/__________________|/
+ // p px
+
+ int p = x + (volDim[0] * y) + (volDim[0] * volDim[1] * (z + offset)),
+ px = p + 1,
+ py = p + volDim[0],
+ pxy = py + 1,
+ pz = p + volDim[0] * volDim[1],
+ pxz = px + volDim[0] * volDim[1],
+ pyz = py + volDim[0] * volDim[1],
+ pxyz = pxy + volDim[0] * volDim[1];
+
+ // X Y Z
+ float position[] = new float[]{x * voxDim[0], y * voxDim[1], (z + offset) * voxDim[2]};
+
+ // Voxel intensities
+ short value0 = values[p],
+ value1 = values[px],
+ value2 = values[py],
+ value3 = values[pxy],
+ value4 = values[pz],
+ value5 = values[pxz],
+ value6 = values[pyz],
+ value7 = values[pxyz];
+
+ // Voxel is active if its intensity is above isolevel
+ int cubeindex = 0;
+ if (value0 > isoLevel) cubeindex |= 1;
+ if (value1 > isoLevel) cubeindex |= 2;
+ if (value2 > isoLevel) cubeindex |= 8;
+ if (value3 > isoLevel) cubeindex |= 4;
+ if (value4 > isoLevel) cubeindex |= 16;
+ if (value5 > isoLevel) cubeindex |= 32;
+ if (value6 > isoLevel) cubeindex |= 128;
+ if (value7 > isoLevel) cubeindex |= 64;
+
+ // Fetch the triggered edges
+ int bits = TablesMC.MC_EDGE_TABLE[cubeindex];
+
+ // If no edge is triggered... skip
+ if (bits == 0) continue;
+
+ // Interpolate the positions based od voxel intensities
+ float mu = 0.5f;
+
+ // bottom of the cube
+ if ((bits & 1) != 0) {
+ mu = (isoLevel - value0) / (value1 - value0);
+ vertList[0] = lerp(position, new float[]{position[0] + voxDim[0], position[1], position[2]}, mu);
+ }
+ if ((bits & 2) != 0) {
+ mu = (isoLevel - value1) / (value3 - value1);
+ vertList[1] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
+ }
+ if ((bits & 4) != 0) {
+ mu = (isoLevel - value2) / (value3 - value2);
+ vertList[2] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
+ }
+ if ((bits & 8) != 0) {
+ mu = (isoLevel - value0) / (value2 - value0);
+ vertList[3] = lerp(position, new float[]{position[0], position[1] + voxDim[1], position[2]}, mu);
+ }
+ // top of the cube
+ if ((bits & 16) != 0) {
+ mu = (isoLevel - value4) / (value5 - value4);
+ vertList[4] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 32) != 0) {
+ mu = (isoLevel - value5) / (value7 - value5);
+ vertList[5] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 64) != 0) {
+ mu = (isoLevel - value6) / (value7 - value6);
+ vertList[6] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 128) != 0) {
+ mu = (isoLevel - value4) / (value6 - value4);
+ vertList[7] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ // vertical lines of the cube
+ if ((bits & 256) != 0) {
+ mu = (isoLevel - value0) / (value4 - value0);
+ vertList[8] = lerp(position, new float[]{position[0], position[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 512) != 0) {
+ mu = (isoLevel - value1) / (value5 - value1);
+ vertList[9] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 1024) != 0) {
+ mu = (isoLevel - value3) / (value7 - value3);
+ vertList[10] = lerp(new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1]+ voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 2048) != 0) {
+ mu = (isoLevel - value2) / (value6 - value2);
+ vertList[11] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+
+ // construct triangles -- get correct vertices from triTable.
+ int i = 0;
+ // "Re-purpose cubeindex into an offset into triTable."
+ cubeindex <<= 4;
+
+ while (TablesMC.MC_TRI_TABLE[cubeindex + i] != -1) {
+ int index1 = TablesMC.MC_TRI_TABLE[cubeindex + i];
+ int index2 = TablesMC.MC_TRI_TABLE[cubeindex + i + 1];
+ int index3 = TablesMC.MC_TRI_TABLE[cubeindex + i + 2];
+
+ // Add triangles vertices normalized with the maximal possible value
+ vertices.add(new float[] {vertList[index3][0] / maxAxisVal - 0.5f, vertList[index3][1] / maxAxisVal - 0.5f, vertList[index3][2] / maxAxisVal - 0.5f});
+ vertices.add(new float[] {vertList[index2][0] / maxAxisVal - 0.5f, vertList[index2][1] / maxAxisVal - 0.5f, vertList[index2][2] / maxAxisVal - 0.5f});
+ vertices.add(new float[] {vertList[index1][0] / maxAxisVal - 0.5f, vertList[index1][1] / maxAxisVal - 0.5f, vertList[index1][2] / maxAxisVal - 0.5f});
+
+ i += 3;
+ }
+ }
+ }
+ }
+
+ callback.setVertices(vertices);
+ callback.run();
+ }
+
+ static void marchingCubesInt(int[] values, int[] volDim, int volZFull, float[] voxDim, int isoLevel, int offset, CallbackMC callback) {
+
+ ArrayList vertices = new ArrayList<>();
+ // Actual position along edge weighted according to function values.
+ float vertList[][] = new float[12][3];
+
+
+ // Calculate maximal possible axis value (used in vertice normalization)
+ float maxX = voxDim[0] * (volDim[0] - 1);
+ float maxY = voxDim[1] * (volDim[1] - 1);
+ float maxZ = voxDim[2] * (volZFull - 1);
+ float maxAxisVal = Math.max(maxX, Math.max(maxY, maxZ));
+
+ // Volume iteration
+ for (int z = 0; z < volDim[2] - 1; z++) {
+ for (int y = 0; y < volDim[1] - 1; y++) {
+ for (int x = 0; x < volDim[0] - 1; x++) {
+
+ // Indices pointing to cube vertices
+ // pyz ___________________ pxyz
+ // /| /|
+ // / | / |
+ // / | / |
+ // pz /___|______________/pxz|
+ // | | | |
+ // | | | |
+ // | py |______________|___| pxy
+ // | / | /
+ // | / | /
+ // | / | /
+ // |/__________________|/
+ // p px
+
+ int p = x + (volDim[0] * y) + (volDim[0] * volDim[1] * (z + offset)),
+ px = p + 1,
+ py = p + volDim[0],
+ pxy = py + 1,
+ pz = p + volDim[0] * volDim[1],
+ pxz = px + volDim[0] * volDim[1],
+ pyz = py + volDim[0] * volDim[1],
+ pxyz = pxy + volDim[0] * volDim[1];
+
+ // X Y Z
+ float position[] = new float[]{x * voxDim[0], y * voxDim[1], (z + offset) * voxDim[2]};
+
+ // Voxel intensities
+ int value0 = values[p],
+ value1 = values[px],
+ value2 = values[py],
+ value3 = values[pxy],
+ value4 = values[pz],
+ value5 = values[pxz],
+ value6 = values[pyz],
+ value7 = values[pxyz];
+
+ // Voxel is active if its intensity is above isolevel
+ int cubeindex = 0;
+ if (value0 > isoLevel) cubeindex |= 1;
+ if (value1 > isoLevel) cubeindex |= 2;
+ if (value2 > isoLevel) cubeindex |= 8;
+ if (value3 > isoLevel) cubeindex |= 4;
+ if (value4 > isoLevel) cubeindex |= 16;
+ if (value5 > isoLevel) cubeindex |= 32;
+ if (value6 > isoLevel) cubeindex |= 128;
+ if (value7 > isoLevel) cubeindex |= 64;
+
+ // Fetch the triggered edges
+ int bits = TablesMC.MC_EDGE_TABLE[cubeindex];
+
+ // If no edge is triggered... skip
+ if (bits == 0) continue;
+
+ // Interpolate the positions based od voxel intensities
+ float mu = 0.5f;
+
+ // bottom of the cube
+ if ((bits & 1) != 0) {
+ mu = (isoLevel - value0) / (value1 - value0);
+ vertList[0] = lerp(position, new float[]{position[0] + voxDim[0], position[1], position[2]}, mu);
+ }
+ if ((bits & 2) != 0) {
+ mu = (isoLevel - value1) / (value3 - value1);
+ vertList[1] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
+ }
+ if ((bits & 4) != 0) {
+ mu = (isoLevel - value2) / (value3 - value2);
+ vertList[2] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
+ }
+ if ((bits & 8) != 0) {
+ mu = (isoLevel - value0) / (value2 - value0);
+ vertList[3] = lerp(position, new float[]{position[0], position[1] + voxDim[1], position[2]}, mu);
+ }
+ // top of the cube
+ if ((bits & 16) != 0) {
+ mu = (isoLevel - value4) / (value5 - value4);
+ vertList[4] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 32) != 0) {
+ mu = (isoLevel - value5) / (value7 - value5);
+ vertList[5] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 64) != 0) {
+ mu = (isoLevel - value6) / (value7 - value6);
+ vertList[6] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 128) != 0) {
+ mu = (isoLevel - value4) / (value6 - value4);
+ vertList[7] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ // vertical lines of the cube
+ if ((bits & 256) != 0) {
+ mu = (isoLevel - value0) / (value4 - value0);
+ vertList[8] = lerp(position, new float[]{position[0], position[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 512) != 0) {
+ mu = (isoLevel - value1) / (value5 - value1);
+ vertList[9] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 1024) != 0) {
+ mu = (isoLevel - value3) / (value7 - value3);
+ vertList[10] = lerp(new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1]+ voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 2048) != 0) {
+ mu = (isoLevel - value2) / (value6 - value2);
+ vertList[11] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+
+ // construct triangles -- get correct vertices from triTable.
+ int i = 0;
+ // "Re-purpose cubeindex into an offset into triTable."
+ cubeindex <<= 4;
+
+ while (TablesMC.MC_TRI_TABLE[cubeindex + i] != -1) {
+ int index1 = TablesMC.MC_TRI_TABLE[cubeindex + i];
+ int index2 = TablesMC.MC_TRI_TABLE[cubeindex + i + 1];
+ int index3 = TablesMC.MC_TRI_TABLE[cubeindex + i + 2];
+
+ // Add triangles vertices normalized with the maximal possible value
+ vertices.add(new float[] {vertList[index3][0] / maxAxisVal - 0.5f, vertList[index3][1] / maxAxisVal - 0.5f, vertList[index3][2] / maxAxisVal - 0.5f});
+ vertices.add(new float[] {vertList[index2][0] / maxAxisVal - 0.5f, vertList[index2][1] / maxAxisVal - 0.5f, vertList[index2][2] / maxAxisVal - 0.5f});
+ vertices.add(new float[] {vertList[index1][0] / maxAxisVal - 0.5f, vertList[index1][1] / maxAxisVal - 0.5f, vertList[index1][2] / maxAxisVal - 0.5f});
+
+ i += 3;
+ }
+ }
+ }
+ }
+
+ callback.setVertices(vertices);
+ callback.run();
+ }
+
+ static void marchingCubesFloat(float[] values, int[] volDim, int volZFull, float[] voxDim, float isoLevel, int offset, CallbackMC callback) {
+
+ ArrayList vertices = new ArrayList<>();
+ // Actual position along edge weighted according to function values.
+ float vertList[][] = new float[12][3];
+
+
+ // Calculate maximal possible axis value (used in vertice normalization)
+ float maxX = voxDim[0] * (volDim[0] - 1);
+ float maxY = voxDim[1] * (volDim[1] - 1);
+ float maxZ = voxDim[2] * (volZFull - 1);
+ float maxAxisVal = Math.max(maxX, Math.max(maxY, maxZ));
+
+ // Volume iteration
+ for (int z = 0; z < volDim[2] - 1; z++) {
+ for (int y = 0; y < volDim[1] - 1; y++) {
+ for (int x = 0; x < volDim[0] - 1; x++) {
+
+ // Indices pointing to cube vertices
+ // pyz ___________________ pxyz
+ // /| /|
+ // / | / |
+ // / | / |
+ // pz /___|______________/pxz|
+ // | | | |
+ // | | | |
+ // | py |______________|___| pxy
+ // | / | /
+ // | / | /
+ // | / | /
+ // |/__________________|/
+ // p px
+
+ int p = x + (volDim[0] * y) + (volDim[0] * volDim[1] * (z + offset)),
+ px = p + 1,
+ py = p + volDim[0],
+ pxy = py + 1,
+ pz = p + volDim[0] * volDim[1],
+ pxz = px + volDim[0] * volDim[1],
+ pyz = py + volDim[0] * volDim[1],
+ pxyz = pxy + volDim[0] * volDim[1];
+
+ // X Y Z
+ float position[] = new float[]{x * voxDim[0], y * voxDim[1], (z + offset) * voxDim[2]};
+
+ // Voxel intensities
+ float value0 = values[p],
+ value1 = values[px],
+ value2 = values[py],
+ value3 = values[pxy],
+ value4 = values[pz],
+ value5 = values[pxz],
+ value6 = values[pyz],
+ value7 = values[pxyz];
+
+ // Voxel is active if its intensity is above isolevel
+ int cubeindex = 0;
+ if (value0 > isoLevel) cubeindex |= 1;
+ if (value1 > isoLevel) cubeindex |= 2;
+ if (value2 > isoLevel) cubeindex |= 8;
+ if (value3 > isoLevel) cubeindex |= 4;
+ if (value4 > isoLevel) cubeindex |= 16;
+ if (value5 > isoLevel) cubeindex |= 32;
+ if (value6 > isoLevel) cubeindex |= 128;
+ if (value7 > isoLevel) cubeindex |= 64;
+
+ // Fetch the triggered edges
+ int bits = TablesMC.MC_EDGE_TABLE[cubeindex];
+
+ // If no edge is triggered... skip
+ if (bits == 0) continue;
+
+ // Interpolate the positions based od voxel intensities
+ float mu = 0.5f;
+
+ // bottom of the cube
+ if ((bits & 1) != 0) {
+ mu = (float) ((isoLevel - value0) / (value1 - value0));
+ vertList[0] = lerp(position, new float[]{position[0] + voxDim[0], position[1], position[2]}, mu);
+ }
+ if ((bits & 2) != 0) {
+ mu = (float) ((isoLevel - value1) / (value3 - value1));
+ vertList[1] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
+ }
+ if ((bits & 4) != 0) {
+ mu = (float) ((isoLevel - value2) / (value3 - value2));
+ vertList[2] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
+ }
+ if ((bits & 8) != 0) {
+ mu = (float) ((isoLevel - value0) / (value2 - value0));
+ vertList[3] = lerp(position, new float[]{position[0], position[1] + voxDim[1], position[2]}, mu);
+ }
+ // top of the cube
+ if ((bits & 16) != 0) {
+ mu = (float) ((isoLevel - value4) / (value5 - value4));
+ vertList[4] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 32) != 0) {
+ mu = (float) ((isoLevel - value5) / (value7 - value5));
+ vertList[5] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 64) != 0) {
+ mu = (float) ((isoLevel - value6) / (value7 - value6));
+ vertList[6] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 128) != 0) {
+ mu = (float) ((isoLevel - value4) / (value6 - value4));
+ vertList[7] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ // vertical lines of the cube
+ if ((bits & 256) != 0) {
+ mu = (float) ((isoLevel - value0) / (value4 - value0));
+ vertList[8] = lerp(position, new float[]{position[0], position[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 512) != 0) {
+ mu = (float) ((isoLevel - value1) / (value5 - value1));
+ vertList[9] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 1024) != 0) {
+ mu = (float) ((isoLevel - value3) / (value7 - value3));
+ vertList[10] = lerp(new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1]+ voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 2048) != 0) {
+ mu = (float) ((isoLevel - value2) / (value6 - value2));
+ vertList[11] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+
+ // construct triangles -- get correct vertices from triTable.
+ int i = 0;
+ // "Re-purpose cubeindex into an offset into triTable."
+ cubeindex <<= 4;
+
+ while (TablesMC.MC_TRI_TABLE[cubeindex + i] != -1) {
+ int index1 = TablesMC.MC_TRI_TABLE[cubeindex + i];
+ int index2 = TablesMC.MC_TRI_TABLE[cubeindex + i + 1];
+ int index3 = TablesMC.MC_TRI_TABLE[cubeindex + i + 2];
+
+ // Add triangles vertices normalized with the maximal possible value
+ vertices.add(new float[] {vertList[index3][0] / maxAxisVal - 0.5f, vertList[index3][1] / maxAxisVal - 0.5f, vertList[index3][2] / maxAxisVal - 0.5f});
+ vertices.add(new float[] {vertList[index2][0] / maxAxisVal - 0.5f, vertList[index2][1] / maxAxisVal - 0.5f, vertList[index2][2] / maxAxisVal - 0.5f});
+ vertices.add(new float[] {vertList[index1][0] / maxAxisVal - 0.5f, vertList[index1][1] / maxAxisVal - 0.5f, vertList[index1][2] / maxAxisVal - 0.5f});
+
+ i += 3;
+ }
+ }
+ }
+ }
+
+ callback.setVertices(vertices);
+ callback.run();
+ }
+
+ static void marchingCubesDouble(double[] values, int[] volDim, int volZFull, float[] voxDim, double isoLevel, int offset, CallbackMC callback) {
+
+ ArrayList vertices = new ArrayList<>();
+ // Actual position along edge weighted according to function values.
+ float vertList[][] = new float[12][3];
+
+
+ // Calculate maximal possible axis value (used in vertice normalization)
+ float maxX = voxDim[0] * (volDim[0] - 1);
+ float maxY = voxDim[1] * (volDim[1] - 1);
+ float maxZ = voxDim[2] * (volZFull - 1);
+ float maxAxisVal = Math.max(maxX, Math.max(maxY, maxZ));
+
+ // Volume iteration
+ for (int z = 0; z < volDim[2] - 1; z++) {
+ for (int y = 0; y < volDim[1] - 1; y++) {
+ for (int x = 0; x < volDim[0] - 1; x++) {
+
+ // Indices pointing to cube vertices
+ // pyz ___________________ pxyz
+ // /| /|
+ // / | / |
+ // / | / |
+ // pz /___|______________/pxz|
+ // | | | |
+ // | | | |
+ // | py |______________|___| pxy
+ // | / | /
+ // | / | /
+ // | / | /
+ // |/__________________|/
+ // p px
+
+ int p = x + (volDim[0] * y) + (volDim[0] * volDim[1] * (z + offset)),
+ px = p + 1,
+ py = p + volDim[0],
+ pxy = py + 1,
+ pz = p + volDim[0] * volDim[1],
+ pxz = px + volDim[0] * volDim[1],
+ pyz = py + volDim[0] * volDim[1],
+ pxyz = pxy + volDim[0] * volDim[1];
+
+ // X Y Z
+ float position[] = new float[]{x * voxDim[0], y * voxDim[1], (z + offset) * voxDim[2]};
+
+ // Voxel intensities
+ double value0 = values[p],
+ value1 = values[px],
+ value2 = values[py],
+ value3 = values[pxy],
+ value4 = values[pz],
+ value5 = values[pxz],
+ value6 = values[pyz],
+ value7 = values[pxyz];
+
+ // Voxel is active if its intensity is above isolevel
+ int cubeindex = 0;
+ if (value0 > isoLevel) cubeindex |= 1;
+ if (value1 > isoLevel) cubeindex |= 2;
+ if (value2 > isoLevel) cubeindex |= 8;
+ if (value3 > isoLevel) cubeindex |= 4;
+ if (value4 > isoLevel) cubeindex |= 16;
+ if (value5 > isoLevel) cubeindex |= 32;
+ if (value6 > isoLevel) cubeindex |= 128;
+ if (value7 > isoLevel) cubeindex |= 64;
+
+ // Fetch the triggered edges
+ int bits = TablesMC.MC_EDGE_TABLE[cubeindex];
+
+ // If no edge is triggered... skip
+ if (bits == 0) continue;
+
+ // Interpolate the positions based od voxel intensities
+ float mu = 0.5f;
+
+ // bottom of the cube
+ if ((bits & 1) != 0) {
+ mu = (float) ((isoLevel - value0) / (value1 - value0));
+ vertList[0] = lerp(position, new float[]{position[0] + voxDim[0], position[1], position[2]}, mu);
+ }
+ if ((bits & 2) != 0) {
+ mu = (float) ((isoLevel - value1) / (value3 - value1));
+ vertList[1] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
+ }
+ if ((bits & 4) != 0) {
+ mu = (float) ((isoLevel - value2) / (value3 - value2));
+ vertList[2] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, mu);
+ }
+ if ((bits & 8) != 0) {
+ mu = (float) ((isoLevel - value0) / (value2 - value0));
+ vertList[3] = lerp(position, new float[]{position[0], position[1] + voxDim[1], position[2]}, mu);
+ }
+ // top of the cube
+ if ((bits & 16) != 0) {
+ mu = (float) ((isoLevel - value4) / (value5 - value4));
+ vertList[4] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 32) != 0) {
+ mu = (float) ((isoLevel - value5) / (value7 - value5));
+ vertList[5] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 64) != 0) {
+ mu = (float) ((isoLevel - value6) / (value7 - value6));
+ vertList[6] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 128) != 0) {
+ mu = (float) ((isoLevel - value4) / (value6 - value4));
+ vertList[7] = lerp(new float[]{position[0], position[1], position[2] + voxDim[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ // vertical lines of the cube
+ if ((bits & 256) != 0) {
+ mu = (float) ((isoLevel - value0) / (value4 - value0));
+ vertList[8] = lerp(position, new float[]{position[0], position[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 512) != 0) {
+ mu = (float) ((isoLevel - value1) / (value5 - value1));
+ vertList[9] = lerp(new float[]{position[0] + voxDim[0], position[1], position[2]}, new float[]{position[0] + voxDim[0], position[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 1024) != 0) {
+ mu = (float) ((isoLevel - value3) / (value7 - value3));
+ vertList[10] = lerp(new float[]{position[0] + voxDim[0], position[1] + voxDim[1], position[2]}, new float[]{position[0] + voxDim[0], position[1]+ voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+ if ((bits & 2048) != 0) {
+ mu = (float) ((isoLevel - value2) / (value6 - value2));
+ vertList[11] = lerp(new float[]{position[0], position[1] + voxDim[1], position[2]}, new float[]{position[0], position[1] + voxDim[1], position[2] + voxDim[2]}, mu);
+ }
+
+ // construct triangles -- get correct vertices from triTable.
+ int i = 0;
+ // "Re-purpose cubeindex into an offset into triTable."
+ cubeindex <<= 4;
+
+ while (TablesMC.MC_TRI_TABLE[cubeindex + i] != -1) {
+ int index1 = TablesMC.MC_TRI_TABLE[cubeindex + i];
+ int index2 = TablesMC.MC_TRI_TABLE[cubeindex + i + 1];
+ int index3 = TablesMC.MC_TRI_TABLE[cubeindex + i + 2];
+
+ // Add triangles vertices normalized with the maximal possible value
+ vertices.add(new float[] {vertList[index3][0] / maxAxisVal - 0.5f, vertList[index3][1] / maxAxisVal - 0.5f, vertList[index3][2] / maxAxisVal - 0.5f});
+ vertices.add(new float[] {vertList[index2][0] / maxAxisVal - 0.5f, vertList[index2][1] / maxAxisVal - 0.5f, vertList[index2][2] / maxAxisVal - 0.5f});
+ vertices.add(new float[] {vertList[index1][0] / maxAxisVal - 0.5f, vertList[index1][1] / maxAxisVal - 0.5f, vertList[index1][2] / maxAxisVal - 0.5f});
+
+ i += 3;
+ }
+ }
+ }
+ }
+
+ callback.setVertices(vertices);
+ callback.run();
+ }
+
+ public static ArrayList marchingCubes(Array values, Array xc, Array yc, Array zc, float isoLevel) {
+
+ ArrayList vertices = new ArrayList<>();
+ // Actual position along edge weighted according to function values.
+ float vertList[][] = new float[12][3];
+
+ int[] shape = values.getShape();
+ int[] volDim = new int[]{shape[2], shape[1], shape[0]};
+
+ // Volume iteration
+ float xx, yy, zz;
+ for (int z = 0; z < volDim[2] - 1; z++) {
+ zz = zc.getFloat(z);
+ for (int y = 0; y < volDim[1] - 1; y++) {
+ yy = yc.getFloat(y);
+ for (int x = 0; x < volDim[0] - 1; x++) {
+ xx = xc.getFloat(x);
+ // Indices pointing to cube vertices
+ // pyz ___________________ pxyz
+ // /| /|
+ // / | / |
+ // / | / |
+ // pz /___|______________/pxz|
+ // | | | |
+ // | | | |
+ // | py |______________|___| pxy
+ // | / | /
+ // | / | /
+ // | / | /
+ // |/__________________|/
+ // p px
+
+ int p = x + (volDim[0] * y) + (volDim[0] * volDim[1] * z),
+ px = p + 1,
+ py = p + volDim[0],
+ pxy = py + 1,
+ pz = p + volDim[0] * volDim[1],
+ pxz = px + volDim[0] * volDim[1],
+ pyz = py + volDim[0] * volDim[1],
+ pxyz = pxy + volDim[0] * volDim[1];
+
+ // X, Y, Z position
+ //float position[] = new float[]{xx, yy, zz};
+
+ // Voxel intensities
+ float value0 = values.getFloat(p),
+ value1 = values.getFloat(px),
+ value2 = values.getFloat(py),
+ value3 = values.getFloat(pxy),
+ value4 = values.getFloat(pz),
+ value5 = values.getFloat(pxz),
+ value6 = values.getFloat(pyz),
+ value7 = values.getFloat(pxyz);
+
+ // Voxel is active if its intensity is above isolevel
+ int cubeindex = 0;
+ if (value0 > isoLevel) cubeindex |= 1;
+ if (value1 > isoLevel) cubeindex |= 2;
+ if (value2 > isoLevel) cubeindex |= 8;
+ if (value3 > isoLevel) cubeindex |= 4;
+ if (value4 > isoLevel) cubeindex |= 16;
+ if (value5 > isoLevel) cubeindex |= 32;
+ if (value6 > isoLevel) cubeindex |= 128;
+ if (value7 > isoLevel) cubeindex |= 64;
+
+ // Fetch the triggered edges
+ int bits = TablesMC.MC_EDGE_TABLE[cubeindex];
+
+ // If no edge is triggered... skip
+ if (bits == 0) continue;
+
+ // Interpolate the positions based od voxel intensities
+ float mu = 0.5f;
+
+ // bottom of the cube
+ if ((bits & 1) != 0) {
+ mu = (float) ((isoLevel - value0) / (value1 - value0));
+ vertList[0] = lerp(new float[]{xx, yy, zz}, new float[]{xc.getFloat(x + 1), yy, zz}, mu);
+ }
+ if ((bits & 2) != 0) {
+ mu = (float) ((isoLevel - value1) / (value3 - value1));
+ vertList[1] = lerp(new float[]{xc.getFloat(x + 1), yy, zz}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zz}, mu);
+ }
+ if ((bits & 4) != 0) {
+ mu = (float) ((isoLevel - value2) / (value3 - value2));
+ vertList[2] = lerp(new float[]{xx, yc.getFloat(y + 1), zz}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zz}, mu);
+ }
+ if ((bits & 8) != 0) {
+ mu = (float) ((isoLevel - value0) / (value2 - value0));
+ vertList[3] = lerp(new float[]{xx, yy, zz}, new float[]{xx, yc.getFloat(y + 1), zz}, mu);
+ }
+ // top of the cube
+ if ((bits & 16) != 0) {
+ mu = (float) ((isoLevel - value4) / (value5 - value4));
+ vertList[4] = lerp(new float[]{xx, yy, zc.getFloat(z + 1)}, new float[]{xc.getFloat(x + 1), yy, zc.getFloat(z + 1)}, mu);
+ }
+ if ((bits & 32) != 0) {
+ mu = (float) ((isoLevel - value5) / (value7 - value5));
+ vertList[5] = lerp(new float[]{xc.getFloat(x + 1), yy, zc.getFloat(z + 1)}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
+ }
+ if ((bits & 64) != 0) {
+ mu = (float) ((isoLevel - value6) / (value7 - value6));
+ vertList[6] = lerp(new float[]{xx, yc.getFloat(y + 1), zc.getFloat(z + 1)}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
+ }
+ if ((bits & 128) != 0) {
+ mu = (float) ((isoLevel - value4) / (value6 - value4));
+ vertList[7] = lerp(new float[]{xx, yy, zc.getFloat(z + 1)}, new float[]{xx, yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
+ }
+ // vertical lines of the cube
+ if ((bits & 256) != 0) {
+ mu = (float) ((isoLevel - value0) / (value4 - value0));
+ vertList[8] = lerp(new float[]{xx, yy, zz}, new float[]{xx, yy, zc.getFloat(z + 1)}, mu);
+ }
+ if ((bits & 512) != 0) {
+ mu = (float) ((isoLevel - value1) / (value5 - value1));
+ vertList[9] = lerp(new float[]{xc.getFloat(x + 1), yy, zz}, new float[]{xc.getFloat(x + 1), yy, zc.getFloat(z + 1)}, mu);
+ }
+ if ((bits & 1024) != 0) {
+ mu = (float) ((isoLevel - value3) / (value7 - value3));
+ vertList[10] = lerp(new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zz}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
+ }
+ if ((bits & 2048) != 0) {
+ mu = (float) ((isoLevel - value2) / (value6 - value2));
+ vertList[11] = lerp(new float[]{xx, yc.getFloat(y + 1), zz}, new float[]{xx, yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
+ }
+
+ // construct triangles -- get correct vertices from triTable.
+ int i = 0;
+ // "Re-purpose cubeindex into an offset into triTable."
+ cubeindex <<= 4;
+
+ while (TablesMC.MC_TRI_TABLE[cubeindex + i] != -1) {
+ int index1 = TablesMC.MC_TRI_TABLE[cubeindex + i];
+ int index2 = TablesMC.MC_TRI_TABLE[cubeindex + i + 1];
+ int index3 = TablesMC.MC_TRI_TABLE[cubeindex + i + 2];
+
+ // Add triangles vertices
+ vertices.add(new float[] {vertList[index3][0], vertList[index3][1], vertList[index3][2]});
+ vertices.add(new float[] {vertList[index2][0], vertList[index2][1], vertList[index2][2]});
+ vertices.add(new float[] {vertList[index1][0], vertList[index1][1], vertList[index1][2]});
+
+ i += 3;
+ }
+ }
+ }
+ }
+
+ return vertices;
+ }
+
+ public static void marchingCubes(Array values, Array xc, Array yc, Array zc, float isoLevel,
+ int len, int offset, CallbackMC callback) {
+
+ ArrayList vertices = new ArrayList<>();
+ // Actual position along edge weighted according to function values.
+ float vertList[][] = new float[12][3];
+
+ int[] shape = values.getShape();
+ int[] volDim = new int[]{shape[2], shape[1], len};
+
+ // Volume iteration
+ float xx, yy, zz;
+ for (int z = offset; z < volDim[2] - 1 + offset; z++) {
+ zz = zc.getFloat(z);
+ for (int y = 0; y < volDim[1] - 1; y++) {
+ yy = yc.getFloat(y);
+ for (int x = 0; x < volDim[0] - 1; x++) {
+ xx = xc.getFloat(x);
+ // Indices pointing to cube vertices
+ // pyz ___________________ pxyz
+ // /| /|
+ // / | / |
+ // / | / |
+ // pz /___|______________/pxz|
+ // | | | |
+ // | | | |
+ // | py |______________|___| pxy
+ // | / | /
+ // | / | /
+ // | / | /
+ // |/__________________|/
+ // p px
+
+ int p = x + (volDim[0] * y) + (volDim[0] * volDim[1] * z),
+ px = p + 1,
+ py = p + volDim[0],
+ pxy = py + 1,
+ pz = p + volDim[0] * volDim[1],
+ pxz = px + volDim[0] * volDim[1],
+ pyz = py + volDim[0] * volDim[1],
+ pxyz = pxy + volDim[0] * volDim[1];
+
+ // X, Y, Z position
+ //float position[] = new float[]{xx, yy, zz};
+
+ // Voxel intensities
+ float value0 = values.getFloat(p),
+ value1 = values.getFloat(px),
+ value2 = values.getFloat(py),
+ value3 = values.getFloat(pxy),
+ value4 = values.getFloat(pz),
+ value5 = values.getFloat(pxz),
+ value6 = values.getFloat(pyz),
+ value7 = values.getFloat(pxyz);
+
+ // Voxel is active if its intensity is above isolevel
+ int cubeindex = 0;
+ if (value0 > isoLevel) cubeindex |= 1;
+ if (value1 > isoLevel) cubeindex |= 2;
+ if (value2 > isoLevel) cubeindex |= 8;
+ if (value3 > isoLevel) cubeindex |= 4;
+ if (value4 > isoLevel) cubeindex |= 16;
+ if (value5 > isoLevel) cubeindex |= 32;
+ if (value6 > isoLevel) cubeindex |= 128;
+ if (value7 > isoLevel) cubeindex |= 64;
+
+ // Fetch the triggered edges
+ int bits = TablesMC.MC_EDGE_TABLE[cubeindex];
+
+ // If no edge is triggered... skip
+ if (bits == 0) continue;
+
+ // Interpolate the positions based od voxel intensities
+ float mu = 0.5f;
+
+ // bottom of the cube
+ if ((bits & 1) != 0) {
+ mu = (float) ((isoLevel - value0) / (value1 - value0));
+ vertList[0] = lerp(new float[]{xx, yy, zz}, new float[]{xc.getFloat(x + 1), yy, zz}, mu);
+ }
+ if ((bits & 2) != 0) {
+ mu = (float) ((isoLevel - value1) / (value3 - value1));
+ vertList[1] = lerp(new float[]{xc.getFloat(x + 1), yy, zz}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zz}, mu);
+ }
+ if ((bits & 4) != 0) {
+ mu = (float) ((isoLevel - value2) / (value3 - value2));
+ vertList[2] = lerp(new float[]{xx, yc.getFloat(y + 1), zz}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zz}, mu);
+ }
+ if ((bits & 8) != 0) {
+ mu = (float) ((isoLevel - value0) / (value2 - value0));
+ vertList[3] = lerp(new float[]{xx, yy, zz}, new float[]{xx, yc.getFloat(y + 1), zz}, mu);
+ }
+ // top of the cube
+ if ((bits & 16) != 0) {
+ mu = (float) ((isoLevel - value4) / (value5 - value4));
+ vertList[4] = lerp(new float[]{xx, yy, zc.getFloat(z + 1)}, new float[]{xc.getFloat(x + 1), yy, zc.getFloat(z + 1)}, mu);
+ }
+ if ((bits & 32) != 0) {
+ mu = (float) ((isoLevel - value5) / (value7 - value5));
+ vertList[5] = lerp(new float[]{xc.getFloat(x + 1), yy, zc.getFloat(z + 1)}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
+ }
+ if ((bits & 64) != 0) {
+ mu = (float) ((isoLevel - value6) / (value7 - value6));
+ vertList[6] = lerp(new float[]{xx, yc.getFloat(y + 1), zc.getFloat(z + 1)}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
+ }
+ if ((bits & 128) != 0) {
+ mu = (float) ((isoLevel - value4) / (value6 - value4));
+ vertList[7] = lerp(new float[]{xx, yy, zc.getFloat(z + 1)}, new float[]{xx, yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
+ }
+ // vertical lines of the cube
+ if ((bits & 256) != 0) {
+ mu = (float) ((isoLevel - value0) / (value4 - value0));
+ vertList[8] = lerp(new float[]{xx, yy, zz}, new float[]{xx, yy, zc.getFloat(z + 1)}, mu);
+ }
+ if ((bits & 512) != 0) {
+ mu = (float) ((isoLevel - value1) / (value5 - value1));
+ vertList[9] = lerp(new float[]{xc.getFloat(x + 1), yy, zz}, new float[]{xc.getFloat(x + 1), yy, zc.getFloat(z + 1)}, mu);
+ }
+ if ((bits & 1024) != 0) {
+ mu = (float) ((isoLevel - value3) / (value7 - value3));
+ vertList[10] = lerp(new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zz}, new float[]{xc.getFloat(x + 1), yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
+ }
+ if ((bits & 2048) != 0) {
+ mu = (float) ((isoLevel - value2) / (value6 - value2));
+ vertList[11] = lerp(new float[]{xx, yc.getFloat(y + 1), zz}, new float[]{xx, yc.getFloat(y + 1), zc.getFloat(z + 1)}, mu);
+ }
+
+ // construct triangles -- get correct vertices from triTable.
+ int i = 0;
+ // "Re-purpose cubeindex into an offset into triTable."
+ cubeindex <<= 4;
+
+ while (TablesMC.MC_TRI_TABLE[cubeindex + i] != -1) {
+ int index1 = TablesMC.MC_TRI_TABLE[cubeindex + i];
+ int index2 = TablesMC.MC_TRI_TABLE[cubeindex + i + 1];
+ int index3 = TablesMC.MC_TRI_TABLE[cubeindex + i + 2];
+
+ // Add triangles vertices
+ vertices.add(new float[] {vertList[index3][0], vertList[index3][1], vertList[index3][2]});
+ vertices.add(new float[] {vertList[index2][0], vertList[index2][1], vertList[index2][2]});
+ vertices.add(new float[] {vertList[index1][0], vertList[index1][1], vertList[index1][2]});
+
+ i += 3;
+ }
+ }
+ }
+ }
+
+ callback.setVertices(vertices);
+ callback.run();
+ }
+}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/TablesMC.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/TablesMC.java
similarity index 98%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/TablesMC.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/TablesMC.java
index f76425db..8c125fdd 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/TablesMC.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/TablesMC.java
@@ -1,303 +1,303 @@
-/*
- * 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.jogl.mc;
-
-/**
- * Created by Primoz on 7.7.2016.
- */
-public class TablesMC {
- static int[] MC_EDGE_TABLE = {
- 0x0, 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c,
- 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00,
- 0x190, 0x99, 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c,
- 0x99c, 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90,
- 0x230, 0x339, 0x33, 0x13a, 0x636, 0x73f, 0x435, 0x53c,
- 0xa3c, 0xb35, 0x83f, 0x936, 0xe3a, 0xf33, 0xc39, 0xd30,
- 0x3a0, 0x2a9, 0x1a3, 0xaa, 0x7a6, 0x6af, 0x5a5, 0x4ac,
- 0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa, 0xea3, 0xda9, 0xca0,
- 0x460, 0x569, 0x663, 0x76a, 0x66, 0x16f, 0x265, 0x36c,
- 0xc6c, 0xd65, 0xe6f, 0xf66, 0x86a, 0x963, 0xa69, 0xb60,
- 0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0xff, 0x3f5, 0x2fc,
- 0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0,
- 0x650, 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x55, 0x15c,
- 0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a, 0xb53, 0x859, 0x950,
- 0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0xcc,
- 0xfcc, 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0,
- 0x8c0, 0x9c9, 0xac3, 0xbca, 0xcc6, 0xdcf, 0xec5, 0xfcc,
- 0xcc, 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0,
- 0x950, 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c,
- 0x15c, 0x55, 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650,
- 0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, 0xfff, 0xcf5, 0xdfc,
- 0x2fc, 0x3f5, 0xff, 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0,
- 0xb60, 0xa69, 0x963, 0x86a, 0xf66, 0xe6f, 0xd65, 0xc6c,
- 0x36c, 0x265, 0x16f, 0x66, 0x76a, 0x663, 0x569, 0x460,
- 0xca0, 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, 0xaa5, 0xbac,
- 0x4ac, 0x5a5, 0x6af, 0x7a6, 0xaa, 0x1a3, 0x2a9, 0x3a0,
- 0xd30, 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c,
- 0x53c, 0x435, 0x73f, 0x636, 0x13a, 0x33, 0x339, 0x230,
- 0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, 0x99c,
- 0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x99, 0x190,
- 0xf00, 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c,
- 0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x0 };
-
- static int[] MC_TRI_TABLE = {
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1,
- 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1,
- 3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1,
- 3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1,
- 9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1,
- 1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1,
- 9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1,
- 2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1, -1,
- 8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1,
- 9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1,
- 4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1, -1,
- 3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1,
- 1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1, -1,
- 4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1, -1,
- 4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1,
- 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1,
- 1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1,
- 5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1,
- 2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1, -1,
- 9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1,
- 0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1,
- 2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1, -1,
- 10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1,
- 4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1, -1,
- 5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1, -1,
- 5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1,
- 9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1,
- 0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1,
- 1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1,
- 10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1, -1,
- 8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1, -1,
- 2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1,
- 7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1,
- 9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1, -1,
- 2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1, -1,
- 11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1,
- 9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1, -1,
- 5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1,
- 11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1,
- 11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1,
- 1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1,
- 9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1,
- 5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1, -1,
- 2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1,
- 0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1,
- 5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1, -1,
- 6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1,
- 0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1, -1,
- 3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1, -1,
- 6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1,
- 5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1,
- 1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1,
- 10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1, -1,
- 6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1,
- 1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1, -1,
- 8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1, -1,
- 7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1,
- 3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1,
- 5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1, -1,
- 0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1,
- 9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1,
- 8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1, -1,
- 5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1,
- 0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1,
- 6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1, -1,
- 10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1,
- 10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1,
- 8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1, -1,
- 1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1,
- 3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1, -1,
- 0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1,
- 10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1,
- 0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1, -1,
- 3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1, -1,
- 6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1,
- 9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1, -1,
- 8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1,
- 3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1,
- 6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1,
- 0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1, -1,
- 10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1, -1,
- 10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1,
- 1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1, -1,
- 2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1,
- 7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1,
- 7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1, -1,
- 2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1,
- 1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1,
- 11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1, -1,
- 8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1,
- 0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1, -1,
- 7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1,
- 10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1,
- 2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1,
- 6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1, -1,
- 7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1,
- 2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1,
- 1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1, -1,
- 10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1,
- 10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1, -1,
- 0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1, -1,
- 7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1,
- 6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1,
- 8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1,
- 9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1, -1,
- 6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1,
- 1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1, -1,
- 4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1, -1,
- 10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1,
- 8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1,
- 0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1, -1,
- 1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1,
- 8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1, -1,
- 10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1,
- 4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1,
- 10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1,
- 5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1,
- 11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1, -1,
- 9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1,
- 6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1, -1,
- 7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1, -1,
- 3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1,
- 7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1,
- 9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1, -1,
- 3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1, -1,
- 6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1,
- 9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1, -1,
- 1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1,
- 4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1,
- 7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1, -1,
- 6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1,
- 3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1, -1,
- 0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1, -1,
- 6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1,
- 1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1, -1,
- 0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1,
- 11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1,
- 6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1, -1,
- 5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1, -1,
- 9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1,
- 1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1,
- 1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1,
- 10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1, -1,
- 0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1,
- 5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1,
- 10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1, -1,
- 11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1,
- 0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1, -1,
- 9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1, -1,
- 7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1,
- 2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1,
- 8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1, -1,
- 9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1, -1,
- 9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1,
- 1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1,
- 9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1,
- 9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1,
- 5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1, -1,
- 0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1, -1,
- 10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1,
- 2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1, -1,
- 0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1,
- 0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1,
- 9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1, -1,
- 5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1,
- 3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1,
- 5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1, -1,
- 8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1,
- 0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1, -1,
- 9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1,
- 0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1, -1,
- 1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1, -1,
- 3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1,
- 4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1, -1,
- 9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1,
- 11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1,
- 11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1, -1,
- 2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1, -1,
- 9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1,
- 3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1,
- 1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1,
- 4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1, -1,
- 4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1,
- 0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1,
- 3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1,
- 3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1, -1,
- 0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1,
- 9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1, -1,
- 1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
-}
+/*
+ * 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.jogl.mc;
+
+/**
+ * Created by Primoz on 7.7.2016.
+ */
+public class TablesMC {
+ static int[] MC_EDGE_TABLE = {
+ 0x0, 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c,
+ 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00,
+ 0x190, 0x99, 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c,
+ 0x99c, 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90,
+ 0x230, 0x339, 0x33, 0x13a, 0x636, 0x73f, 0x435, 0x53c,
+ 0xa3c, 0xb35, 0x83f, 0x936, 0xe3a, 0xf33, 0xc39, 0xd30,
+ 0x3a0, 0x2a9, 0x1a3, 0xaa, 0x7a6, 0x6af, 0x5a5, 0x4ac,
+ 0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa, 0xea3, 0xda9, 0xca0,
+ 0x460, 0x569, 0x663, 0x76a, 0x66, 0x16f, 0x265, 0x36c,
+ 0xc6c, 0xd65, 0xe6f, 0xf66, 0x86a, 0x963, 0xa69, 0xb60,
+ 0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0xff, 0x3f5, 0x2fc,
+ 0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0,
+ 0x650, 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x55, 0x15c,
+ 0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a, 0xb53, 0x859, 0x950,
+ 0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0xcc,
+ 0xfcc, 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0,
+ 0x8c0, 0x9c9, 0xac3, 0xbca, 0xcc6, 0xdcf, 0xec5, 0xfcc,
+ 0xcc, 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0,
+ 0x950, 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c,
+ 0x15c, 0x55, 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650,
+ 0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, 0xfff, 0xcf5, 0xdfc,
+ 0x2fc, 0x3f5, 0xff, 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0,
+ 0xb60, 0xa69, 0x963, 0x86a, 0xf66, 0xe6f, 0xd65, 0xc6c,
+ 0x36c, 0x265, 0x16f, 0x66, 0x76a, 0x663, 0x569, 0x460,
+ 0xca0, 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, 0xaa5, 0xbac,
+ 0x4ac, 0x5a5, 0x6af, 0x7a6, 0xaa, 0x1a3, 0x2a9, 0x3a0,
+ 0xd30, 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c,
+ 0x53c, 0x435, 0x73f, 0x636, 0x13a, 0x33, 0x339, 0x230,
+ 0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, 0x99c,
+ 0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x99, 0x190,
+ 0xf00, 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c,
+ 0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x0 };
+
+ static int[] MC_TRI_TABLE = {
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1,
+ 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1,
+ 3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1,
+ 3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1,
+ 9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1,
+ 9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1,
+ 2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1, -1,
+ 8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1,
+ 9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1,
+ 4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1, -1,
+ 3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1,
+ 1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1, -1,
+ 4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1, -1,
+ 4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1,
+ 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1,
+ 1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1,
+ 5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1,
+ 2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1, -1,
+ 9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1,
+ 0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1,
+ 2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1, -1,
+ 10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1,
+ 4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1, -1,
+ 5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1, -1,
+ 5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1,
+ 9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1,
+ 0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1,
+ 1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1,
+ 10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1, -1,
+ 8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1, -1,
+ 2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1,
+ 7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1,
+ 9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1, -1,
+ 2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1, -1,
+ 11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1,
+ 9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1, -1,
+ 5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1,
+ 11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1,
+ 11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1,
+ 1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1,
+ 9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1,
+ 5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1, -1,
+ 2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1,
+ 0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1,
+ 5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1, -1,
+ 6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1,
+ 0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1, -1,
+ 3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1, -1,
+ 6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1,
+ 5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1,
+ 1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1,
+ 10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1, -1,
+ 6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1,
+ 1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1, -1,
+ 8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1, -1,
+ 7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1,
+ 3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1,
+ 5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1, -1,
+ 0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1,
+ 9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1,
+ 8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1, -1,
+ 5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1,
+ 0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1,
+ 6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1, -1,
+ 10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1,
+ 10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1,
+ 8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1, -1,
+ 1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1,
+ 3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1, -1,
+ 0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1,
+ 10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1,
+ 0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1, -1,
+ 3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1, -1,
+ 6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1,
+ 9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1, -1,
+ 8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1,
+ 3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1,
+ 6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1,
+ 0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1, -1,
+ 10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1, -1,
+ 10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1,
+ 1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1, -1,
+ 2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1,
+ 7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1,
+ 7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1, -1,
+ 2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1,
+ 1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1,
+ 11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1, -1,
+ 8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1,
+ 0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1, -1,
+ 7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1,
+ 10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1,
+ 2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1,
+ 6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1, -1,
+ 7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1,
+ 2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1,
+ 1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1, -1,
+ 10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1,
+ 10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1, -1,
+ 0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1, -1,
+ 7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1,
+ 6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1,
+ 8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1,
+ 9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1, -1,
+ 6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1, -1,
+ 4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1, -1,
+ 10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1,
+ 8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1,
+ 0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1, -1,
+ 1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1,
+ 8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1, -1,
+ 10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1,
+ 4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1,
+ 10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1,
+ 5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1,
+ 11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1, -1,
+ 9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1,
+ 6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1, -1,
+ 7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1, -1,
+ 3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1,
+ 7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1,
+ 9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1, -1,
+ 3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1, -1,
+ 6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1,
+ 9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1, -1,
+ 1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1,
+ 4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1,
+ 7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1, -1,
+ 6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1,
+ 3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1, -1,
+ 0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1, -1,
+ 6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1, -1,
+ 0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1,
+ 11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1,
+ 6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1, -1,
+ 5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1, -1,
+ 9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1,
+ 1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1,
+ 1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1,
+ 10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1, -1,
+ 0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1,
+ 5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1,
+ 10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1, -1,
+ 11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1, -1,
+ 9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1, -1,
+ 7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1,
+ 2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1,
+ 8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1, -1,
+ 9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1, -1,
+ 9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1,
+ 1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1,
+ 9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1,
+ 9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1,
+ 5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1, -1,
+ 0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1, -1,
+ 10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1,
+ 2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1, -1,
+ 0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1,
+ 0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1,
+ 9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1, -1,
+ 5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1,
+ 3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1,
+ 5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1, -1,
+ 8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1, -1,
+ 9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1,
+ 0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1, -1,
+ 1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1, -1,
+ 3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1,
+ 4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1, -1,
+ 9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1,
+ 11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1,
+ 11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1, -1,
+ 2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1, -1,
+ 9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1,
+ 3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1,
+ 1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1,
+ 4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1, -1,
+ 4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1,
+ 0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1,
+ 3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1,
+ 3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1, -1,
+ 0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1,
+ 9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1, -1,
+ 1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
+}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/VolumeGenerator.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/VolumeGenerator.java
similarity index 97%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/VolumeGenerator.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/VolumeGenerator.java
index b5b3bb6b..b2a89b49 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/mc/VolumeGenerator.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/mc/VolumeGenerator.java
@@ -1,116 +1,116 @@
-/*
- * 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.jogl.mc;
-
-/**
- * Created by Primoz on 11. 07. 2016.
- */
-public class VolumeGenerator {
- public static char[] generateScalarFieldChar(int []size) {
- final char[] scalarField = new char[size[0] * size[1] * size[2]];
- float axisMin = -10;
- float axisMax = 10;
- float axisRange = axisMax - axisMin;
-
- for (int k = 0; k < size[0]; k++) {
- for (int j = 0; j < size[1]; j++) {
- for (int i = 0; i < size[2]; i++) {
- // actual values
- char x = (char) (axisMin + axisRange * i / (size[0] - 1));
- char y = (char) (axisMin + axisRange * j / (size[1] - 1));
- char z = (char) (axisMin + axisRange * k / (size[2] - 1));
- scalarField[k + size[1] * (j + size[2] * i)] = (char) (x * x + y * y - z * z - 25);
- }
- }
- }
-
- return scalarField;
- }
-
- public static short[] generateScalarFieldShort(int []size) {
- final short[] scalarField = new short[size[0] * size[1] * size[2]];
- float axisMin = -10;
- float axisMax = 10;
- float axisRange = axisMax - axisMin;
-
- for (int k = 0; k < size[0]; k++) {
- for (int j = 0; j < size[1]; j++) {
- for (int i = 0; i < size[2]; i++) {
- // actual values
- short x = (short) (axisMin + axisRange * i / (size[0] - 1));
- short y = (short) (axisMin + axisRange * j / (size[1] - 1));
- short z = (short) (axisMin + axisRange * k / (size[2] - 1));
- scalarField[k + size[1] * (j + size[2] * i)] = (short) (x * x + y * y - z * z - 25);
- }
- }
- }
-
- return scalarField;
- }
-
- public static int[] generateScalarFieldInt(int []size) {
- final int[] scalarField = new int[size[0] * size[1] * size[2]];
- float axisMin = -10;
- float axisMax = 10;
- float axisRange = axisMax - axisMin;
-
- for (int k = 0; k < size[0]; k++) {
- for (int j = 0; j < size[1]; j++) {
- for (int i = 0; i < size[2]; i++) {
- // actual values
- int x = (int) (axisMin + axisRange * i / (size[0] - 1));
- int y = (int) (axisMin + axisRange * j / (size[1] - 1));
- int z = (int) (axisMin + axisRange * k / (size[2] - 1));
- scalarField[k + size[1] * (j + size[2] * i)] = (int) (x * x + y * y - z * z - 25);
- }
- }
- }
-
- return scalarField;
- }
-
- public static float[] generateScalarFieldFloat(int []size) {
- final float[] scalarField = new float[size[0] * size[1] * size[2]];
- float axisMin = -10;
- float axisMax = 10;
- float axisRange = axisMax - axisMin;
-
- for (int k = 0; k < size[0]; k++) {
- for (int j = 0; j < size[1]; j++) {
- for (int i = 0; i < size[2]; i++) {
- // actual values
- float x = axisMin + axisRange * i / (size[0] - 1);
- float y = axisMin + axisRange * j / (size[1] - 1);
- float z = axisMin + axisRange * k / (size[2] - 1);
- scalarField[k + size[1] * (j + size[2] * i)] = x * x + y * y - z * z - 25;
- }
- }
- }
-
- return scalarField;
- }
-
- public static double[] generateScalarFieldDouble(int []size) {
- final double[] scalarField = new double[size[0] * size[1] * size[2]];
- double axisMin = -10;
- double axisMax = 10;
- double axisRange = axisMax - axisMin;
-
- for (int k = 0; k < size[0]; k++) {
- for (int j = 0; j < size[1]; j++) {
- for (int i = 0; i < size[2]; i++) {
- // actual values
- double x = axisMin + axisRange * i / (size[0] - 1);
- double y = axisMin + axisRange * j / (size[1] - 1);
- double z = axisMin + axisRange * k / (size[2] - 1);
- scalarField[k + size[1] * (j + size[2] * i)] = (x * x + y * y - z * z - 25);
- }
- }
- }
-
- return scalarField;
- }
-}
+/*
+ * 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.jogl.mc;
+
+/**
+ * Created by Primoz on 11. 07. 2016.
+ */
+public class VolumeGenerator {
+ public static char[] generateScalarFieldChar(int []size) {
+ final char[] scalarField = new char[size[0] * size[1] * size[2]];
+ float axisMin = -10;
+ float axisMax = 10;
+ float axisRange = axisMax - axisMin;
+
+ for (int k = 0; k < size[0]; k++) {
+ for (int j = 0; j < size[1]; j++) {
+ for (int i = 0; i < size[2]; i++) {
+ // actual values
+ char x = (char) (axisMin + axisRange * i / (size[0] - 1));
+ char y = (char) (axisMin + axisRange * j / (size[1] - 1));
+ char z = (char) (axisMin + axisRange * k / (size[2] - 1));
+ scalarField[k + size[1] * (j + size[2] * i)] = (char) (x * x + y * y - z * z - 25);
+ }
+ }
+ }
+
+ return scalarField;
+ }
+
+ public static short[] generateScalarFieldShort(int []size) {
+ final short[] scalarField = new short[size[0] * size[1] * size[2]];
+ float axisMin = -10;
+ float axisMax = 10;
+ float axisRange = axisMax - axisMin;
+
+ for (int k = 0; k < size[0]; k++) {
+ for (int j = 0; j < size[1]; j++) {
+ for (int i = 0; i < size[2]; i++) {
+ // actual values
+ short x = (short) (axisMin + axisRange * i / (size[0] - 1));
+ short y = (short) (axisMin + axisRange * j / (size[1] - 1));
+ short z = (short) (axisMin + axisRange * k / (size[2] - 1));
+ scalarField[k + size[1] * (j + size[2] * i)] = (short) (x * x + y * y - z * z - 25);
+ }
+ }
+ }
+
+ return scalarField;
+ }
+
+ public static int[] generateScalarFieldInt(int []size) {
+ final int[] scalarField = new int[size[0] * size[1] * size[2]];
+ float axisMin = -10;
+ float axisMax = 10;
+ float axisRange = axisMax - axisMin;
+
+ for (int k = 0; k < size[0]; k++) {
+ for (int j = 0; j < size[1]; j++) {
+ for (int i = 0; i < size[2]; i++) {
+ // actual values
+ int x = (int) (axisMin + axisRange * i / (size[0] - 1));
+ int y = (int) (axisMin + axisRange * j / (size[1] - 1));
+ int z = (int) (axisMin + axisRange * k / (size[2] - 1));
+ scalarField[k + size[1] * (j + size[2] * i)] = (int) (x * x + y * y - z * z - 25);
+ }
+ }
+ }
+
+ return scalarField;
+ }
+
+ public static float[] generateScalarFieldFloat(int []size) {
+ final float[] scalarField = new float[size[0] * size[1] * size[2]];
+ float axisMin = -10;
+ float axisMax = 10;
+ float axisRange = axisMax - axisMin;
+
+ for (int k = 0; k < size[0]; k++) {
+ for (int j = 0; j < size[1]; j++) {
+ for (int i = 0; i < size[2]; i++) {
+ // actual values
+ float x = axisMin + axisRange * i / (size[0] - 1);
+ float y = axisMin + axisRange * j / (size[1] - 1);
+ float z = axisMin + axisRange * k / (size[2] - 1);
+ scalarField[k + size[1] * (j + size[2] * i)] = x * x + y * y - z * z - 25;
+ }
+ }
+ }
+
+ return scalarField;
+ }
+
+ public static double[] generateScalarFieldDouble(int []size) {
+ final double[] scalarField = new double[size[0] * size[1] * size[2]];
+ double axisMin = -10;
+ double axisMax = 10;
+ double axisRange = axisMax - axisMin;
+
+ for (int k = 0; k < size[0]; k++) {
+ for (int j = 0; j < size[1]; j++) {
+ for (int i = 0; i < size[2]; i++) {
+ // actual values
+ double x = axisMin + axisRange * i / (size[0] - 1);
+ double y = axisMin + axisRange * j / (size[1] - 1);
+ double z = axisMin + axisRange * k / (size[2] - 1);
+ scalarField[k + size[1] * (j + size[2] * i)] = (x * x + y * y - z * z - 25);
+ }
+ }
+ }
+
+ return scalarField;
+ }
+}
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/tessellator/Primitive.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/tessellator/Primitive.java
similarity index 100%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/tessellator/Primitive.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/tessellator/Primitive.java
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/tessellator/PrimitiveTessellator.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/tessellator/PrimitiveTessellator.java
similarity index 99%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/tessellator/PrimitiveTessellator.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/tessellator/PrimitiveTessellator.java
index 3d161ada..e73c39c8 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/tessellator/PrimitiveTessellator.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/tessellator/PrimitiveTessellator.java
@@ -1,6 +1,5 @@
package org.meteoinfo.chart.jogl.tessellator;
-import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.glu.GLUtessellator;
import com.jogamp.opengl.glu.GLUtessellatorCallbackAdapter;
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/tessellator/TessPolygon.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/tessellator/TessPolygon.java
similarity index 100%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/tessellator/TessPolygon.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/tessellator/TessPolygon.java
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/tessellator/TriangleTessellator.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/tessellator/TriangleTessellator.java
similarity index 99%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/tessellator/TriangleTessellator.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/tessellator/TriangleTessellator.java
index 7c82bbc7..4f3b9732 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/jogl/tessellator/TriangleTessellator.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/tessellator/TriangleTessellator.java
@@ -6,7 +6,6 @@ import com.jogamp.opengl.glu.GLUtessellator;
import com.jogamp.opengl.glu.GLUtessellatorCallbackAdapter;
import org.meteoinfo.chart.jogl.Triangle;
import org.meteoinfo.geometry.shape.PointZ;
-import org.meteoinfo.geometry.shape.Polygon;
import org.meteoinfo.geometry.shape.PolygonZ;
import java.util.ArrayList;
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 e96cded3..ca250acb 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
@@ -10,7 +10,7 @@ import org.meteoinfo.chart.axis.Axis;
import org.meteoinfo.chart.axis.LogAxis;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.PointF;
-import org.meteoinfo.chart.drawing.Draw;
+import org.meteoinfo.geo.drawing.Draw;
import java.awt.*;
import java.awt.geom.AffineTransform;
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/CategoryPlot.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/CategoryPlot.java
similarity index 94%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/CategoryPlot.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/CategoryPlot.java
index cdcae975..28ffb861 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/chart/plot/CategoryPlot.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/CategoryPlot.java
@@ -1,62 +1,63 @@
-/*
- * 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 java.awt.Graphics2D;
-import java.awt.geom.Rectangle2D;
-import org.meteoinfo.chart.Margin;
-import org.meteoinfo.data.CategoryDataset;
-import org.meteoinfo.data.Dataset;
-
-/**
- *
- * @author yaqiang
- */
-public class CategoryPlot extends Plot{
-
- CategoryDataset dataset;
-
- @Override
- public Dataset getDataset(){
- return dataset;
- }
-
- @Override
- public void setDataset(Dataset value){
- dataset = (CategoryDataset)value;
- }
-
- @Override
- public PlotType getPlotType() {
- return PlotType.CATEGORY;
- }
-
- @Override
- public void draw(Graphics2D g2, Rectangle2D area) {
-
- }
-
- @Override
- public Rectangle2D getPositionArea() {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
-
- @Override
- public Margin getTightInset(Graphics2D g, Rectangle2D positionArea) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
-
- @Override
- public Rectangle2D getPositionArea(Rectangle2D figureArea) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
-
- @Override
- public Rectangle2D getOuterPositionArea(Rectangle2D area) {
- return null;
- }
-
-}
+/*
+ * 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.Margin;
+import org.meteoinfo.data.CategoryDataset;
+import org.meteoinfo.data.Dataset;
+
+import java.awt.*;
+import java.awt.geom.Rectangle2D;
+
+/**
+ *
+ * @author yaqiang
+ */
+public class CategoryPlot extends Plot{
+
+ CategoryDataset dataset;
+
+ @Override
+ public Dataset getDataset(){
+ return dataset;
+ }
+
+ @Override
+ public void setDataset(Dataset value){
+ dataset = (CategoryDataset)value;
+ }
+
+ @Override
+ public PlotType getPlotType() {
+ return PlotType.CATEGORY;
+ }
+
+ @Override
+ public void draw(Graphics2D g2, Rectangle2D area) {
+
+ }
+
+ @Override
+ public Rectangle2D getPositionArea() {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public Margin getTightInset(Graphics2D g, Rectangle2D positionArea) {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public Rectangle2D getPositionArea(Rectangle2D figureArea) {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public Rectangle2D getOuterPositionArea(Rectangle2D area) {
+ return null;
+ }
+
+}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/GraphicFactory.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/GraphicFactory.java
index 65f4f628..546277c9 100644
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/GraphicFactory.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/GraphicFactory.java
@@ -8,25 +8,28 @@ package org.meteoinfo.chart.plot;
import org.apache.commons.lang3.ArrayUtils;
import org.meteoinfo.chart.ChartText;
import org.meteoinfo.chart.plot3d.GraphicCollection3D;
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.common.Extent3D;
-import org.meteoinfo.common.MIMath;
-import org.meteoinfo.common.PointD;
+import org.meteoinfo.common.*;
import org.meteoinfo.data.GridArray;
import org.meteoinfo.data.GridData;
import org.meteoinfo.data.XYListDataset;
import org.meteoinfo.data.analysis.Statistics;
-import org.meteoinfo.drawing.ContourDraw;
-import org.meteoinfo.drawing.Draw;
-import org.meteoinfo.geoprocess.GeoComputation;
-import org.meteoinfo.geoprocess.GeometryUtil;
-import org.meteoinfo.layer.ImageLayer;
-import org.meteoinfo.layer.VectorLayer;
-import org.meteoinfo.legend.*;
-import org.meteoinfo.math.ArrayMath;
-import org.meteoinfo.math.ArrayUtil;
+import org.meteoinfo.geo.drawing.ContourDraw;
+import org.meteoinfo.geo.drawing.Draw;
+import org.meteoinfo.geo.layer.ImageLayer;
+import org.meteoinfo.geo.layer.VectorLayer;
+import org.meteoinfo.geo.legend.LegendManage;
+import org.meteoinfo.geometry.graphic.Graphic;
+import org.meteoinfo.geometry.graphic.GraphicCollection;
+import org.meteoinfo.geometry.graphic.ImageGraphic;
+import org.meteoinfo.geometry.legend.*;
+import org.meteoinfo.geometry.shape.Shape;
+import org.meteoinfo.geometry.shape.*;
+import org.meteoinfo.geometry.geoprocess.GeoComputation;
+import org.meteoinfo.geometry.geoprocess.GeometryUtil;
import org.meteoinfo.math.meteo.MeteoMath;
-import org.meteoinfo.ndarray.InvalidRangeException;
+import org.meteoinfo.ndarray.*;
+import org.meteoinfo.ndarray.math.ArrayMath;
+import org.meteoinfo.ndarray.math.ArrayUtil;
import org.meteoinfo.ndarray.util.BigDecimalUtil;
import wcontour.Contour;
import wcontour.global.Point3D;
@@ -735,7 +738,7 @@ public class GraphicFactory {
* @return LineString graphics
*/
public static GraphicCollection createErrorLineString(Array xdata, Array ydata, Array xErrorLeft,
- Array xErrorRight, Array yErrorBottom, Array yErrorUp, PolylineBreak cb, PolylineBreak ecb, float capSize) {
+ Array xErrorRight, Array yErrorBottom, Array yErrorUp, PolylineBreak cb, PolylineBreak ecb, float capSize) {
GraphicCollection gc = new GraphicCollection();
PolylineShape pls;
CapPolylineShape epls;
@@ -2942,7 +2945,7 @@ public class GraphicFactory {
* @return Graphics
*/
public static GraphicCollection createImage(GridArray gdata, LegendScheme ls, double offset,
- String zdir, List sePoint, String interpolation) {
+ String zdir, List sePoint, String interpolation) {
Graphic gg = createImage(gdata, ls);
if (interpolation != null) {
((ImageShape) gg.getShape()).setInterpolation(interpolation);
@@ -3053,17 +3056,17 @@ public class GraphicFactory {
ArrayUtils.reverse(y);
Object[] cbs = ContourDraw.tracingContourLines(gridData.data,
cValues, x, y, gridData.missingValue, S1);
- List ContourLines = (List) cbs[0];
+ List ContourLines = (List) cbs[0];
if (ContourLines.isEmpty()) {
return null;
}
if (isSmooth) {
- ContourLines = wcontour.Contour.smoothLines(ContourLines);
+ ContourLines = Contour.smoothLines(ContourLines);
}
- wcontour.global.PolyLine aLine;
+ PolyLine aLine;
double v;
ColorBreak cbb = ls.findLegendBreak(0);
GraphicCollection graphics = new GraphicCollection();
@@ -3142,17 +3145,17 @@ public class GraphicFactory {
ArrayUtils.reverse(y);
Object[] cbs = ContourDraw.tracingContourLines(gridData.data,
cValues, x, y, gridData.missingValue, S1);
- List ContourLines = (List) cbs[0];
+ List ContourLines = (List) cbs[0];
if (ContourLines.isEmpty()) {
return null;
}
if (isSmooth) {
- ContourLines = wcontour.Contour.smoothLines(ContourLines);
+ ContourLines = Contour.smoothLines(ContourLines);
}
- wcontour.global.PolyLine aLine;
+ PolyLine aLine;
double v;
ColorBreak cbb;
GraphicCollection3D graphics = new GraphicCollection3D();
@@ -3234,17 +3237,17 @@ public class GraphicFactory {
ArrayUtils.reverse(yArray);
Object[] cbs = ContourDraw.tracingContourLines(gridData.data,
cValues, xArray, yArray, gridData.missingValue, S1);
- List ContourLines = (List) cbs[0];
+ List ContourLines = (List) cbs[0];
if (ContourLines.isEmpty()) {
return null;
}
if (isSmooth) {
- ContourLines = wcontour.Contour.smoothLines(ContourLines);
+ ContourLines = Contour.smoothLines(ContourLines);
}
- wcontour.global.PolyLine aLine;
+ PolyLine aLine;
double v;
ColorBreak cbb;
GraphicCollection3D graphics = new GraphicCollection3D();
@@ -3346,11 +3349,11 @@ public class GraphicFactory {
ArrayUtils.reverse(yArray);
Object[] cbs = ContourDraw.tracingContourLines(gridData.data,
cValues, xArray, yArray, gridData.missingValue, S1);
- List contourLines = (List) cbs[0];
+ List contourLines = (List) cbs[0];
List borders = (List) cbs[1];
if (isSmooth) {
- contourLines = wcontour.Contour.smoothLines(contourLines);
+ contourLines = Contour.smoothLines(contourLines);
}
List contourPolygons = ContourDraw.tracingPolygons(gridData.data, contourLines, borders, cValues);
@@ -3482,11 +3485,11 @@ public class GraphicFactory {
ArrayUtils.reverse(yArray);
Object[] cbs = ContourDraw.tracingContourLines(gridData.data,
cValues, xArray, yArray, gridData.missingValue, S1);
- List contourLines = (List) cbs[0];
+ List contourLines = (List) cbs[0];
List borders = (List) cbs[1];
if (isSmooth) {
- contourLines = wcontour.Contour.smoothLines(contourLines);
+ contourLines = Contour.smoothLines(contourLines);
}
List contourPolygons = ContourDraw.tracingPolygons(gridData.data, contourLines, borders, cValues);
@@ -3644,11 +3647,11 @@ public class GraphicFactory {
ArrayUtils.reverse(yArray);
Object[] cbs = ContourDraw.tracingContourLines(gridData.data,
cValues, xArray, yArray, gridData.missingValue, S1);
- List contourLines = (List) cbs[0];
+ List contourLines = (List) cbs[0];
List borders = (List) cbs[1];
if (isSmooth) {
- contourLines = wcontour.Contour.smoothLines(contourLines);
+ contourLines = Contour.smoothLines(contourLines);
}
List contourPolygons = ContourDraw.tracingPolygons(gridData.data, contourLines, borders, cValues);
@@ -4970,9 +4973,9 @@ public class GraphicFactory {
double[][] v = (double[][])ArrayUtil.copyToNDJavaArray_Double(vdata);
double[] x = (double[]) ArrayUtil.copyToNDJavaArray_Double(xdata);
double[] y = (double[]) ArrayUtil.copyToNDJavaArray_Double(ydata);
- List streamlines = wcontour.Contour.tracingStreamline(u, v,
+ List streamlines = Contour.tracingStreamline(u, v,
x, y, density);
- wcontour.global.PolyLine line;
+ PolyLine line;
for (int i = 0; i < streamlines.size() - 1; i++) {
line = streamlines.get(i);
PolylineShape aPolyline = new PolylineShape();
@@ -5011,18 +5014,18 @@ public class GraphicFactory {
GraphicCollection3D graphics = new GraphicCollection3D();
double[][] u = (double[][]) ArrayUtil.copyToNDJavaArray_Double(ua);
double[][] v = (double[][]) ArrayUtil.copyToNDJavaArray_Double(va);
- List streamlines;
+ List streamlines;
if (xa.getRank() == 1) {
double[] x = (double[]) ArrayUtil.copyToNDJavaArray_Double(xa);
double[] y = (double[]) ArrayUtil.copyToNDJavaArray_Double(ya);
- streamlines = wcontour.Contour.tracingStreamline(u, v,
+ streamlines = Contour.tracingStreamline(u, v,
x, y, density);
} else {
xa = xa.copyIfView();
ya = ya.copyIfView();
double[][] x = (double[][]) ArrayUtil.copyToNDJavaArray_Double(xa);
double[][] y = (double[][]) ArrayUtil.copyToNDJavaArray_Double(ya);
- streamlines = wcontour.Contour.tracingStreamline(u, v,
+ streamlines = Contour.tracingStreamline(u, v,
x, y, density);
}
@@ -5030,7 +5033,7 @@ public class GraphicFactory {
int nx = u[0].length;
ColorBreak cb = ls.getLegendBreak(0);
if (data == null) {
- for (wcontour.global.PolyLine line : streamlines) {
+ for (PolyLine line : streamlines) {
PolylineZShape shape = new PolylineZShape();
List points = new ArrayList<>();
PointZ p;
@@ -5063,7 +5066,7 @@ public class GraphicFactory {
graphics.add(new Graphic(shape, cb));
}
} else {
- for (wcontour.global.PolyLine line : streamlines) {
+ for (PolyLine line : streamlines) {
PolylineZShape shape = new PolylineZShape();
List points = new ArrayList<>();
PointZ p;
@@ -5144,18 +5147,18 @@ public class GraphicFactory {
GraphicCollection3D graphics = new GraphicCollection3D();
double[][] u = (double[][]) ArrayUtil.copyToNDJavaArray_Double(ua);
double[][] v = (double[][]) ArrayUtil.copyToNDJavaArray_Double(va);
- List streamlines;
+ List streamlines;
if (xa.getRank() == 1) {
double[] x = (double[]) ArrayUtil.copyToNDJavaArray_Double(xa);
double[] y = (double[]) ArrayUtil.copyToNDJavaArray_Double(ya);
- streamlines = wcontour.Contour.tracingStreamline(u, v,
+ streamlines = Contour.tracingStreamline(u, v,
x, y, density);
} else {
xa = xa.copyIfView();
ya = ya.copyIfView();
double[][] x = (double[][]) ArrayUtil.copyToNDJavaArray_Double(xa);
double[][] y = (double[][]) ArrayUtil.copyToNDJavaArray_Double(ya);
- streamlines = wcontour.Contour.tracingStreamline(u, v,
+ streamlines = Contour.tracingStreamline(u, v,
x, y, density);
}
@@ -5163,7 +5166,7 @@ public class GraphicFactory {
int nx = u[0].length;
ColorBreak cb = ls.getLegendBreak(0);
if (data == null) {
- for (wcontour.global.PolyLine line : streamlines) {
+ for (PolyLine line : streamlines) {
PolylineZShape shape = new PolylineZShape();
List points = new ArrayList<>();
PointZ p;
@@ -5183,7 +5186,7 @@ public class GraphicFactory {
graphics.add(new Graphic(shape, cb));
}
} else {
- for (wcontour.global.PolyLine line : streamlines) {
+ for (PolyLine line : streamlines) {
PolylineZShape shape = new PolylineZShape();
List points = new ArrayList<>();
PointZ p;
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 b99c1dae..fc1ab86e 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
@@ -5,7 +5,7 @@
*/
package org.meteoinfo.chart.plot;
-import org.meteoinfo.chart.legend.LineStyles;
+import org.meteoinfo.geometry.legend.LineStyles;
import java.awt.*;
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/MapPlot.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/MapPlot.java
index 37586011..f74137af 100644
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/MapPlot.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/MapPlot.java
@@ -7,23 +7,23 @@ package org.meteoinfo.chart.plot;
import org.meteoinfo.chart.*;
import org.meteoinfo.chart.axis.LonLatAxis;
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.common.MIMath;
-import org.meteoinfo.common.PointD;
-import org.meteoinfo.common.PointF;
+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.drawing.Draw;
-import org.meteoinfo.layer.LayerCollection;
-import org.meteoinfo.layer.MapLayer;
-import org.meteoinfo.legend.*;
-import org.meteoinfo.map.GridLabel;
-import org.meteoinfo.map.MapView;
+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.*;
+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.meteoinfo.projection.info.ProjectionInfo;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
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 12b4a3f9..3c421af6 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
@@ -6,13 +6,13 @@
package org.meteoinfo.chart.plot;
import org.meteoinfo.common.PointF;
-import org.meteoinfo.drawing.Draw;
-import org.meteoinfo.legend.ColorBreak;
-import org.meteoinfo.legend.PolygonBreak;
-import org.meteoinfo.shape.ArcShape;
-import org.meteoinfo.shape.Graphic;
-import org.meteoinfo.shape.GraphicCollection;
-import org.meteoinfo.shape.Shape;
+import org.meteoinfo.geo.drawing.Draw;
+import org.meteoinfo.geometry.graphic.Graphic;
+import org.meteoinfo.geometry.graphic.GraphicCollection;
+import org.meteoinfo.geometry.legend.ColorBreak;
+import org.meteoinfo.geometry.legend.PolygonBreak;
+import org.meteoinfo.geometry.shape.ArcShape;
+import org.meteoinfo.geometry.shape.Shape;
import java.awt.*;
import java.awt.geom.AffineTransform;
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/Plot.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/Plot.java
index 01c0c523..0480d1ae 100644
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/Plot.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/Plot.java
@@ -6,6 +6,7 @@
package org.meteoinfo.chart.plot;
import org.meteoinfo.chart.Margin;
+import org.meteoinfo.data.Dataset;
import java.awt.*;
import java.awt.geom.Ellipse2D;
@@ -261,7 +262,19 @@ public abstract class Plot {
public void setOuterPositionArea(Rectangle2D value){
this.outerPositionArea = value;
}
-
+
+ /**
+ * Get dataset
+ * @return Dataset
+ */
+ public abstract Dataset getDataset();
+
+ /**
+ * Set dataset
+ * @param dataset Dataset
+ */
+ public abstract void setDataset(Dataset dataset);
+
/**
* Get plot type
* @return Plot type
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 1a49c74b..df83075c 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
@@ -17,22 +17,21 @@ import org.meteoinfo.chart.ChartLegend;
import org.meteoinfo.chart.ChartText;
import org.meteoinfo.chart.axis.LogAxis;
import org.meteoinfo.chart.axis.TimeAxis;
-import org.meteoinfo.chart.graphic.Graphic;
-import org.meteoinfo.chart.graphic.GraphicCollection;
-import org.meteoinfo.chart.graphic.ImageGraphic;
-import org.meteoinfo.chart.graphic.PolylineErrorShape;
-import org.meteoinfo.chart.legend.*;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.PointD;
import org.meteoinfo.common.PointF;
-import org.meteoinfo.chart.drawing.Draw;
-import org.meteoinfo.geometry.geoprocess.GeometryUtil;
-import org.meteoinfo.geo.shape.*;
-import org.meteoinfo.geometry.shape.*;
+import org.meteoinfo.data.Dataset;
+import org.meteoinfo.geo.drawing.Draw;
+import org.meteoinfo.geometry.graphic.Graphic;
+import org.meteoinfo.geometry.graphic.GraphicCollection;
+import org.meteoinfo.geometry.graphic.ImageGraphic;
+import org.meteoinfo.geometry.legend.*;
import org.meteoinfo.geometry.shape.Polygon;
import org.meteoinfo.geometry.shape.Shape;
-import org.meteoinfo.legend.*;
+import org.meteoinfo.geometry.shape.*;
+import org.meteoinfo.geometry.geoprocess.GeometryUtil;
+import org.meteoinfo.chart.shape.PolylineErrorShape;
import java.awt.*;
import java.awt.geom.*;
@@ -40,7 +39,7 @@ import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
-import static org.meteoinfo.chart.drawing.Draw.getHatchImage;
+import static org.meteoinfo.geo.drawing.Draw.getHatchImage;
/**
*
@@ -1195,6 +1194,16 @@ public class Plot2D extends AbstractPlot2D {
}
}
+ @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 legend scheme
*
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/Plot3D.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/Plot3D.java
index d584c771..4410a742 100644
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/Plot3D.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/Plot3D.java
@@ -8,20 +8,17 @@ package org.meteoinfo.chart.plot;
import org.meteoinfo.chart.*;
import org.meteoinfo.chart.axis.Axis;
import org.meteoinfo.chart.axis.LogAxis;
-import org.meteoinfo.chart.graphic.Graphic;
-import org.meteoinfo.chart.graphic.GraphicCollection;
-import org.meteoinfo.chart.legend.*;
import org.meteoinfo.chart.plot3d.GraphicCollection3D;
import org.meteoinfo.chart.plot3d.Projector;
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.common.Extent3D;
-import org.meteoinfo.common.MIMath;
-import org.meteoinfo.common.PointF;
-//import org.meteoinfo.data.DataMath;
-import org.meteoinfo.chart.drawing.Draw;
-import org.meteoinfo.geo.shape.*;
-import org.meteoinfo.geometry.shape.*;
+import org.meteoinfo.common.*;
+import org.meteoinfo.data.DataMath;
+import org.meteoinfo.data.Dataset;
+import org.meteoinfo.geo.drawing.Draw;
+import org.meteoinfo.geometry.graphic.Graphic;
+import org.meteoinfo.geometry.graphic.GraphicCollection;
+import org.meteoinfo.geometry.legend.*;
import org.meteoinfo.geometry.shape.Shape;
+import org.meteoinfo.geometry.shape.*;
import org.meteoinfo.math.sort.QuickSort;
import java.awt.*;
@@ -652,6 +649,16 @@ public class Plot3D extends Plot {
return new Rectangle2D.Double(x, y, w, h);
}
+ @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.
+ }
+
@Override
public PlotType getPlotType() {
return PlotType.XYZ;
@@ -1931,9 +1938,9 @@ public class Plot3D extends Plot {
g.setColor(this.xAxis.getLineColor());
g.drawLine(x[0], y[0], projection.x, projection.y);
if (projection.x > x[0]) {
- value = MIMath.getDSFromUV(projection.x - x[0], projection.y - y[0]);
+ value = DataMath.getDSFromUV(projection.x - x[0], projection.y - y[0]);
} else {
- value = MIMath.getDSFromUV(x[0] - projection.x, y[0] - projection.y);
+ value = DataMath.getDSFromUV(x[0] - projection.x, y[0] - projection.y);
}
xangle = (float) value[0];
xlen = (float) value[1];
@@ -1946,9 +1953,9 @@ public class Plot3D extends Plot {
g.setColor(this.yAxis.getLineColor());
g.drawLine(x[0], y[0], projection.x, projection.y);
if (projection.x > x[0]) {
- value = MIMath.getDSFromUV(projection.x - x[0], projection.y - y[0]);
+ value = DataMath.getDSFromUV(projection.x - x[0], projection.y - y[0]);
} else {
- value = MIMath.getDSFromUV(x[0] - projection.x, y[0] - projection.y);
+ value = DataMath.getDSFromUV(x[0] - projection.x, y[0] - projection.y);
}
yangle = (float) value[0];
ylen = (float) value[1];
@@ -1994,11 +2001,11 @@ public class Plot3D extends Plot {
}
}
//projection = projector.project(vi, factor_y * 10.5f, -10);
- value = MIMath.getEndPoint(tickpos.x, tickpos.y, angle, this.xAxis.getTickLength());
+ value = DataMath.getEndPoint(tickpos.x, tickpos.y, angle, this.xAxis.getTickLength());
g.setColor(this.xAxis.getLineColor());
//g.drawLine(projection.x, projection.y, tickpos.x, tickpos.y);
g.drawLine(tickpos.x, tickpos.y, (int) value[0], (int) value[1]);
- value = MIMath.getEndPoint(tickpos.x, tickpos.y, angle, this.xAxis.getTickLength() + 5);
+ value = DataMath.getEndPoint(tickpos.x, tickpos.y, angle, this.xAxis.getTickLength() + 5);
tickpos = new Point((int) value[0], (int) value[1]);
if (x_left) {
//outString(g, tickpos.x, tickpos.y, s, XAlign.LEFT, YAlign.TOP);
@@ -2020,7 +2027,7 @@ public class Plot3D extends Plot {
tickpos = projector.project(0, factor_y * 10.f, -10);
Dimension dim = Draw.getStringDimension(label, g);
strWidth = (int) Math.abs((strWidth * Math.sin(Math.toRadians(angle))));
- value = MIMath.getEndPoint(tickpos.x, tickpos.y, angle, this.xAxis.getTickLength() + strWidth + dim.height + 5);
+ value = DataMath.getEndPoint(tickpos.x, tickpos.y, angle, this.xAxis.getTickLength() + strWidth + dim.height + 5);
tickpos.x = (int) value[0];
tickpos.y = (int) value[1];
if (this.projector.getElevationAngle() < 10) {
@@ -2075,10 +2082,10 @@ public class Plot3D extends Plot {
g.drawLine(x[0], y[0], projection.x, projection.y);
}
}
- value = MIMath.getEndPoint(tickpos.x, tickpos.y, angle, this.xAxis.getTickLength());
+ value = DataMath.getEndPoint(tickpos.x, tickpos.y, angle, this.xAxis.getTickLength());
g.setColor(this.yAxis.getLineColor());
g.drawLine(tickpos.x, tickpos.y, (int) value[0], (int) value[1]);
- value = MIMath.getEndPoint(tickpos.x, tickpos.y, angle, this.xAxis.getTickLength() + 5);
+ value = DataMath.getEndPoint(tickpos.x, tickpos.y, angle, this.xAxis.getTickLength() + 5);
tickpos = new Point((int) value[0], (int) value[1]);
if (y_left) {
//outString(g, tickpos.x, tickpos.y, s, XAlign.LEFT, YAlign.TOP);
@@ -2100,7 +2107,7 @@ public class Plot3D extends Plot {
tickpos = projector.project(factor_x * 10.f, 0, -10);
Dimension dim = Draw.getStringDimension(label, g);
strWidth = (int) Math.abs((strWidth * Math.sin(Math.toRadians(angle))));
- value = MIMath.getEndPoint(tickpos.x, tickpos.y, angle, this.yAxis.getTickLength() + strWidth + dim.height + 5);
+ value = DataMath.getEndPoint(tickpos.x, tickpos.y, angle, this.yAxis.getTickLength() + strWidth + dim.height + 5);
tickpos.x = (int) value[0];
tickpos.y = (int) value[1];
if (this.projector.getElevationAngle() < 10) {
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 8320257f..4f84630e 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
@@ -6,14 +6,12 @@
package org.meteoinfo.chart.plot;
import org.meteoinfo.chart.Margin;
-import org.meteoinfo.common.Extent;
-import org.meteoinfo.common.MIMath;
-import org.meteoinfo.drawing.Draw;
-import org.meteoinfo.global.DataConvert;
-import org.meteoinfo.legend.LineStyles;
+import org.meteoinfo.common.*;
+import org.meteoinfo.geo.drawing.Draw;
+import org.meteoinfo.geometry.graphic.Graphic;
+import org.meteoinfo.geometry.graphic.GraphicCollection;
+import org.meteoinfo.geometry.legend.LineStyles;
import org.meteoinfo.ndarray.util.BigDecimalUtil;
-import org.meteoinfo.shape.Graphic;
-import org.meteoinfo.shape.GraphicCollection;
import java.awt.*;
import java.awt.geom.Ellipse2D;
@@ -22,7 +20,7 @@ import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
-import static org.meteoinfo.drawing.Draw.getDashPattern;
+import static org.meteoinfo.geo.drawing.Draw.getDashPattern;
/**
*
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/SeriesLegend.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/SeriesLegend.java
index ad9fcb8c..c4b54c40 100644
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/SeriesLegend.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/SeriesLegend.java
@@ -5,10 +5,10 @@
*/
package org.meteoinfo.chart.plot;
-import org.meteoinfo.legend.ColorBreak;
-import org.meteoinfo.legend.PointBreak;
-import org.meteoinfo.legend.PolygonBreak;
-import org.meteoinfo.legend.PolylineBreak;
+import org.meteoinfo.geometry.legend.ColorBreak;
+import org.meteoinfo.geometry.legend.PointBreak;
+import org.meteoinfo.geometry.legend.PolygonBreak;
+import org.meteoinfo.geometry.legend.PolylineBreak;
import java.awt.*;
import java.util.ArrayList;
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/XAlign.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/XAlign.java
deleted file mode 100644
index 2051c40d..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/XAlign.java
+++ /dev/null
@@ -1,16 +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;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public enum XAlign {
- LEFT,
- CENTER,
- RIGHT
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/XY1DPlot.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/XY1DPlot.java
index 93e78982..f679e711 100644
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/XY1DPlot.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/XY1DPlot.java
@@ -13,9 +13,9 @@ import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.PointF;
import org.meteoinfo.common.colors.ColorUtil;
import org.meteoinfo.data.*;
-import org.meteoinfo.drawing.Draw;
-import org.meteoinfo.legend.*;
-import org.meteoinfo.shape.ShapeTypes;
+import org.meteoinfo.geo.drawing.Draw;
+import org.meteoinfo.geometry.legend.*;
+import org.meteoinfo.geometry.shape.ShapeTypes;
import java.awt.*;
import java.awt.geom.AffineTransform;
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/YAlign.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/YAlign.java
deleted file mode 100644
index e1a54afe..00000000
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot/YAlign.java
+++ /dev/null
@@ -1,16 +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;
-
-/**
- *
- * @author Yaqiang Wang
- */
-public enum YAlign {
- TOP,
- CENTER,
- BOTTOM
-}
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot3d/GraphicCollection3D.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot3d/GraphicCollection3D.java
index 92e8f32c..3b08cec7 100644
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot3d/GraphicCollection3D.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot3d/GraphicCollection3D.java
@@ -5,7 +5,7 @@
*/
package org.meteoinfo.chart.plot3d;
-import org.meteoinfo.chart.graphic.GraphicCollection;
+import org.meteoinfo.geometry.graphic.GraphicCollection;
import java.util.List;
diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot3d/Projector.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot3d/Projector.java
index 2fb6900f..2db40e75 100644
--- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot3d/Projector.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/plot3d/Projector.java
@@ -21,7 +21,7 @@
*----------------------------------------------------------------------------------------*/
package org.meteoinfo.chart.plot3d;
-import org.meteoinfo.common.MIMath;
+import org.meteoinfo.data.DataMath;
import java.awt.*;
import java.util.ArrayList;
@@ -425,7 +425,7 @@ public final class Projector {
Point p2 = project(x2, y2, z2);
float u = p2.x - p1.x;
float v = p2.y - p1.y;
- return MIMath.getDSFromUV(u, v);
+ return DataMath.getDSFromUV(u, v);
}
/**
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/shape/PolylineErrorShape.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/shape/PolylineErrorShape.java
similarity index 99%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/shape/PolylineErrorShape.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/shape/PolylineErrorShape.java
index b7ca812d..c930160c 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/shape/PolylineErrorShape.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/shape/PolylineErrorShape.java
@@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
-package org.meteoinfo.shape;
+package org.meteoinfo.chart.shape;
import org.meteoinfo.geometry.shape.PolylineShape;
import org.meteoinfo.geometry.shape.ShapeTypes;
diff --git a/MeteoInfoLib/src/main/java/org/meteoinfo/plot/PlotUtil.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/util/PlotUtil.java
similarity index 95%
rename from MeteoInfoLib/src/main/java/org/meteoinfo/plot/PlotUtil.java
rename to meteoinfo-chart/src/main/java/org/meteoinfo/chart/util/PlotUtil.java
index 995c58a7..fba71fa2 100644
--- a/MeteoInfoLib/src/main/java/org/meteoinfo/plot/PlotUtil.java
+++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/util/PlotUtil.java
@@ -3,11 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
-package org.meteoinfo.plot;
-
-import java.io.FileNotFoundException;
-import java.util.ArrayList;
-import java.util.List;
+package org.meteoinfo.chart.util;
import org.meteoinfo.chart.Chart;
import org.meteoinfo.chart.ChartPanel;
@@ -19,6 +15,10 @@ import org.meteoinfo.data.XYArrayDataset;
import org.meteoinfo.data.XYDataset;
import org.meteoinfo.geometry.legend.PointBreak;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.List;
+
/**
*
* @author yaqiang
@@ -83,8 +83,8 @@ public class PlotUtil {
* @param chart The chart
* @param width Width
* @param height Heigth
- * @throws java.io.FileNotFoundException
- * @throws java.lang.InterruptedException
+ * @throws FileNotFoundException
+ * @throws InterruptedException
*/
public static void exportToPicture(String fileName, Chart chart, int width, int height)
throws FileNotFoundException, InterruptedException {
diff --git a/MeteoInfoMap/src/main/resources/images/TSMI_AttriData.Image.png b/meteoinfo-chart/src/main/resources/images/AttributeTable.png
similarity index 100%
rename from MeteoInfoMap/src/main/resources/images/TSMI_AttriData.Image.png
rename to meteoinfo-chart/src/main/resources/images/AttributeTable.png
diff --git a/meteoinfo-chart/src/main/resources/images/Edit_tool.png b/meteoinfo-chart/src/main/resources/images/Edit_tool.png
new file mode 100644
index 00000000..534f615c
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/Edit_tool.png differ
diff --git a/MeteoInfoMap/src/main/resources/images/TSB_LabelSet.Image.png b/meteoinfo-chart/src/main/resources/images/Label.png
similarity index 100%
rename from MeteoInfoMap/src/main/resources/images/TSB_LabelSet.Image.png
rename to meteoinfo-chart/src/main/resources/images/Label.png
diff --git a/MeteoInfoMap/src/main/resources/images/Layers.png b/meteoinfo-chart/src/main/resources/images/Layers.png
similarity index 100%
rename from MeteoInfoMap/src/main/resources/images/Layers.png
rename to meteoinfo-chart/src/main/resources/images/Layers.png
diff --git a/MeteoInfoMap/src/main/resources/images/MeteoInfo_1_16x16x8.png b/meteoinfo-chart/src/main/resources/images/MeteoInfo.png
similarity index 100%
rename from MeteoInfoMap/src/main/resources/images/MeteoInfo_1_16x16x8.png
rename to meteoinfo-chart/src/main/resources/images/MeteoInfo.png
diff --git a/MeteoInfoLab/src/main/resources/images/Pan_Open_32x32x32.png b/meteoinfo-chart/src/main/resources/images/Pan_Open_32x32x32.png
similarity index 100%
rename from MeteoInfoLab/src/main/resources/images/Pan_Open_32x32x32.png
rename to meteoinfo-chart/src/main/resources/images/Pan_Open_32x32x32.png
diff --git a/meteoinfo-chart/src/main/resources/images/Properties.png b/meteoinfo-chart/src/main/resources/images/Properties.png
new file mode 100644
index 00000000..c629822f
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/Properties.png differ
diff --git a/meteoinfo-chart/src/main/resources/images/TSB_Add.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_Add.Image.png
new file mode 100644
index 00000000..d76f26b9
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/TSB_Add.Image.png differ
diff --git a/meteoinfo-chart/src/main/resources/images/TSB_Area.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_Area.Image.png
new file mode 100644
index 00000000..95892dc4
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/TSB_Area.Image.png differ
diff --git a/meteoinfo-chart/src/main/resources/images/TSB_Del.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_Del.Image.png
new file mode 100644
index 00000000..29bbd5b6
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/TSB_Del.Image.png differ
diff --git a/meteoinfo-chart/src/main/resources/images/TSB_DelAll.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_DelAll.Image.png
new file mode 100644
index 00000000..4a0678c7
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/TSB_DelAll.Image.png differ
diff --git a/meteoinfo-chart/src/main/resources/images/TSB_Distance.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_Distance.Image.png
new file mode 100644
index 00000000..b2df39fd
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/TSB_Distance.Image.png differ
diff --git a/meteoinfo-chart/src/main/resources/images/TSB_Down.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_Down.Image.png
new file mode 100644
index 00000000..e8f1e01b
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/TSB_Down.Image.png differ
diff --git a/meteoinfo-chart/src/main/resources/images/TSB_Feature.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_Feature.Image.png
new file mode 100644
index 00000000..69e7744c
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/TSB_Feature.Image.png differ
diff --git a/MeteoInfoMap/src/main/resources/images/TSB_FullExent.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_FullExent.Image.png
similarity index 100%
rename from MeteoInfoMap/src/main/resources/images/TSB_FullExent.Image.png
rename to meteoinfo-chart/src/main/resources/images/TSB_FullExent.Image.png
diff --git a/meteoinfo-chart/src/main/resources/images/TSB_LabelSet.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_LabelSet.Image.png
new file mode 100644
index 00000000..94b529d2
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/TSB_LabelSet.Image.png differ
diff --git a/meteoinfo-chart/src/main/resources/images/TSB_MakeBreaks.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_MakeBreaks.Image.png
new file mode 100644
index 00000000..fdb60dd8
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/TSB_MakeBreaks.Image.png differ
diff --git a/meteoinfo-chart/src/main/resources/images/TSB_None.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_None.Image.png
new file mode 100644
index 00000000..e25bed01
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/TSB_None.Image.png differ
diff --git a/MeteoInfoMap/src/main/resources/images/TSB_Open.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_Open.Image.png
similarity index 100%
rename from MeteoInfoMap/src/main/resources/images/TSB_Open.Image.png
rename to meteoinfo-chart/src/main/resources/images/TSB_Open.Image.png
diff --git a/MeteoInfoLab/src/main/resources/images/TSB_Pan.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_Pan.Image.png
similarity index 100%
rename from MeteoInfoLab/src/main/resources/images/TSB_Pan.Image.png
rename to meteoinfo-chart/src/main/resources/images/TSB_Pan.Image.png
diff --git a/meteoinfo-chart/src/main/resources/images/TSB_Reverse.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_Reverse.Image.png
new file mode 100644
index 00000000..545db110
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/TSB_Reverse.Image.png differ
diff --git a/meteoinfo-chart/src/main/resources/images/TSB_Save.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_Save.Image.png
new file mode 100644
index 00000000..4bdcf113
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/TSB_Save.Image.png differ
diff --git a/meteoinfo-chart/src/main/resources/images/TSB_Up.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_Up.Image.png
new file mode 100644
index 00000000..f0b81863
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/TSB_Up.Image.png differ
diff --git a/MeteoInfoLab/src/main/resources/images/TSB_ZoomIn.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_ZoomIn.Image.png
similarity index 100%
rename from MeteoInfoLab/src/main/resources/images/TSB_ZoomIn.Image.png
rename to meteoinfo-chart/src/main/resources/images/TSB_ZoomIn.Image.png
diff --git a/MeteoInfoLab/src/main/resources/images/TSB_ZoomOut.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_ZoomOut.Image.png
similarity index 100%
rename from MeteoInfoLab/src/main/resources/images/TSB_ZoomOut.Image.png
rename to meteoinfo-chart/src/main/resources/images/TSB_ZoomOut.Image.png
diff --git a/MeteoInfoMap/src/main/resources/images/TSB_ZoomToLayer.Image.png b/meteoinfo-chart/src/main/resources/images/TSB_ZoomToLayer.Image.png
similarity index 100%
rename from MeteoInfoMap/src/main/resources/images/TSB_ZoomToLayer.Image.png
rename to meteoinfo-chart/src/main/resources/images/TSB_ZoomToLayer.Image.png
diff --git a/meteoinfo-chart/src/main/resources/images/VertexEdit_32x32x32.png b/meteoinfo-chart/src/main/resources/images/VertexEdit_32x32x32.png
new file mode 100644
index 00000000..5969c27f
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/VertexEdit_32x32x32.png differ
diff --git a/MeteoInfoLab/src/main/resources/images/find.png b/meteoinfo-chart/src/main/resources/images/ZoomToLayer.png
similarity index 100%
rename from MeteoInfoLab/src/main/resources/images/find.png
rename to meteoinfo-chart/src/main/resources/images/ZoomToLayer.png
diff --git a/MeteoInfoLab/src/main/resources/images/identifer_32x32x32.png b/meteoinfo-chart/src/main/resources/images/identifer_32x32x32.png
similarity index 100%
rename from MeteoInfoLab/src/main/resources/images/identifer_32x32x32.png
rename to meteoinfo-chart/src/main/resources/images/identifer_32x32x32.png
diff --git a/MeteoInfoLab/src/main/resources/images/information.png b/meteoinfo-chart/src/main/resources/images/information.png
similarity index 100%
rename from MeteoInfoLab/src/main/resources/images/information.png
rename to meteoinfo-chart/src/main/resources/images/information.png
diff --git a/meteoinfo-chart/src/main/resources/images/insert_vertice.png b/meteoinfo-chart/src/main/resources/images/insert_vertice.png
new file mode 100644
index 00000000..adfb1914
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/insert_vertice.png differ
diff --git a/meteoinfo-chart/src/main/resources/images/loading.png b/meteoinfo-chart/src/main/resources/images/loading.png
new file mode 100644
index 00000000..c65be32c
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/loading.png differ
diff --git a/meteoinfo-chart/src/main/resources/images/rotate.png b/meteoinfo-chart/src/main/resources/images/rotate.png
new file mode 100644
index 00000000..35e33771
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/rotate.png differ
diff --git a/meteoinfo-chart/src/main/resources/images/star.bmp b/meteoinfo-chart/src/main/resources/images/star.bmp
new file mode 100644
index 00000000..15737cda
Binary files /dev/null and b/meteoinfo-chart/src/main/resources/images/star.bmp differ
diff --git a/MeteoInfoLab/src/main/resources/images/zoom_in_32x32x32.png b/meteoinfo-chart/src/main/resources/images/zoom_in_32x32x32.png
similarity index 100%
rename from MeteoInfoLab/src/main/resources/images/zoom_in_32x32x32.png
rename to meteoinfo-chart/src/main/resources/images/zoom_in_32x32x32.png
diff --git a/MeteoInfoLab/src/main/resources/images/zoom_out_32x32x32.png b/meteoinfo-chart/src/main/resources/images/zoom_out_32x32x32.png
similarity index 100%
rename from MeteoInfoLab/src/main/resources/images/zoom_out_32x32x32.png
rename to meteoinfo-chart/src/main/resources/images/zoom_out_32x32x32.png
diff --git a/meteoinfo-data/pom.xml b/meteoinfo-data/pom.xml
index 9012bbc9..9819e34e 100644
--- a/meteoinfo-data/pom.xml
+++ b/meteoinfo-data/pom.xml
@@ -16,6 +16,14 @@
1.8
+
+
+ unidata-all
+ Unidata All
+ https://artifacts.unidata.ucar.edu/repository/unidata-all/
+
+
+
${project.groupId}
diff --git a/meteoinfo-data/src/main/java/org/meteoinfo/data/mapdata/geotiff/compression/DeflateCompression.java b/meteoinfo-data/src/main/java/org/meteoinfo/data/mapdata/geotiff/compression/DeflateCompression.java
deleted file mode 100644
index c9ca0ea7..00000000
--- a/meteoinfo-data/src/main/java/org/meteoinfo/data/mapdata/geotiff/compression/DeflateCompression.java
+++ /dev/null
@@ -1,68 +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.data.mapdata.geotiff.compression;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.nio.ByteOrder;
-import java.util.zip.DataFormatException;
-import java.util.zip.Deflater;
-import java.util.zip.Inflater;
-
-/**
- *
- * @author wyq
- */
-public class DeflateCompression implements CompressionDecoder, CompressionEncoder {
-
- @Override
- public byte[] decode(byte[] bytes, ByteOrder byteOrder) {
- try {
- Inflater inflater = new Inflater();
- inflater.setInput(bytes);
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream(bytes.length);
- byte[] buffer = new byte[1024];
- while (!inflater.finished()) {
- int count = inflater.inflate(buffer);
- outputStream.write(buffer, 0, count);
- }
- outputStream.close();
- byte[] output = outputStream.toByteArray();
-
- return output;
- } catch (IOException e) {
- throw new TiffException("Failed close decoded byte stream", e);
- } catch (DataFormatException e) {
- throw new TiffException("Data format error while decoding stream", e);
- }
- }
-
- @Override
- public boolean rowEncoding() {
- return false;
- }
-
- @Override
- public byte[] encode(byte[] bytes, ByteOrder byteOrder) {
- try {
- Deflater deflater = new Deflater();
- deflater.setInput(bytes);
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream(bytes.length);
- deflater.finish();
- byte[] buffer = new byte[1024];
- while (!deflater.finished()) {
- int count = deflater.deflate(buffer); // returns the generated code... index
- outputStream.write(buffer, 0, count);
- }
-
- outputStream.close();
- byte[] output = outputStream.toByteArray();
- return output;
- } catch (IOException e) {
- throw new TiffException("Failed close encoded stream", e);
- }
- }
-}
diff --git a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/MeteoDataInfo.java b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/MeteoDataInfo.java
index bf2e4b94..80fcd1d8 100644
--- a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/MeteoDataInfo.java
+++ b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/MeteoDataInfo.java
@@ -22,6 +22,9 @@ import org.meteoinfo.data.meteodata.arl.ARLDataInfo;
import org.meteoinfo.data.meteodata.ascii.ASCIIGridDataInfo;
import org.meteoinfo.data.meteodata.ascii.LonLatStationDataInfo;
import org.meteoinfo.data.meteodata.ascii.SurferGridDataInfo;
+import org.meteoinfo.data.meteodata.awx.AWXDataInfo;
+import org.meteoinfo.data.meteodata.bandraster.BILDataInfo;
+import org.meteoinfo.data.meteodata.bandraster.GeoTiffDataInfo;
import org.meteoinfo.data.meteodata.grads.GrADSDataInfo;
import org.meteoinfo.data.meteodata.hysplit.HYSPLITConcDataInfo;
import org.meteoinfo.data.meteodata.hysplit.HYSPLITPartDataInfo;
@@ -43,9 +46,6 @@ import org.meteoinfo.data.meteodata.mm5.MM5DataInfo;
import org.meteoinfo.data.meteodata.mm5.MM5IMDataInfo;
import org.meteoinfo.data.mathparser.MathParser;
import org.meteoinfo.data.mathparser.ParseException;
-import org.meteoinfo.data.meteodata.awx.AWXDataInfo;
-import org.meteoinfo.data.meteodata.bandraster.BILDataInfo;
-import org.meteoinfo.data.meteodata.bandraster.GeoTiffDataInfo;
import org.meteoinfo.data.meteodata.metar.METARDataInfo;
import org.meteoinfo.data.meteodata.synop.SYNOPDataInfo;
import org.meteoinfo.ndarray.Array;
diff --git a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/ascii/ASCIIGridDataInfo.java b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/ascii/ASCIIGridDataInfo.java
index 9f4ed6d4..2ec229b6 100644
--- a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/ascii/ASCIIGridDataInfo.java
+++ b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/ascii/ASCIIGridDataInfo.java
@@ -15,6 +15,7 @@ package org.meteoinfo.data.meteodata.ascii;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.data.GridData;
+import org.meteoinfo.data.meteodata.MeteoDataType;
import org.meteoinfo.data.meteodata.DataInfo;
import org.meteoinfo.ndarray.Dimension;
import org.meteoinfo.ndarray.DimensionType;
@@ -34,7 +35,6 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.meteoinfo.data.GridArray;
-import org.meteoinfo.data.meteodata.MeteoDataType;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.ndarray.IndexIterator;
diff --git a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/bandraster/BILDataInfo.java b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/bandraster/BILDataInfo.java
index be0a96af..194f1c73 100644
--- a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/bandraster/BILDataInfo.java
+++ b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/bandraster/BILDataInfo.java
@@ -28,11 +28,11 @@ import java.util.logging.Logger;
import org.meteoinfo.common.DataConvert;
import org.meteoinfo.data.GridArray;
import org.meteoinfo.data.GridData;
+import org.meteoinfo.data.meteodata.MeteoDataType;
import org.meteoinfo.data.meteodata.DataInfo;
import org.meteoinfo.ndarray.Dimension;
import org.meteoinfo.ndarray.DimensionType;
import org.meteoinfo.data.meteodata.IGridDataInfo;
-import org.meteoinfo.data.meteodata.MeteoDataType;
import org.meteoinfo.data.meteodata.Variable;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.DataType;
diff --git a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/bandraster/GeoTiffDataInfo.java b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/bandraster/GeoTiffDataInfo.java
index 874ccd0a..7b329845 100644
--- a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/bandraster/GeoTiffDataInfo.java
+++ b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/bandraster/GeoTiffDataInfo.java
@@ -22,12 +22,12 @@ import java.util.logging.Logger;
import org.meteoinfo.data.GridArray;
import org.meteoinfo.data.GridData;
import org.meteoinfo.data.mapdata.geotiff.GeoTiff;
+import org.meteoinfo.data.meteodata.MeteoDataType;
import org.meteoinfo.data.meteodata.DataInfo;
import org.meteoinfo.ndarray.math.ArrayMath;
import org.meteoinfo.ndarray.Dimension;
import org.meteoinfo.ndarray.DimensionType;
import org.meteoinfo.data.meteodata.IGridDataInfo;
-import org.meteoinfo.data.meteodata.MeteoDataType;
import org.meteoinfo.data.meteodata.Variable;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.IndexIterator;
diff --git a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/grads/GrADSDataInfo.java b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/grads/GrADSDataInfo.java
index 2b2a7512..92c75543 100644
--- a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/grads/GrADSDataInfo.java
+++ b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/grads/GrADSDataInfo.java
@@ -17,6 +17,7 @@ import org.meteoinfo.common.DataConvert;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.util.JDateUtil;
import org.meteoinfo.data.GridData;
+import org.meteoinfo.data.meteodata.arl.ARLDataInfo;
import org.meteoinfo.data.meteodata.DataInfo;
import org.meteoinfo.ndarray.Dimension;
import org.meteoinfo.ndarray.DimensionType;
@@ -52,7 +53,6 @@ import org.meteoinfo.data.meteodata.IStationDataInfo;
import org.meteoinfo.data.meteodata.MeteoDataType;
import org.meteoinfo.data.meteodata.StationInfoData;
import org.meteoinfo.data.meteodata.StationModelData;
-import org.meteoinfo.data.meteodata.arl.ARLDataInfo;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.ndarray.IndexIterator;
diff --git a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/grads/VARDEFS.java b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/grads/VARDEFS.java
index 26cb0acd..e889c03a 100644
--- a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/grads/VARDEFS.java
+++ b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/grads/VARDEFS.java
@@ -14,6 +14,7 @@
package org.meteoinfo.data.meteodata.grads;
import org.meteoinfo.data.meteodata.Variable;
+
import java.util.ArrayList;
import java.util.List;
diff --git a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/grib2/GRIB2MessageIndex.java b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/grib2/GRIB2MessageIndex.java
index 9c81e185..e93cbb6b 100644
--- a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/grib2/GRIB2MessageIndex.java
+++ b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/grib2/GRIB2MessageIndex.java
@@ -5,6 +5,7 @@
package org.meteoinfo.data.meteodata.grib2;
import java.util.Date;
+
import org.meteoinfo.data.meteodata.Variable;
/**
diff --git a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/hysplit/HYSPLITConcDataInfo.java b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/hysplit/HYSPLITConcDataInfo.java
index 9c0c0c71..0355956b 100644
--- a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/hysplit/HYSPLITConcDataInfo.java
+++ b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/hysplit/HYSPLITConcDataInfo.java
@@ -15,6 +15,7 @@ package org.meteoinfo.data.meteodata.hysplit;
import org.meteoinfo.common.DataConvert;
import org.meteoinfo.common.util.JDateUtil;
+import org.meteoinfo.data.meteodata.arl.ARLDataInfo;
import org.meteoinfo.data.meteodata.ascii.ASCIIGridDataInfo;
import org.meteoinfo.data.GridData;
import org.meteoinfo.data.meteodata.DataInfo;
@@ -34,7 +35,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.meteoinfo.data.GridArray;
import org.meteoinfo.data.meteodata.MeteoDataType;
-import org.meteoinfo.data.meteodata.arl.ARLDataInfo;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.ndarray.IndexIterator;
@@ -226,7 +226,7 @@ public class HYSPLITConcDataInfo extends DataInfo implements IGridDataInfo {
yDim.setValues(Y);
this.setYDimension(yDim);
this.addDimension(yDim);
- List variables = new ArrayList<>();
+ List variables = new ArrayList<>();
//Record #4
br.skipBytes(8);
diff --git a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/hysplit/HYSPLITTrajDataInfo.java b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/hysplit/HYSPLITTrajDataInfo.java
index 04cdf10e..a889b0c0 100644
--- a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/hysplit/HYSPLITTrajDataInfo.java
+++ b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/hysplit/HYSPLITTrajDataInfo.java
@@ -16,13 +16,13 @@ package org.meteoinfo.data.meteodata.hysplit;
import org.meteoinfo.common.DataConvert;
import org.meteoinfo.common.PointD;
import org.meteoinfo.common.util.JDateUtil;
+import org.meteoinfo.data.meteodata.Attribute;
import org.meteoinfo.data.meteodata.DataInfo;
-import org.meteoinfo.geometry.legend.*;
+import org.meteoinfo.data.meteodata.MeteoDataType;
+import org.meteoinfo.data.meteodata.Variable;
import org.meteoinfo.ndarray.Dimension;
import org.meteoinfo.ndarray.DimensionType;
-import org.meteoinfo.data.meteodata.Variable;
-import java.awt.Color;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
@@ -36,11 +36,6 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.meteoinfo.data.XYListDataset;
-import org.meteoinfo.data.meteodata.MeteoDataType;
-import org.meteoinfo.geometry.shape.PointZ;
-import org.meteoinfo.geometry.shape.PointZShape;
-import org.meteoinfo.geometry.shape.PolylineZShape;
-import org.meteoinfo.geometry.shape.ShapeTypes;
import org.meteoinfo.table.ColumnData;
import org.meteoinfo.table.DataColumn;
import org.meteoinfo.table.DataTable;
@@ -50,8 +45,6 @@ import org.meteoinfo.ndarray.Index;
import org.meteoinfo.ndarray.InvalidRangeException;
import org.meteoinfo.ndarray.Range;
import org.meteoinfo.ndarray.Section;
-import org.meteoinfo.data.meteodata.Attribute;
-import org.meteoinfo.table.Field;
/**
*
diff --git a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPS2DataInfo.java b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPS2DataInfo.java
index 4f58960e..b512d05a 100644
--- a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPS2DataInfo.java
+++ b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPS2DataInfo.java
@@ -39,7 +39,7 @@ import org.meteoinfo.data.meteodata.Attribute;
*
* @author Yaqiang Wang
*/
-public class MICAPS2DataInfo extends DataInfo implements IStationDataInfo{
+public class MICAPS2DataInfo extends DataInfo implements IStationDataInfo {
//
private String _description;
private List _varList = new ArrayList<>();
diff --git a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPS7DataInfo.java b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPS7DataInfo.java
index 08e27c4b..a64e33cb 100644
--- a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPS7DataInfo.java
+++ b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/micaps/MICAPS7DataInfo.java
@@ -13,7 +13,6 @@
*/
package org.meteoinfo.data.meteodata.micaps;
-import java.awt.Color;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
@@ -28,21 +27,14 @@ import java.util.logging.Logger;
import org.meteoinfo.common.PointD;
import org.meteoinfo.common.util.JDateUtil;
+import org.meteoinfo.data.meteodata.Attribute;
import org.meteoinfo.data.meteodata.DataInfo;
-import org.meteoinfo.geometry.legend.LegendScheme;
-import org.meteoinfo.geometry.legend.LegendType;
-import org.meteoinfo.ndarray.Dimension;
-import org.meteoinfo.ndarray.DimensionType;
import org.meteoinfo.data.meteodata.MeteoDataType;
import org.meteoinfo.data.meteodata.Variable;
import org.meteoinfo.data.meteodata.hysplit.TrajectoryInfo;
-import org.meteoinfo.ndarray.DataType;
-import org.meteoinfo.geometry.shape.PointShape;
-import org.meteoinfo.geometry.shape.PolylineShape;
-import org.meteoinfo.geometry.shape.ShapeTypes;
+import org.meteoinfo.ndarray.Dimension;
+import org.meteoinfo.ndarray.DimensionType;
import org.meteoinfo.ndarray.Array;
-import org.meteoinfo.data.meteodata.Attribute;
-import org.meteoinfo.table.Field;
/**
*
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 edafbefa..1a156f35 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
@@ -14,6 +14,7 @@
package org.meteoinfo.data.meteodata.micaps;
import org.meteoinfo.data.meteodata.MeteoDataType;
+
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
diff --git a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/netcdf/NCUtil.java b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/netcdf/NCUtil.java
index ba854943..8c0953fe 100644
--- a/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/netcdf/NCUtil.java
+++ b/meteoinfo-data/src/main/java/org/meteoinfo/data/meteodata/netcdf/NCUtil.java
@@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
+
import org.meteoinfo.data.meteodata.Attribute;
import org.meteoinfo.data.meteodata.Variable;
import org.meteoinfo.ndarray.*;
diff --git a/meteoinfo-geo/meteoinfo-geo.iml b/meteoinfo-geo/meteoinfo-geo.iml
index f37e9381..ca5caf2c 100644
--- a/meteoinfo-geo/meteoinfo-geo.iml
+++ b/meteoinfo-geo/meteoinfo-geo.iml
@@ -38,7 +38,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/meteoinfo-geo/pom.xml b/meteoinfo-geo/pom.xml
index e73a40fa..545207f6 100644
--- a/meteoinfo-geo/pom.xml
+++ b/meteoinfo-geo/pom.xml
@@ -16,6 +16,29 @@
1.8
+
+
+ central
+ Maven Central
+ https://repo1.maven.org/maven2/
+
+
+ freehep
+ freehep
+ http://java.freehep.org/maven2/
+
+
+ boundless
+ boundlessgeo
+ http://repo.boundlessgeo.com/main/
+
+
+ ebi
+ ebiRepo
+ http://www.ebi.ac.uk/intact/maven/nexus/content/repositories/ebi-repo/
+
+
+
${project.groupId}
@@ -32,6 +55,16 @@
meteoinfo-table
${project.version}
+
+ ${project.groupId}
+ meteoinfo-image
+ ${project.version}
+
+
+ ${project.groupId}
+ meteoinfo-data
+ ${project.version}
+
${project.groupId}
wContour
@@ -42,6 +75,56 @@
l2fprod-common-all
0.1
+
+ org.apache.commons
+ commons-lang3
+ 3.12.0
+
+
+ org.scilab.forge
+ jlatexmath
+ 1.0.7
+
+
+ com.formdev
+ flatlaf
+ 1.0
+
+
+ com.formdev
+ flatlaf-extras
+ 1.0
+
+
+ org.freehep
+ freehep-util
+ 2.0.2
+
+
+ org.freehep
+ freehep-graphicsio-emf
+ 2.4
+
+
+ org.freehep
+ freehep-graphicsio-pdf
+ 2.4
+
+
+ org.freehep
+ freehep-graphics2d
+ 2.4
+
+
+ org.freehep
+ freehep-graphicsio-ps
+ 2.4
+
+
+ com.itextpdf
+ itextpdf
+ 5.5.7
+
\ No newline at end of file
diff --git a/meteoinfo-geo/src/main/java/org/meteoinfo/geo/analysis/GeoComputation.java b/meteoinfo-geo/src/main/java/org/meteoinfo/geo/analysis/GeoComputation.java
index 041d3d65..3e97e4dd 100644
--- a/meteoinfo-geo/src/main/java/org/meteoinfo/geo/analysis/GeoComputation.java
+++ b/meteoinfo-geo/src/main/java/org/meteoinfo/geo/analysis/GeoComputation.java
@@ -5,7 +5,7 @@ import org.meteoinfo.common.Extent;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.PointD;
import org.meteoinfo.geo.layer.VectorLayer;
-import org.meteoinfo.geo.mapview.GridLabel;
+import org.meteoinfo.common.GridLabel;
import org.meteoinfo.geometry.geoprocess.BorderPoint;
import org.meteoinfo.geometry.shape.Line;
import org.meteoinfo.geometry.shape.PolygonShape;
diff --git a/meteoinfo-geo/src/main/java/org/meteoinfo/geo/analysis/GeometryUtil.java b/meteoinfo-geo/src/main/java/org/meteoinfo/geo/analysis/GeometryUtil.java
new file mode 100644
index 00000000..33bdfb45
--- /dev/null
+++ b/meteoinfo-geo/src/main/java/org/meteoinfo/geo/analysis/GeometryUtil.java
@@ -0,0 +1,956 @@
+/*
+ * 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.geo.analysis;
+
+import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.geom.GeometryFactory;
+import org.meteoinfo.common.Extent;
+import org.meteoinfo.common.Extent3D;
+import org.meteoinfo.common.PointD;
+import org.meteoinfo.geo.layer.VectorLayer;
+import org.meteoinfo.geometry.shape.*;
+import org.meteoinfo.ndarray.Array;
+import org.meteoinfo.ndarray.DataType;
+import org.meteoinfo.ndarray.IndexIterator;
+import org.meteoinfo.ndarray.InvalidRangeException;
+import org.meteoinfo.ndarray.math.ArrayMath;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author wyq
+ */
+public class GeometryUtil {
+
+ /**
+ * Get extent from point list
+ *
+ * @param PList point list
+ * @return extent
+ */
+ public static Extent getPointsExtent(List extends PointD> PList) {
+ if (PList.get(0) instanceof PointZ){
+ Extent3D cET = new Extent3D();
+ for (int i = 0; i < PList.size(); i++) {
+ PointZ aP = (PointZ)PList.get(i);
+ if (i == 0) {
+ cET.minX = aP.X;
+ cET.maxX = aP.X;
+ cET.minY = aP.Y;
+ cET.maxY = aP.Y;
+ cET.minZ = aP.Z;
+ cET.maxZ = aP.Z;
+ } else {
+ if (cET.minX > aP.X) {
+ cET.minX = aP.X;
+ } else if (cET.maxX < aP.X) {
+ cET.maxX = aP.X;
+ }
+
+ if (cET.minY > aP.Y) {
+ cET.minY = aP.Y;
+ } else if (cET.maxY < aP.Y) {
+ cET.maxY = aP.Y;
+ }
+
+ if (cET.minZ > aP.Z) {
+ cET.minZ = aP.Z;
+ } else if (cET.maxZ < aP.Z) {
+ cET.maxZ = aP.Z;
+ }
+ }
+ }
+
+ return cET;
+ } else {
+ Extent cET = new Extent();
+ for (int i = 0; i < PList.size(); i++) {
+ PointD aP = PList.get(i);
+ if (i == 0) {
+ cET.minX = aP.X;
+ cET.maxX = aP.X;
+ cET.minY = aP.Y;
+ cET.maxY = aP.Y;
+ } else {
+ if (cET.minX > aP.X) {
+ cET.minX = aP.X;
+ } else if (cET.maxX < aP.X) {
+ cET.maxX = aP.X;
+ }
+
+ if (cET.minY > aP.Y) {
+ cET.minY = aP.Y;
+ } else if (cET.maxY < aP.Y) {
+ cET.maxY = aP.Y;
+ }
+ }
+ }
+
+ return cET;
+ }
+ }
+
+ /**
+ * Get extent of the shapes
+ *
+ * @param shapes
+ * @return Extent
+ */
+ public static Extent getExtent(List extends Shape> shapes) {
+ Extent extent = (Extent) shapes.get(0).getExtent().clone();
+ double minx = extent.minX;
+ double maxx = extent.maxX;
+ double miny = extent.minY;
+ double maxy = extent.maxY;
+ Extent ext;
+ for (int i = 1; i < shapes.size(); i++) {
+ ext = shapes.get(i).getExtent();
+ if (minx > ext.minX) {
+ minx = ext.minX;
+ }
+ if (maxx < ext.maxX) {
+ maxx = ext.maxX;
+ }
+ if (miny > ext.minY) {
+ miny = ext.minY;
+ }
+ if (maxy < ext.maxY) {
+ maxy = ext.maxY;
+ }
+ }
+
+ extent.minX = minx;
+ extent.maxX = maxx;
+ extent.minY = miny;
+ extent.maxY = maxy;
+
+ return extent;
+ }
+
+ /**
+ * Get extent of the points
+ *
+ * @param points
+ * @return Extent
+ */
+ public static Extent3D getExtent(PointZ[] points) {
+ PointZ p = points[0];
+ double minx = p.X;
+ double maxx = p.X;
+ double miny = p.Y;
+ double maxy = p.Y;
+ double minz = p.Z;
+ double maxz = p.Z;
+ for (int i = 1; i < points.length; i++) {
+ if (minx > p.X) {
+ minx = p.M;
+ }
+ if (maxx < p.X) {
+ maxx = p.M;
+ }
+ if (miny > p.Y) {
+ miny = p.Y;
+ }
+ if (maxy < p.Y) {
+ maxy = p.Y;
+ }
+ if (minz > p.Z) {
+ minz = p.Z;
+ }
+ if (maxz < p.Z) {
+ maxz = p.Z;
+ }
+ }
+
+ Extent3D extent = new Extent3D();
+ extent.minX = minx;
+ extent.maxX = maxx;
+ extent.minY = miny;
+ extent.maxY = maxy;
+ extent.minZ = minz;
+ extent.maxZ = maxz;
+
+ return extent;
+ }
+
+ /**
+ * Get ellipse coordinate
+ * @param x0 Center x
+ * @param y0 Center y
+ * @param a Major axis
+ * @param b Minor axis
+ * @param angle Angle
+ * @return Coordinate on the ellipse
+ */
+ public static PointD getEllipseXY(double x0, double y0, double a, double b, double angle) {
+ double rangle = Math.toRadians(angle);
+ double x = (a * b) / Math.sqrt(b * b + a * a * Math.tan(rangle) * Math.tan(rangle));
+ if (angle > 90 && angle < 270){
+ x = -x;
+ }
+ double y = Math.tan(rangle) * x;
+ if (angle > 0 && angle < 180) {
+ y = -Math.abs(y);
+ }
+
+ return new PointD(x + x0, y + y0);
+ }
+
+ /**
+ * Get ellipse coordinates
+ * @param x0 Center x
+ * @param y0 Center y
+ * @param a Major axis
+ * @param b Minor axis
+ * @param deltaAngle Delta angle
+ * @return Coordinate on the ellipse
+ */
+ public static List getEllipseCoordinates(double x0, double y0, double a, double b, double deltaAngle) {
+ List points = new ArrayList<>();
+ for (double angle = 0; angle <= 360; angle += deltaAngle){
+ points.add(getEllipseXY(x0, y0, a, b, angle));
+ }
+
+ return points;
+ }
+
+ /**
+ * Get ellipse coordinates
+ * @param x0 Center x
+ * @param y0 Center y
+ * @param a Major axis
+ * @param b Minor axis
+ * @return Coordinate on the ellipse
+ */
+ public static List getEllipseCoordinates(double x0, double y0, double a, double b) {
+ List points = new ArrayList<>();
+ double deltaAngle = 1;
+ for (double angle = 0; angle <= 360; angle += deltaAngle){
+ points.add(getEllipseXY(x0, y0, a, b, angle));
+ }
+
+ return points;
+ }
+
+ /**
+ * Computes the smallest convex Polygon that contains all the
+ * points
+ *
+ * @param x X array
+ * @param y Y array
+ * @return PolygonShape
+ */
+ public static PolygonShape convexHull(Array x, Array y) {
+ int n = (int) x.getSize();
+ List geos = new ArrayList<>();
+ GeometryFactory factory = new GeometryFactory();
+ IndexIterator xIter = x.getIndexIterator();
+ IndexIterator yIter = y.getIndexIterator();
+ double xx, yy;
+ while(xIter.hasNext()) {
+ xx = xIter.getDoubleNext();
+ yy = yIter.getDoubleNext();
+ if (!Double.isNaN(xx) && !Double.isNaN(yy)) {
+ Coordinate c = new Coordinate(xx, yy);
+ geos.add(factory.createPoint(c));
+ }
+ }
+ Geometry gs = factory.createGeometryCollection(geos.toArray(new Geometry[geos.size()]));
+ Geometry ch = gs.convexHull();
+ return new PolygonShape(ch);
+ }
+
+ /**
+ * In polygon function
+ *
+ * @param a Array a
+ * @param x X dimension values
+ * @param y Y dimension values
+ * @param layer Polygon vector layer
+ * @return Result array with cell values of 1 inside polygons and -1 outside
+ * polygons
+ */
+ public static Array inPolygon(Array a, List x, List y, VectorLayer layer) {
+ List polygons = (List) layer.getShapes();
+ return inPolygon(a, x, y, polygons);
+ }
+
+ /**
+ * In polygon function
+ *
+ * @param a Array a
+ * @param x X dimension values
+ * @param y Y dimension values
+ * @param ps Polygon shape
+ * @return Result array with cell values of 1 inside polygons and -1 outside
+ * polygons
+ */
+ public static Array inPolygon(Array a, List x, List y, PolygonShape ps) {
+ List polygons = new ArrayList<>();
+ polygons.add(ps);
+ return inPolygon(a, x, y, polygons);
+ }
+
+ /**
+ * In polygon function
+ *
+ * @param a Array a
+ * @param x X dimension values
+ * @param y Y dimension values
+ * @param polygons PolygonShape list
+ * @return Result array with cell values of 1 inside polygons and -1 outside
+ * polygons
+ */
+ public static Array inPolygon(Array a, List x, List y, List polygons) {
+ if (a.getRank() == 2) {
+ int xNum = x.size();
+ int yNum = y.size();
+
+ Array r = Array.factory(DataType.INT, a.getShape());
+ for (int i = 0; i < yNum; i++) {
+ for (int j = 0; j < xNum; j++) {
+ if (GeoComputation.pointInPolygons(polygons, new PointD(x.get(j).doubleValue(), y.get(i).doubleValue()))) {
+ r.setInt(i * xNum + j, 1);
+ } else {
+ r.setInt(i * xNum + j, -1);
+ }
+ }
+ }
+
+ return r;
+ } else if (a.getRank() == 1) {
+ int n = x.size();
+ Array r = Array.factory(DataType.INT, a.getShape());
+ for (int i = 0; i < n; i++) {
+ if (GeoComputation.pointInPolygons(polygons, new PointD(x.get(i).doubleValue(), y.get(i).doubleValue()))) {
+ r.setInt(i, 1);
+ } else {
+ r.setInt(i, -1);
+ }
+ }
+
+ return r;
+ }
+
+ return null;
+ }
+
+ /**
+ * In polygon function
+ *
+ * @param x X coordinates
+ * @param y Y coordinates
+ * @param polygons PolygonShape list
+ * @return Result boolean array
+ */
+ public static Array inPolygon(Array x, Array y, List polygons) {
+ Array r = Array.factory(DataType.BOOLEAN, x.getShape());
+ IndexIterator xIter = x.getIndexIterator();
+ IndexIterator yIter = y.getIndexIterator();
+ IndexIterator rIter = r.getIndexIterator();
+ while (rIter.hasNext()){
+ if (GeoComputation.pointInPolygons(polygons, new PointD(xIter.getDoubleNext(),
+ yIter.getDoubleNext()))) {
+ rIter.setBooleanNext(true);
+ } else {
+ rIter.setBooleanNext(false);
+ }
+ }
+
+ return r;
+ }
+
+ /**
+ * In polygon function
+ *
+ * @param a Array a
+ * @param x X dimension values
+ * @param y Y dimension values
+ * @param x_p X coordinate of the polygon
+ * @param y_p Y coordinate of the polygon
+ * @return Result array with cell values of 1 inside polygons and -1 outside
+ * polygons
+ */
+ public static Array inPolygon(Array a, List x, List y, List x_p, List y_p) {
+ PolygonShape ps = new PolygonShape();
+ List points = new ArrayList<>();
+ for (int i = 0; i < x_p.size(); i++) {
+ points.add(new PointD(x_p.get(i).doubleValue(), y_p.get(i).doubleValue()));
+ }
+ ps.setPoints(points);
+ List shapes = new ArrayList<>();
+ shapes.add(ps);
+
+ return inPolygon(a, x, y, shapes);
+ }
+
+ /**
+ * In polygon function
+ *
+ * @param x X coordinates
+ * @param y Y coordinates
+ * @param x_p X coordinate of the polygon
+ * @param y_p Y coordinate of the polygon
+ * @return Result boolean array
+ */
+ public static Array inPolygon(Array x, Array y, Array x_p, Array y_p) {
+ PolygonShape ps = new PolygonShape();
+ List points = new ArrayList<>();
+ IndexIterator xIter = x_p.getIndexIterator();
+ IndexIterator yIter = y_p.getIndexIterator();
+ while (xIter.hasNext()) {
+ points.add(new PointD(xIter.getDoubleNext(), yIter.getDoubleNext()));
+ }
+ ps.setPoints(points);
+ List shapes = new ArrayList<>();
+ shapes.add(ps);
+
+ return inPolygon(x, y, shapes);
+ }
+
+ /**
+ * Maskout function
+ *
+ * @param a Array a
+ * @param x X dimension values
+ * @param y Y dimension values
+ * @param layer VectorLayer
+ * @param missingValue Missing value
+ * @return Result array with cell values of missing outside polygons
+ */
+ public static Array maskout(Array a, List x, List y, VectorLayer layer, Number missingValue) {
+ List polygons = (List) layer.getShapes();
+ return maskout(a, x, y, polygons, missingValue);
+ }
+
+ /**
+ * Maskout function
+ *
+ * @param a Array a
+ * @param x X dimension values
+ * @param y Y dimension values
+ * @param polygon Polygon shape
+ * @param missingValue Missing value
+ * @return Result array with cell values of missing outside polygons
+ */
+ public static Array maskout(Array a, List x, List y, PolygonShape polygon, Number missingValue) {
+ List polygons = new ArrayList<>();
+ polygons.add(polygon);
+ return maskout(a, x, y, polygons, missingValue);
+ }
+
+ /**
+ * Maskout function
+ *
+ * @param a Array a
+ * @param x X Array
+ * @param y Y Array
+ * @param polygons Polygons for maskout
+ * @return Result array with cell values of missing outside polygons
+ */
+ public static Array maskout(Array a, Array x, Array y, List polygons) {
+ Array r = Array.factory(a.getDataType(), a.getShape());
+ IndexIterator aIter = a.getIndexIterator();
+ IndexIterator xIter = x.getIndexIterator();
+ IndexIterator yIter = y.getIndexIterator();
+ int i = 0;
+ while (aIter.hasNext()){
+ if (GeoComputation.pointInPolygons(polygons, new PointD(xIter.getDoubleNext(),
+ yIter.getDoubleNext()))) {
+ r.setObject(i, aIter.getObjectNext());
+ } else {
+ r.setObject(i, Double.NaN);
+ aIter.next();
+ }
+ i++;
+ }
+ return r;
+ }
+
+ /**
+ * Maskin function
+ *
+ * @param a Array a
+ * @param x X Array
+ * @param y Y Array
+ * @param polygons Polygons for maskin
+ * @return Result array with cell values of missing inside polygons
+ */
+ public static Array maskin(Array a, Array x, Array y, List polygons) {
+ Array r = Array.factory(a.getDataType(), a.getShape());
+ IndexIterator aIter = a.getIndexIterator();
+ IndexIterator xIter = x.getIndexIterator();
+ IndexIterator yIter = y.getIndexIterator();
+ int i = 0;
+ while(aIter.hasNext()) {
+ if (GeoComputation.pointInPolygons(polygons, new PointD(xIter.getDoubleNext(),
+ yIter.getDoubleNext()))) {
+ r.setObject(i, Double.NaN);
+ aIter.next();
+ } else {
+ r.setObject(i, aIter.getObjectNext());
+ }
+ i++;
+ }
+ return r;
+ }
+
+ /**
+ * Maskout function
+ *
+ * @param a Array a
+ * @param x X Array
+ * @param y Y Array
+ * @param polygons Polygons for maskout
+ * @return Result arrays removing cells outside polygons
+ */
+ public static Array[] maskout_Remove(Array a, Array x, Array y, List polygons) {
+ List