/************************************************************/ /* Platz.java Version 2003/03/28 */ /* */ /* Tom Fellmann, Christoph Weißenborn */ /* */ /************************************************************/ import java.awt.*; import java.io.*; import javax.swing.*; public class Platz extends JComponent implements PN_Knoten{ /***************************************************/ /* Daten-Teil */ /***************************************************/ public static final Color NORMAL_FARBE = Color.black; public static final Color MARKIERT_FARBE = Color.red; public static final Color TEXT_FARBE = Color.white; protected static int maxID=0; //globale Durchnummerierung aller Platz-Objekte, für ID private int ID; // private Point Mittel_Pkt; // Koordinaten des Platzes private int Radius; // Radius des Platzes private String Text; // Bezeichnung des Platzes private Tupel Kapazitaet; // Kapazität (FarbTupel) private Tupel Marken; // Marken (FarbTupel) private KantenListe WegKanten; // Liste aller ausgehenden Kanten private KantenListe HinKanten; // Liste aller eingehenden Kanten private boolean Markierung; // Hervorhebung private smartiPunkte smarties; // Punkte der Marken & übrigen Kapazitäten private boolean seitletztemMalenGeaendert; /***************************************************/ /* Konstruktor */ /***************************************************/ public Platz(Point mittelPkt, int radius, String text) { this.ID = maxID; maxID++; this.Mittel_Pkt = new Point( mittelPkt); this.Radius = radius; this.Text = new String(text); this.Kapazitaet = new Tupel( 0); this.Marken = new Tupel( 0); this.WegKanten = new KantenListe(); this.HinKanten = new KantenListe(); this.Markierung = false; this.setLocation( mittelPkt.x-(radius>>1), mittelPkt.y-(radius>>1)); this.setSize( Radius, Radius); smarties = new smartiPunkte(this, smarties); seitletztemMalenGeaendert = false; } //Platz-Konstruktor private Platz() { this.ID = -1; this.Mittel_Pkt = null; this.Radius = 0; this.Text = null; this.Kapazitaet = new Tupel( 0); this.Marken = new Tupel( 0); this.WegKanten = new KantenListe(); this.HinKanten = new KantenListe(); this.Markierung = false; smarties = null; seitletztemMalenGeaendert = false; } //Platz-Konstruktor (privat & ohne Parameter) /***************************************************/ /* PN_Knoten-Implementierung */ /***************************************************/ public int getID() { return ID; }//getID public boolean gleich(PN_Knoten Knoten) { return Knoten.getID() == ID; }//gleich public boolean isKlasse(String str) { return getClass().getName().compareTo(str)==0; }//isKlasse /***************************************************/ /* Darstellungsteil */ /***************************************************/ protected myJLabel[] getMatrixTexte() { myJLabel[] jls = new myJLabel[ Netz.getFarbanzahl()+ 1]; jls[0] = new myJLabel( Text); int h; for( int i=1; i 0) jls[i] = new myJLabel( Netz.Zweistellig( Marken.getWert(i-1))+ "/"+ Netz.Zweistellig( h), JLabel.LEFT); else jls[i] = new myJLabel( " ", JLabel.LEFT); return jls; }//getMatrixTexte protected int getBitMusterBenutzeFarben() { if( smarties==null) return 0; int muster = 0; for( int i=0; i= maxID) maxID = neuPlatz.ID+1; if( !Netz.IntLesenBisCharOK( 1, 'p', LD)) break PlatzLesen; if( !Netz.IntLesenBisCharOK( 2, 'p', LD)) break PlatzLesen; neuPlatz.Mittel_Pkt = new Point( LD.wert[1], LD.wert [2]); if( !Netz.IntLesenBisCharOK( 1, 'p', LD)) break PlatzLesen; neuPlatz.Radius = LD.wert[1]; if( !Netz.IntLesenBisCharOK( 1, 'p', LD)) break PlatzLesen; if( !Netz.TextLesenOK( LD.wert[1], LD)) break PlatzLesen; neuPlatz.Text = LD.text; eTupel = Tupel.Laden( LD); if( eTupel == null) break PlatzLesen; neuPlatz.Kapazitaet = eTupel; eTupel = Tupel.Laden( LD); if((eTupel == null) || !neuPlatz.KapazitaetMindestens(eTupel)) break PlatzLesen; neuPlatz.Marken = eTupel; neuPlatz.smarties = new smartiPunkte(neuPlatz, neuPlatz.smarties); if( !Netz.EinlesenOK(LD)) break PlatzLesen; neuPlatz.seitletztemMalenGeaendert = true; return neuPlatz; } return null; } catch(Exception e) { return null; } }//Laden /*private static boolean readIntKomponente(String objstr) { int comlen = objstr.indexOf(':'); try { int wert = Integer.valueOf(objstr.substring(0,comlen-1)).intValue(); } catch (NumberFormatException e) { return false; } objstr = objstr.substring(comlen+1); return true; }//readIntKomponente /***************************************************/ /* Darstellungsteil */ /***************************************************/ public void Verschieben(int x_entfernung, int y_entfernung, boolean kantenAktualisieren) { Mittel_Pkt.translate( x_entfernung, y_entfernung); setLocation( Mittel_Pkt.x-(Radius>>1), Mittel_Pkt.y-(Radius>>1)); smarties = new smartiPunkte(this, smarties); if( kantenAktualisieren ){ Kante[] hinKant = HinKanten.toArray(); Kante[] wegKant = WegKanten.toArray(); int iKant, anzHin = hinKant.length, anzWeg = wegKant.length; for( iKant=0; iKant0 ){ if( Marken.Addieren(einfMarken) ){ smarties = new smartiPunkte(this, smarties); seitletztemMalenGeaendert = true; return true; } else { if( smarties.alsMatrixDarstellen ) Petri.frame.gefNetz.InMatrixEinfuegen( this, false); seitletztemMalenGeaendert = true; smarties = null; return false; } } else return true; }//MarkenEinfuegen public boolean MarkenEntfernen(Tupel entfMarken) { if( !(MarkenVorhanden(entfMarken)) ) return false; if( entfMarken.getSummeAller()>0 ){ if( Marken.Abziehen(entfMarken) ){ smarties = new smartiPunkte(this, smarties); seitletztemMalenGeaendert = true; return true; } else { if( smarties.alsMatrixDarstellen ) Petri.frame.gefNetz.InMatrixEinfuegen( this, false); seitletztemMalenGeaendert = true; smarties = null; return false; } } else return true; }//MarkenEntfernen public Tupel getKopieKapazitaetMarken() { return new Tupel( Kapazitaet); }//getKapazitaetMarken public Tupel getKopieMarken() { return new Tupel( Marken); }//getMarken /***************************************************/ /* ...-Teil */ /***************************************************/ }//Platz-Klasse class smartiPunkte { // 0, 1, 2, 3, 4, 5, 6, 7, 8 private static final double radiuskoeff[] = { 0, 0.460, 0.460, 0.460, 0.410, 0.360, 0.330, 0.290, 0.280}; private double[] kreis_x, kreis_y; private double kreisradius; private int maxBenuKapa; private Platz ePlatz; protected boolean alsMatrixDarstellen; protected boolean leer; protected int anzBenuFarben; //benu = benutzt protected int[] benuFarbe; protected int[] benuMark; protected int[] benuKapa; protected int[][] x, y; protected double[] markenradius; public smartiPunkte(Platz ePlatz, smartiPunkte alterWert) { if( (Netz.MAX_FARBENDARSTELLANZ >= radiuskoeff.length) || (Netz.MAX_MARKENDARSTELLANZ >= radiuskoeff.length) ) throw new IllegalArgumentException( "Die Anzahl der darzustellenden Farben und Marken wurde zu sehr erhoeht. Daher "+ " sind nun die notwendigen Parameter nicht ausreichend vorhanden. Siehe Platz.java!"); if( alterWert != null ){ if( alterWert.alsMatrixDarstellen ) Petri.frame.gefNetz.InMatrixEinfuegen( alterWert.ePlatz, false); } /*try{*/ this.ePlatz = ePlatz; initialisieren(); alsMatrixDarstellen = false; leer = false; if( anzBenuFarben==0 ) leer = true; else if( (00 ) anzBenuFarben++; } benuFarbe = new int[anzBenuFarben]; benuKapa = new int[anzBenuFarben]; benuMark = new int[anzBenuFarben]; markenradius = new double[anzBenuFarben]; kreis_x = new double[anzBenuFarben]; kreis_y = new double[anzBenuFarben]; x = new int[anzBenuFarben][]; y = new int[anzBenuFarben][]; maxBenuKapa = 0; for( int i=0; i