Skip to content
Snippets Groups Projects
AvatarPanelDrawer.java 44.7 KiB
Newer Older
					bl.addAttribute(new TAttribute(0, attr.getName(), attr.getType().getDefaultInitialValue(), type));
				}
				if (attr.getName().contains("key_") || attr.getName().contains("privKey_")) {
					hasCrypto = true;
					bl.addCryptoElements();
				}
			}
		}

		for (AvatarAttribute attr : ab.getConstants()) {
			int type = 5;
			if (attr.getType() == AvatarType.BOOLEAN) {
				type = 4;
			}
			if (attr.getType() == AvatarType.INTEGER) {
				type = 0;
			}
			if (attr.hasInitialValue()) {
				bl.addAttribute(new TAttribute(0, attr.getName(), attr.getInitialValue(), type));
			} else {
				bl.addAttribute(new TAttribute(0, attr.getName(), attr.getType().getDefaultInitialValue(), type));
			}
			if (attr.getName().contains("key_") || attr.getName().contains("privKey_")) {
				hasCrypto = true;
				bl.addCryptoElements();
			}
		}

		for (avatartranslator.AvatarMethod method : ab.getMethods()) {
			String methodId = "";
			if (useOriginalValues) {
				methodId = method.toOriginalString().replaceAll(" = 0", "");
			} else {
				methodId = method.toString().replaceAll(" = 0", "");
			}
			String result = methodId.replaceAll(" = false", "");
			TraceManager.addDev("Adding method:" + result);

			//TraceManager.addDev("Extra types are:" + as.getExtraTypes().toString());
			bl.addMethodIfApplicable(result, as.getExtraTypes());
		}
	}

	public String getLastKeyword(String s) {
		return s.split("__")[s.split("__").length - 1];
	}


	public void makeSecurityPragmas(AvatarSpecification avspec, AvatarDesignPanel adp) {
		AvatarBDPanel abd = adp.abdp;
		int dec = 250;
		int xPos = 100, yPos = 500;
		TGComponent tgcO;

		HashMap<Object, AvatarBDPragma> setOfNewSecurityPragmaComponent = new HashMap<>();

		for (AvatarPragma p : avspec.getPragmas()) {

			//    arr[i] = p.getName();
			TraceManager.addDev("Handling security pragma: " + p.getName());
			Object o = p.getReferenceObject();

			AvatarBDPragma comp = null;
			if (o != null) {
				//TraceManager.addDev(" - - - - Pragma " + pragmaS + " has reference object " + o.toString());
				// already created?
				comp = setOfNewSecurityPragmaComponent.get(o);
				if ((o instanceof TGComponent) && (comp == null))
					tgcO = (TGComponent)o;
				else tgcO = null;
			} else {
				tgcO = null;
			}
			if (comp == null) {
				// We must create it
				if (tgcO != null) {
					xPos = tgcO.getX();
					yPos = tgcO.getY();
				}
				comp = new AvatarBDPragma(xPos, yPos, abd.getMinX(), abd.getMaxX(), abd.getMinY(), abd.getMaxY(), false, null, abd);
				xPos = xPos + dec;
				yPos = yPos + dec;
				abd.addComponent(comp, xPos, yPos, false, true);
				if (tgcO != null) {
					comp.resize(tgcO.getWidth(), tgcO.getHeight());
				}
				setOfNewSecurityPragmaComponent.put(o, comp);
			}

			String value = comp.getValue();
			value = value + "\n" + p.getAdvancedValue();
			comp.setValue(value);
			comp.makeValue();

		}
	}

	public void makePerformancePragmas(AvatarSpecification avspec, AvatarDesignPanel adp) {
		AvatarBDPanel abd = adp.abdp;
		int dec = 250;
		int xPos = 100, yPos = 500;
		TGComponent tgcO;

		HashMap<Object, AvatarBDPerformancePragma> setOfNewPerformancePragmaComponent = new HashMap<>();

		for (AvatarPragmaLatency p : avspec.getLatencyPragmas()) {

			//    arr[i] = p.getName();
			TraceManager.addDev("Handling performance pragma: " + p.getName());
			Object o = p.getReferenceObject();

			AvatarBDPerformancePragma comp = null;
			if (o != null) {
				//TraceManager.addDev(" - - - - Pragma " + pragmaS + " has reference object " + o.toString());
				// already created?
				comp = setOfNewPerformancePragmaComponent.get(o);
				if ((o instanceof TGComponent) && (comp == null))
					tgcO = (TGComponent)o;
				else tgcO = null;
			} else {
				tgcO = null;
			}
			if (comp == null) {
				// We must create it
				if (tgcO != null) {
					xPos = tgcO.getX();
					yPos = tgcO.getY();
				}
				comp = new AvatarBDPerformancePragma(xPos, yPos, abd.getMinX(), abd.getMaxX(), abd.getMinY(), abd.getMaxY(), false, null, abd);
				xPos = xPos + dec;
				yPos = yPos + dec;
				abd.addComponent(comp, xPos, yPos, false, true);
				if (tgcO != null) {
					comp.resize(tgcO.getWidth(), tgcO.getHeight());
				}
				setOfNewPerformancePragmaComponent.put(o, comp);
			}

			String value = comp.getValue();
			value = value + "\n" + p.getAdvancedValue();
			comp.setValue(value);
			comp.makeValue();

		}
	}


	public void makeNotes(AvatarSpecification avspec, AvatarDesignPanel adp) {
		AvatarBDPanel abd = adp.abdp;
		int dec = 250;
		int xPos = 100, yPos = 500;
		TGComponent tgcO = null;
		TGCNote tgcNote;


		for(AvatarNote note: avspec.getNotes()) {
			Object o = note.getReferenceObject();

			if ((o != null) && (o instanceof TGComponent)) {
				tgcO = (TGComponent)o;
				xPos = tgcO.getX();
				yPos = tgcO.getY();
			}

			tgcNote = new TGCNote(xPos, yPos, abd.getMinX(), abd.getMaxX(), abd.getMinY(), abd.getMaxY(), false, null, abd);
			xPos = xPos + dec;
			yPos = yPos + dec;
			abd.addComponent(tgcNote, xPos, yPos, false, true);
			tgcNote.setValue(note.getValue());
			tgcNote.makeValue();
			if (tgcO != null) {
				tgcNote.resize(tgcO.getWidth(), tgcO.getHeight());
			}
		}
	}


	public void makeSafetyPragmas(AvatarSpecification avspec, AvatarDesignPanel adp) {
		AvatarBDPanel abd = adp.abdp;
		int dec = 250;
		int xPos = 100, yPos = 500;
		TGComponent tgcO;

		HashMap<Object, AvatarBDSafetyPragma> setOfNewSafetyPragmaComponent = new HashMap<>();

		for(String pragmaS: avspec.getSafetyPragmas()) {
			Object o = avspec.getReferenceObjectOfSafetyPragma(pragmaS);

			AvatarBDSafetyPragma comp = null;
			if (o != null) {
				//TraceManager.addDev(" - - - - Pragma " + pragmaS + " has reference object " + o.toString());
				// already created?
				comp = setOfNewSafetyPragmaComponent.get(o);
				if ((o instanceof TGComponent) && (comp == null))
					tgcO = (TGComponent)o;
				else tgcO = null;
			} else {
				tgcO = null;
			}
			if (comp == null) {
				// We must create it
				if (tgcO != null) {
					xPos = tgcO.getX();
					yPos = tgcO.getY();
				}
				comp = new AvatarBDSafetyPragma(xPos, yPos, abd.getMinX(), abd.getMaxX(), abd.getMinY(), abd.getMaxY(), false, null, abd);
				xPos = xPos + dec;
				yPos = yPos + dec;
				abd.addComponent(comp, xPos, yPos, false, true);
				if (tgcO != null) {
					comp.resize(tgcO.getWidth(), tgcO.getHeight());
				}
				setOfNewSafetyPragmaComponent.put(o, comp);
			}

			String value = comp.getValue();
			value = value + "\n" + pragmaS;
			comp.setValue(value);
			comp.makeValue();
		}
	}