📄 pajeknode.java
字号:
//Skye Bender-deMoll draft translation code 2/13/01
//skyebend@bennington.edu
package PajekConverter;
import java.text.*;
import java.util.*;
public class PajekNode extends Object
{
//vars for pajek
private int pajekId; //numeric Id used by Pajek
private Vector arcsList = new Vector(); //array of out connection pajekIds
private Vector arcsColorList = new Vector();
private Vector arcsWidthList = new Vector();
private Vector arcsWeightList = new Vector();
private String label = ""; //text label to appear in pajek
//default values
private String shape = "default"; //shape of node
private String size = "default"; //relitive size of node
private String color = "default"; //name of pajek color of node
private String xCoord = "0.000"; //inital screen coordiates of node
private String yCoord = "0.000";
private String zCoord = "0.000";
//status vars
private boolean forOutput = true; //indicates whether this node is to be exported
private boolean error = false; //set if there is a parsing problem setting up the node
private String errorItems = ""; //indicates where the first error occured
public PajekNode(int id) //instatiates new node with only ID and defaults
{
pajekId = id;
}
public PajekNode(int id, String lbl) //new node with ID, label, and defualts
{
pajekId = id;
label = lbl;
}
public PajekNode(int id, int link, String newLabel, String newShape, String newSize, String newColor, String x, String y)
//new node with one link and all values except zCoord
{
pajekId = id;
addLink(link);
label = newLabel;
shape = newShape;
size = newSize;
color = newColor;
xCoord = x;
yCoord = y;
}
//-----------Accesors-------------------
//pajekId
public void setPajekId(int val)
{
pajekId = val;
}
public int getPajekId()
{
return pajekId;
}
//arcsList
public void addLink(int val)
{
arcsList.add(new Integer(val));
//check if link already exists, modify output so that they won't overlap
}
public int getLink(int index)
{
//returns int value of link at index, will throw exception if index out of range
Integer link = (Integer)arcsList.get(index);
return link.intValue();
}
public String getLinks()
{
//returns a space deliniated string of all link ids
String returnList = "";
Integer link;
for (int i=0; i<arcsList.size(); i++)
{
link = (Integer)arcsList.get(i);
returnList = returnList + link.intValue()+" ";
}
return returnList;
}
//arcsColorList
public void addArcColor(String str)
{
arcsColorList.add(str);
}
public String getArcColor(int index)
{
//returns string for the color catagory of the link at index, will throw exception if index out of range
String color = (String)arcsColorList.get(index);
return color;
}
//arcsWidthList
public void addArcWidth(double width)
{
arcsWidthList.add(new Double(width));
}
public double getArcWidth(int index)
{
//returns double value of link at index, will throw exception if index out of range
Double width = (Double)arcsWidthList.get(index);
return width.doubleValue();
}
//arcsWeightList
public void addArcWeight(double weight)
{
arcsWeightList.add(new Double(weight));
}
public double getArcWeight(int index)
{
//returns double value of link at index, will throw exception if index out of range
Double weight = (Double)arcsWeightList.get(index);
return weight.doubleValue();
}
//label
public void setLabel(String str)
{
label = str;
}
public String getLabel()
{
return label;
}
// size
public void setSize(String str)
{
size = str;
}
public String getSize()
{
return size;
}
//color
public void setColor(String str)
{
color = str;
}
public String getColor()
{
return color;
}
//shape
public void setShape(String str)
{
shape = str;
}
public String getShape()
{
return shape;
}
//xCoord
public void setXCoord(String str)
{
xCoord = str;
}
public String getXCoord()
{
return xCoord;
}
//yCoord
public void setYCoord(String str)
{
yCoord = str;
}
public String getYCoord()
{
return yCoord;
}
//zCoord
public void setZCoord(String str)
{
zCoord = str;
}
public String getZCoord()
{
return zCoord;
}
//forOutput
public boolean isForOutput()
{
return forOutput;
}
//error
public boolean isError()
{
return error;
}
//errorItems
public String getErrorItems()
{
return errorItems;
}
//-----------METHODS------------------
//toPajekNodeString returns a string describing the node formatted for pajek
public String toPajekNodeString()
{
String nodeString = " "+pajekId+" \""+label+"\" "+xCoord+" "+yCoord+
" "+shape+" x_fact "+size+" y_fact "+size+" ic "+color+" bw 0.5\r";
return nodeString;
}
//toPajekArcString returns a string describing each of the arcs of the node, formatted for pajek
public String toPajekArcString()
{
String arcString ="";
if (arcsList.size() > 0)
{
//loop over links, adding them to string with ID
for (int i=0; i<arcsList.size(); i++)
{
//width is used both as the width and as a value for the weight
arcString += " "+pajekId+" "+((Integer)arcsList.get(i)).toString()+" "+ //link
((Double)arcsWeightList.get(i)).toString()+ //value
" w "+((Double)arcsWidthList.get(i)).toString()+ //width
" c "+(String)arcsColorList.get(i)+"\r"; //color
}
}
return arcString;
}
//-----------Utility Methods ----------
//to string
public String toString()
{
String returnString = pajekId+"\t"+getLinks().toString()+"\t"+label+"\t"+shape+"\t"+size+"\t"+color+"\t"+xCoord+"\t"+yCoord+"\t"+zCoord+"\n";
return returnString;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -