1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-02 00:20:49 +00:00
plantuml/src/net/sourceforge/plantuml/acearth/PSystemXearth.java

135 lines
4.7 KiB
Java
Raw Normal View History

2011-09-07 20:41:58 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, Arnaud Roques
2011-09-07 20:41:58 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2011-09-07 20:41:58 +00:00
*
2017-03-15 19:13:31 +00:00
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
2011-09-07 20:41:58 +00:00
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2011-09-07 20:41:58 +00:00
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.acearth;
import java.io.IOException;
import java.io.OutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
2016-05-31 19:41:55 +00:00
import java.util.Locale;
2011-09-07 20:41:58 +00:00
import java.util.Map;
import java.util.TimeZone;
2020-04-19 16:04:39 +00:00
import ext.plantuml.com.ctreber.acearth.ACearth;
import ext.plantuml.com.ctreber.acearth.ConfigurationACearth;
import ext.plantuml.com.ctreber.acearth.plugins.markers.Marker;
2011-09-07 20:41:58 +00:00
import net.sourceforge.plantuml.AbstractPSystem;
import net.sourceforge.plantuml.FileFormatOption;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.api.ImageDataSimple;
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.ImageData;
2011-09-07 20:41:58 +00:00
public class PSystemXearth extends AbstractPSystem {
final private int width;
final private int height;
final private Map<String, String> config;
final private List<Marker> markers;
final private Collection<String> enums = Arrays.asList("viewPositionType");
final private Collection<String> doubles = Arrays.asList("sunPosRelLat", "sunPosRelLong", "orbitPeriod",
"orbitInclination", "viewPosLat", "viewPosLong", "starFrequency", "viewMagnification");
final private Collection<String> integers = Arrays.asList("daySideBrightness", "nightSideBrightness",
"terminatorDiscontinuity", "gridDivision", "gridPixelDivision", "bigStars");
final private Collection<String> booleans = Arrays.asList("shadeP", "gridP", "starsP");
public PSystemXearth(int width, int height, Map<String, String> config, List<Marker> markers) {
this.width = width;
this.height = height;
this.config = config;
this.markers = markers;
}
2016-12-01 20:29:25 +00:00
@Override
2017-04-19 18:30:16 +00:00
final protected ImageData exportDiagramNow(OutputStream os, int num, FileFormatOption fileFormat, long seed)
2016-12-01 20:29:25 +00:00
throws IOException {
2019-09-14 18:12:04 +00:00
synchronized (PSystemXearth.class) {
final ACearth earth = new ACearth(markers);
final ConfigurationACearth conf = earth.getConf();
conf.setInt("imageWidth", width);
conf.setInt("imageHeight", height);
2011-09-07 20:41:58 +00:00
2019-09-14 18:12:04 +00:00
for (Map.Entry<String, String> ent : config.entrySet()) {
final String key = ent.getKey();
final String value = ent.getValue();
if (key.equalsIgnoreCase("GMT")) {
final Date date = extractGmt(value);
conf.setInt("fixedTime", (int) (date.getTime() / 1000L));
} else if (enums.contains(key)) {
conf.getMOEnum(key).set(value);
} else if (doubles.contains(key)) {
conf.setDouble(key, Double.parseDouble(value));
} else if (integers.contains(key)) {
conf.setInt(key, Integer.parseInt(value));
} else if (booleans.contains(key)) {
conf.setBoolean(key, value.equalsIgnoreCase("true"));
} else {
throw new UnsupportedOperationException(key);
}
2011-09-07 20:41:58 +00:00
}
2019-09-14 18:12:04 +00:00
earth.exportPng(os);
return new ImageDataSimple(width, height);
2011-09-07 20:41:58 +00:00
}
}
private Date extractGmt(String s) {
final SimpleDateFormat timeFormat;
if (s.matches("\\d{4}/\\d{2}/\\d{2} \\d{2}:\\d{2}:\\d{2}")) {
2016-05-31 19:41:55 +00:00
timeFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.US);
2011-09-07 20:41:58 +00:00
} else if (s.matches("\\d{4}/\\d{2}/\\d{2} \\d{2}:\\d{2}")) {
2016-05-31 19:41:55 +00:00
timeFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm", Locale.US);
2011-09-07 20:41:58 +00:00
} else {
throw new UnsupportedOperationException(s);
}
timeFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
try {
return timeFormat.parse(s);
} catch (ParseException e) {
throw new UnsupportedOperationException(s);
}
}
2013-12-10 19:36:50 +00:00
public DiagramDescription getDescription() {
2017-03-12 17:22:02 +00:00
return new DiagramDescription("(XEarth)");
2011-09-07 20:41:58 +00:00
}
}