[Home] Restricted access for guests. The link to Java source code is disabled
Java source code of 'jhplot.jadraw.Diagram'
// * This code is licensed under:
// * SCaVi License, Version 1.0
// * - for license details see http://jhepwork.sourceforge.net/license.html
// *
// * Copyright (c) 2005 by S.Chekanov (chekanov@mail.desy.de).
// * All rights reserved.
package jhplot.jadraw;
import japlot.Global;
import japlot.jaxodraw.JaxoColor;
import japlot.jaxodraw.JaxoMainPanel;
import japlot.jaxodraw.JaxoPrefs;
import japlot.jaxodraw.JaxoStaticCanvasMethods;
import java.awt.Color;
import java.awt.Font;
import java.util.ResourceBundle;
/**
* Main static methods to build objects for Feynman diagrams.
* @author S.Chekanov (ANL)
*
*/
public class Diagram {
private static int nofclicks=0;
private static ResourceBundle language;
//private static Vector points;
private static int[] points = new int[6];
private static boolean pointsON;
/**
* Get a box object
* @param xin coordinate in NDC
* @param yin coordinate in NDC
* @return
*/
public static JaBox Box(float xin, float yin) {
return (JaBox)JaxoStaticCanvasMethods.newBox(Global.fromX(xin),
Global.fromY(yin) );
}
/**
* Get a blob object
* @param xin coordinate in NDC
* @param yin coordinate in NDC
* @return
*/
public static JaBlob Blob(float xin, float yin) {
return (JaBlob)JaxoStaticCanvasMethods.newBlob(Global.fromX(xin),
Global.fromY(yin) );
}
/**
* Get a vertex object
* @param vertexType
* 0 A vertex type 1 object (a dot).
* 1 A vertex type 2 object (a cross with a circle)
* 2 A vertex type 3 object (a filled square)
* 3 A vertex type 4 object (a cross).
* 4 A vertex type 5 object (a triangle).
* 5 A vertex type 6 object (a diamond).
* @param xxin coordinate in NDC
* @param yyin coordinate in NDC
* @return
*/
public static JaObject Vertex(int vertexType, float xxin, float yyin) {
JaObject newob = null;
int xin = Global.fromX(xxin);
int yin = Global.fromY(yyin);
if (vertexType == 0) {
// JaxoMainPanel.VERTEXT1
JaVertexT1 newVertexT1 = new JaVertexT1();
newVertexT1.setX(xin);
newVertexT1.setY(yin);
newVertexT1.setColor(JaxoColor.getColor(JaxoPrefs.getPref(
JaxoPrefs.PREF_COLOR)));
newob = (JaObject) newVertexT1;
} else if (vertexType == 1) {
// JaxoMainPanel.VERTEXT2)
JaVertexT2 newVertexT2 = new JaVertexT2();
newVertexT2.setX(xin);
newVertexT2.setY(yin);
newVertexT2.setColor(JaxoColor.getColor(JaxoPrefs.getPref(
JaxoPrefs.PREF_COLOR)));
newVertexT2.setStroke(JaxoPrefs.getFloatPref(
JaxoPrefs.PREF_LINEWIDTH));
newVertexT2.setColor(JaxoColor.getColor(JaxoPrefs.getPref(
JaxoPrefs.PREF_COLOR)));
newVertexT2.setFillColor(JaxoColor.WHITE);
newob = (JaObject) newVertexT2;
} else if (vertexType == 2) {
// JaxoMainPanel.VERTEXT3) {
JaVertexT3 newVertexT3 = new JaVertexT3();
newVertexT3.setX(xin);
newVertexT3.setY(yin);
newVertexT3.setColor(JaxoColor.getColor(JaxoPrefs.getPref(
JaxoPrefs.PREF_COLOR)));
newob = (JaObject) newVertexT3;
} else if (vertexType == 3) {
// JaxoMainPanel.VERTEXT4) {
JaVertexT4 newVertexT4 = new JaVertexT4();
newVertexT4.setX(xin);
newVertexT4.setY(yin);
newVertexT4.setColor(JaxoColor.getColor(JaxoPrefs.getPref(
JaxoPrefs.PREF_COLOR)));
newVertexT4.setStroke(JaxoPrefs.getFloatPref(
JaxoPrefs.PREF_LINEWIDTH));
newob = (JaObject) newVertexT4;
} else if (vertexType == 4) {
// JaxoMainPanel.VERTEXT5) {
if ((nofclicks % 3) != 0) {
pointsON = true;
int pos = (nofclicks % 3) - 1;
points[2 * pos] = xin;
points[(2 * pos) + 1] = yin;
} else {
pointsON = false;
points[4] = xin;
points[5] = yin;
JaVertexT5 newVertexT5 = new JaVertexT5();
newVertexT5.setVertexPts(points[0], points[1], points[2],
points[3], points[4], points[5]);
newVertexT5.setStroke(JaxoPrefs.getFloatPref(
JaxoPrefs.PREF_LINEWIDTH));
newVertexT5.setColor(JaxoColor.getColor(JaxoPrefs.getPref(
JaxoPrefs.PREF_COLOR)));
newVertexT5.setFillColor(getDefaultFillColor());
newob = (JaObject) newVertexT5;
}
} else if (vertexType == 5) {
// JaxoMainPanel.VERTEXT6) {
JaVertexT6 newVertexT6 = new JaVertexT6();
newVertexT6.setX(xin);
newVertexT6.setY(yin);
newVertexT6.setColor(JaxoColor.getColor(JaxoPrefs.getPref(
JaxoPrefs.PREF_COLOR)));
newob = (JaObject) newVertexT6;
}
return newob;
}
/**
* Get a zig zag object
* @param xin coordinate in NDC
* @param yin coordinate in NDC
* @return
*/
public static JaZigZagLine ZigZagLine(float xin, float yin) {
return (JaZigZagLine)JaxoStaticCanvasMethods.newZigZagLine(Global.fromX(xin),
Global.fromY(yin) );
}
/**
* Get a text object
* @param xxin coordinate in NDC
* @param yyin coordinate in NDC
* @return
*/
public static JaText Text(String text, float xxin, float yyin) {
int xin = Global.fromX(xxin);
int yin = Global.fromY(yyin);
JaText newText = new JaText();
newText.setX(xin);
newText.setY(yin);
newText.setRotAngle(JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSROTANGLE));
newText.setColor(JaxoColor.getColor(JaxoPrefs.getPref(
JaxoPrefs.PREF_TEXTCOLOR)));
newText.setText(text);
newText.setFont(new Font(JaxoPrefs.getPref(JaxoPrefs.PREF_PSFAMILY),
JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSSTYLE),
JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSSIZE)));
return newText;
}
/**
* A boxed text object
* @param text input string
* @param xxin coordinate in NDC
* @param yyin coordinate in NDC
* @return
*/
public static JaTextBox TextBox(String text, float xxin, float yyin) {
int xin = Global.fromX(xxin);
int yin = Global.fromY(yyin);
JaTextBox newText = new JaTextBox();
newText.setX(xin);
newText.setY(yin);
newText.setRotAngle(JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSROTANGLE));
newText.setColor(JaxoColor.getColor(JaxoPrefs.getPref(
JaxoPrefs.PREF_TEXTCOLOR)));
newText.setText(text);
newText.setFont(new Font(JaxoPrefs.getPref(JaxoPrefs.PREF_PSFAMILY),
JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSSTYLE),
JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSSIZE)));
return newText;
}
/**
* A multiline boxed text object
* @param text input strings
* @param xxin coordinate in NDC
* @param yyin coordinate in NDC
* @return
*/
public static JaTextBox TextBox(String[] text, float xxin, float yyin) {
int xin = Global.fromX(xxin);
int yin = Global.fromY(yyin);
JaTextBox newText = new JaTextBox();
newText.setX(xin);
newText.setY(yin);
newText.setRotAngle(JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSROTANGLE));
newText.setColor(JaxoColor.getColor(JaxoPrefs.getPref(
JaxoPrefs.PREF_TEXTCOLOR)));
newText.setMultiText(text);
newText.setFont(new Font(JaxoPrefs.getPref(JaxoPrefs.PREF_PSFAMILY),
JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSSTYLE),
JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSSIZE)));
return newText;
}
/**
* Get a text with key symbol
* @param keytype key type (1-12 and 20 (line), 21 (box), 22 (filled box)
* @param text text
* @param xxin coordinate in NDC
* @param yyin coordinate in NDC
* @return
*/
public static JaKey Key(int keytype, String text, float xxin, float yyin) {
int xin = Global.fromX(xxin);
int yin = Global.fromY(yyin);
JaKey newText = new JaKey();
newText.setX(xin);
newText.setY(yin);
newText.setRotAngle(JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSROTANGLE));
newText.setColor(JaxoColor.getColor(JaxoPrefs.getPref(
JaxoPrefs.PREF_TEXTCOLOR)));
newText.setText(text);
newText.setKey(keytype);
newText.setFont(new Font(JaxoPrefs.getPref(JaxoPrefs.PREF_PSFAMILY),
JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSSTYLE),
JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSSIZE)));
return newText;
}
/**
* Get a photon line object
* @param xin coordinate in NDC
* @param yin coordinate in NDC
* @return
*/
public static JaPLine PLine(float xin, float yin) {
return (JaPLine)JaxoStaticCanvasMethods.newPLine(Global.fromX(xin),
Global.fromY(yin) );
}
public static JaPArc PArc(float x1, float y1,
float x2, float y2,
float x3, float y3) {
points[0] = Global.fromX(x1);
points[1] = Global.fromY(y1);
points[2] = Global.fromX(x2);
points[3] = Global.fromY(y2);
points[4] = Global.fromX(x3);
points[5] = Global.fromY(y3);
JaPArc newPArc = new JaPArc();
newPArc.setArcPts(points[0], points[1], points[2], points[3],
points[4], points[5]);
newPArc.setAmp(-JaxoPrefs.getIntPref(JaxoPrefs.PREF_AMPLITUDE));
newPArc.setFreq(20.0f);
newPArc.setColor(JaxoColor.getColor(JaxoPrefs.getPref(
JaxoPrefs.PREF_COLOR)));
newPArc.setStroke(JaxoPrefs.getFloatPref(JaxoPrefs.PREF_LINEWIDTH));
newPArc.setDoubleLine(false);
newPArc.setDLSeparation(JaxoPrefs.getFloatPref(
JaxoPrefs.PREF_DLSEP));
return newPArc;
}
/**
* Get a photon loop object
* @param xin coordinate in NDC
* @param yin coordinate in NDC
* @return
*/
public static JaPLoop PLoop(float xin, float yin) {
return (JaPLoop)JaxoStaticCanvasMethods.newPLoop(Global.fromX(xin),
Global.fromY(yin) );
}
/**
* Get a gluon line object
* @param xin coordinate in NDC
* @param yin coordinate in NDC
* @return
*/
public static JaGlLine GlLine(float xin, float yin) {
return (JaGlLine)JaxoStaticCanvasMethods.newGlLine(Global.fromX(xin),
Global.fromY(yin) );
}
public static JaGlArc GlArc(float x1, float y1,
float x2, float y2,
float x3, float y3) {
points[0] = Global.fromX(x1);
points[1] = Global.fromY(y1);
points[2] = Global.fromX(x2);
points[3] = Global.fromY(y2);
points[4] = Global.fromX(x3);
points[5] = Global.fromY(y3);
JaGlArc newGlArc = new JaGlArc();
newGlArc.setArcPts(points[0], points[1], points[2], points[3],
points[4], points[5]);
newGlArc.setAmp(JaxoPrefs.getIntPref(JaxoPrefs.PREF_AMPLITUDE));
newGlArc.setFreq(20.0f);
newGlArc.setColor(JaxoColor.getColor(JaxoPrefs.getPref(
JaxoPrefs.PREF_COLOR)));
newGlArc.setStroke(JaxoPrefs.getFloatPref(JaxoPrefs.PREF_LINEWIDTH));
newGlArc.setDoubleLine(false);
newGlArc.setDLSeparation(JaxoPrefs.getFloatPref(
JaxoPrefs.PREF_DLSEP));
return newGlArc;
}
/**
* Get a gluon loop object
* @param xin coordinate in NDC
* @param yin coordinate in NDC
* @return
*/
public static JaGlLoop GlLoop(float xin, float yin) {
return (JaGlLoop)JaxoStaticCanvasMethods.newGlLoop(Global.fromX(xin),
Global.fromY(yin) );
}
/**
* Get a fermion line
* @param xin coordinate in NDC
* @param yin coordinate in NDC
* @return
*/
public static JaFLine FLine(float xin, float yin) {
return (JaFLine)JaxoStaticCanvasMethods.newFLine(Global.fromX(xin),
Global.fromY(yin) );
}
/**
* Get a fermion loop object
* @param xin coordinate in NDC
* @param yin coordinate in NDC
* @return
*/
public static JaFLoop FLoop(float xin, float yin) {
return (JaFLoop)JaxoStaticCanvasMethods.newFLoop(Global.fromX(xin),
Global.fromY(yin) );
}
public static JaFArc FArc(float x1, float y1,
float x2, float y2,
float x3, float y3) {
points[0] = Global.fromX(x1);
points[1] = Global.fromY(y1);
points[2] = Global.fromX(x2);
points[3] = Global.fromY(y2);
points[4] = Global.fromX(x3);
points[5] = Global.fromY(y3);
JaFArc newFArc = new JaFArc();
newFArc.setArcPts(points[0], points[1], points[2], points[3],
points[4], points[5]);
newFArc.setColor(JaxoColor.getColor(JaxoPrefs.getPref(
JaxoPrefs.PREF_COLOR)));
newFArc.setStroke(JaxoPrefs.getFloatPref(JaxoPrefs.PREF_LINEWIDTH));
newFArc.setArrow(JaxoPrefs.getBooleanPref(JaxoPrefs.PREF_ARROW));
newFArc.setFlip(false);
newFArc.setStangle(0);
newFArc.setDoubleLine(false);
newFArc.setDLSeparation(JaxoPrefs.getFloatPref(
JaxoPrefs.PREF_DLSEP));
return newFArc;
}
/**
* A s-line object for scalar particles.
* @param xin coordinate in NDC
* @param yin coordinate in NDC
* @return
*/
public static JaSLine SLine(float xin, float yin) {
return (JaSLine)JaxoStaticCanvasMethods.newSLine(Global.fromX(xin),
Global.fromY(yin) );
}
/**
* A s-loop for scalar particles.
* @param xin coordinate in NDC
* @param yin coordinate in NDC
* @return
*/
public static JaSLoop SLoop(float xin, float yin) {
return (JaSLoop)JaxoStaticCanvasMethods.newSLoop(Global.fromX(xin),
Global.fromY(yin) );
}
/**
* A s-line for scalar particles.
* @param xin coordinate in NDC
* @param yin coordinate in NDC
* @return
*/
public static JaSArc SArc(float x1, float y1,
float x2, float y2,
float x3, float y3) {
points[0] = Global.fromX(x1);
points[1] = Global.fromY(y1);
points[2] = Global.fromX(x2);
points[3] = Global.fromY(y2);
points[4] = Global.fromX(x3);
points[5] = Global.fromY(y3);
JaSArc newSArc = new JaSArc();
newSArc.setArcPts(points[0], points[1], points[2], points[3],
points[4], points[5]);
newSArc.setColor(JaxoColor.getColor(JaxoPrefs.getPref(
JaxoPrefs.PREF_COLOR)));
newSArc.setStroke(JaxoPrefs.getFloatPref(JaxoPrefs.PREF_LINEWIDTH));
newSArc.setDash(10.0f);
newSArc.setArrow(JaxoPrefs.getBooleanPref(JaxoPrefs.PREF_ARROW));
newSArc.setFlip(false);
newSArc.setStangle(0);
newSArc.setDoubleLine(false);
newSArc.setDLSeparation(JaxoPrefs.getFloatPref(
JaxoPrefs.PREF_DLSEP));
return newSArc;
}
/**
* A g-line for ghost particles.
* @param xin coordinate in NDC
* @param yin coordinate in NDC
* @return
*/
public static JaGLine GLine(float xin, float yin) {
return (JaGLine)JaxoStaticCanvasMethods.newGLine(Global.fromX(xin),
Global.fromY(yin) );
}
/**
* Get a g-loop object
* @param xin coordinate in NDC
* @param yin coordinate in NDC
* @return
*/
public static JaGLoop GLoop(float xin, float yin) {
return (JaGLoop)JaxoStaticCanvasMethods.newGLoop(Global.fromX(xin),
Global.fromY(yin) );
}
/**
* Get a g-line object
* @param xin coordinate in NDC
* @param yin coordinate in NDC
* @return
*/
public static JaGArc GArc(float x1, float y1,
float x2, float y2,
float x3, float y3) {
points[0] = Global.fromX(x1);
points[1] = Global.fromY(y1);
points[2] = Global.fromX(x2);
points[3] = Global.fromY(y2);
points[4] = Global.fromX(x3);
points[5] = Global.fromY(y3);
JaGArc newGArc = new JaGArc();
newGArc.setArcPts(points[0], points[1], points[2], points[3],
points[4], points[5]);
newGArc.setColor(JaxoColor.getColor(JaxoPrefs.getPref(
JaxoPrefs.PREF_COLOR)));
newGArc.setStroke(JaxoPrefs.getFloatPref(JaxoPrefs.PREF_LINEWIDTH));
newGArc.setArrow(JaxoPrefs.getBooleanPref(JaxoPrefs.PREF_ARROW));
newGArc.setFlip(false);
newGArc.setStangle(0);
newGArc.setDash(2.0f);
newGArc.setDoubleLine(false);
newGArc.setDLSeparation(JaxoPrefs.getFloatPref(
JaxoPrefs.PREF_DLSEP));
return newGArc;
}
private static Color getDefaultFillColor() {
if (JaxoPrefs.getPref(JaxoPrefs.PREF_COLOR).equals(JaxoColor
.getColorName(JaxoColor.BLACK))) {
return (JaxoColor.GRAYSCALE225);
} else {
return (JaxoColor.GRAY);
}
}
}