Dolev/ 0040755 0024345 0024276 00000000000 07240223461 0013276 5 ustar 00schnitz i4staff 0000257 0000121 Dolev/AdjFrame.java 0100644 0024345 0024276 00000002471 07240223457 0015620 0 ustar 00schnitz i4staff 0000257 0000121 /* * AdjFrame.java * * Created on 28. Dezember 2000, 09:50 */ /** * * @author fhofmann * @version */ import java.awt.*; public class AdjFrame extends java.awt.Frame { AdjPanel mysim; Algorithm algorithm; /** Creates new form GraphFrame */ public AdjFrame(Algorithm sm, CommunicationGraph cg) { super("adjacence matrix"); initComponents (); algorithm = sm; mysim = new AdjPanel(sm, cg); this.add("Center", mysim); this.setLocation(0, 300); this.setSize(500, 400); this.show(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the FormEditor. */ private void initComponents () { addWindowListener (new java.awt.event.WindowAdapter () { public void windowClosing (java.awt.event.WindowEvent evt) { exitForm (evt); } } ); } /** Exit the Application */ private void exitForm(java.awt.event.WindowEvent evt) { System.exit (0); } public void notifyNextTimestep() { mysim.repaint(); } public void paint(Graphics g) { mysim.paint(g); } // Variables declaration - do not modify // End of variables declaration } Dolev/AdjPanel.java 0100644 0024345 0024276 00000005705 07240223457 0015630 0 ustar 00schnitz i4staff 0000257 0000121 /* * AdjMatrixPanel.java * * Created on 27. Dezember 2000, 21:17 */ /** * * @author fhofmann * @version */ import java.awt.*; import java.awt.event.*; public class AdjPanel extends Panel implements ActionListener { Algorithm algorithm; CommunicationGraph cg; Button mybuttons[][]; int dimension; Algorithm notifySystem = null; public AdjPanel(Algorithm a, CommunicationGraph cg) { this.algorithm = a; this.cg = cg; dimension = cg.dimension; add_buttons(); } private void add_buttons() { mybuttons= new Button[dimension + 1][dimension + 1]; setLayout(new GridLayout(dimension + 1, dimension + 1)); // the corner-button mybuttons[0][0] = new Button(" "); mybuttons[0][0].setForeground (Color.black); mybuttons[0][0].setBackground (Color.gray); add (mybuttons[0][0]); // the first line is just for heading for (int i = 1; i < dimension + 1; i++) { mybuttons[0][i] = new Button("" + i); mybuttons[0][i].setForeground (Color.black); mybuttons[0][i].setBackground (Color.gray); add (mybuttons[0][i]);} // now insert the buttons; use Grid-Layout to set them correct for (int i = 1; i < dimension + 1; i++) { mybuttons[i][0] = new Button("" + i); mybuttons[i][0].setForeground (Color.black); mybuttons[i][0].setBackground (Color.gray); add (mybuttons[i][0]); for (int j = 1; j < dimension + 1; j++) { mybuttons[i][j] = new Button(" "); mybuttons[i][j].setForeground (Color.black); mybuttons[i][j].setBackground (Color.lightGray); add (mybuttons[i][j]); mybuttons[i][j].addActionListener(this); } } } public void actionPerformed(ActionEvent e) { Koord k; if ((k = detect_button(e.getSource())) != null) { invert(k); } else System.out.println ("internal Error occured! no Button catched"); } public void paint(Graphics g) { paintNodes(); } protected void invert(Koord k) { boolean flag; if (flag = cg.test(k)) { cg.unset(k); if (notifySystem != null) notifySystem.deleteEdge(k); } else { cg.set(k); if (notifySystem != null) notifySystem.addEdge(k); } repaint(); } protected Koord detect_button(Object w) { for (int i = 0; i < dimension + 1; i++) for (int j = 0; j < dimension + 1; j++) if (w == mybuttons[i][j]) return new Koord(i - 1, j - 1); return null; } protected void paintNodes() { Koord k = new Koord(); for (k.x = 0; k.x < dimension; k.x++) for (k.y = 0; k.y < dimension; k.y++) mark_node(k, cg.test(k)); } protected void mark_node(Koord k, boolean b) { if (b) mybuttons[k.x+1][k.y+1].setLabel("X"); else mybuttons[k.x+1][k.y+1].setLabel(" "); } public void changeNotify(Algorithm s) { notifySystem = s; } } Dolev/Algorithm.java 0100644 0024345 0024276 00000001231 07240223457 0016066 0 ustar 00schnitz i4staff 0000257 0000121 import java.awt.*; import java.util.*; public interface Algorithm { public SimManager getSimManager(); public int getSimulationTime(); public void enqueue(Message message); public int getNumberOfNodes(); public Vector getMessages(); public int[] getDecisions(); public void incrementClock(int t); public void addRow(String string, int node, boolean withApplicationButton); public CommunicationGraph getCommunicationGraph(); public Vector getOutgoingBuffers(int i); public HistoryFrame getHistoryFrame(); public GraphFrame getGraphFrame(); public void addEdge(Koord k); public void deleteEdge(Koord k); } Dolev/BasicConnection.java 0100644 0024345 0024276 00000005010 07240223457 0017200 0 ustar 00schnitz i4staff 0000257 0000121 import java.util.*; import scheduler.*; import sysPr.*; public class BasicConnection { SimProcess source, destination; Semaphore empty, full, mutex; Semaphore messageArrived = null; Vector buffer = new Vector(); public BasicConnection(SimProcess source, SimProcess destination) { this.source = source; this.destination = destination; empty = new Semaphore("E ", 100, source.scheduler); full = new Semaphore("F ", 0, source.scheduler); mutex = new Semaphore("M ", 1, source.scheduler); } public BasicConnection(SimProcess source, SimProcess destination, Semaphore messageArrived) { this.source = source; this.destination = destination; empty = new Semaphore("E ", 100, source.scheduler); full = new Semaphore("F ", 0, source.scheduler); mutex = new Semaphore("M ", 1, source.scheduler); this.messageArrived = messageArrived; } public void send(String type) { BasicMessage message = new BasicMessage(source, destination, type, 2); message.print(source.getName() + " ---> " + destination.getName() + ": "); xmit(message); } public BasicMessage receive() { BasicMessage message = null; message = xrcv(); message.destination.setTime(message.timestamp < destination.getTime() ? destination.getTime() + 1 : message.timestamp + 1); // message.print(destination.getName() + " <--- " + source.getName() + ": "); return message; } public synchronized void xmit(BasicMessage message) { SimProcess destination = message.destination; empty.p(); mutex.p(); buffer.addElement(message); full.v(); if (messageArrived != null) { messageArrived.v(); } mutex.v(); ((Algorithm)(destination.scheduler.system)).getGraphFrame().stateChanged(); } BasicMessage xrcv() { BasicMessage message; SimProcess process; full.p(); mutex.p(); message = (BasicMessage)(buffer.elementAt(0)); process = message.destination; buffer.removeElementAt(0); for (int i = 0; i < buffer.size(); i++) { if (((BasicMessage)(buffer.elementAt(i))).deliveringTime <= ((Algorithm)(destination.scheduler.system)).getSimulationTime()) { ((BasicMessage)(buffer.elementAt(i))).deliveringTime = ((Algorithm)(process.scheduler.system)).getSimulationTime() + 1; } } empty.v(); mutex.v(); return message; } public void print(String string) { SystemPrinter.println(string + "source =" + source.getName() + ", destination = " + destination.getName()); } } } public BasicConnection(SimProcess source, SimProcess destination, Semaphore messageArrived) { this.source = source; this.destination = destination; empty = new Semaphore("E ", 100, source.scheduler); full = new Semaphore("F ", 0, source.scheduler); mutex = new Semaphore("M ", 1, source.scheduler); this.messageArrived = messageArrived; } public void send(String type) { BasicMessage message = new BasicMessage(source, destination, type, 2); message.pDolev/BasicMessage.java 0100644 0024345 0024276 00000001555 07240223457 0016477 0 ustar 00schnitz i4staff 0000257 0000121 import sysPr.*; class BasicMessage { static final int DATALEN = 10; SimProcess source, destination; String type; String label = null; double timestamp; int creationTime; int deliveringTime; public BasicMessage(SimProcess f_source, SimProcess f_destination, String f_type, int latency) { source = f_source; destination = f_destination; type = f_type; timestamp = source.incrementTime(); creationTime = ((Algorithm)(source.scheduler.system)).getSimulationTime(); deliveringTime = creationTime + latency; } public void print(String string) { SystemPrinter.println(string + "source = " + source.getName() + ", destination = " + destination.getName() + ", type = " + type + ", timestamp = " + timestamp + ", creationTime = " + creationTime + ", deliveringTime = " + deliveringTime); } } Dolev/CommunicationGraph.java 0100644 0024345 0024276 00000002046 07240223457 0017734 0 ustar 00schnitz i4staff 0000257 0000121 /* * CommunicationGraph.java * * Created on 30. November 2000, 21:22 */ /** * * @author fhofmann * @version */ public class CommunicationGraph extends Object { public int dimension = 0; public boolean[][] adjacenceMatrix = null; /** Creates new CommunicationGraph */ public CommunicationGraph() { } public CommunicationGraph(int n) { adjacenceMatrix = new boolean[n][n]; dimension = n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { adjacenceMatrix[i][j] = false; } } } public void addBidirectionalConnection(int i, int j) { adjacenceMatrix[i][j] = true; adjacenceMatrix[j][i] = true; } public void addUnidirectionalConnection(int i, int j) { adjacenceMatrix[i][j] = true; } public boolean test(Koord k) { return adjacenceMatrix[k.x][k.y]; } public void set(Koord k) { adjacenceMatrix[k.x][k.y] = true; } public void unset(Koord k) { adjacenceMatrix[k.x][k.y] = false; } } Dolev/Connection.java 0100644 0024345 0024276 00000001574 07240223457 0016251 0 ustar 00schnitz i4staff 0000257 0000121 import scheduler.*; public class Connection extends BasicConnection { public Connection(SimProcess source, SimProcess destination) { super(source, destination); } public Connection(SimProcess source, SimProcess destination, Semaphore messageArrived) { super(source, destination, messageArrived); } public void send(String type) { Message message; if (type.equals("NEXTROUND")) { message = new Message(source, destination, type, 0, 1); } else { message = new Message(source, destination, type, 0, 2); } // message.print(source.getName() + " ---> " + destination.getName() + ": "); xmit(message); } public void send(String type, int j) { Message message = new Message(source, destination, type, j, 2); // message.print(source.getName() + " ---> " + destination.getName() + ": "); xmit(message); } } Dolev/ControlThread.java 0100644 0024345 0024276 00000001422 07240223457 0016712 0 ustar 00schnitz i4staff 0000257 0000121 /* * ControlThread.java * * Created on 8. Dezember 2000, 10:46 */ /** * * @author fhofmann * @version */ import scheduler.*; public class ControlThread extends SimProcess { /** Creates new ControlThread */ public ControlThread(String name, Scheduler scheduler, int nodeNumber) { super(name, scheduler, nodeNumber); ((Algorithm)(scheduler.system)).addRow(name, nodeNumber, false); scheduler.createThread(this); } public void runProcess() { int i; while (true) { scheduler.suspend(); for (i = 0; i < ((Algorithm)(scheduler.system)).getNumberOfNodes(); i++) { // SystemPrinter.println("Send REQUEST"); ((Connection)(outgoingConnections.elementAt(i))).send("NEXTROUND"); } } } } Dolev/DolevMain.java 0100644 0024345 0024276 00000021400 07240223457 0016016 0 ustar 00schnitz i4staff 0000257 0000121 /* * Ricart.java * * Created on 20. November 2000, 19:42 */ /** * * @author fhofmann * @version */ import java.awt.*; import java.awt.event.*; import java.util.*; import java.lang.*; import java.io.*; import scheduler.*; import sysPr.*; public class DolevMain extends java.applet.Applet implements Algorithm, Application, Runnable { static private final int NODES = 7; static private final int PROCESSESPERNODE = 1; static private final int SYSERR = 1; static private final int SPECIALPROCESSES = 1; static Scheduler scheduler; static Timer timer; private GridBagLayout gridBag; private GridBagConstraints c; private Button timeStepButton = new Button("next timestep(0)"); private Button exitButton = new Button("exit"); private Label label; private TextField[] textField = new TextField[NODES * PROCESSESPERNODE + SPECIALPROCESSES]; private Button[] button = new Button[NODES * PROCESSESPERNODE + SPECIALPROCESSES]; private Button[] applicationButton = new Button[NODES * PROCESSESPERNODE + SPECIALPROCESSES]; private TextField[] syncState = new TextField[NODES * PROCESSESPERNODE + SPECIALPROCESSES]; static public int simulationTime = 0; private Vector oldMessageQueue, messageQueue; private SimManager simulationManager; private CommunicationGraph communicationGraph; public HistoryFrame repFrame; public GraphFrame graphFrame; public AdjFrame adjFrame; SystemPrinter systemPrinter = new SystemPrinter(); SystemThread[] systemThread = new SystemThread[NODES]; SpecialThread specialThread; private int rowNumber = 0; // varaible for counting rows /** * @param args the command line arguments */ public void init () { int i, j; gridBag = new GridBagLayout(); c = new GridBagConstraints(); setLayout(gridBag); // Create scheduler scheduler = new Scheduler(this, NODES * 2); messageQueue = new Vector(); communicationGraph = new CommunicationGraph(getNumberOfNodes()); // Create and name the processes specialThread = new SpecialThread("round", scheduler, 0, communicationGraph); for (i = 0; i < NODES; i++) { systemThread[i] = new SystemThread("S" + (i + 1), scheduler, i, communicationGraph); } // Add connections for (i = 0; i < getNumberOfNodes(); i++) { specialThread.addConnection(systemThread[i]); systemThread[i].addConnection(systemThread[i]); communicationGraph.addBidirectionalConnection(i, i); for (j = 0; j < i; j++) { systemThread[i].addConnection(systemThread[j]); systemThread[j].addConnection(systemThread[i]); communicationGraph.addBidirectionalConnection(i, j); } } c.gridwidth = 8; c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = rowNumber; c.weightx = 1.0; c.weighty = 1.0; gridBag.setConstraints(timeStepButton, c); add(timeStepButton); c.gridwidth = 8; c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = rowNumber + 1; c.weightx = 1.0; c.weighty = 1.0; gridBag.setConstraints(exitButton, c); add(exitButton); validate(); MyTimeStepListener myTimeStepListener = new MyTimeStepListener(); timeStepButton.addActionListener(myTimeStepListener); MyExitListener myExitListener = new MyExitListener(); exitButton.addActionListener(myExitListener); simulationManager = new SimManager(this); repFrame = new HistoryFrame(this); graphFrame = new GraphFrame(this); adjFrame = new AdjFrame(this, communicationGraph); adjFrame.mysim.changeNotify(this); // For scheduling purposes create intervall timer timer = new Timer(scheduler); timer.setName("timer"); timer.start(); scheduler.initialize(); } public static void main(String args[]) { Frame f = new Frame("Dolev"); DolevMain system = new DolevMain(); system.init(); system.setSize(350, 400); system.setLocation(0,0); system.start(); f.add("Center", system); f.setSize(350, 300); f.setLocation(0, 0); f.show(); } public void updateState(int pid, String string, Color color, String buttonText) { textField[pid].setBackground(color); textField[pid].setText(string); button[pid].setLabel(buttonText); } public void updateButton(int pid, String label, boolean enabled, Color background) { button[pid].setEnabled(enabled); button[pid].setLabel(label); button[pid].setBackground(background); } public void updateSyncState(int pid, Color color) { syncState[pid].setBackground(color); } public void updateSyncState(int pid, String string, Color color) { syncState[pid].setText(string); syncState[pid].setBackground(color); } public SimManager getSimManager() { return simulationManager; } public int getSimulationTime() { return simulationTime; } public synchronized void enqueue(Message message) { messageQueue.addElement(message); } public int getNumberOfNodes() { return NODES; } public synchronized Vector getMessages() { return oldMessageQueue; } public int[] getDecisions() { return simulationManager.decisions; } public CommunicationGraph getCommunicationGraph() { return communicationGraph; } public void incrementClock(int t) { for (int i = 0; i < NODES; i++) { } } public void addRow(String string, int node, boolean withApplicationButton) { addLabel("Thread", rowNumber); addTextField("", rowNumber); addButton("resume", rowNumber); addSyncState("", rowNumber); rowNumber++; } public void addLabel(String name, int index) { label = new Label(name + index, Label.LEFT); c.gridx = 0; c.gridy = index; c.gridwidth = 1; c.weighty = 1.0; c.weightx = 1.0; gridBag.setConstraints(label, c); add(label); } public void addTextField(String string, int index) { textField[index] = new TextField(string, 8); textField[index].setEditable(true); c.gridx = 1; c.gridwidth = 1; c.weighty = 1.0; c.weightx = 1.0; gridBag.setConstraints(textField[index], c); add(textField[index]); } public void addButton(String string, int index) { button[index] = new Button(string); button[index].setEnabled(false); button[index].setBackground(Color.gray); button[index].addMouseListener(new MyMouseListener(index)); c.gridx = 2; c.weighty = 1.0; c.weightx = 1.0; c.gridwidth = 1; gridBag.setConstraints(button[index], c); add(button[index]); } public void addSyncState(String string, int index) { syncState[index] = new TextField(string, 8); syncState[index].setEditable(true); c.gridx = 3; c.gridwidth = 1; c.weighty = 1.0; c.weightx = 1.0; gridBag.setConstraints(syncState[index], c); add(syncState[index]); } public void run() { } public Vector getOutgoingBuffers(int i) { Vector outgoingBuffers = new Vector(); for (int j = 0; j < systemThread[i].outgoingConnections.size(); j++) { outgoingBuffers.add(((BasicConnection)(systemThread[i].outgoingConnections.elementAt(j))).buffer); } return outgoingBuffers; } public HistoryFrame getHistoryFrame() { return repFrame; } public GraphFrame getGraphFrame() { return graphFrame; } class MyMouseListener extends MouseAdapter { private int index; public MyMouseListener(int i) { index = i; } public synchronized void mousePressed(MouseEvent e) { } public synchronized void mouseReleased(MouseEvent e) { button[index].setLabel(""); scheduler.resume(textField[index].getText()); } } public void addEdge(Koord k) { systemThread[k.x].addConnection(systemThread[k.y]); systemThread[k.y].addConnection(systemThread[k.x]); communicationGraph.addUnidirectionalConnection(k.x, k.y); graphFrame.stateChanged(); } public void deleteEdge(Koord k) { systemThread[k.x].deleteConnection(systemThread[k.y]); systemThread[k.y].deleteConnection(systemThread[k.x]); graphFrame.stateChanged(); } class MyTimeStepListener implements ActionListener { public void actionPerformed(ActionEvent e) { simulationTime++; timeStepButton.setLabel("next timestep(" + simulationTime + ")"); oldMessageQueue = messageQueue; messageQueue = new Vector(); simulationManager.nextTimestep(oldMessageQueue); } } class MyExitListener implements ActionListener { public void actionPerformed(ActionEvent e) { SystemPrinter.close(); System.exit(1); } } } Dolev/GraphCanvas.java 0100644 0024345 0024276 00000004042 07240223460 0016332 0 ustar 00schnitz i4staff 0000257 0000121 /* * GraphCanvas.java * * Created on 26. November 2000, 10:39 */ /** * * @author fhofmann * @version */ import java.awt.*; import java.awt.event.*; import sysPr.*; public class GraphCanvas extends Canvas { GraphLayout ms; Algorithm algorithm; int mousemovenode; /** Creates new GraphCanvas */ public GraphCanvas(Algorithm a) { // Instantiating GraphCanvas this.algorithm = a; ms = new GraphLayout(a); doLayout(); // //setup our Mouse-Event-Adapters // this.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { mousemovenode = ms.getnodehandle(new Koord(e.getX(),e.getY())); if (mousemovenode >= 0) ms.invertnode(mousemovenode); if (e.getClickCount() > 1) doubleclick_action(mousemovenode, e.getClickCount()); repaint(); } public void mouseReleased(MouseEvent e) { Koord k = new Koord (e.getX(),e.getY()); if (mousemovenode >= 0) { if (ms.getnodehandle(k) != mousemovenode) if (contains (k.x,k.y)) ms.newkoord(mousemovenode, k); ms.invertnode(mousemovenode); } repaint(); } }); this.addMouseMotionListener ( new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { Koord k = new Koord (e.getX(),e.getY()); if (mousemovenode >= 0) if (ms.getnodehandle(k) != mousemovenode) if (contains (k.x,k.y)) ms.newkoord(mousemovenode, k); repaint(); } }); } public void doLayout() { ms.doLayout(); repaint(); } public void paint(Graphics g) { ms.paint(g); } protected void doubleclick_action(int nodeid, int count) { ms.doubleclick_action(nodeid, count); } public void addEdge(Koord k) { SystemPrinter.println("********** GraphCanvas.addEdge not yet implemented!"); } public void deleteEdge(Koord k) { SystemPrinter.println("********** GraphCanvas.deleteEdge not yet implemented!"); } } Dolev/GraphFrame.form 0100644 0024345 0024276 00000002553 07240223460 0016200 0 ustar 00schnitz i4staff 0000257 0000121
Dolev/GraphFrame.java 0100644 0024345 0024276 00000003023 07240223460 0016147 0 ustar 00schnitz i4staff 0000257 0000121 /* * GraphFrame.java * * Created on 25. November 2000, 17:08 */ /** * * @author fhofmann * @version */ import java.awt.*; import java.awt.event.*; public class GraphFrame extends java.awt.Frame { GraphCanvas mysim; Algorithm algorithm; /** Creates new form GraphFrame */ public GraphFrame(Algorithm sm) { super("Communication graph"); initComponents (); algorithm = sm; mysim = new GraphCanvas(sm); this.add("Center", mysim); this.setLocation(0, 300); this.setSize(500, 400); this.show(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the FormEditor. */ private void initComponents () {//GEN-BEGIN:initComponents addWindowListener (new java.awt.event.WindowAdapter () { public void windowClosing (java.awt.event.WindowEvent evt) { exitForm (evt); } } ); }//GEN-END:initComponents /** Exit the Application */ private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm System.exit (0); }//GEN-LAST:event_exitForm public void notifyNextTimestep() { mysim.repaint(); } public void paint(Graphics g) { mysim.paint(g); } public void stateChanged() { mysim.repaint(); } // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables } Dolev/GraphLayout.java 0100644 0024345 0024276 00000015676 07240223460 0016413 0 ustar 00schnitz i4staff 0000257 0000121 /* * SimSystem.java * * Created on 28. November 2000, 20:53 */ /** * * @author fhofmann * @version */ import java.awt.*; import java.util.*; import sysPr.*; public class GraphLayout extends Object { GraphLayoutManager slm; GraphNode[] myNodes; Algorithm algorithm; int count; // counts teh number of outgoing messages NormVec nv; double defaultlength = 30; double spitzen_faktor = 0.8; double dist_faktor = 0.2; Color mycolor = Color.blue; /** Creates new SimSystem */ public GraphLayout(Algorithm a) { // Instantiating GraphLayout algorithm = a; myNodes = new GraphNode[a.getNumberOfNodes()]; for (int i = 0; i < a.getNumberOfNodes(); i++) { myNodes[i] = new GraphNode(i); } slm = new GraphLayoutManager(a); } public void doLayout() { slm.layout(myNodes); } public void paint(Graphics g) { CommunicationGraph cg = algorithm.getCommunicationGraph(); // draw edges for (int i = 0; i < cg.dimension; i++) { for (int j = 0; j < i; j++) { if (cg.adjacenceMatrix[i][j] && cg.adjacenceMatrix[j][i]) { GraphNode a = myNodes[i]; GraphNode b = myNodes[j]; Koord ka = new Koord (a.mykoord.x + a.getdim().x/2, a.mykoord.y + a.getdim().y/2); Koord kb = new Koord (b.mykoord.x + b.getdim().x/2, b.mykoord.y + b.getdim().y/2); g.setColor(Color.black); g.drawLine(ka.x, ka.y, kb.x, kb.y); } } for (int j = 0; j < cg.dimension; j++) { if (cg.adjacenceMatrix[i][j] && !cg.adjacenceMatrix[j][i]) { GraphNode a = myNodes[i]; GraphNode b = myNodes[j]; Koord ka = new Koord (a.mykoord.x + a.getdim().x/2, a.mykoord.y + a.getdim().y/2); Koord kb = new Koord (b.mykoord.x + b.getdim().x/2, b.mykoord.y + b.getdim().y/2); Koord km = new Koord((ka.x + kb.x) / 2, (ka.y + kb.y) / 2); nv = new NormVec(ka, km); Koord kh = new Koord((int)(km.x - nv.x * 10), (int)(km.y - nv.y * 10)); Koord spitze1 = new Koord((int) ( nv.y * defaultlength * dist_faktor) + kh.x, (int) (-nv.x * defaultlength * dist_faktor) + kh.y); Koord spitze2 = new Koord((int) (-nv.y * defaultlength * dist_faktor) + kh.x, (int) ( nv.x * defaultlength * dist_faktor) + kh.y); g.setColor(Color.black); g.drawLine(ka.x, ka.y, kb.x, kb.y); g.drawLine(spitze1.x, spitze1.y, km.x, km.y); g.drawLine(spitze2.x, spitze2.y, km.x, km.y); } } } // draw nodes for (int i = 0; i < algorithm.getNumberOfNodes(); i++) { myNodes[i].paint(g); } // draw messages in transition for (int i = 0; i < cg.dimension; i++) { Vector outgoingBuffers; outgoingBuffers = algorithm.getOutgoingBuffers(i); for (int j = 0; j < outgoingBuffers.size(); j++) { Vector buffer = (Vector)outgoingBuffers.elementAt(j); count = 0; for (int k = 0; k < buffer.size(); k++) { BasicMessage message = (BasicMessage)buffer.elementAt(k); // draw arrow paintMessage(g, message); } } } } Koord msgdir; public void paintMessage(Graphics g, BasicMessage m) { // MessageRepresentation mr; Koord k0, k1, k2, spitze1, spitze2, kdir; // atobcount = btoacount = 0; // Enumeration iter = msgreps.elements(); // while (iter.hasMoreElements()) { // mr = (MessageRepresentation)iter.nextElement(); k0 = calculate_koord(m); k1 = new Koord((int) ( nv.x * defaultlength) + k0.x, (int) (nv.y * defaultlength) + k0.y); k2 = new Koord((int) ( nv.x * defaultlength * spitzen_faktor) + k0.x, (int) ( nv.y * defaultlength * spitzen_faktor) + k0.y); spitze1 = new Koord((int) ( nv.y * defaultlength * dist_faktor) + k2.x, (int) (-nv.x * defaultlength * dist_faktor) + k2.y); spitze2 = new Koord((int) (-nv.y * defaultlength * dist_faktor) + k2.x, (int) ( nv.x * defaultlength * dist_faktor) + k2.y); g.setColor(((Message)m).getColor()); g.drawLine(k0.x, k0.y, k1.x, k1.y); g.drawLine(spitze1.x, spitze1.y, k1.x, k1.y); g.drawLine(spitze2.x, spitze2.y, k1.x, k1.y); if (m.label != null) g.drawString (m.label, k0.x, k0.y); } public Koord calculate_koord(BasicMessage m) { // always has to be called before calculate_direction GraphNode from = myNodes[m.source.nodeNumber]; GraphNode to = myNodes[m.destination.nodeNumber]; if (m.source.nodeNumber == 1 && m.destination.nodeNumber == 0) { int z = 1; } Koord fromk, tok; int edgedist = 15; int actedgedist; fromk = new Koord(from.getkoord().x + from.getdim().x / 2, from.getkoord().y + from.getdim().y / 2); tok = new Koord(to.getkoord().x + to.getdim().x / 2, to.getkoord().y + to.getdim().y / 2); count++; if (from == to) { fromk = new Koord(tok.x + 50, tok.y); tok = new Koord(to.getkoord().x + to.getdim().x / 2, to.getkoord().y + to.getdim().y / 2); } nv = new NormVec (fromk, tok); double distance = nv.l * 0.3; // which offset from from-node to be drawn Koord k1 = new Koord((int)(nv.x * distance) + fromk.x, (int)(nv.y * distance) + fromk.y); // Calculate the individual distance from the connection actedgedist = edgedist * count; Koord msgkoord = new Koord ((int)(-nv.y * actedgedist) + k1.x, (int)( nv.x * actedgedist) + k1.y); msgdir = new Koord ((int)( nv.x * actedgedist * 2) + msgkoord.x, (int)( nv.y * actedgedist * 2) + msgkoord.y); return msgkoord; } public int getnodehandle(Koord k) { for (int i = 0; i < algorithm.getNumberOfNodes(); i++) if (myNodes[i].is_in(k)) return i; return -1; } public void newkoord(int handle, Koord k) throws ArrayIndexOutOfBoundsException { if (handle > myNodes.length) throw new ArrayIndexOutOfBoundsException(); myNodes[handle].setkoord(k); } public void invertnode(int handle) throws ArrayIndexOutOfBoundsException { if (handle > myNodes.length) throw new ArrayIndexOutOfBoundsException(); myNodes[handle].invert(); } public boolean doubleclick_action(int nodehandle, int count) throws ArrayIndexOutOfBoundsException { if (nodehandle > myNodes.length) throw new ArrayIndexOutOfBoundsException(); return myNodes[nodehandle].doubleclick_action(count); } class NormVec { double x, y, l; NormVec(Koord k0, Koord k1) { x = k1.x - k0.x; y = k1.y - k0.y; l = (int) Math.sqrt (Math.pow (x, 2) + Math.pow (y, 2)); x /= l; y /= l; } public void print(String string) { SystemPrinter.println(string + ": x = " + x + ", " + y); } } }.y) / 2); nv = new NormVec(ka, km); Koord khDolev/GraphLayoutManager.java 0100644 0024345 0024276 00000001502 07240223460 0017665 0 ustar 00schnitz i4staff 0000257 0000121 /* * GraphLayoutManager.java * * Created on 28. November 2000, 21:03 */ /** * * @author fhofmann * @version */ import sysPr.*; public class GraphLayoutManager extends Object { int r; int xoffset; int yoffset; Algorithm algorithm; /** Creates new GraphLayoutManager */ public GraphLayoutManager(Algorithm a) { r = 100; xoffset = 250; yoffset = 150; algorithm = a; } public void layout(GraphNode []nodes) { int anz = algorithm.getNumberOfNodes(); // CircleLayout GraphNode m; for (int i = 0; i < algorithm.getNumberOfNodes(); i++) { m = (GraphNode)nodes[i]; m.setx(xoffset + (int)(r * Math.cos(2 * Math.PI / anz * i))); m.sety(yoffset + (int)(r * Math.sin(2 * Math.PI / anz * i))); } } } Dolev/GraphNode.java 0100644 0024345 0024276 00000010361 07240223460 0016005 0 ustar 00schnitz i4staff 0000257 0000121 import java.awt.Graphics; import java.awt.Color; import java.awt.FontMetrics; import java.awt.Rectangle; /** * Description of the Class * *@author administrator *@created 31. Januar 2001 */ public class GraphNode { Koord mykoord; Koord dim; String mylabel; // protected DNodeComment mycomment; Color defaultcolor = Color.white; //normal state Color invertcolor = Color.blue; //if i'm clicked Color initiatorcolor = Color.yellow; //if i'm initiator Color actcolor; //actual state to be painted Color mymsgcolor = Color.blue; //my messages... if the messages don't get the choice // k is Coord, d is height and width /** * Constructor for the GraphNode object * *@param n Description of Parameter *@param k Description of Parameter *@param d Description of Parameter */ public GraphNode(int n, Koord k, Koord d) { // super(n); mylabel = String.valueOf(n + 1); mykoord = (Koord) k.clone(); dim = (Koord) d.clone(); // mylabel = new String ("" + mynumber); actcolor = defaultcolor; } /** * Constructor for the GraphNode object * *@param n Description of Parameter */ public GraphNode(int n) { this(n, new Koord(25 * n, (5 + n) * n), new Koord(20, 20)); } /** * Description of the Method * *@param c Description of Parameter */ public void set_color(Color c) { actcolor = defaultcolor = c; } /** * Description of the Method * *@param x Description of Parameter */ public void setx(int x) { mykoord.x = x; notify_koords(); } /** * Description of the Method * *@param y Description of Parameter */ public void sety(int y) { mykoord.y = y; notify_koords(); } /** * Description of the Method * *@param k Description of Parameter */ public void setkoord(Koord k) { mykoord.x = k.x; mykoord.y = k.y; notify_koords(); } /** * Description of the Method * *@param d Description of Parameter */ public void setdim(Koord d) { dim.x = d.x; dim.y = d.y; } /** * Description of the Method * *@return Description of the Returned Value */ public int getx() { return mykoord.x; } /** * Description of the Method * *@return Description of the Returned Value */ public int gety() { return mykoord.y; } /** * Description of the Method * *@return Description of the Returned Value */ public Koord getkoord() { return mykoord; } /** * Description of the Method * *@return Description of the Returned Value */ public Koord getdim() { return dim; } /** * Description of the Method * *@param k Description of Parameter *@return Description of the Returned Value */ public boolean is_in(Koord k) { Rectangle r = new Rectangle(mykoord.x, mykoord.y, dim.x, dim.y); return (r.contains(k.x, k.y)); } /** * Description of the Method */ public void be_initiator() { //override the HistoryNode.be_initiator() // super.be_initiator(); defaultcolor = initiatorcolor; } /** * Description of the Method * *@param g Description of Parameter */ public void paint(Graphics g) { FontMetrics fm = g.getFontMetrics(); g.setColor(actcolor); g.fillRect(mykoord.x, mykoord.y, dim.x, dim.y); g.setColor(Color.black); g.drawRect(mykoord.x, mykoord.y, dim.x, dim.y); g.drawString(mylabel, mykoord.x + (dim.x - fm.stringWidth(mylabel)) / 2, mykoord.y + (dim.y + fm.getAscent()) / 2); } /** * Description of the Method */ public void invert() { if (actcolor == defaultcolor) { actcolor = invertcolor; } else { actcolor = defaultcolor; } } /* * public void set_commentator(DNodeComment d) { * mycomment = d; * } */ /** * Description of the Method * *@param count Description of Parameter *@return Description of the Returned Value */ public boolean doubleclick_action(int count) { be_initiator(); return true; } /** * Description of the Method */ private void notify_koords() { // if (mycomment != null) {mycomment.notify_koords (mykoord, dim);} } } Dolev/GridMessage.java 0100644 0024345 0024276 00000003153 07240223460 0016331 0 ustar 00schnitz i4staff 0000257 0000121 import java.awt.*; import java.io.*; public class GridMessage { HistoryNode from; HistoryNode to; public int sendingTime; Color mycolor; Color defaultcolor = Color.blue; public GridMessage(HistoryNode a, HistoryNode b){ mycolor = defaultcolor; from = (HistoryNode) a; to = (HistoryNode) b; } public void setColor(Color c) { mycolor=c; } // Paint a Message public void paint(Graphics g){ g.setColor(mycolor); g.drawLine(from.getX(),from.getY(),to.getX(),to.getY()); } public void printGraphic(PrintWriter tmp) { System.out.println("printing GridMessage " + mycolor); String color = "Blau"; if (mycolor == Color.red) color = "Rot"; else if (mycolor == Color.magenta) color = "Magenta"; else if (mycolor == Color.yellow) color = "Gelb"; else if (mycolor == Color.cyan) color = "Cyan"; else if (mycolor == Color.green) color = "Gr\\x9f n"; tmp.println("