/******************************************************************************/ /* Name: Venn-O-Matic */ /* Description: Tests the validity of a categorical syllogism and draws */ /* its Venn diagram */ /* Copyright (C) 1999 Ron Blatt, Cygnus@unimatrix.com */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* any later version. */ /* */ /* This program is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU General Public License for more details. */ /* */ /* You should have received a copy of the GNU General Public License */ /* along with this program; if not, write to the Free Software */ /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /******************************************************************************/ import java.awt.*; import java.awt.event.*; import java.lang.Math; import java.applet.*; public final class VennDiagram extends Applet implements ActionListener, ItemListener, MouseListener { final static byte REGION_1 = 0x01; final static byte REGION_2 = 0x02; final static byte REGION_3 = 0x04; final static byte REGION_4 = 0x08; final static byte REGION_5 = 0x10; final static byte REGION_6 = 0x20; final static byte REGION_7 = 0x40; final static short CIRCLE_1 = 0x0080; final static short CIRCLE_2 = 0x0100; final static short CIRCLE_3 = 0x0200; final static short CIRCLE_4 = 0x0400; final static short CIRCLE_5 = 0x0800; final static short CIRCLE_6 = 0x1000; final static short CIRCLE_7 = 0x2000; final static short CIRCLE_8 = 0x4000; final static int CIRCLE_9 = 0x8000; final static byte FALLACY_2 = 0x01; final static byte FALLACY_3_MAJOR = 0x02; final static byte FALLACY_3_MINOR = 0x04; final static byte FALLACY_4 = 0x08; final static byte FALLACY_5 = 0x10; final static byte FALLACY_6 = 0x20; final static byte VennCorrect = 0x01; final static byte MajorCorrect = 0x02; final static byte MinorCorrect = 0x04; final static byte ConclusionCorrect = 0x08; final static byte FigureCorrect = 0x10; final static byte ValidCorrect = 0x20; final static byte NameCorrect = 0x40; final static short Fallacy2Correct = 0x80; final static short Fallacy3aCorrect = 0x0100; final static short Fallacy3bCorrect = 0x0200; final static short Fallacy4Correct = 0x0400; final static short Fallacy5Correct = 0x0800; final static short Fallacy6Correct = 0x1000; final static short RADIUS = 50; final static short SMALL_RADIUS = 7; final static int width[] = {RADIUS * 2, RADIUS * 2, RADIUS * 2}; final static int SmallWidth[] = {SMALL_RADIUS * 2, SMALL_RADIUS * 2, SMALL_RADIUS * 2, SMALL_RADIUS * 2, SMALL_RADIUS * 2, SMALL_RADIUS * 2, SMALL_RADIUS * 2, SMALL_RADIUS * 2, SMALL_RADIUS * 2}; final static int BLINK_TIME = 1300; final static int SFONTSIZE = 22; Blinker b = new Blinker(this, BLINK_TIME); Image dblBufferImage; Graphics dblBuffer; boolean Valid; short UserCorrect = 0; // boolean VennCorrect, MajorCorrect, MinorCorrect, ConclusionCorrect, // FigureCorrect, ValidCorrect, Fallacy5Correct, Fallacy6Correct, // Fallacy2Correct, Fallacy3aCorrect, Fallacy3bCorrect, Fallacy4Correct = false; boolean Import[] = {false, false}; boolean DistributedM[] = {false, false}; boolean DistributedT[] = {false, false}; boolean DistributedC[] = {false, false}; boolean ChoiceGone = false; String SyllogismName = ""; byte EmptyVennRegions = 0; byte ClickedRegions = 0; byte ClickedRegions2 = -1; int ImportedRegions = 0; int ImportedRegions2 = 0; byte Fallacy; byte PropType[] = new byte[4]; byte PropType2; int xDistCircle[] = {0, 0}; int yDistCircle[] = {0, 0}; int xUnDistCircle[] = {0, 0}; int yUnDistCircle[] = {0, 0}; int xImport[] = {0, 0}; int yImport[] = {0, 0}; int xTerm[] = {0, 0}; int yTerm[] = {0, 60}; int xTestTerm[] = {0, 0}; int yTestTerm[] = {0, 60}; int xSmallCircles[] = new int[9]; int ySmallCircles[] = new int[9]; int xMiddle; int yMiddle; int xTestMiddle; int yTestMiddle; int offset; int xSImport; int ySImport; int xPImport; int yPImport; int xMImport; int yMImport; int xTestSImport; int yTestSImport; int xTestPImport; int yTestPImport; int xTestMImport; int yTestMImport; Font TNRItalic = new Font("Serif", Font.ITALIC, 28); Font TNR = new Font("Serif", Font.PLAIN, 24); Font TNRSmall = new Font("Serif", Font.PLAIN, 14); Font TNRItalicSmall = new Font("Serif", Font.ITALIC, SFONTSIZE); Choice MajorPremise = new Choice(); Choice TestMajor = new Choice(); Choice MinorPremise = new Choice(); Choice TestMinor = new Choice(); Choice Conclusion = new Choice(); Choice TestConclusion = new Choice(); Choice Figure = new Choice(); Choice TestFigure = new Choice(); Choice TempChoice = new Choice(); Choice TestValid = new Choice(); Choice TestName = new Choice(); Button Evaluate = new Button("Evaluate & Test"); Checkbox BlinkCheckbox = new Checkbox("Blink Conclusion", true); Panel p = new Panel(new GridLayout(0, 2)); Panel p2 = new Panel(new GridLayout(0, 2)); Panel p3 = new Panel(new GridLayout(0, 1)); Label Form = new Label("AAA - 2"); Button RandomSyllogism = new Button("Random Syllogism"); Button RandomDiagram = new Button("Random Diagram"); Checkbox Fallacy2 = new Checkbox("Fallacy #2: Undistributed middle"); Checkbox Fallacy3_Major = new Checkbox("Fallacy #3a: Illicite major"); Checkbox Fallacy3_Minor = new Checkbox("Fallacy #3b: Illicite minor"); Checkbox Fallacy4 = new Checkbox("Fallacy #4: Exclusive fallacy"); Checkbox Fallacy5 = new Checkbox("Fallacy #5: Affirmitive conclusion from negative premise"); Checkbox Fallacy6 = new Checkbox("Fallacy #6: Existential fallacy"); String FormStr; public void init() { dblBufferImage = this.createImage(getSize().width, getSize().height); dblBuffer = dblBufferImage.getGraphics(); Evaluate.addActionListener(this); RandomSyllogism.addActionListener(this); RandomDiagram.addActionListener(this); addMouseListener(this); Evaluate.setActionCommand("ButtonAction"); RandomSyllogism.setActionCommand("Randomize"); RandomDiagram.setActionCommand("RandomDiagram"); BlinkCheckbox.addItemListener(this); Figure.addItemListener(this); MajorPremise.addItemListener(this); MinorPremise.addItemListener(this); Conclusion.addItemListener(this); TempChoice.add(""); MajorPremise.add("A - All P is M"); MajorPremise.add("A - All M is P"); MajorPremise.add("E - No P is M"); MajorPremise.add("E - No M is P"); MajorPremise.add("I - Some P is M"); MajorPremise.add("I - Some M is P"); MajorPremise.add("O - Some P is not M"); MajorPremise.add("O - Some M is not P"); TestMajor.add("A - All P is M"); TestMajor.add("A - All M is P"); TestMajor.add("E - No P is M"); TestMajor.add("E - No M is P"); TestMajor.add("I - Some P is M"); TestMajor.add("I - Some M is P"); TestMajor.add("O - Some P is not M"); TestMajor.add("O - Some M is not P"); MinorPremise.add("A - All S is M"); MinorPremise.add("A - All M is S"); MinorPremise.add("E - No S is M"); MinorPremise.add("E - No M is S"); MinorPremise.add("I - Some S is M"); MinorPremise.add("I - Some M is S"); MinorPremise.add("O - Some S is not M"); MinorPremise.add("O - Some M is not S"); TestMinor.add("A - All S is M"); TestMinor.add("A - All M is S"); TestMinor.add("E - No S is M"); TestMinor.add("E - No M is S"); TestMinor.add("I - Some S is M"); TestMinor.add("I - Some M is S"); TestMinor.add("O - Some S is not M"); TestMinor.add("O - Some M is not S"); Conclusion.add("A - All S is P"); Conclusion.add("E - No S is P"); Conclusion.add("I - Some S is P"); Conclusion.add("O - Some S is not P"); TestConclusion.add("A - All S is P"); TestConclusion.add("E - No S is P"); TestConclusion.add("I - Some S is P"); TestConclusion.add("O - Some S is not P"); Figure.add("1"); Figure.add("2"); Figure.add("3"); Figure.add("4"); Figure.select(1); TestFigure.add("1"); TestFigure.add("2"); TestFigure.add("3"); TestFigure.add("4"); TestFigure.select(1); TestValid.add("Valid"); TestValid.add("Invalid"); TestName.add("Invalid: No name"); TestName.add("Barbara"); TestName.add("Celarent"); TestName.add("Darii"); TestName.add("Ferio"); TestName.add("Camestres"); TestName.add("Cesare"); TestName.add("Baroko"); TestName.add("Festino"); TestName.add("Dastisi"); TestName.add("Disamis"); TestName.add("Ferison"); TestName.add("Bokardo"); TestName.add("Camenes"); TestName.add("Dimaris"); TestName.add("Fresison"); p.add(new Label("Major Premise:")); p.add(MajorPremise); p.add(new Label("Minor Premise:")); p.add(MinorPremise); p.add(new Label("Conclusion:")); p.add(Conclusion); p.add(new Label("Figure:")); p.add(Figure); p.add(new Label("Form:")); p.add(Form); p.add(Evaluate); Panel f = new Panel(new FlowLayout(FlowLayout.RIGHT, 0, 0)); f.add(BlinkCheckbox); p.add(f); p.add(RandomSyllogism); p.add(RandomDiagram); p2.add(new Label("Major Premise:")); p2.add(TestMajor); p2.add(new Label("Minor Premise:")); p2.add(TestMinor); p2.add(new Label("Conclusion:")); p2.add(TestConclusion); p2.add(new Label("Figure:")); p2.add(TestFigure); p2.add(new Label("Is it valid?")); p2.add(TestValid); p2.add(new Label("Syllogism name:")); p2.add(TestName); p3.add(Fallacy2); p3.add(Fallacy3_Major); p3.add(Fallacy3_Minor); p3.add(Fallacy4); p3.add(Fallacy5); p3.add(Fallacy6); this.setLayout(null); this.add(p); this.add(p2); this.add(p3); p.setBounds(new Rectangle(new Point(0, 0), p.getMinimumSize())); p2.setBounds(new Rectangle(new Point(0, p.getSize().height + 85), p2.getMinimumSize())); p3.setBounds(new Rectangle(new Point(p2.getSize().width + 85, p2.getLocation().y), p3.getMinimumSize())); xTerm[1] = p.getSize().width + 70; xTestTerm[1] = p.getSize().width + 270; xMiddle = xTerm[1] + (int)(RADIUS / 2); yMiddle = yTerm[1] + RADIUS; xTestMiddle = xTestTerm[1] + (int)(RADIUS / 2); yTestMiddle = yTestTerm[1] + RADIUS; offset = (int)(RADIUS / 1.5); xSImport = xTerm[1] + offset - 10; ySImport = yTerm[1] + offset; xMImport = xMiddle + RADIUS - 6; yMImport = yMiddle + RADIUS + offset - 6; xTestSImport = xTestTerm[1] + offset - 10; yTestSImport = yTestTerm[1] + offset; xTestMImport = xTestMiddle + RADIUS - 6; yTestMImport = yTestMiddle + RADIUS + offset - 6; xTerm[0] = xTerm[1] + RADIUS; yTerm[0] = yTerm[1]; xTestTerm[0] = xTestTerm[1] + RADIUS; yTestTerm[0] = yTestTerm[1]; xPImport = xTerm[0] + RADIUS * 2 - offset; yPImport = yTerm[0] + offset; xTestPImport = xTestTerm[0] + RADIUS * 2 - offset; yTestPImport = yTestTerm[0] + offset; offset = (int)(RADIUS * 0.707); xSmallCircles[0] = xTestTerm[0] + RADIUS - offset - SMALL_RADIUS * 2; ySmallCircles[0] = yTestTerm[0] + RADIUS - offset; xSmallCircles[1] = xTestTerm[1] + RADIUS + offset; ySmallCircles[1] = yTestTerm[1] + RADIUS - offset; xSmallCircles[2] = xTestMiddle + RADIUS - offset - SMALL_RADIUS * 2; ySmallCircles[2] = yTestMiddle + RADIUS - offset; xSmallCircles[3] = xTestMiddle + RADIUS - SMALL_RADIUS; ySmallCircles[3] = yTestMiddle - SMALL_RADIUS; xSmallCircles[4] = xTestMiddle + RADIUS + offset; ySmallCircles[4] = yTestMiddle + RADIUS - offset; xSmallCircles[5] = xTestTerm[0] + RADIUS - offset - SMALL_RADIUS * 2; ySmallCircles[5] = yTestTerm[0] + RADIUS + offset - SMALL_RADIUS * 2; xSmallCircles[6] = xTestTerm[1] + RADIUS + offset; ySmallCircles[6] = yTestTerm[1] + RADIUS + offset - SMALL_RADIUS * 2;; xSmallCircles[7] = xTestTerm[1] + RADIUS - SMALL_RADIUS; ySmallCircles[7] = yTestTerm[1] + RADIUS * 2 - SMALL_RADIUS; xSmallCircles[8] = xTestTerm[0] + RADIUS - SMALL_RADIUS; ySmallCircles[8] = yTestTerm[0] + RADIUS * 2 - SMALL_RADIUS; this.DeduceForm(); } public void itemStateChanged(ItemEvent e) { ItemSelectable Test = e.getItemSelectable(); if (Test.equals(BlinkCheckbox)) { if (b.isAlive() && !BlinkCheckbox.getState()) { b.stop(); b = new Blinker(this, BLINK_TIME); } update(dblBuffer); return; } int MajorP = MajorPremise.getSelectedIndex(); int MinorP = MinorPremise.getSelectedIndex(); int MajorType = MajorP % 2; int MinorType = MinorP % 2; char form[] = Form.getText().toCharArray(); ClickedRegions2 = -1; update(dblBuffer); if (b.isAlive()) { b.stop(); b = new Blinker(this, BLINK_TIME); } if (Test.equals(Figure)) { switch (Figure.getSelectedIndex() + 1) { case 1: if (MajorType == 0) MajorPremise.select(MajorP + 1); if (MinorType == 1) MinorPremise.select(MinorP - 1); form[6] = '1'; break; case 2: if (MajorType == 1) MajorPremise.select(MajorP - 1); if (MinorType == 1) MinorPremise.select(MinorP - 1); form[6] = '2'; break; case 3: if (MajorType == 0) MajorPremise.select(MajorP + 1); if (MinorType == 0) MinorPremise.select(MinorP + 1); form[6] = '3'; break; case 4: if (MajorType == 1) MajorPremise.select(MajorP - 1); if (MinorType == 0) MinorPremise.select(MinorP + 1); form[6] = '4'; break; } } else if (!Test.equals(Conclusion)) { int f = DetermineFigure(MajorP, MinorP); Figure.select(f - 1); form[6] = Integer.toString(f).charAt(0); int i = (Test.equals(MajorPremise) ? 0 : 1); switch(i == 0 ? MajorP : MinorP) { case 0: case 1: form[i] = 'A'; break; case 2: case 3: form[i] = 'E'; break; case 4: case 5: form[i] = 'I'; break; case 6: case 7: form[i] = 'O'; break; } } else { switch (Conclusion.getSelectedIndex()) { case 0: form[2] = 'A'; break; case 1: form[2] = 'E'; break; case 2: form[2] = 'I'; break; case 3: form[2] = 'O'; break; } } Form.setText(new String(form)); } public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("ButtonAction")) { if (ChoiceGone) { MajorPremise.setVisible(true); MinorPremise.setVisible(true); Conclusion.setVisible(true); Figure.setVisible(true); Form.setText(FormStr); ChoiceGone = false; } ImportedRegions2 = 0; ClickedRegions2 = 0; DeduceForm(); FormStr = Form.getText(); PropType2 = PropType[2]; if (b.isAlive()) { b.stop(); b = new Blinker(this, BLINK_TIME); } EvaluateVennDiagram(); Fallacy = DetermineFallacy(); SyllogismName = DetermineName(FormStr); TestUser(); update(dblBuffer); } else if (e.getActionCommand().equals("Randomize") || e.getActionCommand().equals("RandomDiagram")) { ItemEvent event; if (e.getActionCommand().equals("RandomDiagram")) { if (!ChoiceGone) { MajorPremise.setVisible(false); MinorPremise.setVisible(false); Conclusion.setVisible(false); Figure.setVisible(false); ChoiceGone = true; } Form.setVisible(false); BlinkCheckbox.setState(true); } MajorPremise.select((int)Math.round(Math.random() * 7)); event = new ItemEvent(MajorPremise, 0, null, 0); itemStateChanged(event); MinorPremise.select((int)Math.round(Math.random() * 7)); event = new ItemEvent(MinorPremise, 0, null, 0); itemStateChanged(event); Conclusion.select((int)Math.round(Math.random() * 3)); event = new ItemEvent(Conclusion, 0, null, 0); itemStateChanged(event); if (e.getActionCommand().equals("RandomDiagram")) { ImportedRegions2 = 0; ClickedRegions2 = 0; DeduceForm(); FormStr = Form.getText(); PropType2 = PropType[2]; if (b.isAlive()) { b.stop(); b = new Blinker(this, BLINK_TIME); } Fallacy = DetermineFallacy(); EvaluateVennDiagram(); update(dblBuffer); Form.setText("??? - ?"); Form.setVisible(true); } else if (ChoiceGone) { MajorPremise.setVisible(true); MinorPremise.setVisible(true); Conclusion.setVisible(true); Figure.setVisible(true); ChoiceGone = false; } } else if (e.getActionCommand().equals("Blinker")) update(dblBuffer); } public void DeduceForm() { int Term[] = {MajorPremise.getSelectedIndex(), MinorPremise.getSelectedIndex()}; for (int i = 0; i <= 1; i++) { switch (Term[i]) { case 0: PropType[i] = 1; DistributedT[i] = true; DistributedM[i] = false; break; case 1: PropType[i] = 1; DistributedT[i] = false; DistributedM[i] = true; break; case 2: case 3: PropType[i] = 2; DistributedT[i] = DistributedM[i] = true; break; case 4: case 5: PropType[i] = 3; DistributedT[i] = DistributedM[i] = false; break; case 6: PropType[i] = 4; DistributedT[i] = false; DistributedM[i] = true; break; case 7: PropType[i] = 4; DistributedT[i] = true; DistributedM[i] = false; break; } } int MajorType = Term[0] % 2; int MinorType = Term[1] % 2; if ((MajorType == 0) && (MinorType == 0)) PropType[3] = 2; else if ((MajorType == 0) && (MinorType == 1)) PropType[3] = 4; else if ((MajorType == 1) && (MinorType == 1)) PropType[3] = 3; else PropType[3] = 1; PropType[2] = (byte)(Conclusion.getSelectedIndex() + 1); switch (PropType[2]) { case 1: DistributedC[0] = true; DistributedC[1] = false; break; case 2: DistributedC[0] = DistributedC[1] = true; break; case 3: DistributedC[0] = DistributedC[1] = false; break; case 4: DistributedC[0] = false; DistributedC[1] = true; break; } } public int DetermineFigure(int MajorP, int MinorP) { int MajorType = MajorP % 2; int MinorType = MinorP % 2; switch(MajorType + MinorType) { case 0: return 2; case 1: if (MajorType == 1) return 1; return 4; } return 3; //case 2 } public void EvaluateVennDiagram() { EmptyVennRegions = 0; int i = ((PropType[0] > 2) && (PropType[1] < 3) ? 1 : 0); for (int j = 0; j <= 1; j++) { switch (PropType[i]) { case 1: case 2: if (DistributedT[i] == false) { xDistCircle[i] = xMiddle; yDistCircle[i] = yMiddle; xUnDistCircle[i] = xTerm[i]; yUnDistCircle[i] = yTerm[i]; if (i == 0) EmptyVennRegions = (byte)(PropType[i] == 1 ? REGION_4 | REGION_7 : REGION_5 | REGION_6); else EmptyVennRegions = (byte)(PropType[i] == 1 ? REGION_6 | REGION_7 : REGION_4 | REGION_5); } else { xDistCircle[i] = xTerm[i]; yDistCircle[i] = yTerm[i]; xUnDistCircle[i] = xMiddle; yUnDistCircle[i] = yMiddle; if (i == 0) EmptyVennRegions = (byte)(PropType[i] == 1 ? REGION_2 | REGION_3 : REGION_5 | REGION_6); else EmptyVennRegions = (byte)(PropType[i] == 1 ? REGION_1 | REGION_2 : REGION_4 | REGION_5); } Import[i] = false; i = (i == 0 ? 1 : 0); ClickedRegions2 |= EmptyVennRegions; break; case 3: byte EmptyTest; if (i == 0) { EmptyTest = (byte)(EmptyVennRegions & (REGION_5 | REGION_6)); if (EmptyTest == 0) { //Regions 5 & 6 xImport[i] = xTerm[1] + RADIUS + offset; yImport[i] = yTerm[1] + RADIUS + offset; ImportedRegions2 |= CIRCLE_7; } else if (EmptyTest == REGION_6) { //Region 5 xImport[i] = (xSImport + xPImport) / 2; yImport[i] = (ySImport + yMImport) / 2 - 5; ImportedRegions2 |= REGION_5; } else { //Region 6 xImport[i] = (xPImport + xMImport) / 2 + 7; yImport[i] = (yPImport + yMImport) / 2 + 8; ImportedRegions2 |= REGION_6; } } else { EmptyTest = (byte)(EmptyVennRegions & (REGION_4 | REGION_5)); if (EmptyTest == 0) { xImport[i] = xTerm[0] + RADIUS - offset - 10; yImport[i] = yTerm[0] + RADIUS + offset; ImportedRegions2 |= CIRCLE_6; } else if (EmptyTest == REGION_4) { xImport[i] = (xSImport + xPImport) / 2; yImport[i] = (ySImport + yMImport) / 2 - 5; ImportedRegions2 |= REGION_5; } else { xImport[i] = (xSImport + xMImport) / 2 - 5; yImport[i] = (ySImport + yMImport) / 2 + 8; ImportedRegions2 |= REGION_4; } } Import[i] = true; i = 1; break; case 4: if (i == 0) { if ((PropType[3] == 3) || (PropType[3] == 1)) { EmptyTest = (byte)(EmptyVennRegions & (REGION_4 | REGION_7)); if (EmptyTest == 0) { xImport[i] = xTerm[1] + RADIUS; yImport[i] = yTerm[1] + RADIUS * 2 + 6; ImportedRegions2 |= CIRCLE_8; } else if (EmptyTest == REGION_7) { xImport[i] = (xSImport + xMImport) / 2 - 8; yImport[i] = (ySImport + yMImport) / 2 + 8; ImportedRegions2 |= REGION_6; } else { xImport[i] = xMImport; yImport[i] = yMImport; ImportedRegions2 |= REGION_7; } } else { EmptyTest = (byte)(EmptyVennRegions & (REGION_2 | REGION_3)); if (EmptyTest == 0) { xImport[i] = xTerm[1] + RADIUS + offset; yImport[i] = yTerm[1] + RADIUS - offset + 12; ImportedRegions2 |= CIRCLE_2; } else if (EmptyTest == REGION_3) { xImport[i] = (xSImport + xPImport) / 2; yImport[i] = ySImport; ImportedRegions2 |= REGION_2; } else { xImport[i] = xPImport; yImport[i] = yPImport; ImportedRegions2 |= REGION_3; } } } else { if ((PropType[3] == 3) || (PropType[3] == 4)) { EmptyTest = (byte)(EmptyVennRegions & (REGION_7 | REGION_6)); if (EmptyTest == 0) { xImport[i] = xTerm[0] + RADIUS; yImport[i] = yTerm[0] + RADIUS * 2 + 6; ImportedRegions2 |= CIRCLE_9; } else if (EmptyTest == REGION_7) { xImport[i] = (xPImport + xMImport) / 2 + 7; yImport[i] = (yPImport + yMImport) / 2 + 8; ImportedRegions2 |= REGION_6; } else { xImport[i] = xMImport; yImport[i] = yMImport; ImportedRegions2 |= REGION_7; } } else { EmptyTest = (byte)(EmptyVennRegions & (REGION_1 | REGION_2)); if (EmptyTest == 0) { xImport[i] = xTerm[0] + RADIUS - offset - 10; yImport[i] = yTerm[0] + RADIUS - offset + 12; ImportedRegions2 |= CIRCLE_1; } else if (EmptyTest == REGION_1) { xImport[i] = (xSImport + xPImport) / 2; yImport[i] = ySImport; ImportedRegions2 |= REGION_2; } else { xImport[i] = xSImport; yImport[i] = ySImport; ImportedRegions2 |= REGION_1; } } } Import[i] = true; i = 1; break; } } if (DetermineFallacy() == 0) Valid = true; else Valid = false; } public byte DetermineFallacy() { byte Fallacy = 0; if (!DistributedM[0] && !DistributedM[1]) Fallacy = (byte)(Fallacy | FALLACY_2); if (DistributedC[1] == true && DistributedT[0] == false) Fallacy = (byte)(Fallacy | FALLACY_3_MAJOR); if (DistributedC[0] == true && DistributedT[1] == false) Fallacy = (byte)(Fallacy | FALLACY_3_MINOR); if ((PropType[0] == 2 || PropType[0] == 4) && (PropType[1] == 2 || PropType[1] == 4)) Fallacy = (byte)(Fallacy | FALLACY_4); if ((PropType[2] == 1 || PropType[2] == 3) && ((PropType[0] == 2 || PropType[0] == 4) || (PropType[1] == 2 || PropType[1] == 4))) Fallacy = (byte)(Fallacy | FALLACY_5); if (PropType[2] > 2 && PropType[0] < 3 && PropType[1] < 3) Fallacy = (byte)(Fallacy | FALLACY_6); return Fallacy; } public boolean SameAs(int P1, int P2) { if (P1 == P2) return true; switch (P1) { case 2: if (P2 == 3) return true; break; case 3: if (P2 == 2) return true; break; case 4: if (P2 == 5) return true; break; case 5: if (P2 == 4) return true; break; } return false; } public void TestUser() { UserCorrect = 0; if ((ClickedRegions == ClickedRegions2) && (ImportedRegions == ImportedRegions2)) UserCorrect |= VennCorrect; if (!((TestValid.getSelectedIndex() == 0 && !Valid) || (TestValid.getSelectedIndex() == 1 && Valid))) UserCorrect |= ValidCorrect; if (SameAs(TestMajor.getSelectedIndex(), MajorPremise.getSelectedIndex())) UserCorrect |= MajorCorrect; if (SameAs(TestMinor.getSelectedIndex(), MinorPremise.getSelectedIndex())) UserCorrect |= MinorCorrect; if (TestConclusion.getSelectedIndex() == Conclusion.getSelectedIndex()) UserCorrect |= ConclusionCorrect; int f = DetermineFigure(TestMajor.getSelectedIndex(), TestMinor.getSelectedIndex()) - 1; if (TestFigure.getSelectedIndex() == f) UserCorrect |= FigureCorrect; if (!((Fallacy & FALLACY_2) == FALLACY_2 ^ Fallacy2.getState())) UserCorrect |= Fallacy2Correct; if (!((Fallacy & FALLACY_3_MAJOR) == FALLACY_3_MAJOR ^ Fallacy3_Major.getState())) UserCorrect |= Fallacy3aCorrect; if (!((Fallacy & FALLACY_3_MINOR) == FALLACY_3_MINOR ^ Fallacy3_Minor.getState())) UserCorrect |= Fallacy3bCorrect; if (!((Fallacy & FALLACY_4) == FALLACY_4 ^ Fallacy4.getState())) UserCorrect |= Fallacy4Correct; if (!((Fallacy & FALLACY_5) == FALLACY_5 ^ Fallacy5.getState())) UserCorrect |= Fallacy5Correct; if (!((Fallacy & FALLACY_6) == FALLACY_6 ^ Fallacy6.getState())) UserCorrect |= Fallacy6Correct; if (!Valid && SyllogismName.equals(TestName.getSelectedItem())) UserCorrect |= NameCorrect; else if (Valid && (UserCorrect & MajorCorrect) > 0 && (UserCorrect & FigureCorrect) > 0 && (UserCorrect & MinorCorrect) > 0 && (UserCorrect & ConclusionCorrect) > 0) { char[] TestFormStr = FormStr.toCharArray(); TestFormStr[6] = Integer.toString(TestFigure.getSelectedIndex() + 1).charAt(0); if (DetermineName(new String(TestFormStr)).equals(TestName.getSelectedItem())) UserCorrect |= NameCorrect; } } public String DetermineName(String FormStr) { String SyllogismName; if (FormStr.equals("AAA - 1")) SyllogismName = "Barbara"; else if (FormStr.equals("EAE - 1")) SyllogismName = "Celarent"; else if (FormStr.equals("AII - 1")) SyllogismName = "Darii"; else if (FormStr.equals("EIO - 1")) SyllogismName = "Ferio"; else if (FormStr.equals("AEE - 2")) SyllogismName = "Camestres"; else if (FormStr.equals("EAE - 2")) SyllogismName = "Cesare"; else if (FormStr.equals("AOO - 2")) SyllogismName = "Baroko"; else if (FormStr.equals("EIO - 2")) SyllogismName = "Festino"; else if (FormStr.equals("AII - 3")) SyllogismName = "Dastisi"; else if (FormStr.equals("IAI - 3")) SyllogismName = "Disamis"; else if (FormStr.equals("EIO - 3")) SyllogismName = "Ferison"; else if (FormStr.equals("OAO - 3")) SyllogismName = "Bokardo"; else if (FormStr.equals("AEE - 4")) SyllogismName = "Camenes"; else if (FormStr.equals("IAI - 4")) SyllogismName = "Dimaris"; else if (FormStr.equals("EIO - 4")) SyllogismName = "Fresison"; else SyllogismName = "Invalid: No name"; return SyllogismName; } public void paint(Graphics g) { if (ClickedRegions2 != -1) { for (int i = 0; i <= 1; i++) { if (!Import[i]) { g.setColor(Color.red); int x[] = {xDistCircle[i], xUnDistCircle[i]}; int y[] = {yDistCircle[i], yUnDistCircle[i]}; fillDelimCircle(g, 2, x, y, width, width, (DistributedM[i] && DistributedT[i] ? REGION_1 | REGION_2 : REGION_1)); } else { g.setFont(TNRItalic); g.setColor(Color.blue); g.drawString("x", xImport[i], yImport[i]); } } g.setFont(TNR); int y = (p.getSize()).height + 27; if (!ChoiceGone) { if (Valid) { g.setColor(Color.green); g.drawString("Valid", xMImport - 23, yTerm[1] - 17); g.setFont(TNRSmall); g.setColor(Color.black); g.drawString("Syllogism Name: " + SyllogismName, 15, y); } else { g.setColor(Color.red); g.drawString("Invalid", xMImport - 26, yTerm[1] - 17); g.setFont(TNRSmall); g.setColor(Color.black); if ((Fallacy & FALLACY_2) != 0) { g.drawString("Breaks rule 2: Fallacy of the undistributed middle", 15, y); y += 18; } if ((Fallacy & FALLACY_3_MAJOR) != 0) { g.drawString("Breaks rule 3a: Fallacy of the illicite major", 15, y); y += 18; } if ((Fallacy & FALLACY_3_MINOR) != 0) { g.drawString("Breaks rule 3b: Fallacy of the illicite minor", 15, y); y += 18; } if ((Fallacy & FALLACY_4) != 0) { g.drawString("Breaks rule 4: Exclusive fallacy", 15, y); y += 18; } if ((Fallacy & FALLACY_5) != 0) { g.drawString("Breaks rule 5: Affirmative conclusion from a negative premiss", 15, y); y += 18; } if ((Fallacy & FALLACY_6) != 0) { g.drawString("Breaks rule 6: Existential fallacy", 15, y); y += 18; } } } if (!b.isAlive() && BlinkCheckbox.getState()) b.start(); if (b.show) { g.setColor(Color.orange); g.setFont(TNRItalic); int x2[] = {xTerm[1], xTerm[0]}; int y2[] = {yTerm[1], yTerm[0]}; switch (PropType2) { case 1: fillDelimCircle(g, 2, x2, y2, width, width, REGION_1); break; case 2: fillDelimCircle(g, 2, x2, y2, width, width, (byte)(REGION_1 | REGION_2)); break; case 3: g.drawString("x", xMImport, yMiddle + 6); break; case 4: g.drawString("x", xMiddle + RADIUS - offset - 8, yMiddle + RADIUS - offset + 10); break; } } g.setFont(TNR); if (!ChoiceGone) { if ((UserCorrect & VennCorrect) > 0) { g.setColor(Color.green); g.drawString("Correct", xTestMImport - 28, yTestTerm[1] - 17); } else { g.setColor(Color.red); g.drawString("Incorrect", xTestMImport - 36, yTestTerm[1] - 17); } int height = p2.getComponent(2).getSize().height; int height2 = height; int Y = p2.getLocation().y - 5; int width = p2.getSize().width + 10; for (int i = MajorCorrect; i <= NameCorrect; i <<= 1) { if ((UserCorrect & i) > 0) { g.setColor(Color.green); g.drawString("C", width, Y + height2); } else { g.setColor(Color.red); g.drawString("X", width, Y + height2); } height2 += height; } height = height2 = p3.getComponent(2).getSize().height; Y = p3.getLocation().y - 6; width = p3.getLocation().x - 23; for (int i = Fallacy2Correct; i <= Fallacy6Correct; i <<= 1) { if ((UserCorrect & i) > 0) { g.setColor(Color.green); g.drawString("C", width, Y + height2); } else { g.setColor(Color.red); g.drawString("X", width, Y + height2); } height2 += height; } } } if (ClickedRegions > 0) { g.setColor(Color.blue); for (int i = 0; i < 7; i++) { int x[] = {xTestTerm[1], xTestTerm[0], xTestMiddle}; int y[] = {yTestTerm[1], yTestTerm[0], yTestMiddle}; byte Test = (byte)(ClickedRegions & power(2, i)); if (Test > 0) { switch (Test) { case REGION_2: Test = REGION_1 | REGION_2; break; case REGION_3: Test = REGION_2; break; case REGION_4: Test = REGION_1 | REGION_3; break; case REGION_5: Test = REGION_1 | REGION_2 | REGION_3; break; case REGION_6: Test = REGION_2 | REGION_3; break; case REGION_7: Test = REGION_3; break; } fillDelimCircle(g, 3, x, y, width, width, Test); } } } g.setColor(Color.black); g.drawOval(xTerm[0], yTerm[0], RADIUS * 2, RADIUS * 2); g.drawOval(xTerm[1], yTerm[1], RADIUS * 2, RADIUS * 2); g.drawOval(xMiddle, yMiddle, RADIUS * 2, RADIUS * 2); g.drawOval(xTestTerm[0], yTestTerm[0], RADIUS * 2, RADIUS * 2); g.drawOval(xTestTerm[1], yTestTerm[1], RADIUS * 2, RADIUS * 2); g.drawOval(xTestMiddle, yTestMiddle, RADIUS * 2, RADIUS * 2); for (int i = 0; i < 9; i++) { g.setColor(Color.white); g.fillOval(xSmallCircles[i], ySmallCircles[i], SMALL_RADIUS * 2, SMALL_RADIUS * 2); g.setColor(Color.black); g.drawOval(xSmallCircles[i], ySmallCircles[i], SMALL_RADIUS * 2, SMALL_RADIUS * 2); } if (ImportedRegions > 0) { g.setColor(Color.orange.darker()); g.setFont(TNRItalic); if ((ImportedRegions & REGION_1) > 0) g.drawString("x", xTestSImport, yTestSImport); if ((ImportedRegions & REGION_3) > 0) g.drawString("x", xTestPImport, yTestPImport); if ((ImportedRegions & REGION_7) > 0) g.drawString("x", xTestMImport, yTestMImport); if ((ImportedRegions & REGION_2) > 0) g.drawString("x", (xTestSImport + xTestPImport) / 2, yTestSImport); if ((ImportedRegions & REGION_4) > 0) g.drawString("x", (xTestSImport + xTestMImport) / 2 - 7, (yTestSImport + yTestMImport) / 2 + 8); if ((ImportedRegions & REGION_5) > 0) g.drawString("x", (xTestSImport + xTestPImport) / 2, (yTestSImport + yTestMImport) / 2 - 5); if ((ImportedRegions & REGION_6) > 0) g.drawString("x", (xTestPImport + xTestMImport) / 2 + 6, (yTestPImport + yTestMImport) / 2 + 8); g.setFont(TNRItalicSmall); if ((ImportedRegions & CIRCLE_1) > 0) g.drawString("x", xSmallCircles[0] + 3, ySmallCircles[0] + (SFONTSIZE / 2)); if ((ImportedRegions & CIRCLE_2) > 0) g.drawString("x", xSmallCircles[1] + 3, ySmallCircles[1] + (SFONTSIZE / 2)); if ((ImportedRegions & CIRCLE_3) > 0) g.drawString("x", xSmallCircles[2] + 3, ySmallCircles[2] + (SFONTSIZE / 2)); if ((ImportedRegions & CIRCLE_4) > 0) g.drawString("x", xSmallCircles[3] + 3, ySmallCircles[3] + (SFONTSIZE / 2)); if ((ImportedRegions & CIRCLE_5) > 0) g.drawString("x", xSmallCircles[4] + 3, ySmallCircles[4] + (SFONTSIZE / 2)); if ((ImportedRegions & CIRCLE_6) > 0) g.drawString("x", xSmallCircles[5] + 3, ySmallCircles[5] + (SFONTSIZE / 2)); if ((ImportedRegions & CIRCLE_7) > 0) g.drawString("x", xSmallCircles[6] + 3, ySmallCircles[6] + (SFONTSIZE / 2)); if ((ImportedRegions & CIRCLE_8) > 0) g.drawString("x", xSmallCircles[7] + 3, ySmallCircles[7] + (SFONTSIZE / 2)); if ((ImportedRegions & CIRCLE_9) > 0) g.drawString("x", xSmallCircles[8] + 3, ySmallCircles[8] + (SFONTSIZE / 2)); } g.setColor(Color.black); g.setFont(TNR); g.drawString("S", xTerm[1] - 3, yTerm[1] + 5); g.drawString("P", xTerm[0] + RADIUS * 2 - 7, yTerm[0] + 5); g.drawString("M", xMiddle + RADIUS - 9, yMiddle + RADIUS * 2 + 23); g.drawString("S", xTestTerm[1] - 3, yTestTerm[1] + 5); g.drawString("P", xTestTerm[0] + RADIUS * 2 - 7, yTestTerm[0] + 5); g.drawString("M", xTestMiddle + RADIUS - 9, yMiddle + RADIUS * 2 + 23); g.setFont(TNRSmall); g.drawString("Program's diagram:", xTerm[1] - 5, 15); g.drawString("User's diagram:", xTestTerm[1] - 5, 15); if (g.equals(dblBuffer)) getGraphics().drawImage(dblBufferImage, 0, 0, this); } /* public void PaintBlink() { switch (PropType[2]) { case 1: update(xTerm[1], yTerm[1], RADIUS * 2, RADIUS * 2); break; case 2: update(xTerm[1] + RADIUS, yTerm[1], RADIUS, RADIUS * 2); break; case 3: update(xMImport - 1, yMiddle - 14, 14, 28); break; case 4: update(xMiddle + RADIUS - offset - 9, yMiddle + RADIUS - offset - 3, 14, 14); break; } update(dblBuffer); } */ public void fillDelimCircle (Graphics g, int NumOfCircles, int x[], int y[], int width[], int height[], byte Circles) { //int xDelim, int yDelim, int widthDelim, int heightDelim, boolean outside) { for (int i = 0; i < NumOfCircles; i++) { y[i] += height[i] / 2; x[i] += width[i] / 2; } int i = 0; boolean FirstFound = false; while (!FirstFound) { int h = height[i] / 2; int w = width[i] / 2; double h2 = h * h; double w2 = w * w; for (int yTest = h * -1; yTest <= h; yTest++) { double d = 1 - ((double)(yTest * yTest) / h2); int x2 = (int)Math.sqrt(d * w2); int right = 0; for (int xTest = x2; xTest >= x2 * -1 - 1; xTest--) { if (xTest != x2 * -1 - 1 && DetermineRegion(xTest + x[i], yTest + y[i], NumOfCircles, x, y, width, height) == Circles) { if (right == 0) right = xTest + x[i]; } else { if (right != 0) { if (!FirstFound) FirstFound = true; g.drawLine(right, yTest + y[i], xTest + x[i] + 1, yTest + y[i]); right = 0; } } } } i++; } } public int DetermineRegion(int x, int y, int NumOfCircles, int xCircle[], int yCircle[], int width[], int height[]) { int Circles = 0; for (int i = 0; i < NumOfCircles; i++) { double x2 = (x - xCircle[i]) * (x - xCircle[i]); double w2 = (width[i] / 2) * (width[i] / 2); double y2 = (y - yCircle[i]) * (y - yCircle[i]); double h2 = (height[i] / 2) * (height[i] / 2); if ((x2 / w2) + (y2 / h2) <= 1) Circles |= power(2, i); } return Circles; } public int power(int a, int b) { int c = 1; for (int i = 1; i <= b; i++) c *= a; return c; } public void mouseClicked(MouseEvent e) { if ((e.getModifiers() & e.BUTTON1_MASK) > 0 && (e.getModifiers() & e.CTRL_MASK) == 0) { // | e.BUTTON2_MASK | e.BUTTON3_MASK)) { int i; int x[] = new int[9]; int y[] = new int[9]; for (i = 0; i < 9; i++) { x[i] = xSmallCircles[i] + SMALL_RADIUS; y[i] = ySmallCircles[i] + SMALL_RADIUS; } if (DetermineRegion(e.getX(), e.getY(), 9, x, y, SmallWidth, SmallWidth) == 0) { x[0] = xTestTerm[1] + RADIUS; x[1] = xTestTerm[0] + RADIUS; x[2] = xTestMiddle + RADIUS; y[0] = yTestTerm[1] + RADIUS; y[1] = yTestTerm[0] + RADIUS; y[2] = yTestMiddle + RADIUS; byte Regions = (byte)DetermineRegion(e.getX(), e.getY(), 3, x, y, width, width); if (Regions > 0) { ClickedRegions ^= ConvertRegions(Regions); update(dblBuffer); } } } else { int i; int x2[] = new int[12]; int y2[] = new int[12]; int WidthSize[] = new int[12]; x2[0] = xTestTerm[1] + RADIUS; x2[1] = xTestTerm[0] + RADIUS; x2[2] = xTestMiddle + RADIUS; y2[0] = yTestTerm[1] + RADIUS; y2[1] = yTestTerm[0] + RADIUS; y2[2] = yTestMiddle + RADIUS; for (i = 0; i < 3; i++) WidthSize[i] = width[i]; for (i = 3; i < 12; i++) { x2[i] = xSmallCircles[i - 3] + SMALL_RADIUS; y2[i] = ySmallCircles[i - 3] + SMALL_RADIUS; WidthSize[i] = SmallWidth[i - 3]; } int Regions = (int)DetermineRegion(e.getX(), e.getY(), 12, x2, y2, WidthSize, WidthSize); if (Regions > 0) { ImportedRegions ^= ConvertRegions(Regions); update(dblBuffer); } } } public int ConvertRegions(int Regions) { switch (Regions) { case (REGION_1 | REGION_2 | REGION_3): return REGION_5; case (REGION_1 | REGION_2): return REGION_2; case (REGION_1 | REGION_3): return REGION_4; case (REGION_2 | REGION_3): return REGION_6; case REGION_2: return REGION_3; case REGION_3: return REGION_7; default: if (Regions > 0x07) Regions = (Regions - (Regions & 0x07)) << 4; return Regions; } } public void destroy() { Evaluate.removeActionListener(this); RandomSyllogism.removeActionListener(this); RandomDiagram.removeActionListener(this); removeMouseListener(this); BlinkCheckbox.removeItemListener(this); Figure.removeItemListener(this); MajorPremise.removeItemListener(this); MinorPremise.removeItemListener(this); Conclusion.removeItemListener(this); } public void mousePressed(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } } class Blinker extends Thread { public boolean show = false; int delay; ActionListener a; boolean run = true; Blinker(ActionListener A, int Delay) { a = A; delay = Delay; run = true; } public void run() { do { try { sleep(delay); } catch (InterruptedException e) { run = false; } show = !show; a.actionPerformed(new ActionEvent(this, 2112, "Blinker")); } while (run); } }