Unknown error 0x80DE0001 - javafx

I get this error when I try to drag TreeView node
E r r o r : 8 0 d e 0 0 0 1 i n C a l l b a c k T o J a v a ( j a v a I D s . V i e w . n o t i
f y D r a g D r o p , g r f K e y S t a t e , p t , p d w E f f e c t )
C O M E r r o r : 8 0 d e 0 0 0 1 U n k n o w n e r r o r 0 x 8 0 D E 0 0 0 1
E r r o r : 8 0 d e 0 0 0 1 i n : : D o D r a g D r o p ( p c d , I D r o p S o u r c e P t
r ( n e w G l a s s D r o p S o u r c e ( o b j ) , f a l s e ) , g e t D R O P E F F E C T (
s u p p o r t e d A c t i o n s ) , & p e r f o r m e d D r o p E f f e c t )
C O M E r r o r : 8 0 d e 0 0 0 1 U n k n o w n e r r o r 0 x 8 0 D E 0 0 0 1
Test code:
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeItem.TreeModificationEvent;
import javafx.scene.control.TreeView;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DataFormat;
import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
public class MainApp extends Application
{
private EventHandler<TreeModificationEvent<DynamicTreeNodeModel>> branchExpandedEventHandler;
/**
* #param args the command line arguments
*/
public static void main(String[] args)
{
Application.launch(MainApp.class, args);
}
#Override
public void start(Stage primaryStage)
{
primaryStage.setTitle("Example Dynamic Tree");
primaryStage.setResizable(true);
final VBox box = new VBox();
box.setFillWidth(false);
Scene scene = new Scene(box);
primaryStage.setScene(scene);
box.getChildren().add(this.getExampleTree());
primaryStage.show();
}
private TreeView<DynamicTreeNodeModel> getExampleTree()
{
DynamicTreeNodeModel rootNode = new RandomDynamicTreeNodeModel(null, "Root Node");
TreeView<DynamicTreeNodeModel> treeView = new TreeView<>();
treeView.setCellFactory(new Callback<TreeView<DynamicTreeNodeModel>, TreeCell<DynamicTreeNodeModel>>()
{
#Override
public TreeCell call(TreeView<DynamicTreeNodeModel> param)
{
return new DnDCell(param);
}
});
treeView.setPrefSize(1000, 750);
TreeItem rootItem = new TreeItem(rootNode);
branchExpandedEventHandler = new EventHandler<TreeModificationEvent<DynamicTreeNodeModel>>()
{
#Override
public void handle(TreeModificationEvent<DynamicTreeNodeModel> event)
{
// System.out.println("handling event " + event);
TreeItem<DynamicTreeNodeModel> item = event.getTreeItem();
populateTreeItem(item);
}
};
rootItem.addEventHandler(TreeItem.branchExpandedEvent(), branchExpandedEventHandler);
treeView.setShowRoot(true);
treeView.setRoot(rootItem);
populateTreeItem(rootItem);
rootItem.setExpanded(true);
// treeView.setCellFactory(new LearningTreeCellFactory());
return treeView;
}
private void populateTreeItem(TreeItem<DynamicTreeNodeModel> item)
{
DynamicTreeNodeModel node = item.getValue();
boolean isPopulated = node.isPopulated();
boolean areGrandChildrenPopulated = node.areChildenPopulated();
node.populateToDepth(2);
if (!isPopulated)
{
for (DynamicTreeNodeModel childNode : node.getChildren())
{
TreeItem childItem = new TreeItem(childNode);
childItem.addEventHandler(TreeItem.branchExpandedEvent(), branchExpandedEventHandler);
item.getChildren().add(childItem);
}
}
if (!areGrandChildrenPopulated)
{
int i = 0;
int size = node.getChildren().size();
for (TreeItem childItem : item.getChildren())
{
// get cooresponding node in the model
if (i < size)
{
DynamicTreeNodeModel childNode = node.getChildren().get(i);
i++;
for (DynamicTreeNodeModel grandChildNode : childNode.getChildren())
{
TreeItem grandChildItem = new TreeItem(grandChildNode);
grandChildItem.addEventHandler(TreeItem.branchExpandedEvent(), branchExpandedEventHandler);
childItem.getChildren().add(grandChildItem);
}
}
}
}
}
private static interface DynamicTreeNodeModel
{
public String getName();
public void setName(String name);
public boolean isPopulated();
public boolean areChildenPopulated();
public List<DynamicTreeNodeModel> getChildren();
public void setChildren(List<DynamicTreeNodeModel> children);
public DynamicTreeNodeModel getParent();
public void setParent(DynamicTreeNodeModel parent);
public void populateToDepth(int depth);
#Override
public String toString();
}
private static class RandomDynamicTreeNodeModel implements DynamicTreeNodeModel
{
private DynamicTreeNodeModel parent;
private String name;
private List<DynamicTreeNodeModel> children = null;
public RandomDynamicTreeNodeModel(DynamicTreeNodeModel parent, String name)
{
this.parent = parent;
this.name = name;
}
#Override
public String getName()
{
return name;
}
#Override
public void setName(String name)
{
this.name = name;
}
#Override
public boolean isPopulated()
{
if (children == null)
{
return false;
}
return true;
}
#Override
public boolean areChildenPopulated()
{
if (!this.isPopulated())
{
return false;
}
for (DynamicTreeNodeModel child : this.children)
{
if (!child.isPopulated())
{
return false;
}
}
return true;
}
#Override
public List<DynamicTreeNodeModel> getChildren()
{
return children;
}
#Override
public void setChildren(List<DynamicTreeNodeModel> children)
{
this.children = children;
}
#Override
public DynamicTreeNodeModel getParent()
{
return parent;
}
#Override
public void setParent(DynamicTreeNodeModel parent)
{
this.parent = parent;
}
private static Random random = new Random();
#Override
public void populateToDepth(int depth)
{
if (depth <= 0)
{
return;
}
if (children == null)
{
int num = random.nextInt(5);
System.out.println("Random number " + num);
children = new ArrayList(num);
for (int i = 0; i < num; i++)
{
// children.add(new RandomDynamicTreeNodeModel(this, "child " + i));
children.add(new RandomDynamicTreeNodeModel(this, "child " + System.currentTimeMillis()));
try
{
Thread.sleep(100);
}
catch (InterruptedException ex)
{
Logger.getLogger(MainApp.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
int childDepth = depth - 1;
for (DynamicTreeNodeModel child : children)
{
child.populateToDepth(childDepth);
}
}
#Override
public String toString()
{
return this.name;
}
}
public class DnDCell extends TreeCell<DynamicTreeNodeModel>
{
private TreeView<DynamicTreeNodeModel> parentTree;
public DnDCell(final TreeView<DynamicTreeNodeModel> parentTree)
{
this.parentTree = parentTree;
// ON SOURCE NODE.
setOnDragDetected(new EventHandler<MouseEvent>()
{
#Override
public void handle(MouseEvent event)
{
System.out.println("Drag detected on " + item);
if (item == null)
{
return;
}
Dragboard dragBoard = startDragAndDrop(TransferMode.MOVE);
ClipboardContent content = new ClipboardContent();
content.put(DataFormat.PLAIN_TEXT, item.toString());
dragBoard.setContent(content);
event.consume();
}
});
setOnDragDone(new EventHandler<DragEvent>()
{
#Override
public void handle(DragEvent dragEvent)
{
System.out.println("Drag done on " + item);
dragEvent.consume();
}
});
// ON TARGET NODE.
// setOnDragEntered(new EventHandler<DragEvent>() {
// #Override
// public void handle(DragEvent dragEvent) {
// System.out.println("Drag entered on " + item);
// dragEvent.consume();
// }
// });
setOnDragOver(new EventHandler<DragEvent>()
{
#Override
public void handle(DragEvent dragEvent)
{
System.out.println("Drag over on " + item);
if (dragEvent.getDragboard().hasString())
{
String valueToMove = dragEvent.getDragboard().getString();
if (!valueToMove.matches(item.getName()))
{
// We accept the transfer!!!!!
dragEvent.acceptTransferModes(TransferMode.MOVE);
}
}
dragEvent.consume();
}
});
// setOnDragExited(new EventHandler<DragEvent>() {
// #Override
// public void handle(DragEvent dragEvent) {
// System.out.println("Drag exited on " + item);
// dragEvent.consume();
// }
// });
setOnDragDropped(new EventHandler<DragEvent>()
{
#Override
public void handle(DragEvent dragEvent)
{
System.out.println("Drag dropped on " + item);
String valueToMove = dragEvent.getDragboard().getString();
TreeItem<DynamicTreeNodeModel> itemToMove = search(parentTree.getRoot(), valueToMove);
TreeItem<DynamicTreeNodeModel> newParent = search(parentTree.getRoot(), item.getName());
// Remove from former parent.
itemToMove.getParent().getChildren().remove(itemToMove);
// Add to new parent.
newParent.getChildren().add(itemToMove);
newParent.setExpanded(true);
dragEvent.consume();
}
});
}
private TreeItem<DynamicTreeNodeModel> search(final TreeItem<DynamicTreeNodeModel> currentNode, final String valueToSearch)
{
TreeItem<DynamicTreeNodeModel> result = null;
if (currentNode.getValue().getName().matches(valueToSearch))
{
result = currentNode;
}
else if (!currentNode.isLeaf())
{
for (TreeItem<DynamicTreeNodeModel> child : currentNode.getChildren())
{
result = search(child, valueToSearch);
if (result != null)
{
break;
}
}
}
return result;
}
private DynamicTreeNodeModel item;
#Override
protected void updateItem(DynamicTreeNodeModel item, boolean empty)
{
super.updateItem(item, empty);
this.item = item;
String text = (item == null) ? null : item.toString();
setText(text);
}
}
}
Can you help me to fix the issue?

Bug report: RT-38641 Unknown error 0x80DE0001.
Developer (Anthony Petrov) notes:
I can reproduce the bug on the latest 8u40 builds.
Suggested developer workaround:
Use TransferMode.COPY instead of TransferMode.MOVE when initiating a
DnD operation."

Related

FloodFill method not working properly. (Recursion)

I am trying to make minesweeper game. Everything is working fine except the floodFill method. Once the floodFill method reveals one number, the recursion stops. I do not want the recursion to stop but go on so that it checks other neighbors as well but it does not. I am not sure what I am doing wrong.
package zProject_MineSweeper;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.*;
import javax.swing.JPanel;
public class MyPanel extends JPanel{
/**
*
*/
private static final long serialVersionUID = 1L;
static final int screenW = 600;
static final int screenH = 600;
static final int unitSize = 40;
static final int rowsNum = screenW/unitSize;
static final int colsNum = screenH/unitSize;
// In this code i have defined bomb as -5
static final int bombNum = -5;
static final int bombGap = 10;
static final double bombProb = 0.05;
static final int fontSize = 20;
int[][] values;
boolean[][] path;
Random random;
MyPanel(){
initializeAll();
initializeValues();
}
private void initializeAll() {
this.addMouseListener(new MyMouseListeners());
this.setPreferredSize(new Dimension(screenW,screenH));
this.setFocusable(true);
this.setBackground(new Color(200,200,200));
random = new Random();
values = new int[rowsNum][colsNum];
path = new boolean[rowsNum][colsNum];
}
private void initializeValues() {
double randomBombProb;
for(int i=0; i<rowsNum; i++) {
for(int j=0; j<colsNum; j++) {
path[i][j] = false;
}
}
for(int i=0; i<rowsNum; i++) {
for(int j=0; j<colsNum; j++) {
randomBombProb = random.nextDouble();
if (randomBombProb< bombProb) {
values[i][j] = bombNum;
}
}
}
for(int i=0; i<rowsNum; i++) {
for(int j=0; j<colsNum; j++) {
if (values[i][j] != bombNum) {
setNumbers(i,j);
}
}
}
}
private void setNumbers(int i, int j) {
//Check number of bombs near each node
int sum = 0;
for(int x=-1; x<2; x++) {
for(int y=-1; y<2; y++) {
int rowx = (i + x + rowsNum) / rowsNum;
int coly = (j + y + colsNum) / colsNum;
if (rowx==1 && coly==1) {
if(values[i+x][j+y] == bombNum) {
sum++;
}
}
}
}
values[i][j] = sum;
}
public void floodFill(int i, int j) {
if(values[i][j]==0) {
for(int x=-1; x<2; x++) {
for(int y=-1; y<2; y++) {
int rowx = (i + x + rowsNum)/rowsNum;
int coly = (j + y + colsNum)/colsNum;
if (rowx == 1 && coly == 1 && !path[i][j]) {
path[i][j] = true;
floodFill(i+x,j+y);
}
}
}
}
else {
path[i][j] = true;
}
}
#Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
draw(g);
}
private void draw(Graphics g) {
g.setFont(new Font("Times Roman", Font.BOLD, fontSize));
FontMetrics metrics = getFontMetrics(g.getFont());
for(int i=0; i<rowsNum; i++) {
for(int j=0; j<colsNum; j++) {
if (path[i][j]==true) {
drawValue(g,metrics,i,j);
}
else {
g.setColor(new Color(120,120,120));
g.fillRect(i*unitSize, j*unitSize, unitSize, unitSize);
}
}
}
drawGrid(g);
}
private void drawValue(Graphics g, FontMetrics metrics,int i, int j) {
// Centering the numbers in each cell
if (values[i][j] != bombNum) {
g.setColor(new Color(10,10,10));
g.drawString("" + values[i][j],
i*unitSize + unitSize/2 - metrics.stringWidth("" + values[i][j])/2,
j*unitSize + unitSize/2 + fontSize/2);
}
else {
g.setColor(Color.RED);
g.fillOval(i*unitSize+bombGap, j*unitSize+bombGap, unitSize-(2*bombGap), unitSize-(2*bombGap));
}
}
private void drawGrid(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(new BasicStroke(2));
g2.setColor(new Color(10,10,10));
for(int i=0; i<rowsNum; i++) {
g2.drawLine(unitSize*i, 0, unitSize*i, screenH);
}
for(int i=0; i<colsNum; i++) {
g2.drawLine(0, unitSize*i, screenW, unitSize*i);
}
}
public class MyMouseListeners implements MouseListener {
public void mouseClicked(MouseEvent e) {
if(e.getButton() == 1) {
int i = e.getX()/unitSize;
int j = e.getY()/unitSize;
floodFill(i, j);
repaint();
}
}
#Override
public void mousePressed(MouseEvent e) {
}
#Override
public void mouseReleased(MouseEvent e) {
}
#Override
public void mouseEntered(MouseEvent e) {
}
#Override
public void mouseExited(MouseEvent e) {
}
}
}

OrientDB: How to query a graph using dijkstra function while ignoring some edges

I am trying to query data from orientdb while ignoring some edges.
My query has the form:
select expand(dijkstra(#12:15,#12:20,'property','both'))
but as mentioned I want to ignore some edges of the graph.
Are there any suggestions?
Edit
Here is my graph structure .
Station as Vertex
Image Click
Path as Edge
Image Click
Thank you #Ivan Mainetti so much for answer i have try the testing main()
Here is my main()
String nomeDb = "Demo2";
try {
System.out.println("Before connect OServerAdmin");
OServerAdmin serverAdmin = new OServerAdmin("remote:128.199.xxx.xxx/"+nomeDb).connect("admin","password");
System.out.println("After connect");
if(serverAdmin.existsDatabase()){ // il db esiste
System.out.println("in if");
//connessione a db
OrientGraph g = new OrientGraph("remote:128.199.xxx.xxx/"+nomeDb);
DijkstraExcl d = new DijkstraExcl(g, "Path", "distance");
Set<String> ex =new HashSet<String>();
//------------------------------------------------
Vertex start = g.getVertex("#12:6");
Vertex end = g.getVertex("#12:11");
ex.add("#13:0");
Direction direction = Direction.OUT;
System.out.println(d.getPath(start,end,direction,ex));
System.out.println(d.getPathString(start,end,direction,ex));
System.out.println(d.getWeight(start,end,direction,ex));
//------------------------------------------------
//chiude db
g.shutdown();
}
else{
System.out.println("Il database '"+ nomeDb + "' non esiste");
}
serverAdmin.close();
} catch (IOException e) {
e.printStackTrace();
}
and the result after run the main() is
null
null
2147483647
The correct answer after ignore [#13:0] should be
[#12:6,#12:8,#12:10,#12:11]
Try the following JS function that has as parameters ridFrom, ridTo, property, direction and excludeEdges.
With Studio you can try it with this command:
select expand(result) from (select myFunction("12:6","12:11","distance","out","[#13:0]") as result)
The edges "edge1" and "edge2" are ignored.
var g=orient.getGraph();
var listEdges=excludeEdges.substring(1,excludeEdges.length-1).split(",");
var S=[], T=[] , id_weigth=[] , from , to , infinity = Number.MAX_VALUE;
step1();
step2();
return getPath();
// Initialization
function step1() {
var selectFrom=g.command("sql","select from V where #rid ="+ ridFrom);
var selectTo=g.command("sql","select from V where #rid ="+ ridTo);
if(selectFrom.length>0 && selectTo.length>0){
from=selectFrom[0];
to=selectTo[0];
S.push(from);
var selectAll=g.command("sql","select from V");
for (i=0;i<selectAll.length;i++) {
if (selectAll[i].getId()!=from.getId())
T.push(selectAll[i]);
}
var index=1;
for (i=0;i<selectAll.length;i++) {
var id = selectAll[i].getId();
if (selectAll[i].getId()!= from.getId()) {
id_weigth[index] = {id:id,weigth:infinity};
index++;
}
else
id_weigth[0] = {id:id,weigth:0};
}
setWeigth_Direction(from);
}
}
// Assignment permanent label
function step2(){
var stop = true;
do {
stop = true;
for (i=0;i<T.length;i++) {
var id = T[i].getId();
for (j=0;j<id_weigth.length;j++) {
if (id_weigth[j].id==id) {
if (id_weigth[j].weigth != infinity){
stop = false;
}
}
}
}
if (stop == true)
break;
else {
var index2 = 0; minWeigth = 0; j = null;
for (i=0;i<T.length;i++) {
var id = T[i].getId();
for (m=0;m<id_weigth.length;m++) {
if (id_weigth[m].id==id) {
if (index2 == 0) {
minWeigth = id_weigth[m].weigth;
index2++;
j = T[i];
}
else if (id_weigth[m].weigth < minWeigth) {
minWeigth = id_weigth[m].weigth;
j = T[i];
}
}
}
}
T.splice(getPositionInT(j.getId()),1);
S.push(j);
if (T.length == 0)
break;
else
step3(j);
}
} while (stop == false);
}
// Assignment temporary label
function step3(j) {
setWeigth_Direction(j);
}
function setWeigth(vertex,direction1,direction2) {
var edges=g.command("sql","select expand(" + direction1+"E()) from "+ vertex.getId());
for(m=0;m<edges.length;m++){
var myEdge=edges[m];;
var idEdge = myEdge.getId().toString();
var validEdge=true;
for (s=0;s<listEdges.length;s++) {
if(listEdges[s]==idEdge)
validEdge=false;
}
if(validEdge==true){
var myWeigth = myEdge.getProperty(property);
var myVertex=g.command("sql","select expand("+ direction2 + ") from " +myEdge.getId());
var id = myVertex[0].getId();
if(vertex!=from){
for (p=0;p<T.length;p++) {
if (T[p].getId()==id) {
var id_weight_i = getId_Weigth(id);
var id_weight_j = getId_Weigth(j.getId());
var weigthi = id_weight_i.weigth;
var weigthj = id_weight_j.weigth;
if (weigthi > weigthj + myWeigth) {
id_weight_i.weigth=weigthj + myWeigth;
id_weight_i.previous=vertex;
}
}
}
}
else{
for (q=0;q<id_weigth.length;q++) {
if (id_weigth[q].id==id) {
id_weigth[q].weigth=myWeigth;
id_weigth[q].previous=vertex;
}
}
}
}
}
}
function getId_Weigth(id) {
for (l=0;l<id_weigth.length;l++) {
if (id_weigth[l].id==id)
return id_weigth[l];
}
return null;
}
function getPath(){
var validPath = true, temp = [], path = [];
temp.push(to);
var npm = getId_Weigth(to.getId());
var v = npm.previous;
while (v != from) {
temp.push(v);
if (v == null) {
validPath = false;
break;
}
npm = getId_Weigth(v.getId());
v = npm.previous;
}
if (validPath == true) {
temp.push(from);
for (i = temp.length - 1; i >= 0; i--)
path.push(temp[i]);
}
return path;
}
function setWeigth_Direction(vertex){
if (direction == "both"){
setWeigth(vertex,"in","out");
setWeigth(vertex,"out","in");
}
else if (direction == "in")
setWeigth(vertex,"in","out");
else
setWeigth(vertex,"out","in");
}
function getPositionInT(id){
for (l=0;l<T.length;l++) {
if(T[l].getId()==id)
return l;
}
return null;
}
I created this class that find the dijkstra path including the option of excluding a specific list of edges by rid number.
DijkstraExcl.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
public class DijkstraExcl {
private OrientGraph g; //grafh DB
private Set<String> S; //visited rids
private Set<String> T; //to visit rids
private Map<String,Integer> f; //f(i) < #rid, weight_to_get_to_#rid >
private Map<String,String> J; //J(i) < #rid, previous_node_in_the_shortest_path >
private String eClass; //edge class to use
private String prop; //weight property to use on the edge
public DijkstraExcl(OrientGraph g, String e, String p){
this.g= g;
this.eClass = e;
this.prop = p;
S = new HashSet<String>();
T = new HashSet<String>();
f = new HashMap<String,Integer>();
J = new HashMap<String,String>();
}
//private methods
// (Vertex start_vertex, Vertex dest_vertex, Direction.IN/OUT/BOTH, Set of edge rids to exclude)
private void findPath(Vertex startV, Vertex endV, Direction dir, Set<String> excludeEdgeRids){
//init
S.clear();
T.clear();
f.clear();
J.clear();
//step1
Iterator<Vertex> vertici = g.getVertices().iterator();
while(vertici.hasNext()){
Vertex ver = vertici.next();
f.put(ver.getId().toString(), Integer.MAX_VALUE);
T.add(ver.getId().toString());
}
f.put(startV.getId().toString(), 0); //f(startV) = 0
J.put(startV.getId().toString(), null); //J(startV) = null
T.remove(startV.getId().toString()); //startV visited => removed from T
S.add(startV.getId().toString()); // and added in S
Iterator<Vertex> near = startV.getVertices(dir, eClass).iterator();
while(near.hasNext()){
Vertex vicino = near.next();
J.put(vicino.getId().toString(), startV.getId().toString()); //J(i) = startV
f.put(vicino.getId().toString(), weight(startV.getId().toString(), vicino.getId().toString(),dir,excludeEdgeRids)); //f(i) = weight(startV, i)
}
//step2
Boolean cont = false;
Iterator<String> t = T.iterator();
while(t.hasNext()){
String i = t.next();
if(f.get(i)!=Integer.MAX_VALUE){
cont = true;
}
}
while(cont){
String j = startV.getId().toString();
Integer ff = Integer.MAX_VALUE;
t = T.iterator();
while(t.hasNext()){
String i = t.next();
if(f.get(i)<=ff){
ff = f.get(i);
j = i;
}
}
T.remove(j);
S.add(j);
if(T.isEmpty()){
break;
}
//step3
near = g.getVertex(j).getVertices(dir, eClass).iterator();
while(near.hasNext()){
Vertex vic = near.next();
String i = vic.getId().toString();
if( (T.contains(i)) && (f.get(i) > (f.get(j) + weight(j,i,dir,excludeEdgeRids))) ){
if(weight(j,i,dir,excludeEdgeRids)==Integer.MAX_VALUE){
f.put(i, Integer.MAX_VALUE);
}else{
f.put(i, (f.get(j) + weight(j,i,dir,excludeEdgeRids)));
}
J.put(i, j);
}
}
//shall we continue?
cont = false;
t = T.iterator();
while(t.hasNext()){
String i = t.next();
if(f.get(i)!=Integer.MAX_VALUE){
cont = true;
}
}
}
}
private int weight(String rid_a, String rid_b, Direction dir, Set<String> excl){ //in case of multiple/duplicate edges return the lightest
Integer d = Integer.MAX_VALUE;
Integer dd;
rid_b = "v["+rid_b+"]";
if(excl==null){
excl = new HashSet<String>();
}
Vertex a = g.getVertex(rid_a);
Iterator<Edge> eS = a.getEdges(dir, eClass).iterator();
Set<Edge> goodEdges = new HashSet<Edge>();
while(eS.hasNext()){
Edge e = eS.next();
if((e.getProperty("out").toString().equals(rid_b) || e.getProperty("in").toString().equals(rid_b)) && !excl.contains(e.getId().toString())){
goodEdges.add(e);
}
}
Iterator<Edge> edges= goodEdges.iterator();
while(edges.hasNext()){
Edge e=edges.next();
dd = e.getProperty(prop);
if(dd<d){
d=dd;
}
}
return d;
}
//public methods
public List<Vertex> getPath (Vertex startV, Vertex endV, Direction dir, Set<String> exclECl){
String j,i;
List<Vertex> ppp = new ArrayList<Vertex>();
List<Vertex> path = new ArrayList<Vertex>();
findPath(startV, endV, dir, exclECl);
i = endV.getId().toString();
path.add(endV);
if(f.get(endV.getId().toString()) == Integer.MAX_VALUE){
return null;
}
while(!i.equals(startV.getId().toString())){
j = J.get(i);
if(j == null){
return null;
}
path.add(g.getVertex(j));
i = j;
}
for(int a=0, b=path.size()-1;a<path.size();a++, b--){
ppp.add(a, path.get(b));
}
return ppp;
}
public List<String> getPathString (Vertex startV, Vertex endV, Direction dir, Set<String> exclECl){
List<String> pathS = new ArrayList<String>();
List<Vertex> path = getPath(startV, endV, dir, exclECl);
if(path == null){
return null;
}
for(Vertex v : path){
pathS.add(v.getId().toString());
}
return pathS;
}
public Integer getWeight(Vertex startV, Vertex endV, Direction dir, Set<String> exclECl){
findPath(startV, endV, dir,exclECl);
return f.get(endV.getId().toString());
}
}
and hers's a testing main:
public class test_dijkstra {
public static void main(String[] args) {
String nomeDb = "dijkstra_test";
try {
OServerAdmin serverAdmin = new OServerAdmin("remote:localhost/"+nomeDb).connect("root", "root");
if(serverAdmin.existsDatabase()){ // il db esiste
//connessione a db
OrientGraph g = new OrientGraph("remote:localhost/"+nomeDb);
DijkstraExcl d = new DijkstraExcl(g, "arco", "peso");
Set<String> ex =new HashSet<String>();
//------------------------------------------------
Vertex start = g.getVertex("#9:0");
Vertex end = g.getVertex("#9:5");
ex.add("#12:4");
Direction direction = Direction.BOTH;
System.out.println(d.getPath(start,end,direction,ex));
System.out.println(d.getPathString(start,end,direction,ex));
System.out.println(d.getWeight(start,end,direction,ex));
//------------------------------------------------
//chiude db
g.shutdown();
}
else{
System.out.println("Il database '"+ nomeDb + "' non esiste");
}
serverAdmin.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
and its output:
[v[#9:0], v[#9:1], v[#9:2], v[#9:4], v[#9:5]]
[#9:0, #9:1, #9:2, #9:4, #9:5]
10
Here's the structure of my test db:
One approach would be to use the fact that OrientDB has some support for "Infinity", as illustrated by this "console.sh" typescript:
> select 1.0E400
----+------+--------
# |#CLASS|1
----+------+--------
0 |null |Infinity
----+------+--------
> select eval('0 < 1.0E400')
----+------+----
# |#CLASS|eval
----+------+----
0 |null |true
----+------+----
> select -1.0E400
----+------+---------
# |#CLASS|-1
----+------+---------
0 |null |-Infinity
----+------+---------
> select eval('0 < -1.0E400')
----+------+-----
# |#CLASS|eval
----+------+-----
0 |null |false
----+------+-----

JavaFX TableView not Updating UI

I have a Tableview<ObservableList<Item>>, which is not updating when the underlying data is updated. Through debugging, I know that the underlying ObservableList<Item>> is being properly updated. I have ensured that all of Item's properties are visible, and in the format myFieldProperty().
Here is my table creation:
pattern= new TableView<>(mainApp.getItemList());
for (ObservableList<Item> row : pattern.getItems()) {
for (int i= pattern.getColumns().size(); i<row.size(); i++){
final int columnIndex = i ;
TableColumn<ObservableList<Item>, Color> column = new TableColumn<>();
column.setCellValueFactory( rowData ->
rowData.getValue()
.get(columnIndex).displayColorProperty()); // the Item for this cell
column.setCellFactory(col -> {
ItemCell cell = new ItemCell();
cell.setOnMouseEntered( e -> {
if (cell.getItem() != null) {
#SuppressWarnings("unchecked")
ObservableList<Item> stitchRow =
(ObservableList<Item>) cell.getTableRow().getItem();
mainApp.getRLController().setItemLabel(itemRow.get(columnIndex).toString());
}
});
cell.setOnMouseExited( e -> {
mainApp.getRLController().setItemLabel(null);
});
cell.setOnMouseClicked((MouseEvent e) -> {
Item newItem = mainApp.getTBController().getSelectedItem();
if (e.getButton() == MouseButton.PRIMARY && newItem != null) {
ObservableList<Item> itemRow =
(ObservableList<Item>) cell.getTableRow().getItem();
itemRow.set(columnIndex, newItem);
mainApp.getRLController().setItemLabel(itemRow.get(columnIndex).toString());
}
});
return cell;
});
column.setMinWidth(7);
column.setPrefWidth(7);
column.setMaxWidth(7);
pattern.getColumns().add(column);
}
}
pattern.setFixedCellSize(7);
pattern.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);`
Code for my Custom Cell Factory:
public class ItemCell extends TableCell<ObservableList<Item>, Color> {
#Override
protected void updateItem(Color color, boolean empty) {
super.updateItem(color, empty);
if (empty || color == null) {
setText(null);
setStyle(null);
} else {
int r = (int) (color.getRed() * 255);
int g = (int) (color.getGreen() * 255);
int b = (int) (color.getBlue() * 255);
this.setStyle("-fx-background-color: rgb(" + r + "," + g + "," + b + ");"
+ "-fx-border-color: black; -fx-table-cell-border-color: black;");
}
}
}
The basic problem is that the object you are changing (the item which is an element of the list representing the row) is not the property that the cell is observing for changes (the displayColorProperty() belonging to the item). You need to arrange to change the value of a property that the cell is observing.
Three possible solutions:
If possible, just change the displayColor (and other data too) of the item displayed by the cell. I.e.
cell.setOnMouseClicked((MouseEvent e) -> {
if (e.getButton() == MouseButton.PRIMARY && newItem != null) {
ObservableList<Item> itemRow =
(ObservableList<Item>) cell.getTableRow().getItem();
Item item = itemRow.get(columnIndex);
item.setDisplayColor(...);
item.set...(...);
// ...
mainApp.getRLController().setItemLabel(item.toString());
}
});
Or, replace the entire row:
cell.setOnMouseClicked((MouseEvent e) -> {
Item newItem = mainApp.getTBController().getSelectedItem();
if (e.getButton() == MouseButton.PRIMARY && newItem != null) {
ObservableList<Item> itemRow =
(ObservableList<Item>) cell.getTableRow().getItem();
ObservableList<Item> newRow = FXCollections.observableArrayList(itemRow);
newRow.set(columnIndex, newItem);
pattern.getItems().set(cell.getTableRow().getIndex(), newRow);
mainApp.getRLController().setItemLabel(newRow.get(columnIndex).toString());
}
});
Otherwise, you could make your table a TableView<ObservableList<ObjectProperty<Item>>>. This gets a little tricky but it's not too bad. This way you can just set the value of the object property to your new item.
Here's a complete example using the third technique:
import javafx.application.Application;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class ColorTableExample extends Application {
#Override
public void start(Stage primaryStage) {
TableView<ObservableList<ObjectProperty<Item>>> table = new TableView<>();
int NUM_ROWS = 20 ;
int NUM_COLS = 15 ;
ObservableList<ObservableList<ObjectProperty<Item>>> data = table.getItems() ;
for (int y = 0 ; y < NUM_ROWS; y++) {
ObservableList<ObjectProperty<Item>> row = FXCollections.observableArrayList();
data.add(row);
double saturation = (1.0 * y) / NUM_ROWS ;
for (int x = 0 ; x < NUM_COLS; x++) {
double hue = x * 360.0 / NUM_COLS ;
Color color = Color.hsb(hue, saturation, 1.0);
row.add(new SimpleObjectProperty<>(new Item(color)));
}
}
for (ObservableList<ObjectProperty<Item>> row : table.getItems()) {
for (int i = table.getColumns().size() ; i < row.size(); i++) {
int columnIndex = i ;
TableColumn<ObservableList<ObjectProperty<Item>>, Item> column = new TableColumn<>(Integer.toString(i+1));
column.setCellValueFactory(rowData -> rowData.getValue().get(columnIndex));
column.setCellFactory(c -> {
TableCell<ObservableList<ObjectProperty<Item>>, Item> cell = new TableCell<ObservableList<ObjectProperty<Item>>, Item>() {
#Override
public void updateItem(Item item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setStyle("");
} else {
Color color = item.getDisplayColor() ;
int r = (int) (color.getRed() * 255) ;
int g = (int) (color.getGreen() * 255) ;
int b = (int) (color.getBlue() * 255) ;
String style = String.format(
"-fx-background-color: rgb(%d, %d, %d);"
+ "-fx-border-color: black ;"
+ "-fx-table-cell-border-color: black ;"
,r, g, b);
setStyle(style);
}
}
};
cell.setOnMousePressed(evt -> {
if (! cell.isEmpty()) {
ObservableList<ObjectProperty<Item>> rowData = (ObservableList<ObjectProperty<Item>>) cell.getTableRow().getItem();
Color currentColor = cell.getItem().getDisplayColor();
double newHue = ( currentColor.getHue() + 15 ) % 360 ;
Color newColor = Color.hsb(newHue, currentColor.getSaturation(), currentColor.getBrightness());
rowData.get(columnIndex).set(new Item(newColor));
}
});
return cell ;
});
table.getColumns().add(column);
}
}
BorderPane root = new BorderPane(table, null, null, null, null);
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.show();
}
public static class Item {
private final ObjectProperty<Color> displayColor = new SimpleObjectProperty<>() ;
public Item(Color color) {
this.displayColorProperty().set(color);
}
public final ObjectProperty<Color> displayColorProperty() {
return this.displayColor;
}
public final javafx.scene.paint.Color getDisplayColor() {
return this.displayColorProperty().get();
}
public final void setDisplayColor(final javafx.scene.paint.Color displayColor) {
this.displayColorProperty().set(displayColor);
}
}
public static void main(String[] args) {
launch(args);
}
}
(At some point, it might be easier to refactor everything so that you have an actual class representing each row in the table, instead of using a list.)
There may also be a clever workaround using an extractor for the list, but I couldn't make that work.

Draw Map in JavaFX using of shapefile in gis

This is my code :
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;
import javafx.stage.Stage;
import org.nocrala.tools.gis.data.esri.shapefile.ShapeFileReader;
import org.nocrala.tools.gis.data.esri.shapefile.ValidationPreferences;
import org.nocrala.tools.gis.data.esri.shapefile.exception.InvalidShapeFileException;
import org.nocrala.tools.gis.data.esri.shapefile.header.ShapeFileHeader;
import org.nocrala.tools.gis.data.esri.shapefile.shape.AbstractShape;
import org.nocrala.tools.gis.data.esri.shapefile.shape.PointData;
import org.nocrala.tools.gis.data.esri.shapefile.shape.shapes.PolygonShape;
public class MakeMap extends Application
{
static FileInputStream is;
static ShapeFileReader read;
static ShapeFileHeader head;
static AbstractShape shape;
static ValidationPreferences prefs;
static double minLat;
static double minLon;
static double maxLat;
static double maxLon;
static double ratio;
static double bMinLat;
static double bMinLon;
static double bMaxLat;
static double bMaxLon;
int gapx = 0, gapy = 0;
public void makeRatio(double lon_max, double lon_min, double lat_max, double lat_min)
{
double x, y; x = lon_max - lon_min;
y = lat_max - lat_min;
x = 600 / x;
y = 600 / y; if (x < y)
{
ratio = x;
gapy = (int) ((600 - (lat_max - lat_min) * x) / 2);
} else {
ratio = y; gapx = (int) ((600 - (lon_max - lon_min) * y) / 2); } }
public void assignBoundary(double min_lon, double max_lon, double min_lat, double max_lat)
{
minLon = coActLon(min_lon) * ratio; maxLon = coActLon(max_lon) * ratio; minLat = coActLat(min_lat) * ratio;
maxLat = coActLat(max_lat) * ratio;
}
public double coActLat(double p)
{
p = bMaxLat - p; return p;
}
public double coActLon(double p)
{
p = p - bMinLon; return p;
}
public int assignBoundaryLon(double p)
{
p = coActLon(p) * ratio - minLon; p += gapx;
return (int) p;
}
public int assignBoundaryLat(double p)
{
p = coActLat(p) * ratio;
p = p - maxLat; p += gapy;
return (int) p;
}
#Override public void start(Stage stage) throws Exception
{ File file = new File("/home/ranu/world.shp");
Canvas canvas = new Canvas(600, 600);
GraphicsContext gc = canvas.getGraphicsContext2D();
try
{
is = new FileInputStream(file);
}
catch (FileNotFoundException e)
{ // TODO Auto-generated catch block
e.printStackTrace();
} prefs = new ValidationPreferences();
prefs.setMaxNumberOfPointsPerShape(33200);
try
{
read = new ShapeFileReader(is, prefs);
}
catch (InvalidShapeFileException | IOException e)
{ // TODO Auto-generated catch block e.printStackTrace(); }
head = read.getHeader();
bMaxLon = head.getBoxMaxX();
bMinLon = head.getBoxMinX();
bMaxLat = head.getBoxMaxY();
bMinLat = head.getBoxMinY();
makeRatio(head.getBoxMaxX(), head.getBoxMinX(), head.getBoxMaxY(), head.getBoxMinY());
assignBoundary(head.getBoxMinX(), head.getBoxMaxX(), head.getBoxMinY(), head.getBoxMaxY());
gc.setFill(Color.rgb(53, 153, 255));
gc.fillRect(gapx, gapy, (maxLon - minLon), (minLat - maxLat));
drawShape(gc);
StackPane root = new StackPane();
root.getChildren().add(canvas);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public void drawShape(GraphicsContext gc) throws IOException, InvalidShapeFileException
{
int i = 0; gc.setFill(Color.WHITE);
gc.setStroke(Color.LIGHTGREY); gc.setLineWidth(1);
gc.strokeLine(10, 20, 30, 40);
Polygon polygon = new Polygon();
polygon.getPoints().add(new Double(20.0));
int count = 0;
double[] lat;
double[] lon;
Double[] data; gc.setStroke(Color.LIGHTGRAY);
while ((shape = read.next()) != null && count < 360)
{ // System.out.println(shape);
switch (shape.getShapeType())
{
case POINT: // PointShape aPoint = (PointShape) shape;
// Do something with the point shape... break;
case MULTIPOINT_Z: // MultiPointZShape aMultiPointZ = (MultiPointZShape) shape;
// Do something with the MultiPointZ shape... break;
case POLYGON: PolygonShape aPolygon = (PolygonShape) shape;
lat = new double[aPolygon.getNumberOfPoints()];
lon = new double[aPolygon.getNumberOfPoints()];
data = new Double[aPolygon.getNumberOfPoints() * 2];
int j = 0;
double x, y;
PointData[] point = aPolygon.getPoints();
for (i = 0; i < aPolygon.getNumberOfPoints(); i++)
{
x = point[i].getX();
y = point[i].getY();
j = 0; lat[j] = this.assignBoundaryLat(point[i].getY());
lon[j] = this.assignBoundaryLon(point[i].getX());
// data[j++] = new // Double(this.assignBoundaryLon(point[i].getX()));
// data[j] = new // Double(this.assignBoundaryLon(point[i].getY()));
for (j = j + 1, i = i + 1; (x != point[i].getX() || y != point[i] .getY()) && i < aPolygon.getNumberOfPoints(); i++, j++)
{
// lat[j] = this.assignBoundaryLat(point[i].getY());
// lon[j] = this.assignBoundaryLon(point[i].getX());
// data[j++] = new // Double(this.assignBoundaryLat(point[i].getX()));
// data[j] = new // Double(this.assignBoundaryLat(point[i].getY())); }
System.out.println(lat.length + " " + lon.length + " " + j);
// Polygon pg = new Polygon();
// pg.getPoints().addAll(data);
gc.strokePolygon(lon, lat, j);
System.out.println(count);
count ++; }
break; default: break; } } }
public static void main(String[] args)
{ Application.launch(args); }
Problem have in this code :
130 130 129
0
514 514 513
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 512
at javafx.scene.canvas.GraphicsContext.writePoly(GraphicsContext.java:326)
at javafx.scene.canvas.GraphicsContext.strokePolygon(GraphicsContext.java:1591)
at Experiment.MakeMap.drawShape(MakeMap.java:199)
at Experiment.MakeMap.start(MakeMap.java:129)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:216)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication$3$1.run(GtkApplication.java:89)
... 1 more
https://drive.google.com/file/d/0B9nTZs5-E8czSEl4aXpwYjZhdUE/edit?usp=sharing world.shp
https://drive.google.com/file/d/0B9nTZs5-E8czT2RITnY5ZjFmTnM/edit?usp=sharing shapefilereader.jar

JFreechart filling sectors series

I am trying to create a filled series over each region of a polar plot. But the colors are not filled out right. Here is an image of what I get: http://i1122.photobucket.com/albums/l539/jpo2/polar-1.gif
Here is the code I have to loop through a given section is as follows:
if (i < 8) {
for(int r = 0; r< 20; r+=(NumberAxis) plot.getAxis()).getTickUnit().getSize()){
for(int theta = 0; theta <= 180; theta+=30){
XYSeries series = new XYSeries(i + "π/8 " + "< θ < 2π+" + i + "π/8");
for (int e = theta; e < theta+30; e++) {
series.add(90-e-i*45, r);
series.add(90-e-i*45, r- ((NumberAxis) plot.getAxis()).getTickUnit().getSize());
}
result.addSeries(series);
setFilled(result);
i++;
}
}
}
private void setFilled(XYDataset dataset) {
for (int i = 0; i < dataset.getSeriesCount(); i++) {
renderers.setSeriesFilled(i, true);
}
}
This is a modification of #trashgod's draw method at JFreechart Loop through polar chart sectors
Please help.
Full code:
import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTick;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.event.ChartProgressEvent;
import org.jfree.chart.event.ChartProgressListener;
import org.jfree.chart.plot.PolarPlot;
import org.jfree.chart.renderer.DefaultPolarItemRenderer;
import org.jfree.chart.renderer.PolarItemRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.TextAnchor;
public class tests extends JFrame implements ChartProgressListener {
private static final String title = "Archimedes' Spirals";
private XYSeriesCollection result = new XYSeriesCollection();
private DefaultPolarItemRenderer renderers = new DefaultPolarItemRenderer();
private int i;
public tests(String title) {
super(title);
JFreeChart chart = createChart(result);
ChartPanel panel = new ChartPanel(chart);
panel.setPreferredSize(new Dimension(500, 500));
panel.setMouseZoomable(false);
this.add(panel);
}
private JFreeChart createChart(XYDataset dataset) {
ValueAxis radiusAxis = new NumberAxis();
radiusAxis.setTickLabelsVisible(false);
PolarItemRenderer renderer = new DefaultPolarItemRenderer();
PolarPlot plot = new PolarPlot(dataset, radiusAxis, renderer) {
#Override
protected List refreshAngleTicks() {
List<NumberTick> ticks = new ArrayList<NumberTick>();
int delta = (int) this.getAngleTickUnit().getSize();
for (int t = 0; t < 360; t += delta) {
int tp = (360 + 90 - t) % 360;
NumberTick tick = new NumberTick(
Double.valueOf(t), String.valueOf(tp),
TextAnchor.CENTER, TextAnchor.CENTER, 0.0);
ticks.add(tick);
}
return ticks;
}
};
plot.setBackgroundPaint(new Color(0x00f0f0f0));
plot.setRadiusGridlinePaint(Color.gray);
plot.addCornerTextItem("r(θ) = θ; 0 < θ < 2π; +iπ/8");
setFilled(dataset);
plot.setRenderer(renderers);
JFreeChart chart = new JFreeChart(
title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
chart.setBackgroundPaint(Color.white);
chart.addProgressListener(this);
return chart;
}
public static void main(String[] args) {
tests demo = new tests(title);
demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
demo.pack();
demo.setLocationRelativeTo(null);
demo.setVisible(true);
}
#Override
public void chartProgress(ChartProgressEvent e) {
if (e.getType() == ChartProgressEvent.DRAWING_FINISHED) {
System.out.println(e);
JFreeChart chart = e.getChart();
draw();
}
}
public void draw() {
if (i < 4) {
for (int g = 0; g < 30; g += 5) {
for (int h = 0; h < 180; h += 45) {
XYSeries series = new XYSeries(i + "π/8 " + "< θ < 2π+" + i + "π/8");
for (int t = h; t <= h + 45; t++) {
series.add(90 - t, g);
series.add(90 - t, g + 5);
}
result.addSeries(series);
setFilled(result);
i++;
}
}
}
}
private void setFilled(XYDataset dataset) {
for (int i = 0; i < dataset.getSeriesCount(); i++) {
renderers.setSeriesFilled(i, true);
}
}
}
Here's a simplified version the uses PolarPlot directly, without any transformation. It might be easier to experiment with.
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PolarPlot;
import org.jfree.chart.renderer.DefaultPolarItemRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
/** #see http://stackoverflow.com/questions/6669734 */
public class PolarArcs {
private static final String title = "PolarArcs";
private static final double PI2 = 90d; // π/2 radians = 90°
private void display() {
JFrame f = new JFrame(title);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ChartPanel panel = new ChartPanel(createChart(createDataset()));
panel.setPreferredSize(new Dimension(400, 400));
f.add(panel);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
private JFreeChart createChart(XYDataset dataset) {
JFreeChart chart = ChartFactory.createPolarChart(
title, dataset, true, false, false);
PolarPlot plot = (PolarPlot) chart.getPlot();
plot.setBackgroundPaint(Color.white);
plot.setAngleGridlinesVisible(false);
plot.setRadiusGridlinesVisible(false);
DefaultPolarItemRenderer r = (DefaultPolarItemRenderer) plot.getRenderer();
for (int i = 0; i < dataset.getSeriesCount(); i++ ) {
r.setSeriesFilled(i, true);
}
NumberAxis rangeAxis = (NumberAxis) plot.getAxis();
rangeAxis.setTickLabelsVisible(false);
return chart;
}
private XYDataset createDataset() {
XYSeriesCollection result = new XYSeriesCollection();
for (int r = 8; r > 0; r--) {
XYSeries series = new XYSeries(title + String.valueOf(r));
for (int t = (int) -PI2; t <= PI2; t++) {
series.add(t, r);
}
result.addSeries(series);
}
return result;
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
new PolarArcs().display();
}
});
}
}

Resources