diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..905fd4f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/target/ +.settings/* +.project +.classpath \ No newline at end of file diff --git a/distro-zip.xml b/distro-zip.xml new file mode 100644 index 0000000..aa0556b --- /dev/null +++ b/distro-zip.xml @@ -0,0 +1,30 @@ + + distro zip + + zip + + false + + + + / + false + + ${artifact} + + + + + /lib + false + runtime + true + false + + org.openjump:OpenJUMP + + + + \ No newline at end of file diff --git a/doc/JumpChartUserGuide.pdf b/doc/JumpChartUserGuide.pdf new file mode 100644 index 0000000..9283a47 Binary files /dev/null and b/doc/JumpChartUserGuide.pdf differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..146fca4 --- /dev/null +++ b/pom.xml @@ -0,0 +1,122 @@ + + + + 4.0.0 + com.cadplan + jump-chart-extension + 2.1.0 + + + 1.8 + 1.8 + UTF-8 + + [${git.branch}/${git.commit.id.abbrev}/${git.build.time}] + + + + + ojrepo + OpenJUMP Snapshot Repository + https://ojrepo.soldin.de/ + + + + + + org.openjump + OpenJUMP + 2.0-main-SNAPSHOT + + + + + + + src/main/resources + + + src/main/resources + + com/cadplan/jump_chart/language/ + + true + + + + + maven-assembly-plugin + 3.3.0 + + false + + + + distro zip + package + + + distro-zip.xml + + false + + + single + + + + + + pl.project13.maven + git-commit-id-plugin + 4.9.10 + + + + + fetch git properties of current branch + + revision + + validate + + + + true + + ^git.branch$ + ^git.build.(time|version|(number(|.unique)))$ + ^git.commit.(id.(abbrev|full)|message.short)$ + ^git.dirty$ + + + + + net.nicoulaj.maven.plugins + checksum-maven-plugin + 1.10 + + + + files + + package + + + + ${project.build.directory} + + ${project.build.finalName}.zip + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/cadplan/jump_chart/designer/GridBagDesigner.java b/src/main/java/com/cadplan/jump_chart/designer/GridBagDesigner.java new file mode 100644 index 0000000..05efc7d --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/designer/GridBagDesigner.java @@ -0,0 +1,223 @@ +/* + * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI + * for visualizing and manipulating spatial features with geometry and attributes. + * + * Copyright (C) 2006 Cadplan + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 com.cadplan.jump_chart.designer; +//=================================================== +// GridBagDesigner +//=================================================== + + + + +import java.awt.*; +import javax.swing.*; + +/** + * @author Geoffrey G. Roy + * @version 1.0 + */ + + +public class GridBagDesigner +{ + + + + +private GridBagLayout layout; +private GridBagConstraints constraints; +private Container container; + + + + /** + * Constructor for GridBagDesgner + * + * @param container + */ +public GridBagDesigner(Container container) +{ + layout = new GridBagLayout(); + constraints = new GridBagConstraints(); + container.setLayout(layout); + this.container = container; + setDefaults(); +} + + + + /** + * Adds a component using currrent settings + * + * @param component + */ + +public void addComponent(Component component) +{ + layout.setConstraints(component, constraints); + container.add(component); + setDefaults(); +} + public void addComponentRetain(Component component) +{ + layout.setConstraints(component, constraints); + container.add(component); +} + + /** + * Adds a JComponent using current settings and fixes + * size to xSize * ySize + * + * @param component + * @param xSize + * @param ySize + */ +public void addComponent(JComponent component, int xSize, int ySize) +{ + Dimension size = new Dimension(xSize, ySize); + component.setMinimumSize(size); + component.setMaximumSize(size); + component.setPreferredSize(size); + layout.setConstraints(component, constraints); + container.add(component); + setDefaults(); +} + +public void addComponentRetain(JComponent component, int xSize, int ySize) +{ + Dimension size = new Dimension(xSize, ySize); + component.setMinimumSize(size); + component.setMaximumSize(size); + component.setPreferredSize(size); + layout.setConstraints(component, constraints); + container.add(component); +} + +public void resetLayout() +{ + setDefaults(); +} + + + /** + * Sets gid position + * Default is (0,0); + * + * @param gridx + * @param gridy + */ +public void setPosition(int gridx, int gridy) +{ + constraints.gridx = gridx; + constraints.gridy = gridy; +} + + + /** + * Sets grid span + * Defaults are (1,1) + * + * @param gridwidth + * @param gridheight + */ +public void setSpan(int gridwidth, int gridheight) +{ + constraints.gridwidth = gridwidth; + constraints.gridheight = gridheight; +} + + + /** + * Sets cell weights + * Defaults are (0.0,0.0) + * + * @param weightx + * @param weighty + */ +public void setWeight(double weightx, double weighty) +{ + constraints.weightx = weightx; + constraints.weighty = weighty; +} + + + /** + * Sets cell fill type as one of: + * GridBagConstraints.{NONE, VERTICAL, HORIZONTAL, BOTH} + * Default is NONE + * + * @param fill + */ +public void setFill(int fill) +{ + constraints.fill = fill; +} + + + /** + * Sets cell anchor type as one of: + * GridBagConstraints.{NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST, CENTER} + * Default is CENTER + * + * @param anchor + */ +public void setAnchor(int anchor) +{ + constraints.anchor = anchor; +} + + + + /** + * Sets cell insets + * Defaults are (0,0,0,0) + * + * @param top + * @param left + * @param bottom + * @param right + */ +public void setInsets(int top, int left, int bottom, int right) +{ + constraints.insets = new Insets(top, left, bottom, right); +} + + + /** + * Sets cell defaults + * + */ +private void setDefaults() +{ + constraints.gridx = 0; + constraints.gridy = 0; + constraints.gridwidth = 1; + constraints.gridheight = 1; + constraints.fill = GridBagConstraints.NONE; + constraints.anchor = GridBagConstraints.CENTER; + constraints.weightx = 0.0; + constraints.weighty = 0.0; + constraints.insets = new Insets(0,0,0,0); + +} + + +} diff --git a/src/main/java/com/cadplan/jump_chart/fileio/FileChooser.java b/src/main/java/com/cadplan/jump_chart/fileio/FileChooser.java new file mode 100644 index 0000000..e0d92d5 --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/fileio/FileChooser.java @@ -0,0 +1,138 @@ +package com.cadplan.jump_chart.fileio; + + + +import javax.swing.*; +import javax.swing.filechooser.FileFilter; +import java.io.File; +import java.awt.*; +import java.util.Properties; + +/** + * User: geoff + * Date: 5/04/2006 + * Time: 12:54:42 + * Copyright 2005 Geoffrey G Roy. + */ +public class FileChooser +{ + JFileChooser chooser; + public String fileName; + public String dirName; + + public FileChooser(Component parent, String defaultDirName, String defaultFileName, + String [] filterText, String info, int type) + { + int returnVal; + File dir; + Properties props = System.getProperties(); + if(defaultDirName == null) dir = new File(props.getProperty("user.dir")); + else dir = new File(defaultDirName+File.separator); + chooser = new JFileChooser(); + chooser.setDialogType(type); + + + MyFileFilter filter = new MyFileFilter(info, filterText); + + chooser.setFileFilter(filter); + chooser.setCurrentDirectory(dir); + if(defaultFileName != null) chooser.setSelectedFile(new File(defaultFileName)); + + if(type == JFileChooser.OPEN_DIALOG) + { + returnVal= chooser.showOpenDialog(parent); + } + else + { + returnVal= chooser.showSaveDialog(parent); + } + + if(returnVal == JFileChooser.APPROVE_OPTION) + { + fileName = chooser.getSelectedFile().getName(); + if(type == JFileChooser.SAVE_DIALOG) fileName = addExtension(fileName,filterText); + dirName = chooser.getCurrentDirectory().getPath(); + } + else + { + fileName = null; + } + } + public String getFile() + { + return fileName; + } + public String getDir() + { + return dirName; + } + + private String addExtension(String name, String [] filterText) + { + boolean OK = false; + for (int i=0; i < filterText.length; i++) + { + String ext = filterText[i]; + if(name.toLowerCase().endsWith("."+ext)) OK = true; + } + if(!OK) name = name + "." + filterText[0]; + return name; + } +} + +class MyFileFilter extends FileFilter +{ + String description; + String [] extensions; + boolean acceptAll = false; + + public MyFileFilter(String description, String extension) + { + this(description, new String [] {extension}); + } + + public MyFileFilter(String description, String [] extensions) + { + if(description == null) this.description = "Files like: "+extensions[0]; + else this.description = description; + this.extensions = (String []) extensions.clone(); + toLower(this.extensions); + for(int i=0; i < this.extensions.length; i++) + { + if(this.extensions[i].equals("*")) acceptAll = true; + } + } + + private void toLower(String [] sa) + { + for (int i=0, n = sa.length; i < n; i++) + { + sa[i] = sa[i].toLowerCase(); + } + } + + public String getDescription() + { + return description; + } + + public boolean accept(File file) + { + if(file.isDirectory()) return true; + if(acceptAll) return true; + else + { + String path = file.getAbsolutePath().toLowerCase(); + for (int i=0; i < extensions.length; i++) + { + + String extension = extensions[i]; + if(path.endsWith(extension) && (path.charAt(path.length() - extension.length()-1) == '.')) + { + return true; + } + } + } + return false; + } +} diff --git a/src/main/java/com/cadplan/jump_chart/fileio/IconLoader.java b/src/main/java/com/cadplan/jump_chart/fileio/IconLoader.java new file mode 100644 index 0000000..1b8aa9f --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/fileio/IconLoader.java @@ -0,0 +1,105 @@ +package com.cadplan.jump_chart.fileio; + +//================================================================== +// +// IconLoader +// +//================================================================== +// +// This module is a part of the P-Coder package +// �2002, Geoffrey G. Roy, School of Engineering, Murdoch University +//================================================================== + + +import java.awt.*; +import java.net.*; +import java.util.*; +import java.io.*; +import java.util.jar.*; +import java.lang.*; + + +public class IconLoader extends Component { + boolean debug = false; + Image image = null; + Properties prop = null; + MediaTracker tracker; + URL url, jarurl; + String appName; + String wd = ""; + + + public IconLoader(String wd, String appName) { + this.wd = wd; + this.appName = appName; + } + + public IconLoader(String appName) { + + prop = System.getProperties(); + wd = prop.getProperty("user.dir"); + this.appName = appName; + } + + public void setWD(String dirName) { + wd = dirName; + } + + public Image loadImage(String name) { + tracker = new MediaTracker(this); + Image image = load(name); + return (image); + + } + + + public Image load(String name) { + + + if (debug) System.out.println("User WD = " + wd); + String filename; + filename = "jar:file:" + wd + "/" + appName + ".jar!/" + "Resources/" + name; + if (debug) System.out.println("Loading from jar: " + filename); + try { + jarurl = new URL(filename); + // System.out.println("URL= "+jarurl); + JarURLConnection jarConnection = (JarURLConnection) jarurl.openConnection(); + Manifest manifest = jarConnection.getManifest(); + // System.out.println("Loading splash from JAR"); + + } catch (MalformedURLException e) { + if (debug) System.out.println("Jar file not found at " + wd); + } catch (IOException e) { + + + if (debug) System.out.println("Error opening Jar file at: " + wd); + if (debug) System.out.println("Jar file not found " + e); + if (debug) System.out.println("Error opening Jar file from URL, trying local file: " + e); + try { + String fname = ""; + fname = "file:///" + wd + "/Classes/Resources/" + name; + if (debug) System.out.println("Loading from: " + fname); + jarurl = new URL(fname); + if (debug) System.out.println("Loading icon from GIF"); + } catch (MalformedURLException e1) { + System.out.println("ERROR - " + e1); + } + + } + if (debug) System.out.println("URL= " + jarurl); + image = Toolkit.getDefaultToolkit().getImage(jarurl); + try { + tracker.addImage(image, 1); + tracker.waitForID(1); + } catch (InterruptedException e) { + } + + if (debug) System.out.println("Image size: " + image.getWidth(this) + ", " + image.getHeight(this)); + if (image.getWidth(this) < 0) image = null; +// Icon icon = new ImageIcon(image); + return (image); + + } + + +} diff --git a/src/main/java/com/cadplan/jump_chart/fileio/TextFile.java b/src/main/java/com/cadplan/jump_chart/fileio/TextFile.java new file mode 100644 index 0000000..5cdd496 --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/fileio/TextFile.java @@ -0,0 +1,123 @@ +package com.cadplan.jump_chart.fileio; + +import java.io.*; +import java.util.Properties; + +/** + * User: geoff + * Date: 18/10/2006 + * Time: 09:49:10 + * Copyright 2005 Geoffrey G Roy. + */ +public class TextFile +{ + String fileName; + String dirName; + BufferedReader reader = null; + FileWriter writer = null; + + public TextFile(String dirName, String fileName) + { + this.dirName = dirName; + Properties props = System.getProperties(); + if(dirName == null) this.dirName = props.getProperty("user.dir"); + this.fileName = fileName; + } + + public boolean exists() + { + File file = new File(dirName+File.separator+fileName); + return file.exists(); + } + + public boolean openRead() + { + File file = new File(dirName+File.separator+fileName); + + try + { + reader = new BufferedReader(new FileReader(file)); + return true; + } + catch (FileNotFoundException ex) + { + return false; + } + + } + + public boolean openWrite() + { + File file = new File(dirName+File.separator+fileName); + + try + { + writer = new FileWriter(file); + return true; + } + catch (IOException ex) + { + return false; + } + } + + public String readLine() + { + try + { + return reader.readLine(); + } + catch (IOException ex) + { + return null; + } + } + + public String readAll() + { + String line = ""; + StringBuffer sb = new StringBuffer(); + try + { + while (line != null) + { + line = reader.readLine(); + if(line != null) sb.append(line+"\n"); + } + } + catch (IOException ex) + { + return sb.toString(); + } + return sb.toString(); + } + + public boolean write(String s) + { + try + { + writer.write(s); + return true; + } + catch (IOException ex) + { + return false; + } + } + + public void close() + { try + { + if(reader != null) reader.close(); + else if(writer != null) + { + writer.flush(); + writer.close(); + } + } + catch (IOException ex) + { + + } + } +} diff --git a/src/main/java/com/cadplan/jump_chart/jump/AttributeOrder.java b/src/main/java/com/cadplan/jump_chart/jump/AttributeOrder.java new file mode 100644 index 0000000..b862323 --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/jump/AttributeOrder.java @@ -0,0 +1,169 @@ +/* + * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI + * for visualizing and manipulating spatial features with geometry and attributes. + * + * Copyright (C) 2006 Cadplan + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 com.cadplan.jump_chart.jump; + +import com.cadplan.jump_chart.designer.GridBagDesigner; +import com.vividsolutions.jump.I18N; + +import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.border.EtchedBorder; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import java.awt.*; + +/** + * User: geoff + * Date: 10/05/2007 + * Time: 10:03:35 + * Copyright 2005 Geoffrey G Roy. + */ +public class AttributeOrder extends JDialog implements ActionListener { + + private static final I18N i18n = JumpChartPlugIn.I18N; + JList attributeList; + JButton upButton, downButton, acceptButton, cancelButton; + String[] localList; + int numItems; + ChartDialog parent; + + public AttributeOrder(ChartDialog parent) + { + super(parent, i18n.get("JumpChart.Order.Order"), true); + this.parent = parent; + numItems = 0; + for (int i=0; i < ChartParams.attributes.length; i++) + { + if(ChartParams.includeAttribute[i]) numItems++; + } + //System.out.println("number of selected items = "+numItems); + + localList = new String[numItems]; + int k = 0; + for (int i=0; i < ChartParams.attributes.length; i++) + { + if(ChartParams.includeAttribute[i]) + { + //String item = ChartParams.attributes[i].name; + int order = ChartParams.attributeOrder[i]; + if(order >= 0) localList[order] = ChartParams.attributes[i].name; + else localList[k] = ChartParams.attributes[i].name; + k++; + } + } + init(); + } + + public void init() + { + GridBagDesigner gb = new GridBagDesigner(this); + + JPanel panel = new JPanel(); + gb.setPosition(0,0); + gb.setInsets(10,10,10,10); + gb.setSpan(1,4); + attributeList = new JList<>(localList); + Border border = new EtchedBorder(EtchedBorder.LOWERED); + panel.setBorder(border); + panel.setBackground(Color.WHITE); + panel.add(attributeList); + gb.addComponent(panel); + + upButton = new JButton(i18n.get("JumpChart.Order.MoveUp")); + gb.setPosition(1,0); + gb.setInsets(10,0,0,10); + gb.setFill(GridBagConstraints.HORIZONTAL); + gb.addComponent(upButton); + + downButton = new JButton(i18n.get("JumpChart.Order.MoveDown")); + gb.setPosition(1,1); + gb.setInsets(10,0,0,10); + gb.setFill(GridBagConstraints.HORIZONTAL); + gb.addComponent(downButton); + + acceptButton = new JButton(i18n.get("JumpChart.Order.Accept")); + gb.setPosition(1,2); + gb.setInsets(10,0,0,10); + gb.setFill(GridBagConstraints.HORIZONTAL); + gb.addComponent(acceptButton); + + cancelButton = new JButton(i18n.get("JumpChart.Order.Cancel")); + gb.setPosition(1,3); + gb.setInsets(10,0,10,10); + gb.setFill(GridBagConstraints.HORIZONTAL); + gb.setAnchor(GridBagConstraints.SOUTH); + gb.addComponent(cancelButton); + + upButton.addActionListener(this); + downButton.addActionListener(this); + acceptButton.addActionListener(this); + cancelButton.addActionListener(this); + + pack(); + setLocation(parent.getLocation()); + setVisible(true); + + } + public void actionPerformed(ActionEvent ev) + { + if(ev.getSource() == upButton) + { + int selectedIndex = attributeList.getSelectedIndex(); + if(selectedIndex < 1) return; + String temp = localList[selectedIndex-1]; + localList[selectedIndex-1] = localList[selectedIndex]; + localList[selectedIndex] = temp; + attributeList.setListData(localList); + attributeList.setSelectedIndex(selectedIndex-1); + + + } + if(ev.getSource() == downButton) + { + int selectedIndex = attributeList.getSelectedIndex(); + if(selectedIndex < 0 || selectedIndex > (localList.length-2)) return; + String temp = localList[selectedIndex+1]; + localList[selectedIndex+1] = localList[selectedIndex]; + localList[selectedIndex] = temp; + attributeList.setListData(localList); + attributeList.setSelectedIndex(selectedIndex+1); + } + if(ev.getSource() == acceptButton) + { + for (int i=0; i < numItems; i++) + { + String item = localList[i]; + for (int j=0; j < ChartParams.attributes.length; j++) + { + if(ChartParams.attributes[j].name.equals(item)) ChartParams.attributeOrder[j] = i; + } + } + dispose(); + } + if(ev.getSource() == cancelButton) + { + dispose(); + } + } + +} diff --git a/src/main/java/com/cadplan/jump_chart/jump/BarChart.java b/src/main/java/com/cadplan/jump_chart/jump/BarChart.java new file mode 100644 index 0000000..c85038e --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/jump/BarChart.java @@ -0,0 +1,334 @@ +/* + * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI + * for visualizing and manipulating spatial features with geometry and attributes. + * + * Copyright (C) 2006 Cadplan + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 com.cadplan.jump_chart.jump; + +import com.vividsolutions.jump.feature.*; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.LinearRing; + + +/** + * User: geoff + * Date: 28/04/2007 + * Time: 16:50:31 + * Copyright 2007 Geoffrey G Roy. + */ +public class BarChart +{ + boolean debug = false; + ChartAttribute [] attributes; + ChartValues [] values; + double screenScale; + double maxValue; + double maxSize; + double xoffs, yoffs; + double originX, originY; + + public BarChart(ChartAttribute[] attributes, ChartValues[] values, double screenScale) + { + this.attributes = attributes; + this.values = values; + this.screenScale = screenScale; + xoffs = ChartParams.originX*screenScale; + yoffs = ChartParams.originY*screenScale; + } + + public double getMaxValue() + { + return maxValue; + } + public double getMaxSize() + { + return maxSize; + } + public void addFeatures(FeatureCollection dataset) + { + + double barHeight; + double barWidth = 5*screenScale; + double height = 60; + double dataMax = Double.MIN_VALUE; + double x, y; + double barHeightRatio; + double maxHeight; + double dx; + + double[] itemMax = new double[values.length]; + + for (int i=0; i < values.length; i++) + { + + double[] data = values[i].values; + itemMax[i] = Double.MIN_VALUE; + + for (int j=0; j < data.length; j++) + { + if(data[j] > dataMax) dataMax = data[j]; + if(data[j] > itemMax[i]) itemMax[i] = data[j]; + } + } + maxValue = dataMax; + + + for(int i=0; i < values.length; i++) + { + double [] data = values[i].values; + String [] ctypes = values[i].types; + String nameValue = values[i].name; + x = values[i].x; + y = values[i].y; + originY = y; + + if(ChartParams.autoScale) + { + maxHeight = height*screenScale; + barWidth = 7*screenScale; + } + else + { + maxHeight = ChartParams.scaleValue*screenScale; + barWidth = ChartParams.barWidth*screenScale; + } + maxSize = maxHeight; + if(ChartParams.uniformSize) + { + if(itemMax[i] != 0.0) barHeightRatio = maxHeight/itemMax[i]; + else barHeightRatio = 1.0; + } + else + { + if(dataMax != 0.0) barHeightRatio = maxHeight/dataMax; + else barHeightRatio = 1.0; + } + if(Double.isInfinite(barHeightRatio)) barHeightRatio = 1.0; + //System.out.println("barHeightRatio="+barHeightRatio); + dx = x - data.length*barWidth/2; + for (int j=0; j < data.length; j++) + { + String name = attributes[j].name; + Feature feature = buildFeature(j, dx, y, barWidth, data[j]*barHeightRatio, data[j], name, ctypes[j]); + dataset.add(feature); + dx = dx + barWidth; + } + + // ------------------------------------------- + // build underlabel feature if required + //-------------------------------------------- + //String nameValue = "Missing"; + if(ChartParams.showUnderLabels) + { + + //System.out.println("Adding feature value namevalue="+nameValue); + Feature feature = buildLabelFeature(x, y, nameValue); + dataset.add(feature); + } + + } + + + + + if(ChartParams.localScale && !ChartParams.uniformSize) + { + for(int i=0; i < values.length; i++) + { + double [] data = values[i].values; + + x = values[i].x; + y = values[i].y; + originX = x + data.length*barWidth/2 + barWidth/2 + xoffs; + originY = y + yoffs; + + double interval = ChartParams.scaleInterval(maxValue); + double scale = maxSize/maxValue; + if(ChartParams.localScale) createLocalScale(dataset,originX, originY, interval, scale, itemMax[i]); + + } + } + + } + + private Feature buildLabelFeature(double x, double y, String name) + { + double xpos, ypos; + double fontHeight = 10.0 * screenScale; + //System.out.println("fontHeight = " + fontHeight); + xpos = x; + ypos = y - fontHeight; + + FeatureSchema featureSchema = new FeatureSchema(); + + featureSchema.addAttribute("Geometry",AttributeType.GEOMETRY); + featureSchema.addAttribute("Index", AttributeType.INTEGER); + featureSchema.addAttribute("dValue", AttributeType.DOUBLE); + featureSchema.addAttribute("iValue", AttributeType.INTEGER); + featureSchema.addAttribute(ChartParams.underLabelName, AttributeType.STRING); + + //System.out.println("Label Feature at:"+x+","+y+" name="+name+ " for attribute: " + ChartParams.underLabelName); + Feature feature = new BasicFeature(featureSchema); + + + Geometry geometry = new GeometryFactory().createPoint(new Coordinate(xpos,ypos)); + feature.setGeometry(geometry); + feature.setAttribute("iValue",-1); + feature.setAttribute("dValue",-1.0); + feature.setAttribute(ChartParams.underLabelName,name); + + + + return feature; + } + + + private Feature buildFeature(int index, double x, double y, double width, double height, double value, String name, String ctype) + { + FeatureSchema featureSchema = new FeatureSchema(); + + featureSchema.addAttribute("Geometry", AttributeType.GEOMETRY); + featureSchema.addAttribute("iValue", AttributeType.INTEGER); + featureSchema.addAttribute("dValue", AttributeType.DOUBLE); + featureSchema.addAttribute("Index", AttributeType.INTEGER); + featureSchema.addAttribute("Name", AttributeType.STRING); + + + if(debug) System.out.println("Feature at:"+x+","+y+" value="+value); + Coordinate p = new Coordinate(x+xoffs,y+yoffs); + Coordinate [] pointArray = new Coordinate[5]; + pointArray[0] = new Coordinate(x+xoffs,y+yoffs); + pointArray[1]= new Coordinate(x+xoffs+width,y+yoffs); + pointArray[2] = new Coordinate(x+xoffs+width,y+yoffs+height); + pointArray[3] = new Coordinate(x+xoffs,y+yoffs+height); + pointArray[4] = new Coordinate(x+xoffs,y+yoffs); + for (int i=0; i < pointArray.length; i++) + { + if(debug) System.out.println("Point "+i+":"+pointArray[i]); + } + + LinearRing lr = new GeometryFactory().createLinearRing(pointArray); + Geometry geometry = new GeometryFactory().createPolygon(lr, null); + + Feature feature = new BasicFeature(featureSchema); + + if(debug) System.out.println("Geometry: "+geometry); + feature.setGeometry(geometry); + + feature.setAttribute("iValue", (int) value); + feature.setAttribute("dValue", value); + feature.setAttribute("Index", index); + + + if(ChartParams.showLabels) feature.setAttribute("Name",name); + else feature.setAttribute("Name",""); + return feature; + } + + private void createLocalScale(FeatureCollection dataset, double x, double y, double interval, double scale, double maxValue) + { + //boolean debug = true; + FeatureSchema featureSchema = new FeatureSchema(); + featureSchema.addAttribute("Geometry", AttributeType.GEOMETRY); + featureSchema.addAttribute("dValue", AttributeType.DOUBLE); + featureSchema.addAttribute("iValue", AttributeType.INTEGER); + featureSchema.addAttribute("Index", AttributeType.INTEGER); + featureSchema.addAttribute("Name", AttributeType.STRING); + + double width = 3*screenScale; + double yp = y+ 5*interval*scale; + + //Coordinate [] points = new Coordinate[2]; + //points[0] = new Coordinate(x,y); + //points[1] = new Coordinate(x,y+ 5*interval*scale); + + //Geometry geometry = new GeometryFactory().createLineString(points); + + //if(debug) System.out.println("Line Geometry: "+geometry); + //Feature feature = new BasicFeature(featureSchema); + + + //feature.setGeometry(geometry); + //feature.setAttribute("iValue",-1); + //feature.setAttribute("dValue",-1.0); + //feature.setAttribute("Name",""); + //dataset.add(feature); + for(int i=1; i <=5 ; i++) + { + Coordinate [] linePoints = new Coordinate[2]; + linePoints[0] = new Coordinate(x,y+interval*scale*i); + linePoints[1] = new Coordinate(x-width, y+interval*scale*i); + + Geometry linegeometry = new GeometryFactory().createLineString(linePoints); + + Feature linefeature = new BasicFeature(featureSchema); + + if(debug) System.out.println("i="+i+" Bar Geometry: "+linegeometry); + linefeature.setGeometry(linegeometry); + linefeature.setAttribute("dValue",-1.0); + linefeature.setAttribute("iValue",-1); + linefeature.setAttribute("Index",-1); + + if(interval*i < maxValue && i < 5) + { + linefeature.setAttribute("Name",""); + dataset.add(linefeature); + } + else + { + linefeature.setAttribute("Name",formatValue(interval,i)); + dataset.add(linefeature); + + Coordinate [] points = new Coordinate[2]; + points[0] = new Coordinate(x,y); + points[1] = new Coordinate(x,y+ i*interval*scale); + Geometry geometry = new GeometryFactory().createLineString(points); + if(debug) System.out.println("Line Geometry: "+geometry); + Feature feature = new BasicFeature(featureSchema); + feature.setGeometry(geometry); + feature.setAttribute("iValue",-1); + feature.setAttribute("dValue",-1.0); + feature.setAttribute("Name",""); + dataset.add(feature); + break; + } + + //if(i < 5) linefeature.setAttribute("Name",""); + //else linefeature.setAttribute("Name",formatValue(interval,i)); + //dataset.add(linefeature); + + + } + + + + } + + private String formatValue(double interval, int step) + { + return NumberFormatter.format(interval*step); + //if(interval < 1.0) return String.valueOf(interval*step); + //return String.valueOf((int)(interval*step)); + } + +} diff --git a/src/main/java/com/cadplan/jump_chart/jump/Chart.java b/src/main/java/com/cadplan/jump_chart/jump/Chart.java new file mode 100644 index 0000000..fc5c84e --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/jump/Chart.java @@ -0,0 +1,559 @@ +/* + * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI + * for visualizing and manipulating spatial features with geometry and attributes. + * + * Copyright (C) 2006 Cadplan + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 com.cadplan.jump_chart.jump; + +import java.awt.Color; +import java.util.HashMap; +import java.util.Map; + +import com.vividsolutions.jump.I18N; +import com.vividsolutions.jump.feature.AttributeType; +import com.vividsolutions.jump.feature.BasicFeature; +import com.vividsolutions.jump.feature.Feature; +import com.vividsolutions.jump.feature.FeatureCollection; +import com.vividsolutions.jump.feature.FeatureDataset; +import com.vividsolutions.jump.feature.FeatureSchema; +import com.vividsolutions.jump.workbench.model.Category; +import com.vividsolutions.jump.workbench.model.Layer; +import com.vividsolutions.jump.workbench.plugin.PlugInContext; +import com.vividsolutions.jump.workbench.ui.renderer.style.BasicStyle; +import com.vividsolutions.jump.workbench.ui.renderer.style.ColorThemingStyle; +import com.vividsolutions.jump.workbench.ui.renderer.style.LabelStyle; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.LinearRing; + +/** + * User: geoff Date: 28/04/2007 Time: 10:04:38 Copyright 2007 Geoffrey G Roy. + */ +public class Chart { + boolean debug = false; + PlugInContext context; + String categoryName = "Jump Charts"; + ChartData chartData; + ChartValues[] chartValues; + ChartAttribute[] chartAttributes; + FeatureDataset dataset; + double screenScale; + I18N i18n; + + public Chart(PlugInContext context, I18N i18n) { + this.context = context; + this.i18n = i18n; + ChartParams.cancelled = false; + chartData = new ChartData(context, i18n); + + if (!ChartParams.cancelled) { + + getData(); + + for (final ChartValues chartValue : chartValues) { + // System.out.println("Att i="+i+ " value="+ + // chartValues[i].toString()); + } + + createContext(); + createFeatures(); + final Layer layer = context + .addLayer(categoryName, "Chart", dataset); + final ColorThemingStyle colorThemingStyle = ColorThemingStyle + .get(layer); + final String actualName = layer.getName(); + final BasicStyle layerStyle = layer.getBasicStyle(); + layerStyle.setAlpha(255); + + final LabelStyle newLabelStyle = layer.getLabelStyle(); + newLabelStyle.setEnabled(true); + newLabelStyle.setAttribute("Name"); + newLabelStyle.setEnabled(true); // to show labels in legends + + newLabelStyle.setVerticalAlignment(LabelStyle.ON_LINE); + + // System.out.println("Vert Align:"+newLabelStyle.verticalAlignment); + layer.removeStyle(layer.getLabelStyle()); + layer.addStyle(newLabelStyle); + + final Map themeMap = new HashMap<>(); + + final Map labelMap = new HashMap<>(); + + final int numElements = chartAttributes.length; + + for (int i = 0; i < numElements; i++) { + final BasicStyle style = new BasicStyle(); + final int alpha = 128; + final Color color = new Color(Color.HSBtoRGB((float) i + / (float) numElements, 1.0f, 1.0f), true); + style.setFillColor(color); + // themeMap.put(i,style); + // labelMap.put(i,String.valueOf(i)); + themeMap.put(i, style); + // [Giuseppe Aruta 2018-04-04] Added Attribute names to layer + // legend + labelMap.put(i, chartAttributes[i].name); + + } + layer.removeStyle(layer.getStyle(ColorThemingStyle.class)); + final BasicStyle basicStyle = new BasicStyle(); + basicStyle.setFillColor(new Color(230, 230, 230)); + basicStyle.setLineColor(Color.BLACK); + colorThemingStyle.setAttributeName("Index"); + colorThemingStyle.setAttributeValueToBasicStyleMap(themeMap); + colorThemingStyle.setAttributeValueToLabelMap(labelMap); + // [Giuseppe Aruta 2018-04-04] Uncomment as it does not work since + // OpenJUMP 1.6 + // ColorThemingStyle themingStyle = new ColorThemingStyle("Index", + // themeMap, labelMap, basicStyle); + colorThemingStyle.setEnabled(true); + layer.addStyle(colorThemingStyle); + + } + } + + private void createContext() { + + if (debug) { + System.out.println("Creating new catagory"); + } + final Category category = new Category(); + category.setName(categoryName); + final FeatureSchema featureSchema = new FeatureSchema(); + if (ChartParams.chartType == ChartParams.LABELS) { + // featureSchema.addAttribute("$FID", AttributeType.INTEGER); + featureSchema.addAttribute("Geometry", AttributeType.GEOMETRY); + // featureSchema.addAttribute("Index", AttributeType.INTEGER); + + featureSchema.addAttribute("Name", AttributeType.STRING); + for (final ChartAttribute chartAttribute : chartAttributes) { + featureSchema.addAttribute(chartAttribute.toString(), + AttributeType.STRING); + } + } else { + featureSchema.addAttribute("Geometry", AttributeType.GEOMETRY); + featureSchema.addAttribute("Index", AttributeType.INTEGER); + featureSchema.addAttribute("iValue", AttributeType.INTEGER); + featureSchema.addAttribute("dValue", AttributeType.DOUBLE); + featureSchema.addAttribute("Name", AttributeType.STRING); + + } + + dataset = new FeatureDataset(featureSchema); + + screenScale = 1.0 / context.getLayerViewPanel().getViewport() + .getScale(); + if (debug) { + System.out.println("Screen scale= " + screenScale); + } + } + + private void getData() { + chartValues = chartData.getValues(); + chartAttributes = chartData.getAttributes(); + } + + private void createFeatures() { + double maxValue = 0.0; + double maxSize = 0.0; + + switch (ChartParams.chartType) { + case ChartParams.PIE_EAST: + PieChart pieChart = new PieChart(chartAttributes, chartValues, + screenScale, 0.0); + pieChart.addFeatures(dataset); + maxValue = pieChart.getMaxValue(); + maxSize = pieChart.getMaxSize(); + break; + case ChartParams.PIE_NORTH: + pieChart = new PieChart(chartAttributes, chartValues, screenScale, + Math.PI / 2.0); + pieChart.addFeatures(dataset); + maxValue = pieChart.getMaxValue(); + maxSize = pieChart.getMaxSize(); + break; + case ChartParams.BAR: + final BarChart barChart = new BarChart(chartAttributes, + chartValues, screenScale); + barChart.addFeatures(dataset); + maxValue = barChart.getMaxValue(); + maxSize = barChart.getMaxSize(); + + break; + case ChartParams.COLUMN: + final ColumnChart columnChart = new ColumnChart(chartAttributes, + chartValues, screenScale); + columnChart.addFeatures(dataset); + maxValue = columnChart.getMaxValue(); + maxSize = columnChart.getMaxSize(); + break; + case ChartParams.LABELS: + final LabelsChart labelsChart = new LabelsChart(chartAttributes, + chartValues, screenScale); + labelsChart.addFeatures(dataset); + + break; + } + if (ChartParams.includeLegend + && ChartParams.chartType != ChartParams.LABELS) { + createLegend(dataset); + } + if (ChartParams.showScale && !ChartParams.uniformSize) { + final double interval = ChartParams.scaleInterval(maxValue); + final double scale = maxSize / maxValue; + if (debug) { + System.out.println("maxValue=" + maxValue + " maxSize=" + + maxSize + " scale=" + scale); + } + createScale(ChartParams.chartType, dataset, interval, scale); + } + } + + private void createScale(int type, FeatureCollection dataset, + double interval, double scale) { + final FeatureSchema featureSchema = new FeatureSchema(); + featureSchema.addAttribute("Geometry", AttributeType.GEOMETRY); + featureSchema.addAttribute("dValue", AttributeType.DOUBLE); + featureSchema.addAttribute("iValue", AttributeType.INTEGER); + featureSchema.addAttribute("Index", AttributeType.INTEGER); + featureSchema.addAttribute("Name", AttributeType.STRING); + + final double x0 = context.getLayerViewPanel().getViewport() + .getEnvelopeInModelCoordinates().getMinX(); + final double y0 = context.getLayerViewPanel().getViewport() + .getEnvelopeInModelCoordinates().getMinY(); + + final double w = 100 * screenScale; + final double h = 15 * screenScale; + final double s = 5 * screenScale; + final double x = x0 + 100 * screenScale * 2; + final double y = y0; + + switch (type) { + case ChartParams.PIE_EAST: + case ChartParams.PIE_NORTH: + double rad = 5 * scale * interval; + final double radMax = ChartParams.maxValue * scale; + // System.out.println("Chart: maxValue="+ChartParams.maxValue+" radMax="+radMax+" rad="+rad); + double rada = rad; + + final int nsides = 32; + for (int i = 4; i >= 0; i--) { + rada = rad; + if (!ChartParams.linearScale) { + rada = radMax * Math.sqrt(rad / radMax); + } + if (debug) { + System.out.println("rada=" + rada); + } + final Coordinate[] circlePoints = new Coordinate[nsides + 1]; + for (int k = 0; k < 32; k++) { + final double xp = x + rada + * Math.cos(k * 2.0 * Math.PI / nsides); + final double yp = y + rada + rada + * Math.sin(k * 2.0 * Math.PI / nsides); + + circlePoints[k] = new Coordinate(xp, yp); + } + circlePoints[nsides] = circlePoints[0]; + // Geometry geometry = new + // GeometryFactory().createLineString(circlePoints); + final LinearRing lr = new GeometryFactory() + .createLinearRing(circlePoints); + final Geometry geometry = new GeometryFactory().createPolygon( + lr, null); + if (debug) { + System.out.println("Geometry: " + geometry); + } + final Feature feature = new BasicFeature(featureSchema); + + if (debug) { + System.out.println("Geometry: " + geometry); + } + feature.setGeometry(geometry); + feature.setAttribute("dValue", 0.0); + feature.setAttribute("iValue", 0); + feature.setAttribute("Index", -1); + feature.setAttribute("Name", ""); + dataset.add(feature); + + final Coordinate[] linePoints = new Coordinate[2]; + linePoints[0] = new Coordinate(x, y + rada * 2.0); + linePoints[1] = new Coordinate(x + scale * 5.2 * interval, y + + rada * 2.0); + + final Geometry linegeometry = new GeometryFactory() + .createLineString(linePoints); + + if (debug) { + System.out.println("Geometry: " + geometry); + } + final Feature linefeature = new BasicFeature(featureSchema); + + if (debug) { + System.out.println("Geometry: " + linegeometry); + } + linefeature.setGeometry(linegeometry); + linefeature.setAttribute("dValue", -1.0); + linefeature.setAttribute("iValue", -1); + linefeature.setAttribute("Index", -1); + linefeature.setAttribute("Name", ""); + dataset.add(linefeature); + + // Coordinate [] pointPoints = new Coordinate[1]; + // pointPoints[0] = new Coordinate(x+scale*8.0*interval, + // y+rad*2.0); + // Geometry pointgeometry = new + // GeometryFactory().createMultiPoint(pointPoints); + + final Coordinate[] pointPoints = new Coordinate[2]; + pointPoints[0] = new Coordinate(x + scale * 5.2 * interval, y + + rada * 2.0); + pointPoints[1] = new Coordinate(x + scale * 8.0 * interval, y + + rada * 2.0); + // Geometry pointgeometry = new + // GeometryFactory().createLineString(pointPoints); + final Coordinate position = new Coordinate(x + scale * 6.2 + * interval, y + rada * 2.0); + final Geometry pointgeometry = new GeometryFactory() + .createPoint(position); + + if (debug) { + System.out.println("Geometry: " + geometry); + } + final Feature pointfeature = new BasicFeature(featureSchema); + + if (debug) { + System.out.println("Geometry: " + pointgeometry); + } + pointfeature.setGeometry(pointgeometry); + pointfeature.setAttribute("dValue", -1.0); + pointfeature.setAttribute("iValue", -1); + pointfeature.setAttribute("Index", -1); + pointfeature.setAttribute("Name", format(interval * (i + 1))); + dataset.add(pointfeature); + + rad = rad - interval * scale; + } + + break; + case ChartParams.BAR: + case ChartParams.COLUMN: + final double width = 10 * screenScale; + double yp = y + 5 * interval * scale; + for (int i = 4; i >= 0; i--) { + final Coordinate[] points = new Coordinate[5]; + points[0] = new Coordinate(x, yp); + points[1] = new Coordinate(x + width, yp); + points[2] = new Coordinate(x + width, yp + interval * scale); + points[3] = new Coordinate(x, yp + interval * scale); + points[4] = points[0]; + // Geometry geometry = new + // GeometryFactory().createLineString(points); + final LinearRing lr = new GeometryFactory() + .createLinearRing(points); + final Geometry geometry = new GeometryFactory().createPolygon( + lr, null); + + if (debug) { + System.out.println("Geometry: " + geometry); + } + final Feature feature = new BasicFeature(featureSchema); + + if (debug) { + System.out.println("Geometry: " + geometry); + } + feature.setGeometry(geometry); + feature.setAttribute("iValue", -1); + feature.setAttribute("dValue", -1.0); + feature.setAttribute("Name", ""); + dataset.add(feature); + + final Coordinate[] linePoints = new Coordinate[2]; + linePoints[0] = new Coordinate(x + width, yp + interval * scale); + linePoints[1] = new Coordinate(x + 2.0 * width, yp + interval + * scale); + + final Geometry linegeometry = new GeometryFactory() + .createLineString(linePoints); + if (debug) { + System.out.println("Geometry: " + geometry); + } + final Feature linefeature = new BasicFeature(featureSchema); + + if (debug) { + System.out.println("Geometry: " + linegeometry); + } + linefeature.setGeometry(linegeometry); + linefeature.setAttribute("dValue", -1.0); + linefeature.setAttribute("iValue", -1); + linefeature.setAttribute("Index", -1); + linefeature.setAttribute("Name", ""); + dataset.add(linefeature); + + // Coordinate [] pointPoints = new Coordinate[1]; + // pointPoints[0] = new Coordinate(x+4*width, + // yp+interval*scale); + // Geometry pointgeometry = new + // GeometryFactory().createMultiPoint(pointPoints); + + final Coordinate[] pointPoints = new Coordinate[2]; + pointPoints[0] = new Coordinate(x + 2.0 * width, yp + interval + * scale); + pointPoints[1] = new Coordinate(x + 6.0 * width, yp + interval + * scale); + final Geometry pointgeometry = new GeometryFactory() + .createLineString(pointPoints); + + if (debug) { + System.out.println("Geometry: " + geometry); + } + final Feature pointfeature = new BasicFeature(featureSchema); + + if (debug) { + System.out.println("Geometry: " + pointgeometry); + } + pointfeature.setGeometry(pointgeometry); + pointfeature.setAttribute("dValue", -1.0); + pointfeature.setAttribute("iValue", -1); + pointfeature.setAttribute("Index", 1); + pointfeature.setAttribute("Name", format(interval * (i + 1))); + + dataset.add(pointfeature); + + yp = yp - interval * scale; + } + + break; + } + + } + + private void createLegend(FeatureCollection dataset) { + final FeatureSchema featureSchema = new FeatureSchema(); + featureSchema.addAttribute("Geometry", AttributeType.GEOMETRY); + featureSchema.addAttribute("dValue", AttributeType.DOUBLE); + featureSchema.addAttribute("iValue", AttributeType.INTEGER); + featureSchema.addAttribute("Index", AttributeType.INTEGER); + featureSchema.addAttribute("Name", AttributeType.STRING); + + final double x0 = context.getLayerViewPanel().getViewport() + .getEnvelopeInModelCoordinates().getMinX(); + final double y0 = context.getLayerViewPanel().getViewport() + .getEnvelopeInModelCoordinates().getMinY(); + + double w = 100 * screenScale; + final double h = 15 * screenScale; + final double s = 5 * screenScale; + double x = x0 + h; + double y = y0 + h; + for (int i = chartAttributes.length - 1; i >= 0; i--) { + final Coordinate[] pointArray = new Coordinate[5]; + pointArray[0] = new Coordinate(x, y); + pointArray[1] = new Coordinate(x + w, y); + pointArray[2] = new Coordinate(x + w, y + h); + pointArray[3] = new Coordinate(x, y + h); + pointArray[4] = new Coordinate(x, y); + //for (final Coordinate element : pointArray) { + // System.out.println("Point "+j+":"+pointArray[j]); + //} + + final LinearRing lr = new GeometryFactory() + .createLinearRing(pointArray); + final Geometry geometry = new GeometryFactory().createPolygon(lr, + null); + + final Feature feature = new BasicFeature(featureSchema); + + if (debug) { + System.out.println("Geometry: " + geometry); + } + feature.setGeometry(geometry); + feature.setAttribute("dValue", -1.0); + feature.setAttribute("iValue", -1); + feature.setAttribute("Index", i); + feature.setAttribute("Name", chartAttributes[i].name); + dataset.add(feature); + y = y + h + s; + + } + x = x0 - 5 * screenScale + h; + y = y0 - 5 * screenScale + h; + w = w + 10 * screenScale; + double th = 0; + for (final ChartAttribute chartAttribute : chartAttributes) { + th = th + h + s; + } + th = th - s + 10 * screenScale; + final Coordinate[] borderArray = new Coordinate[5]; + borderArray[0] = new Coordinate(x, y); + borderArray[1] = new Coordinate(x + w, y); + borderArray[2] = new Coordinate(x + w, y + th); + borderArray[3] = new Coordinate(x, y + th); + borderArray[4] = new Coordinate(x, y); + + final Geometry geometry = new GeometryFactory() + .createLineString(borderArray); + final Feature feature = new BasicFeature(featureSchema); + feature.setGeometry(geometry); + + feature.setAttribute("Name", ""); + feature.setAttribute("dValue", 0.0); + feature.setAttribute("iValue", 0); + feature.setAttribute("Index", 0); + final LabelStyle labelStyle = new LabelStyle(); + + dataset.add(feature); + + if (!ChartParams.uniformSize) { + final Coordinate[] labelArray = new Coordinate[5]; + labelArray[0] = new Coordinate(x, y + th); + labelArray[1] = new Coordinate(x + w, y + th); + labelArray[2] = new Coordinate(x + w, y + th + h); + labelArray[3] = new Coordinate(x, y + th + h); + labelArray[4] = new Coordinate(x, y + th); + + final LinearRing lr = new GeometryFactory() + .createLinearRing(labelArray); + final Geometry labelGeometry = new GeometryFactory().createPolygon( + lr, null); + + // Geometry labelGeometry = new + // GeometryFactory().createLineString(labelArray); + // System.out.println("labelGeom: "+labelGeometry.toString()); + final Feature labelFeature = new BasicFeature(featureSchema); + labelFeature.setGeometry(labelGeometry); + labelFeature.setAttribute("Name", + i18n.get("JumpChart.Legend.ChartType")); + labelFeature.setAttribute("dValue", -1.0); + labelFeature.setAttribute("iValue", -1); + labelFeature.setAttribute("Index", -1); + dataset.add(labelFeature); + } + + } + + private String format(double val) { + return NumberFormatter.format(val); + } + +} diff --git a/src/main/java/com/cadplan/jump_chart/jump/ChartAttribute.java b/src/main/java/com/cadplan/jump_chart/jump/ChartAttribute.java new file mode 100644 index 0000000..af88578 --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/jump/ChartAttribute.java @@ -0,0 +1,49 @@ +/* + * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI + * for visualizing and manipulating spatial features with geometry and attributes. + * + * Copyright (C) 2006 Cadplan + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 com.cadplan.jump_chart.jump; + +/** + * User: geoff + * Date: 28/04/2007 + * Time: 10:53:49 + * Copyright 2007 Geoffrey G Roy. + */ +public class ChartAttribute +{ + public int index; + public String name; + + + public ChartAttribute(int index, String name) + { + this.index = index; + this.name = name; + + } + + + public String toString() + { + return "["+index+"]"+name; + } +} diff --git a/src/main/java/com/cadplan/jump_chart/jump/ChartData.java b/src/main/java/com/cadplan/jump_chart/jump/ChartData.java new file mode 100644 index 0000000..c5bbb8c --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/jump/ChartData.java @@ -0,0 +1,219 @@ +/* + * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI + * for visualizing and manipulating spatial features with geometry and attributes. + * + * Copyright (C) 2006 Cadplan + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 com.cadplan.jump_chart.jump; + +import com.vividsolutions.jump.I18N; +import com.vividsolutions.jump.workbench.plugin.PlugInContext; +import com.vividsolutions.jump.workbench.model.Layer; +import com.vividsolutions.jump.feature.FeatureSchema; +import com.vividsolutions.jump.feature.AttributeType; +import com.vividsolutions.jump.feature.Feature; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.Point; + +import javax.swing.*; +import java.util.Vector; +import java.util.List; +import java.util.Iterator; +import java.text.*; + +/** + * User: geoff + * Date: 28/04/2007 + * Time: 10:27:06 + * Copyright 2007 Geoffrey G Roy. + */ +public class ChartData { + + boolean debug = false; + Layer selectedLayer; + FeatureSchema featureSchema; + Vector attributes; + ChartValues[] chartData; + + Vector possibleNames = new Vector<>(); + String chosenName = ""; + DecimalFormat iformat = new DecimalFormat("#####"); + + + public ChartData(PlugInContext context, I18N i18n) { + ChartDialog chartDialog; + selectedLayer = context.getSelectedLayer(0); + if (selectedLayer != null) { + featureSchema = selectedLayer.getFeatureCollectionWrapper().getFeatureSchema(); + + do { + //System.out.println("Preparing data - ChartType = "+ ChartParams.chartType); + attributes = new Vector<>(10, 2); + for (int i = 0; i < featureSchema.getAttributeCount(); i++) { + AttributeType type = featureSchema.getAttributeType(i); + if (type == AttributeType.DOUBLE || type == AttributeType.INTEGER || // type == AttributeType.STRING || + ((ChartParams.chartType == ChartParams.LABELS) && type == AttributeType.STRING)) { + String name = featureSchema.getAttributeName(i); + + ChartAttribute att = new ChartAttribute(i, name); + attributes.addElement(att); + //System.out.println("Attribute added: "+name); + } + } + + + chartDialog = new ChartDialog(selectedLayer.getName(), attributes, i18n); + //System.out.println("Reload = "+ ChartParams.reloadDialog); + if (ChartParams.reloadDialog) chartDialog = null; + + } while (ChartParams.reloadDialog); + + if (!ChartParams.cancelled) { + attributes = chartDialog.getSelections(); + if (debug) System.out.println("Number of selected att: " + attributes.size()); + + // if attribute "Name" is not present choose required name label. + if (ChartParams.chartType == ChartParams.LABELS || ChartParams.showUnderLabels) { + boolean nameFound = false; + for (int i = 0; i < featureSchema.getAttributeCount(); i++) { + AttributeType type = featureSchema.getAttributeType(i); + if (type == AttributeType.STRING) { + String name = featureSchema.getAttributeName(i); + possibleNames.addElement(name); + //System.out.println("Possible Name added: "+name); + if (name.equals("Name")) nameFound = true; + } + } + String[] pNames = new String[possibleNames.size()]; + + for (int i = 0; i < possibleNames.size(); i++) { + pNames[i] = possibleNames.elementAt(i); + } + + if (!nameFound && pNames.length > 0) { + String result = (String) JOptionPane.showInputDialog(null, + i18n.get("JumpChart.message5"), i18n.get("JumpChart.message6"), + JOptionPane.QUESTION_MESSAGE, null, pNames, pNames[0]); + + if (result != null) chosenName = result; + else chosenName = null; + + } else { + chosenName = "Missing"; + } + } + + List featureList = selectedLayer.getFeatureCollectionWrapper().getFeatures(); + + + int numFeatures = featureList.size(); + chartData = new ChartValues[numFeatures]; + + Iterator j = featureList.iterator(); + int count = 0; + while (j.hasNext()) { + Feature feature = j.next(); + int ID = feature.getID(); + String name; + String underName = "Missing"; + String ctype = "INT"; + + try { + name = (String) feature.getAttribute("Name"); + + } catch (Exception ex) { + if (ChartParams.chartType == ChartParams.LABELS && chosenName != null) + name = (String) feature.getAttribute(chosenName); + else name = ""; + + if (ChartParams.showUnderLabels && chosenName != null) name = (String) feature.getAttribute(chosenName); + //System.out.println("ERROR: Attribute Name not found - inserted: "+name); + } + + + Geometry geometry = feature.getGeometry(); + Point centroid = geometry.getInteriorPoint(); + double[] values = new double[attributes.size()]; + String[] nameValues = new String[attributes.size()]; + String[] chartTypes = new String[numFeatures]; + for (int k = 0; k < attributes.size(); k++) { + int index = attributes.elementAt(k).index; + double value = -1.0; + String vtype = "UND"; + String nameValue; + try { + value = feature.getDouble(index); + nameValue = String.valueOf(value); + //System.out.println("Decoding Double: "+value+ " to "+nameValue); + vtype = "DBL"; + } catch (ClassCastException ex) { + try { + value = feature.getInteger(index); + nameValue = String.valueOf(iformat.format(value)); + vtype = "INT"; + + //System.out.println("Decoding Integer: "+value+ " to "+nameValue); + } catch (ClassCastException ex2) { + value = -1.0; + nameValue = feature.getString(index); + vtype = "STR"; + //System.out.println("Decoding String: "+value+ " to "+nameValue); + } + + } catch (Exception ex) { + + value = -1.0; + nameValue = String.valueOf(value); + vtype = "UND"; + //System.out.println("Fail: decode as string: "+nameValue+" value:"+value); + } + values[k] = value; + nameValues[k] = nameValue; + chartTypes[k] = vtype; + + } + + + ChartValues chartValues = new ChartValues(ID, name, centroid.getX(), centroid.getY(), values, nameValues, chartTypes); + chartData[count] = chartValues; + //System.out.println("Values: "+chartData[count].toString()); + count++; + } + } + + + } else { + ChartParams.cancelled = true; + JOptionPane.showMessageDialog(null, + i18n.get("JumpChart.message1"), "Warning...", JOptionPane.WARNING_MESSAGE); + } + } + + public ChartValues[] getValues() { + return chartData; + } + + public ChartAttribute[] getAttributes() { + ChartAttribute[] attributeData = new ChartAttribute[attributes.size()]; + for (int i = 0; i < attributes.size(); i++) { + attributeData[i] = attributes.elementAt(i); + } + return attributeData; + } +} diff --git a/src/main/java/com/cadplan/jump_chart/jump/ChartDialog.java b/src/main/java/com/cadplan/jump_chart/jump/ChartDialog.java new file mode 100644 index 0000000..fb145d5 --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/jump/ChartDialog.java @@ -0,0 +1,657 @@ +/* + * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI + * for visualizing and manipulating spatial features with geometry and attributes. + * + * Copyright (C) 2006 Cadplan + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 com.cadplan.jump_chart.jump; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.Arrays; +import java.util.Vector; + +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JScrollBar; +import javax.swing.JScrollPane; +import javax.swing.JTextField; + +import com.cadplan.jump_chart.designer.GridBagDesigner; +import com.vividsolutions.jump.I18N; +import com.vividsolutions.jump.workbench.ui.GUIUtil; +import com.vividsolutions.jump.workbench.ui.OKCancelApplyPanel; + +/** + * User: geoff Date: 29/04/2007 Time: 08:26:10 Copyright 2007 Geoffrey G Roy. + */ +public class ChartDialog extends JDialog implements ActionListener, + ItemListener { + + private static final long serialVersionUID = 1L; + private static final I18N i18n = JumpChartPlugIn.I18N; + boolean debug = false; + JLabel nameLabel, attributeLabel, typeLabel, sizeLabel, scaleLabel, + widthLabel, originLabel, underLabel; + JTextField nameField, scaleField, widthField, xorigField, yorigField; + JComboBox typeCombo, underLabelCombo; + JCheckBox legendCB, orderCB, clockwiseCB, showScaleCB, showLabelsCB, + showLocalScaleCB, linearCB, underLabelCB; + JRadioButton uniformRB, variableRB, autoRB, fixedRB; + JButton cancelButton, aboutButton, acceptButton, setAllButton, + clearAllButton, orderButton; + String[] typeNames = ChartParams.typeNames; + JPanel attributePanel; + JCheckBox[] selectAttribute; + Vector orderedAttributes; + ButtonGroup sizeGroup, scaleGroup; + Vector attributes; + GridBagDesigner gb; + int currentType = ChartParams.chartType; + String[] underLabelOptions; + JPanel mainPanel = new JPanel(); + OKCancelApplyPanel okPanel = new OKCancelApplyPanel(); + + public ChartDialog(String layerName, Vector attributes, + I18N i18n) { + super(new JFrame(), "Chart Dialog", true); + + setIconImage(GUIUtil.resize(JumpChartPlugIn.ICON, 12).getImage()); + + this.attributes = attributes; + ChartParams.reloadDialog = false; + + // System.out.println("Creating ChartDialog" + " Attributes size=" + + // attributes.size()); + + ChartParams.attributes = new ChartAttribute[attributes.size()]; + final boolean[] oldInclude = ChartParams.includeAttribute; + ChartParams.includeAttribute = new boolean[attributes.size()]; + for (int i = 0; i < attributes.size(); i++) { + ChartParams.includeAttribute[i] = false; + } + final int[] oldAttributeOrder = ChartParams.attributeOrder; + ChartParams.attributeOrder = new int[attributes.size()]; + underLabelOptions = new String[attributes.size()]; + for (int i = 0; i < attributes.size(); i++) { + + ChartParams.attributes[i] = attributes.elementAt(i); + ChartParams.attributeOrder[i] = -1; + underLabelOptions[i] = ChartParams.attributes[i].name; + // System.out.println("layerName="+layerName+" from Params: :"+ChartParams.layerName); + if (ChartParams.layerName != null + && layerName.equals(ChartParams.layerName)) { + try { + ChartParams.includeAttribute[i] = oldInclude[i]; + ChartParams.attributeOrder[i] = oldAttributeOrder[i]; + } catch (final Exception ex) { + + } + } else { + ChartParams.includeAttribute[i] = false; + } + } + ChartParams.layerName = layerName; + // System.out.println("Setting layer name: "+layerName+" No of attr.="+ChartParams.attributes.length); + // [Giuseppe Aruta 2018-04-04] workaround to close in a proper way the + // dialog + // + setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent windowEvent) { + ChartParams.cancelled = true; + ChartParams.chartType = typeCombo.getSelectedIndex(); + dispose(); + } + }); + init(); + } + + public void init() { + mainPanel = new JPanel(new GridBagLayout()); + gb = new GridBagDesigner(mainPanel); + nameLabel = new JLabel(i18n.get("JumpChart.Dialog.SelectedLayer")); + gb.setPosition(0, 0); + gb.setInsets(10, 10, 0, 5); + gb.addComponent(nameLabel); + + nameField = new JTextField(ChartParams.layerName); + nameField.setEditable(false); + gb.setPosition(1, 0); + gb.setInsets(10, 0, 0, 10); + gb.setSpan(3, 1); + gb.setFill(GridBagConstraints.HORIZONTAL); + gb.addComponent(nameField); + + attributeLabel = new JLabel(i18n.get("JumpChart.Dialog.Attributes")); + gb.setPosition(0, 1); + gb.setInsets(5, 10, 0, 5); + gb.addComponent(attributeLabel); + + setAllButton = new JButton(i18n.get("JumpChart.Dialog.SelectAll")); + gb.setPosition(0, 2); + gb.setInsets(5, 10, 0, 5); + gb.setFill(GridBagConstraints.HORIZONTAL); + gb.addComponent(setAllButton); + setAllButton.addActionListener(this); + + clearAllButton = new JButton(i18n.get("JumpChart.Dialog.ClearAll")); + gb.setPosition(0, 3); + gb.setInsets(5, 10, 0, 5); + gb.setFill(GridBagConstraints.HORIZONTAL); + gb.addComponent(clearAllButton); + clearAllButton.addActionListener(this); + + orderButton = new JButton(i18n.get("JumpChart.Dialog.Order")); + gb.setPosition(0, 4); + gb.setInsets(5, 10, 0, 5); + gb.setFill(GridBagConstraints.HORIZONTAL); + gb.addComponent(orderButton); + orderButton.addActionListener(this); + + createSelectPanel(); + addAttributePanel(); + + typeLabel = new JLabel(i18n.get("JumpChart.Dialog.ChartType")); + gb.setPosition(0, 6); + gb.setInsets(5, 10, 0, 5); + gb.addComponent(typeLabel); + + typeCombo = new JComboBox(typeNames); + gb.setPosition(1, 6); + gb.setInsets(5, 0, 0, 10); + gb.addComponent(typeCombo); + typeCombo.setSelectedIndex(ChartParams.chartType); + typeCombo.addActionListener(this); + + clockwiseCB = new JCheckBox(i18n.get("JumpChart.Dialog.Clockwise")); + gb.setPosition(2, 6); + gb.setInsets(5, 0, 0, 5); + gb.addComponent(clockwiseCB); + clockwiseCB.setSelected(ChartParams.clockwise); + + legendCB = new JCheckBox(i18n.get("JumpChart.Dialog.Legend")); + gb.setPosition(3, 6); + gb.setInsets(5, 0, 0, 5); + gb.setAnchor(GridBagConstraints.WEST); + gb.addComponent(legendCB); + legendCB.setSelected(ChartParams.includeLegend); + + // orderCB = new JCheckBox("Order"); + // gb.setPosition(3,6); + // gb.setInsets(5,0,0,10); + // gb.addComponent(orderCB); + // orderCB.setSelected(ChartParams.ordered); + + sizeLabel = new JLabel(i18n.get("JumpChart.Dialog.Size")); + gb.setPosition(0, 7); + gb.setInsets(5, 10, 0, 5); + gb.addComponent(sizeLabel); + + uniformRB = new JRadioButton(i18n.get("JumpChart.Dialog.Uniform")); + gb.setPosition(1, 7); + gb.setInsets(5, 0, 0, 0); + gb.setAnchor(GridBagConstraints.WEST); + gb.addComponent(uniformRB); + + variableRB = new JRadioButton(i18n.get("JumpChart.Dialog.Variable")); + gb.setPosition(2, 7); + gb.setInsets(5, 0, 0, 0); + gb.setAnchor(GridBagConstraints.WEST); + gb.addComponent(variableRB); + + linearCB = new JCheckBox(i18n.get("JumpChart.Dialog.Linear")); + gb.setPosition(3, 7); + gb.setInsets(5, 0, 0, 10); + gb.setAnchor(GridBagConstraints.WEST); + gb.addComponent(linearCB); + linearCB.setSelected(ChartParams.linearScale); + + sizeGroup = new ButtonGroup(); + sizeGroup.add(uniformRB); + sizeGroup.add(variableRB); + uniformRB.setSelected(ChartParams.uniformSize); + variableRB.setSelected(!ChartParams.uniformSize); + + scaleLabel = new JLabel(i18n.get("JumpChart.Dialog.Scale")); + gb.setPosition(0, 8); + gb.setInsets(5, 10, 0, 5); + gb.addComponent(scaleLabel); + + autoRB = new JRadioButton(i18n.get("JumpChart.Dialog.Auto")); + gb.setPosition(1, 8); + gb.setInsets(5, 0, 0, 0); + gb.setAnchor(GridBagConstraints.WEST); + gb.addComponent(autoRB); + + fixedRB = new JRadioButton(i18n.get("JumpChart.Dialog.Fixed")); + gb.setPosition(2, 8); + gb.setInsets(5, 0, 0, 0); + gb.setAnchor(GridBagConstraints.WEST); + gb.addComponent(fixedRB); + + scaleGroup = new ButtonGroup(); + scaleGroup.add(fixedRB); + scaleGroup.add(autoRB); + autoRB.setSelected(ChartParams.autoScale); + fixedRB.setSelected(!ChartParams.autoScale); + + scaleField = new JTextField(8); + scaleField.setText(String.valueOf(ChartParams.scaleValue)); + gb.setPosition(3, 8); + gb.setInsets(5, 10, 0, 10); + gb.addComponent(scaleField); + + showScaleCB = new JCheckBox(i18n.get("JumpChart.Dialog.ShowScale")); + gb.setPosition(1, 9); + gb.setInsets(5, 0, 0, 0); + gb.setAnchor(GridBagConstraints.WEST); + gb.addComponent(showScaleCB); + showScaleCB.setSelected(ChartParams.showScale); + + showLocalScaleCB = new JCheckBox( + i18n.get("JumpChart.Dialog.LocalScale")); + gb.setPosition(2, 9); + gb.setInsets(5, 0, 0, 0); + gb.setAnchor(GridBagConstraints.WEST); + gb.addComponent(showLocalScaleCB); + showLocalScaleCB.setSelected(ChartParams.localScale); + + showLabelsCB = new JCheckBox(i18n.get("JumpChart.Dialog.ShowLabels")); + gb.setPosition(1, 10); + gb.setInsets(5, 0, 0, 10); + gb.addComponent(showLabelsCB); + showLabelsCB.setSelected(ChartParams.showLabels); + + widthLabel = new JLabel(i18n.get("JumpChart.Dialog.Width")); + gb.setPosition(2, 10); + gb.setInsets(5, 10, 0, 5); + gb.setAnchor(GridBagConstraints.EAST); + gb.addComponent(widthLabel); + + widthField = new JTextField(8); + widthField.setText(String.valueOf(ChartParams.barWidth)); + gb.setPosition(3, 10); + gb.setInsets(5, 10, 0, 10); + gb.addComponent(widthField); + + originLabel = new JLabel(i18n.get("JumpChart.Dialog.Offsets")); + gb.setPosition(0, 11); + gb.setInsets(5, 10, 0, 5); + gb.setSpan(3, 1); + gb.setAnchor(GridBagConstraints.WEST); + gb.addComponent(originLabel); + + final JLabel xLabel = new JLabel("X"); + gb.setPosition(0, 12); + gb.setInsets(5, 10, 0, 5); + gb.setAnchor(GridBagConstraints.EAST); + gb.addComponent(xLabel); + + xorigField = new JTextField(8); + gb.setPosition(1, 12); + gb.addComponent(xorigField); + xorigField.setText(String.valueOf(ChartParams.originX)); + + final JLabel yLabel = new JLabel("Y"); + gb.setPosition(2, 12); + gb.setInsets(5, 10, 0, 5); + gb.setAnchor(GridBagConstraints.EAST); + gb.addComponent(yLabel); + + yorigField = new JTextField(8); + gb.setPosition(3, 12); + gb.addComponent(yorigField); + yorigField.setText(String.valueOf(ChartParams.originY)); + + underLabel = new JLabel(i18n.get("JumpChart.Dialog.UnderLabels")); + gb.setPosition(0, 13); + gb.setInsets(5, 10, 0, 5); + // gb.setAnchor(GridBagConstraints.EAST); + gb.addComponent(underLabel); + + underLabelCB = new JCheckBox(""); + gb.setPosition(1, 13); + gb.setInsets(5, 10, 0, 5); + gb.setAnchor(GridBagConstraints.WEST); + gb.addComponent(underLabelCB); + underLabelCB.setSelected(ChartParams.showUnderLabels); + + // underLabelCombo= new JComboBox(underLabelOptions); + // gb.setPosition(2,13); + // gb.setInsets(5, 10, 0, 5); + // gb.setFill(GridBagConstraints.HORIZONTAL); + // gb.setSpan(2,1); + // gb.addComponent(underLabelCombo); + // underLabelCombo.setSelectedIndex(ChartParams.underLabelIndex); + + // cancelButton = new JButton(iPlug.get("JumpChart.Dialog.Cancel")); + // gb.setPosition(3, 14); + // gb.setInsets(20, 10, 10, 0); + // gb.addComponent(cancelButton); + // cancelButton.addActionListener(this); + + aboutButton = new JButton(i18n.get("JumpChart.Dialog.About")); + gb.setPosition(3, 13); + gb.setInsets(20, 10, 10, 0); + gb.addComponent(aboutButton); + aboutButton.addActionListener(this); + + // acceptButton = new JButton(iPlug.get("JumpChart.Dialog.Accept")); + // gb.setPosition(2, 14); + // gb.setInsets(20, 10, 10, 10); + // gb.addComponent(acceptButton); + // acceptButton.addActionListener(this); + + okPanel.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (okPanel.wasOKPressed()) { + okAction(e); + } else { + closeAction(e); + } + } + }); + add(mainPanel, BorderLayout.NORTH); + add(okPanel, BorderLayout.SOUTH); + pack(); + setLocation(100, 100); + setVisible(true); + + } + + private void createSelectPanel() { + attributePanel = new JPanel(); + final GridBagDesigner gba = new GridBagDesigner(attributePanel); + selectAttribute = new JCheckBox[ChartParams.attributes.length]; + for (int i = 0; i < ChartParams.attributes.length; i++) { + if (debug) { + System.out.println("Adding Attr: " + ChartParams.attributes[i]); + } + selectAttribute[i] = new JCheckBox(ChartParams.attributes[i].name); + gba.setPosition(0, i); + gba.setInsets(0, 10, 0, 10); + gba.setFill(GridBagConstraints.HORIZONTAL); + gba.setAnchor(GridBagConstraints.WEST); + gba.setWeight(1.0, 0.0); + gba.addComponent(selectAttribute[i]); + selectAttribute[i].setSelected(ChartParams.includeAttribute[i]); + selectAttribute[i].addItemListener(this); + + } + } + + private void addAttributePanel() { + final JScrollPane scrollPane = new JScrollPane(attributePanel); + scrollPane.setPreferredSize(new Dimension(0, 120)); + gb.setPosition(1, 1); + gb.setInsets(5, 0, 0, 10); + gb.setSpan(3, 5); + gb.setWeight(1.0, 1.0); + gb.setFill(GridBagConstraints.BOTH); + gb.addComponent(scrollPane); + final JScrollBar vsb = scrollPane.getVerticalScrollBar(); + vsb.setUnitIncrement(20); + } + + public Vector getSelections() { + return attributes; + } + + private void clearOrder() { + Arrays.fill(ChartParams.attributeOrder, -1); + } + + @Override + public void itemStateChanged(ItemEvent ev) { + for (int i = 0; i < ChartParams.attributes.length; i++) { + if (ev.getSource() == selectAttribute[i]) { + ChartParams.includeAttribute[i] = selectAttribute[i] + .isSelected(); + } + // System.out.println("i="+i+" selected:"+ChartParams.includeAttribute[i]); + } + clearOrder(); + } + + public void closeAction(ActionEvent ev) { + ChartParams.cancelled = true; + ChartParams.chartType = typeCombo.getSelectedIndex(); + dispose(); + } + + public void okAction(ActionEvent ev) { + attributes = new Vector<>(10, 2); + int numSelected = 0; + for (int i = 0; i < selectAttribute.length; i++) { + if (ChartParams.includeAttribute[i]) { + numSelected++; + } + } + final ChartAttribute[] tempAttributes = new ChartAttribute[numSelected]; + int k = 0; + for (int i = 0; i < selectAttribute.length; i++) { + ChartParams.includeAttribute[i] = selectAttribute[i].isSelected(); + // if(ChartParams.includeAttribute[i]) + // attributes.addElement(ChartParams.attributes[i]); + final int order = ChartParams.attributeOrder[i]; + if (ChartParams.includeAttribute[i]) { + if (order >= 0) { + tempAttributes[order] = ChartParams.attributes[i]; + } else { + tempAttributes[k++] = ChartParams.attributes[i]; + } + } + } + for (int i = 0; i < numSelected; i++) { + attributes.addElement(tempAttributes[i]); + } + if (attributes.size() <= 0) { + JOptionPane.showMessageDialog(this, + i18n.get("JumpChart.message3"), "Error...", + JOptionPane.ERROR_MESSAGE); + return; + } + + ChartParams.autoScale = autoRB.isSelected(); + ChartParams.uniformSize = uniformRB.isSelected(); + try { + ChartParams.scaleValue = Double.parseDouble(scaleField.getText()); + ChartParams.barWidth = Double.parseDouble(widthField.getText()); + } catch (final NumberFormatException ex) { + JOptionPane.showMessageDialog(this, + i18n.get("JumpChart.message2"), "Error...", + JOptionPane.ERROR_MESSAGE); + return; + } + ChartParams.includeLegend = legendCB.isSelected(); + ChartParams.clockwise = clockwiseCB.isSelected(); + ChartParams.chartType = typeCombo.getSelectedIndex(); + ChartParams.showScale = showScaleCB.isSelected(); + ChartParams.cancelled = false; + ChartParams.showLabels = showLabelsCB.isSelected(); + ChartParams.localScale = showLocalScaleCB.isSelected(); + ChartParams.linearScale = linearCB.isSelected(); + + try { + ChartParams.originX = Integer.parseInt(xorigField.getText()); + ChartParams.originY = Integer.parseInt(yorigField.getText()); + } catch (final NumberFormatException ex) { + JOptionPane.showMessageDialog(this, + i18n.get("JumpChart.message4"), "Error...", + JOptionPane.ERROR_MESSAGE); + return; + } + ChartParams.showUnderLabels = underLabelCB.isSelected(); + // ChartParams.underLabelIndex = underLabelCombo.getSelectedIndex(); + // ChartParams.underLabelName = (String) + // underLabelCombo.getSelectedItem(); + + dispose(); + } + + @Override + public void actionPerformed(ActionEvent ev) { + + if (ev.getSource() == typeCombo) { + + if (typeCombo.getSelectedIndex() == ChartParams.LABELS) { + if (currentType != ChartParams.LABELS) { + ChartParams.chartType = ChartParams.LABELS; + ChartParams.cancelled = true; + ChartParams.reloadDialog = true; + dispose(); + } + } else { + if (currentType == ChartParams.LABELS) { + ChartParams.chartType = typeCombo.getSelectedIndex(); + ChartParams.cancelled = true; + ChartParams.reloadDialog = true; + dispose(); + } + } + // System.out.println("Type Item selected"); + } + if (ev.getSource() == cancelButton) { + ChartParams.cancelled = true; + ChartParams.chartType = typeCombo.getSelectedIndex(); + dispose(); + } + + if (ev.getSource() == acceptButton) { + attributes = new Vector<>(10, 2); + int numSelected = 0; + for (int i = 0; i < selectAttribute.length; i++) { + if (ChartParams.includeAttribute[i]) { + numSelected++; + } + } + final ChartAttribute[] tempAttributes = new ChartAttribute[numSelected]; + int k = 0; + for (int i = 0; i < selectAttribute.length; i++) { + ChartParams.includeAttribute[i] = selectAttribute[i] + .isSelected(); + // if(ChartParams.includeAttribute[i]) + // attributes.addElement(ChartParams.attributes[i]); + final int order = ChartParams.attributeOrder[i]; + if (ChartParams.includeAttribute[i]) { + if (order >= 0) { + tempAttributes[order] = ChartParams.attributes[i]; + } else { + tempAttributes[k++] = ChartParams.attributes[i]; + } + } + } + for (int i = 0; i < numSelected; i++) { + attributes.addElement(tempAttributes[i]); + } + if (attributes.size() <= 0) { + JOptionPane.showMessageDialog(this, + i18n.get("JumpChart.message3"), "Error...", + JOptionPane.ERROR_MESSAGE); + return; + } + + ChartParams.autoScale = autoRB.isSelected(); + ChartParams.uniformSize = uniformRB.isSelected(); + try { + ChartParams.scaleValue = Double.parseDouble(scaleField + .getText()); + ChartParams.barWidth = Double.parseDouble(widthField.getText()); + } catch (final NumberFormatException ex) { + JOptionPane.showMessageDialog(this, + i18n.get("JumpChart.message2"), "Error...", + JOptionPane.ERROR_MESSAGE); + return; + } + ChartParams.includeLegend = legendCB.isSelected(); + ChartParams.clockwise = clockwiseCB.isSelected(); + ChartParams.chartType = typeCombo.getSelectedIndex(); + ChartParams.showScale = showScaleCB.isSelected(); + ChartParams.cancelled = false; + ChartParams.showLabels = showLabelsCB.isSelected(); + ChartParams.localScale = showLocalScaleCB.isSelected(); + ChartParams.linearScale = linearCB.isSelected(); + + try { + ChartParams.originX = Integer.parseInt(xorigField.getText()); + ChartParams.originY = Integer.parseInt(yorigField.getText()); + } catch (final NumberFormatException ex) { + JOptionPane.showMessageDialog(this, + i18n.get("JumpChart.message4"), "Error...", + JOptionPane.ERROR_MESSAGE); + return; + } + ChartParams.showUnderLabels = underLabelCB.isSelected(); + // ChartParams.underLabelIndex = underLabelCombo.getSelectedIndex(); + // ChartParams.underLabelName = (String) + // underLabelCombo.getSelectedItem(); + + dispose(); + } + + if (ev.getSource() == aboutButton) { + JOptionPane + .showMessageDialog( + null, + "JumpChart Vers:" + + ChartParams.version + + "\nBased on an idea from Beate Stollberg by Geoffrey G. Roy\nCopyright 2007-2010, Cadplan", + "About...", JOptionPane.INFORMATION_MESSAGE); + } + + if (ev.getSource() == setAllButton) { + for (int i = 0; i < ChartParams.attributes.length; i++) { + ChartParams.includeAttribute[i] = true; + selectAttribute[i].setSelected(true); + } + } + + if (ev.getSource() == clearAllButton) { + for (int i = 0; i < ChartParams.attributes.length; i++) { + ChartParams.includeAttribute[i] = false; + selectAttribute[i].setSelected(false); + } + } + + if (ev.getSource() == orderButton) { + // System.out.println("Ordering"); + final AttributeOrder attributeOder = new AttributeOrder(this); + } + + } +} diff --git a/src/main/java/com/cadplan/jump_chart/jump/ChartParams.java b/src/main/java/com/cadplan/jump_chart/jump/ChartParams.java new file mode 100644 index 0000000..898abcb --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/jump/ChartParams.java @@ -0,0 +1,99 @@ +/* + * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI + * for visualizing and manipulating spatial features with geometry and attributes. + * + * Copyright (C) 2006 Cadplan + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 com.cadplan.jump_chart.jump; + + +import com.vividsolutions.jump.I18N; + +/** + * User: geoff + * Date: 29/04/2007 + * Time: 08:29:31 + * Copyright 2007 Geoffrey G Roy. + */ +public class ChartParams { + public static String version = "2.1.0"; + public static final int PIE_EAST = 0; + public static final int PIE_NORTH = 1; + public static final int BAR = 2; + public static final int COLUMN = 3; + public static final int LABELS = 4; + public static boolean clockwise = true; + + public static String[] typeNames; + + public static String layerName = null; + public static ChartAttribute[] attributes; + public static int[] attributeOrder; + public static boolean[] includeAttribute; + public static int chartType = PIE_EAST; + public static boolean includeLegend = true; + public static boolean uniformSize = true; + public static boolean autoScale = true; + public static double scaleValue = 20.0; + public static double barWidth = 5; + public static boolean cancelled = false; + public static boolean reloadDialog = false; + public static boolean ordered = false; + public static boolean showScale = false; + public static boolean linearScale = true; + public static double maxValue = 1.0; + + public static int originX = 0; + public static int originY = 0; + public static boolean showLabels = false; + public static boolean localScale = false; + + public static boolean showUnderLabels = false; + public static int underLabelIndex = 0; + public static String underLabelName = "Name"; + + public ChartParams() { + + } + + public static void setNames(I18N i18n) { + typeNames = new String[]{ + i18n.get("JumpChart.Dialog.PieEast"), + i18n.get("JumpChart.Dialog.PieNorth"), + i18n.get("JumpChart.Dialog.Bar"), + i18n.get("JumpChart.Dialog.Column"), + i18n.get("JumpChart.Dialog.Labels")}; + } + + public static double scaleInterval(double val) { + boolean debug = false; + double interval; + double order; + int k = 1; + double s = val * 2.0 / 4.0; + + order = Math.floor(Math.log10(s)); + double sb = Math.floor(s / Math.pow(10.0, order)); + interval = sb * Math.pow(10.0, order) / 2.0; + if (debug) System.out.println("Scaling: val=" + val + " order=" + order + " k=" + k + " sb=" + sb); + + if (debug) System.out.println("interval=" + interval); + return interval; + } +} diff --git a/src/main/java/com/cadplan/jump_chart/jump/ChartValues.java b/src/main/java/com/cadplan/jump_chart/jump/ChartValues.java new file mode 100644 index 0000000..ef7079b --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/jump/ChartValues.java @@ -0,0 +1,62 @@ +/* + * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI + * for visualizing and manipulating spatial features with geometry and attributes. + * + * Copyright (C) 2006 Cadplan + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 com.cadplan.jump_chart.jump; + +/** + * User: geoff + * Date: 28/04/2007 + * Time: 11:31:54 + * Copyright 2007 Geoffrey G Roy. + */ +public class ChartValues +{ + public int ID; + public String name; + public double x; + public double y; + public double [] values; + public String [] names; + public String [] types; + + public ChartValues(int ID, String name, double x, double y, double [] values, String [] names, String [] types) + { + this.ID = ID; + this.name = name; + this.x = x; + this.y = y; + this.values = values; + this.names = names; + this.types = types; + } + + public String toString() + { + String s = "Item:"+ID+ ":"+name+" ["+x+","+y+"]"; + for (int i=0; i < values.length; i++) + { + s = s + "["+types[i]+":"+names[i]+"] "+ values[i]; + if(i < values.length-1) s = s+","; + } + return s; + } +} diff --git a/src/main/java/com/cadplan/jump_chart/jump/ColumnChart.java b/src/main/java/com/cadplan/jump_chart/jump/ColumnChart.java new file mode 100644 index 0000000..2d3cb79 --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/jump/ColumnChart.java @@ -0,0 +1,323 @@ +/* + * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI + * for visualizing and manipulating spatial features with geometry and attributes. + * + * Copyright (C) 2006 Cadplan + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 com.cadplan.jump_chart.jump; + +import com.vividsolutions.jump.feature.*; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.LinearRing; + +/** + * User: geoff + * Date: 29/04/2007 + * Time: 13:18:57 + * Copyright 2007 Geoffrey G Roy. + */ +public class ColumnChart +{ + boolean debug = false; + ChartAttribute [] attributes; + ChartValues [] values; + double screenScale; + double maxValue; + double maxSize; + double xoffs, yoffs; + double originX, originY; + + public ColumnChart(ChartAttribute [] attributes, ChartValues [] values, double screenScale) + { + this.attributes = attributes; + this.values = values; + this.screenScale = screenScale; + xoffs = ChartParams.originX*screenScale; + yoffs = ChartParams.originY*screenScale; + } + + public double getMaxValue() + { + return maxValue; + } + + public double getMaxSize() + { + return maxSize; + } + + public void addFeatures(FeatureCollection dataset) + { + + double barHeight = 60; + double barWidth = 5*screenScale; + double maxHeight = 60; + double dataMax = Double.MIN_VALUE; + double x, y; + + double [] itemMax = new double[values.length]; + double [] sumItem = new double[values.length]; + double sumMax = Double.MIN_VALUE; + for (int i=0; i < values.length; i++) + { + + double [] data = values[i].values; + itemMax[i] = Double.MIN_VALUE; + sumItem[i] = 0.0; + for (int j=0; j < data.length; j++) + { + if(data[j] > dataMax) dataMax = data[j]; + if(data[j] > itemMax[i]) itemMax[i] = data[j]; + sumItem[i] = sumItem[i] + data[j]; + } + if(sumItem[i] > sumMax) sumMax = sumItem[i]; + } + double barHeightRatio = maxHeight/dataMax; + + + for(int i=0; i < values.length; i++) + { + double [] data = values[i].values; + String nameValue = values[i].name; + x = values[i].x; + y = values[i].y; + double dy = y; + + + if(ChartParams.autoScale) + { + maxHeight = barHeight*screenScale; + barWidth = 10*screenScale; + } + else + { + maxHeight = ChartParams.scaleValue*screenScale; + barWidth = ChartParams.barWidth*screenScale; + } + double dx = x - barWidth/2; + if(ChartParams.uniformSize) + { + barHeightRatio = 1.0 * maxHeight; + } + else + { + barHeightRatio = maxHeight * sumItem[i] / sumMax; + } + maxValue = sumMax; + maxSize = maxHeight; + if(Double.isInfinite(barHeightRatio)) barHeightRatio = 1.0; + for (int j=0; j < data.length; j++) + { + double height = data[j]*barHeightRatio/sumItem[i]; + String name = attributes[j].name; + if(Double.isInfinite(height)) height = 30.0; + if(Double.isNaN(height)) height = 30.0; + //System.out.println("i="+i+" j="+j+" height="+height+" barHeightratio="+barHeightRatio); + Feature feature = buildFeature(j, dx, dy, barWidth, height, data[j], name); + dataset.add(feature); + dy = dy + height; + } + + // ------------------------------------------- + // build underlabel feature if required + //-------------------------------------------- + //String nameValue = "Missing"; + if(ChartParams.showUnderLabels) + { + + //System.out.println("Adding feature value namevalue="+nameValue); + Feature feature = buildLabelFeature(x, y, nameValue); + dataset.add(feature); + } + } + + if(ChartParams.localScale && !ChartParams.uniformSize) + { + for(int i=0; i < values.length; i++) + { + double [] data = values[i].values; + + x = values[i].x; + y = values[i].y; + originX = x + 1.0 * barWidth + xoffs; + originY = y + yoffs; + + double interval = ChartParams.scaleInterval(maxValue); + double scale = maxSize/maxValue; + if(ChartParams.localScale) createLocalScale(dataset,originX, originY, interval, scale, sumItem[i]); + + } + } + } + + private Feature buildLabelFeature(double x, double y, String name) + { + double xpos, ypos; + double fontHeight = 10.0 * screenScale; + //System.out.println("fontHeight = " + fontHeight); + xpos = x; + ypos = y - fontHeight; + + FeatureSchema featureSchema = new FeatureSchema(); + + featureSchema.addAttribute("Geometry",AttributeType.GEOMETRY); + featureSchema.addAttribute("Index", AttributeType.INTEGER); + featureSchema.addAttribute("dValue", AttributeType.DOUBLE); + featureSchema.addAttribute("iValue", AttributeType.INTEGER); + featureSchema.addAttribute(ChartParams.underLabelName, AttributeType.STRING); + + //System.out.println("Label Feature at:"+x+","+y+" name="+name+ " for attribute: " + ChartParams.underLabelName); + Feature feature = new BasicFeature(featureSchema); + + + Geometry geometry = new GeometryFactory().createPoint(new Coordinate(xpos,ypos)); + feature.setGeometry(geometry); + feature.setAttribute("iValue",-1); + feature.setAttribute("dValue",-1.0); + feature.setAttribute(ChartParams.underLabelName,name); + + + + return feature; + } + + + private Feature buildFeature(int index, double x, double y, double width, double height, double value, String name) + { + FeatureSchema featureSchema = new FeatureSchema(); + + featureSchema.addAttribute("Geometry", AttributeType.GEOMETRY); + featureSchema.addAttribute("dValue", AttributeType.DOUBLE); + featureSchema.addAttribute("iValue", AttributeType.INTEGER); + featureSchema.addAttribute("Index", AttributeType.INTEGER); + featureSchema.addAttribute("Name", AttributeType.STRING); + + + if(debug) System.out.println("Feature at:"+x+","+y+" value="+value); + Coordinate p = new Coordinate(x+xoffs,y+yoffs); + Coordinate [] pointArray = new Coordinate[5]; + pointArray[0] = new Coordinate(x+xoffs,y+yoffs); + pointArray[1]= new Coordinate(x+xoffs+width,y+yoffs); + pointArray[2] = new Coordinate(x+xoffs+width,y+yoffs+height); + pointArray[3] = new Coordinate(x+xoffs,y+yoffs+height); + pointArray[4] = new Coordinate(x+xoffs,y+yoffs); + for (int i=0; i < pointArray.length; i++) + { + if(debug) System.out.println("Point "+i+":"+pointArray[i]); + } + + LinearRing lr = new GeometryFactory().createLinearRing(pointArray); + Geometry geometry = new GeometryFactory().createPolygon(lr, null); + + Feature feature = new BasicFeature(featureSchema); + + if(debug) System.out.println("Geometry: "+geometry); + feature.setGeometry(geometry); + feature.setAttribute("dValue", value); + feature.setAttribute("iValue", (int) value); + feature.setAttribute("Index", index); + if(ChartParams.showLabels) feature.setAttribute("Name",name); + else feature.setAttribute("Name",""); + return feature; + } + + + private void createLocalScale(FeatureCollection dataset, double x, double y, double interval, double scale, double maxValue) + { + //boolean debug = true; + FeatureSchema featureSchema = new FeatureSchema(); + featureSchema.addAttribute("Geometry", AttributeType.GEOMETRY); + featureSchema.addAttribute("dValue", AttributeType.DOUBLE); + featureSchema.addAttribute("iValue", AttributeType.INTEGER); + featureSchema.addAttribute("Index", AttributeType.INTEGER); + featureSchema.addAttribute("Name", AttributeType.STRING); + + double width = 3*screenScale; + double barWidth = ChartParams.barWidth*screenScale; + double yp = y+ 5*interval*scale; + + //Coordinate [] points = new Coordinate[2]; + //points[0] = new Coordinate(x,y); + //points[1] = new Coordinate(x,y+ 5*interval*scale); + + //Geometry geometry = new GeometryFactory().createLineString(points); + + //if(debug) System.out.println("Line Geometry: "+geometry); + //Feature feature = new BasicFeature(featureSchema); + + + //feature.setGeometry(geometry); + //feature.setAttribute("iValue",-1); + //feature.setAttribute("dValue",-1.0); + //feature.setAttribute("Name",""); + //dataset.add(feature); + for(int i=1; i <=5 ; i++) + { + Coordinate [] linePoints = new Coordinate[2]; + linePoints[0] = new Coordinate(x,y+interval*scale*i); + linePoints[1] = new Coordinate(x-barWidth/2, y+interval*scale*i); + + Geometry linegeometry = new GeometryFactory().createLineString(linePoints); + + Feature linefeature = new BasicFeature(featureSchema); + + if(debug) System.out.println("i="+i+" Bar Geometry: "+linegeometry); + linefeature.setGeometry(linegeometry); + linefeature.setAttribute("dValue",-1.0); + linefeature.setAttribute("iValue",-1); + linefeature.setAttribute("Index",-1); + + if(interval*i < maxValue && i < 5) + { + linefeature.setAttribute("Name",""); + dataset.add(linefeature); + } + else + { + linefeature.setAttribute("Name",NumberFormatter.format(interval*i)); + dataset.add(linefeature); + + Coordinate [] points = new Coordinate[2]; + points[0] = new Coordinate(x,y); + points[1] = new Coordinate(x,y+ i*interval*scale); + Geometry geometry = new GeometryFactory().createLineString(points); + if(debug) System.out.println("Line Geometry: "+geometry); + Feature feature = new BasicFeature(featureSchema); + feature.setGeometry(geometry); + feature.setAttribute("iValue",-1); + feature.setAttribute("dValue",-1.0); + feature.setAttribute("Name",""); + dataset.add(feature); + break; + } + + //if(i < 5) linefeature.setAttribute("Name",""); + //else linefeature.setAttribute("Name",String.valueOf(interval*i)); + //dataset.add(linefeature); + + + } + + + + } + +} diff --git a/src/main/java/com/cadplan/jump_chart/jump/JumpChartExtension.java b/src/main/java/com/cadplan/jump_chart/jump/JumpChartExtension.java new file mode 100644 index 0000000..9e5a49c --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/jump/JumpChartExtension.java @@ -0,0 +1,40 @@ +/* + * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI + * for visualizing and manipulating spatial features with geometry and attributes. + * + * Copyright (C) 2006 Cadplan + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 com.cadplan.jump_chart.jump; + +import com.vividsolutions.jump.workbench.plugin.Extension; +import com.vividsolutions.jump.workbench.plugin.PlugInContext; + +/** + * User: geoff + * Date: 28/04/2007 + * Time: 09:45:45 + * Copyright 2007 Geoffrey G Roy. + */ +public class JumpChartExtension extends Extension +{ + public void configure(PlugInContext context) + { + new JumpChartPlugIn().initialize(context); + } +} diff --git a/src/main/java/com/cadplan/jump_chart/jump/JumpChartPlugIn.java b/src/main/java/com/cadplan/jump_chart/jump/JumpChartPlugIn.java new file mode 100644 index 0000000..588d807 --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/jump/JumpChartPlugIn.java @@ -0,0 +1,74 @@ +/* + * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI + * for visualizing and manipulating spatial features with geometry and attributes. + * + * Copyright (C) 2006 Cadplan + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 com.cadplan.jump_chart.jump; + +import javax.swing.Icon; +import javax.swing.ImageIcon; + +import com.vividsolutions.jump.I18N; +import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn; +import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck; +import com.vividsolutions.jump.workbench.plugin.PlugInContext; +import com.vividsolutions.jump.workbench.ui.GUIUtil; +import com.vividsolutions.jump.workbench.ui.MenuNames; + +import java.util.Objects; + +/** + * User: geoff Date: 28/04/2007 Time: 09:40:22 Copyright 2007 Geoffrey G Roy. + */ +public class JumpChartPlugIn extends AbstractPlugIn { + + public static final I18N I18N = com.vividsolutions.jump.I18N.getInstance("com.cadplan.jump_chart"); + public static final ImageIcon ICON = new ImageIcon(Objects.requireNonNull(JumpChartPlugIn.class.getResource("charticon.gif"))); + + @Override + public void initialize(PlugInContext context) { + ChartParams.setNames(I18N); + final MultiEnableCheck mcheck = new MultiEnableCheck(); + final String menuName = MenuNames.PLUGINS; + final String menuItem = I18N.get("JumpChart.MenuItem"); + context.getFeatureInstaller().addMainMenuPlugin(this, + new String[] { menuName }, menuItem, false, getIcon(), mcheck); + context.getWorkbenchFrame() + .getToolBar() + .addPlugIn(ICON, this, mcheck, context.getWorkbenchContext()); + + } + + public Icon getIcon() { + return ICON; + } + + @Override + public String getName() { + return I18N.get("JumpChart.MenuItem"); + } + + @Override + public boolean execute(PlugInContext context) { + final Chart chart = new Chart(context, I18N); + return true; + } + +} diff --git a/src/main/java/com/cadplan/jump_chart/jump/LabelsChart.java b/src/main/java/com/cadplan/jump_chart/jump/LabelsChart.java new file mode 100644 index 0000000..7b4589f --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/jump/LabelsChart.java @@ -0,0 +1,130 @@ +/* The Unified Mapping Platform (JUMP) is an extensible, interactive GUI + * for visualizing and manipulating spatial features with geometry and attributes. + * + * Copyright (C) 2006 Cadplan + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 com.cadplan.jump_chart.jump; + +import com.vividsolutions.jump.feature.*; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.GeometryFactory; + + +/** + * User: geoff + * Date: 28/04/2007 + * Time: 16:50:31 + * Copyright 2007 Geoffrey G Roy. + */ +public class LabelsChart { + + boolean debug = false; + ChartAttribute[] attributes; + ChartValues[] values; + double screenScale; + double maxValue; + double maxSize; + double xoffs, yoffs; + double originX, originY; + + public LabelsChart(ChartAttribute[] attributes, ChartValues[] values, double screenScale) { + this.attributes = attributes; + this.values = values; + this.screenScale = screenScale; + xoffs = ChartParams.originX * screenScale; + yoffs = ChartParams.originY * screenScale; + + if (debug) { + for (int i = 0; i < attributes.length; i++) { + System.out.println("Attribute " + i + ":" + attributes[i].name); + } + for (int i = 0; i < values.length; i++) { + System.out.println("Value " + i + ":" + values[i].toString()); + } + } + } + + public double getMaxValue() { + return maxValue; + } + + public double getMaxSize() { + return maxSize; + } + + public void addFeatures(FeatureCollection dataset) { + + double x, y; + String name; + double dx = 0.0; + double[] itemMax = new double[values.length]; + + for (int i = 0; i < values.length; i++) { + String[] data = values[i].names; + x = values[i].x; + y = values[i].y; + originY = y; + name = values[i].name; + + Feature feature = buildFeature(i, name, attributes, x, y, data); + dataset.add(feature); + } + + } + + + private Feature buildFeature(int index, String name, ChartAttribute[] attributes, double x, double y, String[] data) { + boolean debug = false; + FeatureSchema featureSchema = new FeatureSchema(); + + //featureSchema.addAttribute("$FID", AttributeType.INTEGER); + featureSchema.addAttribute("Geometry", AttributeType.GEOMETRY); + featureSchema.addAttribute("Name", AttributeType.STRING); + for (int i = 0; i < attributes.length; i++) { + featureSchema.addAttribute(attributes[i].toString(), AttributeType.STRING); + } + + + if (debug) System.out.println("Feature at:" + x + "," + y + " data=" + data); + Coordinate p = new Coordinate(x + xoffs, y + yoffs); + Coordinate[] pointArray = new Coordinate[1]; + pointArray[0] = new Coordinate(x + xoffs, y + yoffs); + Geometry pointgeometry = new GeometryFactory().createMultiPoint(pointArray); + + + Feature feature = new BasicFeature(featureSchema); + + if (debug) System.out.println("Geometry: " + pointgeometry); + feature.setGeometry(pointgeometry); + //feature.setAttribute("$FID", index); + feature.setAttribute("Name", name); + for (int i = 0; i < data.length; i++) { + if (debug) System.out.println("data " + i + ":" + data[i]); + } + for (int i = 0; i < attributes.length; i++) { + + feature.setAttribute(attributes[i].toString(), data[i]); + } + + return feature; + } + +} \ No newline at end of file diff --git a/src/main/java/com/cadplan/jump_chart/jump/NumberFormatter.java b/src/main/java/com/cadplan/jump_chart/jump/NumberFormatter.java new file mode 100644 index 0000000..07a4b24 --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/jump/NumberFormatter.java @@ -0,0 +1,23 @@ +package com.cadplan.jump_chart.jump; + +import java.text.DecimalFormat; + +public class NumberFormatter { + + public static String format(double val) { + //double val0 = val; + DecimalFormat df; + String result; + if (Math.abs(val) <= 100000000.0 && Math.abs(val) >= 0.001) { + val = Math.round(val * 10000.0) / 10000.0; + if ((val) % 1 == 0) result = String.valueOf((int) (val)); + else result = String.valueOf(val); + } else { + df = new DecimalFormat("0.0000E0"); + result = df.format(val); + } + //System.out.println("Formatting: val="+val0+" result="+result); + return result; + } + +} diff --git a/src/main/java/com/cadplan/jump_chart/jump/PieChart.java b/src/main/java/com/cadplan/jump_chart/jump/PieChart.java new file mode 100644 index 0000000..ae5cfea --- /dev/null +++ b/src/main/java/com/cadplan/jump_chart/jump/PieChart.java @@ -0,0 +1,378 @@ +/* + * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI + * for visualizing and manipulating spatial features with geometry and attributes. + * + * Copyright (C) 2006 Cadplan + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 com.cadplan.jump_chart.jump; + +import com.vividsolutions.jump.feature.*; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.LinearRing; + +import java.util.Vector; + + +/** + * User: geoff + * Date: 28/04/2007 + * Time: 13:20:18 + * Copyright 2007 Geoffrey G Roy. + */ +public class PieChart { + boolean debug = false; + ChartAttribute[] attributes; + ChartValues[] values; + double screenScale; + double startAngle; + double maxValue; + double maxSize; + double xoffs, yoffs; + double originX, originY; + + public PieChart(ChartAttribute[] attributes, ChartValues[] values, double screenScale, double startAngle) { + this.attributes = attributes; + this.values = values; + this.screenScale = screenScale; + this.startAngle = startAngle; + xoffs = ChartParams.originX * screenScale; + yoffs = ChartParams.originY * screenScale; + } + + public void addFeatures(FeatureCollection dataset) { + double sumValues, totalValues; + double maxRad; + int[] sizeOrderIndex = new int[values.length]; + + if (ChartParams.autoScale) { + maxRad = 20 * screenScale; + } else { + maxRad = ChartParams.scaleValue * screenScale; + } + + totalValues = 0.0; + double[] itemSum = new double[values.length]; + double itemMax = Double.MIN_VALUE; + for (int i = 0; i < values.length; i++) { + // System.out.println("&&&& Preparing data for: "+values[i].name); + double[] data = values[i].values; + itemSum[i] = 0.0; + for (double datum : data) { + totalValues = totalValues + datum; + itemSum[i] = itemSum[i] + datum; + } + if (itemSum[i] > itemMax) itemMax = itemSum[i]; + } + + // create sizeOrderIndex + double[] tempValues = new double[values.length]; + for (int i = 0; i < values.length; i++) tempValues[i] = itemSum[i]; + for (int i = 0; i < values.length; i++) sizeOrderIndex[i] = i; + for (int i = 0; i < tempValues.length - 1; i++) { + int n = 0; + int nMax = i; + double sizeMax = tempValues[i]; + boolean swap = false; + for (int k = i + 1; k < tempValues.length; k++) { + if (tempValues[k] > sizeMax) { + sizeMax = tempValues[k]; + nMax = k; + swap = true; + + } + } + if (swap) { + double temp = tempValues[i]; + tempValues[i] = tempValues[nMax]; + tempValues[nMax] = temp; + + int tempIndex = sizeOrderIndex[i]; + sizeOrderIndex[i] = sizeOrderIndex[nMax]; + sizeOrderIndex[nMax] = tempIndex; + } + + } + + //System.out.println("Size order"); + //for(int i=0; i < values.length; i++) System.out.println("i="+i+" k="+sizeOrderIndex[i]+" >> "+tempValues[i]+" itemsum[i]="+itemSum[i]); + + maxValue = itemMax; + ChartParams.maxValue = maxValue; + //System.out.println("maxValue="+maxValue+" maxRad="+maxRad); + maxSize = maxRad; + for (int k = 0; k < values.length; k++) { + int i = sizeOrderIndex[k]; + sumValues = 0.0; + double[] data = values[i].values; + String nameValue = values[i].name; + double x = values[i].x; + double y = values[i].y; + double rad = 50; + double angle = startAngle; //0.0; + + for (double datum : data) { + sumValues = sumValues + datum; + } + + if (debug) System.out.println("totalvalues=" + totalValues + " sumValues=" + sumValues); + if (ChartParams.uniformSize) { + rad = maxRad; + } else { + if (ChartParams.linearScale) { + rad = maxRad * (itemSum[i]) / (itemMax); + } else { + rad = maxRad * Math.sqrt((itemSum[i]) / (itemMax)); + } + } + if (Double.isInfinite(rad)) rad = 30.0; + //System.out.println("***Rad="+rad); + for (int j = 0; j < data.length; j++) { + double prop = data[j] / sumValues; // fraction of circle for item + if (Double.isInfinite(prop)) prop = 1.0; + if (Double.isNaN(prop)) prop = 1.0; + String name = attributes[j].name; + Feature feature = buildFeature(j, x, y, rad, prop, angle, data[j], name); + //System.out.println("\nFeature:"+feature.toString()); + dataset.add(feature); + if (!ChartParams.clockwise) angle = angle + 2.0 * Math.PI * prop; + else angle = angle - 2.0 * Math.PI * prop; + } + + // ------------------------------------------- + // build underlabel feature if required + //-------------------------------------------- + //String nameValue = "Missing"; + if (ChartParams.showUnderLabels) { + + // System.out.println("Adding feature value namevalue="+nameValue); + Feature feature = buildLabelFeature(x, y - rad, nameValue); + //System.out.println("Feature:"+feature.toString()); + dataset.add(feature); + } + + } + if (ChartParams.localScale && !ChartParams.uniformSize) { + for (int i = 0; i < values.length; i++) { + //double[] data = values[i].values; + + double x = values[i].x; + double y = values[i].y; + originX = x + xoffs; + originY = y + yoffs; + + double interval = ChartParams.scaleInterval(maxValue); + double scale = maxSize / maxValue; + if (ChartParams.localScale) createLocalScale(dataset, originX, originY, interval, scale, itemSum[i]); + + } + } + } + + public double getMaxValue() { + return maxValue; + } + + public double getMaxSize() { + return maxSize; + } + + private Feature buildLabelFeature(double x, double y, String name) { + double xpos, ypos; + double fontHeight = 10.0 * screenScale; + //System.out.println("fontHeight = " + fontHeight); + xpos = x; + ypos = y - fontHeight; + + FeatureSchema featureSchema = new FeatureSchema(); + + featureSchema.addAttribute("Geometry", AttributeType.GEOMETRY); + featureSchema.addAttribute("Index", AttributeType.INTEGER); + featureSchema.addAttribute("dValue", AttributeType.DOUBLE); + featureSchema.addAttribute("iValue", AttributeType.INTEGER); + featureSchema.addAttribute(ChartParams.underLabelName, AttributeType.STRING); + + //System.out.println("Label Feature at:"+x+","+y+" name="+name+ " for attribute: " + ChartParams.underLabelName); + Feature feature = new BasicFeature(featureSchema); + + + Geometry geometry = new GeometryFactory().createPoint(new Coordinate(xpos, ypos)); + feature.setGeometry(geometry); + feature.setAttribute("iValue", -1); + feature.setAttribute("dValue", -1.0); + feature.setAttribute(ChartParams.underLabelName, name); + + + return feature; + } + + + private Feature buildFeature(int index, double x, double y, double rad, double prop, double angle, double value, String name) { + FeatureSchema featureSchema = new FeatureSchema(); + + featureSchema.addAttribute("Geometry", AttributeType.GEOMETRY); + featureSchema.addAttribute("Index", AttributeType.INTEGER); + featureSchema.addAttribute("dValue", AttributeType.DOUBLE); + featureSchema.addAttribute("iValue", AttributeType.INTEGER); + featureSchema.addAttribute("Name", AttributeType.STRING); + + Vector points = new Vector<>(10, 2); + + if (debug) + System.out.println("Feature at:" + x + "," + y + " rad=" + rad + " prop=" + prop + " angle=" + angle + " value=" + value); + //System.out.println("prop="+prop); + Coordinate p = new Coordinate(x + xoffs, y + yoffs); + if (prop < 1.0) points.addElement(p); + double sweepAngle = prop * (2.0 * Math.PI); + if (ChartParams.clockwise) sweepAngle = -sweepAngle; + double stepAngle = 2.0 * Math.PI / 64.0; + if (ChartParams.clockwise) stepAngle = -stepAngle; + if (debug) System.out.println("sweep=" + sweepAngle + " step=" + stepAngle); + double startAngle = angle; + double xp = x + xoffs + rad * Math.cos(startAngle); + double yp = y + yoffs + rad * Math.sin(startAngle); + p = new Coordinate(xp, yp); + points.addElement(p); + if (!ChartParams.clockwise) { + while (startAngle + stepAngle < angle + sweepAngle) { + startAngle = startAngle + stepAngle; + xp = x + xoffs + rad * Math.cos(startAngle); + yp = y + yoffs + rad * Math.sin(startAngle); + p = new Coordinate(xp, yp); + points.addElement(p); + } + } else // clockwise + { + while (startAngle + stepAngle > angle + sweepAngle) { + startAngle = startAngle + stepAngle; + xp = x + xoffs + rad * Math.cos(startAngle); + yp = y + yoffs + rad * Math.sin(startAngle); + p = new Coordinate(xp, yp); + points.addElement(p); + } + } + startAngle = angle + sweepAngle; + xp = x + xoffs + rad * Math.cos(startAngle); + yp = y + yoffs + rad * Math.sin(startAngle); + p = new Coordinate(xp, yp); + points.addElement(p); + + + xp = x + xoffs; + yp = y + yoffs; + p = new Coordinate(xp, yp); + if (prop < 1.0) points.addElement(p); + else points.addElement(points.elementAt(0)); + + Coordinate[] pointArray = new Coordinate[points.size()]; + for (int i = 0; i < points.size(); i++) { + pointArray[i] = points.elementAt(i); + if (debug) System.out.println("Point " + i + ":" + pointArray[i]); + } + + LinearRing lr = new GeometryFactory().createLinearRing(pointArray); + Geometry geometry = new GeometryFactory().createPolygon(lr, null); + + Feature feature = new BasicFeature(featureSchema); + + if (debug) System.out.println("Geometry: " + geometry); + feature.setGeometry(geometry); + feature.setAttribute("iValue", (int) value); + feature.setAttribute("dValue", value); + feature.setAttribute("Index", index); + if (ChartParams.showLabels) feature.setAttribute("Name", name); + else feature.setAttribute("Name", ""); + return feature; + } + + private void createLocalScale(FeatureCollection dataset, double x, double y, double interval, double scale, double maxValue) { + //boolean debug = true; + FeatureSchema featureSchema = new FeatureSchema(); + featureSchema.addAttribute("Geometry", AttributeType.GEOMETRY); + featureSchema.addAttribute("dValue", AttributeType.DOUBLE); + featureSchema.addAttribute("iValue", AttributeType.INTEGER); + featureSchema.addAttribute("Index", AttributeType.INTEGER); + featureSchema.addAttribute("Name", AttributeType.STRING); + + double width = 3 * screenScale; + double yp = y + 5 * interval * scale; + + //Coordinate [] points = new Coordinate[2]; + //points[0] = new Coordinate(x,y); + //points[1] = new Coordinate(x,y+ 5*interval*scale); + + //Geometry geometry = new GeometryFactory().createLineString(points); + + //if(debug) System.out.println("Line Geometry: "+geometry); + //Feature feature = new BasicFeature(featureSchema); + + //feature.setGeometry(geometry); + //feature.setAttribute("iValue",-1); + //feature.setAttribute("dValue",-1.0); + //feature.setAttribute("Name",""); + //dataset.add(feature); + double yMax = interval * scale * 5; + double yAct; + for (int i = 1; i <= 5; i++) { + yAct = interval * scale * i; + if (!ChartParams.linearScale) { + yAct = yMax * Math.sqrt(interval * scale * i / yMax); + } + Coordinate[] linePoints = new Coordinate[2]; + linePoints[0] = new Coordinate(x, y + yAct); + linePoints[1] = new Coordinate(x - width, y + yAct); + + Geometry linegeometry = new GeometryFactory().createLineString(linePoints); + + Feature linefeature = new BasicFeature(featureSchema); + + if (debug) System.out.println("i=" + i + " Bar Geometry: " + linegeometry); + linefeature.setGeometry(linegeometry); + linefeature.setAttribute("dValue", -1.0); + linefeature.setAttribute("iValue", -1); + linefeature.setAttribute("Index", -1); + + if (interval * i < maxValue && i < 5) { + linefeature.setAttribute("Name", ""); + dataset.add(linefeature); + } else { + linefeature.setAttribute("Name", NumberFormatter.format(interval * i)); + dataset.add(linefeature); + + Coordinate[] points = new Coordinate[2]; + points[0] = new Coordinate(x, y); + points[1] = new Coordinate(x, y + yAct); + Geometry geometry = new GeometryFactory().createLineString(points); + if (debug) System.out.println("Line Geometry: " + geometry); + Feature feature = new BasicFeature(featureSchema); + feature.setGeometry(geometry); + feature.setAttribute("iValue", -1); + feature.setAttribute("dValue", -1.0); + feature.setAttribute("Name", ""); + dataset.add(feature); + break; + } + //if(i < 5) linefeature.setAttribute("Name",""); + //else linefeature.setAttribute("Name",NumberFormatter.format(interval*i)); + //dataset.add(linefeature); + } + } + +} diff --git a/src/main/resources/com/cadplan/jump_chart/jump/charticon.gif b/src/main/resources/com/cadplan/jump_chart/jump/charticon.gif new file mode 100644 index 0000000..986dc8d Binary files /dev/null and b/src/main/resources/com/cadplan/jump_chart/jump/charticon.gif differ diff --git a/src/main/resources/com/cadplan/jump_chart/language/jump.properties b/src/main/resources/com/cadplan/jump_chart/language/jump.properties new file mode 100644 index 0000000..c0eb28c --- /dev/null +++ b/src/main/resources/com/cadplan/jump_chart/language/jump.properties @@ -0,0 +1,46 @@ +JumpChart.Version=${project.version} ${project.build.version.details} +# Properties file for the JumpChart Plugins - default language if none specified +JumpChart.MenuName=Extension +JumpChart.MenuItem=Jump Chart +JumpChart.Dialog.SelectedLayer=Selected Layer +JumpChart.Dialog.Attributes=Attributes +JumpChart.Dialog.ChartType=Chart Type +JumpChart.Dialog.Size=Size +JumpChart.Dialog.Scale=Scale +JumpChart.Dialog.Width=Bar Width +JumpChart.Dialog.Uniform=Uniform +JumpChart.Dialog.Variable=Variable +JumpChart.Dialog.Auto=Auto +JumpChart.Dialog.Fixed=Fixed +JumpChart.Dialog.Cancel=Cancel +JumpChart.Dialog.About=About +JumpChart.Dialog.Accept=Accept +JumpChart.Dialog.Pie=Pie +JumpChart.Dialog.PieEast=Pie-East +JumpChart.Dialog.PieNorth=Pie-North +JumpChart.Dialog.Bar=Bar +JumpChart.Dialog.Column=Column +JumpChart.Dialog.Labels=Labels +JumpChart.Dialog.Clockwise=Clockwise +JumpChart.Dialog.Legend=Legend +JumpChart.Dialog.SelectAll= Select All +JumpChart.Dialog.ClearAll=Clear All +JumpChart.Dialog.Order=Order +JumpChart.Dialog.ShowScale=Layer Scale +JumpChart.Dialog.LocalScale=Local Scale +JumpChart.Dialog.ShowLabels=Show Labels +JumpChart.Dialog.Linear=Linear +JumpChart.Dialog.UnderLabels=Show Under Labels +JumpChart.Order.Order=Order Attributes +JumpChart.Order.MoveUp=Move Up +JumpChart.Order.MoveDown=Move Down +JumpChart.Order.Accept=Accept +JumpChart.Order.Cancel=Cancel +JumpChart.message1=You must have a layer selected +JumpChart.message2=Error in scale or width value fields +JumpChart.message3=You must choose at least one attribute +JumpChart.message4=Offset values must be integers +JumpChart.message5=Select attribute for 'Name' +JumpChart.message6=Attribute 'Name' not found +JumpChart.Legend.ChartType=Variable Chart +JumpChart.Dialog.Offsets=Origin offsets diff --git a/src/main/resources/com/cadplan/jump_chart/language/jump_de.properties b/src/main/resources/com/cadplan/jump_chart/language/jump_de.properties new file mode 100644 index 0000000..44dd504 --- /dev/null +++ b/src/main/resources/com/cadplan/jump_chart/language/jump_de.properties @@ -0,0 +1,45 @@ +# Properties file for the JumpChart Plugins - default language if none specified +JumpChart.MenuName=Extension +JumpChart.MenuItem=Jump Diagramme +JumpChart.Dialog.SelectedLayer=Ebene W\u00E4hlen +JumpChart.Dialog.Attributes=Attribute +JumpChart.Dialog.ChartType=Diagramm-Typ +JumpChart.Dialog.Size=Gr\u00F6sse +JumpChart.Dialog.Scale=Massstab +JumpChart.Dialog.Width=Stab-Breite +JumpChart.Dialog.Uniform=einheitlich +JumpChart.Dialog.Variable=ver\u00E4nderlich +JumpChart.Dialog.Auto=automatisch +JumpChart.Dialog.Fixed=fest +JumpChart.Dialog.Cancel=Abbruch +JumpChart.Dialog.About=\u00DCber.. +JumpChart.Dialog.Accept=\u00DCbernehmen +JumpChart.Dialog.Pie=Tortendiagramm +JumpChart.Dialog.PieEast=Tortendiagramm-Ost +JumpChart.Dialog.PieNorth=Tortendiagramm-Nord +JumpChart.Dialog.Bar=Stabdiagramm +JumpChart.Dialog.Column=S\u00E4ulendiagramm +JumpChart.Dialog.Labels=Aufkleber +JumpChart.Dialog.Clockwise=Rechts herum +JumpChart.Dialog.Legend=Legende +JumpChart.Dialog.SelectAll=Alles w\u00E4hlen +JumpChart.Dialog.ClearAll=Alles l\u00F6schen +JumpChart.Dialog.Order=Reihenfolge +JumpChart.Dialog.ShowScale=Schicht-Skala +JumpChart.Dialog.LocalScale=Lokale Skala +JumpChart.Dialog.ShowLabels=Zeigen Sie Aufkleber +JumpChart.Dialog.Linear=Lineare +JumpChart.Order.Order=Reihenfolge f\u00FCr Attribute +JumpChart.Order.MoveUp=Nach oben bewegen +JumpChart.Order.MoveDown=Nach unten bewegen +JumpChart.Order.Accept=\u00DCbernehmen +JumpChart.Order.Cancel=Abbruch +JumpChart.Dialog.UnderLabels=Anzeigen unter Etiketten +JumpChart.message1=Eine Ebene muss ausgew\u00E4hlt sein. +JumpChart.message2=Fehler im Massstabs oder Breiten-eingabe +JumpChart.message3=Es muss mindestens ein Attribut ausgew\u00E4hlt werden +JumpChart.message4=Offsetwerte m�ssen ganze Zahlen sein +JumpChart.message5=W�hlen Sie Attribut f�r 'Name' +JumpChart.message6=Attribut 'Name' nicht gefunden +JumpChart.Legend.ChartType=Ver\u00E4nderlich Diagramm +JumpChart.Dialog.Offsets=Ursprungsversatz diff --git a/src/main/resources/com/cadplan/jump_chart/language/jump_en.properties b/src/main/resources/com/cadplan/jump_chart/language/jump_en.properties new file mode 100644 index 0000000..c727021 --- /dev/null +++ b/src/main/resources/com/cadplan/jump_chart/language/jump_en.properties @@ -0,0 +1,45 @@ +# Properties file for the JumpChart Plugins - default language if none specified +JumpChart.MenuName=Extension +JumpChart.MenuItem=Jump Chart +JumpChart.Dialog.SelectedLayer=Selected Layer +JumpChart.Dialog.Attributes=Attributes +JumpChart.Dialog.ChartType=Chart Type +JumpChart.Dialog.Size=Size +JumpChart.Dialog.Scale=Scale +JumpChart.Dialog.Width=Bar Width +JumpChart.Dialog.Uniform=Uniform +JumpChart.Dialog.Variable=Variable +JumpChart.Dialog.Auto=Auto +JumpChart.Dialog.Fixed=Fixed +JumpChart.Dialog.Cancel=Cancel +JumpChart.Dialog.About=About +JumpChart.Dialog.Accept=Accept +JumpChart.Dialog.Pie=Pie +JumpChart.Dialog.PieEast=Pie-East +JumpChart.Dialog.PieNorth=Pie-North +JumpChart.Dialog.Bar=Bar +JumpChart.Dialog.Column=Column +JumpChart.Dialog.Clockwise=Clockwise +JumpChart.Dialog.Legend=Legend +JumpChart.Dialog.SelectAll= Select All +JumpChart.Dialog.ClearAll=Clear All +JumpChart.Dialog.Order=Order +JumpChart.Dialog.ShowScale=Layer Scale +JumpChart.Dialog.LocalScale=Local Scale +JumpChart.Dialog.ShowLabels=Show Labels +JumpChart.Dialog.Linear=Linear +JumpChart.Dialog.UnderLabels=Show Under Labels +JumpChart.Order.Order=Order Attributes +JumpChart.Order.MoveUp=Move Up +JumpChart.Order.MoveDown=Move Down +JumpChart.Order.Accept=Accept +JumpChart.Order.Cancel=Cancel +JumpChart.message1=You must have a layer selected +JumpChart.message2=Error in scale or width value fields +JumpChart.message3=You must choose at least one attribute +JumpChart.message4=Offset values must be integers +JumpChart.message5=Select attribute for 'Name' +JumpChart.message6=Attribute 'Name' not found +JumpChart.Legend.ChartType=Variable Chart +JumpChart.Dialog.Offsets=Origin offsets +JumpChart.Dialog.Labels=#T:Labels diff --git a/src/main/resources/com/cadplan/jump_chart/language/jump_es.properties b/src/main/resources/com/cadplan/jump_chart/language/jump_es.properties new file mode 100644 index 0000000..7eb4ebf --- /dev/null +++ b/src/main/resources/com/cadplan/jump_chart/language/jump_es.properties @@ -0,0 +1,45 @@ +#jump_es.properties +JumpChart.Dialog.About=Acerda +JumpChart.Dialog.Accept=Aceptar +JumpChart.Dialog.Attributes=Atributes +JumpChart.Dialog.Auto=Auto +JumpChart.Dialog.Bar=Barras +JumpChart.Dialog.Cancel=Cancelar +JumpChart.Dialog.ChartType=Tipo de diagrama +JumpChart.Dialog.ClearAll=Cancelar todo +JumpChart.Dialog.Clockwise=Horario +JumpChart.Dialog.Column=Columna +JumpChart.Dialog.Fixed=Definido +JumpChart.Dialog.Legend=Leyenda +JumpChart.Dialog.Linear=Lineal +JumpChart.Dialog.LocalScale=Escala local +JumpChart.Dialog.Order=Orden +JumpChart.Dialog.Pie=Circular +JumpChart.Dialog.PieEast=Circular Est +JumpChart.Dialog.PieNorth=Circular Norte +JumpChart.Dialog.Scale=Escala +JumpChart.Dialog.SelectAll=Seleccionar todo +JumpChart.Dialog.SelectedLayer=Capa seleccionada +JumpChart.Dialog.ShowLabels=Mostrar etiquetas +JumpChart.Dialog.ShowScale=Mostrar escala +JumpChart.Dialog.Size=Tama\u00F1o +JumpChart.Dialog.UnderLabels=Mostrar etiquetas individuales +JumpChart.Dialog.Uniform=Uniformemente +JumpChart.Dialog.Variable=Variable +JumpChart.Dialog.Width=Ancho circular +JumpChart.MenuItem=Diagrama +JumpChart.MenuName=Extensi\u00F3n +JumpChart.message1=Debes seleccionar una capa +JumpChart.message2=Error en la escala o en el ancho de los campos de valor +JumpChart.message3=Debes elegir al menos un atributo +JumpChart.message4=Los valores de desplazamiento deben ser enteros (Integer) +JumpChart.message5=Seleccione el atributo per 'Nombre' +JumpChart.message6=No se encuentra el atributo 'Nombre' +JumpChart.Order.Accept=Aceptar +JumpChart.Order.Cancel=Cancelar +JumpChart.Order.MoveDown=Mover abajo +JumpChart.Order.MoveUp=Mover arriba +JumpChart.Order.Order=Orden atributos +JumpChart.Dialog.Labels=Etiquetas +JumpChart.Dialog.Offsets=Desplazamento origen +JumpChart.Legend.ChartType=#T:Variable Chart diff --git a/src/main/resources/com/cadplan/jump_chart/language/jump_fr.properties b/src/main/resources/com/cadplan/jump_chart/language/jump_fr.properties new file mode 100644 index 0000000..18358e8 --- /dev/null +++ b/src/main/resources/com/cadplan/jump_chart/language/jump_fr.properties @@ -0,0 +1,45 @@ +# Properties file for the JumpChart Plugins - default language if none specified +JumpChart.MenuName=Extensions +JumpChart.MenuItem=Diagrammes +JumpChart.Dialog.SelectedLayer=Couche s\u00E9lectionn\u00E9e +JumpChart.Dialog.Attributes=Attributs +JumpChart.Dialog.ChartType=Type de graphique +JumpChart.Dialog.Size=Taille +JumpChart.Dialog.Scale=Echelle +JumpChart.Dialog.Width=Largeur des barres +JumpChart.Dialog.Uniform=Uniforme +JumpChart.Dialog.Variable=Variable +JumpChart.Dialog.Auto=Automatique +JumpChart.Dialog.Fixed=Fixe +JumpChart.Dialog.Cancel=Annuler +JumpChart.Dialog.About=A propos +JumpChart.Dialog.Accept=Valider +JumpChart.Dialog.Pie=Camembert +JumpChart.Dialog.PieEast=Camembert (Est) +JumpChart.Dialog.PieNorth=Camembert (Nord) +JumpChart.Dialog.Bar=Barres +JumpChart.Dialog.Column=Colonnes +JumpChart.Dialog.Labels=Etiquettes +JumpChart.Dialog.Clockwise=Sens horaire +JumpChart.Dialog.Legend=Légende +JumpChart.Dialog.SelectAll=Tout s\u00E9lectionner +JumpChart.Dialog.ClearAll=Tout d\u00E9s\u00E9lectionner +JumpChart.Dialog.Order=Ordre +JumpChart.Dialog.ShowScale=Afficher l'\u00E9chelle +JumpChart.Dialog.LocalScale=Echelle locale +JumpChart.Dialog.ShowLabels=Afficher les \u00E9tiquettes +JumpChart.Order.Order=Ordre des attributs +JumpChart.Order.MoveUp=Monter +JumpChart.Order.MoveDown=Descendre +JumpChart.Order.Accept=Valider +JumpChart.Order.Cancel=Annuler +JumpChart.Dialog.UnderLabels=Montrer les sous étiquettes +JumpChart.message1=Vous devez s\u00E9lectionner une couche +JumpChart.message2=Erreur dans le champ \u00E9chelle ou largeur +JumpChart.message3=Vous devez choisir au moins un attribut +JumpChart.message4=Les valeurs de d\u00E9calages doivent \u00EAtre des entiers +JumpChart.message5=S\u00E9lectionner un attribut pour 'Name' +JumpChart.message6=Attribut 'Name' non trouv\u00E9 +JumpChart.Legend.ChartType=Taille variable +JumpChart.Dialog.Offsets=D\u00E9calage par rapport à l'origine +JumpChart.Dialog.Linear=Linéaire diff --git a/src/main/resources/com/cadplan/jump_chart/language/jump_it.properties b/src/main/resources/com/cadplan/jump_chart/language/jump_it.properties new file mode 100644 index 0000000..3f3bf96 --- /dev/null +++ b/src/main/resources/com/cadplan/jump_chart/language/jump_it.properties @@ -0,0 +1,45 @@ +#jump_it.properties +JumpChart.Dialog.About=Riguardo +JumpChart.Dialog.Accept=OK +JumpChart.Dialog.Attributes=Attributi +JumpChart.Dialog.Auto=Auto +JumpChart.Dialog.Bar=Barra +JumpChart.Dialog.Cancel=Cancella +JumpChart.Dialog.ChartType=Tipo diagramma +JumpChart.Dialog.ClearAll=Cancella tutto +JumpChart.Dialog.Clockwise=Orario +JumpChart.Dialog.Column=Colonna +JumpChart.Dialog.Fixed=Definito +JumpChart.Dialog.Legend=Legenda +JumpChart.Dialog.Linear=Lineare +JumpChart.Dialog.LocalScale=Scala locale +JumpChart.Dialog.Order=Ordine +JumpChart.Dialog.Pie=Torta +JumpChart.Dialog.PieEast=Torta-Est +JumpChart.Dialog.PieNorth=Torta-Nord +JumpChart.Dialog.Scale=Scala +JumpChart.Dialog.SelectAll=Seleziona tutto +JumpChart.Dialog.SelectedLayer=Livello selezionato +JumpChart.Dialog.ShowLabels=Mostra etichette +JumpChart.Dialog.ShowScale=Scala del livello +JumpChart.Dialog.Size=Dimensione +JumpChart.Dialog.UnderLabels=Mostra etichette individuali +JumpChart.Dialog.Uniform=Uniforme +JumpChart.Dialog.Variable=Variabile +JumpChart.Dialog.Width=Larghezza torta +JumpChart.Legend.ChartType=Diagramma variabile +JumpChart.MenuItem=Diagramma +JumpChart.MenuName=Estensione +JumpChart.message1=Devi selezionare un livello +JumpChart.message2=Errore nella scala o nella larghezza dei campi del valore +JumpChart.message3=Devi scegliere almeno un attributo +JumpChart.message4=I valori di offset devono essere interi (Integer) +JumpChart.message5=Seleziona l'attributo per 'Nome' +JumpChart.message6=Attributo 'Nome' non trovato +JumpChart.Order.Accept=OK +JumpChart.Order.Cancel=Cancella +JumpChart.Order.MoveDown=Muovo sotto +JumpChart.Order.MoveUp=Muovi sopra +JumpChart.Order.Order=Ordina attributi +JumpChart.Dialog.Labels=Etichette +JumpChart.Dialog.Offsets=Offset origine