package symlog; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.text.*; public class SymlogDiagram extends Applet { static final int UD = 0; static final int PN = 1; static final int FB = 2; boolean isStandalone = false; static final int MAX_INDIVIDUALS = 25; int numberOfIndividuals; String[] individualNames = new String[MAX_INDIVIDUALS]; int[][] individualProfiles = new int[MAX_INDIVIDUALS][3]; int[] wishProfile = new int[3]; int[] avoidProfile = new int[3]; int[] oughtProfile = new int[3]; int[] actualProfile = new int[3]; int[] rejectProfile = new int[3]; int[] workProfile = new int[3]; private String personBehavior; private String wish; private String avoid; private String ought; private String actual; private String reject; private String importedString; static public NumberFormat scores = NumberFormat.getInstance(); static public ParsePosition startingCharacter = new ParsePosition(0); /**Construct the applet*/ public SymlogDiagram() { } /**Initialize the applet*/ public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { this.setBackground(Color.white); } public synchronized void paint(Graphics g) { g.setFont(new Font("SansSerif",Font.PLAIN,10)); // Draw self circles. g.setColor(Color.pink); drawCircles(g,avoidProfile); drawName(g,avoidProfile, "Avoid"); g.setColor(Color.red); drawCircles(g,rejectProfile); drawName(g,rejectProfile, "Reject"); g.setColor(Color.cyan); drawCircles(g,actualProfile); drawName(g,actualProfile, "Actual"); g.setColor(Color.green); drawCircles(g,oughtProfile); drawName(g,oughtProfile, "Ought"); g.setColor(Color.orange); drawCircles(g,wishProfile); drawName(g,wishProfile, "Wish"); // Draw axes. Each SYMLOG unit = 12 pixels. g.setColor(Color.lightGray); g.drawLine(0,0,480,0); g.drawLine(0,120,480,120); g.drawLine(0,360,480,360); g.drawLine(0,480,480,480); g.drawLine(0,0,480,0); g.drawLine(120,0,120,480); g.drawLine(360,0,360,480); g.drawLine(480,0,480,480); g.setColor(Color.darkGray); g.drawLine(240, 0, 240,480); g.drawLine(0,240,480,240); // Draw individual behavior circles. g.setColor(Color.darkGray); for (int i=0; i=0) { // 17 pixels is radius for zero on Up-Down. intProfile[UD] = 17 + (int) Math.round(2.4 * intProfile[UD]); // Up radius is 2.4 pixels * value of U. } else { intProfile[UD] = 17 + (int) Math.round(0.72 * intProfile[UD]); // Down radius is 0.72 pixels * (negative) value of D. } } else if (epa==PN){ intProfile[PN] = 12 * (intProfile[PN] + 20); // P-N: Convert SYMLOG -20 to 20 into graph 0 to 480. } else { intProfile[FB] = 12 * (20 - intProfile[FB]); // F-B: Convert SYMLOG 20 to -20 into graph 0 to 480. } } return intProfile; } public static int readNumber(String digits) throws NumberFormatException { // Obtain a number from its string representation. Number entry; entry = null; int stringLength = digits.length(); // Parsing index must be set by the calling routine. e.g., startingCharacter.setIndex(0); int firstDigit = startingCharacter.getIndex(); // Work through the string to find the number. while (entry==null) { // Parse returns null if the starting character is not part of a number. startingCharacter.setIndex(firstDigit++); entry = scores.parse(digits, startingCharacter); if (firstDigit>stringLength) { throw new NumberFormatException("Not a number: " + digits); } } return entry.intValue(); } void drawCircles (Graphics g, int[] profile) { int diameter = 2 * profile[UD]; g.fillOval(profile[PN]-2, profile[FB]-2, 4, 4); // Dot at center. g.drawOval(profile[PN]-profile[UD], profile[FB]-profile[UD], diameter, diameter); } void drawName (Graphics g, int[] profile, String theName) { int x = profile[PN] + 3; int y = profile[FB]; g.drawString(theName, x, y); } }