📄 datalayer.java
字号:
String nameInput = null;
double nameOffsetYInput = 0;
double nameOffsetXInput = 0;
double rate = 1.0;
boolean timedTransition;
int angle = 0;
String positionXTempStorage = inputTransitionElement.getAttribute("positionX");
String positionYTempStorage = inputTransitionElement.getAttribute("positionY");
String idTempStorage = inputTransitionElement.getAttribute("id");
String nameTempStorage = inputTransitionElement.getAttribute("name");
String nameOffsetYTempStorage = inputTransitionElement.getAttribute("nameOffsetX");
String nameOffsetXTempStorage = inputTransitionElement.getAttribute("nameOffsetY");
String nameRate = inputTransitionElement.getAttribute("rate");
String nameTimed = inputTransitionElement.getAttribute("timed");
String nameAngle = inputTransitionElement.getAttribute("angle");
if (nameTimed.length() == 0)
timedTransition = false;
else if (nameTimed.length()== 5)
timedTransition = false;
else
timedTransition = true;
if (positionXTempStorage.length() > 0)
positionXInput = Double.valueOf(positionXTempStorage).doubleValue()*(false ? DISPLAY_SCALE_FACTORX : 1)+(false ? DISPLAY_SHIFT_FACTORX : 1);
if (positionYTempStorage.length() > 0)
positionYInput = Double.valueOf(positionYTempStorage).doubleValue()*(false ? DISPLAY_SCALE_FACTORY : 1)+(false ? DISPLAY_SHIFT_FACTORY : 1);
if (idTempStorage.length() > 0)
idInput = idTempStorage;
else if (nameTempStorage.length() > 0)
idInput = nameTempStorage;
if (nameTempStorage.length() > 0)
nameInput = nameTempStorage;
else if (idTempStorage.length() > 0)
nameInput = idTempStorage;
if (nameOffsetXTempStorage.length() > 0)
nameOffsetXInput = Double.valueOf(nameOffsetXTempStorage).doubleValue();
if (nameOffsetYTempStorage.length() > 0)
nameOffsetYInput = Double.valueOf(nameOffsetYTempStorage).doubleValue();
if (nameRate.length()== 0)
{
nameRate = "1.0";
}
if (nameRate != "1.0"){
rate = Double.valueOf(nameRate).doubleValue();}
else
rate = 1.0;
if (nameAngle.length()>0)
angle = Integer.valueOf(nameAngle).intValue();
// Pete: Removed colour properties
positionXInput+=PLACE_TRANSITION_HEIGHT/2-1;
positionYInput+=PLACE_TRANSITION_HEIGHT/2-1;
return new Transition(positionXInput, positionYInput, idInput, nameInput, nameOffsetXInput, nameOffsetYInput, rate , timedTransition, angle);
}
/**
* Creates a Arc object from a Arc DOM Element
*
* @param inputArcElement Input Arc DOM Element
* @return Arc Object
*/
private Arc createArc(Element inputArcElement){
String idInput = null;
String sourceInput = null;
String targetInput = null;
int weightInput = 1;
double inscriptionOffsetXInput = 0;
double inscriptionOffsetYInput = 0;
double startX = 0;
double startY = 0;
double endX = 0;
double endY = 0;
sourceInput = inputArcElement.getAttribute("source");
targetInput = inputArcElement.getAttribute("target");
String idTempStorage = inputArcElement.getAttribute("id");
String sourceTempStorage = inputArcElement.getAttribute("source");
String targetTempStorage = inputArcElement.getAttribute("target");
String inscriptionTempStorage = inputArcElement.getAttribute("inscription");
// String inscriptionOffsetXTempStorage = inputArcElement.getAttribute("inscriptionOffsetX");
// String inscriptionOffsetYTempStorage = inputArcElement.getAttribute("inscriptionOffsetY");
if (idTempStorage.length() > 0)
idInput = idTempStorage;
if (sourceTempStorage.length() > 0)
sourceInput = sourceTempStorage;
if (targetTempStorage.length() > 0)
targetInput = targetTempStorage;
if (inscriptionTempStorage.length() > 0)
weightInput = Integer.valueOf((inputArcElement.getAttribute("inscription") != null ? inputArcElement.getAttribute("inscription") : "1")).intValue();
// if (inscriptionOffsetXTempStorage.length() > 0)
// inscriptionOffsetXInput = Double.valueOf(inputArcElement.getAttribute("inscriptionOffsetX")).doubleValue();
// if (inscriptionOffsetYTempStorage.length() > 0)
// inscriptionOffsetYInput = Double.valueOf(inputArcElement.getAttribute("inscriptionOffsetY")).doubleValue();
if (sourceInput.length() > 0) {
if (getPlaceTransitionObject(sourceInput) != null) {
// System.out.println("PNMLDATA: sourceInput is not null");
startX = getPlaceTransitionObject(sourceInput).getPositionX();
startX += getPlaceTransitionObject(sourceInput).centreOffsetLeft();
startY = getPlaceTransitionObject(sourceInput).getPositionY();
startY += getPlaceTransitionObject(sourceInput).centreOffsetTop();
}
}
if (targetInput.length() > 0) {
if (getPlaceTransitionObject(targetInput) != null) {
// System.out.println("PNMLDATA: targetInput is not null");
endX = getPlaceTransitionObject(targetInput).getPositionX();
endY = getPlaceTransitionObject(targetInput).getPositionY();
}
}
PlaceTransitionObject sourceIn = getPlaceTransitionObject(sourceInput);
PlaceTransitionObject targetIn = getPlaceTransitionObject(targetInput);
int aStartx;
int aStarty;
int aEndx;
int aEndy;
aStartx = sourceIn.getX();
aStarty = sourceIn.getY();
// add the insets and offset
aStartx += sourceIn.centreOffsetLeft();
aStarty += sourceIn.centreOffsetTop();
aEndx = targetIn.getX();
aEndy = targetIn.getY();
aEndx += targetIn.centreOffsetLeft();
aEndy += targetIn.centreOffsetTop();
double _startx = aStartx;
double _starty = aStarty;
double _endx = aEndx;
double _endy = aEndy;
//TODO
Arc tempArc = new Arc(_startx, _starty, _endx, _endy, sourceIn, targetIn, weightInput, idInput, Color.BLACK);
getPlaceTransitionObject(sourceInput).addConnectFrom(tempArc);
getPlaceTransitionObject(targetInput).addConnectTo(tempArc);
//**********************************************************************************
//The following section attempts to load and display arcpath details****************
// ArcPath tempArcPath = tempArc.getArcPath();
float arcPointX = 0;
float arcPointY = 0;
boolean arcPointType = false;
String arcTempX = null;
String arcTempY = null;
String arcTempType = null;
Node node = null;
NodeList nodelist = null;
nodelist = inputArcElement.getChildNodes();
if (nodelist.getLength()>0) {
tempArc.getArcPath().purgePathPoints();
for (int i = 1; i < nodelist.getLength()-1; i++) {
node = nodelist.item(i);
if(node instanceof Element) {
Element element = (Element)node;
if ("arcpath".equals(element.getNodeName())){
arcTempX = element.getAttribute("x");
arcTempY = element.getAttribute("y");
arcTempType = element.getAttribute("arcPointType");
arcPointX = Float.valueOf(arcTempX).floatValue();
arcPointY = Float.valueOf(arcTempY).floatValue();
arcPointX+=ARC_CONTROL_POINT_CONSTANT+1;
arcPointY+=ARC_CONTROL_POINT_CONSTANT+1;
arcPointType = Boolean.valueOf(arcTempType).booleanValue();
tempArc.getArcPath().addPoint(arcPointX,arcPointY,arcPointType);
}
}
}
}
//Arc path creation ends here***************************************************************
//******************************************************************************************
return tempArc;
}
/**
* Creates a Place Element for a PNML Petri-Net DOM
*
* @param inputPlace Input Place
* @param document Any DOM to enable creation of Elements and Attributes
* @return Place Element for a PNML Petri-Net DOM
*/
private Element createPlaceElement(Place inputPlace, Document document){
Element placeElement = null;
if(document != null) {
placeElement = document.createElement("place");
}
if(inputPlace != null ) {
Integer attrValue = null;
Double positionXInput = inputPlace.getPositionXObject();
Double positionYInput = inputPlace.getPositionYObject();
String idInput = inputPlace.getId();
String nameInput = inputPlace.getName();
// Double nameOffsetYInput = inputPlace.getNameOffsetXObject();
// Double nameOffsetXInput = inputPlace.getNameOffsetXObject();
Integer initialMarkingInput = inputPlace.getCurrentMarkingObject();
Double markingOffsetXInput = inputPlace.getMarkingOffsetXObject();
Double markingOffsetYInput = inputPlace.getMarkingOffsetYObject();
placeElement.setAttribute("positionX", (positionXInput != null ? String.valueOf(positionXInput) : ""));
placeElement.setAttribute("positionY", (positionYInput != null ? String.valueOf(positionYInput) : ""));
placeElement.setAttribute("name", (nameInput != null ? nameInput : (idInput != null && idInput.length() > 0? idInput : "")));
placeElement.setAttribute("id", (idInput != null ? idInput : "error"));
// placeElement.setAttribute("nameOffsetX", (nameOffsetXInput != null ? String.valueOf(nameOffsetXInput) : ""));
// placeElement.setAttribute("nameOffsetY", (nameOffsetYInput != null ? String.valueOf(nameOffsetYInput) : ""));
placeElement.setAttribute("initialMarking", (initialMarkingInput != null ? String.valueOf(initialMarkingInput) : "0"));
placeElement.setAttribute("markingOffsetX", (markingOffsetXInput != null ? String.valueOf(markingOffsetXInput) : ""));
placeElement.setAttribute("markingOffsetY", (markingOffsetYInput != null ? String.valueOf(markingOffsetYInput) : ""));
}
return placeElement;
}
/**
* Creates a Place Element for a PNML Petri-Net DOM
*
* @param inputPlace Input Place
* @param document Any DOM to enable creation of Elements and Attributes
* @return Place Element for a PNML Petri-Net DOM
*/
private Element createAnnotationNoteElement(AnnotationNote inputLabel, Document document){
Element labelElement = null;
if(document != null) {
labelElement = document.createElement("labels");
}
if(inputLabel != null ) {
int positionXInput = inputLabel.getX();
int positionYInput = inputLabel.getY();
int widthInput = inputLabel.getNoteWidth();
int heightInput = inputLabel.getNoteHeight();
String nameInput = inputLabel.getNoteText();
boolean borderInput = inputLabel.isShowingBorder();
labelElement.setAttribute("positionX", (positionXInput >= 0.0 ? String.valueOf(positionXInput) : ""));
labelElement.setAttribute("positionY", (positionYInput >= 0.0 ? String.valueOf(positionYInput) : ""));
labelElement.setAttribute("width", (widthInput>=0.0? String.valueOf(widthInput):""));
labelElement.setAttribute("height", (heightInput>=0.0? String.valueOf(heightInput):""));
labelElement.setAttribute("border",String.valueOf(borderInput));
labelElement.setAttribute("text", (nameInput != null ? nameInput : ""));
}
return labelElement;
}
/**
* Creates a Transition Element for a PNML Petri-Net DOM
*
* @param inputTransition Input Transition
* @param document Any DOM to enable creation of Elements and Attributes
* @return Transition Element for a PNML Petri-Net DOM
*/
private Element createTransitionElement(Transition inputTransition, Document document){
Element transitionElement = null;
if(document != null) {
transitionElement = document.createElement("transition");
}
if(inputTransition != null ) {
Integer attrValue = null;
Double positionXInput = inputTransition.getPositionXObject();
Double positionYInput = inputTransition.getPositionYObject();
String idInput = inputTransition.getId();
String nameInput = inputTransition.getName();
double aRate = inputTransition.getRate();
boolean timedTrans = inputTransition.getTimed();
int orientation = inputTransition.getAngle();
transitionElement.setAttribute("positionX", (positionXInput != null ? String.valueOf(positionXInput) : ""));
transitionElement.setAttribute("positionY", (positionYInput != null ? String.valueOf(positionYInput) : ""));
transitionElement.setAttribute("name", (nameInput != null ? nameInput : (idInput != null && idInput.length() > 0? idInput : "")));
transitionElement.setAttribute("id", (idInput != null ? idInput : "error"));
transitionElement.setAttribute("rate", (aRate != 1 ? String.valueOf(aRate):"1.0"));
transitionElement.setAttribute("timed", String.valueOf(timedTrans));
transitionElement.setAttribute("angle", String.valueOf(orientation));
}
return transitionElement;
}
/**
* Creates a Arc Element for a PNML Petri-Net DOM
*
* @param inputArc Input Arc
* @param document Any DOM to enable creation of Elements and Attributes
* @return Arc Element for a PNML Petri-Net DOM
*/
private Element createArcElement(Arc inputArc, Document document){
Element arcElement = null;
if(document != null) {
arcElement = document.createElement("arc");
}
if(inputArc != null ) {
Integer attrValue = null;
double positionXInputD = (int)inputArc.getStartPositionX();
Double positionXInput = new Double (positionXInputD);
double positionYInputD = (int)inputArc.getStartPositionY();
Double positionYInput = new Double (positionXInputD);
String idInput = inputArc.getId();
String sourceInput = inputArc.getSource().getId();
String targetInput = inputArc.getTarget().getId();
int inscriptionInput = (inputArc != null ? inputArc.getWeight() : 1);
// Double inscriptionPositionXInput = inputArc.getInscriptionOffsetXObject();
// Double inscriptionPositionYInput = inputArc.getInscriptionOffsetYObject();
arcElement.setAttribute("id", (idInput != null ? idInput : "error"));
arcElement.setAttribute("source", (sourceInput != null ? sourceInput : ""));
arcElement.setAttribute("target", (targetInput != null ? targetInput : ""));
arcElement.setAttribute("inscription", Integer.toString(inscriptionInput));
// arcElement.setAttribute("inscriptionOffsetX", (inscriptionPositionXInput != null ? String.valueOf(inscriptionPositionXInput) : ""));
// arcElement.setAttribute("inscriptionOffsetY", (inscriptionPositionYInput != null ? String.valueOf(inscriptionPositionYInput) : ""));
}
return arcElement;
}
private Element createArcPoint(String x, String y, String type, Document document, int id) {
Element arcPoint = null;
if (document != null) {
arcPoint = document.createElement("arcpath");
}
String pointId = String.valueOf(id);
if (pointId.length() < 3)
pointId = "0" + pointId;
if (pointId.length() < 3)
pointId = "0" + pointId;
arcPoint.setAttribute("id", pointId);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -